@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
package/README.md CHANGED
@@ -81,9 +81,28 @@ The agent skills previously shipped with this package now live at the repository
81
81
  ## Upcoming tsdown builds
82
82
 
83
83
  `code-infra build-new` is experimental. It compiles the `src` modules behind the package's
84
- `exports`, `imports` and `bin`, plus every module they import, to the `publishConfig.directory`
85
- with tsdown, keeping every package import external. Modules loaded with
84
+ `exports`, `imports` and `bin`, plus every module they import, to the `publishConfig.directory` with
85
+ tsdown, keeping every package import external. Modules loaded with
86
86
  `new URL('./file', import.meta.url)`, such as workers, are built too, and the URL points at their
87
- output. It does not
88
- apply the Babel configuration or write declarations, `package.json` or extra files.
89
- Continue using `code-infra build` for package builds.
87
+ output. It copies files with tsdown's `copy` option using the same `--copy` rules as
88
+ `code-infra build`. It writes the same `package.json` as `code-infra build` (the deprecated
89
+ `--no-expand` keeps `exports`/`imports` patterns). Every JavaScript file starts with the package's
90
+ license header. Oxc strips types, compiles JSX and lowers syntax for the `stable` (ESM) and `node`
91
+ (CJS) browserslist environments, and `MUI_VERSION` variables are inlined. Babel runs the workspace
92
+ `babel.config.js` with `getBaseConfig` reduced to the MUI plugins Oxc lacks: display names, React
93
+ pure annotations, prop-types removal and clsx optimization, plus the React compiler with
94
+ `--enableReactCompiler`. Babel helpers, and the helpers Oxc's lowering needs, are imported from the
95
+ `@babel/runtime` version the package depends on; the build fails when the output imports them
96
+ without that dependency. Declarations come from tsdown's `dts` with the workspace TypeScript 7 `tsc`
97
+ and the package's `tsconfig.build.json` (`--no-buildTypes` skips them); hand-written `.d.ts` files
98
+ need explicit exports. The output keeps `export * as` and `import * as` namespaces, which Rolldown
99
+ turns into `<name>_exports` objects in unbundled builds. A namespace stays an object when Rolldown
100
+ inlines its constants into it, when the module reads it itself, or, in JavaScript, when it is
101
+ imported next to a default import or by a quoted name. The output is validated with publint, as in
102
+ `code-infra build`. With
103
+ `--cjsCopy`, imported `.cjs` sources are emitted unchanged and imported as-is, as in
104
+ `code-infra build`, and the local modules they `require` are built at the paths they name; the build
105
+ fails when no bundle outputs a module at that path. `--cjsCopy` is deprecated: only
106
+ `@mui/material-nextjs` needs it, until `next` has an `exports` map
107
+ ([vercel/next.js#77200](https://github.com/vercel/next.js/issues/77200)). Continue using
108
+ `code-infra build` for package builds.
@@ -1,7 +1,11 @@
1
1
  export type ReactCompilationMode = 'annotation' | 'syntax' | 'infer' | 'all';
2
+ export type Compiler = 'babel' | 'oxc';
2
3
  /**
3
4
  * @typedef {'annotation' | 'syntax' | 'infer' | 'all'} ReactCompilationMode
4
5
  */
6
+ /**
7
+ * @typedef {'babel' | 'oxc'} Compiler
8
+ */
5
9
  /**
6
10
  * @param {Object} param0
7
11
  * @param {boolean} [param0.debug]
@@ -14,9 +18,10 @@ export type ReactCompilationMode = 'annotation' | 'syntax' | 'infer' | 'all';
14
18
  * @param {string} [param0.reactCompilerReactVersion]
15
19
  * @param {ReactCompilationMode} [param0.reactCompilerMode]
16
20
  * @param {{ allowedCallees?: Record<string, string[]> }} [param0.displayName] - Options for the display name plugin.
21
+ * @param {Compiler} [param0.compiler] - `oxc` keeps only the plugins Oxc has no equivalent for.
17
22
  * @returns {import('@babel/core').InputOptions} The base Babel configuration.
18
23
  */
19
- export declare function getBaseConfig({ debug, optimizeClsx, removePropTypes, noResolveImports, bundle, runtimeVersion, outExtension, reactCompilerReactVersion, reactCompilerMode, displayName, }: {
24
+ export declare function getBaseConfig({ debug, optimizeClsx, removePropTypes, noResolveImports, bundle, runtimeVersion, outExtension, reactCompilerReactVersion, reactCompilerMode, displayName, compiler, }: {
20
25
  debug?: boolean;
21
26
  optimizeClsx?: boolean;
22
27
  removePropTypes?: boolean;
@@ -29,6 +34,7 @@ export declare function getBaseConfig({ debug, optimizeClsx, removePropTypes, no
29
34
  displayName?: {
30
35
  allowedCallees?: Record<string, string[]>;
31
36
  };
37
+ compiler?: Compiler;
32
38
  }): import('@babel/core').InputOptions;
33
39
  export type Options = {
34
40
  bundle?: 'esm' | 'cjs';
@@ -0,0 +1,36 @@
1
+ export type Octokit = import('@octokit/rest').Octokit;
2
+ export type GitHubRepository = import('./types.ts').GitHubRepository;
3
+ export type ChangelogAuthor = import('./types.ts').ChangelogAuthor;
4
+ export type ChangelogChange = import('./types.ts').ChangelogChange;
5
+ export type Commit = Awaited<ReturnType<Octokit['repos']['compareCommitsWithBasehead']>>['data']['commits'][number];
6
+ export type PullRequest = {
7
+ number: number;
8
+ title: string;
9
+ body: string | null;
10
+ user: {
11
+ login: string;
12
+ type: string;
13
+ } | null;
14
+ author_association: string;
15
+ labels: {
16
+ name?: string;
17
+ }[];
18
+ };
19
+ /**
20
+ * @param {Object} options
21
+ * @param {Octokit} options.octokit
22
+ * @param {GitHubRepository} options.repository
23
+ * @param {string} options.previousSha
24
+ * @param {string} options.releaseSha
25
+ * @param {boolean} options.includeDirectCommits
26
+ * @param {AbortController} options.controller - Aborted when a request fails
27
+ * @returns {Promise<ChangelogChange[]>}
28
+ */
29
+ export declare function fetchChangelogChanges({ octokit, repository, previousSha, releaseSha, includeDirectCommits, controller, }: {
30
+ octokit: Octokit;
31
+ repository: GitHubRepository;
32
+ previousSha: string;
33
+ releaseSha: string;
34
+ includeDirectCommits: boolean;
35
+ controller: AbortController;
36
+ }): Promise<ChangelogChange[]>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The closest version tag behind a commit. Tags on the commit itself are the release being made, not
3
+ * the one before it.
4
+ *
5
+ * @param {Object} options
6
+ * @param {string} options.cwd
7
+ * @param {string | null} options.remote - Remote to fetch the tags and the commit from
8
+ * @param {string} options.sha
9
+ * @returns {Promise<string>}
10
+ */
11
+ export declare function findPreviousVersionTag({ cwd, remote, sha }: {
12
+ cwd: string;
13
+ remote: string | null;
14
+ sha: string;
15
+ }): Promise<string>;
@@ -0,0 +1,16 @@
1
+ export type FetchChangelogDataOptions = import('./types.ts').FetchChangelogDataOptions;
2
+ export type GitHubRepository = import('./types.ts').GitHubRepository;
3
+ export type ChangelogData = import('./types.ts').ChangelogData;
4
+ /**
5
+ * @typedef {import('./types.ts').FetchChangelogDataOptions} FetchChangelogDataOptions
6
+ * @typedef {import('./types.ts').GitHubRepository} GitHubRepository
7
+ * @typedef {import('./types.ts').ChangelogData} ChangelogData
8
+ */
9
+ /**
10
+ * Collects what happened in a release: its changes and its packages. Run inside a checkout of the
11
+ * repository, every option is optional.
12
+ *
13
+ * @param {FetchChangelogDataOptions} [options]
14
+ * @returns {Promise<ChangelogData>}
15
+ */
16
+ export declare function fetchChangelogData(options?: FetchChangelogDataOptions): Promise<ChangelogData>;
@@ -1,7 +1,20 @@
1
1
  /**
2
2
  * Changelog generation utilities.
3
3
  */
4
+ export type FetchChangelogDataOptions = import('./types.ts').FetchChangelogDataOptions;
5
+ export type ChangelogData = import('./types.ts').ChangelogData;
6
+ export type ChangelogChange = import('./types.ts').ChangelogChange;
7
+ export type ChangelogAuthor = import('./types.ts').ChangelogAuthor;
8
+ export type ChangelogPackage = import('./types.ts').ChangelogPackage;
9
+ /**
10
+ * @typedef {import('./types.ts').FetchChangelogDataOptions} FetchChangelogDataOptions
11
+ * @typedef {import('./types.ts').ChangelogData} ChangelogData
12
+ * @typedef {import('./types.ts').ChangelogChange} ChangelogChange
13
+ * @typedef {import('./types.ts').ChangelogAuthor} ChangelogAuthor
14
+ * @typedef {import('./types.ts').ChangelogPackage} ChangelogPackage
15
+ */
4
16
  export { generateChangelog } from './generateChangelog.mjs';
5
17
  export * from './loadChangelogConfig.mjs';
6
18
  export * from './fetchChangelogs.mjs';
19
+ export { fetchChangelogData } from './fetchChangelogData.mjs';
7
20
  export { findLatestTaggedVersion } from '../utils/git.mjs';
@@ -0,0 +1,7 @@
1
+ import { Octokit } from '@octokit/rest';
2
+ /**
3
+ * A client that authenticates as the developer running it.
4
+ *
5
+ * @returns {Octokit}
6
+ */
7
+ export declare function createOctokit(): Octokit;
@@ -1,3 +1,5 @@
1
+ import type { Octokit } from '@octokit/rest';
2
+ import type { RepoInfo } from '../utils/git.mjs';
1
3
  /**
2
4
  * Commit details fetched from GitHub including PR information and labels.
3
5
  */
@@ -390,3 +392,138 @@ export interface GenerateChangelogResult {
390
392
  all: string[];
391
393
  };
392
394
  }
395
+ export type GitHubRepository = Pick<RepoInfo, 'owner' | 'repo'>;
396
+ export interface ReleaseRef {
397
+ /**
398
+ * The ref as given. A local `HEAD` is replaced by its SHA.
399
+ */
400
+ ref: string;
401
+ sha: string;
402
+ }
403
+ export interface ChangelogAuthor {
404
+ /**
405
+ * `null` for a commit author without a linked GitHub account.
406
+ */
407
+ login: string | null;
408
+ /**
409
+ * Git author name. Only known for direct commits.
410
+ */
411
+ name: string | null;
412
+ association: 'team' | 'community' | 'first-timer';
413
+ }
414
+ /**
415
+ * A merged pull request, or a commit that landed without one.
416
+ */
417
+ export interface ChangelogChange {
418
+ /**
419
+ * Subject of the commit, without the references that the other fields already carry: the pull
420
+ * request it belongs to and, for a cherry-pick, the original pull request and its author.
421
+ */
422
+ title: string;
423
+ /**
424
+ * Full commit message.
425
+ */
426
+ message: string;
427
+ sha: string;
428
+ /**
429
+ * Page of the pull request, or of the commit when there is none.
430
+ */
431
+ url: string;
432
+ labels: string[];
433
+ pullRequest: {
434
+ number: number;
435
+ title: string;
436
+ body: string;
437
+ } | null;
438
+ /**
439
+ * `null` when the GitHub account was deleted.
440
+ */
441
+ author: ChangelogAuthor | null;
442
+ /**
443
+ * When the pull request was opened, or the commit authored. ISO 8601.
444
+ */
445
+ createdAt: string | null;
446
+ /**
447
+ * When the pull request was merged, or the commit committed. ISO 8601.
448
+ */
449
+ mergedAt: string | null;
450
+ }
451
+ export interface ChangelogPackage {
452
+ name: string;
453
+ version: string | null;
454
+ /**
455
+ * Whether the package can't be published: marked as private, or without a version.
456
+ */
457
+ private: boolean;
458
+ /**
459
+ * Directory relative to the workspace root, with `/` separators. `.` for the root package.
460
+ */
461
+ path: string;
462
+ /**
463
+ * Whether the version differs from the previous release. `true` for a new package, `null` when the
464
+ * previous release isn't available locally.
465
+ */
466
+ changed: boolean | null;
467
+ }
468
+ /**
469
+ * What happened in a release, as JSON-serializable data.
470
+ */
471
+ export interface ChangelogData {
472
+ repository: GitHubRepository;
473
+ previous: ReleaseRef;
474
+ release: ReleaseRef;
475
+ version: string;
476
+ /**
477
+ * ISO 8601.
478
+ */
479
+ date: string;
480
+ /**
481
+ * Oldest first.
482
+ */
483
+ changes: ChangelogChange[];
484
+ /**
485
+ * Named packages in the working tree, sorted by path. Without a workspace, only the root package.
486
+ */
487
+ packages: ChangelogPackage[];
488
+ }
489
+ export interface FetchChangelogDataOptions {
490
+ /**
491
+ * A directory of the released workspace.
492
+ * @default process.cwd()
493
+ */
494
+ cwd?: string;
495
+ /**
496
+ * Repository name. Defaults to the one the checkout's remote points at.
497
+ */
498
+ repo?: string;
499
+ /**
500
+ * @default 'mui'
501
+ */
502
+ org?: string;
503
+ /**
504
+ * Ref of the previous release. Defaults to the closest version tag before `release`.
505
+ */
506
+ lastRelease?: string;
507
+ /**
508
+ * Ref of the release.
509
+ * @default 'HEAD'
510
+ */
511
+ release?: string;
512
+ /**
513
+ * Defaults to the version `release` is a tag of, else the version of the root package.
514
+ */
515
+ version?: string;
516
+ /**
517
+ * Defaults to the commit date when `release` is a version tag, else now.
518
+ */
519
+ date?: Date | string;
520
+ /**
521
+ * Include commits that landed without a pull request.
522
+ * @default false
523
+ */
524
+ includeDirectCommits?: boolean;
525
+ /**
526
+ * GitHub client. Defaults to one authenticated as the developer running it.
527
+ */
528
+ octokit?: Octokit;
529
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Runs a Babel config in `oxc` mode: `getBaseConfig` keeps only the plugins Oxc has no
3
+ * equivalent for, and the config file adds its own. Oxc then strips types, compiles JSX and
4
+ * lowers syntax.
5
+ * @param {string} configFile
6
+ * @returns {import('tsdown').Rolldown.Plugin}
7
+ */
8
+ export declare function babelPlugin(configFile: string): import('tsdown').Rolldown.Plugin;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Ships `.cjs` sources unchanged. Rolldown would turn them into ESM whose `require` calls go
3
+ * through a runtime helper bundlers can't resolve, so imports of them stay as written and each is
4
+ * emitted as is. The local modules one requires are built at the path the `require` names. Only
5
+ * `@mui/material-nextjs` needs it: its `.cjs` shims exist because `next` has no `exports` map
6
+ * (https://github.com/vercel/next.js/issues/77200). Remove this plugin once that is fixed.
7
+ * @param {string} sourceDir
8
+ * @param {string | undefined} cjsExtension The CommonJS bundle's output extension, if it is built.
9
+ * @returns {import('tsdown').Rolldown.Plugin}
10
+ */
11
+ export declare function cjsSourcesPlugin(sourceDir: string, cjsExtension: string | undefined): import('tsdown').Rolldown.Plugin;
@@ -0,0 +1,8 @@
1
+ export type Body = import('rolldown/utils').ParseResult['program']['body'];
2
+ /**
3
+ * rolldown-plugin-dts prints re-exports as `import { X } from …; export { X }`. Module
4
+ * augmentation of the exported alias then doesn't reach the interface other declarations
5
+ * reference, so these become `export { X } from …`.
6
+ * @returns {import('tsdown').Rolldown.Plugin}
7
+ */
8
+ export declare function dtsExportsPlugin(): import('tsdown').Rolldown.Plugin;
@@ -0,0 +1,19 @@
1
+ export type Node = import('./rolldownOutput.mjs').Node;
2
+ export type Namespace = {
3
+ /**
4
+ * The binding the module exports the namespace by.
5
+ */
6
+ local: string;
7
+ /**
8
+ * The declaration or import that creates it.
9
+ */
10
+ node: Node;
11
+ };
12
+ /**
13
+ * For a namespace import, rolldown-plugin-dts declares a `<name>_exports` namespace that leaves out
14
+ * names re-exported from packages. Importers get `import * as` instead, as tsc emits, and the
15
+ * namespace is dropped. Remove this plugin once rolldown-plugin-dts keeps those names:
16
+ * https://github.com/sxzz/rolldown-plugin-dts/issues/300
17
+ * @returns {import('tsdown').Rolldown.Plugin}
18
+ */
19
+ export declare function dtsNamespacesPlugin(): import('tsdown').Rolldown.Plugin;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @param {Object} options
3
+ * @param {import('../cli/packageJson').PackageJson} options.packageJson - The source package.json content.
4
+ * @param {import('./build.mjs').BundleType[]} options.bundles
5
+ * @param {string} options.outputDir
6
+ * @param {string} options.cwd
7
+ * @param {boolean} options.addTypes - Whether to add type declarations for the package.
8
+ * @param {boolean} [options.expand] - Whether to enumerate glob patterns into concrete entries.
9
+ * @param {'module' | 'commonjs'} options.packageType - The package.json type field.
10
+ * @returns {Promise<import('../cli/packageJson').PackageJson>} The package.json to publish from `outputDir`.
11
+ */
12
+ export declare function getPublishedPkgJson({ packageJson: source, bundles, outputDir, cwd, addTypes, expand, packageType, }: {
13
+ packageJson: import('../cli/packageJson').PackageJson;
14
+ bundles: import('./build.mjs').BundleType[];
15
+ outputDir: string;
16
+ cwd: string;
17
+ addTypes: boolean;
18
+ expand?: boolean;
19
+ packageType: 'module' | 'commonjs';
20
+ }): Promise<import('../cli/packageJson').PackageJson>;
@@ -0,0 +1,13 @@
1
+ export type Edit = import('./rolldownOutput.mjs').Edit;
2
+ export type Node = import('./rolldownOutput.mjs').Node;
3
+ /**
4
+ * Rolldown turns `export * as X from './parts'` into an `__exportAll()` object holding every
5
+ * export, which bundlers can't tree-shake. Rolldown also reads names an external `export *` provides
6
+ * through that object. ESM chunks import such namespaces with `import * as` instead, and CommonJS
7
+ * chunks read the module's `exports`. Objects nothing references any more are removed with their
8
+ * `<name>_exports` export.
9
+ * Remove this plugin once Rolldown keeps namespace re-exports in unbundled builds:
10
+ * https://github.com/rolldown/rolldown/issues/6669
11
+ * @returns {import('tsdown').Rolldown.Plugin}
12
+ */
13
+ export declare function jsNamespacesPlugin(): import('tsdown').Rolldown.Plugin;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Lints the output directory with publint. Errors fail the build, warnings are only reported.
3
+ * @param {string} buildDir - The build directory to validate.
4
+ * @returns {Promise<void>}
5
+ */
6
+ export declare function validateWithPublint(buildDir: string): Promise<void>;
@@ -0,0 +1,38 @@
1
+ export declare const DTS_FILES: RegExp;
2
+ export declare const GENERATED_NAMESPACE: RegExp;
3
+ export type Edit = {
4
+ start: number;
5
+ end: number;
6
+ text: string;
7
+ };
8
+ export type Node = import('rolldown/utils').ESTree.Node;
9
+ export type Name = import('rolldown/utils').ESTree.ModuleExportName | import('rolldown/utils').ESTree.BindingIdentifier;
10
+ /**
11
+ * @typedef {{ start: number; end: number; text: string }} Edit
12
+ * @typedef {import('rolldown/utils').ESTree.Node} Node
13
+ * @typedef {import('rolldown/utils').ESTree.ModuleExportName | import('rolldown/utils').ESTree.BindingIdentifier} Name
14
+ */
15
+ /**
16
+ * @param {string} code
17
+ * @param {Edit[]} edits
18
+ */
19
+ export declare function applyEdits(code: string, edits: Edit[]): string;
20
+ /**
21
+ * @param {string} code
22
+ * @param {string} name
23
+ */
24
+ export declare function countReferences(code: string, name: string): number;
25
+ /** @param {Name} node */
26
+ export declare function getName(node: Name): string;
27
+ /**
28
+ * The imported and local names of an import specifier, or the local and exported names of an
29
+ * export specifier.
30
+ * @param {Node} specifier
31
+ * @returns {[Name, Name] | []}
32
+ */
33
+ export declare function getBinding(specifier: Node): [Name, Name] | [];
34
+ /**
35
+ * @param {string} code
36
+ * @param {Node} node
37
+ */
38
+ export declare function slice(code: string, node: Node): string;
@@ -33,3 +33,4 @@ export declare function publicPkg(name: string, pkgPath: string): import('./pnpm
33
33
  * @returns {import('./pnpm.mjs').PrivatePackage}
34
34
  */
35
35
  export declare function privatePkg(name: string, pkgPath: string): import('./pnpm.mjs').PrivatePackage;
36
+ export declare function getTsgo(): Promise<any>;
@@ -10,6 +10,11 @@ export declare function findTscPair(cwd: string): Promise<{
10
10
  native: string | null;
11
11
  js: string;
12
12
  }>;
13
+ /**
14
+ * @param {string} cwd
15
+ * @returns {Promise<string>} The `tsconfig.build.json` to emit declarations with.
16
+ */
17
+ export declare function getTsconfig(cwd: string): Promise<string>;
13
18
  /**
14
19
  * Emits TypeScript declaration files.
15
20
  * @param {string} tsconfig - The path to the tsconfig.json file.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-code-infra",
3
- "version": "0.1.1-canary.36",
3
+ "version": "0.1.1-canary.38",
4
4
  "author": "MUI Team",
5
5
  "description": "Infra scripts and configs to be used across MUI repos.",
6
6
  "license": "MIT",
@@ -199,7 +199,7 @@
199
199
  "publishConfig": {
200
200
  "access": "public"
201
201
  },
202
- "gitSha": "29461ce4eeb3bcf91d92816e632191bebb17677d",
202
+ "gitSha": "e44688894ae822e6f958f1b7f0ce29cab20210a8",
203
203
  "scripts": {
204
204
  "build": "tsc -p tsconfig.build.json",
205
205
  "typescript": "tsc -noEmit",
@@ -14,10 +14,21 @@ import pluginTransformInlineEnvVars from './babelPluginInlineEnvironmentVariable
14
14
  // Plain TypeScript, ie. files that can't contain JSX.
15
15
  const TS_WITHOUT_JSX = /\.[cm]?ts$/;
16
16
 
17
+ // Work `code-infra build-new` leaves to Oxc and Rolldown.
18
+ const OXC_HANDLED_PLUGINS = new Set([
19
+ 'babel-plugin-transform-inline-environment-variables',
20
+ 'babel-plugin-transform-import-meta',
21
+ '@mui/internal-babel-plugin-resolve-imports',
22
+ ]);
23
+
17
24
  /**
18
25
  * @typedef {'annotation' | 'syntax' | 'infer' | 'all'} ReactCompilationMode
19
26
  */
20
27
 
28
+ /**
29
+ * @typedef {'babel' | 'oxc'} Compiler
30
+ */
31
+
21
32
  /**
22
33
  * @param {Object} param0
23
34
  * @param {boolean} [param0.debug]
@@ -30,6 +41,7 @@ const TS_WITHOUT_JSX = /\.[cm]?ts$/;
30
41
  * @param {string} [param0.reactCompilerReactVersion]
31
42
  * @param {ReactCompilationMode} [param0.reactCompilerMode]
32
43
  * @param {{ allowedCallees?: Record<string, string[]> }} [param0.displayName] - Options for the display name plugin.
44
+ * @param {Compiler} [param0.compiler] - `oxc` keeps only the plugins Oxc has no equivalent for.
33
45
  * @returns {import('@babel/core').InputOptions} The base Babel configuration.
34
46
  */
35
47
  export function getBaseConfig({
@@ -43,6 +55,7 @@ export function getBaseConfig({
43
55
  reactCompilerReactVersion,
44
56
  reactCompilerMode,
45
57
  displayName,
58
+ compiler = 'babel',
46
59
  }) {
47
60
  /**
48
61
  * @type {import('@babel/preset-env').Options}
@@ -124,7 +137,8 @@ export function getBaseConfig({
124
137
  ]);
125
138
  }
126
139
 
127
- return {
140
+ /** @type {import('@babel/core').InputOptions} */
141
+ const config = {
128
142
  assumptions: {
129
143
  noDocumentAll: true,
130
144
  // With our case these assumptions are safe, and the
@@ -170,6 +184,21 @@ export function getBaseConfig({
170
184
  },
171
185
  ],
172
186
  };
187
+ if (compiler === 'babel') {
188
+ return config;
189
+ }
190
+
191
+ return {
192
+ assumptions: config.assumptions,
193
+ ignore: config.ignore,
194
+ plugins: [
195
+ ...plugins.filter(
196
+ (plugin) => !OXC_HANDLED_PLUGINS.has(/** @type {[unknown, unknown, string]} */ (plugin)[2]),
197
+ ),
198
+ // Oxc only marks JSX as pure, not React calls such as `createContext()`.
199
+ [pluginReactPureAnnotations, {}, '@babel/plugin-transform-react-pure-annotations'],
200
+ ],
201
+ };
173
202
  }
174
203
 
175
204
  /**
@@ -188,12 +217,16 @@ export default function getBabelConfig(api) {
188
217
  let bundle;
189
218
  /** @type {boolean} */
190
219
  let noResolveImports;
220
+ /** @type {Compiler} */
221
+ let compiler = 'babel';
191
222
 
192
223
  if (api.env) {
193
224
  // legacy
194
225
  bundle = api.env(['regressions', 'stable']) ? 'esm' : 'cjs';
195
226
  // eslint-disable-next-line mui/consistent-production-guard
196
227
  noResolveImports = api.env('test') || process.env.NODE_ENV === 'test';
228
+ compiler =
229
+ api.caller((caller) => /** @type {{ compiler?: Compiler }} */ (caller)?.compiler) ?? compiler;
197
230
  } else {
198
231
  bundle = api.bundle || 'esm';
199
232
  noResolveImports = api.noResolveImports || false;
@@ -211,5 +244,6 @@ export default function getBabelConfig(api) {
211
244
  noResolveImports,
212
245
  reactCompilerReactVersion: process.env.MUI_REACT_COMPILER_REACT_VERSION,
213
246
  reactCompilerMode: /** @type {ReactCompilationMode} */ (process.env.MUI_REACT_COMPILER_MODE),
247
+ compiler,
214
248
  });
215
249
  }