(sourceProcessorSet, arch)
| 51 | |
| 52 | // Returns a sort comparator to order files into load order. |
| 53 | var loadOrderSort = function (sourceProcessorSet, arch) { |
| 54 | const isTemplate = _.memoize((filename) => { |
| 55 | const classification = sourceProcessorSet.classifyFilename(filename, arch); |
| 56 | switch (classification.type) { |
| 57 | case 'extension': |
| 58 | case 'filename': |
| 59 | if (! classification.sourceProcessors) { |
| 60 | // This is *.js, not a template. #HardcodeJs |
| 61 | return false; |
| 62 | } |
| 63 | if (classification.sourceProcessors.length > 1) { |
| 64 | throw Error("conflicts in compiler?"); |
| 65 | } |
| 66 | return classification.sourceProcessors[0].isTemplate; |
| 67 | |
| 68 | case 'legacy-handler': |
| 69 | return classification.legacyIsTemplate; |
| 70 | |
| 71 | case 'wrong-arch': |
| 72 | case 'unmatched': |
| 73 | case 'meteor-ignore': |
| 74 | return false; |
| 75 | |
| 76 | default: |
| 77 | throw Error(`surprising type ${classification.type} for ${filename}`); |
| 78 | } |
| 79 | }); |
| 80 | |
| 81 | return function (a, b) { |
| 82 | // XXX MODERATELY SIZED HACK -- |
| 83 | // push template files ahead of everything else. this is |
| 84 | // important because the user wants to be able to say |
| 85 | // Template.foo.events = { ... } |
| 86 | // in a JS file and not have to worry about ordering it |
| 87 | // before the corresponding .html file. |
| 88 | // |
| 89 | // maybe all of the templates should go in one file? |
| 90 | var isTemplate_a = isTemplate(files.pathBasename(a)); |
| 91 | var isTemplate_b = isTemplate(files.pathBasename(b)); |
| 92 | if (isTemplate_a !== isTemplate_b) { |
| 93 | return (isTemplate_a ? -1 : 1); |
| 94 | } |
| 95 | |
| 96 | // main.* loaded last |
| 97 | var ismain_a = (files.pathBasename(a).indexOf('main.') === 0); |
| 98 | var ismain_b = (files.pathBasename(b).indexOf('main.') === 0); |
| 99 | if (ismain_a !== ismain_b) { |
| 100 | return (ismain_a ? 1 : -1); |
| 101 | } |
| 102 | |
| 103 | // /lib/ loaded first |
| 104 | var islib_a = (a.indexOf(files.pathSep + 'lib' + files.pathSep) !== -1 || |
| 105 | a.indexOf('lib' + files.pathSep) === 0); |
| 106 | var islib_b = (b.indexOf(files.pathSep + 'lib' + files.pathSep) !== -1 || |
| 107 | b.indexOf('lib' + files.pathSep) === 0); |
| 108 | if (islib_a !== islib_b) { |
| 109 | return (islib_a ? -1 : 1); |
| 110 | } |
no test coverage detected
searching dependent graphs…