@lerna/package
Advanced tools
Comparing version 3.16.0 to 4.0.0
@@ -6,2 +6,38 @@ # Change Log | ||
# [4.0.0](https://github.com/lerna/lerna/compare/v3.22.1...v4.0.0) (2021-02-10) | ||
### Code Refactoring | ||
* **package:** Move Package.lazy() to static method ([e52108e](https://github.com/lerna/lerna/commit/e52108e308192150e1d5e21f3a23c9e91f87d4b7)) | ||
### Features | ||
* **package:** Improve JSDoc-inferred types, encapsulation ([4d80c38](https://github.com/lerna/lerna/commit/4d80c3832cf2a1cceb31e535fa841db4c68a7346)) | ||
* Consume named exports of sibling modules ([63499e3](https://github.com/lerna/lerna/commit/63499e33652bc78fe23751875d74017e2f16a689)) | ||
* Drop support for Node v6.x & v8.x ([ff4bb4d](https://github.com/lerna/lerna/commit/ff4bb4da215555e3bb136f5af09b5cbc631e57bb)) | ||
* Expose named export ([c1303f1](https://github.com/lerna/lerna/commit/c1303f13adc4cf15f96ff25889b52149f8224c0e)) | ||
* Remove default export ([e2f1ec3](https://github.com/lerna/lerna/commit/e2f1ec3dd049d2a89880029908a2aa7c66f15082)) | ||
* **deps:** load-json-file@^6.2.0 ([239f54b](https://github.com/lerna/lerna/commit/239f54b070691106dd9b31f2a279d726744651f8)) | ||
* **deps:** npm-package-arg@^8.1.0 ([12c8923](https://github.com/lerna/lerna/commit/12c892342d33b86a00ee2cf9079f9b26fe316dc6)) | ||
* **deps:** write-pkg@^4.0.0 ([34db21c](https://github.com/lerna/lerna/commit/34db21c8e344928d9ade36e191b337b74783c566)) | ||
### BREAKING CHANGES | ||
* The default export has been removed, please use a named export instead. | ||
* **package:** The `lazy` named export is now a proper static method of `Package`. | ||
* Node v6.x & v8.x are no longer supported. Please upgrade to the latest LTS release. | ||
Here's the gnarly one-liner I used to make these changes: | ||
``` | ||
npx lerna exec --concurrency 1 --stream -- 'json -I -f package.json -e '"'"'this.engines=this.engines||{};this.engines.node=">= 10.18.0"'"'" | ||
``` | ||
(requires `npm i -g json` beforehand) | ||
# [3.16.0](https://github.com/lerna/lerna/compare/v3.15.0...v3.16.0) (2019-07-18) | ||
@@ -8,0 +44,0 @@ |
211
index.js
@@ -11,2 +11,14 @@ "use strict"; | ||
/* eslint-disable no-underscore-dangle */ | ||
// private fields | ||
const _location = Symbol("location"); | ||
const _resolved = Symbol("resolved"); | ||
const _rootPath = Symbol("rootPath"); | ||
const _scripts = Symbol("scripts"); | ||
const _contents = Symbol("contents"); | ||
/** | ||
* @param {import("npm-package-arg").Result} result | ||
*/ | ||
function binSafeName({ name, scope }) { | ||
@@ -34,3 +46,50 @@ return scope ? name.substring(scope.length + 1) : name; | ||
/** | ||
* @typedef {object} RawManifest The subset of package.json properties that Lerna uses | ||
* @property {string} name | ||
* @property {string} version | ||
* @property {boolean} [private] | ||
* @property {Record<string, string>|string} [bin] | ||
* @property {Record<string, string>} [scripts] | ||
* @property {Record<string, string>} [dependencies] | ||
* @property {Record<string, string>} [devDependencies] | ||
* @property {Record<string, string>} [optionalDependencies] | ||
* @property {Record<string, string>} [peerDependencies] | ||
* @property {Record<'directory' | 'registry' | 'tag', string>} [publishConfig] | ||
* @property {string[] | { packages: string[] }} [workspaces] | ||
*/ | ||
/** | ||
* Lerna's internal representation of a local package, with | ||
* many values resolved directly from the original JSON. | ||
*/ | ||
class Package { | ||
/** | ||
* Create a Package instance from parameters, possibly reusing existing instance. | ||
* @param {string|Package|RawManifest} ref A path to a package.json file, Package instance, or JSON object | ||
* @param {string} [dir] If `ref` is a JSON object, this is the location of the manifest | ||
* @returns {Package} | ||
*/ | ||
static lazy(ref, dir = ".") { | ||
if (typeof ref === "string") { | ||
const location = path.resolve(path.basename(ref) === "package.json" ? path.dirname(ref) : ref); | ||
const manifest = loadJsonFile.sync(path.join(location, "package.json")); | ||
return new Package(manifest, location); | ||
} | ||
// don't use instanceof because it fails across nested module boundaries | ||
if ("__isLernaPackage" in ref) { | ||
return ref; | ||
} | ||
// assume ref is a json object | ||
return new Package(ref, dir); | ||
} | ||
/** | ||
* @param {RawManifest} pkg | ||
* @param {string} location | ||
* @param {string} [rootPath] | ||
*/ | ||
constructor(pkg, location, rootPath = location) { | ||
@@ -40,53 +99,62 @@ // npa will throw an error if the name is invalid | ||
Object.defineProperties(this, { | ||
// read-only | ||
name: { | ||
enumerable: true, | ||
value: pkg.name, | ||
}, | ||
location: { | ||
value: location, | ||
}, | ||
private: { | ||
value: Boolean(pkg.private), | ||
}, | ||
resolved: { | ||
value: resolved, | ||
}, | ||
rootPath: { | ||
value: rootPath, | ||
}, | ||
// internal state is "private" | ||
[PKG]: { | ||
configurable: true, | ||
value: pkg, | ||
}, | ||
// safer than instanceof across module boundaries | ||
__isLernaPackage: { | ||
value: true, | ||
}, | ||
// immutable | ||
bin: { | ||
value: | ||
typeof pkg.bin === "string" | ||
? { | ||
[binSafeName(resolved)]: pkg.bin, | ||
} | ||
: Object.assign({}, pkg.bin), | ||
}, | ||
scripts: { | ||
value: Object.assign({}, pkg.scripts), | ||
}, | ||
manifestLocation: { | ||
value: path.join(location, "package.json"), | ||
}, | ||
nodeModulesLocation: { | ||
value: path.join(location, "node_modules"), | ||
}, | ||
binLocation: { | ||
value: path.join(location, "node_modules", ".bin"), | ||
}, | ||
}); | ||
this.name = pkg.name; | ||
this[PKG] = pkg; | ||
// omit raw pkg from default util.inspect() output, but preserve internal mutability | ||
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); | ||
} | ||
get resolved() { | ||
return this[_resolved]; | ||
} | ||
get rootPath() { | ||
return this[_rootPath]; | ||
} | ||
get scripts() { | ||
return this[_scripts]; | ||
} | ||
get bin() { | ||
const pkg = this[PKG]; | ||
return typeof pkg.bin === "string" | ||
? { | ||
[binSafeName(this.resolved)]: pkg.bin, | ||
} | ||
: Object.assign({}, pkg.bin); | ||
} | ||
get binLocation() { | ||
return path.join(this.location, "node_modules", ".bin"); | ||
} | ||
get manifestLocation() { | ||
return path.join(this.location, "package.json"); | ||
} | ||
get nodeModulesLocation() { | ||
return path.join(this.location, "node_modules"); | ||
} | ||
// eslint-disable-next-line class-methods-use-this | ||
get __isLernaPackage() { | ||
// safer than instanceof across module boundaries | ||
return true; | ||
} | ||
// accessors | ||
@@ -103,4 +171,4 @@ get version() { | ||
// if modified with setter, use that value | ||
if (this._contents) { | ||
return this._contents; | ||
if (this[_contents]) { | ||
return this[_contents]; | ||
} | ||
@@ -118,5 +186,3 @@ | ||
set contents(subDirectory) { | ||
Object.defineProperty(this, "_contents", { | ||
value: path.join(this.location, subDirectory), | ||
}); | ||
this[_contents] = path.join(this.location, subDirectory); | ||
} | ||
@@ -143,4 +209,5 @@ | ||
* Map-like retrieval of arbitrary values | ||
* @param {String} key field name to retrieve value | ||
* @returns {Any} value stored under key, if present | ||
* @template {keyof RawManifest} K | ||
* @param {K} key field name to retrieve value | ||
* @returns {RawManifest[K]} value stored under key, if present | ||
*/ | ||
@@ -153,4 +220,5 @@ get(key) { | ||
* Map-like storage of arbitrary values | ||
* @param {String} key field name to store value | ||
* @param {Any} val value to store | ||
* @template {keyof RawManifest} K | ||
* @param {T} key field name to store value | ||
* @param {RawManifest[K]} val value to store | ||
* @returns {Package} instance for chaining | ||
@@ -176,7 +244,4 @@ */ | ||
refresh() { | ||
return loadJsonFile(this.manifestLocation).then(pkg => { | ||
// overwrite configurable property | ||
Object.defineProperty(this, PKG, { | ||
value: pkg, | ||
}); | ||
return loadJsonFile(this.manifestLocation).then((pkg) => { | ||
this[PKG] = pkg; | ||
@@ -241,20 +306,2 @@ return this; | ||
function lazy(ref, dir = ".") { | ||
if (typeof ref === "string") { | ||
const location = path.resolve(path.basename(ref) === "package.json" ? path.dirname(ref) : ref); | ||
const manifest = loadJsonFile.sync(path.join(location, "package.json")); | ||
return new Package(manifest, location); | ||
} | ||
// don't use instanceof because it fails across nested module boundaries | ||
if ("__isLernaPackage" in ref) { | ||
return ref; | ||
} | ||
// assume ref is a json object | ||
return new Package(ref, dir); | ||
} | ||
module.exports = Package; | ||
module.exports.lazy = lazy; | ||
module.exports.Package = Package; |
{ | ||
"name": "@lerna/package", | ||
"version": "3.16.0", | ||
"version": "4.0.0", | ||
"description": "Lerna's internal representation of a package", | ||
@@ -20,3 +20,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">= 6.9.0" | ||
"node": ">= 10.18.0" | ||
}, | ||
@@ -35,7 +35,7 @@ "publishConfig": { | ||
"dependencies": { | ||
"load-json-file": "^5.3.0", | ||
"npm-package-arg": "^6.1.0", | ||
"write-pkg": "^3.1.0" | ||
"load-json-file": "^6.2.0", | ||
"npm-package-arg": "^8.1.0", | ||
"write-pkg": "^4.0.0" | ||
}, | ||
"gitHead": "8ca18bedecf4f141c6242a099086e84b2ced72de" | ||
"gitHead": "4582c476e07dddddd6b2e3ab6e7f52c1f9eed59a" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16090
245
+ Added@babel/code-frame@7.24.7(transitive)
+ Added@babel/helper-validator-identifier@7.24.7(transitive)
+ Added@babel/highlight@7.24.7(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhosted-git-info@4.1.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjson-parse-even-better-errors@2.3.1(transitive)
+ Addedlines-and-columns@1.2.4(transitive)
+ Addedload-json-file@6.2.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addedmake-dir@2.1.0(transitive)
+ Addednpm-package-arg@8.1.5(transitive)
+ Addedparse-json@5.2.0(transitive)
+ Addedpicocolors@1.1.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedstrip-bom@4.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedtype-fest@0.4.10.6.0(transitive)
+ Addedwrite-json-file@3.2.0(transitive)
+ Addedwrite-pkg@4.0.0(transitive)
+ Addedyallist@4.0.0(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedjson-parse-better-errors@1.0.2(transitive)
- Removedload-json-file@5.3.0(transitive)
- Removedmake-dir@1.3.0(transitive)
- Removednpm-package-arg@6.1.1(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedosenv@0.1.5(transitive)
- Removedparse-json@4.0.0(transitive)
- Removedpify@3.0.0(transitive)
- Removedstrip-bom@3.0.0(transitive)
- Removedtype-fest@0.3.1(transitive)
- Removedwrite-json-file@2.3.0(transitive)
- Removedwrite-pkg@3.2.0(transitive)
Updatedload-json-file@^6.2.0
Updatednpm-package-arg@^8.1.0
Updatedwrite-pkg@^4.0.0