@mui/internal-code-infra 0.0.4-canary.2 → 0.0.4-canary.20
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 +19 -8
- package/build/babel-config.d.mts +11 -3
- package/build/cli/cmdListWorkspaces.d.mts +2 -0
- package/build/cli/cmdPublish.d.mts +1 -0
- package/build/cli/cmdPublishCanary.d.mts +1 -0
- package/build/cli/cmdPublishNewPackage.d.mts +2 -0
- package/build/utils/pnpm.d.mts +57 -0
- package/build/utils/testUtils.d.mts +7 -0
- package/package.json +35 -31
- package/src/babel-config.mjs +9 -3
- package/src/build-env.d.ts +13 -0
- package/src/cli/cmdListWorkspaces.mjs +9 -2
- package/src/cli/cmdNetlifyIgnore.mjs +4 -88
- package/src/cli/cmdPublish.mjs +36 -4
- package/src/cli/cmdPublishCanary.mjs +70 -91
- package/src/cli/cmdPublishNewPackage.mjs +27 -6
- package/src/eslint/baseConfig.mjs +2 -1
- package/src/eslint/docsConfig.mjs +2 -1
- package/src/eslint/jsonConfig.mjs +2 -1
- package/src/eslint/mui/config.mjs +2 -1
- package/src/eslint/testConfig.mjs +2 -1
- package/src/utils/build.test.mjs +546 -575
- package/src/utils/pnpm.mjs +171 -2
- package/src/utils/pnpm.test.mjs +580 -0
- package/src/utils/testUtils.mjs +18 -0
- package/src/utils/typescript.test.mjs +249 -272
package/src/utils/pnpm.mjs
CHANGED
|
@@ -48,6 +48,7 @@ import * as semver from 'semver';
|
|
|
48
48
|
* @property {boolean} [publicOnly=false] - Whether to filter to only public packages
|
|
49
49
|
* @property {boolean} [nonPublishedOnly=false] - Whether to filter to only non-published packages. It by default means public packages yet to be published.
|
|
50
50
|
* @property {string} [cwd] - Current working directory to run pnpm command in
|
|
51
|
+
* @property {string[]} [filter] - Same as filtering packages with --filter in pnpm. Only include packages matching the filter. See https://pnpm.io/filtering.
|
|
51
52
|
*/
|
|
52
53
|
|
|
53
54
|
/**
|
|
@@ -73,10 +74,15 @@ import * as semver from 'semver';
|
|
|
73
74
|
* @returns {Promise<(PrivatePackage | PublicPackage)[]>} Array of packages
|
|
74
75
|
*/
|
|
75
76
|
export async function getWorkspacePackages(options = {}) {
|
|
76
|
-
const { sinceRef = null, publicOnly = false, nonPublishedOnly = false } = options;
|
|
77
|
+
const { sinceRef = null, publicOnly = false, nonPublishedOnly = false, filter = [] } = options;
|
|
77
78
|
|
|
78
79
|
// Build command with conditional filter
|
|
79
80
|
const filterArg = sinceRef ? ['--filter', `...[${sinceRef}]`] : [];
|
|
81
|
+
if (filter.length > 0) {
|
|
82
|
+
filter.forEach((f) => {
|
|
83
|
+
filterArg.push('--filter', f);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
80
86
|
const result = options.cwd
|
|
81
87
|
? await $({ cwd: options.cwd })`pnpm ls -r --json --depth -1 ${filterArg}`
|
|
82
88
|
: await $`pnpm ls -r --json --depth -1 ${filterArg}`;
|
|
@@ -172,7 +178,170 @@ export async function publishPackages(packages, options = {}) {
|
|
|
172
178
|
args.push('--no-git-checks');
|
|
173
179
|
}
|
|
174
180
|
|
|
175
|
-
await $({
|
|
181
|
+
await $({
|
|
182
|
+
stdio: 'inherit',
|
|
183
|
+
env: { npm_config_loglevel: 'warn' },
|
|
184
|
+
})`pnpm -r publish --access public --tag=${tag} ${args}`;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @typedef {Object} GetTransitiveDependenciesOptions
|
|
189
|
+
* @property {Map<string, string>} [workspacePathByName] - Map of workspace package name to directory path
|
|
190
|
+
* @property {boolean} [includeDev=true] - Whether to include devDependencies in the traversal
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Get all transitive workspace dependencies for a set of packages.
|
|
195
|
+
*
|
|
196
|
+
* Only follows deps whose version spec starts with `workspace:` (e.g. `workspace:*`
|
|
197
|
+
* or `workspace:^`), meaning they are sourced directly from the monorepo. Pinned
|
|
198
|
+
* external versions (e.g. `^1.0.0`) are ignored even when the package name exists
|
|
199
|
+
* in the workspace. Traverses `dependencies` and optionally `devDependencies`.
|
|
200
|
+
* Results are cached per package so each package is read from disk at most once
|
|
201
|
+
* regardless of how many roots depend on it.
|
|
202
|
+
*
|
|
203
|
+
* @param {string[]} packageNames - Package names to start the traversal from
|
|
204
|
+
* @param {GetTransitiveDependenciesOptions} [options]
|
|
205
|
+
* @returns {Promise<Set<string>>} All reachable workspace package names, including the input packages themselves
|
|
206
|
+
*/
|
|
207
|
+
export async function getTransitiveDependencies(packageNames, options = {}) {
|
|
208
|
+
const { includeDev = true, workspacePathByName = new Map() } = options;
|
|
209
|
+
|
|
210
|
+
/** @type {Map<string, Promise<Set<string>>>} */
|
|
211
|
+
const cache = new Map();
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @param {string} packageName
|
|
215
|
+
* @returns {Promise<Set<string>>}
|
|
216
|
+
*/
|
|
217
|
+
function collectDeps(packageName) {
|
|
218
|
+
const cached = cache.get(packageName);
|
|
219
|
+
if (cached) {
|
|
220
|
+
return cached;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const promise = (async () => {
|
|
224
|
+
const packagePath = workspacePathByName.get(packageName);
|
|
225
|
+
if (!packagePath) {
|
|
226
|
+
throw new Error(`Workspace "${packageName}" not found`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const pkgJson = await readPackageJson(packagePath);
|
|
230
|
+
const allDepEntries = [
|
|
231
|
+
...Object.entries(pkgJson.dependencies ?? {}),
|
|
232
|
+
...(includeDev ? Object.entries(pkgJson.devDependencies ?? {}) : []),
|
|
233
|
+
];
|
|
234
|
+
const workspaceDeps = allDepEntries
|
|
235
|
+
.filter(
|
|
236
|
+
([dep, spec]) =>
|
|
237
|
+
workspacePathByName.has(dep) &&
|
|
238
|
+
typeof spec === 'string' &&
|
|
239
|
+
spec.startsWith('workspace:'),
|
|
240
|
+
)
|
|
241
|
+
.map(([dep]) => dep);
|
|
242
|
+
|
|
243
|
+
const recursiveResults = await Promise.all(workspaceDeps.map(collectDeps));
|
|
244
|
+
return new Set([...workspaceDeps, ...recursiveResults.flatMap((s) => [...s])]);
|
|
245
|
+
})();
|
|
246
|
+
|
|
247
|
+
cache.set(packageName, promise);
|
|
248
|
+
return promise;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
for (const name of packageNames) {
|
|
252
|
+
if (!workspacePathByName.has(name)) {
|
|
253
|
+
throw new Error(`Workspace "${name}" not found`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const results = await Promise.all(packageNames.map(collectDeps));
|
|
258
|
+
return new Set([...packageNames, ...results.flatMap((s) => [...s])]);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Pure validation logic: given a publish set and workspace maps, checks that all
|
|
263
|
+
* transitive hard workspace dependencies are covered and none are private.
|
|
264
|
+
*
|
|
265
|
+
* A hard dependency is one listed in `dependencies` (not `peerDependencies` or
|
|
266
|
+
* `devDependencies`) using a `workspace:` version specifier (e.g. `workspace:*` or
|
|
267
|
+
* `workspace:^`). Peer dependencies are never bundled and dev dependencies are not installed
|
|
268
|
+
* on consumer devices - both are excluded regardless of version specifier. Pinned-version
|
|
269
|
+
* references in `dependencies` are also excluded - they resolve from the registry and do
|
|
270
|
+
* not need to be co-published.
|
|
271
|
+
*
|
|
272
|
+
* @param {PublicPackage[]} packages - The packages intended for publishing
|
|
273
|
+
* @param {Map<string, PublicPackage | PrivatePackage>} workspacePackageByName - All workspace packages by name
|
|
274
|
+
* @param {Map<string, string>} workspacePathByName - Map of workspace package name to directory path
|
|
275
|
+
* @returns {Promise<{issues: string[]}>}
|
|
276
|
+
* List of human-readable issue strings. Empty when the dependency set is valid.
|
|
277
|
+
* @internal
|
|
278
|
+
*/
|
|
279
|
+
export async function checkPublishDependencies(
|
|
280
|
+
packages,
|
|
281
|
+
workspacePackageByName,
|
|
282
|
+
workspacePathByName,
|
|
283
|
+
) {
|
|
284
|
+
const publishedNames = new Set(packages.map((pkg) => pkg.name));
|
|
285
|
+
|
|
286
|
+
const transitiveDeps = await getTransitiveDependencies(
|
|
287
|
+
packages.map((pkg) => pkg.name),
|
|
288
|
+
{ includeDev: false, workspacePathByName },
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
/** @type {Set<string>} */
|
|
292
|
+
const privateButRequired = new Set();
|
|
293
|
+
/** @type {Set<string>} */
|
|
294
|
+
const missingFromPublish = new Set();
|
|
295
|
+
|
|
296
|
+
for (const depName of transitiveDeps) {
|
|
297
|
+
if (publishedNames.has(depName)) {
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
const workspacePkg = workspacePackageByName.get(depName);
|
|
301
|
+
if (workspacePkg?.isPrivate) {
|
|
302
|
+
privateButRequired.add(depName);
|
|
303
|
+
} else {
|
|
304
|
+
missingFromPublish.add(depName);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** @type {string[]} */
|
|
309
|
+
const issues = [];
|
|
310
|
+
|
|
311
|
+
if (privateButRequired.size > 0) {
|
|
312
|
+
issues.push(
|
|
313
|
+
`The following private workspace packages are required as dependencies but cannot be published: ${[...privateButRequired].join(', ')}`,
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (missingFromPublish.size > 0) {
|
|
318
|
+
issues.push(
|
|
319
|
+
`The following workspace packages are required as dependencies but are not included in the publish set: ${[...missingFromPublish].join(', ')}. Add them to the --filter list.`,
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return { issues };
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Validate that a set of packages covers all of their transitive hard workspace dependencies,
|
|
328
|
+
* and that none of those dependencies are private (which would make them unpublishable).
|
|
329
|
+
*
|
|
330
|
+
* @param {PublicPackage[]} packages - The packages intended for publishing
|
|
331
|
+
* @returns {Promise<{issues: string[]}>}
|
|
332
|
+
* List of human-readable issue strings. Empty when the dependency set is valid.
|
|
333
|
+
*/
|
|
334
|
+
export async function validatePublishDependencies(packages) {
|
|
335
|
+
const allWorkspacePackages = await getWorkspacePackages();
|
|
336
|
+
|
|
337
|
+
const workspacePackageByName = /** @type {Map<string, PublicPackage | PrivatePackage>} */ (
|
|
338
|
+
new Map(allWorkspacePackages.flatMap((pkg) => (pkg.name ? [[pkg.name, pkg]] : [])))
|
|
339
|
+
);
|
|
340
|
+
const workspacePathByName = new Map(
|
|
341
|
+
allWorkspacePackages.flatMap((pkg) => (pkg.name ? [[pkg.name, pkg.path]] : [])),
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
return checkPublishDependencies(packages, workspacePackageByName, workspacePathByName);
|
|
176
345
|
}
|
|
177
346
|
|
|
178
347
|
/**
|