MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / applyWorkspaceVersions

Function applyWorkspaceVersions

scripts/publish-packages.ts:112–212  ·  view source on GitHub ↗
(
  pkgDir: string,
  publishable: ReadonlySet<string>,
  publishableVersions: ReadonlyMap<string, string>,
)

Source from the content-addressed store, hash-verified

110 * install-time warnings for unresolvable packages.
111 */
112const applyWorkspaceVersions = async (
113 pkgDir: string,
114 publishable: ReadonlySet<string>,
115 publishableVersions: ReadonlyMap<string, string>,
116): Promise<() => Promise<void>> => {
117 const isInternalScope = (key: string): boolean => key.startsWith(`${PACKAGE_SCOPE}/`);
118
119 const renameDepBlock = (block: DependencyBlock | undefined): DependencyBlock | undefined => {
120 if (!block) return block;
121 const next: DependencyBlock = {};
122 let mutated = false;
123 for (const [key, value] of Object.entries(block)) {
124 if (publishable.has(key) && value.startsWith("workspace:")) {
125 next[key] = publishableVersions.get(key) ?? value;
126 mutated = true;
127 } else if (isInternalScope(key) && !publishable.has(key)) {
128 // Workspace-only `@executor-js/*` regular dep that we don't
129 // publish (e.g. `@executor-js/api`). Strip it: it's not in the
130 // shipped runtime entries (those imports live in
131 // `src/api/*` / `src/react/*` which don't make it into the
132 // packed dist), and leaving it in would 404 at install time.
133 mutated = true;
134 } else {
135 next[key] = value;
136 }
137 }
138 return mutated ? next : block;
139 };
140
141 /**
142 * Peer-deps variant of `renameDepBlock`: resolve workspace specifiers for
143 * publishable peers, but DROP non-publishable `@executor-js/*` peers.
144 * They reference workspace-only packages (`@executor-js/api`,
145 * `@executor-js/react`) that don't exist on npm, so leaving them in
146 * the packed manifest emits install-time warnings for unresolvable
147 * packages. Non-`@executor-js` peers (`react`, `@tanstack/*`,
148 * `@effect-atom/*`, etc.) are real npm packages and pass through
149 * unchanged.
150 */
151 const renamePeerDepBlock = (block: DependencyBlock | undefined): DependencyBlock | undefined => {
152 if (!block) return block;
153 const next: DependencyBlock = {};
154 let mutated = false;
155 for (const [key, value] of Object.entries(block)) {
156 if (publishable.has(key)) {
157 next[key] = value.startsWith("workspace:")
158 ? (publishableVersions.get(key) ?? value)
159 : value;
160 if (next[key] !== value) mutated = true;
161 } else if (isInternalScope(key)) {
162 // Workspace-only `@executor-js/*` peer that we don't publish —
163 // strip it so the packed tarball doesn't reference an
164 // npm package that doesn't exist.
165 mutated = true;
166 } else {
167 next[key] = value;
168 }
169 }

Callers 2

publishPackageFunction · 0.85
prepareOnePackageFunction · 0.85

Calls 3

renameDepBlockFunction · 0.85
renamePeerDepBlockFunction · 0.85
renamePeerMetaBlockFunction · 0.85

Tested by

no test coverage detected