@mui/internal-code-infra 0.1.1-canary.4 ā 0.1.1-canary.40
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 +36 -4
- package/build/babel-config.d.mts +7 -1
- package/build/changelog/changelogChanges.d.mts +42 -0
- package/build/changelog/changelogGrouping.d.mts +52 -0
- package/build/changelog/changelogMarkdown.d.mts +69 -0
- package/build/changelog/changelogTags.d.mts +15 -0
- package/build/changelog/changelogTitle.d.mts +28 -0
- package/build/changelog/fetchChangelogData.d.mts +16 -0
- package/build/changelog/fetchChangelogs.d.mts +11 -12
- package/build/changelog/index.d.mts +25 -0
- package/build/changelog/octokit.d.mts +7 -0
- package/build/changelog/types.d.ts +174 -0
- package/build/eslint/baseConfig.d.mts +1 -1
- package/build/eslint/index.d.mts +1 -0
- package/build/eslint/mui/rules/no-constructor-assigned-field.d.mts +50 -0
- package/build/eslint/nodeSupportConfig.d.mts +11 -0
- package/build/eslint/packageJsonConfig.d.mts +7 -0
- package/build/remark/config.d.mts +5 -14
- package/build/utils/babelPlugin.d.mts +8 -0
- package/build/utils/build.d.mts +22 -0
- package/build/utils/cjsSourcesPlugin.d.mts +11 -0
- package/build/utils/credentials.d.mts +2 -2
- package/build/utils/dtsExportsPlugin.d.mts +8 -0
- package/build/utils/dtsNamespacesPlugin.d.mts +19 -0
- package/build/utils/fileUrlEntriesPlugin.d.mts +9 -0
- package/build/utils/getPublishedPkgJson.d.mts +20 -0
- package/build/utils/git.d.mts +30 -9
- package/build/utils/github.d.mts +8 -0
- package/build/utils/jsNamespacesPlugin.d.mts +13 -0
- package/build/utils/pnpm.d.mts +67 -3
- package/build/utils/publint.d.mts +6 -0
- package/build/utils/rolldownOutput.d.mts +38 -0
- package/build/utils/testUtils.d.mts +8 -0
- package/build/utils/typescript.d.mts +17 -0
- package/package.json +61 -49
- package/src/babel-config.mjs +35 -1
- package/src/brokenLinksChecker/index.mjs +8 -1
- package/src/changelog/changelogChanges.mjs +479 -0
- package/src/changelog/changelogGrouping.mjs +148 -0
- package/src/changelog/changelogMarkdown.mjs +110 -0
- package/src/changelog/changelogTags.mjs +34 -0
- package/src/changelog/changelogTitle.mjs +56 -0
- package/src/changelog/fetchChangelogData.mjs +172 -0
- package/src/changelog/fetchChangelogs.mjs +47 -34
- package/src/changelog/index.mjs +34 -0
- package/src/changelog/octokit.mjs +35 -0
- package/src/changelog/types.ts +187 -0
- package/src/cli/cmdBaseline.mjs +31 -0
- package/src/cli/cmdBuild.mjs +20 -89
- package/src/cli/cmdBuildNew.mjs +471 -0
- package/src/cli/cmdNetlifyIgnore.mjs +14 -7
- package/src/cli/cmdPublish.mjs +17 -3
- package/src/cli/cmdPublishNewPackage.mjs +11 -4
- package/src/cli/cmdValidateBuiltTypes.mjs +447 -32
- package/src/cli/index.mjs +4 -0
- package/src/eslint/baseConfig.mjs +10 -2
- package/src/eslint/docsConfig.mjs +28 -10
- package/src/eslint/index.mjs +1 -0
- package/src/eslint/jsonConfig.mjs +2 -1
- package/src/eslint/mui/config.mjs +16 -1
- package/src/eslint/mui/index.mjs +2 -0
- package/src/eslint/mui/rules/disallow-react-api-in-server-components.mjs +4 -1
- package/src/eslint/mui/rules/no-constructor-assigned-field.mjs +183 -0
- package/src/eslint/nodeSupportConfig.mjs +70 -0
- package/src/eslint/packageJsonConfig.mjs +50 -0
- package/src/eslint/testConfig.mjs +4 -2
- package/src/remark/config.mjs +60 -13
- package/src/utils/babelPlugin.mjs +52 -0
- package/src/utils/build.mjs +81 -0
- package/src/utils/cjsSourcesPlugin.mjs +92 -0
- package/src/utils/credentials.mjs +4 -3
- package/src/utils/dtsExportsPlugin.mjs +103 -0
- package/src/utils/dtsNamespacesPlugin.mjs +226 -0
- package/src/utils/extractErrorCodes.mjs +1 -3
- package/src/utils/fileUrlEntriesPlugin.mjs +84 -0
- package/src/utils/getPublishedPkgJson.mjs +86 -0
- package/src/utils/git.mjs +107 -46
- package/src/utils/github.mjs +27 -0
- package/src/utils/jsNamespacesPlugin.mjs +505 -0
- package/src/utils/pnpm.mjs +126 -25
- package/src/utils/publint.mjs +34 -0
- package/src/utils/rolldownOutput.mjs +70 -0
- package/src/utils/testUtils.mjs +26 -0
- package/src/utils/typescript.mjs +23 -13
- package/vale/styles/MUI/GoogleLatin.yml +5 -2
- package/build/cli/cmdArgosPush.d.mts +0 -18
- package/build/cli/cmdBuild.d.mts +0 -64
- package/build/cli/cmdCopyFiles.d.mts +0 -20
- package/build/cli/cmdExtractErrorCodes.d.mts +0 -6
- package/build/cli/cmdGenerateChangelog.d.mts +0 -32
- package/build/cli/cmdGithubAuth.d.mts +0 -11
- package/build/cli/cmdListWorkspaces.d.mts +0 -29
- package/build/cli/cmdNetlifyIgnore.d.mts +0 -17
- package/build/cli/cmdPublish.d.mts +0 -32
- package/build/cli/cmdPublishCanary.d.mts +0 -34
- package/build/cli/cmdPublishNewPackage.d.mts +0 -17
- package/build/cli/cmdRenameScope.d.mts +0 -18
- package/build/cli/cmdSetVersionOverrides.d.mts +0 -9
- package/build/cli/cmdVale.d.mts +0 -46
- package/build/cli/cmdValidateBuiltTypes.d.mts +0 -2
- package/build/cli/index.d.mts +0 -1
- package/vale/styles/MUI/CorrectRererenceCased.yml +0 -14
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import getTargets from '@babel/helper-compilation-targets';
|
|
2
|
+
import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
|
|
3
|
+
import * as fs from 'node:fs/promises';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
import { globby } from 'globby';
|
|
8
|
+
import * as semver from 'semver';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
getOutExtension,
|
|
12
|
+
getPackageSources,
|
|
13
|
+
validateEnginesNode,
|
|
14
|
+
validatePkgJson,
|
|
15
|
+
} from '../utils/build.mjs';
|
|
16
|
+
import { getVersionEnvVariables } from '../utils/babel.mjs';
|
|
17
|
+
import { babelPlugin } from '../utils/babelPlugin.mjs';
|
|
18
|
+
import { cjsSourcesPlugin } from '../utils/cjsSourcesPlugin.mjs';
|
|
19
|
+
import { dtsExportsPlugin } from '../utils/dtsExportsPlugin.mjs';
|
|
20
|
+
import { dtsNamespacesPlugin } from '../utils/dtsNamespacesPlugin.mjs';
|
|
21
|
+
import { jsNamespacesPlugin } from '../utils/jsNamespacesPlugin.mjs';
|
|
22
|
+
import { fileUrlEntriesPlugin } from '../utils/fileUrlEntriesPlugin.mjs';
|
|
23
|
+
import { getPublishedPkgJson } from '../utils/getPublishedPkgJson.mjs';
|
|
24
|
+
import { readPnpmConfig } from '../utils/pnpm.mjs';
|
|
25
|
+
import { validateWithPublint } from '../utils/publint.mjs';
|
|
26
|
+
import { getTsconfig } from '../utils/typescript.mjs';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {Object} Args
|
|
30
|
+
* @property {import('../utils/build.mjs').BundleType[]} bundle
|
|
31
|
+
* @property {string[]} copy
|
|
32
|
+
* @property {boolean} buildTypes
|
|
33
|
+
* @property {boolean} enableReactCompiler
|
|
34
|
+
* @property {boolean} cjsCopy
|
|
35
|
+
* @property {boolean} expand
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
const SOURCE_DIR = 'src';
|
|
39
|
+
// Importers keep `#` specifiers, so consumers resolve the `imports` conditions.
|
|
40
|
+
const PACKAGE_IMPORTS = /^#/;
|
|
41
|
+
const MODULE_LEVEL_DIRECTIVE = 'MODULE_LEVEL_DIRECTIVE';
|
|
42
|
+
|
|
43
|
+
/** @type {Record<import('../utils/build.mjs').BundleType, 'es' | 'cjs'>} */
|
|
44
|
+
const FORMATS = { esm: 'es', cjs: 'cjs' };
|
|
45
|
+
|
|
46
|
+
const BABEL_CONFIG_FILES = ['babel.config.js', 'babel.config.mjs'];
|
|
47
|
+
|
|
48
|
+
const TYPESCRIPT = 'typescript';
|
|
49
|
+
|
|
50
|
+
const BABEL_RUNTIME = '@babel/runtime';
|
|
51
|
+
|
|
52
|
+
const OXC_HELPERS = '@oxc-project/runtime/helpers/';
|
|
53
|
+
// Oxc's legacy decorator helpers have no `@babel/runtime` equivalent, so Rolldown bundles them.
|
|
54
|
+
const OXC_SHARED_HELPERS = /^@oxc-project\/runtime\/helpers\/(?!decorate)/;
|
|
55
|
+
|
|
56
|
+
/** @type {Record<import('../utils/build.mjs').BundleType, string>} */
|
|
57
|
+
const BROWSERSLIST_ENVS = { esm: 'stable', cjs: 'node' };
|
|
58
|
+
|
|
59
|
+
// Oxc exports no compat table and accepts some engines it then ignores (android, ie, hermes,
|
|
60
|
+
// rhino), so this lists the Babel target engines Oxc was verified to lower for.
|
|
61
|
+
const OXC_ENGINES = new Set([
|
|
62
|
+
'chrome',
|
|
63
|
+
'edge',
|
|
64
|
+
'electron',
|
|
65
|
+
'firefox',
|
|
66
|
+
'ios',
|
|
67
|
+
'node',
|
|
68
|
+
'opera',
|
|
69
|
+
'safari',
|
|
70
|
+
'samsung',
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Resolves the bundle's browserslist environment the way `@babel/preset-env` does. Oxc can't lower
|
|
75
|
+
* for every engine Babel knows, so those fail instead of silently shipping less-compiled code.
|
|
76
|
+
* @param {string} cwd
|
|
77
|
+
* @param {import('../utils/build.mjs').BundleType} bundle
|
|
78
|
+
* @returns {string[]} Oxc targets.
|
|
79
|
+
*/
|
|
80
|
+
function getTarget(cwd, bundle) {
|
|
81
|
+
const env = BROWSERSLIST_ENVS[bundle];
|
|
82
|
+
const targets = Object.entries(getTargets({}, { configPath: cwd, browserslistEnv: env }));
|
|
83
|
+
if (targets.length === 0) {
|
|
84
|
+
throw new Error(`No browserslist targets found for the "${env}" environment.`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const unsupported = targets.filter(([engine]) => !OXC_ENGINES.has(engine));
|
|
88
|
+
if (unsupported.length > 0) {
|
|
89
|
+
const engines = unsupported.map(([engine]) => engine).join(', ');
|
|
90
|
+
throw new Error(`Oxc cannot target ${engines} from the "${env}" browserslist environment.`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return targets.map(([engine, version]) => `${engine}${version}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The workspace Babel config, or the base config without one.
|
|
98
|
+
* @param {string} cwd
|
|
99
|
+
* @returns {Promise<string>}
|
|
100
|
+
*/
|
|
101
|
+
async function getBabelConfigFile(cwd) {
|
|
102
|
+
const workspaceDir = await findWorkspaceDir(cwd);
|
|
103
|
+
if (!workspaceDir) {
|
|
104
|
+
throw new Error('Workspace directory not found');
|
|
105
|
+
}
|
|
106
|
+
for (const name of BABEL_CONFIG_FILES) {
|
|
107
|
+
const file = path.join(workspaceDir, name);
|
|
108
|
+
// eslint-disable-next-line no-await-in-loop
|
|
109
|
+
if (await exists(file)) {
|
|
110
|
+
return file;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return path.join(import.meta.dirname, '../babel-config.mjs');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @param {string} cwd
|
|
118
|
+
* @returns {Promise<string>} The native binary of the workspace's TypeScript 7, which
|
|
119
|
+
* rolldown-plugin-dts runs as `tsgo`.
|
|
120
|
+
*/
|
|
121
|
+
async function getTsc(cwd) {
|
|
122
|
+
const workspaceDir = await findWorkspaceDir(cwd);
|
|
123
|
+
if (!workspaceDir) {
|
|
124
|
+
throw new Error('Workspace directory not found');
|
|
125
|
+
}
|
|
126
|
+
const manifest = path.join(workspaceDir, 'package.json');
|
|
127
|
+
const { dependencies, devDependencies } = JSON.parse(await fs.readFile(manifest, 'utf8'));
|
|
128
|
+
const require = createRequire(manifest);
|
|
129
|
+
const candidates = await Promise.all(
|
|
130
|
+
Object.entries({ ...dependencies, ...devDependencies })
|
|
131
|
+
.filter(([name, spec]) => name === TYPESCRIPT || spec.startsWith(`npm:${TYPESCRIPT}@`))
|
|
132
|
+
.map(async ([name]) => {
|
|
133
|
+
const file = require.resolve(`${name}/package.json`);
|
|
134
|
+
const { version } = JSON.parse(await fs.readFile(file, 'utf8'));
|
|
135
|
+
return { dir: path.dirname(file), version };
|
|
136
|
+
}),
|
|
137
|
+
);
|
|
138
|
+
const native = candidates.find(({ version }) => semver.major(version) >= 7);
|
|
139
|
+
if (!native) {
|
|
140
|
+
throw new Error(
|
|
141
|
+
'Install TypeScript 7 at the workspace root, as "typescript@^7" or under an alias such as "@typescript/native", to build types.',
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
// `node_modules/.bin/tsc` is a shell script on Windows, which rolldown-plugin-dts can't spawn.
|
|
145
|
+
const { default: getExePath } = await import(
|
|
146
|
+
pathToFileURL(path.join(native.dir, 'lib/getExePath.js')).href
|
|
147
|
+
);
|
|
148
|
+
return getExePath();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @param {import('./packageJson').PackageJson} packageJson
|
|
153
|
+
* @returns {Promise<string | undefined>} The `@babel/runtime` range the package depends on.
|
|
154
|
+
*/
|
|
155
|
+
async function getBabelRuntime(packageJson) {
|
|
156
|
+
const version = packageJson.dependencies?.[BABEL_RUNTIME];
|
|
157
|
+
if (version !== 'catalog:') {
|
|
158
|
+
return version;
|
|
159
|
+
}
|
|
160
|
+
const config = await readPnpmConfig();
|
|
161
|
+
return config.catalog[BABEL_RUNTIME];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The environment Babel runs in; workspace configs branch on it.
|
|
166
|
+
* @param {import('./packageJson').PackageJson} packageJson
|
|
167
|
+
* @param {{ bundles: import('../utils/build.mjs').BundleType[]; babelRuntime: string | undefined; reactCompiler: 'on' | 'off' }} options
|
|
168
|
+
* @returns {Record<string, string>}
|
|
169
|
+
*/
|
|
170
|
+
function getBabelEnv(packageJson, { bundles, babelRuntime, reactCompiler }) {
|
|
171
|
+
const dependencies = packageJson.dependencies ?? {};
|
|
172
|
+
/** @type {Record<string, string>} */
|
|
173
|
+
const env = {
|
|
174
|
+
NODE_ENV: 'production',
|
|
175
|
+
// One Babel pass serves every format, so configs see the first bundle's environment.
|
|
176
|
+
BABEL_ENV: BROWSERSLIST_ENVS[bundles[0]],
|
|
177
|
+
};
|
|
178
|
+
if (dependencies['prop-types'] !== undefined) {
|
|
179
|
+
env.MUI_REMOVE_PROP_TYPES = 'true';
|
|
180
|
+
}
|
|
181
|
+
if (dependencies.clsx !== undefined || dependencies.classnames !== undefined) {
|
|
182
|
+
env.MUI_OPTIMIZE_CLSX = 'true';
|
|
183
|
+
}
|
|
184
|
+
if (babelRuntime) {
|
|
185
|
+
env.MUI_BABEL_RUNTIME_VERSION = babelRuntime;
|
|
186
|
+
}
|
|
187
|
+
if (reactCompiler === 'on') {
|
|
188
|
+
env.MUI_REACT_COMPILER = '1';
|
|
189
|
+
env.MUI_REACT_COMPILER_REACT_VERSION =
|
|
190
|
+
semver.minVersion(packageJson.peerDependencies?.react ?? '')?.version ?? 'latest';
|
|
191
|
+
}
|
|
192
|
+
return env;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @param {import('./packageJson').PackageJson} packageJson
|
|
197
|
+
* @returns {string | undefined} The package's license header.
|
|
198
|
+
*/
|
|
199
|
+
function getBanner(packageJson) {
|
|
200
|
+
if (!packageJson.license) {
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
return `/**
|
|
204
|
+
* ${packageJson.name} v${packageJson.version}
|
|
205
|
+
*
|
|
206
|
+
* @license ${packageJson.license}
|
|
207
|
+
* This source code is licensed under the ${packageJson.license} license found in the
|
|
208
|
+
* LICENSE file in the root directory of this source tree.
|
|
209
|
+
*/`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Fails the build when the output imports Babel helpers the package doesn't depend on.
|
|
214
|
+
* @param {string | undefined} babelRuntime
|
|
215
|
+
* @returns {import('tsdown').Rolldown.Plugin}
|
|
216
|
+
*/
|
|
217
|
+
function babelRuntimePlugin(babelRuntime) {
|
|
218
|
+
return {
|
|
219
|
+
name: 'code-infra:babel-runtime',
|
|
220
|
+
generateBundle(_options, bundle) {
|
|
221
|
+
if (babelRuntime) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const chunk = Object.values(bundle).find(
|
|
225
|
+
(output) =>
|
|
226
|
+
output.type === 'chunk' &&
|
|
227
|
+
output.imports.some(
|
|
228
|
+
(id) => id.startsWith(`${BABEL_RUNTIME}/`) || id.startsWith(OXC_HELPERS),
|
|
229
|
+
),
|
|
230
|
+
);
|
|
231
|
+
if (!chunk) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
this.error(
|
|
235
|
+
`${chunk.fileName} imports Babel helpers, so package.json needs a dependency on \`${BABEL_RUNTIME}\`.`,
|
|
236
|
+
);
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Resolves the source modules behind the package's published paths, keyed by output name.
|
|
243
|
+
* @param {import('./packageJson').PackageJson} packageJson
|
|
244
|
+
* @param {string} cwd
|
|
245
|
+
* @returns {Promise<Record<string, string>>}
|
|
246
|
+
*/
|
|
247
|
+
async function getEntry(packageJson, cwd) {
|
|
248
|
+
const sources = await getPackageSources(packageJson, cwd);
|
|
249
|
+
|
|
250
|
+
return Object.fromEntries(
|
|
251
|
+
sources.map((source) => {
|
|
252
|
+
const name = path.relative(SOURCE_DIR, source);
|
|
253
|
+
|
|
254
|
+
return [name.slice(0, -path.extname(name).length), source];
|
|
255
|
+
}),
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const DOCUMENTS = ['README.md', 'LICENSE', 'CHANGELOG.md'];
|
|
260
|
+
|
|
261
|
+
/** @param {string} file */
|
|
262
|
+
function exists(file) {
|
|
263
|
+
return fs.stat(file).then(
|
|
264
|
+
() => true,
|
|
265
|
+
() => false,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Package documents fall back to the workspace root, `source:target` globs expand directories and
|
|
271
|
+
* drop the first source directory, and missing paths are skipped.
|
|
272
|
+
* @param {string} cwd
|
|
273
|
+
* @param {string} outDir
|
|
274
|
+
* @param {string[]} globs
|
|
275
|
+
* @returns {Promise<import('tsdown').UserConfig['copy']>}
|
|
276
|
+
*/
|
|
277
|
+
async function getCopy(cwd, outDir, globs) {
|
|
278
|
+
const workspaceDir = await findWorkspaceDir(cwd);
|
|
279
|
+
if (!workspaceDir) {
|
|
280
|
+
throw new Error('Workspace directory not found');
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const documents = Promise.all(
|
|
284
|
+
DOCUMENTS.map(async (name) => {
|
|
285
|
+
const local = path.join(cwd, name);
|
|
286
|
+
if (await exists(local)) {
|
|
287
|
+
return [{ from: local, to: outDir }];
|
|
288
|
+
}
|
|
289
|
+
const root = path.join(workspaceDir, name);
|
|
290
|
+
return (await exists(root)) ? [{ from: root, to: outDir }] : [];
|
|
291
|
+
}),
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const extras = Promise.all(
|
|
295
|
+
globs.map(async (glob) => {
|
|
296
|
+
const [pattern, target = ''] = glob.split(':');
|
|
297
|
+
const from = await globby(pattern, { cwd });
|
|
298
|
+
if (!from.length) {
|
|
299
|
+
return [];
|
|
300
|
+
}
|
|
301
|
+
return [{ from, to: path.join(outDir, target), flatten: false }];
|
|
302
|
+
}),
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
return (await Promise.all([documents, extras])).flat(2);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
309
|
+
command: 'build-new',
|
|
310
|
+
describe: 'Experimental tsdown build. Compiles JavaScript, copies files and writes package.json.',
|
|
311
|
+
builder: (yargs) =>
|
|
312
|
+
yargs
|
|
313
|
+
.option('bundle', {
|
|
314
|
+
array: true,
|
|
315
|
+
type: 'string',
|
|
316
|
+
choices: /** @type {const} */ (['esm', 'cjs']),
|
|
317
|
+
default: /** @type {import('../utils/build.mjs').BundleType[]} */ (['esm', 'cjs']),
|
|
318
|
+
description: 'Bundles to output.',
|
|
319
|
+
})
|
|
320
|
+
.option('copy', {
|
|
321
|
+
array: true,
|
|
322
|
+
type: 'string',
|
|
323
|
+
default: /** @type {string[]} */ ([]),
|
|
324
|
+
description: 'Files to copy to the output directory, as `glob` or `glob:target`.',
|
|
325
|
+
})
|
|
326
|
+
.option('buildTypes', {
|
|
327
|
+
type: 'boolean',
|
|
328
|
+
default: true,
|
|
329
|
+
description: 'Whether to write declarations with the workspace TypeScript 7 `tsc`.',
|
|
330
|
+
})
|
|
331
|
+
.option('enableReactCompiler', {
|
|
332
|
+
type: 'boolean',
|
|
333
|
+
default: false,
|
|
334
|
+
description: 'Compile components with the React compiler.',
|
|
335
|
+
})
|
|
336
|
+
// Remove once `next` has an `exports` map: https://github.com/vercel/next.js/issues/77200
|
|
337
|
+
.option('cjsCopy', {
|
|
338
|
+
type: 'boolean',
|
|
339
|
+
deprecated: 'Only for `@mui/material-nextjs`.',
|
|
340
|
+
default: false,
|
|
341
|
+
description:
|
|
342
|
+
'Emit imported `.cjs` sources unchanged instead of compiling them, and build the local modules they require.',
|
|
343
|
+
})
|
|
344
|
+
.option('expand', {
|
|
345
|
+
type: 'boolean',
|
|
346
|
+
default: true,
|
|
347
|
+
deprecated:
|
|
348
|
+
'Patterns will always be expanded; this flag will be removed in a future release.',
|
|
349
|
+
description:
|
|
350
|
+
'Enumerate glob patterns in the package.json "exports"/"imports" into concrete entries. Use --no-expand to keep them as Node runtime subpath patterns.',
|
|
351
|
+
}),
|
|
352
|
+
async handler(args) {
|
|
353
|
+
const cwd = process.cwd();
|
|
354
|
+
const packageJson = JSON.parse(await fs.readFile(path.join(cwd, 'package.json'), 'utf8'));
|
|
355
|
+
validatePkgJson(packageJson, { enableReactCompiler: args.enableReactCompiler });
|
|
356
|
+
validateEnginesNode(packageJson, cwd);
|
|
357
|
+
|
|
358
|
+
const outDir = path.join(cwd, packageJson.publishConfig.directory);
|
|
359
|
+
const packageType = packageJson.type === 'module' ? 'module' : 'commonjs';
|
|
360
|
+
const bundles = [...new Set(args.bundle)];
|
|
361
|
+
|
|
362
|
+
const [entry, copy, babelRuntime, babelConfigFile, tsconfig, tsc, { build }] =
|
|
363
|
+
await Promise.all([
|
|
364
|
+
getEntry(packageJson, cwd),
|
|
365
|
+
getCopy(cwd, outDir, args.copy),
|
|
366
|
+
getBabelRuntime(packageJson),
|
|
367
|
+
getBabelConfigFile(cwd),
|
|
368
|
+
args.buildTypes ? getTsconfig(cwd) : undefined,
|
|
369
|
+
args.buildTypes ? getTsc(cwd) : undefined,
|
|
370
|
+
import('tsdown'),
|
|
371
|
+
]);
|
|
372
|
+
|
|
373
|
+
const { MUI_PRERELEASE: prerelease, ...versionEnv } = getVersionEnvVariables(
|
|
374
|
+
packageJson.version,
|
|
375
|
+
);
|
|
376
|
+
const reactCompiler = args.enableReactCompiler ? 'on' : 'off';
|
|
377
|
+
Object.assign(process.env, getBabelEnv(packageJson, { bundles, babelRuntime, reactCompiler }));
|
|
378
|
+
await build({
|
|
379
|
+
cwd,
|
|
380
|
+
config: false,
|
|
381
|
+
entry,
|
|
382
|
+
unbundle: true,
|
|
383
|
+
platform: 'neutral',
|
|
384
|
+
root: SOURCE_DIR,
|
|
385
|
+
outDir,
|
|
386
|
+
clean: true,
|
|
387
|
+
format: Object.fromEntries(
|
|
388
|
+
bundles.map((bundle) => [FORMATS[bundle], { target: getTarget(cwd, bundle) }]),
|
|
389
|
+
),
|
|
390
|
+
env: versionEnv,
|
|
391
|
+
// `env` values go through JSON, which can't hold the `undefined` of a stable version.
|
|
392
|
+
define: {
|
|
393
|
+
'process.env.MUI_PRERELEASE':
|
|
394
|
+
prerelease === undefined ? 'undefined' : JSON.stringify(prerelease),
|
|
395
|
+
},
|
|
396
|
+
envPrefix: [],
|
|
397
|
+
// `.js` sources may contain JSX.
|
|
398
|
+
loader: { '.js': 'jsx' },
|
|
399
|
+
plugins: [
|
|
400
|
+
args.cjsCopy &&
|
|
401
|
+
cjsSourcesPlugin(
|
|
402
|
+
path.join(cwd, SOURCE_DIR),
|
|
403
|
+
bundles.includes('cjs') ? getOutExtension('cjs', { packageType }) : undefined,
|
|
404
|
+
),
|
|
405
|
+
fileUrlEntriesPlugin(),
|
|
406
|
+
babelPlugin(babelConfigFile),
|
|
407
|
+
// https://github.com/rolldown/rolldown/issues/6669
|
|
408
|
+
jsNamespacesPlugin(),
|
|
409
|
+
babelRuntimePlugin(babelRuntime),
|
|
410
|
+
],
|
|
411
|
+
// tsdown leaves `plugins` out of its CJS declaration pass; `inputOptions` reaches every pass.
|
|
412
|
+
inputOptions: (options) => ({
|
|
413
|
+
...options,
|
|
414
|
+
// tsdown otherwise takes `jsx` from the package's tsconfig, which may preserve JSX.
|
|
415
|
+
transform: { ...options.transform, jsx: { runtime: 'automatic' } },
|
|
416
|
+
plugins: [
|
|
417
|
+
dtsExportsPlugin(),
|
|
418
|
+
// https://github.com/sxzz/rolldown-plugin-dts/issues/300
|
|
419
|
+
dtsNamespacesPlugin(),
|
|
420
|
+
options.plugins,
|
|
421
|
+
],
|
|
422
|
+
external: [PACKAGE_IMPORTS, OXC_SHARED_HELPERS],
|
|
423
|
+
}),
|
|
424
|
+
outExtensions: ({ format }) => ({
|
|
425
|
+
js: getOutExtension(format === 'es' ? 'esm' : 'cjs', { packageType }),
|
|
426
|
+
}),
|
|
427
|
+
deps: { neverBundle: true },
|
|
428
|
+
outputOptions: {
|
|
429
|
+
exports: 'named',
|
|
430
|
+
// Returning the id itself would print relative externals unresolved; `undefined` keeps
|
|
431
|
+
// Rolldown's own path for them.
|
|
432
|
+
paths: /** @type {(id: string) => string} */ (
|
|
433
|
+
(id) =>
|
|
434
|
+
id.startsWith(OXC_HELPERS)
|
|
435
|
+
? `${BABEL_RUNTIME}/helpers/${id.slice(OXC_HELPERS.length)}`
|
|
436
|
+
: undefined
|
|
437
|
+
),
|
|
438
|
+
},
|
|
439
|
+
banner: { js: getBanner(packageJson) },
|
|
440
|
+
tsconfig,
|
|
441
|
+
// Keeps CJS declarations on `export default`, matching the named-exports JS interop.
|
|
442
|
+
cjsDefault: false,
|
|
443
|
+
// TODO: tsdown >=0.23.5 (rolldown-plugin-dts >=0.29) runs TS7 through its API, which needs
|
|
444
|
+
// TypeScript 7.1. Once it's stable, bump and replace `tsgo.path` with `tsgo.moduleUrl`.
|
|
445
|
+
dts: args.buildTypes ? { generator: 'tsgo', tsgo: { path: tsc }, sourcemap: false } : false,
|
|
446
|
+
exports: false,
|
|
447
|
+
report: false,
|
|
448
|
+
copy,
|
|
449
|
+
logLevel: 'warn',
|
|
450
|
+
// Unbundled output keeps each module's directives; the warning is about bundling.
|
|
451
|
+
suppressWarnings: [MODULE_LEVEL_DIRECTIVE],
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const publishedPkgJson = await getPublishedPkgJson({
|
|
455
|
+
packageJson,
|
|
456
|
+
bundles,
|
|
457
|
+
outputDir: outDir,
|
|
458
|
+
cwd,
|
|
459
|
+
addTypes: args.buildTypes,
|
|
460
|
+
expand: args.expand,
|
|
461
|
+
packageType,
|
|
462
|
+
});
|
|
463
|
+
await fs.writeFile(
|
|
464
|
+
path.join(outDir, 'package.json'),
|
|
465
|
+
JSON.stringify(publishedPkgJson, null, 2),
|
|
466
|
+
'utf-8',
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
await validateWithPublint(outDir);
|
|
470
|
+
},
|
|
471
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {Object} Args
|
|
7
|
-
* @property {string[]} workspaces -
|
|
7
|
+
* @property {string[]} workspaces - Workspace names or root-relative paths to process
|
|
8
8
|
* @property {boolean} [check] - Check mode - error if the generated content differs from current
|
|
9
9
|
* @property {string} [baseBranch] - Branch to compare PRs against (default: master)
|
|
10
10
|
*/
|
|
@@ -100,7 +100,7 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
100
100
|
.positional('workspaces', {
|
|
101
101
|
type: 'string',
|
|
102
102
|
array: true,
|
|
103
|
-
describe: '
|
|
103
|
+
describe: 'Workspace names or root-relative paths to process',
|
|
104
104
|
demandOption: true,
|
|
105
105
|
})
|
|
106
106
|
.option('check', {
|
|
@@ -115,6 +115,7 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
115
115
|
"Branch to compare PRs against (the site's production branch on Netlify). Production and branch deploys always rebuild regardless of this value.",
|
|
116
116
|
})
|
|
117
117
|
.example('$0 netlify-ignore @mui/internal-docs-infra', 'Update netlify.toml for a workspace')
|
|
118
|
+
.example('$0 netlify-ignore ./apps/dashboard', 'Update an unnamed workspace by path')
|
|
118
119
|
.example(
|
|
119
120
|
'$0 netlify-ignore @mui/internal-docs-infra @mui/internal-code-infra',
|
|
120
121
|
'Update netlify.toml for multiple workspaces',
|
|
@@ -135,11 +136,17 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
135
136
|
|
|
136
137
|
// Get all workspace packages and create workspace map
|
|
137
138
|
const allWorkspaces = await getWorkspacePackages({ cwd: workspaceRoot });
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
)
|
|
142
|
-
|
|
139
|
+
/** @type {Map<string, string>} */
|
|
140
|
+
const workspaceMap = new Map();
|
|
141
|
+
for (const workspace of allWorkspaces) {
|
|
142
|
+
if (workspace.name) {
|
|
143
|
+
workspaceMap.set(workspace.name, workspace.path);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Paths also identify private workspaces that have no package name.
|
|
147
|
+
const relativePath = toPosixPath(path.relative(workspaceRoot, workspace.path));
|
|
148
|
+
workspaceMap.set(`./${relativePath}`, workspace.path);
|
|
149
|
+
}
|
|
143
150
|
|
|
144
151
|
// Process each workspace concurrently
|
|
145
152
|
await Promise.all(
|
package/src/cli/cmdPublish.mjs
CHANGED
|
@@ -19,7 +19,9 @@ import * as semver from 'semver';
|
|
|
19
19
|
|
|
20
20
|
import { persistentAuthStrategy } from '../utils/github.mjs';
|
|
21
21
|
import {
|
|
22
|
+
getDistTagConflicts,
|
|
22
23
|
getPackagesNeedingManualPublish,
|
|
24
|
+
getRegistryPackages,
|
|
23
25
|
getReleaseVersion,
|
|
24
26
|
getWorkspacePackages,
|
|
25
27
|
publishPackages,
|
|
@@ -364,7 +366,8 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
364
366
|
githubReleaseData = await validateGitHubRelease(version);
|
|
365
367
|
}
|
|
366
368
|
|
|
367
|
-
const
|
|
369
|
+
const registryPackages = await getRegistryPackages(filteredPackages);
|
|
370
|
+
const newPackages = getPackagesNeedingManualPublish(filteredPackages, registryPackages);
|
|
368
371
|
|
|
369
372
|
if (newPackages.length > 0) {
|
|
370
373
|
const newPackageNames = newPackages.map((pkg) => pkg.name).join(', ');
|
|
@@ -373,6 +376,15 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
373
376
|
);
|
|
374
377
|
}
|
|
375
378
|
|
|
379
|
+
const distTagConflicts = getDistTagConflicts(filteredPackages, tag, registryPackages);
|
|
380
|
+
if (distTagConflicts.length > 0) {
|
|
381
|
+
throw new Error(
|
|
382
|
+
`Publishing with the "${tag}" dist-tag would move it to the wrong release line:
|
|
383
|
+
${distTagConflicts.map(({ pkg, reason }) => ` * ${pkg.name}: ${reason}`).join('\n')}
|
|
384
|
+
Publish a previous major with its "latest-vX" dist-tag and a prerelease of the next major with "next". On a release branch, also make that dist-tag the "dist-tag" default of the publish workflow. If the dist-tag on npm is outdated, fix it with "npm dist-tag" first.`,
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
376
388
|
// Publish to npm (pnpm handles duplicate checking automatically)
|
|
377
389
|
// No git checks, we'll do our own
|
|
378
390
|
console.log('\nš¦ Publishing packages to npm...');
|
|
@@ -426,8 +438,10 @@ const PUBLISH_WORKFLOW_ID = `.github/${WORKFLOW_PATH}`;
|
|
|
426
438
|
*/
|
|
427
439
|
async function triggerLocalGithubPublishWorkflow(opts) {
|
|
428
440
|
console.log(`š Checking if there are new packages to publish in the workspace...`);
|
|
429
|
-
const
|
|
430
|
-
|
|
441
|
+
const packages = await getWorkspacePackages({ publicOnly: true });
|
|
442
|
+
const newPackages = getPackagesNeedingManualPublish(
|
|
443
|
+
packages,
|
|
444
|
+
await getRegistryPackages(packages, { npmOnly: true }),
|
|
431
445
|
);
|
|
432
446
|
if (newPackages.length) {
|
|
433
447
|
console.warn(
|
|
@@ -11,7 +11,12 @@ import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
|
|
|
11
11
|
|
|
12
12
|
import { getRepositoryInfo } from '../utils/git.mjs';
|
|
13
13
|
import { toPosixPath } from '../utils/path.mjs';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
getPackagesNeedingManualPublish,
|
|
16
|
+
getRegistryPackages,
|
|
17
|
+
getWorkspacePackages,
|
|
18
|
+
PLACEHOLDER_VERSION,
|
|
19
|
+
} from '../utils/pnpm.mjs';
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
22
|
* @typedef {Object} Args
|
|
@@ -46,8 +51,10 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
46
51
|
}),
|
|
47
52
|
async handler(args) {
|
|
48
53
|
console.log(`š Detecting new packages to publish in workspace...`);
|
|
49
|
-
const
|
|
50
|
-
|
|
54
|
+
const packages = await getWorkspacePackages({ publicOnly: true });
|
|
55
|
+
const newPackages = getPackagesNeedingManualPublish(
|
|
56
|
+
packages,
|
|
57
|
+
await getRegistryPackages(packages, { npmOnly: true }),
|
|
51
58
|
);
|
|
52
59
|
|
|
53
60
|
if (!newPackages.length) {
|
|
@@ -78,7 +85,7 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
|
|
|
78
85
|
const repo = await getRepositoryInfo();
|
|
79
86
|
const packageJson = {
|
|
80
87
|
name: pkg.name,
|
|
81
|
-
version:
|
|
88
|
+
version: PLACEHOLDER_VERSION,
|
|
82
89
|
repository: {
|
|
83
90
|
type: 'git',
|
|
84
91
|
url: `git+https://github.com/${repo.owner}/${repo.repo}.git`,
|