Skip to content

Commit

Permalink
Move meteorBabelHelpers to modules package, and restrict to legacy bu…
Browse files Browse the repository at this point in the history
…ndle.

Should fix #10595.

Code from the application `node_modules` directory becomes part of the
`modules` package, so that it can be imported by any other package that
uses the module system, regardless of package load order.

Now that we compile code from `node_modules` using `babel-compiler` and
`meteor-babel` (#10585), `node_modules` code requires the same runtime
environment as any other Meteor JS code. For the most part, this need is
satisfied by the `@babel/runtime/helpers/...` modules, which are also
defined in the `modules` package because they come from `node_modules`.
However, in the legacy bundle, `meteorBabelHelpers.sanitizeForInObject` is
used to fix buggy for-in iteration in older Internet Explorers.

Thankfully, this extra helper code does not need to be included in the
modern or server bundles, but only in legacy code.
  • Loading branch information
benjamn committed Jun 25, 2019
1 parent 097b493 commit 7cff9bc
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 29 deletions.
1 change: 0 additions & 1 deletion packages/babel-runtime/.npm/package/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions packages/babel-runtime/.npm/package/README

This file was deleted.

10 changes: 0 additions & 10 deletions packages/babel-runtime/.npm/package/npm-shrinkwrap.json

This file was deleted.

2 changes: 0 additions & 2 deletions packages/babel-runtime/babel-runtime.js
@@ -1,5 +1,3 @@
exports.meteorBabelHelpers = require("meteor-babel-helpers");

try {
var babelRuntimeVersion = require("@babel/runtime/package.json").version;
} catch (e) {
Expand Down
7 changes: 1 addition & 6 deletions packages/babel-runtime/package.js
@@ -1,16 +1,11 @@
Package.describe({
name: "babel-runtime",
summary: "Runtime support for output of Babel transpiler",
version: '1.3.0',
version: '1.4.0',
documentation: 'README.md'
});

Npm.depends({
"meteor-babel-helpers": "0.0.3"
});

Package.onUse(function (api) {
api.use("modules");
api.mainModule("babel-runtime.js");
api.export("meteorBabelHelpers");
});
6 changes: 4 additions & 2 deletions packages/ecmascript/runtime-tests.js
Expand Up @@ -322,8 +322,10 @@ Tinytest.add("ecmascript - runtime - destructuring", (test) => {

Tinytest.addAsync("ecmascript - runtime - misc support", (test, done) => {
// Verify that the runtime was installed.
test.equal(typeof meteorBabelHelpers, "object");
test.equal(typeof meteorBabelHelpers.sanitizeForInObject, "function");
if (Meteor.isLegacy) {
test.equal(typeof meteorBabelHelpers, "object");
test.equal(typeof meteorBabelHelpers.sanitizeForInObject, "function");
}

class Base {
constructor(...args) {
Expand Down
5 changes: 5 additions & 0 deletions packages/modules/.npm/package/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/modules/legacy.js
@@ -0,0 +1,4 @@
// The meteor-babel/plugins/sanitize-for-in-objects plugin generates code
// that uses meteorBabelHelpers.sanitizeForInObject, but only when
// compiling code for the web.browser.legacy bundle. See #10595.
meteorBabelHelpers = require("meteor-babel-helpers");
11 changes: 10 additions & 1 deletion packages/modules/package.js
Expand Up @@ -6,12 +6,21 @@ Package.describe({
});

Npm.depends({
reify: "0.20.6"
reify: "0.20.6",
"meteor-babel-helpers": "0.0.3"
});

Package.onUse(function(api) {
api.use("modules-runtime");
api.mainModule("client.js", "client");
api.mainModule("server.js", "server");
api.export("meteorInstall");

// When compiling legacy code, the babel-compiler and meteor-babel
// packages assume meteorBabelHelpers.sanitizeForInObject is defined.
// Since the modules package is responsible for code from node_modules,
// it must also be responsible for exposing this runtime helper, but
// only in the legacy bundle.
api.addFiles("legacy.js", "legacy");
api.export("meteorBabelHelpers", "legacy");
});

0 comments on commit 7cff9bc

Please sign in to comment.