UNPKG

@lerna/publish

Version:

Publish packages in the current project

97 lines (96 loc) 4.03 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var import_core = require("@lerna/core"); var import_p_map = __toESM(require("p-map")); var import_path = __toESM(require("path")); var import_slash = __toESM(require("slash")); module.exports = function factory(argv) { return new LinkCommand(argv); }; class LinkCommand extends import_core.Command { allPackages = []; targetGraph; get requiresGit() { return false; } initialize() { if (this.options.npmClient === "pnpm") { throw new import_core.ValidationError( "EWORKSPACES", "Link is not supported with pnpm workspaces, since pnpm will automatically link dependencies during `pnpm install`. See the pnpm docs for details: https://pnpm.io/workspaces" ); } this.allPackages = this.packageGraph?.rawPackageList ?? []; if (this.options.contents) { for (const pkg of this.allPackages) { pkg.contents = this.options.contents; } } this.targetGraph = this.options.forceLocal ? new import_core.PackageGraph(this.allPackages, "allDependencies", true) : this.packageGraph; } execute() { if (this.options._?.pop() === "convert") { return this.convertLinksToFileSpecs(); } return (0, import_core.symlinkDependencies)(this.allPackages, this.targetGraph, this.logger.newItem("link dependencies")); } convertLinksToFileSpecs() { const rootPkg = this.project.manifest; const rootDependencies = {}; const hoisted = {}; const changed = /* @__PURE__ */ new Set(); const savePrefix = "file:"; if (this.targetGraph) { for (const targetNode of this.targetGraph.values()) { const resolved = { name: targetNode.name, type: "directory", registry: false, scope: null, escapedName: null, rawSpec: "", saveSpec: null, fetchSpec: null, raw: "" }; if (targetNode.pkg.resolved.saveSpec) { rootDependencies[targetNode.name] = targetNode.pkg.resolved.saveSpec; } for (const depNode of targetNode.localDependents.values()) { const depVersion = (0, import_slash.default)(import_path.default.relative(depNode.pkg.location, targetNode.pkg.location)); depNode.pkg.updateLocalDependency(resolved, depVersion, savePrefix); changed.add(depNode); } if (targetNode.pkg.devDependencies) { Object.assign(hoisted, targetNode.pkg.devDependencies); targetNode.pkg.set("devDependencies", {}); changed.add(targetNode); } } } rootPkg?.set("dependencies", rootDependencies); rootPkg?.set("devDependencies", Object.assign(rootPkg?.get("devDependencies") || {}, hoisted)); return (0, import_p_map.default)(changed, (node) => node.pkg.serialize()).then(() => rootPkg?.serialize()); } } module.exports.LinkCommand = LinkCommand;