everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
51 lines (49 loc) • 2.2 kB
JavaScript
const require_services_deploy_integrity = require('./integrity.cjs');
const require_workspace_subtree = require('../../utils/workspace-subtree.cjs');
let node_fs = require("node:fs");
let node_path = require("node:path");
let node_crypto = require("node:crypto");
let node_os = require("node:os");
let tar = require("tar");
//#region src/services/deploy/source-archive.ts
/** Temp directory for a source archive leg (caller passes it as `outDir`). */
function makeSourceArchiveTempDir(prefix = "bos-source-archive-") {
return (0, node_fs.mkdtempSync)((0, node_path.join)((0, node_os.tmpdir)(), prefix));
}
/**
* Build the workspace's source archive in `outDir`: the shared subtree ignore
* set (`listWorkspaceSubtreeFiles`) selects the files; `tar.create` receives
* that explicit list, so its own ignore logic never re-derives the selection.
* The archive name is content-addressed — identical source bytes produce the
* identical `source.<16hex>.tar.gz` (gzip is deterministic for the same input
* bytes; file mtimes differ only when source files change, which changes the
* name anyway).
*/
async function buildSourceArchive(input) {
const files = await require_workspace_subtree.listWorkspaceSubtreeFiles(input.repoRoot, input.workspace);
if (files.length === 0) throw new Error(`[source-archive] workspace subtree is empty: ${input.workspace}`);
const pendingPath = (0, node_path.join)(input.outDir, ".pending.tar.gz");
await (0, tar.create)({
file: pendingPath,
cwd: input.repoRoot,
portable: true,
gzip: { level: 9 }
}, files);
const bytes = (0, node_fs.readFileSync)(pendingPath);
const name = `source.${(0, node_crypto.createHash)("sha256").update(bytes).digest("hex").slice(0, 16)}.tar.gz`;
const path = (0, node_path.join)(input.outDir, name);
(0, node_fs.renameSync)(pendingPath, path);
return {
file: `source/${name}`,
path,
integrity: require_services_deploy_integrity.computeSriHash(bytes),
cleanup: () => (0, node_fs.rmSync)(input.outDir, {
recursive: true,
force: true
})
};
}
//#endregion
exports.buildSourceArchive = buildSourceArchive;
exports.makeSourceArchiveTempDir = makeSourceArchiveTempDir;
//# sourceMappingURL=source-archive.cjs.map