@lerna/project
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.9
@@ -6,2 +6,15 @@ # Change Log | ||
<a name="3.0.0-beta.9"></a> | ||
# [3.0.0-beta.9](https://github.com/lerna/lerna/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2018-03-24) | ||
### Features | ||
* **project:** Normalize config.commands -> config.command ([24e55e3](https://github.com/lerna/lerna/commit/24e55e3)) | ||
* **project:** Use cosmiconfig to locate and read lerna.json ([b8c2789](https://github.com/lerna/lerna/commit/b8c2789)) | ||
<a name="3.0.0-beta.1"></a> | ||
@@ -8,0 +21,0 @@ # [3.0.0-beta.1](https://github.com/lerna/lerna/compare/v3.0.0-beta.0...v3.0.0-beta.1) (2018-03-09) |
80
index.js
"use strict"; | ||
const cosmiconfig = require("cosmiconfig"); | ||
const dedent = require("dedent"); | ||
const findUp = require("find-up"); | ||
const globParent = require("glob-parent"); | ||
@@ -9,2 +9,3 @@ const loadJsonFile = require("load-json-file"); | ||
const path = require("path"); | ||
const writeJsonFile = require("write-json-file"); | ||
@@ -18,39 +19,56 @@ const ValidationError = require("@lerna/validation-error"); | ||
constructor(cwd) { | ||
const lernaJsonLocation = | ||
// findUp returns null when not found | ||
findUp.sync("lerna.json", { cwd }) || | ||
// path.resolve(".", ...) starts from process.cwd() | ||
path.resolve(cwd || ".", "lerna.json"); | ||
const explorer = cosmiconfig("lerna", { | ||
js: false, // not unless we store version somewhere else... | ||
rc: "lerna.json", | ||
rcStrictJson: true, | ||
sync: true, | ||
transform: obj => { | ||
// normalize command-specific config namespace | ||
if (obj.config.commands) { | ||
obj.config.command = obj.config.commands; | ||
delete obj.config.commands; | ||
} | ||
this.rootPath = path.dirname(lernaJsonLocation); | ||
log.verbose("rootPath", this.rootPath); | ||
return obj; | ||
}, | ||
}); | ||
this.lernaJsonLocation = lernaJsonLocation; | ||
this.packageJsonLocation = path.join(this.rootPath, "package.json"); | ||
} | ||
let loaded; | ||
get lernaJson() { | ||
if (!this._lernaJson) { | ||
try { | ||
this._lernaJson = loadJsonFile.sync(this.lernaJsonLocation); | ||
} catch (err) { | ||
// don't swallow syntax errors | ||
if (err.name === "JSONError") { | ||
throw new ValidationError(err.name, err.message); | ||
} | ||
// No need to distinguish between missing and empty, | ||
// saves a lot of noisy guards elsewhere | ||
this._lernaJson = {}; | ||
try { | ||
loaded = explorer.load(cwd); | ||
} catch (err) { | ||
// don't swallow syntax errors | ||
if (err.name === "JSONError") { | ||
throw new ValidationError(err.name, err.message); | ||
} | ||
} | ||
return this._lernaJson; | ||
// cosmiconfig returns null when nothing is found | ||
loaded = loaded || { | ||
// No need to distinguish between missing and empty, | ||
// saves a lot of noisy guards elsewhere | ||
config: {}, | ||
// path.resolve(".", ...) starts from process.cwd() | ||
filepath: path.resolve(cwd || ".", "lerna.json"), | ||
}; | ||
this.config = loaded.config; | ||
this.rootPath = path.dirname(loaded.filepath); | ||
log.verbose("rootPath", this.rootPath); | ||
this.lernaConfigLocation = loaded.filepath; | ||
this.packageJsonLocation = path.join(this.rootPath, "package.json"); | ||
} | ||
get version() { | ||
return this.lernaJson.version; | ||
return this.config.version; | ||
} | ||
set version(val) { | ||
this.config.version = val; | ||
} | ||
get packageConfigs() { | ||
if (this.lernaJson.useWorkspaces) { | ||
if (this.config.useWorkspaces) { | ||
if (!this.packageJson.workspaces) { | ||
@@ -68,3 +86,4 @@ throw new ValidationError( | ||
} | ||
return this.lernaJson.packages || [DEFAULT_PACKAGE_GLOB]; | ||
return this.config.packages || [DEFAULT_PACKAGE_GLOB]; | ||
} | ||
@@ -109,4 +128,11 @@ | ||
} | ||
serializeConfig() { | ||
// TODO: might be package.json prop | ||
return writeJsonFile(this.lernaConfigLocation, this.config, { indent: 2, detectIndent: true }).then( | ||
() => this.lernaConfigLocation | ||
); | ||
} | ||
} | ||
module.exports = Project; |
{ | ||
"name": "@lerna/project", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.9", | ||
"description": "TODO", | ||
@@ -35,9 +35,10 @@ "keywords": [ | ||
"@lerna/validation-error": "^3.0.0-beta.0", | ||
"cosmiconfig": "^4.0.0", | ||
"dedent": "^0.7.0", | ||
"find-up": "^2.1.0", | ||
"glob-parent": "^3.1.0", | ||
"load-json-file": "^4.0.0", | ||
"npmlog": "^4.1.2" | ||
"npmlog": "^4.1.2", | ||
"write-json-file": "^2.3.0" | ||
}, | ||
"gitHead": "5a527968bb9f7b7c3af0d5d86391d6d2650ddc7a" | ||
"gitHead": "70528f23cad0186fdf7529fe32148cc1eff21272" | ||
} |
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
5459
110
8
+ Addedcosmiconfig@^4.0.0
+ Addedwrite-json-file@^2.3.0
+ Addedargparse@1.0.10(transitive)
+ Addedcosmiconfig@4.0.0(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedis-directory@0.3.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedsprintf-js@1.0.3(transitive)
- Removedfind-up@^2.1.0
- Removedfind-up@2.1.0(transitive)
- Removedlocate-path@2.0.0(transitive)
- Removedp-limit@1.3.0(transitive)
- Removedp-locate@2.0.0(transitive)
- Removedp-try@1.0.0(transitive)
- Removedpath-exists@3.0.0(transitive)