release: WRNexusJS 0.5.10

This commit is contained in:
2026-07-30 13:36:29 +05:30
parent 8fc6f15402
commit d1b0c55b53
159 changed files with 7509 additions and 604 deletions
+62 -6
View File
@@ -50,6 +50,20 @@ const ASSETS: Record<string, string[]> = {
],
};
function packageAssets(m: Record<string, any>): string[] {
const declared = Array.isArray(m.files)
? m.files.filter(
(entry: unknown): entry is string =>
typeof entry === "string" &&
entry !== "src" &&
!entry.startsWith("src/") &&
entry !== "dist" &&
entry !== "README.md",
)
: [];
return [...new Set([...(ASSETS[m.name] ?? []), ...declared])];
}
interface Pkg {
dir: string;
name: string;
@@ -104,6 +118,17 @@ function entriesOf(dir: string, m: Record<string, any>): Record<string, string>
add(m.main);
if (m.bin) Object.values(m.bin).forEach(add);
if (m.exports) for (const v of Object.values(m.exports)) add(v);
if (m.wrnexus?.plugin) {
const routesDir = join(dir, "src", "routes");
if (existsSync(routesDir)) {
for (const file of readdirSync(routesDir, { recursive: true }) as string[]) {
if (typeof file !== "string" || !file.endsWith(".ts")) continue;
const source = join(routesDir, file);
const outName = join("routes", file).replace(/\\/g, "/").replace(/\.ts$/, "");
map[outName] = source.replace(/\\/g, "/");
}
}
}
return map;
}
@@ -130,7 +155,11 @@ function removeDirectoryWithRetry(path: string): void {
}
/** Rewrite the manifest for publishing. */
function publishManifest(m: Record<string, any>, version: string): Record<string, any> {
function publishManifest(
m: Record<string, any>,
version: string,
workspaceVersions: Map<string, string>,
): Record<string, any> {
const js = (ts: string) => "./dist/" + ts.replace(/^\.?\/?src\//, "").replace(/\.ts$/, ".js");
const dts = (ts: string) => "./dist/" + ts.replace(/^\.?\/?src\//, "").replace(/\.ts$/, ".d.ts");
@@ -170,12 +199,22 @@ function publishManifest(m: Record<string, any>, version: string): Record<string
if (m.dependencies) {
out.dependencies = {};
for (const [dep, range] of Object.entries(m.dependencies)) {
out.dependencies[dep] = String(range).startsWith("workspace:") ? `^${version}` : range;
out.dependencies[dep] = String(range).startsWith("workspace:")
? `^${workspaceVersions.get(dep) ?? version}`
: range;
}
}
if (m.wrnexus) {
out.wrnexus = structuredClone(m.wrnexus);
const plugin = out.wrnexus?.plugin?.plugin;
if (typeof plugin === "string" && plugin.endsWith(".ts")) {
out.wrnexus.plugin.plugin = js(plugin);
}
}
const files = new Set(["dist"]);
for (const a of ASSETS[m.name] ?? []) files.add(a);
for (const a of packageAssets(m)) files.add(a);
out.files = [...files];
return out;
@@ -183,7 +222,16 @@ function publishManifest(m: Record<string, any>, version: string): Record<string
async function main() {
const filter = process.argv.slice(2);
const pkgs = topoSort(readPackages(filter));
const allPackages = readPackages([]);
const workspaceVersions = new Map(
allPackages.map((pkg) => [pkg.name, String(pkg.manifest.version)]),
);
const selected = filter.length
? allPackages.filter(
(pkg) => filter.includes(pkg.dir.split(/[\\/]/).pop()!) || filter.includes(pkg.name),
)
: allPackages;
const pkgs = topoSort(selected);
if (!pkgs.length) {
console.error("No @wrnexus packages matched.");
process.exit(1);
@@ -225,11 +273,19 @@ async function main() {
const stage = join(stageRoot, p.name.replace("@wrnexus/", ""));
mkdirSync(stage, { recursive: true });
cpSync(join(p.dir, "dist"), join(stage, "dist"), { recursive: true });
for (const a of ASSETS[p.name] ?? []) {
for (const a of packageAssets(p.manifest)) {
if (existsSync(join(p.dir, a))) cpSync(join(p.dir, a), join(stage, a), { recursive: true });
}
const manifest = publishManifest(p.manifest, p.manifest.version);
const manifest = publishManifest(p.manifest, p.manifest.version, workspaceVersions);
writeFileSync(join(stage, "package.json"), JSON.stringify(manifest, null, 2) + "\n");
if (p.manifest.wrnexus && !manifest.wrnexus?.plugin?.plugin) {
throw new Error(`${p.name} lost its wrnexus.plugin metadata while staging.`);
}
for (const asset of packageAssets(p.manifest)) {
if (!existsSync(join(stage, asset))) {
throw new Error(`${p.name} did not stage declared runtime asset ${asset}.`);
}
}
// Ship the package's own README.md if it has one; else a minimal placeholder.
const srcReadme = join(p.dir, "README.md");
if (existsSync(srcReadme)) {