Skip to content

Commit

Permalink
Fix for yarnpkg#1214
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser committed Nov 21, 2016
1 parent 328b4e1 commit 4c95db9
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 3 deletions.
11 changes: 11 additions & 0 deletions __tests__/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,3 +775,14 @@ test.concurrent('install uses OS line endings when lockfile doesn\'t exist', asy
assert(lockfile.indexOf(os.EOL) >= 0);
});
});

test.concurrent('install will not overwrite files in symlinked scoped directories', async (): Promise<void> => {
await runInstall({}, 'install-dont-overwrite-linked-scoped', async (config): Promise<void> => {
const dependencyPath = path.join(config.cwd, 'node_modules', '@fakescope', 'fake-dependency');
assert.equal(
'Symlinked scoped package test',
(await fs.readJson(path.join(dependencyPath, 'package.json'))).description,
);
assert.ok(!(await fs.exists(path.join(dependencyPath, 'index.js'))));
});
});
2 changes: 1 addition & 1 deletion __tests__/commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ test.concurrent('removes multiple installed packages', (): Promise<void> => {

test.concurrent('removes scoped packages', (): Promise<void> => {
return runRemove({}, ['@scoped/package'], 'scoped-package', async (config): Promise<void> => {
assert(!await fs.exists(path.join(config.cwd, 'node_modules/@scoped')));
assert(!await fs.exists(path.join(config.cwd, 'node_modules/@scoped/package')));

assert.deepEqual(
JSON.parse(await fs.readFile(path.join(config.cwd, 'package.json'))).dependencies,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn-offline-mirror=./mirror-for-offline
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@fakescope/fake-dependency",
"description": "Symlinked scoped package test",
"version": "1.0.1",
"dependencies": {},
"license": "MIT"
}
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@fakescope/fake-dependency": "1.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@fakescope/fake-dependency@1.0.1":
version "1.0.1"
resolved "@fakescope-fake-dependency-1.0.1.tgz#477dafd486d856af0b3faf5a5f1c895001221609"
15 changes: 14 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,20 @@ export default class Config {
await fs.mkdirp(this.tempFolder);

await fs.mkdirp(this.linkFolder);
this.linkedModules = await fs.readdir(this.linkFolder);

this.linkedModules = [];

const maybeLinkedModules = await fs.readdir(this.linkFolder);

for (const maybeLinked of maybeLinkedModules) {
// handle scoped modules separately
if (maybeLinked.indexOf('@') === 0) {
const scopedLinked = await fs.readdir(path.join(this.linkFolder, maybeLinked));
this.linkedModules.push(...scopedLinked.map((dir) => path.join(maybeLinked, dir)));
} else {
this.linkedModules.push(maybeLinked);
}
}

for (const key of Object.keys(registries)) {
const Registry = registries[key];
Expand Down
12 changes: 11 additions & 1 deletion src/package-linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default class PackageLinker {
}

async copyModules(patterns: Array<string>): Promise<void> {

let flatTree = await this.getFlatHoistedTree(patterns);

// sorted tree makes file creation and copying not to interfere with each other
Expand Down Expand Up @@ -158,7 +159,16 @@ export default class PackageLinker {
if (await fs.exists(loc)) {
const files = await fs.readdir(loc);
for (const file of files) {
possibleExtraneous.add(path.join(loc, file));
const filePath = path.join(loc, file);
// scoped packages are a nested one level deeper
if (file.indexOf('@') === 0) {
const scopedFiles = await fs.readdir(filePath);
for (const scoped of scopedFiles) {
possibleExtraneous.add(path.join(filePath, scoped));
}
} else {
possibleExtraneous.add(filePath);
}
}
}
}
Expand Down

0 comments on commit 4c95db9

Please sign in to comment.