Skip to content

Commit

Permalink
📦 Update dependency esbuild to v0.11.19 (#34147)
Browse files Browse the repository at this point in the history
* 📦 Update dependency esbuild to v0.11.19

* Add workaround for evanw/esbuild#1202

* Hack: leave .mjs as esm

* cleanup

* experiment with excluding all of node_modules instead of just .mjs files.

* update comment

* nit:hoist

Co-authored-by: Raghu Simha <[email protected]>
Co-authored-by: Jake Fried <[email protected]>
  • Loading branch information
3 people authored May 11, 2021
1 parent 709223e commit 4251200
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
42 changes: 38 additions & 4 deletions build-system/common/esbuild-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,51 @@ function getEsbuildBabelPlugin(
build.onLoad({filter: /\.[cm]?js$/, namespace: ''}, async (file) => {
const filename = file.path;
const {contents, hash} = await batchedRead(filename, optionsHash);
const transformed = await transformContents(filename, contents, hash, {
...babelOptions,

const transformed = await transformContents(
filename,
filenameRelative: path.basename(filename),
});
contents,
hash,
getFileBabelOptions(babelOptions, filename)
);
return {contents: transformed};
});
},
};
}

const CJS_TRANSFORMS = new Set([
'transform-modules-commonjs',
'proposal-dynamic-import',
'syntax-dynamic-import',
'proposal-export-namespace-from',
'syntax-export-namespace-from',
]);

/**
* @param {!Object} babelOptions
* @param {string} filename
* @return {!Object}
*/
function getFileBabelOptions(babelOptions, filename) {
// Patch for leaving files within node_modules as esm, since esbuild will break when trying
// to process a module file that contains CJS exports. This function is called after
// babel.loadOptions, therefore all of the plugins from preset-env have already been applied.
// and must be disabled individually.
if (filename.includes('node_modules')) {
const plugins = babelOptions.plugins.filter(
({key}) => !CJS_TRANSFORMS.has(key)
);
babelOptions = {...babelOptions, plugins};
}

return {
...babelOptions,
filename,
filenameRelative: path.basename(filename),
};
}

module.exports = {
getEsbuildBabelPlugin,
};
4 changes: 4 additions & 0 deletions build-system/tasks/runtime-test/runtime-test-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ class RuntimeTestConfig {
},
plugins: [importPathPlugin, babelPlugin],
sourcemap: 'inline',
// TODO(rsimha): Remove this workaround once evanw/esbuild#1202 is fixed.
banner: {
js: "function require(x) { throw new Error('Cannot require ' + x) }",
},
};
}

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"del": "6.0.0",
"enzyme": "3.11.0",
"enzyme-adapter-preact-pure": "3.1.0",
"esbuild": "0.9.7",
"esbuild": "0.11.19",
"escodegen": "2.0.0",
"eslint": "7.26.0",
"eslint-config-prettier": "8.3.0",
Expand Down

0 comments on commit 4251200

Please sign in to comment.