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 Mar 20, 2022
1 parent ec3fbea commit 53adfa3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
60 changes: 37 additions & 23 deletions Gulpfile.mjs
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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",
Expand All @@ -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(
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 53adfa3

Please sign in to comment.