diff --git a/History.md b/History.md index 26aba420e8..28d29632cc 100644 --- a/History.md +++ b/History.md @@ -14,6 +14,10 @@ * Plugins should not process files whose names match the extension exactly (with no extra dot). #3985 +* Adding the same file twice in the same package is now an error. Previously, + this could either lead to the file being included multiple times, or to a + build time crash. + ## `meteor` command-line tool diff --git a/tools/package-api.js b/tools/package-api.js index eb849b7e77..35875107f5 100644 --- a/tools/package-api.js +++ b/tools/package-api.js @@ -77,7 +77,7 @@ function PackageAPI (options) { self.buildingIsopackets = !!options.buildingIsopackets; - // source files used + // source files used. Map arch -> relPath -> {relPath, fileOptions} self.sources = {}; // symbols exported @@ -90,7 +90,7 @@ function PackageAPI (options) { self.implies = {}; _.each(compiler.ALL_ARCHES, function (arch) { - self.sources[arch] = []; + self.sources[arch] = {}; self.exports[arch] = []; self.uses[arch] = []; self.implies[arch] = []; @@ -301,14 +301,26 @@ _.extend(PackageAPI.prototype, { return files.convertToPosixPath(p, true); }); + var errors = []; _.each(paths, function (path) { forAllMatchingArchs(arch, function (a) { + if (_.has(self.sources[a], path)) { + errors.push("Duplicate source file: " + path); + return; + } var source = {relPath: path}; if (fileOptions) source.fileOptions = fileOptions; - self.sources[a].push(source); + self.sources[a][path] = source; }); }); + + // Spit out all the errors at the end, where the number of stack frames to + // skip is just 1 instead of something like 7 from forAllMatchingArchs and + // _.each. Avoid using _.each here to keep stack predictable. + for (var i = 0; i < errors.length; ++i) { + buildmessage.error(errors[i], { useMyCaller: true }); + } }, // Use this release to resolve unclear dependencies for this package. If diff --git a/tools/package-source.js b/tools/package-source.js index 95f6a05b31..752e5d7489 100644 --- a/tools/package-source.js +++ b/tools/package-source.js @@ -974,7 +974,7 @@ _.extend(PackageSource.prototype, { // and then continue. api.sources = {}; _.each(compiler.ALL_ARCHES, function (arch) { - api.sources[arch] = []; + api.sources[arch] = {}; }); fileAndDepLoader = null; @@ -1103,7 +1103,7 @@ _.extend(PackageSource.prototype, { arch: arch, uses: api.uses[arch], implies: api.implies[arch], - getSourcesFunc: function () { return api.sources[arch]; }, + getSourcesFunc: function () { return _.values(api.sources[arch]); }, declaredExports: api.exports[arch], watchSet: watchSet }));