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

Function applyPublishConfig

scripts/publish-packages.ts:222–274  ·  view source on GitHub ↗
(pkgDir: string)

Source from the content-addressed store, hash-verified

220 * `dist/` instead of the dev-time `src/index.ts`.
221 */
222const applyPublishConfig = async (pkgDir: string): Promise<() => Promise<void>> => {
223 const pkgJsonPath = join(pkgDir, "package.json");
224 const original = await readFile(pkgJsonPath, "utf8");
225 const parsed = JSON.parse(original) as {
226 publishConfig?: Record<string, unknown>;
227 [key: string]: unknown;
228 };
229
230 const publishConfig = parsed.publishConfig;
231 if (!publishConfig || typeof publishConfig !== "object") {
232 return async () => {};
233 }
234
235 // Fields we allow publishConfig to override. `access`/`tag`/`registry` are
236 // real npm publish-time config keys — they must NOT be hoisted into the
237 // top-level manifest.
238 const overridable = new Set([
239 "exports",
240 "main",
241 "module",
242 "types",
243 "typings",
244 "bin",
245 "browser",
246 "files",
247 ]);
248
249 const nextPublishConfig: Record<string, unknown> = {};
250 let mutated = false;
251 for (const [key, value] of Object.entries(publishConfig)) {
252 if (overridable.has(key)) {
253 parsed[key] = value;
254 mutated = true;
255 } else {
256 nextPublishConfig[key] = value;
257 }
258 }
259
260 if (!mutated) {
261 return async () => {};
262 }
263
264 if (Object.keys(nextPublishConfig).length === 0) {
265 delete parsed.publishConfig;
266 } else {
267 parsed.publishConfig = nextPublishConfig;
268 }
269
270 await writeFile(pkgJsonPath, `${JSON.stringify(parsed, null, 2)}\n`);
271 return async () => {
272 await writeFile(pkgJsonPath, original);
273 };
274};
275
276const publishPackage = async (
277 pkgDir: string,

Callers 2

publishPackageFunction · 0.85
prepareOnePackageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected