vlt
Version:
The vlt CLI
226 lines (223 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-3UQTYLWM.js";
import {
run
} from "./chunk-XZF5GYDF.js";
import "./chunk-SLTPNBLH.js";
import "./chunk-YWPMIBJS.js";
import "./chunk-SGEQHKFC.js";
import {
prettyBytes
} from "./chunk-57IH4XFG.js";
import {
commandUsage
} from "./chunk-2Y5QRO5N.js";
import {
RegistryClient
} from "./chunk-QAFV2NQX.js";
import "./chunk-VYJVN3B6.js";
import "./chunk-GADRCS54.js";
import "./chunk-GY4L7O2Y.js";
import "./chunk-3HSZY4YW.js";
import "./chunk-6YRWYWZQ.js";
import "./chunk-TJHWNOOA.js";
import "./chunk-3RABDTYN.js";
import "./chunk-264UXZEG.js";
import {
asError
} from "./chunk-X4RDKJKD.js";
import "./chunk-BNCOU5ZT.js";
import {
error
} from "./chunk-RV3EHS4P.js";
import "./chunk-AECDW3EJ.js";
// ../../src/cli-sdk/src/commands/publish.ts
import assert from "node:assert";
import { dirname } from "node:path";
var usage = () => commandUsage({
command: "publish",
usage: "",
description: `Create a tarball from a package and publish it to the configured registry.
This command will pack the package in the current directory or specified folder,
and then upload it to the configured registry.`,
options: {
tag: {
description: "Publish the package with the given tag",
value: "<tag>"
},
access: {
description: "Set access level (public or restricted)",
value: "<level>"
},
otp: {
description: `Provide an OTP to use when publishing a package.`,
value: "<otp>"
}
}
});
var views = {
human: (r) => {
const lines = [
`\u{1F4E6} Package: ${r.id}`,
`\u{1F3F7}\uFE0F Tag: ${r.tag}`,
`\u{1F4E1} Registry: ${r.registry}`,
`\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");
},
json: (r) => r
};
var command = async (conf) => {
const manifestPath = conf.options.packageJson.find();
assert(manifestPath, "No package.json found");
const manifestDir = dirname(manifestPath);
const manifest = conf.options.packageJson.read(manifestDir);
assert(
!manifest.private,
error("Package has been marked as private")
);
const {
tag = "latest",
access,
registry,
"dry-run": dry = false,
otp
} = conf.options;
const registryUrl = new URL(registry);
const runOptions = {
cwd: manifestDir,
projectRoot: conf.projectRoot,
packageJson: conf.options.packageJson,
manifest,
ignoreMissing: true,
ignorePrePost: true
};
await run({
...runOptions,
arg0: "prepublishOnly"
});
await run({
...runOptions,
arg0: "prepublish"
});
await run({
...runOptions,
arg0: "prepack"
});
await run({
...runOptions,
arg0: "prepare"
});
const {
name,
version,
tarballName,
tarballData,
unpackedSize,
files,
integrity,
shasum
} = await packTarball(manifest, manifestDir, conf);
await run({
...runOptions,
arg0: "postpack"
});
await run({
...runOptions,
arg0: "publish"
});
const publishMetadata = {
_id: name,
name,
description: manifest.description || "",
"dist-tags": {
[tag]: version
},
versions: {
[version]: {
...manifest,
_id: `${name}@${version}`,
_nodeVersion: process.versions.node,
dist: {
...manifest.dist,
integrity,
shasum,
tarball: new URL(`${name}/-/${tarballName}`, registryUrl).href
}
}
},
access,
_attachments: {
[tarballName]: {
content_type: "application/octet-stream",
data: tarballData.toString("base64"),
length: tarballData.length
}
}
};
const rc = new RegistryClient(conf.options);
const publishUrl = new URL(
name.startsWith("@") ? name.replace("/", "%2F") : name,
registryUrl
);
if (!dry) {
let response;
try {
response = await rc.request(publishUrl, {
method: "PUT",
headers: {
"content-type": "application/json",
// These control what type of OTP auth flow is used
"npm-auth-type": "web",
"npm-command": "publish"
},
body: JSON.stringify(publishMetadata),
otp
});
} catch (err) {
throw error("Failed to publish package", {
cause: asError(err)
});
}
if (response.statusCode !== 200 && response.statusCode !== 201) {
throw error("Failed to publish package", {
url: publishUrl,
response
});
}
}
await run({
...runOptions,
arg0: "postpublish"
});
return {
id: `${name}@${version}`,
name,
version,
tag,
access,
registry: registryUrl.origin,
integrity,
shasum,
size: tarballData.length,
unpackedSize,
files
};
};
export {
command,
usage,
views
};
//# sourceMappingURL=publish-J2UI2EOB.js.map