diff --git a/packages/ejson/package.js b/packages/ejson/package.js index 26a33d4b35..7b4f238aa6 100644 --- a/packages/ejson/package.js +++ b/packages/ejson/package.js @@ -6,7 +6,7 @@ Package.describe({ Package.on_use(function (api) { api.use(['json', 'underscore']); api.exportSymbol('EJSON'); - api.exportSymbol('_EJSONTest'); + api.exportSymbol('_EJSONTest', {testOnly: true}); api.add_files('ejson.js', ['client', 'server']); api.add_files('base64.js', ['client', 'server']); }); diff --git a/packages/email/package.js b/packages/email/package.js index 393fc107ff..27d22beb5f 100644 --- a/packages/email/package.js +++ b/packages/email/package.js @@ -9,7 +9,7 @@ Npm.depends({mailcomposer: "0.1.15", simplesmtp: "0.1.25", "stream-buffers": "0. Package.on_use(function (api) { api.use('underscore', 'server'); api.exportSymbol('Email', 'server'); - api.exportSymbol('_EmailTest', 'server'); + api.exportSymbol('_EmailTest', 'server', {testOnly: true}); api.add_files('email.js', 'server'); }); diff --git a/packages/livedata/package.js b/packages/livedata/package.js index a7cb9def76..3a9eb2bf38 100644 --- a/packages/livedata/package.js +++ b/packages/livedata/package.js @@ -26,7 +26,7 @@ Package.on_use(function (api) { api.exportSymbol('DDP'); api.exportSymbol('DDPServer', 'server'); - api.exportSymbol('_LivedataTest'); + api.exportSymbol('_LivedataTest', {testOnly: true}); // Transport api.use('reload', 'client'); diff --git a/packages/mongo-livedata/package.js b/packages/mongo-livedata/package.js index d674e56643..e3704754be 100644 --- a/packages/mongo-livedata/package.js +++ b/packages/mongo-livedata/package.js @@ -26,7 +26,7 @@ Package.on_use(function (api) { // Allow us to detect 'autopublish', and publish collections if it's loaded. api.use('autopublish', 'server', {weak: true}); - api.exportSymbol('_MongoLivedataTest', 'server'); + api.exportSymbol('_MongoLivedataTest', 'server', {testOnly: true}); api.add_files('mongo_driver.js', 'server'); api.add_files('local_collection_driver.js', ['client', 'server']); diff --git a/packages/oauth/package.js b/packages/oauth/package.js index ad92dc44a0..5c292869e5 100644 --- a/packages/oauth/package.js +++ b/packages/oauth/package.js @@ -9,7 +9,7 @@ Package.on_use(function (api) { api.use(['underscore', 'service-configuration'], 'server'); api.exportSymbol('Oauth'); - api.exportSymbol('_OauthTest', 'server'); + api.exportSymbol('_OauthTest', 'server', {testOnly: true}); api.add_files('oauth_client.js', 'client'); api.add_files('oauth_server.js', 'server'); diff --git a/packages/oauth1/package.js b/packages/oauth1/package.js index ce76adfaa8..0dd304b6b9 100644 --- a/packages/oauth1/package.js +++ b/packages/oauth1/package.js @@ -11,7 +11,7 @@ Package.on_use(function (api) { api.use('http', 'server'); api.exportSymbol('OAuth1Binding', 'server'); - api.exportSymbol('_OAuth1Test', 'server'); + api.exportSymbol('_OAuth1Test', 'server', {testOnly: true}); api.add_files('oauth1_binding.js', 'server'); api.add_files('oauth1_server.js', 'server'); diff --git a/packages/routepolicy/package.js b/packages/routepolicy/package.js index 8b3db515bc..da08d2699c 100644 --- a/packages/routepolicy/package.js +++ b/packages/routepolicy/package.js @@ -9,7 +9,7 @@ Package.on_use(function (api) { // Package.webapp and only after initial load. api.use('webapp', 'server', {unordered: true}); api.exportSymbol('RoutePolicy', 'server'); - api.exportSymbol('_RoutePolicyTest', 'server'); + api.exportSymbol('_RoutePolicyTest', 'server', {testOnly: true}); api.add_files('routepolicy.js', 'server'); }); diff --git a/packages/spark/package.js b/packages/spark/package.js index 77bb36b188..932bc455d7 100644 --- a/packages/spark/package.js +++ b/packages/spark/package.js @@ -9,7 +9,7 @@ Package.on_use(function (api) { 'client'); api.exportSymbol('Spark', 'client'); - api.exportSymbol('_SparkTest', 'client'); + api.exportSymbol('_SparkTest', 'client', {testOnly: true}); api.add_files(['spark.js', 'patch.js', 'convenience.js', 'utils.js'], 'client'); diff --git a/tools/linker.js b/tools/linker.js index 1b1d24fffe..73dfb32302 100644 --- a/tools/linker.js +++ b/tools/linker.js @@ -462,8 +462,8 @@ var bannerPadding = function (bannerWidth) { // - sourcePath: path to use in error messages // - sourceMap: an optional source map (as string) for the input file // -// declaredExports: an array of symbols that the module exports. null -// if our slice isn't allowed to have exports. +// declaredExports: an array of symbols that the module exports. null if our +// slice isn't allowed to have exports. Symbols are {name,testOnly} pairs. // // useGlobalNamespace: make the top level namespace be the same as the // global namespace, so that symbols are accessible from the diff --git a/tools/packages.js b/tools/packages.js index beb5739d09..e3fbd1802c 100644 --- a/tools/packages.js +++ b/tools/packages.js @@ -399,7 +399,7 @@ _.extend(Slice.prototype, { rootOutputPath: self.pkg.serveRoot, arch: self.arch, fileOptions: fileOptions, - declaredExports: self.declaredExports, + declaredExports: _.pluck(self.declaredExports, 'name'), read: function (n) { if (n === undefined || readOffset + n > contents.length) n = contents.length - readOffset; @@ -493,7 +493,7 @@ _.extend(Slice.prototype, { "/packages/" + self.pkg.name + (self.sliceName === "main" ? "" : ("." + self.sliceName)) + ".js", name: self.pkg.name || null, - declaredExports: self.declaredExports, + declaredExports: _.pluck(self.declaredExports, 'name'), jsAnalyze: jsAnalyze }); @@ -517,14 +517,14 @@ _.extend(Slice.prototype, { self.packageVariables = []; var packageVariableNames = {}; - _.each(self.declaredExports, function (name) { - if (_.has(packageVariableNames, name)) + _.each(self.declaredExports, function (symbol) { + if (_.has(packageVariableNames, symbol.name)) return; self.packageVariables.push({ - name: name, - export: true + name: symbol.name, + export: symbol.testOnly? "tests" : true }); - packageVariableNames[name] = true; + packageVariableNames[symbol.name] = true; }); _.each(results.assignedVariables, function (name) { if (_.has(packageVariableNames, name)) @@ -580,8 +580,9 @@ _.extend(Slice.prototype, { if (! otherSlice.isBuilt) throw new Error("dependency wasn't built?"); _.each(otherSlice.packageVariables, function (symbol) { - // XXX implement test-only exports - if (symbol.export) + // Slightly hacky implementation of test-only exports. + if (symbol.export === true || + (symbol.export === "tests" && self.sliceName === "tests")) imports[symbol.name] = otherSlice.pkg.name; }); }); @@ -1586,13 +1587,22 @@ _.extend(Package.prototype, { // // @param symbols String (eg "Foo") or array of String // @param where 'client', 'server', or an array of those - exportSymbol: function (symbols, where) { + // @param options 'testOnly', boolean. + exportSymbol: function (symbols, where, options) { if (role === "test") { buildmessage.error("You cannot export symbols from a test.", { useMyCaller: true }); // recover by ignoring return; } + // Support `api.exportSymbol("FooTest", {testOnly: true})` without + // where. + if (_.isObject(where) && !_.isArray(where) && !options) { + options = where; + where = null; + } + options = options || {}; + symbols = toArray(symbols); where = toWhereArray(where); @@ -1605,7 +1615,7 @@ _.extend(Package.prototype, { return; } _.each(where, function (w) { - exports[w].push(symbol); + exports[w].push({name: symbol, testOnly: !!options.testOnly}); }); }); },