From 53adfa31ee9884c25a4516c83120cf7f878d8121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 20 Mar 2022 14:34:06 +0100 Subject: [PATCH] Also provide CJS of code-frame and highlight (for prettier) --- Gulpfile.mjs | 60 ++++++++++++++++---------- constraints.pro | 2 + packages/babel-code-frame/package.json | 5 ++- packages/babel-highlight/package.json | 5 ++- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/Gulpfile.mjs b/Gulpfile.mjs index 7c823284e56c..c77d24c3bf4e 100644 --- a/Gulpfile.mjs +++ b/Gulpfile.mjs @@ -476,6 +476,14 @@ const libBundles = [ dest: "lib", })); +const cjsBundles = [ + // This is used by Prettier, @babel/register and @babel/eslint-parser + { src: "packages/babel-parser" }, + // These are used by Prettier + { src: "packages/babel-code-frame", external: ["@babel/highlight"] }, + { src: "packages/babel-highlight", external: ["js-tokens", "chalk"] }, +]; + const dtsBundles = ["packages/babel-types"]; const standaloneBundle = [ @@ -529,29 +537,35 @@ gulp.task( gulp.task("build-babel", () => buildBabel(true, /* exclude */ libBundles)); -gulp.task("build-parser-cjs", async () => { - const input = "./packages/babel-parser/lib/index.js"; - const output = "./packages/babel-parser/lib/index.cjs"; +gulp.task("build-cjs-bundles", () => { + return Promise.all( + cjsBundles.map(async ({ src, external = [] }) => { + const input = `./${src}/lib/index.js`; + const output = `./${src}/lib/index.cjs`; - const bundle = await rollup({ - input, - onwarn(warning, warn) { - if (warning.code === "CIRCULAR_DEPENDENCY") return; - warn(warning); - }, - plugins: [ - rollupNodeResolve({ - extensions: [".js", ".mjs", ".cjs", ".json"], - preferBuiltins: true, - }), - ], - }); + const bundle = await rollup({ + input, + external, + onwarn(warning, warn) { + if (warning.code === "CIRCULAR_DEPENDENCY") return; + warn(warning); + }, + plugins: [ + rollupCommonJs({ defaultIsModuleExports: true }), + rollupNodeResolve({ + extensions: [".js", ".mjs", ".cjs", ".json"], + preferBuiltins: true, + }), + ], + }); - await bundle.write({ - file: output, - format: "cjs", - sourcemap: false, - }); + await bundle.write({ + file: output, + format: "cjs", + sourcemap: false, + }); + }) + ); }); gulp.task("build-vendor", async () => { @@ -604,7 +618,7 @@ gulp.task( "build-vendor", gulp.parallel("build-rollup", "build-babel", "generate-runtime-helpers"), gulp.parallel( - "build-parser-cjs", + "build-cjs-bundles", "generate-standalone", gulp.series( "generate-type-helpers", @@ -628,7 +642,7 @@ gulp.task( "build-vendor", "build-no-bundle", gulp.parallel( - "build-parser-cjs", + "build-cjs-bundles", "generate-standalone", "generate-runtime-helpers", gulp.series( diff --git a/constraints.pro b/constraints.pro index 23302e299e09..58041236b268 100644 --- a/constraints.pro +++ b/constraints.pro @@ -82,6 +82,8 @@ gen_enforced_field(WorkspaceCwd, 'exports', '{ ".": "./lib/index.js", "./package workspace_ident(WorkspaceCwd, WorkspaceIdent), WorkspaceIdent \= '@babel/core', WorkspaceIdent \= '@babel/parser', + WorkspaceIdent \= '@babel/code-frame', + WorkspaceIdent \= '@babel/highlight', WorkspaceIdent \= '@babel/compat-data', WorkspaceIdent \= '@babel/plugin-transform-react-jsx', % TODO: Remove in Babel 8 WorkspaceIdent \= '@babel/helper-plugin-test-runner', % TODO: Remove in Babel 8 diff --git a/packages/babel-code-frame/package.json b/packages/babel-code-frame/package.json index d2f15eb6070d..1d7737a4ae92 100644 --- a/packages/babel-code-frame/package.json +++ b/packages/babel-code-frame/package.json @@ -35,7 +35,10 @@ ] }, "exports": { - ".": "./lib/index.js", + ".": { + "require": "./lib/index.cjs", + "default": "./lib/index.js" + }, "./package.json": "./package.json" }, "type": "module" diff --git a/packages/babel-highlight/package.json b/packages/babel-highlight/package.json index d2f60580d491..88fc2a30dbdd 100644 --- a/packages/babel-highlight/package.json +++ b/packages/babel-highlight/package.json @@ -35,7 +35,10 @@ ] }, "exports": { - ".": "./lib/index.js", + ".": { + "require": "./lib/index.cjs", + "default": "./lib/index.js" + }, "./package.json": "./package.json" }, "type": "module"