Process all package source files with compiler plugins.

Files not explicitly added with api.addFiles are currently ignored by the
Linker, but that will change once we have a module system.
This commit is contained in:
Ben Newman
2015-11-24 21:21:47 -05:00
parent 5883c3feb7
commit fff2e46661
4 changed files with 69 additions and 15 deletions

View File

@@ -361,11 +361,14 @@ exports.makeCompileStep = function (sourceItem, file, inputSourceArch, options)
throw new Error("'sourcePath' option must be supplied to addJavaScript. Consider passing inputPath.");
}
// By default, use fileOptions for the `bare` option but also allow
// overriding it with the options
var bare = fileOptions.bare;
if (options.hasOwnProperty("bare")) {
bare = options.bare;
const fileOptions = self.inputResource.fileOptions;
function getOption(name) {
// By default, use fileOptions for these options but also allow
// overriding them with the options.
return _.has(options, name)
? options.name
: fileOptions && fileOptions[name];
}
var data = new Buffer(
@@ -384,7 +387,8 @@ exports.makeCompileStep = function (sourceItem, file, inputSourceArch, options)
hash: watch.sha1(data),
sourceMap: convertSourceMapPaths(options.sourceMap,
files.convertToStandardPath),
bare: !! bare
lazy: !! getOption("lazy"),
bare: !! getOption("bare"),
});
},

View File

@@ -376,12 +376,14 @@ class ResourceSlot {
throw Error("addJavaScript on non-source ResourceSlot?");
}
// By default, use the 'bare' option given to addFiles, but allow the option
// passed to addJavaScript to override it.
var bare = self.inputResource.fileOptions &&
self.inputResource.fileOptions.bare;
if (options.hasOwnProperty('bare')) {
bare = options.bare;
const fileOptions = self.inputResource.fileOptions;
function getOption(name) {
// By default, use fileOptions for these options but also allow
// overriding them with the options.
return _.has(options, name)
? options.name
: fileOptions && fileOptions[name];
}
var data = new Buffer(
@@ -396,7 +398,8 @@ class ResourceSlot {
// XXX do we need to call convertSourceMapPaths here like we did
// in legacy handlers?
sourceMap: options.sourceMap,
bare: !! bare
lazy: !! getOption("lazy"),
bare: !! getOption("bare"),
});
}

View File

@@ -109,6 +109,11 @@ _.extend(Module.prototype, {
// preserving the line numbers.
if (self.useGlobalNamespace) {
return _.map(self.files, function (file) {
if (file.lazy) {
// Ignore lazy files unless we have a module system.
return;
}
const cacheKey = JSON.stringify([
file.sourceHash, file.bare, file.servePath]);
@@ -147,9 +152,15 @@ _.extend(Module.prototype, {
// Emit each file
_.each(self.files, function (file) {
if (file.lazy) {
// Ignore lazy files unless we have a module system.
return;
}
if (!_.isEmpty(chunks)) {
chunks.push("\n\n\n\n\n\n");
}
chunks.push(file.getPrelinkedOutput({
sourceWidth: sourceWidth,
noLineNumbers: self.noLineNumbers
@@ -244,6 +255,9 @@ var File = function (inputFile, module) {
// the path where this file would prefer to be served if possible
self.servePath = inputFile.servePath;
// True if the input file should not be evaluated eagerly.
self.lazy = !!inputFile.lazy;
// If true, don't wrap this individual file in a closure.
self.bare = !!inputFile.bare;

View File

@@ -1176,8 +1176,41 @@ _.extend(PackageSource.prototype, {
arch: arch,
uses: api.uses[arch],
implies: api.implies[arch],
getFiles() {
return api.files[arch];
getFiles(sourceProcessorSet, watchSet) {
const result = api.files[arch];
const relPathToSourceObj = {};
const sources = result.sources;
// Files explicitly passed to api.addFiles remain at the
// beginning of api.files[arch].sources in their given order.
sources.forEach(sourceObj => {
relPathToSourceObj[sourceObj.relPath] = sourceObj;
});
self._findSources({
sourceProcessorSet,
watchSet,
arch,
isApp: false
}).forEach(relPath => {
if (! _.has(relPathToSourceObj, relPath)) {
const fileOptions = self._inferFileOptions(relPath, {
arch,
isApp: false,
});
// Since this file was not explicitly added with
// api.addFiles, it should not be evaluated eagerly.
fileOptions.lazy = true;
sources.push(relPathToSourceObj[relPath] = {
relPath,
fileOptions,
});
}
});
return result;
},
declaredExports: api.exports[arch],
watchSet: watchSet