Skip to content

Commit

Permalink
Merge pull request #1478 from glimmerjs/re-enable-select-cjs-builds-f…
Browse files Browse the repository at this point in the history
…or-community-tools-not-yet-on-esm

Add CJS back to glimmer/syntax,compiler
  • Loading branch information
NullVoxPopuli authored Oct 31, 2023
2 parents 7b7e97c + eb4e6c9 commit debb645
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
48 changes: 44 additions & 4 deletions packages/@glimmer-workspace/build/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,14 @@ export class Package {

/**
* @param {ImportMeta | string} meta
* @param {Formats} [formats]
* @returns {import("./config.js").RollupExport}
*/
static config(meta) {
static config(meta, formats) {
const pkg = Package.at(meta);

if (pkg) {
return pkg.config();
return pkg.config(formats);
} else {
return [];
}
Expand Down Expand Up @@ -242,10 +243,25 @@ export class Package {
}

/**
* @typedef {object} Formats
* @property {boolean} [ esm ] enabled by default
* @property {boolean} [ cjs ] disabled by default
*
* @returns {import("rollup").RollupOptions[] | import("rollup").RollupOptions}
*/
config() {
return [...this.rollupESM({ env: 'dev' }), ...this.rollupESM({ env: 'prod' })];
config(formats = {}) {
let builds = [];

if (formats.esm ?? true) {
builds.push(...this.rollupESM({ env: 'dev' }));
builds.push(...this.rollupESM({ env: 'prod' }));
}

if (formats.cjs) {
builds.push(...this.rollupCJS({ env: 'dev' }));
}

return builds;
}

/**
Expand Down Expand Up @@ -300,6 +316,30 @@ export class Package {
}));
}

/**
* @param {RollupConfigurationOptions} options
* @returns {import("rollup").RollupOptions[]}
*/
rollupCJS({ env }) {
return this.#shared('cjs', env).map((options) => ({
...options,
external: this.#external,
plugins: [
inline(),
nodePolyfills(),
commonjs(),
nodeResolve(),
...this.replacements(env),
postcss(),
typescript(this.#package, {
target: ScriptTarget.ES2021,
module: ModuleKind.CommonJS,
moduleResolution: ModuleResolutionKind.NodeJs,
}),
],
}));
}

/**
* We only want importMeta stripped for production builds
* @param {'dev' | 'prod'} env
Expand Down
2 changes: 2 additions & 0 deletions packages/@glimmer/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
".": {
"types": "./dist/dev/index.d.ts",
"development": {
"require": "./dist/dev/index.cjs",
"default": "./dist/dev/index.js"
},
"require": "./dist/dev/index.cjs",
"default": "./dist/prod/index.js"
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/compiler/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Package } from '@glimmer-workspace/build-support';

export default Package.config(import.meta);
export default Package.config(import.meta, { esm: true, cjs: true });
2 changes: 2 additions & 0 deletions packages/@glimmer/syntax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
".": {
"types": "./dist/dev/index.d.ts",
"development": {
"require": "./dist/dev/index.cjs",
"default": "./dist/dev/index.js"
},
"require": "./dist/dev/index.cjs",
"default": "./dist/prod/index.js"
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/syntax/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Package } from '@glimmer-workspace/build-support';

export default Package.config(import.meta);
export default Package.config(import.meta, { esm: true, cjs: true });

0 comments on commit debb645

Please sign in to comment.