Skip to content

Commit

Permalink
Also provide CJS of code-frame and highlight (for prettier)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jun 11, 2022
1 parent f2147e4 commit 956bd59
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
66 changes: 38 additions & 28 deletions Gulpfile.mjs
Expand Up @@ -483,6 +483,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 = [
Expand Down Expand Up @@ -536,29 +544,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 () => {
Expand Down Expand Up @@ -610,15 +624,11 @@ gulp.task(
gulp.series(
"build-vendor",
gulp.parallel("build-rollup", "build-babel"),
gulp.parallel(
"build-parser-cjs",
"generate-type-helpers",
"generate-runtime-helpers"
),
gulp.parallel("generate-type-helpers", "generate-runtime-helpers"),
// rebuild @babel/types and @babel/helpers since
// type-helpers and generated helpers may be changed
"build-babel",
"generate-standalone"
gulp.parallel("generate-standalone", "build-cjs-bundles")
)
);

Expand All @@ -635,7 +645,7 @@ gulp.task(
"build-vendor",
"build-no-bundle",
gulp.parallel(
"build-parser-cjs",
"build-cjs-bundles",
"generate-standalone",
"generate-runtime-helpers",
gulp.series(
Expand Down
2 changes: 2 additions & 0 deletions constraints.pro
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion packages/babel-code-frame/package.json
Expand Up @@ -35,7 +35,10 @@
]
},
"exports": {
".": "./lib/index.js",
".": {
"require": "./lib/index.cjs",
"default": "./lib/index.js"
},
"./package.json": "./package.json"
},
"type": "module"
Expand Down
5 changes: 4 additions & 1 deletion packages/babel-highlight/package.json
Expand Up @@ -35,7 +35,10 @@
]
},
"exports": {
".": "./lib/index.js",
".": {
"require": "./lib/index.cjs",
"default": "./lib/index.js"
},
"./package.json": "./package.json"
},
"type": "module"
Expand Down

0 comments on commit 956bd59

Please sign in to comment.