UNPKG

lerna

Version:

Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository

1,443 lines (1,386 loc) 105 kB
"use strict"; 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 __esm = (fn, res) => function __init() { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; }; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; 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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // libs/core/src/lib/add-dependencies.ts var init_add_dependencies = __esm({ "libs/core/src/lib/add-dependencies.ts"() { "use strict"; } }); // libs/core/src/lib/add-dependents.ts var import_lodash; var init_add_dependents = __esm({ "libs/core/src/lib/add-dependents.ts"() { "use strict"; import_lodash = require("lodash"); } }); // libs/child-process/src/set-exit-code.ts function setExitCode(code) { process.exitCode = code; } var init_set_exit_code = __esm({ "libs/child-process/src/set-exit-code.ts"() { "use strict"; } }); // libs/child-process/src/index.ts var src_exports = {}; __export(src_exports, { exec: () => exec, execSync: () => execSync, getChildProcessCount: () => getChildProcessCount, getExitCode: () => getExitCode, spawn: () => spawn, spawnStreaming: () => spawnStreaming }); function exec(command, args, opts) { const options = Object.assign({ stdio: "pipe" }, opts); const spawned = spawnProcess(command, args, options); return wrapError(spawned); } function execSync(command, args, opts) { return import_execa.default.sync(command, args, opts).stdout; } function spawn(command, args, opts) { const options = Object.assign({}, opts, { stdio: "inherit" }); const spawned = spawnProcess(command, args, options); return wrapError(spawned); } function spawnStreaming(command, args, opts, prefix) { const options = Object.assign({}, opts); options.stdio = ["ignore", "pipe", "pipe"]; const spawned = spawnProcess(command, args, options); const stdoutOpts = {}; const stderrOpts = {}; if (prefix) { const colorName = colorWheel[currentColor % NUM_COLORS]; const color = colorName; currentColor += 1; stdoutOpts.tag = `${color.bold(prefix)}:`; stderrOpts.tag = `${color(prefix)}:`; } if (children.size > process.stdout.listenerCount("close")) { process.stdout.setMaxListeners(children.size); process.stderr.setMaxListeners(children.size); } spawned.stdout?.pipe((0, import_strong_log_transformer.default)(stdoutOpts)).pipe(process.stdout); spawned.stderr?.pipe((0, import_strong_log_transformer.default)(stderrOpts)).pipe(process.stderr); return wrapError(spawned); } function getChildProcessCount() { return children.size; } function getExitCode(result) { if (result.exitCode) { return result.exitCode; } if (typeof result.code === "number") { return result.code; } if (typeof result.code === "string") { return import_os.default.constants.errno[result.code]; } return process.exitCode; } function spawnProcess(command, args, opts) { const child = (0, import_execa.default)(command, args, opts); const drain = (exitCode, signal) => { children.delete(child); if (signal === void 0) { child.removeListener("exit", drain); } if (exitCode) { setExitCode(exitCode); } }; child.once("exit", drain); child.once("error", drain); if (opts?.pkg) { child.pkg = opts.pkg; } children.add(child); return child; } function wrapError(spawned) { if (spawned.pkg) { return spawned.catch((err) => { err.exitCode = getExitCode(err); err.pkg = spawned.pkg; throw err; }); } return spawned; } var import_os, import_chalk, import_execa, import_strong_log_transformer, children, colorWheel, NUM_COLORS, currentColor; var init_src = __esm({ "libs/child-process/src/index.ts"() { "use strict"; import_os = __toESM(require("os")); import_chalk = __toESM(require("chalk")); import_execa = __toESM(require("execa")); import_strong_log_transformer = __toESM(require("strong-log-transformer")); init_set_exit_code(); children = /* @__PURE__ */ new Set(); colorWheel = [import_chalk.default.cyan, import_chalk.default.magenta, import_chalk.default.blue, import_chalk.default.yellow, import_chalk.default.green, import_chalk.default.blueBright]; NUM_COLORS = colorWheel.length; currentColor = 0; } }); // libs/core/src/lib/collect-uncommitted.ts function collectUncommitted({ cwd, log: log34 = import_npmlog.default }) { log34.silly("collect-uncommitted", "git status --porcelain (async)"); return childProcess.exec("git", ["status", "--porcelain"], { cwd }).then(({ stdout }) => transformOutput(stdout)); } var import_chalk2, import_npmlog, childProcess, maybeColorize, cRed, cGreen, replaceStatus, colorizeStats, splitOnNewLine, filterEmpty, o, transformOutput; var init_collect_uncommitted = __esm({ "libs/core/src/lib/collect-uncommitted.ts"() { "use strict"; import_chalk2 = __toESM(require("chalk")); import_npmlog = __toESM(require("npmlog")); childProcess = (init_src(), __toCommonJS(src_exports)); maybeColorize = (colorize) => (s) => s !== " " ? colorize(s) : s; cRed = maybeColorize(import_chalk2.default.red); cGreen = maybeColorize(import_chalk2.default.green); replaceStatus = (_, maybeGreen, maybeRed) => `${cGreen(maybeGreen)}${cRed(maybeRed)}`; colorizeStats = (stats) => stats.replace(/^([^U]| )([A-Z]| )/gm, replaceStatus).replace(/^\?{2}|U{2}/gm, cRed("$&")); splitOnNewLine = (str) => str.split("\n"); filterEmpty = (lines) => lines.filter((line) => line.length); o = (l, r) => (x) => l(r(x)); transformOutput = o(filterEmpty, o(splitOnNewLine, colorizeStats)); } }); // libs/core/src/lib/describe-ref.ts var import_npmlog2, childProcess2; var init_describe_ref = __esm({ "libs/core/src/lib/describe-ref.ts"() { "use strict"; import_npmlog2 = __toESM(require("npmlog")); childProcess2 = (init_src(), __toCommonJS(src_exports)); } }); // libs/core/src/lib/validation-error.ts var import_npmlog3, ValidationError; var init_validation_error = __esm({ "libs/core/src/lib/validation-error.ts"() { "use strict"; import_npmlog3 = __toESM(require("npmlog")); ValidationError = class extends Error { constructor(prefix, message, ...rest) { super(message); this.name = "ValidationError"; this.prefix = prefix; import_npmlog3.default.resume(); import_npmlog3.default.error(prefix, message, ...rest); } }; } }); // libs/core/src/lib/check-working-tree.ts function mkThrowIfUncommitted(options = {}) { return function throwIfUncommitted2(opts) { if (opts.isDirty) { return collectUncommitted(options).then((uncommitted) => { throw new ValidationError("EUNCOMMIT", `${EUNCOMMIT_MSG}${uncommitted.join("\n")}`); }); } }; } var EUNCOMMIT_MSG, throwIfUncommitted; var init_check_working_tree = __esm({ "libs/core/src/lib/check-working-tree.ts"() { "use strict"; init_collect_uncommitted(); init_describe_ref(); init_validation_error(); EUNCOMMIT_MSG = "Working tree has uncommitted changes, please commit or remove the following changes before continuing:\n"; throwIfUncommitted = mkThrowIfUncommitted(); } }); // libs/core/src/lib/cli.ts var import_dedent, import_npmlog4, import_yargs; var init_cli = __esm({ "libs/core/src/lib/cli.ts"() { "use strict"; import_dedent = __toESM(require("dedent")); import_npmlog4 = __toESM(require("npmlog")); import_yargs = __toESM(require("yargs")); } }); // libs/core/src/lib/get-packages-for-option.ts var init_get_packages_for_option = __esm({ "libs/core/src/lib/get-packages-for-option.ts"() { "use strict"; } }); // libs/core/src/lib/prerelease-id-from-version.ts var import_semver; var init_prerelease_id_from_version = __esm({ "libs/core/src/lib/prerelease-id-from-version.ts"() { "use strict"; import_semver = __toESM(require("semver")); } }); // libs/core/src/lib/project-graph-with-packages.ts var init_project_graph_with_packages = __esm({ "libs/core/src/lib/project-graph-with-packages.ts"() { "use strict"; } }); // libs/core/src/lib/collect-updates/has-tags.ts var import_npmlog5, childProcess3; var init_has_tags = __esm({ "libs/core/src/lib/collect-updates/has-tags.ts"() { "use strict"; import_npmlog5 = __toESM(require("npmlog")); childProcess3 = (init_src(), __toCommonJS(src_exports)); } }); // libs/core/src/lib/collect-updates/make-diff-predicate.ts var import_minimatch, import_npmlog6, import_slash, execSync2; var init_make_diff_predicate = __esm({ "libs/core/src/lib/collect-updates/make-diff-predicate.ts"() { "use strict"; import_minimatch = __toESM(require("minimatch")); import_npmlog6 = __toESM(require("npmlog")); import_slash = __toESM(require("slash")); init_project_graph_with_packages(); ({ execSync: execSync2 } = (init_src(), __toCommonJS(src_exports))); } }); // libs/core/src/lib/collect-updates/collect-project-updates.ts var import_lodash2, import_npmlog7; var init_collect_project_updates = __esm({ "libs/core/src/lib/collect-updates/collect-project-updates.ts"() { "use strict"; import_lodash2 = require("lodash"); import_npmlog7 = __toESM(require("npmlog")); init_describe_ref(); init_get_packages_for_option(); init_prerelease_id_from_version(); init_project_graph_with_packages(); init_has_tags(); init_make_diff_predicate(); } }); // libs/core/src/lib/collect-updates/index.ts var init_collect_updates = __esm({ "libs/core/src/lib/collect-updates/index.ts"() { "use strict"; init_collect_project_updates(); } }); // libs/core/src/lib/package.ts function binSafeName({ name, scope }) { return scope ? name.substring(scope.length + 1) : name; } function shallowCopy(json) { return Object.keys(json).reduce((obj, key) => { const val = json[key]; if (Array.isArray(val)) { obj[key] = val.slice(); } else if (val && typeof val === "object") { obj[key] = Object.assign({}, val); } else { obj[key] = val; } return obj; }, {}); } var import_devkit, import_fs, import_load_json_file, import_npm_package_arg, import_path, import_write_pkg, PKG, _location, _resolved, _rootPath, _scripts, _contents, Package; var init_package = __esm({ "libs/core/src/lib/package.ts"() { "use strict"; import_devkit = require("@nx/devkit"); import_fs = __toESM(require("fs")); import_load_json_file = __toESM(require("load-json-file")); import_npm_package_arg = __toESM(require("npm-package-arg")); import_path = __toESM(require("path")); import_write_pkg = __toESM(require("write-pkg")); PKG = Symbol("pkg"); _location = Symbol("location"); _resolved = Symbol("resolved"); _rootPath = Symbol("rootPath"); _scripts = Symbol("scripts"); _contents = Symbol("contents"); Package = class _Package { static { PKG, _location, _resolved, _rootPath, _scripts, _contents; } /** * Create a Package instance from parameters, possibly reusing existing instance. * @param ref A path to a package.json file, Package instance, or JSON object * @param [dir] If `ref` is a JSON object, this is the location of the manifest */ static lazy(ref, dir = ".") { if (typeof ref === "string") { const location = import_path.default.resolve(import_path.default.basename(ref) === "package.json" ? import_path.default.dirname(ref) : ref); const manifest = import_load_json_file.default.sync(import_path.default.join(location, "package.json")); return new _Package(manifest, location); } if ("__isLernaPackage" in ref) { return ref; } return new _Package(ref, dir); } constructor(pkg, location, rootPath = location) { const resolved = import_npm_package_arg.default.resolve(pkg.name, `file:${import_path.default.relative(rootPath, location)}`, rootPath); this.name = pkg.name; this[PKG] = pkg; Object.defineProperty(this, PKG, { enumerable: false, writable: true }); this[_location] = location; this[_resolved] = resolved; this[_rootPath] = rootPath; this[_scripts] = { ...pkg.scripts }; } // readonly getters get location() { return this[_location]; } get private() { return Boolean(this[PKG].private); } set private(isPrivate) { this[PKG].private = isPrivate; } get resolved() { return this[_resolved]; } get rootPath() { return this[_rootPath]; } get scripts() { return this[_scripts]; } get lernaConfig() { return this[PKG].lerna; } set lernaConfig(config) { this[PKG].lerna = config; } get bin() { const pkg = this[PKG]; return typeof pkg.bin === "string" ? { // See note on function implementation // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore [binSafeName(this.resolved)]: pkg.bin } : Object.assign({}, pkg.bin); } get binLocation() { return import_path.default.join(this.location, "node_modules", ".bin"); } get manifestLocation() { return import_path.default.join(this.location, "package.json"); } get nodeModulesLocation() { return import_path.default.join(this.location, "node_modules"); } // eslint-disable-next-line class-methods-use-this get __isLernaPackage() { return true; } // accessors get version() { return this[PKG].version; } set version(version) { this[PKG].version = version; } get contents() { if (this[_contents]) { return this[_contents]; } if (this[PKG].publishConfig && this[PKG].publishConfig.directory) { return import_path.default.join(this.location, this[PKG].publishConfig.directory); } return this.location; } set contents(subDirectory) { const _workspaceRoot = process.env["NX_WORKSPACE_ROOT_PATH"] || import_devkit.workspaceRoot; if (subDirectory.startsWith(_workspaceRoot)) { this[_contents] = subDirectory; return; } this[_contents] = import_path.default.join(this.location, subDirectory); } // "live" collections get dependencies() { return this[PKG].dependencies; } get devDependencies() { return this[PKG].devDependencies; } get optionalDependencies() { return this[PKG].optionalDependencies; } get peerDependencies() { return this[PKG].peerDependencies; } /** * Map-like retrieval of arbitrary values */ get(key) { return this[PKG][key]; } /** * Map-like storage of arbitrary values */ set(key, val) { this[PKG][key] = val; return this; } /** * Provide shallow copy for munging elsewhere */ toJSON() { return shallowCopy(this[PKG]); } /** * Refresh internal state from disk (e.g., changed by external lifecycles) */ refresh() { return (0, import_load_json_file.default)(this.manifestLocation).then((pkg) => { this[PKG] = pkg; return this; }); } /** * Write manifest changes to disk * @returns {Promise} resolves when write finished */ serialize() { return (0, import_write_pkg.default)(this.manifestLocation, this[PKG]).then(() => this); } /** * Sync dist manifest version */ async syncDistVersion(doSync) { if (doSync) { const distPkg = import_path.default.join(this.contents, "package.json"); if (distPkg !== this.manifestLocation && import_fs.default.existsSync(distPkg)) { const pkg = await (0, import_load_json_file.default)(distPkg); pkg.version = this[PKG].version; await (0, import_write_pkg.default)(distPkg, pkg); } } return this; } getLocalDependency(depName) { if (this.dependencies && this.dependencies[depName]) { return { collection: "dependencies", spec: this.dependencies[depName] }; } if (this.devDependencies && this.devDependencies[depName]) { return { collection: "devDependencies", spec: this.devDependencies[depName] }; } if (this.optionalDependencies && this.optionalDependencies[depName]) { return { collection: "optionalDependencies", spec: this.optionalDependencies[depName] }; } return null; } /** * Mutate local dependency spec according to type * @param resolved npa metadata * @param depVersion semver * @param savePrefix npm_config_save_prefix */ updateLocalDependency(resolved, depVersion, savePrefix, options = { retainWorkspacePrefix: true }) { const depName = resolved.name; let depCollection = this.dependencies; if (!depCollection || !depCollection[depName]) { depCollection = this.optionalDependencies; } if (!depCollection || !depCollection[depName]) { depCollection = this.devDependencies; } if (resolved.workspaceSpec && options.retainWorkspacePrefix) { if (!resolved.workspaceAlias) { const workspacePrefix = resolved.workspaceSpec.match(/^(workspace:[*~^]?)/)[0]; depCollection[depName] = `${workspacePrefix}${depVersion}`; } } else if (resolved.registry || resolved.type === "directory") { depCollection[depName] = `${savePrefix}${depVersion}`; } else if (resolved.gitCommittish) { const [tagPrefix] = /^\D*/.exec(resolved.gitCommittish); const { hosted } = resolved; hosted.committish = `${tagPrefix}${depVersion}`; depCollection[depName] = hosted.toString({ noGitPlus: false, noCommittish: false }); } else if (resolved.gitRange) { const { hosted } = resolved; hosted.committish = `semver:${savePrefix}${depVersion}`; depCollection[depName] = hosted.toString({ noGitPlus: false, noCommittish: false }); } } /** * Remove the private property, effectively making the package public. */ removePrivate() { delete this[PKG].private; } }; } }); // libs/core/src/lib/project/shallow-extend.ts function shallowExtend(json, defaults = {}) { return Object.keys(json).reduce((obj, key) => { const val = json[key]; if (Array.isArray(val)) { obj[key] = val.slice(); } else if (val && typeof val === "object") { obj[key] = shallowExtend(val, obj[key]); } else { obj[key] = val; } return obj; }, defaults); } var init_shallow_extend = __esm({ "libs/core/src/lib/project/shallow-extend.ts"() { "use strict"; } }); // libs/core/src/lib/project/apply-extends.ts function applyExtends(config, cwd, seen = /* @__PURE__ */ new Set()) { let defaultConfig = {}; if ("extends" in config) { let pathToDefault; try { pathToDefault = (0, import_resolve_from.default)(cwd, config.extends); } catch (err) { throw new ValidationError("ERESOLVED", "Config .extends must be locally-resolvable", err); } if (seen.has(pathToDefault)) { throw new ValidationError("ECIRCULAR", "Config .extends cannot be circular", seen); } seen.add(pathToDefault); defaultConfig = require(pathToDefault); delete config.extends; defaultConfig = applyExtends(defaultConfig, import_path2.default.dirname(pathToDefault), seen); } return shallowExtend(config, defaultConfig); } var import_path2, import_resolve_from; var init_apply_extends = __esm({ "libs/core/src/lib/project/apply-extends.ts"() { "use strict"; import_path2 = __toESM(require("path")); import_resolve_from = __toESM(require("resolve-from")); init_validation_error(); init_shallow_extend(); } }); // libs/core/src/lib/project/make-file-finder.ts function normalize(results) { return results.map((fp) => import_path3.default.normalize(fp)); } function getGlobOpts(rootPath, packageConfigs) { const globOpts = { cwd: rootPath, absolute: true, expandDirectories: false, followSymbolicLinks: false }; if (packageConfigs.some((cfg) => cfg.indexOf("**") > -1)) { if (packageConfigs.some((cfg) => cfg.indexOf("node_modules") > -1)) { throw new ValidationError( "EPKGCONFIG", "An explicit node_modules package path does not allow globstars (**)" ); } globOpts.ignore = [ // allow globs like "packages/**", // but avoid picking up node_modules/**/package.json "**/node_modules/**" ]; } return globOpts; } function makeFileFinder(rootPath, packageConfigs) { const globOpts = getGlobOpts(rootPath, packageConfigs); return (fileName, fileMapper, customGlobOpts) => { const options = Object.assign({}, customGlobOpts, globOpts); const promise = (0, import_p_map.default)( Array.from(packageConfigs).sort(), (globPath) => { let chain = (0, import_globby.default)(import_path3.default.posix.join(globPath, fileName), options); chain = chain.then((results) => results.sort()); chain = chain.then(normalize); if (fileMapper) { chain = chain.then(fileMapper); } return chain; }, { concurrency: 4 } ); return promise.then((results) => results.reduce((acc, result) => acc.concat(result), [])); }; } function makeSyncFileFinder(rootPath, packageConfigs) { const globOpts = getGlobOpts(rootPath, packageConfigs); return (fileName, fileMapper) => { const patterns = packageConfigs.map((globPath) => import_path3.default.posix.join(globPath, fileName)).sort(); let results = import_globby.default.sync(patterns, globOpts); results = normalize(results); return results.map((res) => fileMapper(res)); }; } var import_globby, import_p_map, import_path3; var init_make_file_finder = __esm({ "libs/core/src/lib/project/make-file-finder.ts"() { "use strict"; import_globby = __toESM(require("globby")); import_p_map = __toESM(require("p-map")); import_path3 = __toESM(require("path")); init_validation_error(); } }); // libs/core/src/lib/project/index.ts var import_devkit2, import_cosmiconfig, import_dedent2, import_fs2, import_glob_parent, import_globby2, import_js_yaml, import_load_json_file2, import_npmlog8, import_p_map2, import_path4, LICENSE_GLOB, Project, getPackages, getPackagesSync; var init_project = __esm({ "libs/core/src/lib/project/index.ts"() { "use strict"; import_devkit2 = require("@nx/devkit"); import_cosmiconfig = require("cosmiconfig"); import_dedent2 = __toESM(require("dedent")); import_fs2 = __toESM(require("fs")); import_glob_parent = __toESM(require("glob-parent")); import_globby2 = __toESM(require("globby")); import_js_yaml = require("js-yaml"); import_load_json_file2 = __toESM(require("load-json-file")); import_npmlog8 = __toESM(require("npmlog")); import_p_map2 = __toESM(require("p-map")); import_path4 = __toESM(require("path")); init_package(); init_validation_error(); init_apply_extends(); init_make_file_finder(); LICENSE_GLOB = "LICEN{S,C}E{,.*}"; Project = class _Project { /** * @deprecated Only used in legacy core utilities * TODO: remove in v8 */ static getPackages(cwd) { return new _Project(cwd).getPackages(); } /** * @deprecated Only used in legacy core utilities * TODO: remove in v8 */ static getPackagesSync(cwd) { return new _Project(cwd).getPackagesSync(); } constructor(cwd, options) { const { config, configNotFound, filepath } = this.#resolveLernaConfig(cwd); this.config = config; this.configNotFound = configNotFound || false; this.rootConfigLocation = filepath; this.rootPath = import_path4.default.dirname(filepath); this.manifest = this.#resolveRootPackageJson(); if (this.configNotFound) { throw new ValidationError("ENOLERNA", "`lerna.json` does not exist, have you run `lerna init`?"); } if (!options?.skipLernaConfigValidations) { this.#validateLernaConfig(config); } this.packageConfigs = this.#resolvePackageConfigs(); import_npmlog8.default.verbose("rootPath", this.rootPath); } get version() { return this.config.version; } set version(val) { this.config.version = val; } get packageParentDirs() { return this.packageConfigs.map((packagePattern) => (0, import_glob_parent.default)(packagePattern)).map((parentDir) => import_path4.default.resolve(this.rootPath, parentDir)); } get licensePath() { let licensePath; try { const search = import_globby2.default.sync(LICENSE_GLOB, { cwd: this.rootPath, absolute: true, caseSensitiveMatch: false, // Project license is always a sibling of the root manifest deep: 0 }); licensePath = search.shift(); if (licensePath) { licensePath = import_path4.default.normalize(licensePath); Object.defineProperty(this, "licensePath", { value: licensePath }); } } catch (err) { throw new ValidationError(err.name, err.message); } return licensePath; } get fileFinder() { const finder = makeFileFinder(this.rootPath, this.packageConfigs); Object.defineProperty(this, "fileFinder", { value: finder }); return finder; } /** * A promise resolving to a list of Package instances */ getPackages() { const mapper = (packageConfigPath) => (0, import_load_json_file2.default)(packageConfigPath).then( (packageJson) => new Package(packageJson, import_path4.default.dirname(packageConfigPath), this.rootPath) ); return this.fileFinder("package.json", (filePaths) => (0, import_p_map2.default)(filePaths, mapper, { concurrency: 50 })); } /** * A list of Package instances */ getPackagesSync() { const syncFileFinder = makeSyncFileFinder(this.rootPath, this.packageConfigs); return syncFileFinder("package.json", (packageConfigPath) => { return new Package( import_load_json_file2.default.sync(packageConfigPath), import_path4.default.dirname(packageConfigPath), this.rootPath ); }); } getPackageLicensePaths() { return this.fileFinder(LICENSE_GLOB, null, { caseSensitiveMatch: false }); } isIndependent() { return this.version === "independent"; } serializeConfig() { (0, import_devkit2.writeJsonFile)(this.rootConfigLocation, this.config, { spaces: 2 }); return this.rootConfigLocation; } #resolveRootPackageJson() { try { const manifestLocation = import_path4.default.join(this.rootPath, "package.json"); const packageJson = import_load_json_file2.default.sync(manifestLocation); if (!packageJson.name) { packageJson.name = import_path4.default.basename(import_path4.default.dirname(manifestLocation)); } return new Package(packageJson, this.rootPath); } catch (err) { if (err instanceof Error && err?.name === "JSONError") { throw new ValidationError(err.name, err.message); } throw new ValidationError("ENOPKG", "`package.json` does not exist, have you run `lerna init`?"); } } #resolveLernaConfig(cwd) { try { const explorer = (0, import_cosmiconfig.cosmiconfigSync)("lerna", { loaders: { ...import_cosmiconfig.defaultLoaders, ".json": (filepath, content) => { if (!filepath.endsWith("lerna.json")) { return import_cosmiconfig.defaultLoaders[".json"](filepath, content); } try { return (0, import_devkit2.parseJson)(content); } catch (err) { if (err instanceof Error) { err.name = "JSONError"; err.message = `Error in: ${filepath} ${err.message}`; } throw err; } } }, searchPlaces: ["lerna.json", "package.json"], transform(obj) { if (!obj) { const configNotFoundResult = { // No need to distinguish between missing and empty, // saves a lot of noisy guards elsewhere config: {}, configNotFound: true, // path.resolve(".", ...) starts from process.cwd() filepath: import_path4.default.resolve(cwd || ".", "lerna.json") }; return configNotFoundResult; } obj.config = applyExtends(obj.config, import_path4.default.dirname(obj.filepath)); return obj; } }); return explorer.search(cwd); } catch (err) { if (err.name === "JSONError") { throw new ValidationError(err.name, err.message); } throw err; } } #validateLernaConfig(config) { if (!this.version) { throw new ValidationError("ENOVERSION", "Required property version does not exist in `lerna.json`"); } if (config.useWorkspaces !== void 0) { throw new ValidationError( "ECONFIGWORKSPACES", `The "useWorkspaces" option has been removed. By default lerna will resolve your packages using your package manager's workspaces configuration. Alternatively, you can manually provide a list of package globs to be used instead via the "packages" option in lerna.json.` ); } } #resolvePnpmWorkspaceConfig() { let config; try { const configLocation = import_path4.default.join(this.rootPath, "pnpm-workspace.yaml"); const configContent = import_fs2.default.readFileSync(configLocation, { encoding: "utf8" }); config = (0, import_js_yaml.load)(configContent); } catch (err) { if (err.message.includes("ENOENT: no such file or directory")) { throw new ValidationError( "ENOENT", "No pnpm-workspace.yaml found. See https://pnpm.io/workspaces for help configuring workspaces in pnpm." ); } throw new ValidationError(err.name, err.message); } return config; } /** * By default, the user's package manager workspaces configuration will be used to resolve packages. * However, they can optionally specify an explicit set of package globs to be used instead. * * NOTE: This does not impact the project graph creation process, which will still ultimately use * the package manager workspaces configuration to construct a full graph, it will only impact which * of the packages in that graph will be considered when running commands. */ #resolvePackageConfigs() { if (this.config.packages) { import_npmlog8.default.verbose( "packageConfigs", `Explicit "packages" configuration found in lerna.json. Resolving packages using the configured glob(s): ${JSON.stringify( this.config.packages )}` ); return this.config.packages; } if (this.config.npmClient === "pnpm") { import_npmlog8.default.verbose( "packageConfigs", 'Package manager "pnpm" detected. Resolving packages using `pnpm-workspace.yaml`.' ); const workspaces2 = this.#resolvePnpmWorkspaceConfig().packages; if (!workspaces2) { throw new ValidationError( "EWORKSPACES", 'No "packages" property found in `pnpm-workspace.yaml`. See https://pnpm.io/workspaces for help configuring workspaces in pnpm.' ); } return workspaces2; } const workspaces = this.manifest?.get("workspaces"); const isYarnClassicWorkspacesObjectConfig = Boolean( workspaces && typeof workspaces === "object" && Array.isArray(workspaces.packages) ); const isValidWorkspacesConfig = Array.isArray(workspaces) || isYarnClassicWorkspacesObjectConfig; if (!workspaces || !isValidWorkspacesConfig) { throw new ValidationError( "EWORKSPACES", import_dedent2.default` Lerna is expecting to able to resolve the "workspaces" configuration from your package manager in order to determine what packages to work on, but no "workspaces" config was found. (A) Did you mean to specify a "packages" config manually in lerna.json instead of using your workspaces config? (B) Alternatively, if you are using pnpm as your package manager, make sure you set "npmClient": "pnpm" in your lerna.json so that lerna knows to read from the "pnpm-workspace.yaml" file instead of package.json. See: https://lerna.js.org/docs/getting-started ` ); } import_npmlog8.default.verbose("packageConfigs", `Resolving packages based on package.json "workspaces" configuration.`); if (isYarnClassicWorkspacesObjectConfig) { return workspaces.packages; } return workspaces; } }; getPackages = Project.getPackages; getPackagesSync = Project.getPackagesSync; } }); // libs/core/src/lib/write-log-file.ts var import_npmlog9, import_write_file_atomic; var init_write_log_file = __esm({ "libs/core/src/lib/write-log-file.ts"() { "use strict"; import_npmlog9 = __toESM(require("npmlog")); import_write_file_atomic = __toESM(require("write-file-atomic")); } }); // libs/core/src/lib/command/clean-stack.ts var init_clean_stack = __esm({ "libs/core/src/lib/command/clean-stack.ts"() { "use strict"; } }); // libs/core/src/lib/command/default-options.ts var init_default_options = __esm({ "libs/core/src/lib/command/default-options.ts"() { "use strict"; } }); // libs/core/src/lib/get-package-manifest-path.ts var init_get_package_manifest_path = __esm({ "libs/core/src/lib/get-package-manifest-path.ts"() { "use strict"; } }); // libs/core/src/lib/command/create-project-graph-with-packages.ts var import_devkit3, import_fs_extra, import_lodash3, import_minimatch2, import_npm_package_arg2, import_semver2; var init_create_project_graph_with_packages = __esm({ "libs/core/src/lib/command/create-project-graph-with-packages.ts"() { "use strict"; import_devkit3 = require("@nx/devkit"); import_fs_extra = require("fs-extra"); import_lodash3 = require("lodash"); import_minimatch2 = __toESM(require("minimatch")); import_npm_package_arg2 = require("npm-package-arg"); import_semver2 = require("semver"); init_get_package_manifest_path(); init_package(); init_project_graph_with_packages(); } }); // libs/core/src/lib/command/detect-projects.ts var import_devkit4; var init_detect_projects = __esm({ "libs/core/src/lib/command/detect-projects.ts"() { "use strict"; import_devkit4 = require("@nx/devkit"); init_create_project_graph_with_packages(); } }); // libs/core/src/lib/command/is-git-initialized.ts var import_execa2; var init_is_git_initialized = __esm({ "libs/core/src/lib/command/is-git-initialized.ts"() { "use strict"; import_execa2 = __toESM(require("execa")); } }); // libs/core/src/lib/command/log-package-error.ts var import_npmlog10; var init_log_package_error = __esm({ "libs/core/src/lib/command/log-package-error.ts"() { "use strict"; import_npmlog10 = __toESM(require("npmlog")); } }); // libs/core/src/lib/command/warn-if-hanging.ts var import_npmlog11, childProcess4; var init_warn_if_hanging = __esm({ "libs/core/src/lib/command/warn-if-hanging.ts"() { "use strict"; import_npmlog11 = __toESM(require("npmlog")); childProcess4 = (init_src(), __toCommonJS(src_exports)); } }); // libs/core/src/lib/command/index.ts var import_clone_deep, import_dedent3, import_npmlog12, import_client, import_os2, DEFAULT_CONCURRENCY; var init_command = __esm({ "libs/core/src/lib/command/index.ts"() { "use strict"; import_clone_deep = __toESM(require("clone-deep")); import_dedent3 = __toESM(require("dedent")); import_npmlog12 = __toESM(require("npmlog")); import_client = require("nx/src/daemon/client/client"); import_os2 = __toESM(require("os")); init_project(); init_validation_error(); init_write_log_file(); init_clean_stack(); init_default_options(); init_detect_projects(); init_is_git_initialized(); init_log_package_error(); init_warn_if_hanging(); DEFAULT_CONCURRENCY = import_os2.default.cpus().length; } }); // libs/core/src/lib/conventional-commits/apply-build-metadata.ts function applyBuildMetadata(version, buildMetadata) { if (!buildMetadata) { return version; } if (isValidBuildMetadata(buildMetadata)) { return `${version}+${buildMetadata}`; } throw new ValidationError("EBUILDMETADATA", "Build metadata does not satisfy SemVer specification."); } function isValidBuildMetadata(buildMetadata) { return BUILD_METADATA_REGEX.test(buildMetadata); } var BUILD_METADATA_REGEX; var init_apply_build_metadata = __esm({ "libs/core/src/lib/conventional-commits/apply-build-metadata.ts"() { "use strict"; init_validation_error(); BUILD_METADATA_REGEX = /^[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*$/; } }); // libs/core/src/lib/conventional-commits/get-changelog-config.ts var import_npm_package_arg3, import_npmlog13, import_pify; var init_get_changelog_config = __esm({ "libs/core/src/lib/conventional-commits/get-changelog-config.ts"() { "use strict"; import_npm_package_arg3 = __toESM(require("npm-package-arg")); import_npmlog13 = __toESM(require("npmlog")); import_pify = __toESM(require("pify")); init_validation_error(); } }); // libs/core/src/lib/conventional-commits/recommend-version.ts var import_conventional_recommended_bump, import_npmlog14, import_semver3; var init_recommend_version = __esm({ "libs/core/src/lib/conventional-commits/recommend-version.ts"() { "use strict"; import_conventional_recommended_bump = __toESM(require("conventional-recommended-bump")); import_npmlog14 = __toESM(require("npmlog")); import_semver3 = __toESM(require("semver")); init_apply_build_metadata(); init_get_changelog_config(); } }); // libs/core/src/lib/conventional-commits/constants.ts var EOL, BLANK_LINE, COMMIT_GUIDELINE, CHANGELOG_HEADER; var init_constants = __esm({ "libs/core/src/lib/conventional-commits/constants.ts"() { "use strict"; EOL = "\n"; BLANK_LINE = EOL + EOL; COMMIT_GUIDELINE = "See [Conventional Commits](https://conventionalcommits.org) for commit guidelines."; CHANGELOG_HEADER = [ "# Change Log", "", "All notable changes to this project will be documented in this file.", COMMIT_GUIDELINE ].join(EOL); } }); // libs/core/src/lib/conventional-commits/make-bump-only-filter.ts var init_make_bump_only_filter = __esm({ "libs/core/src/lib/conventional-commits/make-bump-only-filter.ts"() { "use strict"; init_constants(); } }); // libs/core/src/lib/conventional-commits/read-existing-changelog.ts var import_fs_extra2; var init_read_existing_changelog = __esm({ "libs/core/src/lib/conventional-commits/read-existing-changelog.ts"() { "use strict"; import_fs_extra2 = __toESM(require("fs-extra")); init_constants(); } }); // libs/core/src/lib/conventional-commits/update-changelog.ts var import_conventional_changelog_core, import_fs_extra3, import_get_stream, import_npmlog15; var init_update_changelog = __esm({ "libs/core/src/lib/conventional-commits/update-changelog.ts"() { "use strict"; import_conventional_changelog_core = __toESM(require("conventional-changelog-core")); import_fs_extra3 = __toESM(require("fs-extra")); import_get_stream = __toESM(require("get-stream")); import_npmlog15 = __toESM(require("npmlog")); init_constants(); init_get_changelog_config(); init_make_bump_only_filter(); init_read_existing_changelog(); } }); // libs/core/src/lib/conventional-commits/index.ts var init_conventional_commits = __esm({ "libs/core/src/lib/conventional-commits/index.ts"() { "use strict"; init_recommend_version(); init_update_changelog(); init_apply_build_metadata(); } }); // libs/core/src/lib/corepack/is-corepack-enabled.ts var init_is_corepack_enabled = __esm({ "libs/core/src/lib/corepack/is-corepack-enabled.ts"() { "use strict"; } }); // libs/core/src/lib/corepack/exec-package-manager.ts var childProcess5; var init_exec_package_manager = __esm({ "libs/core/src/lib/corepack/exec-package-manager.ts"() { "use strict"; init_is_corepack_enabled(); childProcess5 = (init_src(), __toCommonJS(src_exports)); } }); // libs/core/src/lib/corepack/index.ts var init_corepack = __esm({ "libs/core/src/lib/corepack/index.ts"() { "use strict"; init_exec_package_manager(); } }); // libs/core/src/lib/filter-options.ts var import_dedent4, import_npmlog16; var init_filter_options = __esm({ "libs/core/src/lib/filter-options.ts"() { "use strict"; import_dedent4 = __toESM(require("dedent")); import_npmlog16 = __toESM(require("npmlog")); } }); // libs/core/src/lib/filter-projects.ts var import_multimatch, import_npmlog17; var init_filter_projects = __esm({ "libs/core/src/lib/filter-projects.ts"() { "use strict"; import_multimatch = __toESM(require("multimatch")); import_npmlog17 = __toESM(require("npmlog")); init_add_dependencies(); init_add_dependents(); init_collect_project_updates(); init_validation_error(); } }); // libs/core/src/lib/git-checkout.ts var import_npmlog18, childProcess6; var init_git_checkout = __esm({ "libs/core/src/lib/git-checkout.ts"() { "use strict"; import_npmlog18 = __toESM(require("npmlog")); childProcess6 = (init_src(), __toCommonJS(src_exports)); } }); // libs/core/src/lib/has-npm-version.ts var import_semver4, childProcess7; var init_has_npm_version = __esm({ "libs/core/src/lib/has-npm-version.ts"() { "use strict"; import_semver4 = __toESM(require("semver")); childProcess7 = (init_src(), __toCommonJS(src_exports)); } }); // libs/core/src/lib/cycles/get-cycles.ts var init_get_cycles = __esm({ "libs/core/src/lib/cycles/get-cycles.ts"() { "use strict"; } }); // libs/core/src/lib/cycles/merge-overlapping-cycles.ts var import_lodash4; var init_merge_overlapping_cycles = __esm({ "libs/core/src/lib/cycles/merge-overlapping-cycles.ts"() { "use strict"; import_lodash4 = require("lodash"); } }); // libs/core/src/lib/cycles/report-cycles.ts var import_npmlog19; var init_report_cycles = __esm({ "libs/core/src/lib/cycles/report-cycles.ts"() { "use strict"; import_npmlog19 = __toESM(require("npmlog")); init_validation_error(); } }); // libs/core/src/lib/cycles/index.ts var init_cycles = __esm({ "libs/core/src/lib/cycles/index.ts"() { "use strict"; init_get_cycles(); init_merge_overlapping_cycles(); init_report_cycles(); } }); // libs/core/src/lib/toposort-projects.ts var import_lodash5; var init_toposort_projects = __esm({ "libs/core/src/lib/toposort-projects.ts"() { "use strict"; import_lodash5 = require("lodash"); init_cycles(); } }); // libs/core/src/lib/listable-format-projects.ts var import_chalk3, import_columnify; var init_listable_format_projects = __esm({ "libs/core/src/lib/listable-format-projects.ts"() { "use strict"; import_chalk3 = __toESM(require("chalk")); import_columnify = __toESM(require("columnify")); init_project_graph_with_packages(); init_toposort_projects(); } }); // libs/core/src/lib/listable-options.ts var init_listable_options = __esm({ "libs/core/src/lib/listable-options.ts"() { "use strict"; } }); // libs/core/src/lib/log-packed.ts var import_byte_size, import_columnify2, import_npmlog20, import_has_unicode, hasUnicode; var init_log_packed = __esm({ "libs/core/src/lib/log-packed.ts"() { "use strict"; import_byte_size = __toESM(require("byte-size")); import_columnify2 = __toESM(require("columnify")); import_npmlog20 = __toESM(require("npmlog")); import_has_unicode = __toESM(require("has-unicode")); hasUnicode = (0, import_has_unicode.default)(); } }); // libs/core/src/lib/npm-conf/env-replace.ts function envReplace(str) { if (typeof str !== "string" || !str) { return str; } const regex = /(\\*)\$\{([^}]+)\}/g; return str.replace(regex, (orig, esc, name) => { esc = esc.length > 0 && esc.length % 2; if (esc) { return orig; } if (process.env[name] === void 0) { throw new Error(`Failed to replace env in config: ${orig}`); } return process.env[name]; }); } var init_env_replace = __esm({ "libs/core/src/lib/npm-conf/env-replace.ts"() { "use strict"; } }); // libs/core/src/lib/npm-conf/find-prefix.ts function findPrefix(start) { let dir = import_path5.default.resolve(start); let walkedUp = false; while (import_path5.default.basename(dir) === "node_modules") { dir = import_path5.default.dirname(dir); walkedUp = true; } if (walkedUp) { return dir; } return find(dir, dir); } function find(name, original) { if (name === "/" || process.platform === "win32" && /^[a-zA-Z]:(\\|\/)?$/.test(name)) { return original; } try { const files = import_fs3.default.readdirSync(name); if (files.indexOf("node_modules") !== -1 || files.indexOf("package.json") !== -1) { return name; } const dirname = import_path5.default.dirname(name); if (dirname === name) { return original; } return find(dirname, original); } catch (err) { if (name === original) { if (err.code === "ENOENT") { return original; } throw err; } return original; } } var import_fs3, import_path5; var init_find_prefix = __esm({ "libs/core/src/lib/npm-conf/find-prefix.ts"() { "use strict"; import_fs3 = __toESM(require("fs")); import_path5 = __toESM(require("path")); } }); // libs/core/src/lib/npm-conf/types.ts var require_types = __commonJS({ "libs/core/src/lib/npm-conf/types.ts"(exports2) { "use strict"; var import_path9 = __toESM(require("path")); var import_stream = require("stream"); var import_url2 = __toESM(require("url")); var Umask = () => { }; var getLocalAddresses = () => []; var semver5 = () => { }; exports2.types = { access: [null, "restricted", "public"], "allow-same-version": Boolean, "always-auth": Boolean, also: [null, "dev", "development"], audit: Boolean, "audit-level": ["low", "moderate", "high", "critical"], "auth-type": ["legacy", "sso", "saml", "oauth"], "bin-links": Boolean, browser: [null, String], ca: [null, String, Array], cafile: import_path9.default, cache: import_path9.default, "cache-lock-stale": Number, "cache-lock-retries": Number, "cache-lock-wait": Number, "cache-max": Number, "cache-min": Number, cert: [null, String], cidr: [null, String, Array], color: ["always", Boolean], depth: Number, description: Boolean, dev: Boolean, "dry-run": Boolean, editor: String, "engine-strict": Boolean, force: Boolean, "fetch-retries": Number, "fetch-retry-factor": Numb