Skip to content

Commit

Permalink
Use just .cjs for CommonJS bundles, rather than .cjs.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Jun 23, 2021
1 parent 36b14f4 commit 06dd96b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions config/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function eachFile(dir: string, callback: (

// Avoid re-transforming CommonJS bundle files.
if (relPath.endsWith(".cjs.js")) return;
if (relPath.endsWith(".cjs")) return;

// Avoid re-transforming CommonJS bundle files.
if (relPath.endsWith(".min.js")) return;
Expand Down
2 changes: 1 addition & 1 deletion config/prepareDist.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ entryPoints.forEach(function buildPackageJson({
JSON.stringify({
name: path.posix.join('@apollo', 'client', ...dirs),
type: "module",
main: `${bundleName}.cjs.js`,
main: `${bundleName}.cjs`,
module: 'index.js',
types: 'index.d.ts',
sideEffects,
Expand Down
6 changes: 3 additions & 3 deletions config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function prepareBundle({
return isExternal(id, parentId, true);
},
output: {
file: `${dir}/${bundleName}.cjs.js`,
file: `${dir}/${bundleName}.cjs`,
format: 'cjs',
sourcemap: true,
exports: 'named',
Expand All @@ -109,10 +109,10 @@ export default [
// Convert the ESM entry point to a single CJS bundle.
prepareCJS(
'./dist/core/index.js',
'./dist/apollo-client.cjs.js',
'./dist/apollo-client.cjs',
),
// Minify that single CJS bundle.
prepareCJSMinified(
'./dist/apollo-client.cjs.js',
'./dist/apollo-client.cjs',
),
];
16 changes: 8 additions & 8 deletions config/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ switch (process.argv[2]) {
const {
ApolloClient,
InMemoryCache,
} = require(path.join(distRoot, "core", "core.cjs.js"));
} = require(path.join(distRoot, "core", "core.cjs"));

// Though this may seem like overkill, verifying that ApolloClient is
// constructible in Node.js is actually pretty useful, too!
Expand All @@ -43,15 +43,15 @@ switch (process.argv[2]) {
// the client might have acquired during its construction.
client.stop();

// The CommonJS dist/core/core.cjs.js file is generated from ESM modules
// generated by tsc, including dist/version.js, so verifying core.cjs.js
// exports an ApolloClient class that defines client.version also serves
// to verify that dist/version.js must have been correctly updated,
// which is convenient because dist/version.js uses ECMAScript module
// syntax, and is thus not importable in all versions of Node.js.
// The CommonJS dist/core/core.cjs file is generated from ESM modules
// generated by tsc, including dist/version.js, so verifying core.cjs
// exports an ApolloClient class that defines client.version also serves to
// verify that dist/version.js must have been correctly updated, which is
// convenient because dist/version.js uses ECMAScript module syntax, and is
// thus not importable in all versions of Node.js.
assert.strictEqual(
client.version, version,
"Failed to update dist/version.js and dist/core/core.cjs.js",
"Failed to update dist/version.js and dist/core/core.cjs",
);

break;
Expand Down

0 comments on commit 06dd96b

Please sign in to comment.