mirror of
https://github.com/gorules/zen.git
synced 2026-11-28 16:06:26 +00:00
* build(nodejs): declare the wasm32-wasip1 package as an optional dependency cli 3.10 drops WASI packages from the root optionalDependencies when native targets exist, which would leave browser.js importing an uninstalled package. Ignore and clear the root facades pre-publish now generates. * build(nodejs): keep the root package free of the threadless wasm facade napi prepublish copies the 15.6MB wasm into the root package and rewrites files and exports for workerd consumers. Run it through prepublish.mjs, which keeps its optionalDependencies but restores files and exports and removes the generated root files, so the root tarball is back to ~20kB.
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
import { spawnSync } from 'node:child_process';
|
|
import { readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
const packageJsonPath = join(import.meta.dirname, 'package.json');
|
|
const readPackageJson = () => JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
|
|
const before = readPackageJson();
|
|
|
|
const napi = spawnSync('napi', ['prepublish', ...process.argv.slice(2)], {
|
|
cwd: import.meta.dirname,
|
|
stdio: 'inherit',
|
|
shell: process.platform === 'win32',
|
|
});
|
|
if (napi.status !== 0) process.exit(napi.status ?? 1);
|
|
|
|
const after = readPackageJson();
|
|
const keptFiles = new Set(before.files ?? []);
|
|
const generatedFiles = (after.files ?? []).filter((file) => !keptFiles.has(file));
|
|
|
|
const restoreField = (target, source, key) => {
|
|
if (source && Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
else if (target) delete target[key];
|
|
};
|
|
|
|
restoreField(after, before, 'files');
|
|
restoreField(after, before, 'exports');
|
|
if (after.publishConfig) restoreField(after.publishConfig, before.publishConfig, 'exports');
|
|
|
|
writeFileSync(packageJsonPath, `${JSON.stringify(after, null, 2)}\n`);
|
|
|
|
for (const file of generatedFiles) rmSync(join(import.meta.dirname, file), { force: true });
|