New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better active directory selection #4246
Changes from 6 commits
04d1182
834f41f
ef1141b
ab89f32
a5f4929
716ec7f
b14d35e
e7e6b31
e7a6c4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,22 @@ test('--mutex network', async () => { | |
]); | ||
}); | ||
|
||
test('--cwd option', async () => { | ||
const cwd = await makeTemp(); | ||
const cacheFolder = path.join(cwd, '.cache'); | ||
|
||
const subdir = path.join(cwd, 'a/b/c/d/e/f/g/h/i'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're using |
||
await fs.mkdirp(subdir); | ||
|
||
const packageJsonPath = path.join(cwd, 'package.json'); | ||
await fs.writeFile(packageJsonPath, JSON.stringify({})); | ||
|
||
await runYarn(['add', 'left-pad'], {cwd: subdir}); | ||
|
||
const packageJson = JSON.parse(await fs.readFile(packageJsonPath)); | ||
expect(packageJson.dependencies['left-pad']).toBeDefined(); | ||
}); | ||
|
||
test('yarnrc binary path (js)', async () => { | ||
const cwd = await makeTemp(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,22 @@ const net = require('net'); | |
const onDeath = require('death'); | ||
const path = require('path'); | ||
|
||
function findActiveDirectory(base): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rename this to |
||
let prev = null; | ||
let dir = base; | ||
|
||
do { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be simplified as:
|
||
if (fs.existsSync(path.join(dir, constants.NODE_PACKAGE_JSON))) { | ||
return dir; | ||
} | ||
|
||
prev = dir; | ||
dir = path.dirname(dir); | ||
} while (dir !== prev); | ||
|
||
return base; | ||
} | ||
|
||
export function main({ | ||
startArgs, | ||
args, | ||
|
@@ -337,8 +353,12 @@ export function main({ | |
return reporter.close(); | ||
}; | ||
|
||
const cwd = findActiveDirectory(commander.cwd); | ||
|
||
config | ||
.init({ | ||
cwd, | ||
|
||
binLinks: commander.binLinks, | ||
modulesFolder: commander.modulesFolder, | ||
globalFolder: commander.globalFolder, | ||
|
@@ -358,7 +378,6 @@ export function main({ | |
networkTimeout: commander.networkTimeout, | ||
nonInteractive: commander.nonInteractive, | ||
scriptsPrependNodePath: commander.scriptsPrependNodePath, | ||
cwd: commander.cwd, | ||
|
||
commandName: commandName === 'run' ? commander.args[0] : commandName, | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not run in a temp directory, the new behavior makes us go to the repository root. Other tests don't seem to break.