Skip to content

Commit

Permalink
✨ [bento][npm] Update file naming from mjs to module (ampproject#34568)
Browse files Browse the repository at this point in the history
* Update file naming from mjs to module

* import exports should be in alphabetical order

* Rename helper function
  • Loading branch information
krdwan authored and rochapablo committed Aug 30, 2021
1 parent 51af2b1 commit d0d0d51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions build-system/tasks/extension-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
doBuildJs,
endBuildStep,
maybeToEsmName,
maybeToNpmEsmName,
mkdirSync,
watchDebounceDelay,
} = require('./helpers');
Expand Down Expand Up @@ -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: maybeToNpmEsmName(`${name}.max.js`),
minifiedName: maybeToNpmEsmName(`${name}.js`),
latestName: '',
outputFormat: esm ? 'esm' : 'cjs',
wrapper: '',
Expand Down
14 changes: 11 additions & 3 deletions build-system/tasks/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ function maybeToEsmName(name) {
return argv.esm ? toEsmName(name) : name;
}

/**
* @param {string} name
* @return {string}
*/
function maybeToNpmEsmName(name) {
return argv.esm ? name.replace(/\.js$/, '.module.js') : name;
}

/**
* Minifies a given JavaScript file entry point.
* @param {string} srcDir
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -866,6 +873,7 @@ module.exports = {
compileUnminifiedJs,
maybePrintCoverageMessage,
maybeToEsmName,
maybeToNpmEsmName,
mkdirSync,
printConfigHelp,
printNobuildHelp,
Expand Down

0 comments on commit d0d0d51

Please sign in to comment.