@boost/common
Advanced tools
Comparing version 2.4.1 to 2.5.0
@@ -6,2 +6,14 @@ # Change Log | ||
## 2.5.0 - 2021-01-16 | ||
#### 🚀 Updates | ||
- Migrate to Packemon for package building. (#135) ([1a0e9d8](https://github.com/milesj/boost/commit/1a0e9d8)), closes [#135](https://github.com/milesj/boost/issues/135) | ||
**Note:** Version bump only for package @boost/common | ||
### 2.4.1 - 2020-11-29 | ||
@@ -8,0 +20,0 @@ |
325
lib/index.js
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var optimal = require('optimal'); | ||
var internal = require('@boost/internal'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var glob = require('fast-glob'); | ||
var decorators = require('@boost/decorators'); | ||
var JSON = require('json5'); | ||
var YAML = require('yaml'); | ||
var prettyMs = require('pretty-ms'); | ||
var module$1 = require('module'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function _interopDefaultLegacy(e) { | ||
return e && typeof e === 'object' && 'default' in e ? e : { | ||
'default': e | ||
}; | ||
} | ||
var optimal__default = /*#__PURE__*/_interopDefaultLegacy(optimal); | ||
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs); | ||
var path__default = /*#__PURE__*/_interopDefaultLegacy(path); | ||
var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob); | ||
var JSON__default = /*#__PURE__*/_interopDefaultLegacy(JSON); | ||
var YAML__default = /*#__PURE__*/_interopDefaultLegacy(YAML); | ||
var prettyMs__default = /*#__PURE__*/_interopDefaultLegacy(prettyMs); | ||
var optimal__default = _interopDefaultLegacy(optimal); | ||
var fs__default = _interopDefaultLegacy(fs); | ||
var path__default = _interopDefaultLegacy(path); | ||
var glob__default = _interopDefaultLegacy(glob); | ||
var JSON__default = _interopDefaultLegacy(JSON); | ||
var YAML__default = _interopDefaultLegacy(YAML); | ||
var prettyMs__default = _interopDefaultLegacy(prettyMs); | ||
const errors = { | ||
@@ -39,14 +60,5 @@ PARSE_INVALID_EXT: 'Unable to parse file "{0}". Unsupported file extension.', | ||
} | ||
/** | ||
* Set an options object by merging the new partial and existing options | ||
* with the defined blueprint, while running all validation checks. | ||
* Freeze and return the options object. | ||
*/ | ||
configure(options) { | ||
const nextOptions = typeof options === 'function' ? options(this.options) : options; // We don't want the options property to be modified directly, | ||
// so it's read only, but we still want to modify it with this function. | ||
// @ts-expect-error | ||
const nextOptions = typeof options === 'function' ? options(this.options) : options; | ||
this.options = Object.freeze(optimal__default['default']({ ...this.options, | ||
@@ -59,8 +71,3 @@ ...nextOptions | ||
} | ||
/** | ||
* Define an optimal blueprint in which to validate and build the | ||
* options object passed to the constructor, or when manual setting. | ||
*/ | ||
} | ||
@@ -78,3 +85,2 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
class Node { | ||
@@ -97,25 +103,13 @@ constructor(name) { | ||
} | ||
/** | ||
* Add a package by name with an associated `package.json` object. | ||
* Will map a dependency between the package and its dependees | ||
* found in `dependencies` and `peerDependencies`. | ||
*/ | ||
addPackage(pkg) { | ||
if (this.mapped) { | ||
this.resetNodes(); | ||
} // Cache package data for later use | ||
} | ||
this.packages.set(pkg.name, pkg); // Add node to the graph | ||
this.packages.set(pkg.name, pkg); | ||
this.addNode(pkg.name); | ||
return this; | ||
} | ||
/** | ||
* Add multiple packages. | ||
*/ | ||
addPackages(packages = []) { | ||
@@ -127,8 +121,3 @@ packages.forEach(pkg => { | ||
} | ||
/** | ||
* Resolve the dependency graph and return a list of all | ||
* `package.json` objects in the order they are depended on. | ||
*/ | ||
resolveList() { | ||
@@ -140,8 +129,3 @@ return this.resolveBatchList().reduce((flatList, batchList) => { | ||
} | ||
/** | ||
* Resolve the dependency graph and return a tree of nodes for all | ||
* `package.json` objects and their dependency mappings. | ||
*/ | ||
resolveTree() { | ||
@@ -154,5 +138,4 @@ this.mapDependencies(); | ||
return; | ||
} // Only include nodes that have package data | ||
} | ||
const pkg = this.packages.get(node.name); | ||
@@ -174,3 +157,2 @@ | ||
} else { | ||
// eslint-disable-next-line no-param-reassign | ||
tree.nodes = [branch]; | ||
@@ -188,3 +170,3 @@ } | ||
resolve(node, trunk); | ||
}); // Some nodes are missing, so they must be a cycle | ||
}); | ||
@@ -197,8 +179,3 @@ if (seen.size !== this.nodes.size) { | ||
} | ||
/** | ||
* Resolve the dependency graph and return a list of batched | ||
* `package.json` objects in the order they are depended on. | ||
*/ | ||
resolveBatchList() { | ||
@@ -210,5 +187,3 @@ this.mapDependencies(); | ||
const addBatch = () => { | ||
const nextBatch = Array.from(this.nodes.values()).filter(node => { | ||
return !seen.has(node) && (node.requirements.size === 0 || Array.from(node.requirements.values()).filter(dep => !seen.has(dep)).length === 0); | ||
}); // Some nodes are missing, so they must be a cycle | ||
const nextBatch = Array.from(this.nodes.values()).filter(node => !seen.has(node) && (node.requirements.size === 0 || Array.from(node.requirements.values()).filter(dep => !seen.has(dep)).length === 0)); | ||
@@ -230,16 +205,7 @@ if (nextBatch.length === 0) { | ||
} | ||
/** | ||
* Add a node for the defined package name. | ||
*/ | ||
addNode(name) { | ||
// Cache node for constant lookups | ||
this.nodes.set(name, new Node(name)); | ||
} | ||
/** | ||
* Dig through all nodes and attempt to find a circular dependency cycle. | ||
*/ | ||
detectCycle() { | ||
@@ -262,8 +228,3 @@ const dig = (node, cycle) => { | ||
} | ||
/** | ||
* Return all nodes that can be considered "root", | ||
* as determined by having no requirements. | ||
*/ | ||
getRootNodes() { | ||
@@ -275,3 +236,3 @@ const rootNodes = []; | ||
} | ||
}); // If no root nodes are found, but nodes exist, then we have a cycle | ||
}); | ||
@@ -284,7 +245,3 @@ if (rootNodes.length === 0 && this.nodes.size !== 0) { | ||
} | ||
/** | ||
* Map dependencies between all currently registered packages. | ||
*/ | ||
mapDependencies() { | ||
@@ -304,9 +261,3 @@ if (this.mapped) { | ||
} | ||
/** | ||
* Map a dependency link for a dependent (child) depending on a requirement (parent). | ||
* Will link the parent and child accordingly, and will remove the child | ||
* from the root if it exists. | ||
*/ | ||
mapDependency(dependentName, requirementName) { | ||
@@ -318,14 +269,8 @@ const requirement = this.nodes.get(requirementName); | ||
return; | ||
} // Child depends on parent | ||
} | ||
dependent.requirements.add(requirement); // Parent is a dependee of child | ||
dependent.requirements.add(requirement); | ||
requirement.dependents.add(dependent); | ||
} | ||
/** | ||
* Remove all current nodes in the graph and add new root nodes for each package. | ||
*/ | ||
resetNodes() { | ||
@@ -338,7 +283,3 @@ this.mapped = false; | ||
} | ||
/** | ||
* Sort a set of nodes by most depended on, fall back to alpha sort as tie breaker | ||
*/ | ||
sortByDependedOn(nodes) { | ||
@@ -361,44 +302,21 @@ return Array.from(nodes).sort((a, b) => { | ||
this.internalPath = ''; | ||
// Always use forward slashes for better interop | ||
this.internalPath = path__default['default'].normalize(path__default['default'].join(...parts.map(String))).replace(/\\/gu, Path.SEP); | ||
} | ||
/** | ||
* Create and return a new `Path` instance if a string. | ||
* If already a `Path`, return as is. | ||
*/ | ||
static create(filePath) { | ||
return filePath instanceof Path ? filePath : new Path(filePath); | ||
} | ||
/** | ||
* Like `create()` but also resolves the path against CWD. | ||
*/ | ||
static resolve(filePath, cwd) { | ||
return Path.create(filePath).resolve(cwd); | ||
} | ||
/** | ||
* Append path parts to the end of the current path | ||
* and return a new `Path` instance. | ||
*/ | ||
append(...parts) { | ||
return new Path(this.internalPath, ...parts); | ||
} | ||
/** | ||
* Returns true if both paths are equal using strict equality. | ||
*/ | ||
equals(filePath) { | ||
return this.path() === Path.create(filePath).path(); | ||
} | ||
/** | ||
* Return the extension (if applicable) with or without leading period. | ||
*/ | ||
ext(withoutPeriod = false) { | ||
@@ -408,39 +326,19 @@ const ext = path__default['default'].extname(this.internalPath); | ||
} | ||
/** | ||
* Return true if the current path exists. | ||
*/ | ||
exists() { | ||
return fs__default['default'].existsSync(this.internalPath); | ||
} | ||
/** | ||
* Return true if the current path is absolute. | ||
*/ | ||
isAbsolute() { | ||
return path__default['default'].isAbsolute(this.internalPath); | ||
} | ||
/** | ||
* Return true if the current path is a folder. | ||
*/ | ||
isDirectory() { | ||
return fs__default['default'].statSync(this.internalPath).isDirectory(); | ||
} | ||
/** | ||
* Return true if the current path is a file. | ||
*/ | ||
isFile() { | ||
return fs__default['default'].statSync(this.internalPath).isFile(); | ||
} | ||
/** | ||
* Return the file name (with optional extension) or folder name. | ||
*/ | ||
name(withoutExtension = false) { | ||
@@ -455,51 +353,23 @@ let name = path__default['default'].basename(this.internalPath); | ||
} | ||
/** | ||
* Return the parent folder as a new `Path` instance. | ||
*/ | ||
parent() { | ||
return new Path(path__default['default'].dirname(this.internalPath)); | ||
} | ||
/** | ||
* Return the current path as a normalized string. | ||
*/ | ||
path() { | ||
return this.internalPath; | ||
} | ||
/** | ||
* Prepend path parts to the beginning of the current path | ||
* and return a new `Path` instance. | ||
*/ | ||
prepend(...parts) { | ||
return new Path(...parts, this.internalPath); | ||
} | ||
/** | ||
* Returns a canonical path by resolving directories and symlinks. | ||
*/ | ||
// istanbul ignore next | ||
realPath() { | ||
return fs__default['default'].realpathSync.native(this.path()); | ||
} | ||
/** | ||
* Return a new relative `Path` instance from the current | ||
* "from" path to the defined "to" path. | ||
*/ | ||
relativeTo(to) { | ||
return new Path(path__default['default'].relative(this.path(), String(to))); | ||
} | ||
/** | ||
* Return a new `Path` instance where the current path is accurately | ||
* resolved against the defined current working directory. | ||
*/ | ||
resolve(cwd) { | ||
@@ -518,7 +388,6 @@ return new Path(path__default['default'].resolve(String(cwd || process.cwd()), this.internalPath)); | ||
} | ||
Path.DELIMITER = path__default['default'].delimiter; | ||
Path.SEP = '/'; | ||
// NODE | ||
(function (LookupType) { | ||
@@ -534,14 +403,6 @@ LookupType["FILE_SYSTEM"] = "FILE_SYSTEM"; | ||
/** | ||
* Return a list of all lookup paths. | ||
*/ | ||
getLookupPaths() { | ||
return this.lookups.map(lookup => lookup.path.path()); | ||
} | ||
/** | ||
* Add a file system path to look for, resolved against the defined current | ||
* working directory (or `process.cwd()` otherwise). | ||
*/ | ||
lookupFilePath(filePath, cwd) { | ||
@@ -555,7 +416,3 @@ this.lookups.push({ | ||
} | ||
/** | ||
* Add a Node.js module, either by name or relative path, to look for. | ||
*/ | ||
lookupNodeModule(modulePath) { | ||
@@ -570,9 +427,3 @@ const path = Path.create(modulePath); | ||
} | ||
/** | ||
* Given a list of lookups, attempt to find the first real/existing path and | ||
* return a resolved absolute path. If a file system path, will check using `fs.exists`. | ||
* If a node module path, will check using `require.resolve`. | ||
*/ | ||
resolve() { | ||
@@ -582,3 +433,2 @@ let resolvedPath = ''; | ||
this.lookups.some(lookup => { | ||
// Check that the file exists on the file system. | ||
if (lookup.type === exports.LookupType.FILE_SYSTEM) { | ||
@@ -590,5 +440,3 @@ if (lookup.path.exists()) { | ||
return false; | ||
} // Check that the module path exists using Node's module resolution. | ||
// The `require.resolve` function will throw an error if not found. | ||
} | ||
} else if (lookup.type === exports.LookupType.NODE_MODULE) { | ||
@@ -616,7 +464,3 @@ try { | ||
} | ||
/** | ||
* Like `resolve()` but only returns the resolved path. | ||
*/ | ||
resolvePath() { | ||
@@ -657,20 +501,6 @@ return this.resolve().resolvedPath; | ||
function requireModule(path) { | ||
var _value; | ||
// eslint-disable-next-line | ||
let value = require(String(path)); // Support Babel compiled files | ||
// eslint-disable-next-line no-underscore-dangle | ||
if ((_value = value) != null && _value.__esModule) { | ||
value = value.default; | ||
} | ||
return value; | ||
} | ||
function parse(content, reviver) { | ||
return JSON__default['default'].parse(content, reviver); | ||
} | ||
function stringify(content, options) { | ||
@@ -680,3 +510,3 @@ return JSON__default['default'].stringify(content, options); | ||
var json = /*#__PURE__*/Object.freeze({ | ||
var json = Object.freeze({ | ||
__proto__: null, | ||
@@ -690,2 +520,3 @@ parse: parse, | ||
} | ||
function stringify$1(content, options) { | ||
@@ -695,3 +526,3 @@ return YAML__default['default'].stringify(content, options); | ||
var yaml = /*#__PURE__*/Object.freeze({ | ||
var yaml = Object.freeze({ | ||
__proto__: null, | ||
@@ -702,2 +533,14 @@ parse: parse$1, | ||
function requireModule(path) { | ||
var _value; | ||
let value = require(String(path)); | ||
if ((_value = value) != null && _value.__esModule) { | ||
value = value.default; | ||
} | ||
return value; | ||
} | ||
function parseFile(filePath) { | ||
@@ -729,2 +572,3 @@ const path = Path.create(filePath); | ||
var _dec, _dec2, _dec3, _class, _temp; | ||
let Project = (_dec = decorators.Memoize(), _dec2 = decorators.Memoize(), _dec3 = decorators.Memoize(), (_class = (_temp = class Project { | ||
@@ -735,7 +579,3 @@ constructor(root = process.cwd()) { | ||
} | ||
/** | ||
* Create a workspace metadata object composed of absolute file paths. | ||
*/ | ||
createWorkspaceMetadata(jsonPath) { | ||
@@ -753,7 +593,3 @@ const metadata = {}; | ||
} | ||
/** | ||
* Return the contents of the root `package.json`. | ||
*/ | ||
getPackage() { | ||
@@ -768,9 +604,3 @@ const pkgPath = this.root.append('package.json'); | ||
} | ||
/** | ||
* Return a list of all workspace globs as they are configured | ||
* in `package.json` or `lerna.json`. | ||
*/ | ||
// eslint-disable-next-line complexity | ||
getWorkspaceGlobs(options = {}) { | ||
@@ -780,3 +610,3 @@ const pkgPath = this.root.append('package.json'); | ||
const pnpmPath = this.root.append('pnpm-workspace.yaml'); | ||
const workspacePaths = []; // Yarn | ||
const workspacePaths = []; | ||
@@ -793,5 +623,4 @@ if (pkgPath.exists()) { | ||
} | ||
} // Lerna | ||
} | ||
if (workspacePaths.length === 0 && lernaPath.exists()) { | ||
@@ -803,5 +632,4 @@ const lerna = parseFile(lernaPath); | ||
} | ||
} // PNPM | ||
} | ||
if (workspacePaths.length === 0 && pnpmPath.exists()) { | ||
@@ -821,8 +649,3 @@ const pnpm = parseFile(pnpmPath); | ||
} | ||
/** | ||
* Return all `package.json`s across all workspaces and their packages. | ||
* Once loaded, append workspace path metadata. | ||
*/ | ||
getWorkspacePackages() { | ||
@@ -843,7 +666,3 @@ return glob__default['default'].sync(this.getWorkspaceGlobs({ | ||
} | ||
/** | ||
* Return a list of all workspace package paths, resolved against the file system. | ||
*/ | ||
getWorkspacePackagePaths(options = {}) { | ||
@@ -861,6 +680,3 @@ return glob__default['default'].sync(this.getWorkspaceGlobs({ | ||
}, _temp), (_applyDecoratedDescriptor(_class.prototype, "getWorkspaceGlobs", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "getWorkspaceGlobs"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "getWorkspacePackages", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "getWorkspacePackages"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "getWorkspacePackagePaths", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "getWorkspacePackagePaths"), _class.prototype)), _class)); | ||
// https://github.com/npm/validate-npm-package-name | ||
const MODULE_NAME_PART = /[a-z0-9]{1}[-a-z0-9_.]*/u; // eslint-disable-next-line security/detect-non-literal-regexp | ||
const MODULE_NAME_PART = /[a-z0-9]{1}[-a-z0-9_.]*/u; | ||
const MODULE_NAME_PATTERN = new RegExp(`^(?:@(${MODULE_NAME_PART.source})/)?(${MODULE_NAME_PART.source})$`, 'u'); | ||
@@ -883,3 +699,2 @@ | ||
Object.entries(obj).forEach(([key, value]) => { | ||
// Only freeze plain objects | ||
if (isObject(value) && value.constructor === Object) { | ||
@@ -932,7 +747,2 @@ nextObj[key] = deepFreeze(value); | ||
/** | ||
* Native `instanceof` checks are problematic, as cross realm checks fail. | ||
* They will also fail when comparing against source and built files. | ||
* So emulate an `instanceof` check by comparing constructor names. | ||
*/ | ||
function instanceOf(object, declaration, loose = true) { | ||
@@ -958,8 +768,6 @@ if (!object || typeof object !== 'object') { | ||
if (current.constructor.name === declaration.name || // istanbul ignore next | ||
current instanceof Error && current.name === declaration.name) { | ||
if (current.constructor.name === declaration.name || current instanceof Error && current.name === declaration.name) { | ||
return true; | ||
} // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
} | ||
current = Object.getPrototypeOf(current); | ||
@@ -977,2 +785,3 @@ } | ||
const WIN_START = /^([A-Z]:|\.)/u; | ||
function isFilePath(path) { | ||
@@ -983,5 +792,4 @@ const filePath = path instanceof Path ? path.path() : path; | ||
return false; | ||
} // istanbul ignore next | ||
} | ||
if (process.platform === 'win32') { | ||
@@ -995,2 +803,3 @@ return WIN_START.test(filePath) || filePath.includes('/') || filePath.includes('\\'); | ||
const RESERVED = new Set([...module$1.builtinModules, 'node_modules', 'favicon.ico']); | ||
function isModuleName(name) { | ||
@@ -997,0 +806,0 @@ if (RESERVED.has(name)) { |
{ | ||
"name": "@boost/common", | ||
"version": "2.4.1", | ||
"version": "2.5.0", | ||
"release": "1594765247526", | ||
@@ -13,7 +13,13 @@ "description": "A collection of common utilities, classes, and helpers.", | ||
"main": "./lib/index.js", | ||
"types": "./lib/index.d.ts", | ||
"types": "./dts/index.d.ts", | ||
"engines": { | ||
"node": ">=10.17.0" | ||
"node": ">=10.3.0", | ||
"npm": ">=6.1.0" | ||
}, | ||
"repository": "https://github.com/milesj/boost/tree/master/packages/common", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:milesj/boost.git", | ||
"directory": "packages/common" | ||
}, | ||
"author": "Miles Johnson", | ||
"license": "MIT", | ||
@@ -24,4 +30,4 @@ "publishConfig": { | ||
"dependencies": { | ||
"@boost/decorators": "^2.0.0", | ||
"@boost/internal": "^2.1.2", | ||
"@boost/decorators": "^2.1.0", | ||
"@boost/internal": "^2.2.0", | ||
"fast-glob": "^3.2.4", | ||
@@ -34,3 +40,3 @@ "json5": "^2.1.3", | ||
"devDependencies": { | ||
"@boost/test-utils": "^2.1.1" | ||
"@boost/test-utils": "^2.2.0" | ||
}, | ||
@@ -41,3 +47,6 @@ "funding": { | ||
}, | ||
"gitHead": "5f7e4dd672542eef29f55ec17300600e5fcd6a92" | ||
"packemon": { | ||
"platform": "node" | ||
}, | ||
"gitHead": "e2c452ee0c15aa7db91d1945e23ac6951028e672" | ||
} |
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
1
4
66102
1093
Updated@boost/decorators@^2.1.0
Updated@boost/internal@^2.2.0