@mui/internal-code-infra 0.0.3-canary.24 → 0.0.3-canary.26

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.
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @param {Object} [params]
3
3
  * @param {boolean} [params.enableReactCompiler] - Whether the config is for spec files.
4
- * @param {string} params.baseDirectory - The base directory for the configuration.
4
+ * @param {string} [params.baseDirectory] - The base directory for the configuration.
5
5
  * @returns {import('eslint').Linter.Config[]}
6
6
  */
7
- export function createBaseConfig({ enableReactCompiler, baseDirectory }?: {
7
+ export function createBaseConfig({ enableReactCompiler, baseDirectory, }?: {
8
8
  enableReactCompiler?: boolean | undefined;
9
- baseDirectory: string;
9
+ baseDirectory?: string | undefined;
10
10
  }): import("eslint").Linter.Config[];
@@ -1,8 +1,8 @@
1
- export const EXTENSION_JS: "?(c|m)js?(x)";
2
- export const EXTENSION_JS_NO_MODULE: "js?(x)";
3
- export const EXTENSION_TS: "?(c|m)[jt]s?(x)";
4
- export const EXTENSION_TS_NO_MODULE: "[jt]s?(x)";
5
- export const EXTENSION_TS_ONLY: "?(c|m)ts?(x)";
6
- export const EXTENSION_TS_ONLY_NO_MODULE: "ts?(x)";
1
+ export const EXTENSION_JS: ".?(c|m)js?(x)";
2
+ export const EXTENSION_JS_NO_MODULE: ".js?(x)";
3
+ export const EXTENSION_TS: ".?(c|m)[jt]s?(x)";
4
+ export const EXTENSION_TS_NO_MODULE: ".[jt]s?(x)";
5
+ export const EXTENSION_TS_ONLY: ".?(c|m)ts?(x)";
6
+ export const EXTENSION_TS_ONLY_NO_MODULE: ".ts?(x)";
7
7
  export const EXTENSION_DTS: ".d.?(c|m)ts?(x)";
8
8
  export const EXTENSION_TEST_FILE: ".test.?(c|m)[jt]s?(x)";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @returns {import('eslint').Linter.Config[]}
3
+ */
4
+ export function createJsonConfig(): import("eslint").Linter.Config[];
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @param {Object} [options]
3
- * @param {boolean} [options.reactCompilerEnabled] - Whether the config is for spec files.
3
+ * @param {boolean} [options.enableReactCompiler] - Whether the config is for spec files.
4
4
  */
5
5
  export function createCoreConfig(options?: {
6
- reactCompilerEnabled?: boolean | undefined;
6
+ enableReactCompiler?: boolean | undefined;
7
7
  }): import("eslint").Linter.Config<import("eslint").Linter.RulesRecord>[];
@@ -33,37 +33,11 @@ export function findLatestTaggedVersion(opts: {
33
33
  * Fetches commits between two refs (lastRelease..release) including PR details.
34
34
  * Automatically handles GitHub OAuth authentication if none provided.
35
35
  *
36
- * @overload
37
- * @param {FetchCommitsOptions & {token: string}} opts
38
- * @returns {Promise<FetchedCommitDetails[]>}
39
- *
40
- * @overload
41
- * @param {FetchCommitsOptions & {octokit: OctokitType}} opts
42
- * @returns {Promise<FetchedCommitDetails[]>}
43
- *
44
- * @param {FetchCommitsOptions & ({token: string} | {octokit: OctokitType})} opts
45
- * @returns {Promise<FetchedCommitDetails[]>}
46
- */
47
- export function fetchCommitsBetweenRefs(opts: FetchCommitsOptions & {
48
- token: string;
49
- }): Promise<FetchedCommitDetails[]>;
50
- /**
51
- * Fetches commits between two refs (lastRelease..release) including PR details.
52
- * Automatically handles GitHub OAuth authentication if none provided.
53
- *
54
- * @overload
55
- * @param {FetchCommitsOptions & {token: string}} opts
56
- * @returns {Promise<FetchedCommitDetails[]>}
57
- *
58
- * @overload
59
- * @param {FetchCommitsOptions & {octokit: OctokitType}} opts
60
- * @returns {Promise<FetchedCommitDetails[]>}
61
- *
62
- * @param {FetchCommitsOptions & ({token: string} | {octokit: OctokitType})} opts
36
+ * @param {FetchCommitsOptions & {octokit?: OctokitType}} opts
63
37
  * @returns {Promise<FetchedCommitDetails[]>}
64
38
  */
65
39
  export function fetchCommitsBetweenRefs(opts: FetchCommitsOptions & {
66
- octokit: OctokitType;
40
+ octokit?: OctokitType;
67
41
  }): Promise<FetchedCommitDetails[]>;
68
42
  export type OctokitType = import("@octokit/rest").Octokit;
69
43
  export type AuthorAssociation = "team" | "first_timer" | "contributor";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-code-infra",
3
- "version": "0.0.3-canary.24",
3
+ "version": "0.0.3-canary.26",
4
4
  "description": "Infra scripts and configs to be used across MUI repos.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -56,6 +56,7 @@
56
56
  "@babel/preset-typescript": "^7.27.1",
57
57
  "@eslint/compat": "^1.4.0",
58
58
  "@eslint/js": "^9.36.0",
59
+ "@eslint/json": "^0.13.2",
59
60
  "@inquirer/confirm": "^5.1.18",
60
61
  "@napi-rs/keyring": "^1.2.0",
61
62
  "@next/eslint-plugin-next": "^15.5.4",
@@ -92,9 +93,9 @@
92
93
  "stylelint-config-standard": "^39.0.0",
93
94
  "typescript-eslint": "^8.45.0",
94
95
  "yargs": "^18.0.0",
95
- "@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.10",
96
96
  "@mui/internal-babel-plugin-display-name": "1.0.4-canary.7",
97
- "@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.23"
97
+ "@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.23",
98
+ "@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.10"
98
99
  },
99
100
  "peerDependencies": {
100
101
  "eslint": "^9.0.0",
@@ -126,7 +127,7 @@
126
127
  "publishConfig": {
127
128
  "access": "public"
128
129
  },
129
- "gitSha": "67aee4d1566ff1bdb001664a94aff573072f7818",
130
+ "gitSha": "28991468f6b404f3fbe289764f53d82f984a7d62",
130
131
  "scripts": {
131
132
  "build": "tsc -p tsconfig.build.json",
132
133
  "typescript": "tsc -p tsconfig.json",
package/src/cli/index.mjs CHANGED
@@ -7,7 +7,6 @@ import cmdBuild from './cmdBuild.mjs';
7
7
  import cmdCopyFiles from './cmdCopyFiles.mjs';
8
8
  import cmdExtractErrorCodes from './cmdExtractErrorCodes.mjs';
9
9
  import cmdGithubAuth from './cmdGithubAuth.mjs';
10
- import cmdJsonLint from './cmdJsonLint.mjs';
11
10
  import cmdListWorkspaces from './cmdListWorkspaces.mjs';
12
11
  import cmdPublish from './cmdPublish.mjs';
13
12
  import cmdPublishCanary from './cmdPublishCanary.mjs';
@@ -24,7 +23,6 @@ yargs()
24
23
  .command(cmdCopyFiles)
25
24
  .command(cmdExtractErrorCodes)
26
25
  .command(cmdGithubAuth)
27
- .command(cmdJsonLint)
28
26
  .command(cmdListWorkspaces)
29
27
  .command(cmdPublish)
30
28
  .command(cmdPublishCanary)
@@ -8,63 +8,94 @@ import reactPlugin from 'eslint-plugin-react';
8
8
  import { configs as reactCompilerPluginConfigs } from 'eslint-plugin-react-compiler';
9
9
  import reactHooks from 'eslint-plugin-react-hooks';
10
10
  import globals from 'globals';
11
- import * as fs from 'node:fs';
12
11
  import * as path from 'node:path';
13
12
  import * as tseslint from 'typescript-eslint';
13
+ import fs from 'node:fs';
14
14
  import { createCoreConfig } from './material-ui/config.mjs';
15
15
  import muiPlugin from './material-ui/index.mjs';
16
+ import { EXTENSION_TS } from './extensions.mjs';
17
+ import { createJsonConfig } from './jsonConfig.mjs';
18
+
19
+ /**
20
+ * @param {string} filePath
21
+ * @param {string | undefined} description
22
+ */
23
+ function includeIgnoreIfExists(filePath, description) {
24
+ if (fs.existsSync(filePath)) {
25
+ return includeIgnoreFile(filePath, description);
26
+ }
27
+ return [];
28
+ }
16
29
 
17
30
  /**
18
31
  * @param {Object} [params]
19
32
  * @param {boolean} [params.enableReactCompiler] - Whether the config is for spec files.
20
- * @param {string} params.baseDirectory - The base directory for the configuration.
33
+ * @param {string} [params.baseDirectory] - The base directory for the configuration.
21
34
  * @returns {import('eslint').Linter.Config[]}
22
35
  */
23
- export function createBaseConfig(
24
- { enableReactCompiler = false, baseDirectory } = { baseDirectory: process.cwd() },
25
- ) {
26
- const ignoreRules = /** @type {import('@eslint/compat').FlatConfig[]} */ (
27
- // All repos should use .lintignore going forward.
28
- // .eslintignore is for backward compatibility. Should be removed in future.
29
- ['.gitignore', '.lintignore', '.eslintignore']
30
- .map((file) => {
31
- if (fs.existsSync(`${baseDirectory}/${file}`)) {
32
- return includeIgnoreFile(path.join(baseDirectory, file), `Ignore rules from ${file}`);
33
- }
34
- return null;
35
- })
36
- .filter(Boolean)
37
- );
38
-
39
- return defineConfig(
40
- ...ignoreRules,
41
- eslintJs.configs.recommended,
42
- importPlugin.flatConfigs.recommended,
43
- importPlugin.flatConfigs.react,
44
- jsxA11yPlugin.flatConfigs.recommended,
45
- reactPlugin.configs.flat.recommended,
46
- // @ts-expect-error Types are messed up https://github.com/facebook/react/issues/34705
47
- reactHooks.configs['flat/recommended'],
48
- tseslint.configs.recommended,
49
- importPlugin.flatConfigs.typescript,
50
- enableReactCompiler ? reactCompilerPluginConfigs.recommended : {},
36
+ export function createBaseConfig({
37
+ enableReactCompiler = false,
38
+ baseDirectory = process.cwd(),
39
+ } = {}) {
40
+ return defineConfig([
41
+ includeIgnoreIfExists(path.join(baseDirectory, '.gitignore'), `Ignore rules from .gitignore`),
42
+ includeIgnoreIfExists(path.join(baseDirectory, '.lintignore'), `Ignore rules from .lintignore`),
43
+ createJsonConfig(),
51
44
  prettier,
52
45
  {
53
- name: 'typescript-eslint-parser',
54
- languageOptions: {
55
- ecmaVersion: 7,
56
- globals: {
57
- ...globals.es2020,
58
- ...globals.browser,
59
- ...globals.node,
46
+ name: 'Base config',
47
+ files: [`**/*${EXTENSION_TS}`],
48
+ extends: defineConfig([
49
+ eslintJs.configs.recommended,
50
+ importPlugin.flatConfigs.recommended,
51
+ importPlugin.flatConfigs.react,
52
+ jsxA11yPlugin.flatConfigs.recommended,
53
+ reactPlugin.configs.flat.recommended,
54
+ // @ts-expect-error Types are messed up https://github.com/facebook/react/issues/34705
55
+ reactHooks.configs['flat/recommended'],
56
+ tseslint.configs.recommended,
57
+ importPlugin.flatConfigs.typescript,
58
+ enableReactCompiler ? reactCompilerPluginConfigs.recommended : {},
59
+ {
60
+ name: 'typescript-eslint-parser',
61
+ languageOptions: {
62
+ ecmaVersion: 7,
63
+ globals: {
64
+ ...globals.es2020,
65
+ ...globals.browser,
66
+ ...globals.node,
67
+ },
68
+ },
69
+ plugins: {
70
+ 'material-ui': muiPlugin,
71
+ },
72
+ extends: createCoreConfig({ enableReactCompiler }),
60
73
  },
61
- },
62
- plugins: {
63
- 'material-ui': muiPlugin,
64
- },
65
- extends: createCoreConfig({ reactCompilerEnabled: enableReactCompiler }),
74
+ // Lint rule to disallow usage of typescript namespaces.We've seen at least two problems with them:
75
+ // * Creates non-portable types in base ui. [1]
76
+ // * This pattern [2] leads to broken bundling in codesandbox [3].
77
+ // Gauging the ecosystem it also looks like support for namespaces in tooling is poor and tends to
78
+ // be treated as a deprecated feature.
79
+ // [1] https://github.com/mui/base-ui/pull/2324
80
+ // [2] https://github.com/mui/mui-x/blob/1cf853ed45cf301211ece1c0ca21981ea208edfb/packages/x-virtualizer/src/models/core.ts#L4-L10
81
+ // [3] https://codesandbox.io/embed/kgylpd?module=/src/Demo.tsx&fontsize=12
82
+ {
83
+ rules: {
84
+ '@typescript-eslint/no-namespace': 'error',
85
+ },
86
+ },
87
+ // Part of the migration away from airbnb config. Turned off initially.
88
+ {
89
+ rules: {
90
+ '@typescript-eslint/no-explicit-any': 'off',
91
+ '@typescript-eslint/no-unsafe-function-type': 'off',
92
+ '@typescript-eslint/no-empty-object-type': 'off',
93
+ },
94
+ },
95
+ ]),
66
96
  },
67
97
  {
98
+ name: 'ESM JS files',
68
99
  files: ['**/*.mjs'],
69
100
  rules: {
70
101
  'import/extensions': [
@@ -77,26 +108,5 @@ export function createBaseConfig(
77
108
  ],
78
109
  },
79
110
  },
80
- // Lint rule to disallow usage of typescript namespaces.We've seen at least two problems with them:
81
- // * Creates non-portable types in base ui. [1]
82
- // * This pattern [2] leads to broken bundling in codesandbox [3].
83
- // Gauging the ecosystem it also looks like support for namespaces in tooling is poor and tends to
84
- // be treated as a deprecated feature.
85
- // [1] https://github.com/mui/base-ui/pull/2324
86
- // [2] https://github.com/mui/mui-x/blob/1cf853ed45cf301211ece1c0ca21981ea208edfb/packages/x-virtualizer/src/models/core.ts#L4-L10
87
- // [3] https://codesandbox.io/embed/kgylpd?module=/src/Demo.tsx&fontsize=12
88
- {
89
- rules: {
90
- '@typescript-eslint/no-namespace': 'error',
91
- },
92
- },
93
- // Part of the migration away from airbnb config. Turned of initially.
94
- {
95
- rules: {
96
- '@typescript-eslint/no-explicit-any': 'off',
97
- '@typescript-eslint/no-unsafe-function-type': 'off',
98
- '@typescript-eslint/no-empty-object-type': 'off',
99
- },
100
- },
101
- );
111
+ ]);
102
112
  }
@@ -1,8 +1,8 @@
1
- export const EXTENSION_JS = '?(c|m)js?(x)';
2
- export const EXTENSION_JS_NO_MODULE = 'js?(x)';
3
- export const EXTENSION_TS = '?(c|m)[jt]s?(x)';
4
- export const EXTENSION_TS_NO_MODULE = '[jt]s?(x)';
5
- export const EXTENSION_TS_ONLY = '?(c|m)ts?(x)';
6
- export const EXTENSION_TS_ONLY_NO_MODULE = 'ts?(x)';
7
- export const EXTENSION_DTS = `.d.${EXTENSION_TS_ONLY}`;
8
- export const EXTENSION_TEST_FILE = `.test.${EXTENSION_TS}`;
1
+ export const EXTENSION_JS = '.?(c|m)js?(x)';
2
+ export const EXTENSION_JS_NO_MODULE = '.js?(x)';
3
+ export const EXTENSION_TS = '.?(c|m)[jt]s?(x)';
4
+ export const EXTENSION_TS_NO_MODULE = '.[jt]s?(x)';
5
+ export const EXTENSION_TS_ONLY = '.?(c|m)ts?(x)';
6
+ export const EXTENSION_TS_ONLY_NO_MODULE = '.ts?(x)';
7
+ export const EXTENSION_DTS = `.d${EXTENSION_TS_ONLY}`;
8
+ export const EXTENSION_TEST_FILE = `.test${EXTENSION_TS}`;
@@ -0,0 +1,34 @@
1
+ import { defineConfig } from 'eslint/config';
2
+ import json from '@eslint/json';
3
+
4
+ /**
5
+ * @returns {import('eslint').Linter.Config[]}
6
+ */
7
+ export function createJsonConfig() {
8
+ return defineConfig([
9
+ {
10
+ name: 'JSON files',
11
+ files: ['**/*.json'],
12
+ ignores: ['package-lock.json'],
13
+ plugins: { json },
14
+ language: 'json/json',
15
+ extends: [json.configs.recommended],
16
+ },
17
+
18
+ {
19
+ name: 'JSONC files',
20
+ files: ['**/*.jsonc', '**/tsconfig.json', '**/tsconfig.*.json', '.vscode/**/*.json'],
21
+ plugins: { json },
22
+ language: 'json/jsonc',
23
+ extends: [json.configs.recommended],
24
+ },
25
+
26
+ {
27
+ name: 'JSON5 files',
28
+ files: ['**/*.json5'],
29
+ plugins: { json },
30
+ language: 'json/json5',
31
+ extends: [json.configs.recommended],
32
+ },
33
+ ]);
34
+ }
@@ -304,7 +304,7 @@ const airbnbJsxA11y = {
304
304
 
305
305
  /**
306
306
  * @param {Object} [options]
307
- * @param {boolean} [options.reactCompilerEnabled] - Whether the config is for spec files.
307
+ * @param {boolean} [options.enableReactCompiler] - Whether the config is for spec files.
308
308
  */
309
309
  export function createCoreConfig(options = {}) {
310
310
  return defineConfig([
@@ -502,7 +502,7 @@ export function createCoreConfig(options = {}) {
502
502
 
503
503
  'react/jsx-no-useless-fragment': ['error', { allowExpressions: true }],
504
504
  'lines-around-directive': 'off',
505
- ...(options.reactCompilerEnabled ? { 'react-compiler/react-compiler': 'error' } : {}),
505
+ ...(options.enableReactCompiler ? { 'react-compiler/react-compiler': 'error' } : {}),
506
506
  // Prevent the use of `e` as a shorthand for `event`, `error`, etc.
507
507
  'id-denylist': ['error', 'e'],
508
508
  '@typescript-eslint/return-await': 'off',
@@ -3,12 +3,14 @@ import testingLibrary from 'eslint-plugin-testing-library';
3
3
  import { defineConfig } from 'eslint/config';
4
4
  import globals from 'globals';
5
5
  import * as tseslint from 'typescript-eslint';
6
+ import { EXTENSION_TS } from './extensions.mjs';
6
7
 
7
8
  /**
8
9
  * @type {import('eslint').Linter.Config}
9
10
  */
10
11
  export const baseSpecRules = {
11
- files: ['**/*.spec.*'],
12
+ name: 'Spec files rules',
13
+ files: [`**/*.spec${EXTENSION_TS}`],
12
14
  rules: {
13
15
  'no-alert': 'off',
14
16
  'no-console': 'off',
@@ -51,6 +53,7 @@ export function createTestConfig(options = {}) {
51
53
  testingLibrary.configs['flat/dom'],
52
54
  testingLibrary.configs['flat/react'],
53
55
  {
56
+ name: 'Test files',
54
57
  languageOptions: {
55
58
  parser: tseslint.parser,
56
59
  parserOptions: {
@@ -49,25 +49,14 @@ export async function findLatestTaggedVersion(opts) {
49
49
  * Fetches commits between two refs (lastRelease..release) including PR details.
50
50
  * Automatically handles GitHub OAuth authentication if none provided.
51
51
  *
52
- * @overload
53
- * @param {FetchCommitsOptions & {token: string}} opts
54
- * @returns {Promise<FetchedCommitDetails[]>}
55
- *
56
- * @overload
57
- * @param {FetchCommitsOptions & {octokit: OctokitType}} opts
58
- * @returns {Promise<FetchedCommitDetails[]>}
59
- *
60
- * @param {FetchCommitsOptions & ({token: string} | {octokit: OctokitType})} opts
52
+ * @param {FetchCommitsOptions & {octokit?: OctokitType}} opts
61
53
  * @returns {Promise<FetchedCommitDetails[]>}
62
54
  */
63
55
  export async function fetchCommitsBetweenRefs(opts) {
64
56
  const octokit =
65
- // eslint-disable-next-line no-nested-ternary
66
57
  'octokit' in opts && opts.octokit
67
58
  ? opts.octokit
68
- : 'token' in opts && opts.token
69
- ? new Octokit({ auth: opts.token })
70
- : new Octokit({ authStrategy: persistentAuthStrategy });
59
+ : new Octokit({ authStrategy: persistentAuthStrategy });
71
60
 
72
61
  return fetchCommitsRest({
73
62
  octokit,
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env node
2
- declare const _default: import("yargs").CommandModule<{}, Args>;
3
- export default _default;
4
- export type Args = {
5
- /**
6
- * Run in silent mode without logging
7
- */
8
- silent?: boolean | undefined;
9
- };
@@ -1,69 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk';
4
- import fs from 'node:fs/promises';
5
- import { globby } from 'globby';
6
- import path from 'node:path';
7
- import { mapConcurrently } from '../utils/build.mjs';
8
-
9
- /**
10
- * @typedef {Object} Args
11
- * @property {boolean} [silent] Run in silent mode without logging
12
- */
13
-
14
- /**
15
- * @param {string} message
16
- * @returns {string}
17
- */
18
- const passMessage = (message) => `✓ ${chalk.gray(message)}`;
19
- /**
20
- * @param {string} message
21
- * @returns {string}
22
- */
23
- const failMessage = (message) => `❌ ${chalk.whiteBright(message)}`;
24
-
25
- export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
26
- command: 'jsonlint',
27
- describe: 'Lint JSON files',
28
- builder: (yargs) => {
29
- return yargs.option('silent', {
30
- type: 'boolean',
31
- default: false,
32
- description: "Don't log file names.",
33
- });
34
- },
35
- handler: async (args) => {
36
- const cwd = process.cwd();
37
-
38
- const filenames = await globby('**/*.json', {
39
- cwd,
40
- gitignore: true,
41
- ignoreFiles: ['.lintignore'],
42
- ignore: ['**/tsconfig*.json'],
43
- followSymbolicLinks: false,
44
- });
45
-
46
- let passed = true;
47
-
48
- await mapConcurrently(
49
- filenames,
50
- async (filename) => {
51
- const content = await fs.readFile(path.join(cwd, filename), { encoding: 'utf8' });
52
- try {
53
- JSON.parse(content);
54
- if (!args.silent) {
55
- // eslint-disable-next-line no-console
56
- console.log(passMessage(filename));
57
- }
58
- } catch (error) {
59
- passed = false;
60
- console.error(failMessage(`Error parsing ${filename}:\n\n${String(error)}`));
61
- }
62
- },
63
- 20,
64
- );
65
- if (!passed) {
66
- throw new Error('❌ At least one file did not pass. Check the console output');
67
- }
68
- },
69
- });