@mui/internal-code-infra 0.0.4-canary.42 → 0.0.4-canary.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-code-infra",
3
- "version": "0.0.4-canary.42",
3
+ "version": "0.0.4-canary.43",
4
4
  "author": "MUI Team",
5
5
  "description": "Infra scripts and configs to be used across MUI repos.",
6
6
  "license": "MIT",
@@ -139,8 +139,8 @@
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-minify-errors": "2.0.8-canary.27",
143
142
  "@mui/internal-babel-plugin-display-name": "1.0.4-canary.19",
143
+ "@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.27",
144
144
  "@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.36"
145
145
  },
146
146
  "peerDependencies": {
@@ -191,7 +191,7 @@
191
191
  "publishConfig": {
192
192
  "access": "public"
193
193
  },
194
- "gitSha": "f2b7a9f6b2db57a03f2e16a5bb351f02a55c3e17",
194
+ "gitSha": "fbe2b3e2aa722425dc6eba1ef3806c1b2659bae0",
195
195
  "scripts": {
196
196
  "build": "tsgo -p tsconfig.build.json",
197
197
  "typescript": "tsgo -noEmit",
@@ -34,6 +34,20 @@ export function getOutExtension(bundle, options = {}) {
34
34
  return bundle === 'cjs' ? '.js' : '.mjs';
35
35
  }
36
36
 
37
+ /**
38
+ * Returns a new object with `import` first, `require` second, `default` last,
39
+ * and any other condition keys preserved in their original relative order in between.
40
+ * @param {Record<string, any>} conditions
41
+ * @returns {Record<string, any>}
42
+ */
43
+ function sortExportConditions(conditions) {
44
+ /** @type {Record<string, number | undefined>} */
45
+ const order = { import: 0, require: 1, default: 3 };
46
+ return Object.fromEntries(
47
+ Object.entries(conditions).sort(([a], [b]) => (order[a] ?? 2) - (order[b] ?? 2)),
48
+ );
49
+ }
50
+
37
51
  /**
38
52
  * @param {Object} param0
39
53
  * @param {NonNullable<import('../cli/packageJson').PackageJson.Exports>} param0.importPath
@@ -367,7 +381,8 @@ export async function createPackageExports({
367
381
  }
368
382
  });
369
383
 
370
- // Transform import/require to default/require pattern
384
+ // Rebuild condition objects with stable key order; bundles run in parallel so
385
+ // import/require insertion order would otherwise depend on Promise timing.
371
386
  Object.keys(newExports).forEach((key) => {
372
387
  const exportVal = newExports[key];
373
388
  if (Array.isArray(exportVal)) {
@@ -387,6 +402,8 @@ export async function createPackageExports({
387
402
  ? defaultExport.default
388
403
  : defaultExport;
389
404
  }
405
+
406
+ newExports[key] = sortExportConditions(exportVal);
390
407
  }
391
408
  });
392
409
 
@@ -15,6 +15,45 @@ async function createFile(filePath, contents = '') {
15
15
  }
16
16
 
17
17
  describe('createPackageExports', () => {
18
+ it('always puts import before require regardless of bundle array order', async () => {
19
+ const cwd = await makeTempDir();
20
+ const outputDir = path.join(cwd, 'build');
21
+
22
+ await Promise.all([
23
+ createFile(path.join(cwd, 'src/index.ts')),
24
+ createFile(path.join(cwd, 'src/feature.ts')),
25
+ createFile(path.join(outputDir, 'index.js')),
26
+ createFile(path.join(outputDir, 'index.cjs')),
27
+ createFile(path.join(outputDir, 'feature.js')),
28
+ createFile(path.join(outputDir, 'feature.cjs')),
29
+ ]);
30
+
31
+ // Pass cjs before esm to verify the key order is still 'import' then 'require'
32
+ const { exports: packageExports } = await createPackageExports({
33
+ exports: {
34
+ '.': './src/index.ts',
35
+ './feature': './src/feature.ts',
36
+ },
37
+ bundles: [
38
+ { type: 'cjs', dir: '.' },
39
+ { type: 'esm', dir: '.' },
40
+ ],
41
+ outputDir,
42
+ cwd,
43
+ isFlat: true,
44
+ packageType: 'module',
45
+ });
46
+
47
+ expect(Object.keys(/** @type {Record<string, unknown>} */ (packageExports['.']))).toEqual([
48
+ 'import',
49
+ 'require',
50
+ 'default',
51
+ ]);
52
+ expect(
53
+ Object.keys(/** @type {Record<string, unknown>} */ (packageExports['./feature'])),
54
+ ).toEqual(['import', 'require', 'default']);
55
+ });
56
+
18
57
  it('creates exports for a dual bundle module package', async () => {
19
58
  const cwd = await makeTempDir();
20
59
  const outputDir = path.join(cwd, 'build');