@mui/internal-code-infra 0.1.1-canary.35 → 0.1.1-canary.37

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,32 @@ 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` with
85
+ 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 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,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;
@@ -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,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,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;
@@ -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;
@@ -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
  *
@@ -26,3 +33,4 @@ export declare function publicPkg(name: string, pkgPath: string): import('./pnpm
26
33
  * @returns {import('./pnpm.mjs').PrivatePackage}
27
34
  */
28
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.35",
3
+ "version": "0.1.1-canary.37",
4
4
  "author": "MUI Team",
5
5
  "description": "Infra scripts and configs to be used across MUI repos.",
6
6
  "license": "MIT",
@@ -141,8 +141,10 @@
141
141
  "remark-parse": "^11.0.0",
142
142
  "remark-rehype": "^11.1.2",
143
143
  "resolve-pkg-maps": "^1.0.0",
144
+ "rolldown": "1.2.16",
144
145
  "semver": "^7.8.6",
145
146
  "stylelint-config-standard": "^41.0.0",
147
+ "tsdown": "0.23.4",
146
148
  "typescript-eslint": "^8.72.2",
147
149
  "unified": "^11.0.5",
148
150
  "unified-lint-rule": "^3.0.1",
@@ -197,7 +199,7 @@
197
199
  "publishConfig": {
198
200
  "access": "public"
199
201
  },
200
- "gitSha": "648d5a45da76163e2153dfc37431b1e4df7bb868",
202
+ "gitSha": "71207044a1c3675108c10a64328a4a5434bd16df",
201
203
  "scripts": {
202
204
  "build": "tsc -p tsconfig.build.json",
203
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
  }
@@ -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.