@mui/internal-code-infra 0.0.4-canary.10 ā 0.0.4-canary.100
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 +21 -7
- package/build/babel-config.d.mts +5 -1
- package/build/brokenLinksChecker/crawlWorker.d.mts +1 -0
- package/build/brokenLinksChecker/index.d.mts +192 -2
- package/build/changelog/fetchChangelogs.d.mts +3 -0
- package/build/changelog/types.d.ts +3 -1
- package/build/cli/cmdArgosPush.d.mts +8 -2
- package/build/cli/cmdBuild.d.mts +48 -2
- package/build/cli/cmdCopyFiles.d.mts +14 -2
- package/build/cli/cmdExtractErrorCodes.d.mts +2 -2
- package/build/cli/cmdGenerateChangelog.d.mts +17 -2
- package/build/cli/cmdGithubAuth.d.mts +2 -2
- package/build/cli/cmdListWorkspaces.d.mts +14 -2
- package/build/cli/cmdNetlifyIgnore.d.mts +12 -2
- package/build/cli/cmdPublish.d.mts +23 -4
- package/build/cli/cmdPublishCanary.d.mts +20 -2
- package/build/cli/cmdPublishNewPackage.d.mts +10 -2
- package/build/cli/cmdRenameScope.d.mts +18 -0
- package/build/cli/cmdSetVersionOverrides.d.mts +5 -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 +8 -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 +7 -1
- package/build/utils/build.d.mts +59 -37
- package/build/utils/extractErrorCodes.d.mts +9 -0
- package/build/utils/git.d.mts +16 -0
- package/build/utils/github.d.mts +13 -1
- package/build/utils/pnpm.d.mts +176 -17
- package/build/utils/testUtils.d.mts +28 -0
- package/build/utils/typescript.d.mts +6 -16
- package/package.json +77 -53
- package/src/babel-config.mjs +3 -1
- package/src/brokenLinksChecker/crawlWorker.mjs +240 -0
- package/src/brokenLinksChecker/index.mjs +263 -188
- package/src/changelog/fetchChangelogs.mjs +8 -2
- package/src/changelog/renderChangelog.mjs +1 -1
- package/src/changelog/types.ts +3 -1
- package/src/cli/cmdBuild.mjs +51 -85
- package/src/cli/cmdListWorkspaces.mjs +7 -1
- package/src/cli/cmdNetlifyIgnore.mjs +30 -5
- package/src/cli/cmdPublish.mjs +79 -37
- package/src/cli/cmdPublishCanary.mjs +96 -24
- package/src/cli/cmdPublishNewPackage.mjs +31 -8
- package/src/cli/cmdRenameScope.mjs +76 -0
- package/src/cli/cmdSetVersionOverrides.mjs +8 -9
- package/src/cli/cmdVale.mjs +513 -0
- package/src/cli/index.mjs +4 -0
- package/src/cli/packageJson.d.ts +2 -3
- package/src/eslint/baseConfig.mjs +51 -19
- package/src/eslint/docsConfig.mjs +2 -1
- package/src/eslint/mui/config.mjs +24 -4
- 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-guarded-throw.mjs +115 -0
- package/src/eslint/mui/rules/no-presentation-role.mjs +60 -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/gitDiff.mjs +43 -0
- package/src/remark/noSpaceInLinks.mjs +42 -0
- package/src/remark/straightQuotes.mjs +31 -0
- package/src/remark/tableAlignment.mjs +23 -0
- package/src/remark/terminalLanguage.mjs +19 -0
- package/src/stylelint/index.mjs +2 -2
- package/src/untyped-plugins.d.ts +14 -14
- package/src/utils/build.mjs +604 -270
- package/src/utils/git.mjs +27 -7
- package/src/utils/pnpm.mjs +444 -53
- package/src/utils/testUtils.mjs +53 -0
- package/src/utils/typescript.mjs +23 -42
- package/vale/.vale.ini +1 -0
- package/vale/styles/MUI/CorrectReferenceAllCases.yml +42 -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/brokenLinksChecker/__fixtures__/static-site/broken-links.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/broken-targets.html +0 -22
- package/src/brokenLinksChecker/__fixtures__/static-site/example.md +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/external-links.html +0 -21
- package/src/brokenLinksChecker/__fixtures__/static-site/ignored-page.html +0 -17
- package/src/brokenLinksChecker/__fixtures__/static-site/index.html +0 -28
- package/src/brokenLinksChecker/__fixtures__/static-site/known-targets.json +0 -5
- package/src/brokenLinksChecker/__fixtures__/static-site/nested/page.html +0 -21
- package/src/brokenLinksChecker/__fixtures__/static-site/orphaned-page.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-api-links.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-custom-targets.html +0 -24
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-ignored-content.html +0 -28
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-known-target-links.html +0 -19
- package/src/brokenLinksChecker/__fixtures__/static-site/unclosed-tags.html +0 -1
- package/src/brokenLinksChecker/__fixtures__/static-site/valid.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/with-anchors.html +0 -31
- package/src/brokenLinksChecker/index.test.ts +0 -261
- package/src/changelog/categorizeCommits.test.ts +0 -319
- package/src/changelog/filterCommits.test.ts +0 -363
- package/src/changelog/parseCommitLabels.test.ts +0 -509
- package/src/changelog/renderChangelog.test.ts +0 -378
- package/src/changelog/sortSections.test.ts +0 -199
- package/src/eslint/mui/rules/add-undef-to-optional.test.mjs +0 -361
- package/src/eslint/mui/rules/consistent-production-guard.test.mjs +0 -162
- package/src/eslint/mui/rules/disallow-active-elements-as-key-event-target.test.mjs +0 -66
- package/src/eslint/mui/rules/disallow-react-api-in-server-components.test.mjs +0 -305
- package/src/eslint/mui/rules/docgen-ignore-before-comment.test.mjs +0 -52
- package/src/eslint/mui/rules/flatten-parentheses.test.mjs +0 -245
- package/src/eslint/mui/rules/mui-name-matches-component-name.test.mjs +0 -247
- package/src/eslint/mui/rules/no-empty-box.test.mjs +0 -40
- package/src/eslint/mui/rules/no-styled-box.test.mjs +0 -73
- package/src/eslint/mui/rules/require-dev-wrapper.test.mjs +0 -265
- package/src/eslint/mui/rules/rules-of-use-theme-variants.test.mjs +0 -149
- package/src/eslint/mui/rules/straight-quotes.test.mjs +0 -67
- 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/build.test.mjs +0 -705
- package/src/utils/template.test.mjs +0 -133
- package/src/utils/typescript.test.mjs +0 -380
|
@@ -93,7 +93,11 @@ async function fetchCommitsForPackage({ packagePath }) {
|
|
|
93
93
|
return results;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
const AUTHOR_EXCLUDE_LIST =
|
|
96
|
+
const AUTHOR_EXCLUDE_LIST = new Set([
|
|
97
|
+
'renovate[bot]',
|
|
98
|
+
'dependabot[bot]',
|
|
99
|
+
'code-infra-renovate[bot]',
|
|
100
|
+
]);
|
|
97
101
|
|
|
98
102
|
/**
|
|
99
103
|
* @param {string} message
|
|
@@ -144,7 +148,7 @@ async function prepareChangelogsFromGitCli(packagesToPublish, allPackages, canar
|
|
|
144
148
|
// Exclude commits authored by bots
|
|
145
149
|
.filter(
|
|
146
150
|
// We want to allow commits from copilot or other AI tools, so only filter known bots
|
|
147
|
-
(commit) => !AUTHOR_EXCLUDE_LIST.
|
|
151
|
+
(commit) => !AUTHOR_EXCLUDE_LIST.has(commit.author),
|
|
148
152
|
)
|
|
149
153
|
.map((commit) => `- ${cleanupCommitMessage(commit.message)} by ${commit.author}`);
|
|
150
154
|
|
|
@@ -159,7 +163,10 @@ async function prepareChangelogsFromGitCli(packagesToPublish, allPackages, canar
|
|
|
159
163
|
|
|
160
164
|
const transitiveDepSets = await Promise.all(
|
|
161
165
|
allPackages.map((pkg) =>
|
|
162
|
-
getTransitiveDependencies([pkg.name], {
|
|
166
|
+
getTransitiveDependencies([pkg.name], {
|
|
167
|
+
includeDev: false,
|
|
168
|
+
workspacePathByName,
|
|
169
|
+
}),
|
|
163
170
|
),
|
|
164
171
|
);
|
|
165
172
|
|
|
@@ -225,6 +232,41 @@ async function prepareChangelogsForPackages(packagesToPublish, allPackages, cana
|
|
|
225
232
|
return changelogs;
|
|
226
233
|
}
|
|
227
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Create or replace a GitHub release. Attempts to create the release first,
|
|
237
|
+
* and if it already exists (422), deletes the existing one and retries.
|
|
238
|
+
*
|
|
239
|
+
* @param {InstanceType<typeof Octokit>} octokit
|
|
240
|
+
* @param {NonNullable<Parameters<Octokit['repos']['createRelease']>[0]>} params
|
|
241
|
+
*/
|
|
242
|
+
async function upsertGitHubRelease(octokit, params) {
|
|
243
|
+
try {
|
|
244
|
+
return await octokit.repos.createRelease(params);
|
|
245
|
+
} catch (/** @type {any} */ error) {
|
|
246
|
+
const isAlreadyExists =
|
|
247
|
+
error.status === 422 &&
|
|
248
|
+
error.response?.data?.errors?.some(
|
|
249
|
+
(/** @type {any} */ err) => err.code === 'already_exists' && err.field === 'tag_name',
|
|
250
|
+
);
|
|
251
|
+
if (!isAlreadyExists) {
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Release already exists ā delete and recreate
|
|
257
|
+
const existing = await octokit.repos.getReleaseByTag({
|
|
258
|
+
owner: params.owner,
|
|
259
|
+
repo: params.repo,
|
|
260
|
+
tag: params.tag_name,
|
|
261
|
+
});
|
|
262
|
+
await octokit.repos.deleteRelease({
|
|
263
|
+
owner: params.owner,
|
|
264
|
+
repo: params.repo,
|
|
265
|
+
release_id: existing.data.id,
|
|
266
|
+
});
|
|
267
|
+
return octokit.repos.createRelease(params);
|
|
268
|
+
}
|
|
269
|
+
|
|
228
270
|
/**
|
|
229
271
|
* Create GitHub releases and tags for published packages
|
|
230
272
|
* @param {PublicPackage[]} publishedPackages - Packages that were published
|
|
@@ -277,15 +319,20 @@ async function createGitHubReleasesForPackages(
|
|
|
277
319
|
GIT_COMMITTER_NAME: 'Code infra',
|
|
278
320
|
GIT_COMMITTER_EMAIL: 'code-infra@mui.com',
|
|
279
321
|
},
|
|
280
|
-
})`git tag -
|
|
322
|
+
})`git tag -fa ${tagName} -m ${`Canary release ${pkg.name}@${version}`}`;
|
|
281
323
|
|
|
324
|
+
// Force-push to handle retries where the tag already exists from a previous
|
|
325
|
+
// failed publish. The npm registry is the source of truth for published
|
|
326
|
+
// versions, so it's safe to rewrite a tag even if it points to a different
|
|
327
|
+
// commit ā it just means the prior publish for this version failed partway
|
|
328
|
+
// through and the GitHub release needs to be recreated.
|
|
282
329
|
// eslint-disable-next-line no-await-in-loop
|
|
283
|
-
await $`git push origin ${tagName}`;
|
|
330
|
+
await $`git push --force origin ${tagName}`;
|
|
284
331
|
console.log(`ā
Created and pushed git tag: ${tagName}`);
|
|
285
332
|
|
|
286
333
|
// Create GitHub release
|
|
287
334
|
// eslint-disable-next-line no-await-in-loop
|
|
288
|
-
const res = await octokit
|
|
335
|
+
const res = await upsertGitHubRelease(octokit, {
|
|
289
336
|
owner: repoInfo.owner,
|
|
290
337
|
repo: repoInfo.repo,
|
|
291
338
|
tag_name: tagName,
|
|
@@ -315,7 +362,14 @@ async function getLastCanaryTag() {
|
|
|
315
362
|
// Tag might not exist locally, which is fine
|
|
316
363
|
}
|
|
317
364
|
|
|
318
|
-
|
|
365
|
+
try {
|
|
366
|
+
await $`git fetch origin tag ${CANARY_TAG}`;
|
|
367
|
+
} catch (err) {
|
|
368
|
+
// Tag might not exist on the remote yet (first canary run), which is fine
|
|
369
|
+
if (!(/** @type {Error} */ (err).message?.includes("couldn't find remote ref"))) {
|
|
370
|
+
throw err;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
319
373
|
const { stdout: remoteCanaryTag } = await $`git ls-remote --tags origin ${CANARY_TAG}`;
|
|
320
374
|
return remoteCanaryTag.trim() ? CANARY_TAG : null;
|
|
321
375
|
}
|
|
@@ -427,20 +481,23 @@ async function publishCanaryVersions(
|
|
|
427
481
|
}
|
|
428
482
|
|
|
429
483
|
// Third pass: publish only the changed packages using recursive publish
|
|
430
|
-
|
|
484
|
+
/** @type {Set<string>} */
|
|
485
|
+
const publishedNames = new Set();
|
|
431
486
|
try {
|
|
432
487
|
console.log(`š¤ Publishing ${packagesToPublish.length} canary versions...`);
|
|
433
|
-
await publishPackages(packagesToPublish, {
|
|
488
|
+
const publishedPackages = await publishPackages(packagesToPublish, {
|
|
434
489
|
dryRun: options.dryRun,
|
|
435
490
|
noGitChecks: true,
|
|
436
491
|
tag: CANARY_TAG,
|
|
437
492
|
});
|
|
438
493
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
})
|
|
443
|
-
|
|
494
|
+
// Only use package names from the report summary, not versions.
|
|
495
|
+
// pnpm-publish-summary.json reports the version from the workspace
|
|
496
|
+
// package.json, which is wrong for packages with publishConfig.directory.
|
|
497
|
+
for (const { name } of publishedPackages) {
|
|
498
|
+
publishedNames.add(name);
|
|
499
|
+
console.log(`ā
Published ${name}@${canaryVersions.get(name)}`);
|
|
500
|
+
}
|
|
444
501
|
} finally {
|
|
445
502
|
// Always restore original package.json files in parallel
|
|
446
503
|
console.log('\nš Restoring original package.json files...');
|
|
@@ -454,16 +511,26 @@ async function publishCanaryVersions(
|
|
|
454
511
|
await Promise.all(restorePromises);
|
|
455
512
|
}
|
|
456
513
|
|
|
457
|
-
if (
|
|
458
|
-
// Create
|
|
459
|
-
await createCanaryTag(options.dryRun);
|
|
460
|
-
|
|
461
|
-
// Create GitHub releases if requested
|
|
514
|
+
if (publishedNames.size > 0) {
|
|
515
|
+
// Create GitHub releases only for actually published packages
|
|
462
516
|
if (options.githubRelease) {
|
|
463
|
-
|
|
517
|
+
const actuallyPublished = packagesToPublish.filter((pkg) => publishedNames.has(pkg.name));
|
|
518
|
+
await createGitHubReleasesForPackages(actuallyPublished, canaryVersions, changelogs, options);
|
|
464
519
|
}
|
|
465
520
|
|
|
466
|
-
|
|
521
|
+
// Only advance the canary tag if all expected packages were published.
|
|
522
|
+
// Otherwise the tag would skip over unpublished packages and they'd
|
|
523
|
+
// never be retried on the next run.
|
|
524
|
+
const missing = packagesToPublish.filter((pkg) => !publishedNames.has(pkg.name));
|
|
525
|
+
if (missing.length === 0) {
|
|
526
|
+
await createCanaryTag(options.dryRun);
|
|
527
|
+
console.log('\nš All canary versions published successfully!');
|
|
528
|
+
} else {
|
|
529
|
+
const missingNames = missing.map((pkg) => pkg.name).join(', ');
|
|
530
|
+
console.warn(
|
|
531
|
+
`\nā ļø Canary tag not advanced, some packages failed to publish: ${missingNames}`,
|
|
532
|
+
);
|
|
533
|
+
}
|
|
467
534
|
}
|
|
468
535
|
}
|
|
469
536
|
|
|
@@ -520,9 +587,14 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
520
587
|
const { issues } = await validatePublishDependencies(filteredPackages);
|
|
521
588
|
|
|
522
589
|
if (issues.length > 0) {
|
|
523
|
-
throw new Error(
|
|
524
|
-
|
|
525
|
-
|
|
590
|
+
throw new Error(
|
|
591
|
+
`Invalid dependencies structure of packages to be published -
|
|
592
|
+
${issues.join('\n ')}
|
|
593
|
+
`,
|
|
594
|
+
{
|
|
595
|
+
cause: issues,
|
|
596
|
+
},
|
|
597
|
+
);
|
|
526
598
|
}
|
|
527
599
|
|
|
528
600
|
console.log('ā
All workspace dependency requirements satisfied');
|
|
@@ -11,25 +11,44 @@ import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
|
|
|
11
11
|
|
|
12
12
|
import { getRepositoryInfo } from '../utils/git.mjs';
|
|
13
13
|
import { toPosixPath } from '../utils/path.mjs';
|
|
14
|
-
import { getWorkspacePackages } from '../utils/pnpm.mjs';
|
|
14
|
+
import { getPackagesNeedingManualPublish, getWorkspacePackages } from '../utils/pnpm.mjs';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @typedef {Object} Args
|
|
18
18
|
* @property {boolean} [dryRun] If true, will only log the commands without executing them
|
|
19
|
+
* @property {string} [otp] 6 digit auth code to forward to npm for two-factor authentication
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
22
|
export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
22
23
|
command: 'publish-new-package [pkg...]',
|
|
23
24
|
describe: 'Publish new empty package(s) to the npm registry.',
|
|
24
25
|
builder: (yargs) =>
|
|
25
|
-
yargs
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
yargs
|
|
27
|
+
.option('dryRun', {
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
default: false,
|
|
30
|
+
description: 'If true, will only log the commands without executing them.',
|
|
31
|
+
})
|
|
32
|
+
.option('otp', {
|
|
33
|
+
type: 'string',
|
|
34
|
+
description: '6 digit auth code to forward to npm for two-factor authentication.',
|
|
35
|
+
coerce: (value) => {
|
|
36
|
+
if (value === undefined) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!/^\d{6}$/.test(value)) {
|
|
41
|
+
throw new Error('The --otp option must be a 6 digit number.');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return value;
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
30
47
|
async handler(args) {
|
|
31
48
|
console.log(`š Detecting new packages to publish in workspace...`);
|
|
32
|
-
const newPackages = await
|
|
49
|
+
const newPackages = await getPackagesNeedingManualPublish(
|
|
50
|
+
await getWorkspacePackages({ publicOnly: true }),
|
|
51
|
+
);
|
|
33
52
|
|
|
34
53
|
if (!newPackages.length) {
|
|
35
54
|
console.log('No new packages to publish.');
|
|
@@ -62,7 +81,7 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
62
81
|
version: '0.0.1',
|
|
63
82
|
repository: {
|
|
64
83
|
type: 'git',
|
|
65
|
-
url: `git+https://github.com/${repo.owner}/${repo.
|
|
84
|
+
url: `git+https://github.com/${repo.owner}/${repo.repo}.git`,
|
|
66
85
|
directory: toPosixPath(path.relative(workspaceDir, pkg.path)),
|
|
67
86
|
},
|
|
68
87
|
};
|
|
@@ -78,8 +97,12 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
78
97
|
if (args.dryRun) {
|
|
79
98
|
publishArgs.push('--dry-run');
|
|
80
99
|
}
|
|
100
|
+
if (args.otp) {
|
|
101
|
+
publishArgs.push('--otp', args.otp);
|
|
102
|
+
}
|
|
81
103
|
await $({
|
|
82
104
|
cwd: newPkgDir,
|
|
105
|
+
stdio: 'inherit',
|
|
83
106
|
})`npm publish --access public --tag=canary ${publishArgs}`;
|
|
84
107
|
console.log(
|
|
85
108
|
`ā
${args.dryRun ? '[Dry run] ' : ''}Published ${chalk.bold(`${pkg.name}@${packageJson.version}`)} to npm registry.`,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
import { getWorkspacePackages, renameWorkspaceScope } from '../utils/pnpm.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A scope is a single `@`-prefixed segment. Letting a `/` through would build
|
|
11
|
+
* names like `@acme/private/pkg`, which only npm rejects, long after every
|
|
12
|
+
* matching manifest has been rewritten.
|
|
13
|
+
*/
|
|
14
|
+
const SCOPE_PATTERN = /^@[a-z0-9-~][a-z0-9-._~]*$/;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {Object} Args
|
|
18
|
+
* @property {[string, string]} alias Source and target scope
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} alias
|
|
23
|
+
* @returns {[string, string]}
|
|
24
|
+
*/
|
|
25
|
+
export function parseAlias(alias) {
|
|
26
|
+
const parts = alias.split(':');
|
|
27
|
+
const [from, to] = parts;
|
|
28
|
+
if (parts.length !== 2 || !SCOPE_PATTERN.test(from) || !SCOPE_PATTERN.test(to)) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`Invalid scope mapping "${alias}". Expected exactly two npm scopes separated by a colon, e.g. "@acme:@acme-private".`,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (from === to) {
|
|
34
|
+
throw new Error(`Invalid scope mapping "${alias}". The source and target scope are the same.`);
|
|
35
|
+
}
|
|
36
|
+
return [from, to];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
40
|
+
command: 'rename-scope <alias>',
|
|
41
|
+
describe: 'Move publishable workspace packages to a different npm scope',
|
|
42
|
+
builder: (yargs) =>
|
|
43
|
+
yargs
|
|
44
|
+
.positional('alias', {
|
|
45
|
+
type: 'string',
|
|
46
|
+
describe: 'Scope mapping written as "@from:@to"',
|
|
47
|
+
coerce: parseAlias,
|
|
48
|
+
})
|
|
49
|
+
.example(
|
|
50
|
+
'$0 rename-scope @acme:@acme-private',
|
|
51
|
+
'Publish the workspace @acme packages under @acme-private',
|
|
52
|
+
),
|
|
53
|
+
handler: async (argv) => {
|
|
54
|
+
const [from, to] = argv.alias;
|
|
55
|
+
const packages = await getWorkspacePackages();
|
|
56
|
+
const renamed = await renameWorkspaceScope(packages, from, to);
|
|
57
|
+
|
|
58
|
+
// Matching nothing means the mapping is wrong or stale. Carrying on would
|
|
59
|
+
// publish under the original scope, so fail instead of reporting success.
|
|
60
|
+
if (renamed.size === 0) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`No publishable workspace packages found in ${from}. Check the scope mapping "${from}:${to}", or the workspace may already have been renamed.`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const [oldName, newName] of renamed) {
|
|
67
|
+
console.log(`š¦ ${oldName} ā ${chalk.bold(newName)}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
console.log(
|
|
71
|
+
chalk.yellow(
|
|
72
|
+
'\nā ļø Workspace manifests were rewritten in place and are not restored. Discard them before committing.',
|
|
73
|
+
),
|
|
74
|
+
);
|
|
75
|
+
},
|
|
76
|
+
});
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import fs from 'node:fs/promises';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
3
|
import * as semver from 'semver';
|
|
7
4
|
import { $ } from 'execa';
|
|
8
|
-
import {
|
|
5
|
+
import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
|
|
6
|
+
import {
|
|
7
|
+
resolveVersion,
|
|
8
|
+
findDependencyVersionFromSpec,
|
|
9
|
+
writeOverridesToWorkspace,
|
|
10
|
+
} from '../utils/pnpm.mjs';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* @typedef {Object} Args
|
|
@@ -103,11 +105,8 @@ async function handler(args) {
|
|
|
103
105
|
// eslint-disable-next-line no-console
|
|
104
106
|
console.log(`Using overrides: ${JSON.stringify(overrides, null, 2)}`);
|
|
105
107
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
packageJson.resolutions ??= {};
|
|
109
|
-
Object.assign(packageJson.resolutions, overrides);
|
|
110
|
-
await fs.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}${os.EOL}`);
|
|
108
|
+
const workspaceDir = (await findWorkspaceDir(process.cwd())) ?? process.cwd();
|
|
109
|
+
await writeOverridesToWorkspace(workspaceDir, overrides);
|
|
111
110
|
|
|
112
111
|
await $({ stdio: 'inherit' })`pnpm dedupe`;
|
|
113
112
|
}
|