vlt
Version:
The vlt CLI
206 lines (203 loc) • 5.84 kB
JavaScript
var global = globalThis;
import {Buffer} from "node:buffer";
import {setTimeout as _vlt_setTimeout,clearTimeout as _vlt_clearTimeout,setImmediate as _vlt_setImmediate,clearImmediate as _vlt_clearImmediate,setInterval as _vlt_setInterval,clearInterval as _vlt_clearInterval} from "node:timers";
globalThis.setTimeout = _vlt_setTimeout;
globalThis.clearTimeout = _vlt_clearTimeout;
globalThis.setImmediate = _vlt_setImmediate;
globalThis.clearImmediate = _vlt_clearImmediate;
globalThis.setInterval = _vlt_setInterval;
globalThis.clearInterval = _vlt_clearInterval;
import {createRequire as _vlt_createRequire} from "node:module";
var require = _vlt_createRequire(import.meta.filename);
import {
packTarball
} from "./chunk-6BJTPL2T.js";
import {
prettyBytes
} from "./chunk-OQKFEHWI.js";
import {
createHostContextsMap
} from "./chunk-6K6533KS.js";
import "./chunk-IN6BBUSG.js";
import {
Query,
actual,
run
} from "./chunk-V52UM37T.js";
import "./chunk-6F6VOBW3.js";
import "./chunk-QEOLSUUZ.js";
import {
commandUsage
} from "./chunk-32II74H6.js";
import "./chunk-C3WXW4MY.js";
import "./chunk-JG56ZRZC.js";
import "./chunk-X4GYYGTU.js";
import "./chunk-CGWKWA24.js";
import "./chunk-MBW6A3RQ.js";
import "./chunk-YD3KKYTM.js";
import "./chunk-XGSKO6BL.js";
import "./chunk-RXFAZHP7.js";
import "./chunk-TW6XJ6XF.js";
import "./chunk-4LVU5YJD.js";
import "./chunk-TG2CR2PD.js";
import "./chunk-REP7WICP.js";
import "./chunk-XN35SAI7.js";
import "./chunk-52JFXOJH.js";
import {
error
} from "./chunk-CHD5BAMM.js";
import "./chunk-C5WO664N.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-WDTAG5VG.js.map