-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project): Inherit configuration with yargs-like "extends"
Fixes #1281
- Loading branch information
Showing
19 changed files
with
243 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./circular.json", | ||
"loglevel": "warn" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./base.json", | ||
"loglevel": "error" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./circular.json", | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"packages": [ | ||
"base-pkgs/*" | ||
], | ||
"command": { | ||
"list": { | ||
"json": true | ||
} | ||
}, | ||
"version": "ignored" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./recursive.json", | ||
"version": "1.0.0" | ||
} |
11 changes: 11 additions & 0 deletions
11
core/project/__fixtures__/extends-recursive/recursive.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "./base.json", | ||
"packages": [ | ||
"recursive-pkgs/*" | ||
], | ||
"command": { | ||
"list": { | ||
"private": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "unresolved", | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "local-package", | ||
"version": "1.0.0" | ||
} |
5 changes: 5 additions & 0 deletions
5
core/project/__fixtures__/extends/node_modules/local-package/config.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
core/project/__fixtures__/extends/node_modules/local-package/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
core/project/__fixtures__/extends/node_modules/local-package/subpath.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "extends", | ||
"version": "0.0.0-root", | ||
"private": true, | ||
"devDependencies": { | ||
"local-package": "2.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "pkg-prop", | ||
"version": "0.0.0-root", | ||
"private": true, | ||
"lerna": { | ||
"loglevel": "success", | ||
"command": { | ||
"publish": { | ||
"loglevel": "verbose" | ||
} | ||
}, | ||
"version": "1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use strict"; | ||
|
||
const path = require("path"); | ||
const resolveFrom = require("resolve-from"); | ||
const ValidationError = require("@lerna/validation-error"); | ||
const shallowExtend = require("./shallow-extend"); | ||
|
||
module.exports = applyExtends; | ||
|
||
function applyExtends(config, cwd, seen = new Set()) { | ||
let defaultConfig = {}; | ||
|
||
if ("extends" in config) { | ||
let pathToDefault; | ||
|
||
try { | ||
pathToDefault = resolveFrom(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); | ||
|
||
// eslint-disable-next-line import/no-dynamic-require, global-require | ||
defaultConfig = require(pathToDefault); | ||
delete config.extends; // eslint-disable-line no-param-reassign | ||
|
||
defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault), seen); | ||
} | ||
|
||
return shallowExtend(config, defaultConfig); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use strict"; | ||
|
||
module.exports = shallowExtend; | ||
|
||
function shallowExtend(json, defaults = {}) { | ||
return Object.keys(json).reduce((obj, key) => { | ||
const val = json[key]; | ||
|
||
if (Array.isArray(val)) { | ||
// always clobber arrays, merging isn't worth unexpected complexity | ||
obj[key] = val.slice(); | ||
} else if (val && typeof val === "object") { | ||
obj[key] = shallowExtend(val, obj[key]); | ||
} else { | ||
obj[key] = val; | ||
} | ||
|
||
return obj; | ||
}, defaults); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.