Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [bento][npm] Update file naming from mjs to module #34568

Merged
merged 3 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
npmMaybeToEsmName,
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: npmMaybeToEsmName(`${name}.max.js`),
minifiedName: npmMaybeToEsmName(`${name}.js`),
krdwan marked this conversation as resolved.
Show resolved Hide resolved
latestName: '',
outputFormat: esm ? 'esm' : 'cjs',
wrapper: '',
Expand Down
20 changes: 14 additions & 6 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 npmMaybeToEsmName(name) {
krdwan marked this conversation as resolved.
Show resolved Hide resolved
return argv.esm ? name.replace(/\.js$/, '.module.js') : name;
}

/**
* Minifies a given JavaScript file entry point.
* @param {string} srcDir
Expand Down Expand Up @@ -472,9 +480,9 @@ async function compileUnminifiedJs(srcDir, srcFilename, destDir, options) {
watchedTargets.set(entryPoint, {
rebuild: async () => {
const time = Date.now();
const {rebuild} = /** @type {Required<esbuild.BuildResult>} */ (
buildResult
);
const {
rebuild,
} = /** @type {Required<esbuild.BuildResult>} */ (buildResult);

krdwan marked this conversation as resolved.
Show resolved Hide resolved
const buildPromise = rebuild()
.then(() =>
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,
npmMaybeToEsmName,
mkdirSync,
printConfigHelp,
printNobuildHelp,
Expand Down