From 7aeb64c073d68050e5ca0ed9bd4e7820ed8737c2 Mon Sep 17 00:00:00 2001 From: krdwan Date: Wed, 26 May 2021 16:14:51 -0400 Subject: [PATCH 1/3] Update file naming from mjs to module --- build-system/tasks/extension-helpers.js | 5 +++-- build-system/tasks/helpers.js | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/build-system/tasks/extension-helpers.js b/build-system/tasks/extension-helpers.js index 4edc53056d06..c4a15a34e987 100644 --- a/build-system/tasks/extension-helpers.js +++ b/build-system/tasks/extension-helpers.js @@ -25,6 +25,7 @@ const { doBuildJs, endBuildStep, maybeToEsmName, + npmMaybeToEsmName, mkdirSync, watchDebounceDelay, } = require('./helpers'); @@ -615,8 +616,8 @@ function buildBinaries(extDir, binaries, options) { entryPoint, `${extDir}/dist`, Object.assign(options, { - toName: maybeToEsmName(`${name}.max.js`), - minifiedName: maybeToEsmName(`${name}.js`), + toName: npmMaybeToEsmName(`${name}.max.js`), + minifiedName: npmMaybeToEsmName(`${name}.js`), latestName: '', outputFormat: esm ? 'esm' : 'cjs', wrapper: '', diff --git a/build-system/tasks/helpers.js b/build-system/tasks/helpers.js index 3bcebe486d96..0240f88c3795 100644 --- a/build-system/tasks/helpers.js +++ b/build-system/tasks/helpers.js @@ -291,6 +291,14 @@ function maybeToEsmName(name) { return argv.esm ? toEsmName(name) : name; } +/** + * @param {string} name + * @return {string} + */ +function npmMaybeToEsmName(name) { + return argv.esm ? name.replace(/\.js$/, '.module.js') : name; +} + /** * Minifies a given JavaScript file entry point. * @param {string} srcDir @@ -472,9 +480,9 @@ async function compileUnminifiedJs(srcDir, srcFilename, destDir, options) { watchedTargets.set(entryPoint, { rebuild: async () => { const time = Date.now(); - const {rebuild} = /** @type {Required} */ ( - buildResult - ); + const { + rebuild, + } = /** @type {Required} */ (buildResult); const buildPromise = rebuild() .then(() => @@ -503,9 +511,8 @@ async function compileUnminifiedJs(srcDir, srcFilename, destDir, options) { async function compileJsWithEsbuild(srcDir, srcFilename, destDir, options) { const startTime = Date.now(); const entryPoint = path.join(srcDir, srcFilename); - const destFilename = maybeToEsmName( - options.minify ? options.minifiedName : options.toName - ); + const fileName = options.minify ? options.minifiedName : options.toName; + const destFilename = options.npm ? fileName : maybeToEsmName(fileName); const destFile = path.join(destDir, destFilename); if (watchedTargets.has(entryPoint)) { @@ -866,6 +873,7 @@ module.exports = { compileUnminifiedJs, maybePrintCoverageMessage, maybeToEsmName, + npmMaybeToEsmName, mkdirSync, printConfigHelp, printNobuildHelp, From 2368a6b7cafc6d4f22eba152bb9984746d85a449 Mon Sep 17 00:00:00 2001 From: krdwan Date: Wed, 26 May 2021 17:16:58 -0400 Subject: [PATCH 2/3] import exports should be in alphabetical order --- build-system/tasks/extension-helpers.js | 2 +- build-system/tasks/helpers.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build-system/tasks/extension-helpers.js b/build-system/tasks/extension-helpers.js index c4a15a34e987..b3c295af1731 100644 --- a/build-system/tasks/extension-helpers.js +++ b/build-system/tasks/extension-helpers.js @@ -25,8 +25,8 @@ const { doBuildJs, endBuildStep, maybeToEsmName, - npmMaybeToEsmName, mkdirSync, + npmMaybeToEsmName, watchDebounceDelay, } = require('./helpers'); const { diff --git a/build-system/tasks/helpers.js b/build-system/tasks/helpers.js index 0240f88c3795..cce1d1c619da 100644 --- a/build-system/tasks/helpers.js +++ b/build-system/tasks/helpers.js @@ -480,9 +480,9 @@ async function compileUnminifiedJs(srcDir, srcFilename, destDir, options) { watchedTargets.set(entryPoint, { rebuild: async () => { const time = Date.now(); - const { - rebuild, - } = /** @type {Required} */ (buildResult); + const {rebuild} = /** @type {Required} */ ( + buildResult + ); const buildPromise = rebuild() .then(() => @@ -873,8 +873,8 @@ module.exports = { compileUnminifiedJs, maybePrintCoverageMessage, maybeToEsmName, - npmMaybeToEsmName, mkdirSync, + npmMaybeToEsmName, printConfigHelp, printNobuildHelp, watchDebounceDelay, From 34e295f33efaa0d3b27d3236976670d1fb405ad8 Mon Sep 17 00:00:00 2001 From: krdwan Date: Wed, 26 May 2021 17:49:36 -0400 Subject: [PATCH 3/3] Rename helper function --- build-system/tasks/extension-helpers.js | 6 +++--- build-system/tasks/helpers.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build-system/tasks/extension-helpers.js b/build-system/tasks/extension-helpers.js index b3c295af1731..ba9c905c13a6 100644 --- a/build-system/tasks/extension-helpers.js +++ b/build-system/tasks/extension-helpers.js @@ -25,8 +25,8 @@ const { doBuildJs, endBuildStep, maybeToEsmName, + maybeToNpmEsmName, mkdirSync, - npmMaybeToEsmName, watchDebounceDelay, } = require('./helpers'); const { @@ -616,8 +616,8 @@ function buildBinaries(extDir, binaries, options) { entryPoint, `${extDir}/dist`, Object.assign(options, { - toName: npmMaybeToEsmName(`${name}.max.js`), - minifiedName: npmMaybeToEsmName(`${name}.js`), + toName: maybeToNpmEsmName(`${name}.max.js`), + minifiedName: maybeToNpmEsmName(`${name}.js`), latestName: '', outputFormat: esm ? 'esm' : 'cjs', wrapper: '', diff --git a/build-system/tasks/helpers.js b/build-system/tasks/helpers.js index cce1d1c619da..7e9626d74613 100644 --- a/build-system/tasks/helpers.js +++ b/build-system/tasks/helpers.js @@ -295,7 +295,7 @@ function maybeToEsmName(name) { * @param {string} name * @return {string} */ -function npmMaybeToEsmName(name) { +function maybeToNpmEsmName(name) { return argv.esm ? name.replace(/\.js$/, '.module.js') : name; } @@ -873,8 +873,8 @@ module.exports = { compileUnminifiedJs, maybePrintCoverageMessage, maybeToEsmName, + maybeToNpmEsmName, mkdirSync, - npmMaybeToEsmName, printConfigHelp, printNobuildHelp, watchDebounceDelay,