@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.
Files changed (102) hide show
  1. package/README.md +36 -4
  2. package/build/babel-config.d.mts +7 -1
  3. package/build/changelog/changelogChanges.d.mts +42 -0
  4. package/build/changelog/changelogGrouping.d.mts +52 -0
  5. package/build/changelog/changelogMarkdown.d.mts +69 -0
  6. package/build/changelog/changelogTags.d.mts +15 -0
  7. package/build/changelog/changelogTitle.d.mts +28 -0
  8. package/build/changelog/fetchChangelogData.d.mts +16 -0
  9. package/build/changelog/fetchChangelogs.d.mts +11 -12
  10. package/build/changelog/index.d.mts +25 -0
  11. package/build/changelog/octokit.d.mts +7 -0
  12. package/build/changelog/types.d.ts +174 -0
  13. package/build/eslint/baseConfig.d.mts +1 -1
  14. package/build/eslint/index.d.mts +1 -0
  15. package/build/eslint/mui/rules/no-constructor-assigned-field.d.mts +50 -0
  16. package/build/eslint/nodeSupportConfig.d.mts +11 -0
  17. package/build/eslint/packageJsonConfig.d.mts +7 -0
  18. package/build/remark/config.d.mts +5 -14
  19. package/build/utils/babelPlugin.d.mts +8 -0
  20. package/build/utils/build.d.mts +22 -0
  21. package/build/utils/cjsSourcesPlugin.d.mts +11 -0
  22. package/build/utils/credentials.d.mts +2 -2
  23. package/build/utils/dtsExportsPlugin.d.mts +8 -0
  24. package/build/utils/dtsNamespacesPlugin.d.mts +19 -0
  25. package/build/utils/fileUrlEntriesPlugin.d.mts +9 -0
  26. package/build/utils/getPublishedPkgJson.d.mts +20 -0
  27. package/build/utils/git.d.mts +30 -9
  28. package/build/utils/github.d.mts +8 -0
  29. package/build/utils/jsNamespacesPlugin.d.mts +13 -0
  30. package/build/utils/pnpm.d.mts +67 -3
  31. package/build/utils/publint.d.mts +6 -0
  32. package/build/utils/rolldownOutput.d.mts +38 -0
  33. package/build/utils/testUtils.d.mts +8 -0
  34. package/build/utils/typescript.d.mts +17 -0
  35. package/package.json +61 -49
  36. package/src/babel-config.mjs +35 -1
  37. package/src/brokenLinksChecker/index.mjs +8 -1
  38. package/src/changelog/changelogChanges.mjs +479 -0
  39. package/src/changelog/changelogGrouping.mjs +148 -0
  40. package/src/changelog/changelogMarkdown.mjs +110 -0
  41. package/src/changelog/changelogTags.mjs +34 -0
  42. package/src/changelog/changelogTitle.mjs +56 -0
  43. package/src/changelog/fetchChangelogData.mjs +172 -0
  44. package/src/changelog/fetchChangelogs.mjs +47 -34
  45. package/src/changelog/index.mjs +34 -0
  46. package/src/changelog/octokit.mjs +35 -0
  47. package/src/changelog/types.ts +187 -0
  48. package/src/cli/cmdBaseline.mjs +31 -0
  49. package/src/cli/cmdBuild.mjs +20 -89
  50. package/src/cli/cmdBuildNew.mjs +474 -0
  51. package/src/cli/cmdNetlifyIgnore.mjs +14 -7
  52. package/src/cli/cmdPublish.mjs +17 -3
  53. package/src/cli/cmdPublishNewPackage.mjs +11 -4
  54. package/src/cli/cmdValidateBuiltTypes.mjs +447 -32
  55. package/src/cli/index.mjs +4 -0
  56. package/src/eslint/baseConfig.mjs +10 -2
  57. package/src/eslint/docsConfig.mjs +28 -10
  58. package/src/eslint/index.mjs +1 -0
  59. package/src/eslint/jsonConfig.mjs +2 -1
  60. package/src/eslint/mui/config.mjs +16 -1
  61. package/src/eslint/mui/index.mjs +2 -0
  62. package/src/eslint/mui/rules/disallow-react-api-in-server-components.mjs +4 -1
  63. package/src/eslint/mui/rules/no-constructor-assigned-field.mjs +183 -0
  64. package/src/eslint/nodeSupportConfig.mjs +70 -0
  65. package/src/eslint/packageJsonConfig.mjs +50 -0
  66. package/src/eslint/testConfig.mjs +4 -2
  67. package/src/remark/config.mjs +60 -13
  68. package/src/utils/babelPlugin.mjs +52 -0
  69. package/src/utils/build.mjs +81 -0
  70. package/src/utils/cjsSourcesPlugin.mjs +92 -0
  71. package/src/utils/credentials.mjs +4 -3
  72. package/src/utils/dtsExportsPlugin.mjs +103 -0
  73. package/src/utils/dtsNamespacesPlugin.mjs +226 -0
  74. package/src/utils/extractErrorCodes.mjs +1 -3
  75. package/src/utils/fileUrlEntriesPlugin.mjs +84 -0
  76. package/src/utils/getPublishedPkgJson.mjs +86 -0
  77. package/src/utils/git.mjs +107 -46
  78. package/src/utils/github.mjs +27 -0
  79. package/src/utils/jsNamespacesPlugin.mjs +505 -0
  80. package/src/utils/pnpm.mjs +126 -25
  81. package/src/utils/publint.mjs +34 -0
  82. package/src/utils/rolldownOutput.mjs +70 -0
  83. package/src/utils/testUtils.mjs +26 -0
  84. package/src/utils/typescript.mjs +23 -13
  85. package/vale/styles/MUI/GoogleLatin.yml +5 -2
  86. package/build/cli/cmdArgosPush.d.mts +0 -18
  87. package/build/cli/cmdBuild.d.mts +0 -64
  88. package/build/cli/cmdCopyFiles.d.mts +0 -20
  89. package/build/cli/cmdExtractErrorCodes.d.mts +0 -6
  90. package/build/cli/cmdGenerateChangelog.d.mts +0 -32
  91. package/build/cli/cmdGithubAuth.d.mts +0 -11
  92. package/build/cli/cmdListWorkspaces.d.mts +0 -29
  93. package/build/cli/cmdNetlifyIgnore.d.mts +0 -17
  94. package/build/cli/cmdPublish.d.mts +0 -32
  95. package/build/cli/cmdPublishCanary.d.mts +0 -34
  96. package/build/cli/cmdPublishNewPackage.d.mts +0 -17
  97. package/build/cli/cmdRenameScope.d.mts +0 -18
  98. package/build/cli/cmdSetVersionOverrides.d.mts +0 -9
  99. package/build/cli/cmdVale.d.mts +0 -46
  100. package/build/cli/cmdValidateBuiltTypes.d.mts +0 -2
  101. package/build/cli/index.d.mts +0 -1
  102. package/vale/styles/MUI/CorrectRererenceCased.yml +0 -14
@@ -2,6 +2,40 @@
2
2
  * Changelog generation utilities.
3
3
  */
4
4
 
5
+ /**
6
+ * @typedef {import('./types.ts').FetchChangelogDataOptions} FetchChangelogDataOptions
7
+ * @typedef {import('./types.ts').ChangelogData} ChangelogData
8
+ * @typedef {import('./types.ts').ChangelogChange} ChangelogChange
9
+ * @typedef {import('./types.ts').ChangelogAuthor} ChangelogAuthor
10
+ * @typedef {import('./types.ts').ChangelogPackage} ChangelogPackage
11
+ * @typedef {import('./types.ts').ChangelogTitle} ChangelogTitle
12
+ * @typedef {import('./types.ts').ChangelogCredits} ChangelogCredits
13
+ * @typedef {import('./types.ts').MarkdownBlock} MarkdownBlock
14
+ * @typedef {import('./types.ts').MarkdownInline} MarkdownInline
15
+ */
16
+
5
17
  export { generateChangelog } from './generateChangelog.mjs';
6
18
  export * from './loadChangelogConfig.mjs';
7
19
  export * from './fetchChangelogs.mjs';
20
+ export { fetchChangelogData } from './fetchChangelogData.mjs';
21
+ export {
22
+ creditAuthors,
23
+ groupBy,
24
+ labelValues,
25
+ readLabels,
26
+ sortByTitle,
27
+ } from './changelogGrouping.mjs';
28
+ export {
29
+ bulletList,
30
+ formatAuthor,
31
+ formatDate,
32
+ formatReference,
33
+ formatSubHeader,
34
+ joinBlocks,
35
+ joinWords,
36
+ section,
37
+ } from './changelogMarkdown.mjs';
38
+ export { mapPrefixes, matchPrefix, parseTitle } from './changelogTitle.mjs';
39
+ // Moved to the git utilities, where the rest of the local git plumbing lives. Re-exported because
40
+ // `@mui/internal-code-infra/changelog` is a published entry point and this was part of it.
41
+ export { findLatestTaggedVersion } from '../utils/git.mjs';
@@ -0,0 +1,35 @@
1
+ import { retry } from '@octokit/plugin-retry';
2
+ import { throttling } from '@octokit/plugin-throttling';
3
+ import { Octokit } from '@octokit/rest';
4
+
5
+ import { persistentAuthStrategy } from '../utils/github.mjs';
6
+
7
+ const ThrottledOctokit = Octokit.plugin(throttling, retry);
8
+
9
+ /**
10
+ * Waits out short rate limits. Longer ones fail with the original error.
11
+ *
12
+ * @param {number} retryAfter - Seconds until the request may be retried
13
+ * @param {unknown} options
14
+ * @param {unknown} octokit
15
+ * @param {number} retryCount
16
+ * @returns {boolean}
17
+ */
18
+ function shouldRetryRateLimit(retryAfter, options, octokit, retryCount) {
19
+ return retryAfter <= 60 && retryCount < 3;
20
+ }
21
+
22
+ /**
23
+ * A client that authenticates as the developer running it.
24
+ *
25
+ * @returns {Octokit}
26
+ */
27
+ export function createOctokit() {
28
+ return new ThrottledOctokit({
29
+ authStrategy: persistentAuthStrategy,
30
+ throttle: {
31
+ onRateLimit: shouldRetryRateLimit,
32
+ onSecondaryRateLimit: shouldRetryRateLimit,
33
+ },
34
+ });
35
+ }
@@ -1,3 +1,7 @@
1
+ import type { Octokit } from '@octokit/rest';
2
+ // eslint-disable-next-line import/extensions
3
+ import type { RepoInfo } from '../utils/git.mjs';
4
+
1
5
  /**
2
6
  * Commit details fetched from GitHub including PR information and labels.
3
7
  */
@@ -438,3 +442,186 @@ export interface GenerateChangelogResult {
438
442
  all: string[];
439
443
  };
440
444
  }
445
+
446
+ export type GitHubRepository = Pick<RepoInfo, 'owner' | 'repo'>;
447
+
448
+ export interface ReleaseRef {
449
+ /**
450
+ * The ref as given. A local `HEAD` is replaced by its SHA.
451
+ */
452
+ ref: string;
453
+ sha: string;
454
+ }
455
+
456
+ export interface ChangelogAuthor {
457
+ /**
458
+ * `null` for a commit author without a linked GitHub account.
459
+ */
460
+ login: string | null;
461
+ /**
462
+ * Git author name. Only known for direct commits.
463
+ */
464
+ name: string | null;
465
+ association: 'team' | 'community' | 'first-timer';
466
+ /**
467
+ * Whether it is a bot that works on its own. Not for Copilot, which works for a person.
468
+ */
469
+ isBot: boolean;
470
+ }
471
+
472
+ /**
473
+ * A merged pull request, or a commit that landed without one.
474
+ */
475
+ export interface ChangelogChange {
476
+ /**
477
+ * Subject of the commit, without the references that the other fields already carry: the pull
478
+ * request it belongs to and, for a cherry-pick, the original pull request and its author.
479
+ */
480
+ title: string;
481
+ /**
482
+ * Full commit message.
483
+ */
484
+ message: string;
485
+ sha: string;
486
+ /**
487
+ * Page of the pull request, or of the commit when there is none.
488
+ */
489
+ url: string;
490
+ labels: string[];
491
+ /**
492
+ * Whether the pull request has the `breaking` or the `breaking change` label.
493
+ */
494
+ isBreakingChange: boolean;
495
+ pullRequest: {
496
+ number: number;
497
+ title: string;
498
+ body: string;
499
+ /**
500
+ * Not necessarily the author of the change: a cherry-pick can be opened by a bot, and Copilot
501
+ * works for a person. `null` when the GitHub account was deleted.
502
+ */
503
+ openedBy: ChangelogAuthor | null;
504
+ } | null;
505
+ /**
506
+ * `null` when the GitHub account was deleted.
507
+ */
508
+ author: ChangelogAuthor | null;
509
+ /**
510
+ * When the pull request was opened, or the commit authored. ISO 8601.
511
+ */
512
+ createdAt: string | null;
513
+ /**
514
+ * When the pull request was merged, or the commit committed. ISO 8601.
515
+ */
516
+ mergedAt: string | null;
517
+ }
518
+
519
+ export interface ChangelogPackage {
520
+ name: string;
521
+ version: string | null;
522
+ /**
523
+ * Whether the package can't be published: marked as private, or without a version.
524
+ */
525
+ private: boolean;
526
+ /**
527
+ * Directory relative to the workspace root, with `/` separators. `.` for the root package.
528
+ */
529
+ path: string;
530
+ /**
531
+ * Whether the version differs from the previous release. `true` for a new package, `null` when the
532
+ * previous release isn't available locally.
533
+ */
534
+ changed: boolean | null;
535
+ }
536
+
537
+ /**
538
+ * What happened in a release, as JSON-serializable data.
539
+ */
540
+ export interface ChangelogData {
541
+ repository: GitHubRepository;
542
+ previous: ReleaseRef;
543
+ release: ReleaseRef;
544
+ version: string;
545
+ /**
546
+ * ISO 8601.
547
+ */
548
+ date: string;
549
+ /**
550
+ * Oldest first.
551
+ */
552
+ changes: ChangelogChange[];
553
+ /**
554
+ * Named packages in the working tree, sorted by path. Without a workspace, only the root package.
555
+ */
556
+ packages: ChangelogPackage[];
557
+ }
558
+
559
+ export interface FetchChangelogDataOptions {
560
+ /**
561
+ * A directory of the released workspace.
562
+ * @default process.cwd()
563
+ */
564
+ cwd?: string;
565
+ /**
566
+ * Repository name. Defaults to the one the checkout's remote points at.
567
+ */
568
+ repo?: string;
569
+ /**
570
+ * @default 'mui'
571
+ */
572
+ org?: string;
573
+ /**
574
+ * Ref of the previous release. Defaults to the closest version tag before `release`.
575
+ */
576
+ lastRelease?: string;
577
+ /**
578
+ * Ref of the release.
579
+ * @default 'HEAD'
580
+ */
581
+ release?: string;
582
+ /**
583
+ * Defaults to the version `release` is a tag of, else the version of the root package.
584
+ */
585
+ version?: string;
586
+ /**
587
+ * Defaults to the commit date when `release` is a version tag, else now.
588
+ */
589
+ date?: Date | string;
590
+ /**
591
+ * Include commits that landed without a pull request.
592
+ * @default false
593
+ */
594
+ includeDirectCommits?: boolean;
595
+ /**
596
+ * Bots whose changes are left out, as `app/<slug>` like in GitHub search, or as their login, such
597
+ * as `renovate[bot]`. A change is left out when its author or the opener of its pull request is
598
+ * one of them. Pass `[]` to keep all.
599
+ * @default ['app/renovate', 'app/code-infra-renovate']
600
+ */
601
+ excludeBots?: string[];
602
+ /**
603
+ * GitHub client. Defaults to one authenticated as the developer running it.
604
+ */
605
+ octokit?: Octokit;
606
+ }
607
+
608
+ /**
609
+ * Title of a change, split into its leading `[prefixes]` and the rest.
610
+ */
611
+ export interface ChangelogTitle {
612
+ prefixes: string[];
613
+ text: string;
614
+ }
615
+
616
+ /**
617
+ * Authors to credit, once each.
618
+ */
619
+ export interface ChangelogCredits {
620
+ all: ChangelogAuthor[];
621
+ team: ChangelogAuthor[];
622
+ community: ChangelogAuthor[];
623
+ }
624
+
625
+ export type MarkdownInline = string | false | null | undefined;
626
+
627
+ export type MarkdownBlock = MarkdownInline | readonly MarkdownBlock[];
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ /* eslint-disable no-console */
4
+
5
+ import { resolveBaseline } from '../utils/git.mjs';
6
+
7
+ /**
8
+ * @typedef {Object} Args
9
+ * @property {string} [baseBranch] - Branch pull requests fork from
10
+ * @property {string} [remote] - Remote the base branch is fetched from
11
+ */
12
+
13
+ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
14
+ command: 'baseline',
15
+ describe: 'Print the commit HEAD should be compared against',
16
+ builder: (yargs) => {
17
+ return yargs
18
+ .option('base-branch', {
19
+ type: 'string',
20
+ description: "Branch pull requests fork from. Default: the remote's default branch",
21
+ })
22
+ .option('remote', {
23
+ type: 'string',
24
+ description:
25
+ 'Remote the base branch is fetched from. Default: upstream, else origin, whichever points at a mui repository',
26
+ });
27
+ },
28
+ handler: async (argv) => {
29
+ console.log(await resolveBaseline({ baseBranch: argv.baseBranch, remote: argv.remote }));
30
+ },
31
+ });
@@ -7,13 +7,9 @@ import { sep as posixSep } from 'node:path/posix';
7
7
  import * as semver from 'semver';
8
8
  import { mapAsync } from 'es-toolkit/array';
9
9
 
10
- import {
11
- createPackageBin,
12
- createPackageExports,
13
- createPackageImports,
14
- getOutExtension,
15
- validatePkgJson,
16
- } from '../utils/build.mjs';
10
+ import { getOutExtension, validateEnginesNode, validatePkgJson } from '../utils/build.mjs';
11
+ import { getPublishedPkgJson } from '../utils/getPublishedPkgJson.mjs';
12
+ import { validateWithPublint } from '../utils/publint.mjs';
17
13
  import { readPnpmConfig } from '../utils/pnpm.mjs';
18
14
 
19
15
  /**
@@ -27,6 +23,7 @@ import { readPnpmConfig } from '../utils/pnpm.mjs';
27
23
  * @property {boolean} skipBabelRuntimeCheck - Whether to skip checking for Babel runtime dependencies in the package.
28
24
  * @property {boolean} skipPackageJson - Whether to skip generating the package.json file in the bundle output.
29
25
  * @property {boolean} skipMainCheck - Whether to skip checking for main field in package.json.
26
+ * @property {boolean} skipPublint - Whether to skip validating the output directory with publint.
30
27
  * @property {string[]} ignore - Globs to be ignored by Babel.
31
28
  * @property {string[]} [copy] - Files/Directories to be copied. Can be a glob pattern.
32
29
  * @property {boolean} [enableReactCompiler] - Whether to use the React compiler.
@@ -78,87 +75,6 @@ ${content}`,
78
75
  console.log(`License added to ${file}`);
79
76
  }
80
77
 
81
- /**
82
- * @param {Object} param0
83
- * @param {import('./packageJson').PackageJson} param0.packageJson - The package.json content.
84
- * @param {import('../utils/build.mjs').BundleType[]} param0.bundles
85
- * @param {string} param0.outputDir
86
- * @param {string} param0.cwd
87
- * @param {boolean} param0.addTypes - Whether to add type declarations for the package.
88
- * @param {boolean} [param0.expand] - Whether to enumerate glob patterns into concrete entries.
89
- * @param {'module' | 'commonjs'} param0.packageType - The package.json type field.
90
- */
91
- async function writePackageJson({
92
- packageJson,
93
- bundles,
94
- outputDir,
95
- cwd,
96
- addTypes = false,
97
- expand = true,
98
- packageType,
99
- }) {
100
- delete packageJson.scripts;
101
- delete packageJson.publishConfig?.directory;
102
- delete packageJson.devDependencies;
103
-
104
- const resolvedPackageType = packageType || packageJson.type || 'commonjs';
105
- packageJson.type = resolvedPackageType;
106
-
107
- const originalExports = packageJson.exports;
108
- delete packageJson.exports;
109
- const originalImports = packageJson.imports;
110
- delete packageJson.imports;
111
- const originalBin = packageJson.bin;
112
- delete packageJson.bin;
113
-
114
- const [{ exports: packageExports, main, types }, packageImports] = await Promise.all([
115
- createPackageExports(originalExports, {
116
- bundles,
117
- outputDir,
118
- cwd,
119
- addTypes,
120
- expand,
121
- packageType: resolvedPackageType,
122
- }),
123
- originalImports
124
- ? createPackageImports(originalImports, {
125
- bundles,
126
- cwd,
127
- outputDir,
128
- addTypes,
129
- expand,
130
- packageType: resolvedPackageType,
131
- })
132
- : Promise.resolve(undefined),
133
- ]);
134
-
135
- packageJson.exports = packageExports;
136
- if (packageImports) {
137
- packageJson.imports = packageImports;
138
- }
139
- if (main) {
140
- packageJson.main = main;
141
- }
142
- if (types) {
143
- packageJson.types = types;
144
- }
145
-
146
- const bin = await createPackageBin(originalBin, {
147
- bundles,
148
- cwd,
149
- packageType: resolvedPackageType,
150
- });
151
- if (bin) {
152
- packageJson.bin = bin;
153
- }
154
-
155
- await fs.writeFile(
156
- path.join(outputDir, 'package.json'),
157
- JSON.stringify(packageJson, null, 2),
158
- 'utf-8',
159
- );
160
- }
161
-
162
78
  export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
163
79
  command: 'build',
164
80
  describe: 'Builds the package for publishing.',
@@ -215,6 +131,11 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
215
131
  default: false,
216
132
  description: 'Skip checking for main field in package.json.',
217
133
  })
134
+ .option('skipPublint', {
135
+ type: 'boolean',
136
+ default: false,
137
+ description: 'Skip validating the output directory with publint.',
138
+ })
218
139
  .option('copy', {
219
140
  type: 'string',
220
141
  array: true,
@@ -266,6 +187,7 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
266
187
  const pkgJsonPath = path.join(cwd, 'package.json');
267
188
  const packageJson = JSON.parse(await fs.readFile(pkgJsonPath, { encoding: 'utf8' }));
268
189
  validatePkgJson(packageJson, { skipMainCheck: args.skipMainCheck, enableReactCompiler });
190
+ validateEnginesNode(packageJson, cwd);
269
191
 
270
192
  const buildDirBase = /** @type {string} */ (packageJson.publishConfig?.directory);
271
193
  const buildDir = path.join(cwd, buildDirBase);
@@ -374,7 +296,7 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
374
296
  return;
375
297
  }
376
298
 
377
- await writePackageJson({
299
+ const publishedPkgJson = await getPublishedPkgJson({
378
300
  cwd,
379
301
  packageJson,
380
302
  bundles,
@@ -383,6 +305,11 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
383
305
  expand: args.expand,
384
306
  packageType,
385
307
  });
308
+ await fs.writeFile(
309
+ path.join(buildDir, 'package.json'),
310
+ JSON.stringify(publishedPkgJson, null, 2),
311
+ 'utf-8',
312
+ );
386
313
 
387
314
  await copyHandler({
388
315
  cwd,
@@ -390,6 +317,10 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
390
317
  buildDir,
391
318
  verbose: args.verbose,
392
319
  });
320
+
321
+ if (!args.skipPublint) {
322
+ await validateWithPublint(buildDir);
323
+ }
393
324
  },
394
325
  });
395
326