@mui/internal-code-infra 0.0.4-canary.56 → 0.0.4-canary.58

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.
@@ -13,6 +13,7 @@ export type Args = {
13
13
  enableReactCompiler?: boolean;
14
14
  tsgo?: boolean;
15
15
  flat?: boolean;
16
+ expand: boolean;
16
17
  };
17
18
  declare const _default: import('yargs').CommandModule<{}, Args>;
18
19
  export default _default;
@@ -1,7 +1,12 @@
1
1
  export type BundleType = 'esm' | 'cjs';
2
- /**
3
- * @typedef {'esm' | 'cjs'} BundleType
4
- */
2
+ export type BundleMeta = {
3
+ type: BundleType;
4
+ dir: string;
5
+ condition: 'import' | 'require';
6
+ outExtension: string;
7
+ typeOutExtension: string;
8
+ };
9
+ export declare const BASE_IGNORES: string[];
5
10
  /**
6
11
  * @param {BundleType} bundle
7
12
  * @param {Object} [options]
@@ -16,17 +21,17 @@ export declare function getOutExtension(bundle: BundleType, options?: {
16
21
  packageType?: 'module' | 'commonjs';
17
22
  }): string;
18
23
  /**
19
- * @param {Object} param0
20
- * @param {import('../cli/packageJson').PackageJson['exports']} param0.exports
21
- * @param {{type: BundleType; dir: string}[]} param0.bundles
22
- * @param {string} param0.outputDir
23
- * @param {string} param0.cwd
24
- * @param {boolean} [param0.addTypes]
25
- * @param {boolean} [param0.isFlat]
26
- * @param {'module' | 'commonjs'} [param0.packageType]
24
+ * @param {import('../cli/packageJson').PackageJson['exports']} packageExports
25
+ * @param {Object} options
26
+ * @param {{type: BundleType; dir: string}[]} options.bundles
27
+ * @param {string} options.outputDir
28
+ * @param {string} options.cwd
29
+ * @param {boolean} [options.addTypes]
30
+ * @param {boolean} [options.isFlat]
31
+ * @param {boolean} [options.expand] - Whether to enumerate glob patterns into concrete entries.
32
+ * @param {'module' | 'commonjs'} [options.packageType]
27
33
  */
28
- export declare function createPackageExports({ exports: packageExports, bundles, outputDir, cwd, addTypes, isFlat, packageType, }: {
29
- exports: import('../cli/packageJson').PackageJson['exports'];
34
+ export declare function createPackageExports(packageExports: import('../cli/packageJson').PackageJson['exports'], { bundles, outputDir, cwd, addTypes, isFlat, expand, packageType, }: {
30
35
  bundles: {
31
36
  type: BundleType;
32
37
  dir: string;
@@ -35,6 +40,7 @@ export declare function createPackageExports({ exports: packageExports, bundles,
35
40
  cwd: string;
36
41
  addTypes?: boolean;
37
42
  isFlat?: boolean;
43
+ expand?: boolean;
38
44
  packageType?: 'module' | 'commonjs';
39
45
  }): Promise<{
40
46
  main?: string;
@@ -42,15 +48,46 @@ export declare function createPackageExports({ exports: packageExports, bundles,
42
48
  exports: import('../cli/packageJson').PackageJson.ExportConditions;
43
49
  }>;
44
50
  /**
45
- * @param {Object} param0
46
- * @param {import('../cli/packageJson').PackageJson['bin']} param0.bin
47
- * @param {{type: BundleType; dir: string}[]} param0.bundles
48
- * @param {string} param0.cwd
49
- * @param {boolean} [param0.isFlat]
50
- * @param {'module' | 'commonjs'} [param0.packageType]
51
+ * Generates the package.json `imports` field for the built package, rewriting
52
+ * internal subpath imports (keys starting with `#`) that point at source files
53
+ * into their built equivalents with `import`/`require`/`types` conditions.
54
+ *
55
+ * Mirrors {@link createPackageExports} but without the `.` / `package.json` /
56
+ * `main` / `types` index handling that only applies to public exports. Entries
57
+ * that resolve to bare specifiers (e.g. an external package) are passed through
58
+ * unchanged, since the `imports` field commonly aliases dependencies.
59
+ * @param {import('../cli/packageJson').PackageJson['imports']} packageImports
60
+ * @param {Object} options
61
+ * @param {{type: BundleType; dir: string}[]} options.bundles
62
+ * @param {string} options.cwd
63
+ * @param {string} [options.outputDir] - Used to verify non-source passthrough paths exist in the build output.
64
+ * @param {boolean} [options.addTypes]
65
+ * @param {boolean} [options.isFlat]
66
+ * @param {boolean} [options.expand] - Whether to enumerate glob patterns into concrete entries.
67
+ * @param {'module' | 'commonjs'} [options.packageType]
68
+ * @returns {Promise<import('../cli/packageJson').PackageJson.Imports | undefined>}
51
69
  */
52
- export declare function createPackageBin({ bin, bundles, cwd, isFlat, packageType }: {
53
- bin: import('../cli/packageJson').PackageJson['bin'];
70
+ export declare function createPackageImports(packageImports: import('../cli/packageJson').PackageJson['imports'], { bundles, cwd, outputDir, addTypes, isFlat, expand, packageType, }: {
71
+ bundles: {
72
+ type: BundleType;
73
+ dir: string;
74
+ }[];
75
+ cwd: string;
76
+ outputDir?: string;
77
+ addTypes?: boolean;
78
+ isFlat?: boolean;
79
+ expand?: boolean;
80
+ packageType?: 'module' | 'commonjs';
81
+ }): Promise<import('../cli/packageJson').PackageJson.Imports | undefined>;
82
+ /**
83
+ * @param {import('../cli/packageJson').PackageJson['bin']} bin
84
+ * @param {Object} options
85
+ * @param {{type: BundleType; dir: string}[]} options.bundles
86
+ * @param {string} options.cwd
87
+ * @param {boolean} [options.isFlat]
88
+ * @param {'module' | 'commonjs'} [options.packageType]
89
+ */
90
+ export declare function createPackageBin(bin: import('../cli/packageJson').PackageJson['bin'], { bundles, cwd, isFlat, packageType }: {
54
91
  bundles: {
55
92
  type: BundleType;
56
93
  dir: string;
@@ -84,7 +121,6 @@ export declare function markFn<F extends () => Promise<any>>(label: string, fn:
84
121
  * @param {string} label
85
122
  */
86
123
  export declare function measureFn(label: string): PerformanceMeasure;
87
- export declare const BASE_IGNORES: string[];
88
124
  /**
89
125
  * A utility to map a function over an array of items in a worker pool.
90
126
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-code-infra",
3
- "version": "0.0.4-canary.56",
3
+ "version": "0.0.4-canary.58",
4
4
  "author": "MUI Team",
5
5
  "description": "Infra scripts and configs to be used across MUI repos.",
6
6
  "license": "MIT",
@@ -139,9 +139,9 @@
139
139
  "unified-lint-rule": "^3.0.1",
140
140
  "unist-util-visit": "^5.1.0",
141
141
  "yargs": "^18.0.0",
142
- "@mui/internal-babel-plugin-display-name": "1.0.4-canary.20",
142
+ "@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.27",
143
143
  "@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.36",
144
- "@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.27"
144
+ "@mui/internal-babel-plugin-display-name": "1.0.4-canary.20"
145
145
  },
146
146
  "peerDependencies": {
147
147
  "@next/eslint-plugin-next": "*",
@@ -191,7 +191,7 @@
191
191
  "publishConfig": {
192
192
  "access": "public"
193
193
  },
194
- "gitSha": "c0380f22916148bebba5dee261c1a2a3a9211a5e",
194
+ "gitSha": "bb17bc0e20f7110beb4315d5ddd54d9b83213043",
195
195
  "scripts": {
196
196
  "build": "tsgo -p tsconfig.build.json",
197
197
  "typescript": "tsgo -noEmit",
@@ -10,6 +10,7 @@ import * as semver from 'semver';
10
10
  import {
11
11
  createPackageBin,
12
12
  createPackageExports,
13
+ createPackageImports,
13
14
  getOutExtension,
14
15
  mapConcurrently,
15
16
  validatePkgJson,
@@ -31,6 +32,7 @@ import {
31
32
  * @property {boolean} [enableReactCompiler] - Whether to use the React compiler.
32
33
  * @property {boolean} [tsgo] - Whether to build types using typescript native (tsgo).
33
34
  * @property {boolean} [flat] - Builds the package in a flat structure without subdirectories for each module type.
35
+ * @property {boolean} expand - Whether to enumerate glob patterns in exports/imports into concrete entries.
34
36
  */
35
37
 
36
38
  const validBundles = [
@@ -85,6 +87,7 @@ ${content}`,
85
87
  * @param {string} param0.cwd
86
88
  * @param {boolean} param0.addTypes - Whether to add type declarations for the package.
87
89
  * @param {boolean} param0.isFlat - Whether the build is flat structure.
90
+ * @param {boolean} [param0.expand] - Whether to enumerate glob patterns into concrete entries.
88
91
  * @param {'module' | 'commonjs'} param0.packageType - The package.json type field.
89
92
  */
90
93
  async function writePackageJson({
@@ -94,36 +97,50 @@ async function writePackageJson({
94
97
  cwd,
95
98
  addTypes = false,
96
99
  isFlat = false,
100
+ expand = true,
97
101
  packageType,
98
102
  }) {
99
103
  delete packageJson.scripts;
100
104
  delete packageJson.publishConfig?.directory;
101
105
  delete packageJson.devDependencies;
102
- delete packageJson.imports;
103
106
 
104
107
  const resolvedPackageType = packageType || packageJson.type || 'commonjs';
105
108
  packageJson.type = resolvedPackageType;
106
109
 
107
110
  const originalExports = packageJson.exports;
108
111
  delete packageJson.exports;
112
+ const originalImports = packageJson.imports;
113
+ delete packageJson.imports;
109
114
  const originalBin = packageJson.bin;
110
115
  delete packageJson.bin;
111
116
 
112
- const {
113
- exports: packageExports,
114
- main,
115
- types,
116
- } = await createPackageExports({
117
- exports: originalExports,
118
- bundles,
119
- outputDir,
120
- cwd,
121
- addTypes,
122
- isFlat,
123
- packageType: resolvedPackageType,
124
- });
117
+ const [{ exports: packageExports, main, types }, packageImports] = await Promise.all([
118
+ createPackageExports(originalExports, {
119
+ bundles,
120
+ outputDir,
121
+ cwd,
122
+ addTypes,
123
+ isFlat,
124
+ expand,
125
+ packageType: resolvedPackageType,
126
+ }),
127
+ originalImports
128
+ ? createPackageImports(originalImports, {
129
+ bundles,
130
+ cwd,
131
+ outputDir,
132
+ addTypes,
133
+ isFlat,
134
+ expand,
135
+ packageType: resolvedPackageType,
136
+ })
137
+ : Promise.resolve(undefined),
138
+ ]);
125
139
 
126
140
  packageJson.exports = packageExports;
141
+ if (packageImports) {
142
+ packageJson.imports = packageImports;
143
+ }
127
144
  if (main) {
128
145
  packageJson.main = main;
129
146
  }
@@ -131,8 +148,7 @@ async function writePackageJson({
131
148
  packageJson.types = types;
132
149
  }
133
150
 
134
- const bin = await createPackageBin({
135
- bin: originalBin,
151
+ const bin = await createPackageBin(originalBin, {
136
152
  bundles,
137
153
  cwd,
138
154
  isFlat,
@@ -228,6 +244,12 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
228
244
  default: process.env.MUI_BUILD_FLAT === '1',
229
245
  description:
230
246
  'Builds the package in a flat structure without subdirectories for each module type.',
247
+ })
248
+ .option('expand', {
249
+ type: 'boolean',
250
+ default: true,
251
+ description:
252
+ 'Enumerate glob patterns in the package.json "exports"/"imports" into concrete entries. Use --no-expand to keep them as Node runtime subpath patterns.',
231
253
  });
232
254
  },
233
255
  async handler(args) {
@@ -416,6 +438,7 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
416
438
  outputDir: buildDir,
417
439
  addTypes: buildTypes,
418
440
  isFlat: !!args.flat,
441
+ expand: args.expand,
419
442
  packageType,
420
443
  });
421
444