@mui/internal-code-infra 0.1.1-canary.36 → 0.1.1-canary.38

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 (40) hide show
  1. package/README.md +24 -5
  2. package/build/babel-config.d.mts +7 -1
  3. package/build/changelog/changelogChanges.d.mts +36 -0
  4. package/build/changelog/changelogTags.d.mts +15 -0
  5. package/build/changelog/fetchChangelogData.d.mts +16 -0
  6. package/build/changelog/index.d.mts +13 -0
  7. package/build/changelog/octokit.d.mts +7 -0
  8. package/build/changelog/types.d.ts +137 -0
  9. package/build/utils/babelPlugin.d.mts +8 -0
  10. package/build/utils/cjsSourcesPlugin.d.mts +11 -0
  11. package/build/utils/dtsExportsPlugin.d.mts +8 -0
  12. package/build/utils/dtsNamespacesPlugin.d.mts +19 -0
  13. package/build/utils/getPublishedPkgJson.d.mts +20 -0
  14. package/build/utils/jsNamespacesPlugin.d.mts +13 -0
  15. package/build/utils/publint.d.mts +6 -0
  16. package/build/utils/rolldownOutput.d.mts +38 -0
  17. package/build/utils/testUtils.d.mts +1 -0
  18. package/build/utils/typescript.d.mts +5 -0
  19. package/package.json +2 -2
  20. package/src/babel-config.mjs +35 -1
  21. package/src/changelog/changelogChanges.mjs +418 -0
  22. package/src/changelog/changelogTags.mjs +34 -0
  23. package/src/changelog/fetchChangelogData.mjs +171 -0
  24. package/src/changelog/fetchChangelogs.mjs +3 -30
  25. package/src/changelog/index.mjs +9 -0
  26. package/src/changelog/octokit.mjs +35 -0
  27. package/src/changelog/types.ts +142 -0
  28. package/src/cli/cmdBuild.mjs +9 -125
  29. package/src/cli/cmdBuildNew.mjs +403 -20
  30. package/src/utils/babelPlugin.mjs +52 -0
  31. package/src/utils/cjsSourcesPlugin.mjs +92 -0
  32. package/src/utils/dtsExportsPlugin.mjs +103 -0
  33. package/src/utils/dtsNamespacesPlugin.mjs +226 -0
  34. package/src/utils/getPublishedPkgJson.mjs +86 -0
  35. package/src/utils/jsNamespacesPlugin.mjs +505 -0
  36. package/src/utils/publint.mjs +34 -0
  37. package/src/utils/rolldownOutput.mjs +70 -0
  38. package/src/utils/testUtils.mjs +8 -0
  39. package/src/utils/typescript.mjs +22 -12
  40. package/build/brokenLinksChecker/__fixtures__/no-signal-forwarding.d.mts +0 -1
@@ -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,141 @@ 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
+
468
+ /**
469
+ * A merged pull request, or a commit that landed without one.
470
+ */
471
+ export interface ChangelogChange {
472
+ /**
473
+ * Subject of the commit, without the references that the other fields already carry: the pull
474
+ * request it belongs to and, for a cherry-pick, the original pull request and its author.
475
+ */
476
+ title: string;
477
+ /**
478
+ * Full commit message.
479
+ */
480
+ message: string;
481
+ sha: string;
482
+ /**
483
+ * Page of the pull request, or of the commit when there is none.
484
+ */
485
+ url: string;
486
+ labels: string[];
487
+ pullRequest: { number: number; title: string; body: string } | null;
488
+ /**
489
+ * `null` when the GitHub account was deleted.
490
+ */
491
+ author: ChangelogAuthor | null;
492
+ /**
493
+ * When the pull request was opened, or the commit authored. ISO 8601.
494
+ */
495
+ createdAt: string | null;
496
+ /**
497
+ * When the pull request was merged, or the commit committed. ISO 8601.
498
+ */
499
+ mergedAt: string | null;
500
+ }
501
+
502
+ export interface ChangelogPackage {
503
+ name: string;
504
+ version: string | null;
505
+ /**
506
+ * Whether the package can't be published: marked as private, or without a version.
507
+ */
508
+ private: boolean;
509
+ /**
510
+ * Directory relative to the workspace root, with `/` separators. `.` for the root package.
511
+ */
512
+ path: string;
513
+ /**
514
+ * Whether the version differs from the previous release. `true` for a new package, `null` when the
515
+ * previous release isn't available locally.
516
+ */
517
+ changed: boolean | null;
518
+ }
519
+
520
+ /**
521
+ * What happened in a release, as JSON-serializable data.
522
+ */
523
+ export interface ChangelogData {
524
+ repository: GitHubRepository;
525
+ previous: ReleaseRef;
526
+ release: ReleaseRef;
527
+ version: string;
528
+ /**
529
+ * ISO 8601.
530
+ */
531
+ date: string;
532
+ /**
533
+ * Oldest first.
534
+ */
535
+ changes: ChangelogChange[];
536
+ /**
537
+ * Named packages in the working tree, sorted by path. Without a workspace, only the root package.
538
+ */
539
+ packages: ChangelogPackage[];
540
+ }
541
+
542
+ export interface FetchChangelogDataOptions {
543
+ /**
544
+ * A directory of the released workspace.
545
+ * @default process.cwd()
546
+ */
547
+ cwd?: string;
548
+ /**
549
+ * Repository name. Defaults to the one the checkout's remote points at.
550
+ */
551
+ repo?: string;
552
+ /**
553
+ * @default 'mui'
554
+ */
555
+ org?: string;
556
+ /**
557
+ * Ref of the previous release. Defaults to the closest version tag before `release`.
558
+ */
559
+ lastRelease?: string;
560
+ /**
561
+ * Ref of the release.
562
+ * @default 'HEAD'
563
+ */
564
+ release?: string;
565
+ /**
566
+ * Defaults to the version `release` is a tag of, else the version of the root package.
567
+ */
568
+ version?: string;
569
+ /**
570
+ * Defaults to the commit date when `release` is a version tag, else now.
571
+ */
572
+ date?: Date | string;
573
+ /**
574
+ * Include commits that landed without a pull request.
575
+ * @default false
576
+ */
577
+ includeDirectCommits?: boolean;
578
+ /**
579
+ * GitHub client. Defaults to one authenticated as the developer running it.
580
+ */
581
+ octokit?: Octokit;
582
+ }
@@ -7,14 +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
- validateEnginesNode,
16
- validatePkgJson,
17
- } 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';
18
13
  import { readPnpmConfig } from '../utils/pnpm.mjs';
19
14
 
20
15
  /**
@@ -80,87 +75,6 @@ ${content}`,
80
75
  console.log(`License added to ${file}`);
81
76
  }
82
77
 
83
- /**
84
- * @param {Object} param0
85
- * @param {import('./packageJson').PackageJson} param0.packageJson - The package.json content.
86
- * @param {import('../utils/build.mjs').BundleType[]} param0.bundles
87
- * @param {string} param0.outputDir
88
- * @param {string} param0.cwd
89
- * @param {boolean} param0.addTypes - Whether to add type declarations for the package.
90
- * @param {boolean} [param0.expand] - Whether to enumerate glob patterns into concrete entries.
91
- * @param {'module' | 'commonjs'} param0.packageType - The package.json type field.
92
- */
93
- async function writePackageJson({
94
- packageJson,
95
- bundles,
96
- outputDir,
97
- cwd,
98
- addTypes = false,
99
- expand = true,
100
- packageType,
101
- }) {
102
- delete packageJson.scripts;
103
- delete packageJson.publishConfig?.directory;
104
- delete packageJson.devDependencies;
105
-
106
- const resolvedPackageType = packageType || packageJson.type || 'commonjs';
107
- packageJson.type = resolvedPackageType;
108
-
109
- const originalExports = packageJson.exports;
110
- delete packageJson.exports;
111
- const originalImports = packageJson.imports;
112
- delete packageJson.imports;
113
- const originalBin = packageJson.bin;
114
- delete packageJson.bin;
115
-
116
- const [{ exports: packageExports, main, types }, packageImports] = await Promise.all([
117
- createPackageExports(originalExports, {
118
- bundles,
119
- outputDir,
120
- cwd,
121
- addTypes,
122
- expand,
123
- packageType: resolvedPackageType,
124
- }),
125
- originalImports
126
- ? createPackageImports(originalImports, {
127
- bundles,
128
- cwd,
129
- outputDir,
130
- addTypes,
131
- expand,
132
- packageType: resolvedPackageType,
133
- })
134
- : Promise.resolve(undefined),
135
- ]);
136
-
137
- packageJson.exports = packageExports;
138
- if (packageImports) {
139
- packageJson.imports = packageImports;
140
- }
141
- if (main) {
142
- packageJson.main = main;
143
- }
144
- if (types) {
145
- packageJson.types = types;
146
- }
147
-
148
- const bin = await createPackageBin(originalBin, {
149
- bundles,
150
- cwd,
151
- packageType: resolvedPackageType,
152
- });
153
- if (bin) {
154
- packageJson.bin = bin;
155
- }
156
-
157
- await fs.writeFile(
158
- path.join(outputDir, 'package.json'),
159
- JSON.stringify(packageJson, null, 2),
160
- 'utf-8',
161
- );
162
- }
163
-
164
78
  export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
165
79
  command: 'build',
166
80
  describe: 'Builds the package for publishing.',
@@ -382,7 +296,7 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
382
296
  return;
383
297
  }
384
298
 
385
- await writePackageJson({
299
+ const publishedPkgJson = await getPublishedPkgJson({
386
300
  cwd,
387
301
  packageJson,
388
302
  bundles,
@@ -391,6 +305,11 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
391
305
  expand: args.expand,
392
306
  packageType,
393
307
  });
308
+ await fs.writeFile(
309
+ path.join(buildDir, 'package.json'),
310
+ JSON.stringify(publishedPkgJson, null, 2),
311
+ 'utf-8',
312
+ );
394
313
 
395
314
  await copyHandler({
396
315
  cwd,
@@ -405,41 +324,6 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
405
324
  },
406
325
  });
407
326
 
408
- /**
409
- * Lints the output directory with publint. Errors fail the build, warnings are only reported.
410
- * @param {string} buildDir - The build directory to validate.
411
- * @returns {Promise<void>}
412
- */
413
- async function validateWithPublint(buildDir) {
414
- const [{ publint }, { formatMessage }] = await Promise.all([
415
- import('publint'),
416
- import('publint/utils'),
417
- ]);
418
- // Everything in the output directory is published, so there is nothing to pack.
419
- const result = await publint({ pkgDir: buildDir, pack: false, level: 'warning' });
420
- const { pkg } = result;
421
- // TODO: remove this filter and bump publint to >=0.3.25, which ships the fix from
422
- // https://github.com/publint/publint/pull/265 (publint checks `browser` values
423
- // that point at another package as local files).
424
- const messages = result.messages.filter((message) => {
425
- if (message.code !== 'FILE_DOES_NOT_EXIST' || message.path[0] !== 'browser') {
426
- return true;
427
- }
428
- const value = message.path.length === 2 ? pkg.browser?.[message.path[1]] : undefined;
429
- return typeof value !== 'string' || value.startsWith('.');
430
- });
431
-
432
- for (const message of messages) {
433
- const log = message.type === 'error' ? console.error : console.warn;
434
- log(`publint ${message.type}: ${formatMessage(message, pkg)}`);
435
- }
436
-
437
- const errorCount = messages.filter((message) => message.type === 'error').length;
438
- if (errorCount > 0) {
439
- throw new Error(`publint found ${errorCount} error(s) in "${buildDir}".`);
440
- }
441
- }
442
-
443
327
  /**
444
328
  * @param {Object} param0
445
329
  * @param {string} param0.cwd - The current working directory.