@mui/internal-code-infra 0.0.4-canary.7 → 0.0.4-canary.70
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/LICENSE +1 -1
- package/README.md +19 -8
- package/build/babel-config.d.mts +11 -3
- package/build/brokenLinksChecker/crawlWorker.d.mts +1 -0
- package/build/brokenLinksChecker/index.d.mts +45 -2
- package/build/changelog/types.d.ts +1 -1
- package/build/cli/cmdArgosPush.d.mts +2 -2
- package/build/cli/cmdBuild.d.mts +3 -2
- package/build/cli/cmdCopyFiles.d.mts +2 -2
- package/build/cli/cmdExtractErrorCodes.d.mts +2 -2
- package/build/cli/cmdGenerateChangelog.d.mts +2 -2
- package/build/cli/cmdGithubAuth.d.mts +2 -2
- package/build/cli/cmdListWorkspaces.d.mts +6 -4
- package/build/cli/cmdNetlifyIgnore.d.mts +3 -2
- package/build/cli/cmdPublish.d.mts +4 -2
- package/build/cli/cmdPublishCanary.d.mts +3 -3
- package/build/cli/cmdPublishNewPackage.d.mts +4 -2
- package/build/cli/cmdSetVersionOverrides.d.mts +2 -2
- package/build/cli/cmdVale.d.mts +46 -0
- package/build/cli/cmdValidateBuiltTypes.d.mts +2 -2
- package/build/eslint/baseConfig.d.mts +3 -1
- package/build/eslint/mui/rules/disallow-react-api-in-server-components.d.mts +2 -2
- package/build/eslint/mui/rules/docgen-ignore-before-comment.d.mts +2 -2
- package/build/eslint/mui/rules/no-floating-cleanup.d.mts +5 -0
- package/build/eslint/mui/rules/no-guarded-throw.d.mts +31 -0
- package/build/eslint/mui/rules/no-presentation-role.d.mts +5 -0
- package/build/eslint/mui/rules/no-restricted-resolved-imports.d.mts +2 -2
- package/build/eslint/mui/rules/nodeEnvUtils.d.mts +18 -0
- package/build/remark/config.d.mts +43 -0
- package/build/remark/createLintTester.d.mts +10 -0
- package/build/remark/firstBlockHeading.d.mts +4 -0
- package/build/remark/gitDiff.d.mts +2 -0
- package/build/remark/noSpaceInLinks.d.mts +2 -0
- package/build/remark/straightQuotes.d.mts +2 -0
- package/build/remark/tableAlignment.d.mts +2 -0
- package/build/remark/terminalLanguage.d.mts +2 -0
- package/build/utils/babel.d.mts +1 -1
- package/build/utils/build.d.mts +56 -37
- package/build/utils/github.d.mts +1 -1
- package/build/utils/pnpm.d.mts +81 -2
- package/build/utils/testUtils.d.mts +7 -0
- package/build/utils/typescript.d.mts +6 -16
- package/package.json +60 -38
- package/src/babel-config.mjs +9 -3
- package/src/brokenLinksChecker/__fixtures__/static-site/index.html +1 -0
- package/src/brokenLinksChecker/__fixtures__/static-site/invalid-html.html +15 -0
- package/src/brokenLinksChecker/crawlWorker.mjs +217 -0
- package/src/brokenLinksChecker/index.mjs +263 -188
- package/src/brokenLinksChecker/index.test.ts +50 -13
- package/src/changelog/categorizeCommits.test.ts +5 -5
- package/src/changelog/fetchChangelogs.mjs +6 -2
- package/src/changelog/parseCommitLabels.test.ts +5 -5
- package/src/changelog/renderChangelog.mjs +1 -1
- package/src/changelog/types.ts +1 -1
- package/src/cli/cmdBuild.mjs +51 -85
- package/src/cli/cmdListWorkspaces.mjs +12 -27
- package/src/cli/cmdNetlifyIgnore.mjs +34 -93
- package/src/cli/cmdPublish.mjs +55 -15
- package/src/cli/cmdPublishCanary.mjs +128 -132
- package/src/cli/cmdPublishNewPackage.mjs +27 -6
- package/src/cli/cmdSetVersionOverrides.mjs +8 -9
- package/src/cli/cmdVale.mjs +513 -0
- package/src/cli/cmdVale.test.mjs +644 -0
- package/src/cli/index.mjs +2 -0
- package/src/cli/packageJson.d.ts +1 -1
- package/src/eslint/baseConfig.mjs +51 -19
- package/src/eslint/docsConfig.mjs +2 -1
- package/src/eslint/mui/config.mjs +22 -3
- package/src/eslint/mui/index.mjs +6 -0
- package/src/eslint/mui/rules/no-floating-cleanup.mjs +187 -0
- package/src/eslint/mui/rules/no-floating-cleanup.test.mjs +141 -0
- package/src/eslint/mui/rules/no-guarded-throw.mjs +115 -0
- package/src/eslint/mui/rules/no-guarded-throw.test.mjs +206 -0
- package/src/eslint/mui/rules/no-presentation-role.mjs +60 -0
- package/src/eslint/mui/rules/no-presentation-role.test.mjs +33 -0
- package/src/eslint/mui/rules/nodeEnvUtils.mjs +52 -0
- package/src/eslint/mui/rules/require-dev-wrapper.mjs +25 -40
- package/src/estree-typescript.d.ts +1 -1
- package/src/remark/config.mjs +157 -0
- package/src/remark/createLintTester.mjs +19 -0
- package/src/remark/firstBlockHeading.mjs +87 -0
- package/src/remark/firstBlockHeading.test.mjs +107 -0
- package/src/remark/gitDiff.mjs +43 -0
- package/src/remark/gitDiff.test.mjs +45 -0
- package/src/remark/noSpaceInLinks.mjs +42 -0
- package/src/remark/noSpaceInLinks.test.mjs +22 -0
- package/src/remark/straightQuotes.mjs +31 -0
- package/src/remark/straightQuotes.test.mjs +25 -0
- package/src/remark/tableAlignment.mjs +23 -0
- package/src/remark/tableAlignment.test.mjs +28 -0
- package/src/remark/terminalLanguage.mjs +19 -0
- package/src/remark/terminalLanguage.test.mjs +17 -0
- package/src/untyped-plugins.d.ts +11 -11
- package/src/utils/build.mjs +604 -270
- package/src/utils/build.test.mjs +1079 -521
- package/src/utils/git.mjs +16 -7
- package/src/utils/pnpm.mjs +255 -3
- package/src/utils/pnpm.test.mjs +731 -0
- package/src/utils/testUtils.mjs +18 -0
- package/src/utils/typescript.mjs +23 -42
- package/src/utils/typescript.test.mjs +234 -273
- package/vale/.vale.ini +1 -0
- package/vale/styles/MUI/CorrectReferenceAllCases.yml +43 -0
- package/vale/styles/MUI/CorrectRererenceCased.yml +14 -0
- package/vale/styles/MUI/GoogleLatin.yml +11 -0
- package/vale/styles/MUI/MuiBrandName.yml +22 -0
- package/vale/styles/MUI/NoBritish.yml +112 -0
- package/vale/styles/MUI/NoCompanyName.yml +17 -0
- package/build/markdownlint/duplicate-h1.d.mts +0 -56
- package/build/markdownlint/git-diff.d.mts +0 -11
- package/build/markdownlint/index.d.mts +0 -52
- package/build/markdownlint/straight-quotes.d.mts +0 -11
- package/build/markdownlint/table-alignment.d.mts +0 -11
- package/build/markdownlint/terminal-language.d.mts +0 -11
- package/src/markdownlint/duplicate-h1.mjs +0 -69
- package/src/markdownlint/git-diff.mjs +0 -31
- package/src/markdownlint/index.mjs +0 -62
- package/src/markdownlint/straight-quotes.mjs +0 -26
- package/src/markdownlint/table-alignment.mjs +0 -42
- package/src/markdownlint/terminal-language.mjs +0 -19
package/src/utils/git.mjs
CHANGED
|
@@ -24,6 +24,10 @@ export async function getRepositoryInfo(cwd = process.cwd()) {
|
|
|
24
24
|
* @type {Set<string>}
|
|
25
25
|
*/
|
|
26
26
|
const repoRemotes = new Set();
|
|
27
|
+
/**
|
|
28
|
+
* @type {Map<string, { owner: string, repo: string }>}
|
|
29
|
+
*/
|
|
30
|
+
const validRemotes = new Map();
|
|
27
31
|
|
|
28
32
|
for (const line of lines) {
|
|
29
33
|
// Match pattern: "remoteName url (fetch|push)"
|
|
@@ -36,20 +40,25 @@ export async function getRepositoryInfo(cwd = process.cwd()) {
|
|
|
36
40
|
cause[remoteName] = `Remote is not a GitHub repository under 'mui' organization: ${url}`;
|
|
37
41
|
continue;
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
owner: parsed.owner,
|
|
41
|
-
|
|
42
|
-
remoteName,
|
|
43
|
-
};
|
|
43
|
+
if (!validRemotes.has(remoteName)) {
|
|
44
|
+
validRemotes.set(remoteName, { owner: parsed.owner, repo: parsed.name });
|
|
45
|
+
}
|
|
44
46
|
} catch (error) {
|
|
45
47
|
cause[remoteName] = `Failed to parse URL for remote ${remoteName}: ${url}`;
|
|
46
48
|
}
|
|
47
|
-
}
|
|
48
|
-
if (type !== '(push)') {
|
|
49
|
+
} else if (type !== '(push)') {
|
|
49
50
|
throw new Error(`Unexpected line format for "git remote -v": "${line}"`);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
const preferredOrder = ['upstream', 'origin', ...validRemotes.keys()];
|
|
55
|
+
for (const name of preferredOrder) {
|
|
56
|
+
const match = validRemotes.get(name);
|
|
57
|
+
if (match) {
|
|
58
|
+
return { ...match, remoteName: name };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
throw new Error(
|
|
54
63
|
`Failed to find correct remote(s) in : ${Array.from(repoRemotes.keys()).join(', ')}`,
|
|
55
64
|
{ cause },
|
package/src/utils/pnpm.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
|
|
3
4
|
import { $ } from 'execa';
|
|
4
5
|
import * as fs from 'node:fs/promises';
|
|
5
6
|
import * as path from 'node:path';
|
|
6
7
|
import * as semver from 'semver';
|
|
8
|
+
import { parseDocument, isMap } from 'yaml';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* @typedef {Object} PrivatePackage
|
|
@@ -48,6 +50,7 @@ import * as semver from 'semver';
|
|
|
48
50
|
* @property {boolean} [publicOnly=false] - Whether to filter to only public packages
|
|
49
51
|
* @property {boolean} [nonPublishedOnly=false] - Whether to filter to only non-published packages. It by default means public packages yet to be published.
|
|
50
52
|
* @property {string} [cwd] - Current working directory to run pnpm command in
|
|
53
|
+
* @property {string[]} [filter] - Same as filtering packages with --filter in pnpm. Only include packages matching the filter. See https://pnpm.io/filtering.
|
|
51
54
|
*/
|
|
52
55
|
|
|
53
56
|
/**
|
|
@@ -73,10 +76,15 @@ import * as semver from 'semver';
|
|
|
73
76
|
* @returns {Promise<(PrivatePackage | PublicPackage)[]>} Array of packages
|
|
74
77
|
*/
|
|
75
78
|
export async function getWorkspacePackages(options = {}) {
|
|
76
|
-
const { sinceRef = null, publicOnly = false, nonPublishedOnly = false } = options;
|
|
79
|
+
const { sinceRef = null, publicOnly = false, nonPublishedOnly = false, filter = [] } = options;
|
|
77
80
|
|
|
78
81
|
// Build command with conditional filter
|
|
79
82
|
const filterArg = sinceRef ? ['--filter', `...[${sinceRef}]`] : [];
|
|
83
|
+
if (filter.length > 0) {
|
|
84
|
+
filter.forEach((f) => {
|
|
85
|
+
filterArg.push('--filter', f);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
80
88
|
const result = options.cwd
|
|
81
89
|
? await $({ cwd: options.cwd })`pnpm ls -r --json --depth -1 ${filterArg}`
|
|
82
90
|
: await $`pnpm ls -r --json --depth -1 ${filterArg}`;
|
|
@@ -148,11 +156,17 @@ export async function getPackageVersionInfo(packageName, baseVersion) {
|
|
|
148
156
|
}
|
|
149
157
|
}
|
|
150
158
|
|
|
159
|
+
/**
|
|
160
|
+
* @typedef {Object} PublishSummaryEntry
|
|
161
|
+
* @property {string} name
|
|
162
|
+
* @property {string} version
|
|
163
|
+
*/
|
|
164
|
+
|
|
151
165
|
/**
|
|
152
166
|
* Publish packages with the given options
|
|
153
167
|
* @param {PublicPackage[]} packages - Packages to publish
|
|
154
168
|
* @param {PublishOptions} [options={}] - Publishing options
|
|
155
|
-
* @returns {Promise<
|
|
169
|
+
* @returns {Promise<PublishSummaryEntry[]>}
|
|
156
170
|
*/
|
|
157
171
|
export async function publishPackages(packages, options = {}) {
|
|
158
172
|
const args = [];
|
|
@@ -172,7 +186,183 @@ export async function publishPackages(packages, options = {}) {
|
|
|
172
186
|
args.push('--no-git-checks');
|
|
173
187
|
}
|
|
174
188
|
|
|
175
|
-
|
|
189
|
+
const workspaceDir = await findWorkspaceDir(process.cwd());
|
|
190
|
+
if (!workspaceDir) {
|
|
191
|
+
throw new Error('Could not find pnpm workspace root');
|
|
192
|
+
}
|
|
193
|
+
const summaryPath = path.join(workspaceDir, 'pnpm-publish-summary.json');
|
|
194
|
+
|
|
195
|
+
// Clean up any leftover summary file from a previous run
|
|
196
|
+
await fs.rm(summaryPath, { force: true });
|
|
197
|
+
|
|
198
|
+
await $({
|
|
199
|
+
stdio: 'inherit',
|
|
200
|
+
env: { npm_config_loglevel: 'warn' },
|
|
201
|
+
})`pnpm -r publish --access public --tag=${tag} --report-summary ${args}`;
|
|
202
|
+
|
|
203
|
+
const summary = JSON.parse(await fs.readFile(summaryPath, 'utf-8'));
|
|
204
|
+
await fs.rm(summaryPath, { force: true });
|
|
205
|
+
return /** @type {PublishSummaryEntry[]} */ (summary.publishedPackages);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @typedef {Object} GetTransitiveDependenciesOptions
|
|
210
|
+
* @property {Map<string, string>} [workspacePathByName] - Map of workspace package name to directory path
|
|
211
|
+
* @property {boolean} [includeDev=true] - Whether to include devDependencies in the traversal
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Get all transitive workspace dependencies for a set of packages.
|
|
216
|
+
*
|
|
217
|
+
* Only follows deps whose version spec starts with `workspace:` (e.g. `workspace:*`
|
|
218
|
+
* or `workspace:^`), meaning they are sourced directly from the monorepo. Pinned
|
|
219
|
+
* external versions (e.g. `^1.0.0`) are ignored even when the package name exists
|
|
220
|
+
* in the workspace. Traverses `dependencies` and optionally `devDependencies`.
|
|
221
|
+
* Results are cached per package so each package is read from disk at most once
|
|
222
|
+
* regardless of how many roots depend on it.
|
|
223
|
+
*
|
|
224
|
+
* @param {string[]} packageNames - Package names to start the traversal from
|
|
225
|
+
* @param {GetTransitiveDependenciesOptions} [options]
|
|
226
|
+
* @returns {Promise<Set<string>>} All reachable workspace package names, including the input packages themselves
|
|
227
|
+
*/
|
|
228
|
+
export async function getTransitiveDependencies(packageNames, options = {}) {
|
|
229
|
+
const { includeDev = true, workspacePathByName = new Map() } = options;
|
|
230
|
+
|
|
231
|
+
/** @type {Map<string, Promise<Set<string>>>} */
|
|
232
|
+
const cache = new Map();
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* @param {string} packageName
|
|
236
|
+
* @returns {Promise<Set<string>>}
|
|
237
|
+
*/
|
|
238
|
+
function collectDeps(packageName) {
|
|
239
|
+
const cached = cache.get(packageName);
|
|
240
|
+
if (cached) {
|
|
241
|
+
return cached;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const promise = (async () => {
|
|
245
|
+
const packagePath = workspacePathByName.get(packageName);
|
|
246
|
+
if (!packagePath) {
|
|
247
|
+
throw new Error(`Workspace "${packageName}" not found`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const pkgJson = await readPackageJson(packagePath);
|
|
251
|
+
const allDepEntries = [
|
|
252
|
+
...Object.entries(pkgJson.dependencies ?? {}),
|
|
253
|
+
...(includeDev ? Object.entries(pkgJson.devDependencies ?? {}) : []),
|
|
254
|
+
];
|
|
255
|
+
const workspaceDeps = allDepEntries
|
|
256
|
+
.filter(
|
|
257
|
+
([dep, spec]) =>
|
|
258
|
+
workspacePathByName.has(dep) &&
|
|
259
|
+
typeof spec === 'string' &&
|
|
260
|
+
spec.startsWith('workspace:'),
|
|
261
|
+
)
|
|
262
|
+
.map(([dep]) => dep);
|
|
263
|
+
|
|
264
|
+
const recursiveResults = await Promise.all(workspaceDeps.map(collectDeps));
|
|
265
|
+
return new Set([...workspaceDeps, ...recursiveResults.flatMap((s) => [...s])]);
|
|
266
|
+
})();
|
|
267
|
+
|
|
268
|
+
cache.set(packageName, promise);
|
|
269
|
+
return promise;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
for (const name of packageNames) {
|
|
273
|
+
if (!workspacePathByName.has(name)) {
|
|
274
|
+
throw new Error(`Workspace "${name}" not found`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const results = await Promise.all(packageNames.map(collectDeps));
|
|
279
|
+
return new Set([...packageNames, ...results.flatMap((s) => [...s])]);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Pure validation logic: given a publish set and workspace maps, checks that all
|
|
284
|
+
* transitive hard workspace dependencies are covered and none are private.
|
|
285
|
+
*
|
|
286
|
+
* A hard dependency is one listed in `dependencies` (not `peerDependencies` or
|
|
287
|
+
* `devDependencies`) using a `workspace:` version specifier (e.g. `workspace:*` or
|
|
288
|
+
* `workspace:^`). Peer dependencies are never bundled and dev dependencies are not installed
|
|
289
|
+
* on consumer devices - both are excluded regardless of version specifier. Pinned-version
|
|
290
|
+
* references in `dependencies` are also excluded - they resolve from the registry and do
|
|
291
|
+
* not need to be co-published.
|
|
292
|
+
*
|
|
293
|
+
* @param {PublicPackage[]} packages - The packages intended for publishing
|
|
294
|
+
* @param {Map<string, PublicPackage | PrivatePackage>} workspacePackageByName - All workspace packages by name
|
|
295
|
+
* @param {Map<string, string>} workspacePathByName - Map of workspace package name to directory path
|
|
296
|
+
* @returns {Promise<{issues: string[]}>}
|
|
297
|
+
* List of human-readable issue strings. Empty when the dependency set is valid.
|
|
298
|
+
* @internal
|
|
299
|
+
*/
|
|
300
|
+
export async function checkPublishDependencies(
|
|
301
|
+
packages,
|
|
302
|
+
workspacePackageByName,
|
|
303
|
+
workspacePathByName,
|
|
304
|
+
) {
|
|
305
|
+
const publishedNames = new Set(packages.map((pkg) => pkg.name));
|
|
306
|
+
|
|
307
|
+
const transitiveDeps = await getTransitiveDependencies(
|
|
308
|
+
packages.map((pkg) => pkg.name),
|
|
309
|
+
{ includeDev: false, workspacePathByName },
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
/** @type {Set<string>} */
|
|
313
|
+
const privateButRequired = new Set();
|
|
314
|
+
/** @type {Set<string>} */
|
|
315
|
+
const missingFromPublish = new Set();
|
|
316
|
+
|
|
317
|
+
for (const depName of transitiveDeps) {
|
|
318
|
+
if (publishedNames.has(depName)) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
const workspacePkg = workspacePackageByName.get(depName);
|
|
322
|
+
if (workspacePkg?.isPrivate) {
|
|
323
|
+
privateButRequired.add(depName);
|
|
324
|
+
} else {
|
|
325
|
+
missingFromPublish.add(depName);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** @type {string[]} */
|
|
330
|
+
const issues = [];
|
|
331
|
+
|
|
332
|
+
if (privateButRequired.size > 0) {
|
|
333
|
+
issues.push(
|
|
334
|
+
`The following private workspace packages are required as dependencies but cannot be published: ${[...privateButRequired].join(', ')}`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (missingFromPublish.size > 0) {
|
|
339
|
+
issues.push(
|
|
340
|
+
`The following workspace packages are required as dependencies but are not included in the publish set: ${[...missingFromPublish].join(', ')}. Add them to the --filter list.`,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return { issues };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Validate that a set of packages covers all of their transitive hard workspace dependencies,
|
|
349
|
+
* and that none of those dependencies are private (which would make them unpublishable).
|
|
350
|
+
*
|
|
351
|
+
* @param {PublicPackage[]} packages - The packages intended for publishing
|
|
352
|
+
* @returns {Promise<{issues: string[]}>}
|
|
353
|
+
* List of human-readable issue strings. Empty when the dependency set is valid.
|
|
354
|
+
*/
|
|
355
|
+
export async function validatePublishDependencies(packages) {
|
|
356
|
+
const allWorkspacePackages = await getWorkspacePackages();
|
|
357
|
+
|
|
358
|
+
const workspacePackageByName = /** @type {Map<string, PublicPackage | PrivatePackage>} */ (
|
|
359
|
+
new Map(allWorkspacePackages.flatMap((pkg) => (pkg.name ? [[pkg.name, pkg]] : [])))
|
|
360
|
+
);
|
|
361
|
+
const workspacePathByName = new Map(
|
|
362
|
+
allWorkspacePackages.flatMap((pkg) => (pkg.name ? [[pkg.name, pkg.path]] : [])),
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
return checkPublishDependencies(packages, workspacePackageByName, workspacePathByName);
|
|
176
366
|
}
|
|
177
367
|
|
|
178
368
|
/**
|
|
@@ -196,6 +386,68 @@ export async function writePackageJson(packagePath, packageJson) {
|
|
|
196
386
|
await fs.writeFile(path.join(packagePath, 'package.json'), content);
|
|
197
387
|
}
|
|
198
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Write the computed overrides into whichever manifest already defines
|
|
391
|
+
* overrides — preferring pnpm-workspace.yaml, falling back to package.json
|
|
392
|
+
* `pnpm.overrides`, defaulting to pnpm-workspace.yaml — and persist the result.
|
|
393
|
+
* A missing pnpm-workspace.yaml is treated as empty, so a fresh file is created
|
|
394
|
+
* with just the `overrides:` block. Rejects a `resolutions` field in
|
|
395
|
+
* package.json because pnpm 11 silently ignores it.
|
|
396
|
+
*
|
|
397
|
+
* @param {string} workspaceDir - Workspace root directory
|
|
398
|
+
* @param {Record<string, string>} overrides - Overrides to apply
|
|
399
|
+
* @returns {Promise<void>}
|
|
400
|
+
*/
|
|
401
|
+
export async function writeOverridesToWorkspace(workspaceDir, overrides) {
|
|
402
|
+
const workspaceYamlPath = path.join(workspaceDir, 'pnpm-workspace.yaml');
|
|
403
|
+
const yamlPromise = fs.readFile(workspaceYamlPath, { encoding: 'utf8' }).catch((error) => {
|
|
404
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code !== 'ENOENT') {
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
return '';
|
|
408
|
+
});
|
|
409
|
+
const [rootPackageJson, yamlSource] = await Promise.all([
|
|
410
|
+
readPackageJson(workspaceDir),
|
|
411
|
+
yamlPromise,
|
|
412
|
+
]);
|
|
413
|
+
|
|
414
|
+
const { resolutions } = rootPackageJson;
|
|
415
|
+
if (resolutions && Object.keys(resolutions).length > 0) {
|
|
416
|
+
throw new Error(
|
|
417
|
+
'Found a "resolutions" field in package.json. pnpm 11 ignores it silently. ' +
|
|
418
|
+
'Move those entries into the "overrides:" key of pnpm-workspace.yaml.',
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Parsed once, reused for both the read (does it have overrides?) and the write.
|
|
423
|
+
const doc = parseDocument(yamlSource);
|
|
424
|
+
const existing = doc.get('overrides');
|
|
425
|
+
const workspaceHasOverrides = isMap(existing) && existing.items.length > 0;
|
|
426
|
+
|
|
427
|
+
const pnpm = /** @type {{ overrides?: Record<string, string> } | undefined} */ (
|
|
428
|
+
rootPackageJson.pnpm
|
|
429
|
+
);
|
|
430
|
+
const packageJsonOverrides = pnpm?.overrides;
|
|
431
|
+
|
|
432
|
+
// Write where overrides already live; default to the workspace file.
|
|
433
|
+
if (
|
|
434
|
+
!workspaceHasOverrides &&
|
|
435
|
+
packageJsonOverrides &&
|
|
436
|
+
Object.keys(packageJsonOverrides).length > 0
|
|
437
|
+
) {
|
|
438
|
+
await writePackageJson(workspaceDir, {
|
|
439
|
+
...rootPackageJson,
|
|
440
|
+
pnpm: { ...pnpm, overrides: { ...packageJsonOverrides, ...overrides } },
|
|
441
|
+
});
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
for (const [name, version] of Object.entries(overrides)) {
|
|
446
|
+
doc.setIn(['overrides', name], version);
|
|
447
|
+
}
|
|
448
|
+
await fs.writeFile(workspaceYamlPath, doc.toString());
|
|
449
|
+
}
|
|
450
|
+
|
|
199
451
|
/**
|
|
200
452
|
* Resolve a package@version specifier to an exact version
|
|
201
453
|
* @param {string} packageSpec - Package specifier in format "package@version"
|