Skip to content

Commit 3e0f5c9

Browse files
committed
Merge remote-tracking branch 'origin/esm/again' into fn/astro-node
2 parents 4c17e43 + bf052f6 commit 3e0f5c9

File tree

32 files changed

+350
-21
lines changed

32 files changed

+350
-21
lines changed

dev-packages/rollup-utils/npmHelpers.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
makeSetSDKSourcePlugin,
1818
makeSucrasePlugin,
1919
} from './plugins/index.mjs';
20+
import { makePackageNodeEsm } from './plugins/make-esm-plugin.mjs';
2021
import { mergePlugins } from './utils.mjs';
2122

2223
const packageDotJSON = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), { encoding: 'utf8' }));
@@ -104,6 +105,7 @@ export function makeBaseNPMConfig(options = {}) {
104105
...builtinModules,
105106
...Object.keys(packageDotJSON.dependencies || {}),
106107
...Object.keys(packageDotJSON.peerDependencies || {}),
108+
...Object.keys(packageDotJSON.optionalDependencies || {}),
107109
],
108110
};
109111

@@ -120,7 +122,7 @@ export function makeBaseNPMConfig(options = {}) {
120122
export function makeNPMConfigVariants(baseConfig) {
121123
const variantSpecificConfigs = [
122124
{ output: { format: 'cjs', dir: path.join(baseConfig.output.dir, 'cjs') } },
123-
{ output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm') } },
125+
{ output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm'), plugins: [makePackageNodeEsm()] } },
124126
];
125127

126128
return variantSpecificConfigs.map(variant => deepMerge(baseConfig, variant));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Outputs a package.json file with {type: module} in the root of the output directory so that Node
3+
* treats .js files as ESM.
4+
*/
5+
export function makePackageNodeEsm() {
6+
return {
7+
name: 'make-package-node-esm',
8+
generateBundle() {
9+
this.emitFile({
10+
type: 'asset',
11+
fileName: 'package.json',
12+
source: '{ "type": "module" }',
13+
});
14+
},
15+
};
16+
}

packages/browser/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
"main": "build/npm/cjs/index.js",
1919
"module": "build/npm/esm/index.js",
2020
"types": "build/npm/types/index.d.ts",
21+
"exports": {
22+
"./package.json": "./package.json",
23+
".": {
24+
"import": {
25+
"types": "./build/npm/types/index.d.ts",
26+
"default": "./build/npm/esm/index.js"
27+
},
28+
"require": {
29+
"types": "./build/npm.types/index.d.ts",
30+
"default": "./build/npm/cjs/index.js"
31+
}
32+
}
33+
},
2134
"typesVersions": {
2235
"<4.9": {
2336
"build/npm/types/index.d.ts": [

packages/bun/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
"main": "build/esm/index.js",
1919
"module": "build/esm/index.js",
2020
"types": "build/types/index.d.ts",
21+
"exports": {
22+
"./package.json": "./package.json",
23+
".": {
24+
"import": {
25+
"types": "./build/types/index.d.ts",
26+
"default": "./build/esm/index.js"
27+
},
28+
"require": {
29+
"types": "./build/types/index.d.ts",
30+
"default": "./build/cjs/index.js"
31+
}
32+
}
33+
},
2134
"typesVersions": {
2235
"<4.9": {
2336
"build/npm/types/index.d.ts": [

packages/core/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
"main": "build/cjs/index.js",
1919
"module": "build/esm/index.js",
2020
"types": "build/types/index.d.ts",
21+
"exports": {
22+
"./package.json": "./package.json",
23+
".": {
24+
"import": {
25+
"types": "./build/types/index.d.ts",
26+
"default": "./build/esm/index.js"
27+
},
28+
"require": {
29+
"types": "./build/types/index.d.ts",
30+
"default": "./build/cjs/index.js"
31+
}
32+
}
33+
},
2134
"typesVersions": {
2235
"<4.9": {
2336
"build/types/index.d.ts": [

packages/deno/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
"license": "MIT",
99
"module": "build/index.mjs",
1010
"types": "build/index.d.ts",
11+
"exports": {
12+
"./package.json": "./package.json",
13+
".": {
14+
"import": {
15+
"types": "./build/index.d.ts",
16+
"default": "./build/index.mjs"
17+
}
18+
}
19+
},
1120
"publishConfig": {
1221
"access": "public"
1322
},

packages/feedback/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
"main": "build/npm/cjs/index.js",
1919
"module": "build/npm/esm/index.js",
2020
"types": "build/npm/types/index.d.ts",
21+
"exports": {
22+
"./package.json": "./package.json",
23+
".": {
24+
"import": {
25+
"types": "./build/npm/types/index.d.ts",
26+
"default": "./build/npm/esm/index.js"
27+
},
28+
"require": {
29+
"types": "./build/npm/types/index.d.ts",
30+
"default": "./build/npm/cjs/index.js"
31+
}
32+
}
33+
},
2134
"typesVersions": {
2235
"<4.9": {
2336
"build/npm/types/index.d.ts": [

packages/gatsby/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@
2626
"main": "build/cjs/index.js",
2727
"module": "build/esm/index.js",
2828
"types": "build/types/index.d.ts",
29+
"exports": {
30+
"./package.json": "./package.json",
31+
".": {
32+
"import": {
33+
"types": "./build/types/index.d.ts",
34+
"default": "./build/esm/index.js"
35+
},
36+
"require": {
37+
"types": "./build/types/index.d.ts",
38+
"default": "./build/cjs/index.js"
39+
}
40+
}
41+
},
2942
"typesVersions": {
3043
"<4.9": {
3144
"build/types/index.d.ts": [

packages/integration-shims/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
"main": "build/cjs/index.js",
66
"module": "build/esm/index.js",
77
"types": "build/types/index.d.ts",
8+
"exports": {
9+
"./package.json": "./package.json",
10+
".": {
11+
"import": {
12+
"types": "./build/types/index.d.ts",
13+
"default": "./build/esm/index.js"
14+
},
15+
"require": {
16+
"types": "./build/types/index.d.ts",
17+
"default": "./build/cjs/index.js"
18+
}
19+
}
20+
},
821
"typesVersions": {
922
"<4.9": {
1023
"build/types/index.d.ts": [

packages/nextjs/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
"module": "build/esm/index.server.js",
1414
"browser": "build/esm/index.client.js",
1515
"types": "build/types/index.types.d.ts",
16+
"exports": {
17+
"./package.json": "./package.json",
18+
".": {
19+
"browser": {
20+
"import": "./build/esm/index.client.js",
21+
"require": "./build/cjs/index.client.js"
22+
},
23+
"node": "./build/cjs/index.server.js",
24+
"types": "./build/types/index.types.d.ts"
25+
}
26+
},
1627
"typesVersions": {
1728
"<4.9": {
1829
"build/npm/types/index.d.ts": [

0 commit comments

Comments
 (0)