@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
|
@@ -1,48 +1,463 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import {
|
|
2
|
+
import { $ } from 'execa';
|
|
3
3
|
import * as fs from 'node:fs/promises';
|
|
4
|
+
import * as os from 'node:os';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import { mapAsync, uniqBy } from 'es-toolkit/array';
|
|
7
|
+
import { isEqual } from 'es-toolkit/predicate';
|
|
4
8
|
import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
|
|
5
|
-
import {
|
|
9
|
+
import { resolveExports } from 'resolve-pkg-maps';
|
|
10
|
+
import * as semver from 'semver';
|
|
11
|
+
import { stringify } from 'yaml';
|
|
12
|
+
import { getWorkspacePackages, readPackageJson, writePackageJson } from '../utils/pnpm.mjs';
|
|
13
|
+
import { findTscPair } from '../utils/typescript.mjs';
|
|
6
14
|
|
|
7
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {import('./packageJson').PackageJson} PackageJson
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {Object} TypeScriptError
|
|
21
|
+
* @property {string} file `<package>/<path>` for files inside a packed package, otherwise relative
|
|
22
|
+
* to the consumer project.
|
|
23
|
+
* @property {string} code
|
|
24
|
+
* @property {string} message
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {Map<string, string>} EntryPoints Import specifier to the declaration file it resolves
|
|
29
|
+
* to.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The kinds of consumers, with the runtime `exports` conditions each matches besides `default`.
|
|
34
|
+
* `types` comes first in every published manifest, so matching it in all modes is what TypeScript
|
|
35
|
+
* does too.
|
|
36
|
+
*/
|
|
37
|
+
const CONSUMERS = [
|
|
38
|
+
{ kind: 'esm', extension: 'mts', conditions: ['import', 'node'], module: 'nodenext' },
|
|
39
|
+
{ kind: 'cjs', extension: 'cts', conditions: ['require', 'node'], module: 'nodenext' },
|
|
40
|
+
{
|
|
41
|
+
kind: 'bundler',
|
|
42
|
+
extension: 'mts',
|
|
43
|
+
conditions: ['import'],
|
|
44
|
+
module: 'esnext',
|
|
45
|
+
moduleResolution: 'bundler',
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {unknown} packageExports
|
|
51
|
+
* @param {string} subpath `''` for the package itself.
|
|
52
|
+
* @param {string[]} conditions
|
|
53
|
+
* @returns {string | undefined} The first target, or `undefined` when the subpath doesn't resolve.
|
|
54
|
+
*/
|
|
55
|
+
function resolveTarget(packageExports, subpath, conditions) {
|
|
56
|
+
try {
|
|
57
|
+
return resolveExports(
|
|
58
|
+
/** @type {Parameters<typeof resolveExports>[0]} */ (packageExports),
|
|
59
|
+
subpath,
|
|
60
|
+
conditions,
|
|
61
|
+
)[0];
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (/** @type {{ code?: string }} */ (error).code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Lists the modules consumers can import types from under `conditions`. Glob subpaths are skipped:
|
|
72
|
+
* `code-infra build` expands them into concrete entries. Entry points without a runtime target,
|
|
73
|
+
* such as code-infra's `build-env`, are left out: nothing imports them.
|
|
74
|
+
*
|
|
75
|
+
* @param {PackageJson} packageJson A published manifest.
|
|
76
|
+
* @param {string[]} conditions
|
|
77
|
+
* @returns {EntryPoints}
|
|
78
|
+
*/
|
|
79
|
+
function getTypedEntryPoints(packageJson, conditions) {
|
|
80
|
+
const name = /** @type {string} */ (packageJson.name);
|
|
81
|
+
const types = packageJson.types ?? packageJson.typings;
|
|
82
|
+
const packageExports =
|
|
83
|
+
packageJson.exports ?? (types ? { types, default: packageJson.main ?? './index.js' } : null);
|
|
84
|
+
if (!packageExports) {
|
|
85
|
+
return new Map();
|
|
86
|
+
}
|
|
87
|
+
const subpaths =
|
|
88
|
+
typeof packageExports === 'object' &&
|
|
89
|
+
!Array.isArray(packageExports) &&
|
|
90
|
+
Object.keys(packageExports).some((key) => key.startsWith('.'))
|
|
91
|
+
? Object.keys(packageExports)
|
|
92
|
+
.filter((key) => !key.includes('*'))
|
|
93
|
+
.map((key) => key.slice(2))
|
|
94
|
+
: [''];
|
|
95
|
+
/** @type {EntryPoints} */
|
|
96
|
+
const entryPoints = new Map();
|
|
97
|
+
for (const subpath of subpaths) {
|
|
98
|
+
const declarations = resolveTarget(packageExports, subpath, ['types', ...conditions]);
|
|
99
|
+
if (
|
|
100
|
+
declarations &&
|
|
101
|
+
/\.d\.[cm]?ts$/.test(declarations) &&
|
|
102
|
+
resolveTarget(packageExports, subpath, conditions)
|
|
103
|
+
) {
|
|
104
|
+
entryPoints.set(subpath ? `${name}/${subpath}` : name, declarations);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return entryPoints;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {EntryPoints} entryPoints
|
|
112
|
+
* @returns {string}
|
|
113
|
+
*/
|
|
114
|
+
function createEntryFile(entryPoints) {
|
|
115
|
+
return `${Array.from(entryPoints.keys())
|
|
116
|
+
.map((specifier, index) => `import type * as entry${index} from '${specifier}';`)
|
|
117
|
+
.join('\n')}\nexport {};\n`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* `@scope/pkg` → `scope+pkg`, the same file names as @mui/internal-benchmark's `packWorkspace`.
|
|
122
|
+
* `+` cannot appear in a package name, so no two collide.
|
|
123
|
+
*
|
|
124
|
+
* @param {string} packageName
|
|
125
|
+
*/
|
|
126
|
+
function toFileStem(packageName) {
|
|
127
|
+
return packageName.replace(/^@/, '').replace('/', '+');
|
|
128
|
+
}
|
|
8
129
|
|
|
9
130
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
131
|
+
* The range of versions that satisfy both `a` and `b`.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} name
|
|
134
|
+
* @param {string} a
|
|
135
|
+
* @param {string} b
|
|
136
|
+
* @returns {string}
|
|
12
137
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
138
|
+
function intersectRanges(name, a, b) {
|
|
139
|
+
if (!semver.validRange(a) || !semver.validRange(b)) {
|
|
140
|
+
return a;
|
|
141
|
+
}
|
|
142
|
+
const setsOf = (/** @type {string} */ range) =>
|
|
143
|
+
new semver.Range(range).set.map((comparators) => comparators.map(String).join(' '));
|
|
144
|
+
const intersection = setsOf(a)
|
|
145
|
+
.flatMap((setA) => setsOf(b).map((setB) => `${setA} ${setB}`.trim()))
|
|
146
|
+
.filter((range) => semver.intersects(range, range));
|
|
147
|
+
if (intersection.length === 0) {
|
|
148
|
+
throw new Error(`No version of "${name}" satisfies every peer range: "${a}" and "${b}".`);
|
|
149
|
+
}
|
|
150
|
+
return intersection.join(' || ');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Parses the errors in `tsc --pretty false` output that point at a file.
|
|
155
|
+
*
|
|
156
|
+
* @param {string} output
|
|
157
|
+
* @returns {TypeScriptError[]}
|
|
158
|
+
*/
|
|
159
|
+
function parseTypeScriptErrors(output) {
|
|
160
|
+
/** @type {TypeScriptError[]} */
|
|
161
|
+
const errors = [];
|
|
162
|
+
for (const line of output.split(/\r?\n/)) {
|
|
163
|
+
const match = /^(.+?)\(\d+,\d+\): error (TS\d+): (.*)$/.exec(line);
|
|
164
|
+
if (match) {
|
|
165
|
+
errors.push({ file: match[1], code: match[2], message: match[3] });
|
|
166
|
+
} else if (line.startsWith(' ') && errors.length > 0) {
|
|
167
|
+
errors[errors.length - 1].message += `\n${line}`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return errors;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Keeps the errors in the packed packages and the generated entry files. Errors inside a packed
|
|
175
|
+
* package are reported relative to that package, so the output doesn't depend on the store layout.
|
|
176
|
+
*
|
|
177
|
+
* @param {TypeScriptError[]} errors
|
|
178
|
+
* @param {string[]} packageNames
|
|
179
|
+
* @param {string} tempDir Stripped from messages.
|
|
180
|
+
* @returns {TypeScriptError[]}
|
|
181
|
+
*/
|
|
182
|
+
function getOwnErrors(errors, packageNames, tempDir) {
|
|
183
|
+
return errors.flatMap((error) => {
|
|
184
|
+
const message = error.message.replaceAll(`${tempDir}/`, '');
|
|
185
|
+
const index = error.file.lastIndexOf('node_modules/');
|
|
186
|
+
if (index === -1) {
|
|
187
|
+
return [{ ...error, message }];
|
|
188
|
+
}
|
|
189
|
+
const modulePath = error.file.slice(index + 'node_modules/'.length);
|
|
190
|
+
const owner = packageNames.find((name) => modulePath.startsWith(`${name}/`));
|
|
191
|
+
// Errors in third-party declarations are not ours to fix.
|
|
192
|
+
return owner ? [{ ...error, file: modulePath, message }] : [];
|
|
21
193
|
});
|
|
194
|
+
}
|
|
22
195
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{ concurrency: 20 },
|
|
32
|
-
)
|
|
33
|
-
).filter((file) => typeof file === 'string');
|
|
196
|
+
/**
|
|
197
|
+
* @param {string} tarball
|
|
198
|
+
* @returns {Promise<PackageJson>}
|
|
199
|
+
*/
|
|
200
|
+
async function readPackedManifest(tarball) {
|
|
201
|
+
const { stdout } = await $`tar -xzOf ${tarball} package/package.json`;
|
|
202
|
+
return JSON.parse(stdout);
|
|
203
|
+
}
|
|
34
204
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
205
|
+
/**
|
|
206
|
+
* Installs the packed public packages into a fresh project, the way a consumer would, and
|
|
207
|
+
* type-checks an import of every typed entry point with `skipLibCheck` off.
|
|
208
|
+
*
|
|
209
|
+
* @param {Object} options
|
|
210
|
+
* @param {string} options.workspaceRoot
|
|
211
|
+
* @param {string} options.tempDir An empty directory outside the workspace.
|
|
212
|
+
* @returns {Promise<{ errors: TypeScriptError[], entryPointCount: number, packageCount: number }>}
|
|
213
|
+
*/
|
|
214
|
+
async function validateBuiltTypes({ workspaceRoot, tempDir }) {
|
|
215
|
+
const packages = await getWorkspacePackages({ cwd: workspaceRoot, publicOnly: true });
|
|
216
|
+
if (packages.length === 0) {
|
|
217
|
+
throw new Error('No public packages found.');
|
|
218
|
+
}
|
|
219
|
+
const tarballDir = path.join(tempDir, 'tarballs');
|
|
220
|
+
const projectDir = path.join(tempDir, 'project');
|
|
221
|
+
await Promise.all([
|
|
222
|
+
fs.mkdir(tarballDir, { recursive: true }),
|
|
223
|
+
fs.mkdir(path.join(projectDir, 'checks'), { recursive: true }),
|
|
224
|
+
]);
|
|
225
|
+
|
|
226
|
+
// Packed like @mui/internal-benchmark's `packWorkspace`, so each tarball is what `pnpm publish`
|
|
227
|
+
// would upload.
|
|
228
|
+
const packed = await mapAsync(
|
|
229
|
+
packages,
|
|
230
|
+
async (pkg) => {
|
|
231
|
+
const tarball = path.join(tarballDir, `${toFileStem(pkg.name)}.tgz`);
|
|
232
|
+
await $({ cwd: pkg.path })`pnpm pack --out ${tarball}`;
|
|
233
|
+
return { tarball, manifest: await readPackedManifest(tarball), dir: pkg.path };
|
|
234
|
+
},
|
|
235
|
+
{ concurrency: os.availableParallelism() },
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
/** @type {Record<string, string>} */
|
|
239
|
+
const tarballs = Object.fromEntries(
|
|
240
|
+
packed.map(({ manifest, tarball }) => [manifest.name, `file:${tarball}`]),
|
|
241
|
+
);
|
|
242
|
+
const packageNames = Object.keys(tarballs);
|
|
243
|
+
// Consumers provide every peer, optional ones included, at a version in range of every package.
|
|
244
|
+
// The versions the workspace installed for its packages come first: they are fixed by the
|
|
245
|
+
// lockfile, so a new upstream release can't change the outcome until the workspace updates.
|
|
246
|
+
const declaredPeers = await Promise.all(
|
|
247
|
+
packed.flatMap(({ manifest, dir }) =>
|
|
248
|
+
Object.entries(manifest.peerDependencies ?? {})
|
|
249
|
+
.filter(([name, range]) => range && !tarballs[name])
|
|
250
|
+
.map(async ([name, range]) => {
|
|
251
|
+
const installed = await readPackageJson(path.join(dir, 'node_modules', name)).catch(
|
|
252
|
+
() => undefined,
|
|
253
|
+
);
|
|
254
|
+
return {
|
|
255
|
+
name,
|
|
256
|
+
range: /** @type {string} */ (range),
|
|
257
|
+
version: installed?.version,
|
|
258
|
+
// An aliased install, such as `typescript: npm:@typescript/typescript6@6.0.2`.
|
|
259
|
+
spec:
|
|
260
|
+
installed?.name === name
|
|
261
|
+
? installed.version
|
|
262
|
+
: `npm:${installed?.name}@${installed?.version}`,
|
|
263
|
+
};
|
|
264
|
+
}),
|
|
265
|
+
),
|
|
266
|
+
);
|
|
267
|
+
/** @type {Record<string, string>} */
|
|
268
|
+
const peerRanges = {};
|
|
269
|
+
for (const { name, range } of declaredPeers) {
|
|
270
|
+
peerRanges[name] = peerRanges[name] ? intersectRanges(name, peerRanges[name], range) : range;
|
|
271
|
+
}
|
|
272
|
+
/** @type {Record<string, string>} */
|
|
273
|
+
const peers = {};
|
|
274
|
+
for (const [name, range] of Object.entries(peerRanges)) {
|
|
275
|
+
peers[name] =
|
|
276
|
+
declaredPeers.find(
|
|
277
|
+
(peer) => peer.name === name && peer.version && semver.satisfies(peer.version, range),
|
|
278
|
+
)?.spec ?? range;
|
|
279
|
+
}
|
|
280
|
+
// Installed as in any project that uses Node packages, but not made ambient: a program only loads
|
|
281
|
+
// Node types when declarations reference them, so they don't reach sources that shouldn't see them.
|
|
282
|
+
peers['@types/node'] ??= await readPackageJson(
|
|
283
|
+
path.join(workspaceRoot, 'node_modules', '@types/node'),
|
|
284
|
+
).then(
|
|
285
|
+
(packageJson) => packageJson.version ?? '*',
|
|
286
|
+
() => '*',
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
// One program per package and consumer kind. A consumer is either ESM or CommonJS, and installs
|
|
290
|
+
// one package rather than all of them: a shared program would check the global augmentations of
|
|
291
|
+
// unrelated packages, and of a package's CommonJS and ESM declarations, against each other.
|
|
292
|
+
// CommonJS and bundler consumers only get a program of their own when they resolve other
|
|
293
|
+
// declarations than ESM consumers; on the same files, they find nothing an ESM program misses.
|
|
294
|
+
const checks = packed.flatMap(({ manifest }) => {
|
|
295
|
+
const stem = path.join('checks', toFileStem(/** @type {string} */ (manifest.name)));
|
|
296
|
+
const [esm, ...others] = CONSUMERS.map(({ kind, extension, conditions, ...options }) => ({
|
|
297
|
+
file: `${stem}.${kind}.${extension}`,
|
|
298
|
+
entryPoints: getTypedEntryPoints(manifest, conditions),
|
|
299
|
+
...options,
|
|
300
|
+
}));
|
|
301
|
+
return [
|
|
302
|
+
esm,
|
|
303
|
+
...others.filter(({ entryPoints }) => !isEqual(entryPoints, esm.entryPoints)),
|
|
304
|
+
].filter(({ entryPoints }) => entryPoints.size > 0);
|
|
305
|
+
});
|
|
306
|
+
const entryPointCount = new Set(
|
|
307
|
+
checks.flatMap(({ entryPoints }) => Array.from(entryPoints.keys())),
|
|
308
|
+
).size;
|
|
309
|
+
if (entryPointCount === 0) {
|
|
310
|
+
throw new Error(
|
|
311
|
+
`No entry points with types found in ${packed.length} packages. Build the packages first.`,
|
|
312
|
+
);
|
|
39
313
|
}
|
|
40
314
|
|
|
41
|
-
|
|
315
|
+
await writePackageJson(projectDir, { private: true, dependencies: { ...peers, ...tarballs } });
|
|
316
|
+
// Every package and peer is a dependency of the project, so a package that looked them up from
|
|
317
|
+
// the project's node_modules would resolve what it never declared. With hoisting off and the
|
|
318
|
+
// virtual store outside the project, it only finds the dependencies pnpm linked for it.
|
|
319
|
+
await fs.writeFile(
|
|
320
|
+
path.join(projectDir, 'pnpm-workspace.yaml'),
|
|
321
|
+
stringify({
|
|
322
|
+
virtualStoreDir: '../virtual-store',
|
|
323
|
+
enableGlobalVirtualStore: false,
|
|
324
|
+
hoistPattern: [],
|
|
325
|
+
publicHoistPattern: [],
|
|
326
|
+
autoInstallPeers: false,
|
|
327
|
+
strictPeerDependencies: false,
|
|
328
|
+
blockExoticSubdeps: false,
|
|
329
|
+
ignoreScripts: true,
|
|
330
|
+
overrides: tarballs,
|
|
331
|
+
}),
|
|
332
|
+
);
|
|
333
|
+
await $({ cwd: projectDir })`pnpm install --lockfile=false --prefer-offline`;
|
|
334
|
+
|
|
335
|
+
const compilerOptions = {
|
|
336
|
+
strict: true,
|
|
337
|
+
skipLibCheck: false,
|
|
338
|
+
noEmit: true,
|
|
339
|
+
types: [],
|
|
340
|
+
lib: ['esnext', 'dom', 'dom.iterable'],
|
|
341
|
+
jsx: 'react-jsx',
|
|
342
|
+
};
|
|
343
|
+
const { native, js } = await findTscPair(workspaceRoot);
|
|
344
|
+
const tsc = native ?? js;
|
|
345
|
+
const realTempDir = await fs.realpath(tempDir);
|
|
346
|
+
const ownErrors = await mapAsync(
|
|
347
|
+
checks,
|
|
348
|
+
async ({ file, entryPoints, module, moduleResolution }) => {
|
|
349
|
+
const tsconfigFile = `${file}.json`;
|
|
350
|
+
await Promise.all([
|
|
351
|
+
fs.writeFile(path.join(projectDir, file), createEntryFile(entryPoints)),
|
|
352
|
+
fs.writeFile(
|
|
353
|
+
path.join(projectDir, tsconfigFile),
|
|
354
|
+
`${JSON.stringify({ compilerOptions: { ...compilerOptions, module, moduleResolution }, files: [path.basename(file)] }, null, 2)}\n`,
|
|
355
|
+
),
|
|
356
|
+
]);
|
|
357
|
+
const result = await $({
|
|
358
|
+
cwd: projectDir,
|
|
359
|
+
reject: false,
|
|
360
|
+
})`${tsc} -p ${tsconfigFile} --pretty false`;
|
|
361
|
+
const fileErrors = parseTypeScriptErrors(result.stdout);
|
|
362
|
+
// Errors in third-party declarations also fail tsc, but a failure without any error in a
|
|
363
|
+
// file means tsc didn't check the program at all.
|
|
364
|
+
if (result.failed && fileErrors.length === 0) {
|
|
365
|
+
throw new Error(
|
|
366
|
+
`TypeScript failed to check ${tsconfigFile}:\n${result.stdout || result.stderr || result.message}`,
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
return getOwnErrors(fileErrors, packageNames, realTempDir);
|
|
370
|
+
},
|
|
371
|
+
// Native tsc checks on several threads of its own and takes hundreds of MB per program.
|
|
372
|
+
{
|
|
373
|
+
concurrency: native
|
|
374
|
+
? Math.max(1, Math.floor(os.availableParallelism() / 4))
|
|
375
|
+
: os.availableParallelism(),
|
|
376
|
+
},
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
return {
|
|
380
|
+
errors: uniqBy(ownErrors.flat(), (error) => `${error.file}\0${error.code}\0${error.message}`),
|
|
381
|
+
entryPointCount,
|
|
382
|
+
packageCount: packed.length,
|
|
383
|
+
};
|
|
42
384
|
}
|
|
43
385
|
|
|
44
|
-
|
|
386
|
+
/**
|
|
387
|
+
* @typedef {Object} Args
|
|
388
|
+
* @property {boolean} keep
|
|
389
|
+
* @property {string[]} [expectError]
|
|
390
|
+
*/
|
|
391
|
+
|
|
392
|
+
export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
45
393
|
command: 'validate-built-types',
|
|
46
|
-
describe:
|
|
47
|
-
|
|
394
|
+
describe:
|
|
395
|
+
'Install the packed public packages into a fresh project and type-check every entry point that has types, as a consumer would. Run after building.',
|
|
396
|
+
builder: (yargs) =>
|
|
397
|
+
yargs
|
|
398
|
+
.option('keep', {
|
|
399
|
+
type: 'boolean',
|
|
400
|
+
default: false,
|
|
401
|
+
description: 'Keep the consumer project for inspection.',
|
|
402
|
+
})
|
|
403
|
+
.option('expect-error', {
|
|
404
|
+
type: 'string',
|
|
405
|
+
array: true,
|
|
406
|
+
default: [],
|
|
407
|
+
description:
|
|
408
|
+
'A path in a package, such as `@scope/pkg/subdir`, whose declarations are known to fail. Errors in files under it are not reported, and the check fails once there are none. Repeatable.',
|
|
409
|
+
}),
|
|
410
|
+
handler: async ({ keep, expectError = [] }) => {
|
|
411
|
+
const workspaceRoot = await findWorkspaceDir(process.cwd());
|
|
412
|
+
if (!workspaceRoot) {
|
|
413
|
+
throw new Error('Workspace directory not found');
|
|
414
|
+
}
|
|
415
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'code-infra-built-types-'));
|
|
416
|
+
let failed = false;
|
|
417
|
+
try {
|
|
418
|
+
const { errors, entryPointCount, packageCount } = await validateBuiltTypes({
|
|
419
|
+
workspaceRoot,
|
|
420
|
+
tempDir,
|
|
421
|
+
});
|
|
422
|
+
// Errors are matched by the file they are in rather than by entry point: declarations can
|
|
423
|
+
// fail only next to another entry point's, such as conflicting module augmentations.
|
|
424
|
+
const expectedPaths = expectError.map((expected) => expected.replace(/\/+$/, ''));
|
|
425
|
+
const isUnder = (/** @type {string} */ file, /** @type {string} */ prefix) =>
|
|
426
|
+
file === prefix || file.startsWith(`${prefix}/`);
|
|
427
|
+
const unexpectedErrors = errors.filter(
|
|
428
|
+
(error) => !expectedPaths.some((prefix) => isUnder(error.file, prefix)),
|
|
429
|
+
);
|
|
430
|
+
for (const expected of expectedPaths) {
|
|
431
|
+
const count = errors.filter((error) => isUnder(error.file, expected)).length;
|
|
432
|
+
if (count > 0) {
|
|
433
|
+
console.log(`Ignoring ${count} expected type errors in ${expected}.`);
|
|
434
|
+
} else {
|
|
435
|
+
failed = true;
|
|
436
|
+
console.error(`❌ No type errors in ${expected}: remove it from --expect-error.`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if (unexpectedErrors.length > 0) {
|
|
440
|
+
failed = true;
|
|
441
|
+
console.error(
|
|
442
|
+
`❌ Found ${unexpectedErrors.length} type errors in ${entryPointCount} entry points of ${packageCount} packages.\n`,
|
|
443
|
+
);
|
|
444
|
+
for (const error of unexpectedErrors) {
|
|
445
|
+
console.error(`${error.file}: ${error.code} ${error.message}`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (failed) {
|
|
449
|
+
process.exitCode = 1;
|
|
450
|
+
} else {
|
|
451
|
+
console.log(
|
|
452
|
+
`✅ ${entryPointCount} entry points of ${packageCount} packages type-check for consumers.`,
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
} finally {
|
|
456
|
+
if (keep || failed) {
|
|
457
|
+
console.error(`\nConsumer project: ${path.join(tempDir, 'project')}`);
|
|
458
|
+
} else {
|
|
459
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
},
|
|
48
463
|
});
|
package/src/cli/index.mjs
CHANGED
|
@@ -4,7 +4,9 @@ import yargs from 'yargs';
|
|
|
4
4
|
import { hideBin } from 'yargs/helpers';
|
|
5
5
|
|
|
6
6
|
import cmdArgosPush from './cmdArgosPush.mjs';
|
|
7
|
+
import cmdBaseline from './cmdBaseline.mjs';
|
|
7
8
|
import cmdBuild from './cmdBuild.mjs';
|
|
9
|
+
import cmdBuildNew from './cmdBuildNew.mjs';
|
|
8
10
|
import cmdCopyFiles from './cmdCopyFiles.mjs';
|
|
9
11
|
import cmdExtractErrorCodes from './cmdExtractErrorCodes.mjs';
|
|
10
12
|
import cmdGenerateChangelog from './cmdGenerateChangelog.mjs';
|
|
@@ -38,7 +40,9 @@ await yargs(hideBin(process.argv))
|
|
|
38
40
|
globalArgv = argv;
|
|
39
41
|
}, true)
|
|
40
42
|
.command(cmdArgosPush)
|
|
43
|
+
.command(cmdBaseline)
|
|
41
44
|
.command(cmdBuild)
|
|
45
|
+
.command(cmdBuildNew)
|
|
42
46
|
.command(cmdCopyFiles)
|
|
43
47
|
.command(cmdExtractErrorCodes)
|
|
44
48
|
.command(cmdGenerateChangelog)
|
|
@@ -3,6 +3,7 @@ import eslintJs from '@eslint/js';
|
|
|
3
3
|
import { defineConfig } from 'eslint/config';
|
|
4
4
|
import prettier from 'eslint-config-prettier/flat';
|
|
5
5
|
import compatPlugin from 'eslint-plugin-compat';
|
|
6
|
+
import nPlugin from 'eslint-plugin-n';
|
|
6
7
|
import importPlugin from 'eslint-plugin-import';
|
|
7
8
|
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
|
|
8
9
|
import reactPlugin from 'eslint-plugin-react';
|
|
@@ -17,6 +18,8 @@ import { createCoreConfig } from './mui/config.mjs';
|
|
|
17
18
|
import muiPlugin from './mui/index.mjs';
|
|
18
19
|
import { EXTENSION_TS } from './extensions.mjs';
|
|
19
20
|
import { createJsonConfig } from './jsonConfig.mjs';
|
|
21
|
+
import { createNodeSupportConfig } from './nodeSupportConfig.mjs';
|
|
22
|
+
import { createPackageJsonConfig } from './packageJsonConfig.mjs';
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
25
|
* @param {string} filePath
|
|
@@ -32,7 +35,7 @@ function includeIgnoreIfExists(filePath, description) {
|
|
|
32
35
|
/**
|
|
33
36
|
* @param {Object} [params]
|
|
34
37
|
* @param {boolean} [params.enableReactCompiler] - Whether to enable React Compiler.
|
|
35
|
-
* @param {boolean} [params.consistentTypeImports] - Whether to enforce consistent type imports.
|
|
38
|
+
* @param {boolean} [params.consistentTypeImports] - Whether to enforce consistent type imports. Defaults to `true`.
|
|
36
39
|
* @param {boolean} [params.materialUi] - Whether to enable Material UI specific rules (mui/material-ui-*).
|
|
37
40
|
* @param {string} [params.baseDirectory] - The base directory for the configuration.
|
|
38
41
|
* @param {boolean} [params.markdown] - @deprecated Markdown/MDX linting is enabled by default; this option no longer needs to be passed. To skip markdown linting, use eslint ignore patterns for the relevant files.
|
|
@@ -40,7 +43,7 @@ function includeIgnoreIfExists(filePath, description) {
|
|
|
40
43
|
*/
|
|
41
44
|
export function createBaseConfig({
|
|
42
45
|
enableReactCompiler = false,
|
|
43
|
-
consistentTypeImports =
|
|
46
|
+
consistentTypeImports = true,
|
|
44
47
|
materialUi = false,
|
|
45
48
|
markdown = true,
|
|
46
49
|
baseDirectory = process.cwd(),
|
|
@@ -58,6 +61,9 @@ export function createBaseConfig({
|
|
|
58
61
|
},
|
|
59
62
|
plugins: {
|
|
60
63
|
mui: muiPlugin,
|
|
64
|
+
// Registered once for all files, so consumers can enable `n/*` rules without registering
|
|
65
|
+
// a second, possibly different, instance of the plugin.
|
|
66
|
+
n: nPlugin,
|
|
61
67
|
},
|
|
62
68
|
settings: {
|
|
63
69
|
react: {
|
|
@@ -73,6 +79,8 @@ export function createBaseConfig({
|
|
|
73
79
|
includeIgnoreIfExists(path.join(baseDirectory, '.gitignore'), `Ignore rules from .gitignore`),
|
|
74
80
|
includeIgnoreIfExists(path.join(baseDirectory, '.lintignore'), `Ignore rules from .lintignore`),
|
|
75
81
|
createJsonConfig(),
|
|
82
|
+
createNodeSupportConfig(baseDirectory),
|
|
83
|
+
createPackageJsonConfig(),
|
|
76
84
|
prettier,
|
|
77
85
|
// Markdown + MDX linting via eslint-plugin-mdx. Severities for markdown
|
|
78
86
|
// quality checks live in the project's `.remarkrc` (see
|
|
@@ -19,17 +19,35 @@ export function createDocsConfig() {
|
|
|
19
19
|
? nextjsAlias.flatConfig.recommended
|
|
20
20
|
: nextjsAlias.configs.recommended;
|
|
21
21
|
|
|
22
|
-
return defineConfig(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
return defineConfig(
|
|
23
|
+
recommendedConfig,
|
|
24
|
+
{
|
|
25
|
+
settings: {
|
|
26
|
+
next: {
|
|
27
|
+
rootDir: 'docs',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
files: [`**/*${EXTENSION_TS}`],
|
|
31
|
+
rules: {
|
|
32
|
+
'compat/compat': 'off',
|
|
33
|
+
'jsx-a11y/anchor-is-valid': 'off',
|
|
34
|
+
'no-irregular-whitespace': ['error', { skipJSXText: true, skipStrings: true }],
|
|
26
35
|
},
|
|
27
36
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
{
|
|
38
|
+
// Build configuration and maintenance scripts aren't documentation examples
|
|
39
|
+
// and are often intentionally outside the docs TypeScript project.
|
|
40
|
+
files: [`**/*${EXTENSION_TS}`],
|
|
41
|
+
ignores: ['**/*.config.*', '**/scripts/**'],
|
|
42
|
+
languageOptions: {
|
|
43
|
+
parserOptions: {
|
|
44
|
+
projectService: true,
|
|
45
|
+
tsconfigRootDir: process.cwd(),
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
rules: {
|
|
49
|
+
'@typescript-eslint/no-deprecated': 'error',
|
|
50
|
+
},
|
|
33
51
|
},
|
|
34
|
-
|
|
52
|
+
);
|
|
35
53
|
}
|
package/src/eslint/index.mjs
CHANGED
|
@@ -9,7 +9,8 @@ export function createJsonConfig() {
|
|
|
9
9
|
{
|
|
10
10
|
name: 'JSON files',
|
|
11
11
|
files: ['**/*.json'],
|
|
12
|
-
|
|
12
|
+
// package.json is linted by eslint-plugin-package-json, whose rules need the jsonc-eslint-parser AST.
|
|
13
|
+
ignores: ['package-lock.json', '**/package.json'],
|
|
13
14
|
plugins: { json },
|
|
14
15
|
language: 'json/json',
|
|
15
16
|
extends: [json.configs.recommended],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineConfig } from 'eslint/config';
|
|
2
|
-
import { EXTENSION_DTS } from '../extensions.mjs';
|
|
2
|
+
import { EXTENSION_DTS, EXTENSION_TS_ONLY } from '../extensions.mjs';
|
|
3
3
|
|
|
4
4
|
const restrictedMethods = ['setTimeout', 'setInterval', 'clearTimeout', 'clearInterval'];
|
|
5
5
|
|
|
@@ -184,6 +184,14 @@ const typescriptOverrides = {
|
|
|
184
184
|
// TypeScript equivalents of ESLint rules
|
|
185
185
|
'default-param-last': 'off',
|
|
186
186
|
'@typescript-eslint/default-param-last': 'error',
|
|
187
|
+
'@typescript-eslint/ban-ts-comment': [
|
|
188
|
+
'error',
|
|
189
|
+
{
|
|
190
|
+
'ts-expect-error': 'allow-with-description',
|
|
191
|
+
'ts-ignore': true,
|
|
192
|
+
minimumDescriptionLength: 10,
|
|
193
|
+
},
|
|
194
|
+
],
|
|
187
195
|
'no-array-constructor': 'off',
|
|
188
196
|
'@typescript-eslint/no-array-constructor': 'error',
|
|
189
197
|
'@typescript-eslint/triple-slash-reference': 'off',
|
|
@@ -538,6 +546,13 @@ export function createCoreConfig(options = {}) {
|
|
|
538
546
|
'@typescript-eslint/return-await': 'off',
|
|
539
547
|
},
|
|
540
548
|
},
|
|
549
|
+
{
|
|
550
|
+
name: 'mui-base/ts',
|
|
551
|
+
files: [`**/*${EXTENSION_TS_ONLY}`],
|
|
552
|
+
rules: {
|
|
553
|
+
'mui/no-constructor-assigned-field': 'error',
|
|
554
|
+
},
|
|
555
|
+
},
|
|
541
556
|
{
|
|
542
557
|
name: 'mui-base/dts',
|
|
543
558
|
files: [`**/*${EXTENSION_DTS}`],
|