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 Jul 28, 2021
1 parent a597eff commit f5a7a58
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 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
8 changes: 4 additions & 4 deletions config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function prepareCJSMinified(input) {
return {
input,
output: {
file: input.replace('.js', '.min.js'),
file: input.replace('.cjs', '.min.cjs'),
format: 'cjs',
},
plugins: [
Expand Down Expand Up @@ -108,7 +108,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 @@ -125,10 +125,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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"author": "opensource@apollographql.com",
"license": "MIT",
"main": "./dist/main.cjs.js",
"main": "./dist/main.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"sideEffects": false,
Expand Down Expand Up @@ -54,7 +54,7 @@
"bundlesize": [
{
"name": "apollo-client",
"path": "./dist/apollo-client.cjs.min.js",
"path": "./dist/apollo-client.min.cjs",
"maxSize": "24.6 kB"
}
],
Expand Down

0 comments on commit f5a7a58

Please sign in to comment.