fix: include sharp optional runtime in WP5-05 package
Dada P0-A isolated Windows CI / validate-and-package (push) Successful in 12m34s

TASK-WP5-05: copy sharp and its installed Windows optional dependency, including packages without a default export, so the portable API can start.
This commit is contained in:
suyx
2026-08-04 01:32:20 +08:00
parent e8ffeac269
commit b00500512e
+13 -1
View File
@@ -98,8 +98,12 @@ function copyRuntimeDependencies(sourceRoot, destinationRoot, rootNames) {
try { try {
entry = requireFrom.resolve(name); entry = requireFrom.resolve(name);
} catch (error) { } catch (error) {
try {
entry = requireFrom.resolve(`${name}/package`);
} catch {
throw new Error(`Runtime dependency ${name} is unavailable from ${sourceRoot}.`, { cause: error }); throw new Error(`Runtime dependency ${name} is unavailable from ${sourceRoot}.`, { cause: error });
} }
}
const root = packageRootFromEntry(entry, name); const root = packageRootFromEntry(entry, name);
const manifest = json(join(root, "package.json")); const manifest = json(join(root, "package.json"));
const identity = `${manifest.name}@${manifest.version}`; const identity = `${manifest.name}@${manifest.version}`;
@@ -117,6 +121,14 @@ function copyRuntimeDependencies(sourceRoot, destinationRoot, rootNames) {
for (const dependency of Object.keys(manifest.dependencies ?? {})) { for (const dependency of Object.keys(manifest.dependencies ?? {})) {
copyResolved(dependency, nestedRequire, join(destination, "node_modules"), nestedAncestors); copyResolved(dependency, nestedRequire, join(destination, "node_modules"), nestedAncestors);
} }
for (const dependency of Object.keys(manifest.optionalDependencies ?? {})) {
try {
copyResolved(dependency, nestedRequire, join(destination, "node_modules"), nestedAncestors);
} catch (error) {
if (error?.cause?.code !== "MODULE_NOT_FOUND") throw error;
debug(`skip unavailable optional dependency ${dependency}`);
}
}
} }
const rootRequire = createRequire(join(sourceRoot, "package.json")); const rootRequire = createRequire(join(sourceRoot, "package.json"));
for (const name of rootNames) copyResolved(name, rootRequire, join(destinationRoot, "node_modules"), new Set()); for (const name of rootNames) copyResolved(name, rootRequire, join(destinationRoot, "node_modules"), new Set());
@@ -306,7 +318,7 @@ export async function buildAndValidatePortablePackage({ evidenceDirectory, outpu
const serverRoot = join(packageDirectory, "server"); const serverRoot = join(packageDirectory, "server");
debug("copy API application"); debug("copy API application");
const apiDependencies = copyApplication(join(repositoryRoot, "apps", "api"), join(serverRoot, "api"), ["@fastify/multipart", "@fastify/swagger", "@sinclair/typebox", "better-sqlite3", "fastify"]); const apiDependencies = copyApplication(join(repositoryRoot, "apps", "api"), join(serverRoot, "api"), ["@fastify/multipart", "@fastify/swagger", "@sinclair/typebox", "better-sqlite3", "fastify", "sharp"]);
debug("copy Worker application"); debug("copy Worker application");
const workerDependencies = copyApplication(join(repositoryRoot, "apps", "worker"), join(serverRoot, "worker"), ["better-sqlite3"]); const workerDependencies = copyApplication(join(repositoryRoot, "apps", "worker"), join(serverRoot, "worker"), ["better-sqlite3"]);
const sharedDestination = join(serverRoot, "api", "node_modules", "@dada", "shared-contracts"); const sharedDestination = join(serverRoot, "api", "node_modules", "@dada", "shared-contracts");