Skip to content

Commit 2fa37dc

Browse files
committed
add entry point for each folder, generate exports
1 parent 16fa5d5 commit 2fa37dc

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

package.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
"main": "index.js",
88
"module": "index.mjs",
99
"exports": {
10-
".": {
11-
"types": {
12-
"import": "./index.js.d.mts",
13-
"default": "./index.d.ts"
14-
},
15-
"module": "./index.mjs",
16-
"import": "./index.js.mjs",
17-
"default": "./index.js"
18-
},
1910
"./execution/execute.js": {
2011
"types": {
2112
"import": "./execution/execute.js.d.mts",

resources/build-npm.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ const {
1313
showDirStats,
1414
} = require('./utils.js');
1515

16-
const entryPoints = [
17-
'index.ts',
18-
'execution/execute.ts',
19-
'jsutils/instanceOf.ts',
20-
'language/parser.ts',
21-
'language/ast.ts',
22-
];
16+
const entryPoints = fs
17+
.readdirSync('./src', { recursive: true })
18+
.filter((f) => f.endsWith('index.ts'))
19+
.map((f) => f.replace(/^src/, ''))
20+
.reverse()
21+
.concat([
22+
'execution/execute.ts',
23+
'jsutils/instanceOf.ts',
24+
'language/parser.ts',
25+
'language/ast.ts',
26+
]);
2327

2428
if (require.main === module) {
2529
fs.rmSync('./npmDist', { recursive: true, force: true });
@@ -127,6 +131,27 @@ function buildPackageJSON() {
127131

128132
packageJSON.type = 'commonjs';
129133

134+
for (const entryPoint of entryPoints) {
135+
if (!entryPoint.endsWith('index.ts')) {
136+
continue;
137+
}
138+
const base = ('./' + path.dirname(entryPoint)).replace(/\/.?$/, '');
139+
const generated = {};
140+
generated[base] = {
141+
types: {
142+
import: base + '/index.js.d.mts',
143+
default: base + '/index.d.ts',
144+
},
145+
module: base + '/index.mjs',
146+
import: base + '/index.js.mjs',
147+
default: base + '/index.js',
148+
};
149+
packageJSON.exports = {
150+
...generated,
151+
...packageJSON.exports,
152+
};
153+
}
154+
130155
// TODO: move to integration tests
131156
const publishTag = packageJSON.publishConfig?.tag;
132157
assert(publishTag != null, 'Should have packageJSON.publishConfig defined!');

0 commit comments

Comments
 (0)