@mui/internal-code-infra 0.0.4-canary.67 → 0.0.4-canary.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/utils/build.d.mts +9 -26
- package/build/utils/typescript.d.mts +6 -16
- package/package.json +4 -5
- package/src/brokenLinksChecker/crawlWorker.mjs +2 -2
- package/src/cli/cmdBuild.mjs +14 -71
- package/src/utils/build.mjs +18 -49
- package/src/utils/build.test.mjs +50 -144
- package/src/utils/typescript.mjs +23 -42
- package/src/utils/typescript.test.mjs +28 -44
package/build/utils/build.d.mts
CHANGED
|
@@ -11,35 +11,28 @@ export declare const BASE_IGNORES: string[];
|
|
|
11
11
|
* @param {BundleType} bundle
|
|
12
12
|
* @param {Object} [options]
|
|
13
13
|
* @param {boolean} [options.isType=false] - Whether to get the extension for type declaration files.
|
|
14
|
-
* @param {boolean} [options.isFlat=false] - Whether to get the extension for a flat build structure.
|
|
15
14
|
* @param {'module' | 'commonjs'} [options.packageType='commonjs'] - The package.json type field.
|
|
16
15
|
* @returns {string}
|
|
17
16
|
*/
|
|
18
17
|
export declare function getOutExtension(bundle: BundleType, options?: {
|
|
19
18
|
isType?: boolean;
|
|
20
|
-
isFlat?: boolean;
|
|
21
19
|
packageType?: 'module' | 'commonjs';
|
|
22
20
|
}): string;
|
|
23
21
|
/**
|
|
24
22
|
* @param {import('../cli/packageJson').PackageJson['exports']} packageExports
|
|
25
23
|
* @param {Object} options
|
|
26
|
-
* @param {
|
|
24
|
+
* @param {BundleType[]} options.bundles
|
|
27
25
|
* @param {string} options.outputDir
|
|
28
26
|
* @param {string} options.cwd
|
|
29
27
|
* @param {boolean} [options.addTypes]
|
|
30
|
-
* @param {boolean} [options.isFlat]
|
|
31
28
|
* @param {boolean} [options.expand] - Whether to enumerate glob patterns into concrete entries.
|
|
32
29
|
* @param {'module' | 'commonjs'} [options.packageType]
|
|
33
30
|
*/
|
|
34
|
-
export declare function createPackageExports(packageExports: import('../cli/packageJson').PackageJson['exports'], { bundles, outputDir, cwd, addTypes,
|
|
35
|
-
bundles:
|
|
36
|
-
type: BundleType;
|
|
37
|
-
dir: string;
|
|
38
|
-
}[];
|
|
31
|
+
export declare function createPackageExports(packageExports: import('../cli/packageJson').PackageJson['exports'], { bundles, outputDir, cwd, addTypes, expand, packageType }: {
|
|
32
|
+
bundles: BundleType[];
|
|
39
33
|
outputDir: string;
|
|
40
34
|
cwd: string;
|
|
41
35
|
addTypes?: boolean;
|
|
42
|
-
isFlat?: boolean;
|
|
43
36
|
expand?: boolean;
|
|
44
37
|
packageType?: 'module' | 'commonjs';
|
|
45
38
|
}): Promise<{
|
|
@@ -58,42 +51,32 @@ export declare function createPackageExports(packageExports: import('../cli/pack
|
|
|
58
51
|
* unchanged, since the `imports` field commonly aliases dependencies.
|
|
59
52
|
* @param {import('../cli/packageJson').PackageJson['imports']} packageImports
|
|
60
53
|
* @param {Object} options
|
|
61
|
-
* @param {
|
|
54
|
+
* @param {BundleType[]} options.bundles
|
|
62
55
|
* @param {string} options.cwd
|
|
63
56
|
* @param {string} [options.outputDir] - Used to verify non-source passthrough paths exist in the build output.
|
|
64
57
|
* @param {boolean} [options.addTypes]
|
|
65
|
-
* @param {boolean} [options.isFlat]
|
|
66
58
|
* @param {boolean} [options.expand] - Whether to enumerate glob patterns into concrete entries.
|
|
67
59
|
* @param {'module' | 'commonjs'} [options.packageType]
|
|
68
60
|
* @returns {Promise<import('../cli/packageJson').PackageJson.Imports | undefined>}
|
|
69
61
|
*/
|
|
70
|
-
export declare function createPackageImports(packageImports: import('../cli/packageJson').PackageJson['imports'], { bundles, cwd, outputDir, addTypes,
|
|
71
|
-
bundles:
|
|
72
|
-
type: BundleType;
|
|
73
|
-
dir: string;
|
|
74
|
-
}[];
|
|
62
|
+
export declare function createPackageImports(packageImports: import('../cli/packageJson').PackageJson['imports'], { bundles, cwd, outputDir, addTypes, expand, packageType }: {
|
|
63
|
+
bundles: BundleType[];
|
|
75
64
|
cwd: string;
|
|
76
65
|
outputDir?: string;
|
|
77
66
|
addTypes?: boolean;
|
|
78
|
-
isFlat?: boolean;
|
|
79
67
|
expand?: boolean;
|
|
80
68
|
packageType?: 'module' | 'commonjs';
|
|
81
69
|
}): Promise<import('../cli/packageJson').PackageJson.Imports | undefined>;
|
|
82
70
|
/**
|
|
83
71
|
* @param {import('../cli/packageJson').PackageJson['bin']} bin
|
|
84
72
|
* @param {Object} options
|
|
85
|
-
* @param {
|
|
73
|
+
* @param {BundleType[]} options.bundles
|
|
86
74
|
* @param {string} options.cwd
|
|
87
|
-
* @param {boolean} [options.isFlat]
|
|
88
75
|
* @param {'module' | 'commonjs'} [options.packageType]
|
|
89
76
|
*/
|
|
90
|
-
export declare function createPackageBin(bin: import('../cli/packageJson').PackageJson['bin'], { bundles, cwd,
|
|
91
|
-
bundles:
|
|
92
|
-
type: BundleType;
|
|
93
|
-
dir: string;
|
|
94
|
-
}[];
|
|
77
|
+
export declare function createPackageBin(bin: import('../cli/packageJson').PackageJson['bin'], { bundles, cwd, packageType }: {
|
|
78
|
+
bundles: BundleType[];
|
|
95
79
|
cwd: string;
|
|
96
|
-
isFlat?: boolean;
|
|
97
80
|
packageType?: 'module' | 'commonjs';
|
|
98
81
|
}): Promise<string | Record<string, string> | undefined>;
|
|
99
82
|
/**
|
|
@@ -22,19 +22,14 @@ export declare function copyDeclarations(sourceDirectory: string, destinationDir
|
|
|
22
22
|
* @param {Object} param0
|
|
23
23
|
* @param {string} param0.inputDir
|
|
24
24
|
* @param {string} param0.buildDir
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {boolean} [param0.isFlat]
|
|
25
|
+
* @param {import('../utils/build.mjs').BundleType[]} param0.bundles
|
|
27
26
|
* @param {'module' | 'commonjs'} [param0.packageType]
|
|
28
27
|
* @returns
|
|
29
28
|
*/
|
|
30
|
-
export declare function moveAndTransformDeclarations({ inputDir, buildDir, bundles,
|
|
29
|
+
export declare function moveAndTransformDeclarations({ inputDir, buildDir, bundles, packageType }: {
|
|
31
30
|
inputDir: string;
|
|
32
31
|
buildDir: string;
|
|
33
|
-
bundles:
|
|
34
|
-
type: import('../utils/build.mjs').BundleType;
|
|
35
|
-
dir: string;
|
|
36
|
-
}[];
|
|
37
|
-
isFlat?: boolean;
|
|
32
|
+
bundles: import('../utils/build.mjs').BundleType[];
|
|
38
33
|
packageType?: 'module' | 'commonjs';
|
|
39
34
|
}): Promise<void>;
|
|
40
35
|
/**
|
|
@@ -43,9 +38,8 @@ export declare function moveAndTransformDeclarations({ inputDir, buildDir, bundl
|
|
|
43
38
|
* After copying, babel transformations are applied to the copied files because they need to be alongside the actual js files for proper resolution.
|
|
44
39
|
*
|
|
45
40
|
* @param {Object} param0
|
|
46
|
-
* @param {boolean} [param0.isFlat = false] - Whether to place generated declaration files in a flattened directory.
|
|
47
41
|
* @param {boolean} [param0.verbose = false] - Whether to log additional information while generating and moving declaration files.
|
|
48
|
-
* @param {
|
|
42
|
+
* @param {import('../utils/build.mjs').BundleType[]} param0.bundles - The bundles to create declarations for.
|
|
49
43
|
* @param {string} param0.srcDir - The source directory.
|
|
50
44
|
* @param {string} param0.buildDir - The build directory.
|
|
51
45
|
* @param {string} param0.cwd - The current working directory.
|
|
@@ -53,13 +47,9 @@ export declare function moveAndTransformDeclarations({ inputDir, buildDir, bundl
|
|
|
53
47
|
* @param {boolean} [param0.useTsgo=false] - Whether to build types using typescript native (tsgo).
|
|
54
48
|
* @param {'module' | 'commonjs'} [param0.packageType] - The package.json type field.
|
|
55
49
|
*/
|
|
56
|
-
export declare function createTypes({ bundles, srcDir, buildDir, cwd, skipTsc, useTsgo,
|
|
57
|
-
isFlat?: boolean;
|
|
50
|
+
export declare function createTypes({ bundles, srcDir, buildDir, cwd, skipTsc, useTsgo, packageType, verbose, }: {
|
|
58
51
|
verbose?: boolean;
|
|
59
|
-
bundles:
|
|
60
|
-
type: import('../utils/build.mjs').BundleType;
|
|
61
|
-
dir: string;
|
|
62
|
-
}[];
|
|
52
|
+
bundles: import('../utils/build.mjs').BundleType[];
|
|
63
53
|
srcDir: string;
|
|
64
54
|
buildDir: string;
|
|
65
55
|
cwd: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-code-infra",
|
|
3
|
-
"version": "0.0.4-canary.
|
|
3
|
+
"version": "0.0.4-canary.69",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "Infra scripts and configs to be used across MUI repos.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"babel-plugin-transform-remove-imports": "^1.8.1",
|
|
84
84
|
"chalk": "^5.6.2",
|
|
85
85
|
"clipboardy": "^5.3.1",
|
|
86
|
-
"content-type": "^
|
|
86
|
+
"content-type": "^2.0.0",
|
|
87
87
|
"env-ci": "^11.2.0",
|
|
88
88
|
"es-toolkit": "^1.46.1",
|
|
89
89
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -135,8 +135,8 @@
|
|
|
135
135
|
"unist-util-visit": "^5.1.0",
|
|
136
136
|
"yaml": "^2.9.0",
|
|
137
137
|
"yargs": "^18.0.0",
|
|
138
|
-
"@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.36",
|
|
139
138
|
"@mui/internal-babel-plugin-display-name": "1.0.4-canary.20",
|
|
139
|
+
"@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.36",
|
|
140
140
|
"@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.27"
|
|
141
141
|
},
|
|
142
142
|
"peerDependencies": {
|
|
@@ -158,7 +158,6 @@
|
|
|
158
158
|
"@octokit/types": "16.0.0",
|
|
159
159
|
"@types/babel__core": "7.20.5",
|
|
160
160
|
"@types/babel__preset-env": "7.10.0",
|
|
161
|
-
"@types/content-type": "1.1.9",
|
|
162
161
|
"@types/env-ci": "3.1.4",
|
|
163
162
|
"@types/eslint-plugin-jsx-a11y": "6.10.1",
|
|
164
163
|
"@types/estree": "1.0.9",
|
|
@@ -187,7 +186,7 @@
|
|
|
187
186
|
"publishConfig": {
|
|
188
187
|
"access": "public"
|
|
189
188
|
},
|
|
190
|
-
"gitSha": "
|
|
189
|
+
"gitSha": "8fa07fb68e1c06938b589899e0445b5daf8d26f0",
|
|
191
190
|
"scripts": {
|
|
192
191
|
"build": "tsgo -p tsconfig.build.json",
|
|
193
192
|
"typescript": "tsgo -noEmit",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { workerData, parentPort } from 'node:worker_threads';
|
|
2
2
|
import { parse } from 'node-html-parser';
|
|
3
|
-
import
|
|
3
|
+
import { parse as parseContentType } from 'content-type';
|
|
4
4
|
import { HtmlValidate, StaticConfigLoader, staticResolver } from 'html-validate';
|
|
5
5
|
import { unified } from 'unified';
|
|
6
6
|
import remarkParse from 'remark-parse';
|
|
@@ -111,7 +111,7 @@ let type = 'text/html';
|
|
|
111
111
|
|
|
112
112
|
if (contentTypeHeader) {
|
|
113
113
|
try {
|
|
114
|
-
const parsed =
|
|
114
|
+
const parsed = parseContentType(contentTypeHeader);
|
|
115
115
|
type = parsed.type;
|
|
116
116
|
} catch {
|
|
117
117
|
// invalid content-type, default to text/html
|
package/src/cli/cmdBuild.mjs
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
* @property {string[]} [copy] - Files/Directories to be copied. Can be a glob pattern.
|
|
32
32
|
* @property {boolean} [enableReactCompiler] - Whether to use the React compiler.
|
|
33
33
|
* @property {boolean} [tsgo] - Whether to build types using typescript native (tsgo).
|
|
34
|
-
* @property {boolean} [flat] -
|
|
34
|
+
* @property {boolean} [flat] - Deprecated no-op; flat builds are always used.
|
|
35
35
|
* @property {boolean} expand - Whether to enumerate glob patterns in exports/imports into concrete entries.
|
|
36
36
|
*/
|
|
37
37
|
|
|
@@ -47,13 +47,12 @@ const validBundles = [
|
|
|
47
47
|
* @param {string} options.name - The name of the package.
|
|
48
48
|
* @param {string} options.version - The version of the package.
|
|
49
49
|
* @param {string} options.license - The license of the package.
|
|
50
|
-
* @param {boolean} options.isFlat - Whether the build is flat structure.
|
|
51
50
|
* @param {'module' | 'commonjs'} options.packageType - The package.json type field.
|
|
52
51
|
* @param {import('../utils/build.mjs').BundleType} options.bundle
|
|
53
52
|
* @param {string} options.outputDir
|
|
54
53
|
*/
|
|
55
|
-
async function addLicense({ name, version, license, bundle, outputDir,
|
|
56
|
-
const outExtension = getOutExtension(bundle, {
|
|
54
|
+
async function addLicense({ name, version, license, bundle, outputDir, packageType }) {
|
|
55
|
+
const outExtension = getOutExtension(bundle, { packageType });
|
|
57
56
|
const file = path.join(outputDir, `index${outExtension}`);
|
|
58
57
|
if (
|
|
59
58
|
!(await fs.stat(file).then(
|
|
@@ -82,11 +81,10 @@ ${content}`,
|
|
|
82
81
|
/**
|
|
83
82
|
* @param {Object} param0
|
|
84
83
|
* @param {import('./packageJson').PackageJson} param0.packageJson - The package.json content.
|
|
85
|
-
* @param {
|
|
84
|
+
* @param {import('../utils/build.mjs').BundleType[]} param0.bundles
|
|
86
85
|
* @param {string} param0.outputDir
|
|
87
86
|
* @param {string} param0.cwd
|
|
88
87
|
* @param {boolean} param0.addTypes - Whether to add type declarations for the package.
|
|
89
|
-
* @param {boolean} param0.isFlat - Whether the build is flat structure.
|
|
90
88
|
* @param {boolean} [param0.expand] - Whether to enumerate glob patterns into concrete entries.
|
|
91
89
|
* @param {'module' | 'commonjs'} param0.packageType - The package.json type field.
|
|
92
90
|
*/
|
|
@@ -96,7 +94,6 @@ async function writePackageJson({
|
|
|
96
94
|
outputDir,
|
|
97
95
|
cwd,
|
|
98
96
|
addTypes = false,
|
|
99
|
-
isFlat = false,
|
|
100
97
|
expand = true,
|
|
101
98
|
packageType,
|
|
102
99
|
}) {
|
|
@@ -120,7 +117,6 @@ async function writePackageJson({
|
|
|
120
117
|
outputDir,
|
|
121
118
|
cwd,
|
|
122
119
|
addTypes,
|
|
123
|
-
isFlat,
|
|
124
120
|
expand,
|
|
125
121
|
packageType: resolvedPackageType,
|
|
126
122
|
}),
|
|
@@ -130,7 +126,6 @@ async function writePackageJson({
|
|
|
130
126
|
cwd,
|
|
131
127
|
outputDir,
|
|
132
128
|
addTypes,
|
|
133
|
-
isFlat,
|
|
134
129
|
expand,
|
|
135
130
|
packageType: resolvedPackageType,
|
|
136
131
|
})
|
|
@@ -151,7 +146,6 @@ async function writePackageJson({
|
|
|
151
146
|
const bin = await createPackageBin(originalBin, {
|
|
152
147
|
bundles,
|
|
153
148
|
cwd,
|
|
154
|
-
isFlat,
|
|
155
149
|
packageType: resolvedPackageType,
|
|
156
150
|
});
|
|
157
151
|
if (bin) {
|
|
@@ -241,9 +235,11 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
241
235
|
})
|
|
242
236
|
.option('flat', {
|
|
243
237
|
type: 'boolean',
|
|
244
|
-
|
|
238
|
+
deprecated:
|
|
239
|
+
'Flat builds are now always used; this flag is a no-op and will be removed in a future release.',
|
|
240
|
+
default: true,
|
|
245
241
|
description:
|
|
246
|
-
'
|
|
242
|
+
'@deprecated Flat builds are always used now. The package is always built in a flat structure without subdirectories for each module type.',
|
|
247
243
|
})
|
|
248
244
|
.option('expand', {
|
|
249
245
|
type: 'boolean',
|
|
@@ -256,7 +252,6 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
256
252
|
const {
|
|
257
253
|
bundle: bundles,
|
|
258
254
|
hasLargeFiles,
|
|
259
|
-
skipBundlePackageJson,
|
|
260
255
|
verbose = false,
|
|
261
256
|
ignore: extraIgnores,
|
|
262
257
|
buildTypes,
|
|
@@ -277,9 +272,6 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
277
272
|
const packageType = packageJson.type === 'module' ? 'module' : 'commonjs';
|
|
278
273
|
|
|
279
274
|
console.log(`Selected output directory: "${buildDirBase}"`);
|
|
280
|
-
if (args.flat) {
|
|
281
|
-
console.log('Building package in flat structure.');
|
|
282
|
-
}
|
|
283
275
|
|
|
284
276
|
await fs.rm(buildDir, { recursive: true, force: true });
|
|
285
277
|
|
|
@@ -304,15 +296,6 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
304
296
|
}
|
|
305
297
|
|
|
306
298
|
const { build: babelBuild, cjsCopy } = await import('../utils/babel.mjs');
|
|
307
|
-
const relativeOutDirs = !args.flat
|
|
308
|
-
? {
|
|
309
|
-
cjs: '.',
|
|
310
|
-
esm: 'esm',
|
|
311
|
-
}
|
|
312
|
-
: {
|
|
313
|
-
cjs: '.',
|
|
314
|
-
esm: '.',
|
|
315
|
-
};
|
|
316
299
|
const sourceDir = path.join(cwd, 'src');
|
|
317
300
|
const reactVersion =
|
|
318
301
|
semver.minVersion(packageJson.peerDependencies?.react || '')?.version ?? 'latest';
|
|
@@ -328,13 +311,10 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
328
311
|
await Promise.all(
|
|
329
312
|
bundles.map(async (bundle) => {
|
|
330
313
|
const outExtension = getOutExtension(bundle, {
|
|
331
|
-
isFlat: !!args.flat,
|
|
332
314
|
isType: false,
|
|
333
315
|
packageType,
|
|
334
316
|
});
|
|
335
|
-
|
|
336
|
-
const outputDir = path.join(buildDir, relativeOutDir);
|
|
337
|
-
await fs.mkdir(outputDir, { recursive: true });
|
|
317
|
+
await fs.mkdir(buildDir, { recursive: true });
|
|
338
318
|
|
|
339
319
|
const promises = [];
|
|
340
320
|
|
|
@@ -342,7 +322,7 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
342
322
|
babelBuild({
|
|
343
323
|
cwd,
|
|
344
324
|
sourceDir,
|
|
345
|
-
outDir:
|
|
325
|
+
outDir: buildDir,
|
|
346
326
|
babelRuntimeVersion,
|
|
347
327
|
hasLargeFiles,
|
|
348
328
|
bundle,
|
|
@@ -362,61 +342,28 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
362
342
|
}),
|
|
363
343
|
);
|
|
364
344
|
|
|
365
|
-
if (buildDir !== outputDir && !skipBundlePackageJson && !args.flat) {
|
|
366
|
-
// @TODO - Not needed if the output extension is .mjs. Remove this before PR merge.
|
|
367
|
-
promises.push(
|
|
368
|
-
fs.writeFile(
|
|
369
|
-
path.join(outputDir, 'package.json'),
|
|
370
|
-
JSON.stringify({
|
|
371
|
-
type: bundle === 'esm' ? 'module' : 'commonjs',
|
|
372
|
-
sideEffects: packageJson.sideEffects ?? false,
|
|
373
|
-
}),
|
|
374
|
-
),
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
if (!args.flat) {
|
|
379
|
-
// cjs for reexporting from commons only modules.
|
|
380
|
-
// @NOTE: If we need to rely more on this we can think about setting up
|
|
381
|
-
// a separate commonjs => commonjs build for .cjs files to .cjs
|
|
382
|
-
// `--extensions-.cjs --out-file-extension .cjs`
|
|
383
|
-
promises.push(cjsCopy({ from: sourceDir, to: outputDir }));
|
|
384
|
-
}
|
|
385
|
-
|
|
386
345
|
await Promise.all(promises);
|
|
387
346
|
await addLicense({
|
|
388
347
|
bundle,
|
|
389
348
|
license: packageJson.license,
|
|
390
349
|
name: packageJson.name,
|
|
391
350
|
version: packageJson.version,
|
|
392
|
-
outputDir,
|
|
393
|
-
isFlat: !!args.flat,
|
|
351
|
+
outputDir: buildDir,
|
|
394
352
|
packageType,
|
|
395
353
|
});
|
|
396
354
|
}),
|
|
397
355
|
);
|
|
398
356
|
|
|
399
|
-
|
|
400
|
-
await cjsCopy({ from: sourceDir, to: buildDir });
|
|
401
|
-
}
|
|
357
|
+
await cjsCopy({ from: sourceDir, to: buildDir });
|
|
402
358
|
// js build end
|
|
403
359
|
|
|
404
360
|
if (buildTypes) {
|
|
405
361
|
const tsMod = await import('../utils/typescript.mjs');
|
|
406
|
-
/**
|
|
407
|
-
* @type {{type: import('../utils/build.mjs').BundleType, dir: string}[]};
|
|
408
|
-
*/
|
|
409
|
-
const bundleMap = bundles.map((type) => ({
|
|
410
|
-
type,
|
|
411
|
-
dir: relativeOutDirs[type],
|
|
412
|
-
}));
|
|
413
|
-
|
|
414
362
|
await tsMod.createTypes({
|
|
415
|
-
bundles
|
|
363
|
+
bundles,
|
|
416
364
|
srcDir: sourceDir,
|
|
417
365
|
cwd,
|
|
418
366
|
skipTsc,
|
|
419
|
-
isFlat: !!args.flat,
|
|
420
367
|
buildDir,
|
|
421
368
|
useTsgo,
|
|
422
369
|
packageType,
|
|
@@ -431,13 +378,9 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
431
378
|
await writePackageJson({
|
|
432
379
|
cwd,
|
|
433
380
|
packageJson,
|
|
434
|
-
bundles
|
|
435
|
-
type,
|
|
436
|
-
dir: relativeOutDirs[type],
|
|
437
|
-
})),
|
|
381
|
+
bundles,
|
|
438
382
|
outputDir: buildDir,
|
|
439
383
|
addTypes: buildTypes,
|
|
440
|
-
isFlat: !!args.flat,
|
|
441
384
|
expand: args.expand,
|
|
442
385
|
packageType,
|
|
443
386
|
});
|
package/src/utils/build.mjs
CHANGED
|
@@ -40,16 +40,12 @@ export const BASE_IGNORES = [
|
|
|
40
40
|
* @param {BundleType} bundle
|
|
41
41
|
* @param {Object} [options]
|
|
42
42
|
* @param {boolean} [options.isType=false] - Whether to get the extension for type declaration files.
|
|
43
|
-
* @param {boolean} [options.isFlat=false] - Whether to get the extension for a flat build structure.
|
|
44
43
|
* @param {'module' | 'commonjs'} [options.packageType='commonjs'] - The package.json type field.
|
|
45
44
|
* @returns {string}
|
|
46
45
|
*/
|
|
47
46
|
export function getOutExtension(bundle, options = {}) {
|
|
48
|
-
const { isType = false,
|
|
47
|
+
const { isType = false, packageType = 'commonjs' } = options;
|
|
49
48
|
const normalizedPackageType = packageType === 'module' ? 'module' : 'commonjs';
|
|
50
|
-
if (!isFlat) {
|
|
51
|
-
return isType ? '.d.ts' : '.js';
|
|
52
|
-
}
|
|
53
49
|
if (isType) {
|
|
54
50
|
if (normalizedPackageType === 'module') {
|
|
55
51
|
return bundle === 'esm' ? '.d.ts' : '.d.cts';
|
|
@@ -590,43 +586,33 @@ async function expandExportGlobs(originalExports, cwd) {
|
|
|
590
586
|
/**
|
|
591
587
|
* Builds the per-bundle metadata (output extensions + the `import`/`require`
|
|
592
588
|
* condition each bundle maps to).
|
|
593
|
-
* @param {
|
|
594
|
-
* @param {boolean} isFlat
|
|
589
|
+
* @param {BundleType[]} bundles
|
|
595
590
|
* @param {'module' | 'commonjs'} packageType
|
|
596
591
|
* @returns {BundleMeta[]}
|
|
597
592
|
*/
|
|
598
|
-
function createBundleMetas(bundles,
|
|
599
|
-
return bundles.map((
|
|
593
|
+
function createBundleMetas(bundles, packageType) {
|
|
594
|
+
return bundles.map((type) => ({
|
|
600
595
|
type,
|
|
601
|
-
dir,
|
|
596
|
+
dir: '.',
|
|
602
597
|
condition: type === 'cjs' ? 'require' : 'import',
|
|
603
|
-
outExtension: getOutExtension(type, {
|
|
604
|
-
typeOutExtension: getOutExtension(type, {
|
|
598
|
+
outExtension: getOutExtension(type, { packageType }),
|
|
599
|
+
typeOutExtension: getOutExtension(type, { isType: true, packageType }),
|
|
605
600
|
}));
|
|
606
601
|
}
|
|
607
602
|
|
|
608
603
|
/**
|
|
609
604
|
* @param {import('../cli/packageJson').PackageJson['exports']} packageExports
|
|
610
605
|
* @param {Object} options
|
|
611
|
-
* @param {
|
|
606
|
+
* @param {BundleType[]} options.bundles
|
|
612
607
|
* @param {string} options.outputDir
|
|
613
608
|
* @param {string} options.cwd
|
|
614
609
|
* @param {boolean} [options.addTypes]
|
|
615
|
-
* @param {boolean} [options.isFlat]
|
|
616
610
|
* @param {boolean} [options.expand] - Whether to enumerate glob patterns into concrete entries.
|
|
617
611
|
* @param {'module' | 'commonjs'} [options.packageType]
|
|
618
612
|
*/
|
|
619
613
|
export async function createPackageExports(
|
|
620
614
|
packageExports,
|
|
621
|
-
{
|
|
622
|
-
bundles,
|
|
623
|
-
outputDir,
|
|
624
|
-
cwd,
|
|
625
|
-
addTypes = false,
|
|
626
|
-
isFlat = false,
|
|
627
|
-
expand = true,
|
|
628
|
-
packageType = 'commonjs',
|
|
629
|
-
},
|
|
615
|
+
{ bundles, outputDir, cwd, addTypes = false, expand = true, packageType = 'commonjs' },
|
|
630
616
|
) {
|
|
631
617
|
const resolvedPackageType = packageType === 'module' ? 'module' : 'commonjs';
|
|
632
618
|
/**
|
|
@@ -637,7 +623,7 @@ export async function createPackageExports(
|
|
|
637
623
|
? { '.': packageExports }
|
|
638
624
|
: packageExports || {};
|
|
639
625
|
const originalExports = expand ? await expandExportGlobs(rawExports, cwd) : rawExports;
|
|
640
|
-
const bundleMetas = createBundleMetas(bundles,
|
|
626
|
+
const bundleMetas = createBundleMetas(bundles, resolvedPackageType);
|
|
641
627
|
/**
|
|
642
628
|
* @type {import('../cli/packageJson').PackageJson.ExportConditions}
|
|
643
629
|
*/
|
|
@@ -695,12 +681,6 @@ export async function createPackageExports(
|
|
|
695
681
|
}),
|
|
696
682
|
);
|
|
697
683
|
|
|
698
|
-
bundles.forEach(({ dir }) => {
|
|
699
|
-
if (dir !== '.') {
|
|
700
|
-
newExports[`./${dir}`] = null;
|
|
701
|
-
}
|
|
702
|
-
});
|
|
703
|
-
|
|
704
684
|
finalizeConditions(newExports, addTypes, 'export');
|
|
705
685
|
|
|
706
686
|
return result;
|
|
@@ -717,26 +697,17 @@ export async function createPackageExports(
|
|
|
717
697
|
* unchanged, since the `imports` field commonly aliases dependencies.
|
|
718
698
|
* @param {import('../cli/packageJson').PackageJson['imports']} packageImports
|
|
719
699
|
* @param {Object} options
|
|
720
|
-
* @param {
|
|
700
|
+
* @param {BundleType[]} options.bundles
|
|
721
701
|
* @param {string} options.cwd
|
|
722
702
|
* @param {string} [options.outputDir] - Used to verify non-source passthrough paths exist in the build output.
|
|
723
703
|
* @param {boolean} [options.addTypes]
|
|
724
|
-
* @param {boolean} [options.isFlat]
|
|
725
704
|
* @param {boolean} [options.expand] - Whether to enumerate glob patterns into concrete entries.
|
|
726
705
|
* @param {'module' | 'commonjs'} [options.packageType]
|
|
727
706
|
* @returns {Promise<import('../cli/packageJson').PackageJson.Imports | undefined>}
|
|
728
707
|
*/
|
|
729
708
|
export async function createPackageImports(
|
|
730
709
|
packageImports,
|
|
731
|
-
{
|
|
732
|
-
bundles,
|
|
733
|
-
cwd,
|
|
734
|
-
outputDir,
|
|
735
|
-
addTypes = false,
|
|
736
|
-
isFlat = false,
|
|
737
|
-
expand = true,
|
|
738
|
-
packageType = 'commonjs',
|
|
739
|
-
},
|
|
710
|
+
{ bundles, cwd, outputDir, addTypes = false, expand = true, packageType = 'commonjs' },
|
|
740
711
|
) {
|
|
741
712
|
if (!packageImports || Object.keys(packageImports).length === 0) {
|
|
742
713
|
return undefined;
|
|
@@ -755,7 +726,7 @@ export async function createPackageImports(
|
|
|
755
726
|
packageImports
|
|
756
727
|
);
|
|
757
728
|
const originalImports = expand ? await expandExportGlobs(rawImports, cwd) : rawImports;
|
|
758
|
-
const bundleMetas = createBundleMetas(bundles,
|
|
729
|
+
const bundleMetas = createBundleMetas(bundles, resolvedPackageType);
|
|
759
730
|
|
|
760
731
|
const newImports = await rewriteConditionsMap(originalImports, {
|
|
761
732
|
bundleMetas,
|
|
@@ -773,19 +744,17 @@ export async function createPackageImports(
|
|
|
773
744
|
/**
|
|
774
745
|
* @param {import('../cli/packageJson').PackageJson['bin']} bin
|
|
775
746
|
* @param {Object} options
|
|
776
|
-
* @param {
|
|
747
|
+
* @param {BundleType[]} options.bundles
|
|
777
748
|
* @param {string} options.cwd
|
|
778
|
-
* @param {boolean} [options.isFlat]
|
|
779
749
|
* @param {'module' | 'commonjs'} [options.packageType]
|
|
780
750
|
*/
|
|
781
|
-
export async function createPackageBin(bin, { bundles, cwd,
|
|
751
|
+
export async function createPackageBin(bin, { bundles, cwd, packageType }) {
|
|
782
752
|
if (!bin) {
|
|
783
753
|
return undefined;
|
|
784
754
|
}
|
|
785
755
|
// Use mjs files if present, otherwise fallback to the first bundle type
|
|
786
|
-
const bundleToUse = bundles.find((
|
|
787
|
-
const binOutExtension = getOutExtension(bundleToUse
|
|
788
|
-
isFlat,
|
|
756
|
+
const bundleToUse = bundles.find((type) => type === 'esm') || bundles[0];
|
|
757
|
+
const binOutExtension = getOutExtension(bundleToUse, {
|
|
789
758
|
packageType,
|
|
790
759
|
});
|
|
791
760
|
|
|
@@ -813,7 +782,7 @@ export async function createPackageBin(bin, { bundles, cwd, isFlat = false, pack
|
|
|
813
782
|
}
|
|
814
783
|
const ext = path.extname(binPath);
|
|
815
784
|
newBin[binKey] = binPath
|
|
816
|
-
.replace(/(\.\/)?src\//,
|
|
785
|
+
.replace(/(\.\/)?src\//, './')
|
|
817
786
|
.replace(new RegExp(`\\${ext}$`), binOutExtension);
|
|
818
787
|
}
|
|
819
788
|
// eslint-disable-next-line no-underscore-dangle
|