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

Update module and moduleResolution #1650

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions docs/cli/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ With esbuild, you can supply the following options:

## skuba build-package

Compiles your project for compatibility with CommonJS and ES2015 modules.
Compiles your project for compatibility with CommonJS and ES2022 modules.

This is useful for building isomorphic npm packages.

Expand All @@ -75,8 +75,8 @@ skuba build-package

# commonjs │ TSFILE: ...
# commonjs │ tsc exited with code 0
# es2015 │ TSFILE: ...
# es2015 │ tsc exited with code 0
# esm │ TSFILE: ...
# esm │ tsc exited with code 0
# types │ TSFILE: ...
# types │ tsc exited with code 0
```
Expand Down
20 changes: 10 additions & 10 deletions src/cli/build/assets.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ describe('copyAssetsConcurrently', () => {
prefixColor: 'green',
},
{
outDir: 'lib-es2015',
name: 'es2015',
outDir: 'lib-esm',
name: 'esm',
prefixColor: 'yellow',
},
]);
Expand All @@ -88,21 +88,21 @@ describe('copyAssetsConcurrently', () => {
"lib-commonjs/.vocab/translations.json": "",
"lib-commonjs/other.vocab/th.translations.json": "",
"lib-commonjs/other.vocab/translations.json": "",
"lib-es2015/.vocab/th.translations.json": "",
"lib-es2015/.vocab/translations.json": "",
"lib-es2015/other.vocab/th.translations.json": "",
"lib-es2015/other.vocab/translations.json": "",
"lib-esm/.vocab/th.translations.json": "",
"lib-esm/.vocab/translations.json": "",
"lib-esm/other.vocab/th.translations.json": "",
"lib-esm/other.vocab/translations.json": "",
}
`);
expect(getStdOut()).toMatchInlineSnapshot(`
commonjs │ Copying .vocab/th.translations.json
commonjs │ Copying .vocab/translations.json
commonjs │ Copying other.vocab/th.translations.json
commonjs │ Copying other.vocab/translations.json
es2015 │ Copying .vocab/th.translations.json
es2015 │ Copying .vocab/translations.json
es2015 │ Copying other.vocab/th.translations.json
es2015 │ Copying other.vocab/translations.json
esm │ Copying .vocab/th.translations.json
esm │ Copying .vocab/translations.json
esm │ Copying other.vocab/th.translations.json
esm │ Copying other.vocab/translations.json
`);
});
});
10 changes: 5 additions & 5 deletions src/cli/buildPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export const buildPackage = async (args = process.argv.slice(2)) => {
[
{
command:
'tsc --module CommonJS --outDir lib-commonjs --project tsconfig.build.json',
'tsc --module Node16 --outDir lib-commonjs --project tsconfig.build.json',
name: 'commonjs',
prefixColor: 'green',
},
{
command:
'tsc --module ES2015 --outDir lib-es2015 --project tsconfig.build.json',
name: 'es2015',
'tsc --module ES2022 --outDir lib-esm --project tsconfig.build.json',
name: 'esm',
prefixColor: 'yellow',
},
{
Expand All @@ -37,8 +37,8 @@ export const buildPackage = async (args = process.argv.slice(2)) => {
prefixColor: 'green',
},
{
outDir: 'lib-es2015',
name: 'es2015',
outDir: 'lib-esm',
name: 'esm',
prefixColor: 'yellow',
},
]);
Expand Down
6 changes: 3 additions & 3 deletions src/cli/configure/modules/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('packageModule', () => {
],
license: 'UNLICENSED',
main: './lib-commonjs/index.js',
module: './lib-es2015/index.js',
module: './lib-esm/index.js',
private: false,
scripts: {
build: 'skuba build-package',
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('packageModule', () => {
files: ['lib', 'something-else'],
license: 'UNLICENSED',
main: 'lib/commonjs',
module: 'lib/es2015',
module: 'lib/esm',
scripts: {
build: 'smt build',
commit: 'smt commit',
Expand Down Expand Up @@ -197,7 +197,7 @@ describe('packageModule', () => {
],
license: 'UNLICENSED',
main: './lib-commonjs/index.js',
module: './lib-es2015/index.js',
module: './lib-esm/index.js',
private: false,
scripts: {
build: 'skuba build-package',
Expand Down
2 changes: 1 addition & 1 deletion src/cli/configure/modules/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const packageModule = async ({
// Align with the required syntax for package.json#/paths
if (outputData.scripts.build === 'skuba build-package') {
outputData.main = './lib-commonjs/index.js';
outputData.module = './lib-es2015/index.js';
outputData.module = './lib-esm/index.js';
outputData.types = './lib-types/index.d.ts';
} else {
outputData.main = './lib/index.js';
Expand Down
2 changes: 1 addition & 1 deletion template/oss-npm-package/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "MIT",
"sideEffects": false,
"main": "./lib-commonjs/index.js",
"module": "./lib-es2015/index.js",
"module": "./lib-esm/index.js",
"types": "./lib-types/index.d.ts",
"files": [
"lib*/**/*.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion template/private-npm-package/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "UNLICENSED",
"sideEffects": false,
"main": "./lib-commonjs/index.js",
"module": "./lib-es2015/index.js",
"module": "./lib-esm/index.js",
"types": "./lib-types/index.d.ts",
"files": [
"lib*/**/*.d.ts",
Expand Down