@mui/internal-code-infra 0.0.4-canary.41 → 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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @type {import('eslint').Rule.RuleModule}
3
+ */
4
+ declare const rule: import('eslint').Rule.RuleModule;
5
+ export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-code-infra",
3
- "version": "0.0.4-canary.41",
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",
@@ -140,8 +140,8 @@
140
140
  "unist-util-visit": "^5.1.0",
141
141
  "yargs": "^18.0.0",
142
142
  "@mui/internal-babel-plugin-display-name": "1.0.4-canary.19",
143
- "@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.36",
144
- "@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.27"
143
+ "@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.27",
144
+ "@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.36"
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": "23110663aef8376c78c86ae4c6ee8f54c9f8c9ea",
194
+ "gitSha": "fbe2b3e2aa722425dc6eba1ef3806c1b2659bae0",
195
195
  "scripts": {
196
196
  "build": "tsgo -p tsconfig.build.json",
197
197
  "typescript": "tsgo -noEmit",
@@ -421,6 +421,7 @@ export function createCoreConfig(options = {}) {
421
421
  'mui/consistent-production-guard': 'error',
422
422
  'mui/add-undef-to-optional': 'off',
423
423
  'mui/flatten-parentheses': 'warn',
424
+ 'mui/no-presentation-role': 'off',
424
425
 
425
426
  'react-hooks/exhaustive-deps': [
426
427
  'error',
@@ -12,6 +12,7 @@ import rulesOfUseThemeVariants from './rules/rules-of-use-theme-variants.mjs';
12
12
  import straightQuotes from './rules/straight-quotes.mjs';
13
13
  import addUndefToOptional from './rules/add-undef-to-optional.mjs';
14
14
  import flattenParentheses from './rules/flatten-parentheses.mjs';
15
+ import noPresentationRole from './rules/no-presentation-role.mjs';
15
16
 
16
17
  /** @type {import('eslint').ESLint.Plugin} */
17
18
  const muiPlugin = {
@@ -35,6 +36,7 @@ const muiPlugin = {
35
36
  // Some discrepancies between TypeScript and ESLint types - casting to any
36
37
  'add-undef-to-optional': /** @type {any} */ (addUndefToOptional),
37
38
  'flatten-parentheses': /** @type {any} */ (flattenParentheses),
39
+ 'no-presentation-role': noPresentationRole,
38
40
  },
39
41
  };
40
42
 
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @type {import('eslint').Rule.RuleModule}
3
+ */
4
+ const rule = {
5
+ meta: {
6
+ docs: {
7
+ description:
8
+ 'Disallow role="presentation" in favor of role="none". Both are equivalent, but role="none" is clearer and shorter.',
9
+ },
10
+ messages: {
11
+ noPresentation:
12
+ 'Use role="none" instead of role="presentation". They are equivalent, but role="none" is preferred.',
13
+ },
14
+ fixable: 'code',
15
+ type: 'suggestion',
16
+ schema: [],
17
+ },
18
+ create(context) {
19
+ return {
20
+ /** @param {import('estree-jsx').JSXAttribute} node */
21
+ JSXAttribute(node) {
22
+ if (node.name.type !== 'JSXIdentifier' || node.name.name !== 'role') {
23
+ return;
24
+ }
25
+
26
+ const { value } = node;
27
+
28
+ // role="presentation"
29
+ if (value !== null && value.type === 'Literal' && value.value === 'presentation') {
30
+ context.report({
31
+ node,
32
+ messageId: 'noPresentation',
33
+ fix(fixer) {
34
+ return fixer.replaceText(value, '"none"');
35
+ },
36
+ });
37
+ return;
38
+ }
39
+
40
+ // role={'presentation'}
41
+ if (
42
+ value !== null &&
43
+ value.type === 'JSXExpressionContainer' &&
44
+ value.expression.type === 'Literal' &&
45
+ value.expression.value === 'presentation'
46
+ ) {
47
+ context.report({
48
+ node,
49
+ messageId: 'noPresentation',
50
+ fix(fixer) {
51
+ return fixer.replaceText(value, '"none"');
52
+ },
53
+ });
54
+ }
55
+ },
56
+ };
57
+ },
58
+ };
59
+
60
+ export default rule;
@@ -0,0 +1,33 @@
1
+ import eslint from 'eslint';
2
+ import parser from '@typescript-eslint/parser';
3
+ import rule from './no-presentation-role.mjs';
4
+
5
+ const ruleTester = new eslint.RuleTester({
6
+ languageOptions: {
7
+ parser,
8
+ parserOptions: {
9
+ ecmaFeatures: { jsx: true },
10
+ },
11
+ },
12
+ });
13
+
14
+ ruleTester.run('no-presentation-role', rule, {
15
+ valid: ['<div role="none" />', '<div role="button" />', '<div />', '<div role={presentation} />'],
16
+ invalid: [
17
+ {
18
+ code: '<div role="presentation" />',
19
+ errors: [{ messageId: 'noPresentation' }],
20
+ output: '<div role="none" />',
21
+ },
22
+ {
23
+ code: "<div role={'presentation'} />",
24
+ errors: [{ messageId: 'noPresentation' }],
25
+ output: '<div role="none" />',
26
+ },
27
+ {
28
+ code: '<table role="presentation"><tr><td /></tr></table>',
29
+ errors: [{ messageId: 'noPresentation' }],
30
+ output: '<table role="none"><tr><td /></tr></table>',
31
+ },
32
+ ],
33
+ });
@@ -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');