This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: loading/setting workspace-root config, implicit workspace
TODO: - warn when dropping other project configs if ws root is set - do not allow ws root to be set other than in project or workspace level Related-to: npm/cli#3596
- Loading branch information
Showing
4 changed files
with
329 additions
and
40 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,28 @@ | ||
const walkUp = require('walk-up-path') | ||
const { relative, resolve, dirname, join } = require('path') | ||
const { promisify } = require('util') | ||
const fs = require('fs') | ||
const stat = promisify(fs.stat) | ||
|
||
// starting from the start dir, walk up until we hit the first | ||
// folder with a node_modules or package.json. if none are found, | ||
// then return the start dir itself. | ||
module.exports = async (start, end = null) => { | ||
for (const p of walkUp(start)) { | ||
// walk up until we have a nm dir or a pj file | ||
const hasAny = (await Promise.all([ | ||
stat(resolve(p, 'node_modules')) | ||
.then(st => st.isDirectory()) | ||
.catch(() => false), | ||
stat(resolve(p, 'package.json')) | ||
.then(st => st.isFile()) | ||
.catch(() => false), | ||
])).some(is => is) | ||
if (hasAny) | ||
return p | ||
if (p === end) | ||
break | ||
} | ||
|
||
return start | ||
} |
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,20 @@ | ||
const t = require('tap') | ||
const findProjectDir = require('../lib/find-project-dir.js') | ||
const { resolve } = require('path') | ||
|
||
t.test('walk up, but do not pass end', async t => { | ||
const path = t.testdir({ | ||
hasnm: { | ||
node_modules: {}, | ||
a: { b: { c: {}}}, | ||
}, | ||
haspj: { | ||
'package.json': JSON.stringify({}), | ||
a: { b: { c: {}}}, | ||
}, | ||
}) | ||
t.equal(await findProjectDir(`${path}/hasnm/a/b/c`), resolve(path, 'hasnm')) | ||
t.equal(await findProjectDir(`${path}/haspj/a/b/c`), resolve(path, 'haspj')) | ||
t.equal(await findProjectDir(`${path}/haspj/a/b/c`, resolve(path, 'haspj/a')), | ||
resolve(path, 'haspj/a/b/c')) | ||
}) |
Oops, something went wrong.