@mui/internal-code-infra 0.1.1-canary.4 → 0.1.1-canary.41
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/README.md +36 -4
- package/build/babel-config.d.mts +7 -1
- package/build/changelog/changelogChanges.d.mts +42 -0
- package/build/changelog/changelogGrouping.d.mts +52 -0
- package/build/changelog/changelogMarkdown.d.mts +69 -0
- package/build/changelog/changelogTags.d.mts +15 -0
- package/build/changelog/changelogTitle.d.mts +28 -0
- package/build/changelog/fetchChangelogData.d.mts +16 -0
- package/build/changelog/fetchChangelogs.d.mts +11 -12
- package/build/changelog/index.d.mts +25 -0
- package/build/changelog/octokit.d.mts +7 -0
- package/build/changelog/types.d.ts +174 -0
- package/build/eslint/baseConfig.d.mts +1 -1
- package/build/eslint/index.d.mts +1 -0
- package/build/eslint/mui/rules/no-constructor-assigned-field.d.mts +50 -0
- package/build/eslint/nodeSupportConfig.d.mts +11 -0
- package/build/eslint/packageJsonConfig.d.mts +7 -0
- package/build/remark/config.d.mts +5 -14
- package/build/utils/babelPlugin.d.mts +8 -0
- package/build/utils/build.d.mts +22 -0
- package/build/utils/cjsSourcesPlugin.d.mts +11 -0
- package/build/utils/credentials.d.mts +2 -2
- package/build/utils/dtsExportsPlugin.d.mts +8 -0
- package/build/utils/dtsNamespacesPlugin.d.mts +19 -0
- package/build/utils/fileUrlEntriesPlugin.d.mts +9 -0
- package/build/utils/getPublishedPkgJson.d.mts +20 -0
- package/build/utils/git.d.mts +30 -9
- package/build/utils/github.d.mts +8 -0
- package/build/utils/jsNamespacesPlugin.d.mts +13 -0
- package/build/utils/pnpm.d.mts +67 -3
- package/build/utils/publint.d.mts +6 -0
- package/build/utils/rolldownOutput.d.mts +38 -0
- package/build/utils/testUtils.d.mts +8 -0
- package/build/utils/typescript.d.mts +17 -0
- package/package.json +61 -49
- package/src/babel-config.mjs +35 -1
- package/src/brokenLinksChecker/index.mjs +8 -1
- package/src/changelog/changelogChanges.mjs +479 -0
- package/src/changelog/changelogGrouping.mjs +148 -0
- package/src/changelog/changelogMarkdown.mjs +110 -0
- package/src/changelog/changelogTags.mjs +34 -0
- package/src/changelog/changelogTitle.mjs +56 -0
- package/src/changelog/fetchChangelogData.mjs +172 -0
- package/src/changelog/fetchChangelogs.mjs +47 -34
- package/src/changelog/index.mjs +34 -0
- package/src/changelog/octokit.mjs +35 -0
- package/src/changelog/types.ts +187 -0
- package/src/cli/cmdBaseline.mjs +31 -0
- package/src/cli/cmdBuild.mjs +20 -89
- package/src/cli/cmdBuildNew.mjs +474 -0
- package/src/cli/cmdNetlifyIgnore.mjs +14 -7
- package/src/cli/cmdPublish.mjs +17 -3
- package/src/cli/cmdPublishNewPackage.mjs +11 -4
- package/src/cli/cmdValidateBuiltTypes.mjs +447 -32
- package/src/cli/index.mjs +4 -0
- package/src/eslint/baseConfig.mjs +10 -2
- package/src/eslint/docsConfig.mjs +28 -10
- package/src/eslint/index.mjs +1 -0
- package/src/eslint/jsonConfig.mjs +2 -1
- package/src/eslint/mui/config.mjs +16 -1
- package/src/eslint/mui/index.mjs +2 -0
- package/src/eslint/mui/rules/disallow-react-api-in-server-components.mjs +4 -1
- package/src/eslint/mui/rules/no-constructor-assigned-field.mjs +183 -0
- package/src/eslint/nodeSupportConfig.mjs +70 -0
- package/src/eslint/packageJsonConfig.mjs +50 -0
- package/src/eslint/testConfig.mjs +4 -2
- package/src/remark/config.mjs +60 -13
- package/src/utils/babelPlugin.mjs +52 -0
- package/src/utils/build.mjs +81 -0
- package/src/utils/cjsSourcesPlugin.mjs +92 -0
- package/src/utils/credentials.mjs +4 -3
- package/src/utils/dtsExportsPlugin.mjs +103 -0
- package/src/utils/dtsNamespacesPlugin.mjs +226 -0
- package/src/utils/extractErrorCodes.mjs +1 -3
- package/src/utils/fileUrlEntriesPlugin.mjs +84 -0
- package/src/utils/getPublishedPkgJson.mjs +86 -0
- package/src/utils/git.mjs +107 -46
- package/src/utils/github.mjs +27 -0
- package/src/utils/jsNamespacesPlugin.mjs +505 -0
- package/src/utils/pnpm.mjs +126 -25
- package/src/utils/publint.mjs +34 -0
- package/src/utils/rolldownOutput.mjs +70 -0
- package/src/utils/testUtils.mjs +26 -0
- package/src/utils/typescript.mjs +23 -13
- package/vale/styles/MUI/GoogleLatin.yml +5 -2
- package/build/cli/cmdArgosPush.d.mts +0 -18
- package/build/cli/cmdBuild.d.mts +0 -64
- package/build/cli/cmdCopyFiles.d.mts +0 -20
- package/build/cli/cmdExtractErrorCodes.d.mts +0 -6
- package/build/cli/cmdGenerateChangelog.d.mts +0 -32
- package/build/cli/cmdGithubAuth.d.mts +0 -11
- package/build/cli/cmdListWorkspaces.d.mts +0 -29
- package/build/cli/cmdNetlifyIgnore.d.mts +0 -17
- package/build/cli/cmdPublish.d.mts +0 -32
- package/build/cli/cmdPublishCanary.d.mts +0 -34
- package/build/cli/cmdPublishNewPackage.d.mts +0 -17
- package/build/cli/cmdRenameScope.d.mts +0 -18
- package/build/cli/cmdSetVersionOverrides.d.mts +0 -9
- package/build/cli/cmdVale.d.mts +0 -46
- package/build/cli/cmdValidateBuiltTypes.d.mts +0 -2
- package/build/cli/index.d.mts +0 -1
- package/vale/styles/MUI/CorrectRererenceCased.yml +0 -14
package/src/eslint/mui/index.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import addUndefToOptional from './rules/add-undef-to-optional.mjs';
|
|
|
14
14
|
import flattenParentheses from './rules/flatten-parentheses.mjs';
|
|
15
15
|
import noPresentationRole from './rules/no-presentation-role.mjs';
|
|
16
16
|
import noFloatingCleanup from './rules/no-floating-cleanup.mjs';
|
|
17
|
+
import noConstructorAssignedField from './rules/no-constructor-assigned-field.mjs';
|
|
17
18
|
|
|
18
19
|
/** @type {import('eslint').ESLint.Plugin} */
|
|
19
20
|
const muiPlugin = {
|
|
@@ -39,6 +40,7 @@ const muiPlugin = {
|
|
|
39
40
|
'flatten-parentheses': /** @type {any} */ (flattenParentheses),
|
|
40
41
|
'no-presentation-role': noPresentationRole,
|
|
41
42
|
'no-floating-cleanup': /** @type {any} */ (noFloatingCleanup),
|
|
43
|
+
'no-constructor-assigned-field': /** @type {any} */ (noConstructorAssignedField),
|
|
42
44
|
},
|
|
43
45
|
};
|
|
44
46
|
|
|
@@ -47,7 +47,10 @@ export default /** @type {import('eslint').Rule.RuleModule} */ ({
|
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
const firstToken = context.sourceCode.ast
|
|
50
|
+
const firstToken = context.sourceCode.getFirstToken(context.sourceCode.ast);
|
|
51
|
+
if (!firstToken) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
51
54
|
return fixer.insertTextBefore(firstToken, "'use client';\n");
|
|
52
55
|
}
|
|
53
56
|
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { ASTUtils, ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('@typescript-eslint/utils').TSESTree.PropertyDefinition} PropertyDefinition
|
|
5
|
+
* @typedef {import('@typescript-eslint/utils').TSESTree.Node} Node
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const createRule = ESLintUtils.RuleCreator(
|
|
9
|
+
(name) =>
|
|
10
|
+
`https://github.com/mui/mui-public/blob/master/packages/code-infra/src/eslint/mui/rules/${name}.mjs`,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the constructor whose own code contains `node`, or `null` when `node` is outside a
|
|
15
|
+
* constructor or inside a nested function or class.
|
|
16
|
+
* @param {Node} node
|
|
17
|
+
*/
|
|
18
|
+
function getEnclosingConstructor(node) {
|
|
19
|
+
let current = node.parent;
|
|
20
|
+
while (current && !ASTUtils.isFunction(current)) {
|
|
21
|
+
if (current.type === 'ClassBody') {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
current = current.parent;
|
|
25
|
+
}
|
|
26
|
+
const method = current?.parent;
|
|
27
|
+
return method && ASTUtils.isConstructor(method) ? method : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns the extra edits needed before `field` can be marked `declare`.
|
|
32
|
+
* @param {PropertyDefinition} field
|
|
33
|
+
*/
|
|
34
|
+
function getDeclareHint(field) {
|
|
35
|
+
const edits = [];
|
|
36
|
+
if (field.value) {
|
|
37
|
+
edits.push('drop its initializer');
|
|
38
|
+
}
|
|
39
|
+
if (field.definite) {
|
|
40
|
+
edits.push('drop the `!`');
|
|
41
|
+
}
|
|
42
|
+
if (field.override) {
|
|
43
|
+
edits.push('drop `override`');
|
|
44
|
+
}
|
|
45
|
+
return edits.length > 0 ? ` (${edits.join(', ')})` : '';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* ESLint rule that disallows assigning a class field in the constructor when it is also
|
|
50
|
+
* declared as a (non-`declare`) class field.
|
|
51
|
+
*
|
|
52
|
+
* Babel 8 only strips TypeScript fields marked `declare` (see mui/material-ui#49241), so a
|
|
53
|
+
* field without an initializer is emitted as a property definition that sets it to
|
|
54
|
+
* `undefined` before the constructor assigns it again. Either initialize the field at its
|
|
55
|
+
* declaration, or mark it `declare` so it only serves as a type annotation.
|
|
56
|
+
*
|
|
57
|
+
* `declare` fields are exempt from TypeScript's strict property initialization check
|
|
58
|
+
* (TS2564), so prefer initializing at the declaration where the value doesn't depend on
|
|
59
|
+
* constructor arguments. The `declare` suggestion is only offered when every path through the
|
|
60
|
+
* constructor assigns the field, i.e. for an unconditional top-level assignment.
|
|
61
|
+
*
|
|
62
|
+
* Only plain `=` assignments count: compound assignments read the field rather than
|
|
63
|
+
* re-initialize it. A field with an initializer is only reported for an unconditional
|
|
64
|
+
* top-level assignment, as a conditional one overrides a default. Private (`#`) and decorated
|
|
65
|
+
* fields are ignored: they are runtime declarations that `declare` can't replace.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Invalid
|
|
69
|
+
* class ModalManager {
|
|
70
|
+
* private modals: Modal[];
|
|
71
|
+
* constructor() {
|
|
72
|
+
* this.modals = [];
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // Valid - initialized at the declaration
|
|
78
|
+
* class ModalManager {
|
|
79
|
+
* private modals: Modal[] = [];
|
|
80
|
+
* }
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Valid - declared only, assigned in the constructor
|
|
84
|
+
* class ModalManager {
|
|
85
|
+
* declare private modals: Modal[];
|
|
86
|
+
* constructor(modals: Modal[]) {
|
|
87
|
+
* this.modals = modals;
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
*/
|
|
91
|
+
export default createRule({
|
|
92
|
+
name: 'no-constructor-assigned-field',
|
|
93
|
+
meta: {
|
|
94
|
+
type: 'suggestion',
|
|
95
|
+
docs: {
|
|
96
|
+
description:
|
|
97
|
+
'Disallow assigning class fields in the constructor when they are also declared as class fields',
|
|
98
|
+
},
|
|
99
|
+
hasSuggestions: true,
|
|
100
|
+
messages: {
|
|
101
|
+
assignedInConstructor:
|
|
102
|
+
"Field '{{name}}' is declared as a class field and also assigned in the constructor. " +
|
|
103
|
+
'Either initialize it at the declaration and remove the constructor assignment, ' +
|
|
104
|
+
'or mark it `declare`{{declareHint}}.',
|
|
105
|
+
addDeclare: 'Mark the field `declare`.',
|
|
106
|
+
},
|
|
107
|
+
schema: [],
|
|
108
|
+
},
|
|
109
|
+
defaultOptions: [],
|
|
110
|
+
create(context) {
|
|
111
|
+
/**
|
|
112
|
+
* Fields assigned in a constructor, mapped to whether any of those assignments is an
|
|
113
|
+
* unconditional top-level statement.
|
|
114
|
+
* @type {Map<PropertyDefinition, boolean>}
|
|
115
|
+
*/
|
|
116
|
+
const assignedFields = new Map();
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
AssignmentExpression(node) {
|
|
120
|
+
if (
|
|
121
|
+
node.operator !== '=' ||
|
|
122
|
+
node.left.type !== 'MemberExpression' ||
|
|
123
|
+
node.left.object.type !== 'ThisExpression'
|
|
124
|
+
) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const name = ASTUtils.getPropertyName(node.left);
|
|
128
|
+
if (name === null) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const constructor = getEnclosingConstructor(node);
|
|
132
|
+
if (!constructor) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const field = constructor.parent.body.find(
|
|
137
|
+
/** @returns {member is PropertyDefinition} */
|
|
138
|
+
(member) =>
|
|
139
|
+
member.type === 'PropertyDefinition' &&
|
|
140
|
+
!member.static &&
|
|
141
|
+
!member.declare &&
|
|
142
|
+
member.decorators.length === 0 &&
|
|
143
|
+
ASTUtils.getPropertyName(member) === name,
|
|
144
|
+
);
|
|
145
|
+
if (!field) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const statement = node.parent;
|
|
150
|
+
const unconditional =
|
|
151
|
+
statement.type === 'ExpressionStatement' && statement.parent === constructor.value.body;
|
|
152
|
+
assignedFields.set(field, Boolean(assignedFields.get(field)) || unconditional);
|
|
153
|
+
},
|
|
154
|
+
'ClassBody:exit'(classBody) {
|
|
155
|
+
for (const member of classBody.body) {
|
|
156
|
+
if (member.type !== 'PropertyDefinition' || !assignedFields.has(member)) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const unconditional = Boolean(assignedFields.get(member));
|
|
160
|
+
if (member.value && !unconditional) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const declareHint = getDeclareHint(member);
|
|
165
|
+
context.report({
|
|
166
|
+
node: member,
|
|
167
|
+
messageId: 'assignedInConstructor',
|
|
168
|
+
data: { name: ASTUtils.getPropertyName(member), declareHint },
|
|
169
|
+
suggest:
|
|
170
|
+
unconditional && declareHint === ''
|
|
171
|
+
? [
|
|
172
|
+
{
|
|
173
|
+
messageId: 'addDeclare',
|
|
174
|
+
fix: (fixer) => fixer.insertTextBefore(member, 'declare '),
|
|
175
|
+
},
|
|
176
|
+
]
|
|
177
|
+
: [],
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { defineConfig } from 'eslint/config';
|
|
4
|
+
import nPlugin from 'eslint-plugin-n';
|
|
5
|
+
import { globbySync } from 'globby';
|
|
6
|
+
import { EXTENSION_TEST_FILE, EXTENSION_TS } from './extensions.mjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Finds the packages in the `packages*` directories of the repository that declare the Node.js
|
|
10
|
+
* versions they support in "engines.node". Packages without it, like development tooling, run
|
|
11
|
+
* on the repository's own Node.js version.
|
|
12
|
+
* @param {string} baseDirectory
|
|
13
|
+
* @returns {string[]} Package directories, relative to `baseDirectory`.
|
|
14
|
+
*/
|
|
15
|
+
function findPackageDirsWithEnginesNode(baseDirectory) {
|
|
16
|
+
return globbySync('packages*/*/package.json', { cwd: baseDirectory })
|
|
17
|
+
.filter((packageJsonPath) => {
|
|
18
|
+
const packageJson = JSON.parse(
|
|
19
|
+
fs.readFileSync(path.join(baseDirectory, packageJsonPath), 'utf8'),
|
|
20
|
+
);
|
|
21
|
+
return typeof packageJson.engines?.node === 'string';
|
|
22
|
+
})
|
|
23
|
+
.map((packageJsonPath) => path.posix.dirname(packageJsonPath));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Reports syntax, ECMAScript built-ins and Node.js APIs in package sources that the Node.js
|
|
28
|
+
* versions allowed by the package's "engines.node" don't support. The ESM bundle is compiled for
|
|
29
|
+
* the "stable" browserslist environment rather than for "engines.node", and nothing polyfills
|
|
30
|
+
* built-ins, so all of them reach Node.js consumers as written.
|
|
31
|
+
* Only packages that declare "engines.node", meaning they're intended to run in Node.js, are
|
|
32
|
+
* checked.
|
|
33
|
+
* @param {string} baseDirectory - The repository root. File patterns are resolved against it.
|
|
34
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
35
|
+
*/
|
|
36
|
+
export function createNodeSupportConfig(baseDirectory) {
|
|
37
|
+
const packageDirs = findPackageDirsWithEnginesNode(baseDirectory);
|
|
38
|
+
if (packageDirs.length === 0) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
return defineConfig([
|
|
42
|
+
{
|
|
43
|
+
name: 'Node.js support of package sources',
|
|
44
|
+
basePath: baseDirectory,
|
|
45
|
+
files: packageDirs.map((packageDir) => `${packageDir}/src/**/*${EXTENSION_TS}`),
|
|
46
|
+
ignores: [`**/*${EXTENSION_TEST_FILE}`, `**/*.spec${EXTENSION_TS}`],
|
|
47
|
+
plugins: { n: nPlugin },
|
|
48
|
+
rules: {
|
|
49
|
+
'n/no-unsupported-features/es-builtins': 'error',
|
|
50
|
+
'n/no-unsupported-features/es-syntax': 'error',
|
|
51
|
+
'n/no-unsupported-features/node-builtins': [
|
|
52
|
+
'error',
|
|
53
|
+
// Browser APIs that Node.js also exposes, behind an experimental flag. In packages that
|
|
54
|
+
// combine Node.js tooling with browser code, these refer to the browser API.
|
|
55
|
+
{
|
|
56
|
+
ignores: [
|
|
57
|
+
'localStorage',
|
|
58
|
+
'sessionStorage',
|
|
59
|
+
'Storage',
|
|
60
|
+
'navigator',
|
|
61
|
+
'Navigator',
|
|
62
|
+
'Worker',
|
|
63
|
+
'ErrorEvent',
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
70
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defineConfig } from 'eslint/config';
|
|
2
|
+
import packageJson from 'eslint-plugin-package-json';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Lints package.json files for publishing metadata. Published packages must
|
|
6
|
+
* declare an SPDX license, `"author": "MUI Team"` and a repository pointing at
|
|
7
|
+
* their own directory. Private packages must not carry publishing metadata.
|
|
8
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
9
|
+
*/
|
|
10
|
+
export function createPackageJsonConfig() {
|
|
11
|
+
return defineConfig([
|
|
12
|
+
{
|
|
13
|
+
name: 'package.json files',
|
|
14
|
+
files: ['**/package.json'],
|
|
15
|
+
ignores: ['**/__fixtures__/**'],
|
|
16
|
+
extends: [packageJson.configs.recommended],
|
|
17
|
+
rules: {
|
|
18
|
+
'package-json/require-author': ['error', { ignorePrivate: true }],
|
|
19
|
+
'package-json/require-description': ['error', { ignorePrivate: true }],
|
|
20
|
+
'package-json/restrict-private-properties': [
|
|
21
|
+
'error',
|
|
22
|
+
// `publishConfig.directory` is allowed: `code-infra build` reads it, also for private packages.
|
|
23
|
+
{ blockedProperties: ['files', 'license'] },
|
|
24
|
+
],
|
|
25
|
+
'no-restricted-syntax': [
|
|
26
|
+
'error',
|
|
27
|
+
{
|
|
28
|
+
selector:
|
|
29
|
+
'Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value="author"][value.value!="MUI Team"]',
|
|
30
|
+
message: 'The "author" field must be "MUI Team".',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
// Condition order in "exports" is significant, and scripts are grouped by purpose.
|
|
34
|
+
'package-json/sort-collections': 'off',
|
|
35
|
+
// Packages built with `code-infra build` get these fields in the generated package.json.
|
|
36
|
+
'package-json/require-files': 'off',
|
|
37
|
+
'package-json/require-sideEffects': 'off',
|
|
38
|
+
'package-json/require-type': 'off',
|
|
39
|
+
// Peer dependencies are installed once at the workspace root.
|
|
40
|
+
'package-json/specify-peers-locally': 'off',
|
|
41
|
+
// CLI-only packages have no "exports".
|
|
42
|
+
'package-json/require-exports': 'off',
|
|
43
|
+
// Rejects the object form of "browser", which the browser field spec allows.
|
|
44
|
+
'package-json/valid-browser': 'off',
|
|
45
|
+
// npm only auto-includes "main" when it has no "./" prefix; removing it from "files" can drop the entry point.
|
|
46
|
+
'package-json/no-redundant-files': 'off',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
@@ -21,7 +21,6 @@ export const baseSpecRules = {
|
|
|
21
21
|
'@typescript-eslint/no-unused-expressions': 'off',
|
|
22
22
|
'@typescript-eslint/no-unused-vars': 'off',
|
|
23
23
|
'@typescript-eslint/no-use-before-define': 'off',
|
|
24
|
-
'@typescript-eslint/ban-ts-comment': 'off',
|
|
25
24
|
|
|
26
25
|
'import/prefer-default-export': 'off',
|
|
27
26
|
|
|
@@ -63,6 +62,7 @@ export function createTestConfig() {
|
|
|
63
62
|
'import/named': 'off',
|
|
64
63
|
'mui/disallow-active-element-as-key-event-target': 'error',
|
|
65
64
|
'mui/consistent-production-guard': 'off',
|
|
65
|
+
'mui/no-constructor-assigned-field': 'off',
|
|
66
66
|
|
|
67
67
|
// disable eslint-plugin-jsx-a11y
|
|
68
68
|
// tests are not driven by assistive technology
|
|
@@ -87,11 +87,13 @@ export function createTestConfig() {
|
|
|
87
87
|
'react/no-unused-prop-types': 'off',
|
|
88
88
|
// Part of the migration away from airbnb config. Turned of initially.
|
|
89
89
|
'@typescript-eslint/no-empty-function': 'off',
|
|
90
|
-
'@typescript-eslint/ban-ts-comment': 'off',
|
|
91
90
|
'testing-library/no-node-access': 'off',
|
|
92
91
|
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
|
|
93
92
|
// end migration
|
|
94
93
|
'vitest/prefer-importing-vitest-globals': 'error',
|
|
94
|
+
// Vitest accepts a failure message as the second argument of `expect`, also when it is
|
|
95
|
+
// not a literal.
|
|
96
|
+
'vitest/valid-expect': ['error', { maxArgs: 2 }],
|
|
95
97
|
},
|
|
96
98
|
},
|
|
97
99
|
);
|
package/src/remark/config.mjs
CHANGED
|
@@ -97,6 +97,49 @@ function withOverrides(name, plugin, baseSettings, overrideEntries) {
|
|
|
97
97
|
return wrapper;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Allows link-reference comments while retaining diagnostics for real links and definitions.
|
|
102
|
+
* Existing docs generators use these markers in both Markdown and MDX and parse them as metadata.
|
|
103
|
+
* Authored MDX can use JSX comments without this compatibility option.
|
|
104
|
+
*
|
|
105
|
+
* @param {import('unified').Plugin<any[], any, any>} plugin
|
|
106
|
+
*/
|
|
107
|
+
function withDefinitionComments(plugin) {
|
|
108
|
+
/** @param {any[]} settings */
|
|
109
|
+
return function wrapper(...settings) {
|
|
110
|
+
const processor = unified().use(plugin, ...settings);
|
|
111
|
+
/** @type {import('unified').Transformer} */
|
|
112
|
+
return async function transformer(tree, file) {
|
|
113
|
+
const previousMessages = file.messages.length;
|
|
114
|
+
await processor.run(tree, file);
|
|
115
|
+
file.messages = file.messages.filter((message, index) => {
|
|
116
|
+
const node = message.ancestors?.at(-1);
|
|
117
|
+
return !(
|
|
118
|
+
index >= previousMessages &&
|
|
119
|
+
node?.type === 'definition' &&
|
|
120
|
+
'identifier' in node &&
|
|
121
|
+
node.identifier === '//' &&
|
|
122
|
+
'title' in node &&
|
|
123
|
+
typeof node.title === 'string' &&
|
|
124
|
+
node.title.length > 0
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Makes the processor output the source text unchanged. The preset only lints, and
|
|
133
|
+
* remark-stringify doesn't round-trip Markdown (it escapes GitHub alerts, rewrites bare
|
|
134
|
+
* URLs, ...). eslint-plugin-mdx offers the processed output as a whole-file fix for any
|
|
135
|
+
* remark message, so with this `eslint --fix` leaves Markdown alone.
|
|
136
|
+
*
|
|
137
|
+
* @this {import('unified').Processor}
|
|
138
|
+
*/
|
|
139
|
+
function remarkPreserveSource() {
|
|
140
|
+
this.compiler = (_tree, file) => String(file);
|
|
141
|
+
}
|
|
142
|
+
|
|
100
143
|
/**
|
|
101
144
|
* Returns a remark preset wiring the MUI-authored remark-lint plugins together
|
|
102
145
|
* with a curated set of community plugins. Drop this into `.remarkrc.mjs`:
|
|
@@ -120,9 +163,11 @@ function withOverrides(name, plugin, baseSettings, overrideEntries) {
|
|
|
120
163
|
* ```
|
|
121
164
|
*
|
|
122
165
|
* @param {Object} [options]
|
|
166
|
+
* @param {boolean} [options.allowDefinitionComments=false] Allow titled `[//]` link-reference comments.
|
|
123
167
|
* @param {Array<{ files: string | string[], rules: Record<string, false | unknown[]> }>} [options.overrides]
|
|
168
|
+
* @returns {import('unified').Preset}
|
|
124
169
|
*/
|
|
125
|
-
export function createRemarkConfig({ overrides = [] } = {}) {
|
|
170
|
+
export function createRemarkConfig({ overrides = [], allowDefinitionComments = false } = {}) {
|
|
126
171
|
for (const override of overrides) {
|
|
127
172
|
const unknown = Object.keys(override.rules).filter((ruleName) => !(ruleName in RULES));
|
|
128
173
|
if (unknown.length > 0) {
|
|
@@ -130,10 +175,14 @@ export function createRemarkConfig({ overrides = [] } = {}) {
|
|
|
130
175
|
}
|
|
131
176
|
}
|
|
132
177
|
|
|
178
|
+
/** @type {import('unified').PluggableList} */
|
|
133
179
|
const entries = Object.entries(RULES).map(([name, entry]) => {
|
|
134
|
-
const [
|
|
135
|
-
entry
|
|
136
|
-
|
|
180
|
+
const [rulePlugin, baseSettings] =
|
|
181
|
+
/** @type {[import('unified').Plugin<any[], any, any>, any]} */ (entry);
|
|
182
|
+
const plugin =
|
|
183
|
+
allowDefinitionComments && (name === 'no-empty-url' || name === 'no-unused-definitions')
|
|
184
|
+
? withDefinitionComments(rulePlugin)
|
|
185
|
+
: rulePlugin;
|
|
137
186
|
const overrideEntries = overrides
|
|
138
187
|
.filter((override) => name in override.rules)
|
|
139
188
|
.map((override) => ({ files: override.files, settings: override.rules[name] }));
|
|
@@ -144,14 +193,12 @@ export function createRemarkConfig({ overrides = [] } = {}) {
|
|
|
144
193
|
});
|
|
145
194
|
|
|
146
195
|
return {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
},
|
|
155
|
-
plugins: [[remarkFrontmatter, ['yaml', 'toml']], remarkGfm, remarkLint, ...entries],
|
|
196
|
+
plugins: [
|
|
197
|
+
[remarkFrontmatter, ['yaml', 'toml']],
|
|
198
|
+
remarkGfm,
|
|
199
|
+
remarkLint,
|
|
200
|
+
...entries,
|
|
201
|
+
remarkPreserveSource,
|
|
202
|
+
],
|
|
156
203
|
};
|
|
157
204
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { transformAsync } from '@babel/core';
|
|
2
|
+
|
|
3
|
+
const BABEL_FILES = /\.[cm]?[jt]sx?$/;
|
|
4
|
+
const TS_FILES = /\.[cm]?tsx?$/;
|
|
5
|
+
const TS_WITHOUT_JSX = /\.[cm]?ts$/;
|
|
6
|
+
const COMMONJS_FILES = /\.c[jt]s$/;
|
|
7
|
+
|
|
8
|
+
/** @type {NonNullable<import('@babel/core').InputOptions['caller']> & { compiler: import('../babel-config.mjs').Compiler }} */
|
|
9
|
+
const CALLER = { name: 'code-infra build-new', compiler: 'oxc' };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Runs a Babel config in `oxc` mode: `getBaseConfig` keeps only the plugins Oxc has no
|
|
13
|
+
* equivalent for, and the config file adds its own. Oxc then strips types, compiles JSX and
|
|
14
|
+
* lowers syntax.
|
|
15
|
+
* @param {string} configFile
|
|
16
|
+
* @returns {import('tsdown').Rolldown.Plugin}
|
|
17
|
+
*/
|
|
18
|
+
export function babelPlugin(configFile) {
|
|
19
|
+
return {
|
|
20
|
+
name: 'code-infra:babel',
|
|
21
|
+
transform: {
|
|
22
|
+
// rolldown-plugin-dts turns declarations into JS stubs Babel can't parse.
|
|
23
|
+
filter: { id: { include: BABEL_FILES, exclude: [/node_modules/, /\.d\.[cm]?ts$/] } },
|
|
24
|
+
async handler(code, id) {
|
|
25
|
+
/** @type {NonNullable<import('@babel/core').InputOptions['parserOpts']>['plugins']} */
|
|
26
|
+
const syntax = [];
|
|
27
|
+
if (TS_FILES.test(id)) {
|
|
28
|
+
syntax.push('typescript');
|
|
29
|
+
}
|
|
30
|
+
if (!TS_WITHOUT_JSX.test(id)) {
|
|
31
|
+
syntax.push('jsx');
|
|
32
|
+
}
|
|
33
|
+
const result = await transformAsync(code, {
|
|
34
|
+
filename: id,
|
|
35
|
+
configFile,
|
|
36
|
+
babelrc: false,
|
|
37
|
+
caller: CALLER,
|
|
38
|
+
sourceMaps: true,
|
|
39
|
+
sourceType: COMMONJS_FILES.test(id) ? 'commonjs' : 'module',
|
|
40
|
+
parserOpts: { plugins: syntax },
|
|
41
|
+
});
|
|
42
|
+
if (!result?.code) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
code: result.code,
|
|
47
|
+
map: /** @type {import('tsdown').Rolldown.SourceMapInput} */ (result.map),
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
package/src/utils/build.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
+
import getTargets from '@babel/helper-compilation-targets';
|
|
3
4
|
import { globby } from 'globby';
|
|
4
5
|
import * as semver from 'semver';
|
|
5
6
|
|
|
@@ -793,6 +794,53 @@ export async function createPackageBin(bin, { bundles, cwd, packageType }) {
|
|
|
793
794
|
return newBin;
|
|
794
795
|
}
|
|
795
796
|
|
|
797
|
+
/**
|
|
798
|
+
* @param {unknown} value
|
|
799
|
+
* @returns {string[]}
|
|
800
|
+
*/
|
|
801
|
+
function getLeaves(value) {
|
|
802
|
+
if (typeof value === 'string') {
|
|
803
|
+
return [value];
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
if (!value || typeof value !== 'object') {
|
|
807
|
+
return [];
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
return Object.values(value).flatMap(getLeaves);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* The JS/TS sources the package's `exports`, `imports` and `bin` point at, relative to `cwd`.
|
|
815
|
+
* Glob patterns are expanded against the files on disk, as in the published `package.json`.
|
|
816
|
+
* @param {import('../cli/packageJson').PackageJson} packageJson
|
|
817
|
+
* @param {string} cwd
|
|
818
|
+
* @returns {Promise<string[]>}
|
|
819
|
+
*/
|
|
820
|
+
export async function getPackageSources({ exports, imports, bin }, cwd) {
|
|
821
|
+
const maps = await Promise.all(
|
|
822
|
+
[
|
|
823
|
+
typeof exports === 'string' || Array.isArray(exports) ? { '.': exports } : exports,
|
|
824
|
+
imports,
|
|
825
|
+
].map((map) =>
|
|
826
|
+
expandExportGlobs(
|
|
827
|
+
/** @type {import('../cli/packageJson').PackageJson.ExportConditions} */ (map ?? {}),
|
|
828
|
+
cwd,
|
|
829
|
+
),
|
|
830
|
+
),
|
|
831
|
+
);
|
|
832
|
+
|
|
833
|
+
return [...new Set(getLeaves([...maps, bin]))].flatMap((leaf) => {
|
|
834
|
+
const rel = srcRelative(leaf);
|
|
835
|
+
|
|
836
|
+
if (rel === null || rel.includes('*') || !JS_TS_EXTENSIONS.has(path.extname(rel))) {
|
|
837
|
+
return [];
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
return [path.posix.join('src', rel)];
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
|
|
796
844
|
/**
|
|
797
845
|
* Validates the package.json before building.
|
|
798
846
|
* @param {Record<string, any>} packageJson
|
|
@@ -867,6 +915,39 @@ export function validatePkgJson(packageJson, options = {}) {
|
|
|
867
915
|
}
|
|
868
916
|
}
|
|
869
917
|
|
|
918
|
+
/**
|
|
919
|
+
* Validates that "engines.node" in package.json doesn't allow Node.js versions older than the
|
|
920
|
+
* "node" browserslist environment, which the CommonJS bundle is compiled for. Otherwise the
|
|
921
|
+
* build can emit syntax that the oldest supported Node.js version can't run.
|
|
922
|
+
* Targets are resolved the same way `@babel/preset-env` resolves them during the build.
|
|
923
|
+
* @param {{ name?: string; engines?: { node?: string } }} packageJson
|
|
924
|
+
* @param {string} cwd - The package directory, used to find the browserslist config.
|
|
925
|
+
*/
|
|
926
|
+
export function validateEnginesNode(packageJson, cwd) {
|
|
927
|
+
const enginesNode = packageJson.engines?.node;
|
|
928
|
+
if (!enginesNode) {
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
const minEnginesVersion = semver.minVersion(enginesNode);
|
|
933
|
+
if (!minEnginesVersion) {
|
|
934
|
+
throw new Error(
|
|
935
|
+
`Unable to determine the minimum Node.js version from "engines.node" in "${packageJson.name}" package.json: "${enginesNode}".`,
|
|
936
|
+
);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
const targetNode = getTargets(undefined, { configPath: cwd, browserslistEnv: 'node' }).node;
|
|
940
|
+
if (!targetNode) {
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
if (semver.gt(targetNode, minEnginesVersion)) {
|
|
945
|
+
throw new Error(
|
|
946
|
+
`"engines.node" in "${packageJson.name}" package.json allows Node.js ${minEnginesVersion.version}, but the "node" browserslist environment compiles for Node.js ${targetNode} and up. Raise "engines.node" to at least ${targetNode}, or lower the "node" browserslist target.`,
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
870
951
|
/**
|
|
871
952
|
* Marks the start and end of a function execution for performance measurement.
|
|
872
953
|
* Uses the Performance API to create marks and measure the duration.
|