@mui/internal-code-infra 0.0.4-canary.13 → 0.0.4-canary.15

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.
@@ -190,10 +190,12 @@ export async function publishPackages(packages, options = {}) {
190
190
  /**
191
191
  * Get all transitive workspace dependencies for a set of packages.
192
192
  *
193
- * Traverses `dependencies`, `peerDependencies`, and optionally `devDependencies`,
194
- * following only packages that exist in `workspacePathByName`. Results are cached
195
- * per package so each package is read from disk at most once regardless of how many
196
- * roots depend on it.
193
+ * Only follows deps whose version spec starts with `workspace:` (e.g. `workspace:*`
194
+ * or `workspace:^`), meaning they are sourced directly from the monorepo. Pinned
195
+ * external versions (e.g. `^1.0.0`) are ignored even when the package name exists
196
+ * in the workspace. Traverses `dependencies` and optionally `devDependencies`.
197
+ * Results are cached per package so each package is read from disk at most once
198
+ * regardless of how many roots depend on it.
197
199
  *
198
200
  * @param {string[]} packageNames - Package names to start the traversal from
199
201
  * @param {GetTransitiveDependenciesOptions} [options]
@@ -222,12 +224,18 @@ export async function getTransitiveDependencies(packageNames, options = {}) {
222
224
  }
223
225
 
224
226
  const pkgJson = await readPackageJson(packagePath);
225
- const allDeps = new Set([
226
- ...Object.keys(pkgJson.dependencies ?? {}),
227
- ...(includeDev ? Object.keys(pkgJson.devDependencies ?? {}) : []),
228
- ...Object.keys(pkgJson.peerDependencies ?? {}),
229
- ]);
230
- const workspaceDeps = [...allDeps].filter((dep) => workspacePathByName.has(dep));
227
+ const allDepEntries = [
228
+ ...Object.entries(pkgJson.dependencies ?? {}),
229
+ ...(includeDev ? Object.entries(pkgJson.devDependencies ?? {}) : []),
230
+ ];
231
+ const workspaceDeps = allDepEntries
232
+ .filter(
233
+ ([dep, spec]) =>
234
+ workspacePathByName.has(dep) &&
235
+ typeof spec === 'string' &&
236
+ spec.startsWith('workspace:'),
237
+ )
238
+ .map(([dep]) => dep);
231
239
 
232
240
  const recursiveResults = await Promise.all(workspaceDeps.map(collectDeps));
233
241
  return new Set([...workspaceDeps, ...recursiveResults.flatMap((s) => [...s])]);
@@ -248,25 +256,30 @@ export async function getTransitiveDependencies(packageNames, options = {}) {
248
256
  }
249
257
 
250
258
  /**
251
- * Validate that a set of packages covers all of their transitive workspace dependencies,
252
- * and that none of those dependencies are private (which would make them unpublishable).
259
+ * Pure validation logic: given a publish set and workspace maps, checks that all
260
+ * transitive hard workspace dependencies are covered and none are private.
261
+ *
262
+ * A hard dependency is one listed in `dependencies` (not `peerDependencies` or
263
+ * `devDependencies`) using a `workspace:` version specifier (e.g. `workspace:*` or
264
+ * `workspace:^`). Peer dependencies are never bundled and dev dependencies are not installed
265
+ * on consumer devices - both are excluded regardless of version specifier. Pinned-version
266
+ * references in `dependencies` are also excluded - they resolve from the registry and do
267
+ * not need to be co-published.
253
268
  *
254
269
  * @param {PublicPackage[]} packages - The packages intended for publishing
270
+ * @param {Map<string, PublicPackage | PrivatePackage>} workspacePackageByName - All workspace packages by name
271
+ * @param {Map<string, string>} workspacePathByName - Map of workspace package name to directory path
255
272
  * @returns {Promise<{issues: string[]}>}
256
273
  * List of human-readable issue strings. Empty when the dependency set is valid.
274
+ * @internal
257
275
  */
258
- export async function validatePublishDependencies(packages) {
259
- const allWorkspacePackages = await getWorkspacePackages();
260
-
261
- /** @type {Map<string, PublicPackage | PrivatePackage>} */
262
- const workspacePackageByName = new Map(
263
- allWorkspacePackages.flatMap((pkg) => (pkg.name ? [[pkg.name, pkg]] : [])),
264
- );
265
- const workspacePathByName = new Map(
266
- allWorkspacePackages.flatMap((pkg) => (pkg.name ? [[pkg.name, pkg.path]] : [])),
267
- );
268
-
276
+ export async function checkPublishDependencies(
277
+ packages,
278
+ workspacePackageByName,
279
+ workspacePathByName,
280
+ ) {
269
281
  const publishedNames = new Set(packages.map((pkg) => pkg.name));
282
+
270
283
  const transitiveDeps = await getTransitiveDependencies(
271
284
  packages.map((pkg) => pkg.name),
272
285
  { includeDev: false, workspacePathByName },
@@ -307,6 +320,27 @@ export async function validatePublishDependencies(packages) {
307
320
  return { issues };
308
321
  }
309
322
 
323
+ /**
324
+ * Validate that a set of packages covers all of their transitive hard workspace dependencies,
325
+ * and that none of those dependencies are private (which would make them unpublishable).
326
+ *
327
+ * @param {PublicPackage[]} packages - The packages intended for publishing
328
+ * @returns {Promise<{issues: string[]}>}
329
+ * List of human-readable issue strings. Empty when the dependency set is valid.
330
+ */
331
+ export async function validatePublishDependencies(packages) {
332
+ const allWorkspacePackages = await getWorkspacePackages();
333
+
334
+ const workspacePackageByName = /** @type {Map<string, PublicPackage | PrivatePackage>} */ (
335
+ new Map(allWorkspacePackages.flatMap((pkg) => (pkg.name ? [[pkg.name, pkg]] : [])))
336
+ );
337
+ const workspacePathByName = new Map(
338
+ allWorkspacePackages.flatMap((pkg) => (pkg.name ? [[pkg.name, pkg.path]] : [])),
339
+ );
340
+
341
+ return checkPublishDependencies(packages, workspacePackageByName, workspacePathByName);
342
+ }
343
+
310
344
  /**
311
345
  * Read package.json from a directory
312
346
  * @param {string} packagePath - Path to package directory