From 06dd96bc9617c3d37b60d5ee3018150555b6da9e Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 23 Jun 2021 10:45:07 -0400 Subject: [PATCH] Use just .cjs for CommonJS bundles, rather than .cjs.js. --- config/helpers.ts | 1 + config/prepareDist.js | 2 +- config/rollup.config.js | 6 +++--- config/version.js | 16 ++++++++-------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/config/helpers.ts b/config/helpers.ts index 2c881a98b0e..2fcc9919b9d 100644 --- a/config/helpers.ts +++ b/config/helpers.ts @@ -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; diff --git a/config/prepareDist.js b/config/prepareDist.js index 801cdfd21f5..5d35465337e 100644 --- a/config/prepareDist.js +++ b/config/prepareDist.js @@ -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, diff --git a/config/rollup.config.js b/config/rollup.config.js index 511c832acfc..484a838261f 100644 --- a/config/rollup.config.js +++ b/config/rollup.config.js @@ -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', @@ -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', ), ]; diff --git a/config/version.js b/config/version.js index f48278fc6e8..0abf54fe5c9 100644 --- a/config/version.js +++ b/config/version.js @@ -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! @@ -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;