vlt
Version:
The vlt CLI
200 lines (197 loc) • 5.45 kB
JavaScript
var global = globalThis;
import {Buffer} from "node:buffer";
import {setTimeout,clearTimeout,setImmediate,clearImmediate,setInterval,clearInterval} from "node:timers";
import {createRequire as _vlt_createRequire} from "node:module";
var require = _vlt_createRequire(import.meta.filename);
import {
packTarball
} from "./chunk-TQP53TWL.js";
import {
prettyBytes
} from "./chunk-QGJUWLFF.js";
import {
createHostContextsMap
} from "./chunk-4ADJWTGC.js";
import "./chunk-PVOBL7T7.js";
import "./chunk-3VS4XBYN.js";
import "./chunk-YF5FZDHL.js";
import "./chunk-GGPZGJ5H.js";
import "./chunk-OTLTOVZN.js";
import {
Query,
actual,
run
} from "./chunk-QALMFIGC.js";
import "./chunk-6RYZ5N3C.js";
import {
commandUsage
} from "./chunk-L3E552CT.js";
import "./chunk-GTAUGWLW.js";
import "./chunk-U5J4TCIV.js";
import "./chunk-KPA4XNCN.js";
import "./chunk-VYJVN3B6.js";
import "./chunk-B4MAUXR2.js";
import "./chunk-W7RMFRDJ.js";
import "./chunk-O57KIW5U.js";
import "./chunk-JBBINXAZ.js";
import "./chunk-OAYCZMD4.js";
import "./chunk-QOAKZNUG.js";
import "./chunk-BA67AKYJ.js";
import {
error
} from "./chunk-KVH5ECIG.js";
import "./chunk-AECDW3EJ.js";
// ../../src/cli-sdk/src/commands/pack.ts
import { writeFile } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
import assert from "node:assert";
var usage = () => commandUsage({
command: "pack",
usage: "",
description: `Create a tarball from a package in the current directory or specified folder.
The tarball will be saved to the current directory with the name
<name>-<version>.tgz.`,
options: {
"dry-run": {
description: "Show what would be packed without creating a tarball"
}
}
});
var views = {
human: (results) => {
const item = (r) => {
const lines = [
`\u{1F4E6} Package: ${r.id}`,
`\u{1F4C4} File: ${r.filename}`,
`\u{1F4C1} ${r.files.length} Files`,
...r.files.map((f) => ` - ${f}`),
`\u{1F4CA} Package Size: ${prettyBytes(r.size)}`,
`\u{1F4C2} Unpacked Size: ${prettyBytes(r.unpackedSize)}`
];
if (r.shasum) lines.push(`\u{1F512} Shasum: ${r.shasum}`);
if (r.integrity) lines.push(`\u{1F510} Integrity: ${r.integrity}`);
return lines.join("\n");
};
return Array.isArray(results) ? results.map(item).join("\n\n") : item(results);
},
json: (r) => r
};
var command = async (conf) => {
const { options, projectRoot } = conf;
const queryString = conf.get("scope");
const paths = conf.get("workspace");
const groups = conf.get("workspace-group");
const recursive = conf.get("recursive");
const locations = [];
let single = null;
if (queryString) {
const mainManifest = options.packageJson.maybeRead(projectRoot);
let graph;
if (mainManifest) {
graph = actual.load({
...options,
mainManifest,
monorepo: options.monorepo,
loadManifests: false
});
}
const hostContexts = await createHostContextsMap(conf);
const query = new Query({
/* c8 ignore next */
nodes: graph ? new Set(graph.nodes.values()) : /* @__PURE__ */ new Set(),
edges: graph?.edges ?? /* @__PURE__ */ new Set(),
importers: graph?.importers ?? /* @__PURE__ */ new Set(),
securityArchive: void 0,
hostContexts
});
const { nodes } = await query.search(queryString, {
signal: new AbortController().signal
});
for (const node of nodes) {
const { location } = node.toJSON();
assert(
location,
error(`node ${node.id} has no location`, {
found: node
})
);
locations.push(resolve(projectRoot, location));
}
} else if (paths?.length || groups?.length || recursive) {
for (const workspace of options.monorepo ?? []) {
locations.push(workspace.fullpath);
}
} else {
single = options.packageJson.find(process.cwd()) ?? projectRoot;
}
if (single) {
return commandSingle(single, conf);
}
assert(
locations.length > 0,
error("No workspaces or query results found")
);
const results = [];
for (const location of locations) {
results.push(await commandSingle(location, conf));
}
return results;
};
var commandSingle = async (location, conf) => {
const manifestPath = conf.options.packageJson.find(location);
assert(manifestPath, "No package.json found");
const manifestDir = dirname(manifestPath);
const manifest = conf.options.packageJson.read(manifestDir);
const isDryRun = conf.options["dry-run"];
const runOptions = {
cwd: manifestDir,
projectRoot: conf.projectRoot,
packageJson: conf.options.packageJson,
manifest,
ignoreMissing: true,
ignorePrePost: true
};
await run({
...runOptions,
arg0: "prepack"
});
await run({
...runOptions,
arg0: "prepare"
});
const {
name,
version,
filename,
tarballData,
unpackedSize,
files,
integrity,
shasum
} = await packTarball(manifest, manifestDir, conf);
if (!isDryRun) {
await writeFile(join(manifestDir, filename), tarballData);
}
await run({
...runOptions,
arg0: "postpack"
});
return {
id: `${name}@${version}`,
name,
version,
filename,
files,
size: tarballData.length,
unpackedSize,
shasum,
integrity
};
};
export {
command,
commandSingle,
usage,
views
};
//# sourceMappingURL=pack-ZMHKVULO.js.map