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

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/README.md CHANGED
@@ -77,3 +77,13 @@ After following these steps, the `Publish` workflow can be invoked again.
77
77
  ## Agent skills
78
78
 
79
79
  The agent skills previously shipped with this package now live at the repository root. See [Install instructions](../../README.md#agent-skills).
80
+
81
+ ## Upcoming tsdown builds
82
+
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
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.
@@ -1,5 +1,5 @@
1
1
  export type OctokitType = import('@octokit/rest').Octokit;
2
- export type FetchedCommitDetails = import('./types').FetchedCommitDetails;
2
+ export type FetchedCommitDetails = import('./types.js').FetchedCommitDetails;
3
3
  export type FetchCommitsOptions = {
4
4
  repo: string;
5
5
  lastRelease: string;
@@ -21,7 +21,7 @@ export type FetchCommitsOptions = {
21
21
  * @typedef {import('@octokit/rest').Octokit} OctokitType
22
22
  */
23
23
  /**
24
- * @typedef {import('./types').FetchedCommitDetails} FetchedCommitDetails
24
+ * @typedef {import('./types.js').FetchedCommitDetails} FetchedCommitDetails
25
25
  */
26
26
  /**
27
27
  * @typedef {Object} FetchCommitsOptions
@@ -82,6 +82,14 @@ export declare function createPackageBin(bin: import('../cli/packageJson').Packa
82
82
  cwd: string;
83
83
  packageType?: 'module' | 'commonjs';
84
84
  }): Promise<string | Record<string, string> | undefined>;
85
+ /**
86
+ * The JS/TS sources the package's `exports`, `imports` and `bin` point at, relative to `cwd`.
87
+ * Glob patterns are expanded against the files on disk, as in the published `package.json`.
88
+ * @param {import('../cli/packageJson').PackageJson} packageJson
89
+ * @param {string} cwd
90
+ * @returns {Promise<string[]>}
91
+ */
92
+ export declare function getPackageSources({ exports, imports, bin }: import('../cli/packageJson').PackageJson, cwd: string): Promise<string[]>;
85
93
  /**
86
94
  * Validates the package.json before building.
87
95
  * @param {Record<string, any>} packageJson
@@ -0,0 +1,9 @@
1
+ export type NewExpression = import('rolldown/utils').ESTree.NewExpression;
2
+ /**
3
+ * Builds the modules sources load with `new URL('./file', import.meta.url)`, such as workers. No
4
+ * import or `exports` entry reaches them, so they would be missing from the output. Each becomes
5
+ * an entry, compiled like any other source, and the URL is rewritten to its output path and
6
+ * extension (`new URL('./worker.ts', …)` → `new URL('./worker.mjs', …)`).
7
+ * @returns {import('tsdown').Rolldown.Plugin}
8
+ */
9
+ export declare function fileUrlEntriesPlugin(): import('tsdown').Rolldown.Plugin;
@@ -5,6 +5,13 @@
5
5
  * @returns {Promise<string>} The path of the created temporary directory.
6
6
  */
7
7
  export declare function makeTempDir(): Promise<string>;
8
+ /**
9
+ * Creates a temporary directory (see {@link makeTempDir}) containing `files`.
10
+ *
11
+ * @param {Record<string, string>} files - File contents keyed by path relative to the directory.
12
+ * @returns {Promise<string>} The path of the created temporary directory.
13
+ */
14
+ export declare function makeTempFiles(files: Record<string, string>): Promise<string>;
8
15
  /**
9
16
  * Write a package.json into a subdirectory of a temp workspace.
10
17
  *
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Resolves the native/JS TypeScript CLI pair from the workspace root's
3
+ * `node_modules/.bin`: tsgo/tsc when the legacy `tsgo` shim exists, tsc/tsc6
4
+ * otherwise, with bare `tsc` from PATH as the JS fallback.
5
+ *
6
+ * @param {string} cwd
7
+ * @returns {Promise<{ native: string | null, js: string }>}
8
+ */
9
+ export declare function findTscPair(cwd: string): Promise<{
10
+ native: string | null;
11
+ js: string;
12
+ }>;
1
13
  /**
2
14
  * Emits TypeScript declaration files.
3
15
  * @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.34",
3
+ "version": "0.1.1-canary.36",
4
4
  "author": "MUI Team",
5
5
  "description": "Infra scripts and configs to be used across MUI repos.",
6
6
  "license": "MIT",
@@ -78,9 +78,13 @@
78
78
  "@octokit/plugin-retry": "^8.1.1",
79
79
  "@octokit/plugin-throttling": "^11.0.5",
80
80
  "@octokit/rest": "^22.0.1",
81
+ "@octokit/types": "^18.0.0",
81
82
  "@pnpm/config.version-policy": "^1100.2.10",
82
83
  "@pnpm/find-workspace-dir": "^1000.1.5",
83
84
  "@pnpm/parse-wanted-dependency": "^1001.0.0",
85
+ "@types/babel__core": "^7.20.5",
86
+ "@types/estree": "^1.0.10",
87
+ "@types/mdast": "^4.0.4",
84
88
  "@typescript-eslint/types": "^8.72.2",
85
89
  "@typescript-eslint/utils": "^8.72.2",
86
90
  "@vitest/eslint-plugin": "^1.6.28",
@@ -137,8 +141,10 @@
137
141
  "remark-parse": "^11.0.0",
138
142
  "remark-rehype": "^11.1.2",
139
143
  "resolve-pkg-maps": "^1.0.0",
144
+ "rolldown": "1.2.16",
140
145
  "semver": "^7.8.6",
141
146
  "stylelint-config-standard": "^41.0.0",
147
+ "tsdown": "0.23.4",
142
148
  "typescript-eslint": "^8.72.2",
143
149
  "unified": "^11.0.5",
144
150
  "unified-lint-rule": "^3.0.1",
@@ -162,14 +168,10 @@
162
168
  }
163
169
  },
164
170
  "devDependencies": {
165
- "@octokit/types": "18.0.0",
166
- "@types/babel__core": "7.20.5",
167
171
  "@types/babel__preset-env": "7.10.0",
168
172
  "@types/env-ci": "3.1.4",
169
173
  "@types/eslint-plugin-jsx-a11y": "6.10.1",
170
- "@types/estree": "1.0.10",
171
174
  "@types/estree-jsx": "1.0.5",
172
- "@types/mdast": "4.0.4",
173
175
  "@types/regexp.escape": "2.0.0",
174
176
  "@types/yargs": "17.0.35",
175
177
  "@typescript-eslint/parser": "8.72.2",
@@ -197,7 +199,7 @@
197
199
  "publishConfig": {
198
200
  "access": "public"
199
201
  },
200
- "gitSha": "2246a9a019ec4fd884ec987403c2db99e9a6d1e9",
202
+ "gitSha": "29461ce4eeb3bcf91d92816e632191bebb17677d",
201
203
  "scripts": {
202
204
  "build": "tsc -p tsconfig.build.json",
203
205
  "typescript": "tsc -noEmit",
@@ -25,7 +25,7 @@ function shouldRetryRateLimit(retryAfter, options, octokit, retryCount) {
25
25
  */
26
26
 
27
27
  /**
28
- * @typedef {import('./types').FetchedCommitDetails} FetchedCommitDetails
28
+ * @typedef {import('./types.js').FetchedCommitDetails} FetchedCommitDetails
29
29
  */
30
30
 
31
31
  /**
@@ -180,7 +180,7 @@ async function fetchCommitsRest({ octokit, repo, lastRelease, release, org = 'mu
180
180
  /**
181
181
  *
182
182
  * @param {import('@octokit/rest').RestEndpointMethodTypes["pulls"]["get"]["response"]["data"]["author_association"]} input
183
- * @returns {Exclude<import('./types').FetchedCommitDetails["author"], null>["association"]}
183
+ * @returns {Exclude<import('./types.js').FetchedCommitDetails["author"], null>["association"]}
184
184
  */
185
185
  function getAuthorAssociation(input) {
186
186
  switch (input) {
@@ -0,0 +1,88 @@
1
+ import * as fs from 'node:fs/promises';
2
+ import * as path from 'node:path';
3
+
4
+ import { getOutExtension, getPackageSources, validatePkgJson } from '../utils/build.mjs';
5
+ import { fileUrlEntriesPlugin } from '../utils/fileUrlEntriesPlugin.mjs';
6
+
7
+ /**
8
+ * @typedef {Object} Args
9
+ * @property {import('../utils/build.mjs').BundleType[]} bundle
10
+ */
11
+
12
+ const SOURCE_DIR = 'src';
13
+ // Importers keep `#` specifiers, so consumers resolve the `imports` conditions.
14
+ const PACKAGE_IMPORTS = /^#/;
15
+ const MODULE_LEVEL_DIRECTIVE = 'MODULE_LEVEL_DIRECTIVE';
16
+
17
+ /** @type {Record<import('../utils/build.mjs').BundleType, 'es' | 'cjs'>} */
18
+ const FORMATS = { esm: 'es', cjs: 'cjs' };
19
+
20
+ /**
21
+ * Resolves the source modules behind the package's published paths, keyed by output name.
22
+ * @param {import('./packageJson').PackageJson} packageJson
23
+ * @param {string} cwd
24
+ * @returns {Promise<Record<string, string>>}
25
+ */
26
+ async function getEntry(packageJson, cwd) {
27
+ const sources = await getPackageSources(packageJson, cwd);
28
+
29
+ return Object.fromEntries(
30
+ sources.map((source) => {
31
+ const name = path.relative(SOURCE_DIR, source);
32
+
33
+ return [name.slice(0, -path.extname(name).length), source];
34
+ }),
35
+ );
36
+ }
37
+
38
+ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
39
+ command: 'build-new',
40
+ describe: 'Experimental tsdown build. Compiles JavaScript only.',
41
+ builder: (yargs) =>
42
+ yargs.option('bundle', {
43
+ array: true,
44
+ type: 'string',
45
+ choices: /** @type {const} */ (['esm', 'cjs']),
46
+ default: /** @type {import('../utils/build.mjs').BundleType[]} */ (['esm', 'cjs']),
47
+ description: 'Bundles to output.',
48
+ }),
49
+ async handler(args) {
50
+ const cwd = process.cwd();
51
+ const packageJson = JSON.parse(await fs.readFile(path.join(cwd, 'package.json'), 'utf8'));
52
+ validatePkgJson(packageJson);
53
+
54
+ const outDir = path.join(cwd, packageJson.publishConfig.directory);
55
+ const packageType = packageJson.type === 'module' ? 'module' : 'commonjs';
56
+ const entry = await getEntry(packageJson, cwd);
57
+
58
+ const { build } = await import('tsdown');
59
+ await build({
60
+ cwd,
61
+ config: false,
62
+ entry,
63
+ unbundle: true,
64
+ platform: 'neutral',
65
+ root: SOURCE_DIR,
66
+ outDir,
67
+ clean: true,
68
+ format: [...new Set(args.bundle)].map((bundle) => FORMATS[bundle]),
69
+ outExtensions: ({ format }) => ({
70
+ js: getOutExtension(format === 'es' ? 'esm' : 'cjs', { packageType }),
71
+ }),
72
+ deps: { neverBundle: true },
73
+ plugins: [fileUrlEntriesPlugin()],
74
+ inputOptions: {
75
+ external: [PACKAGE_IMPORTS],
76
+ // tsdown otherwise takes `jsx` from the package's tsconfig, which may preserve JSX.
77
+ transform: { jsx: { runtime: 'automatic' } },
78
+ },
79
+ outputOptions: { exports: 'named' },
80
+ dts: false,
81
+ exports: false,
82
+ report: false,
83
+ logLevel: 'warn',
84
+ // Unbundled output keeps each module's directives; the warning is about bundling.
85
+ suppressWarnings: [MODULE_LEVEL_DIRECTIVE],
86
+ });
87
+ },
88
+ });