-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(type): add support for new link: dependency type
- Loading branch information
Showing
21 changed files
with
229 additions
and
9 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 |
---|---|---|
|
@@ -109,6 +109,22 @@ test.concurrent('install with --optional flag', (): Promise<void> => { | |
}); | ||
}); | ||
|
||
test.concurrent('install with link: specifier', (): Promise<void> => { | ||
return runAdd(['link:../left-pad'], {dev: true}, 'add-with-flag', async config => { | ||
const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock'))); | ||
const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); | ||
|
||
const expectPath = path.join(config.cwd, 'node_modules', 'left-pad'); | ||
|
||
const stat = await fs.lstat(expectPath); | ||
expect(stat.isSymbolicLink()).toEqual(true); | ||
|
||
expect(lockfile.indexOf('[email protected]:')).toEqual(-1); | ||
expect(pkg.devDependencies).toEqual({'left-pad': 'link:../left-pad'}); | ||
expect(pkg.dependencies).toEqual({}); | ||
}); | ||
}); | ||
|
||
test.concurrent('install with arg that has binaries', (): Promise<void> => { | ||
return runAdd(['react-native-cli'], {}, 'install-with-arg-and-bin'); | ||
}); | ||
|
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
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-file-link-dependencies/.npmrc
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 @@ | ||
yarn-link-file-dependencies=true |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-file-link-dependencies/a/index.js
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 @@ | ||
foo; |
7 changes: 7 additions & 0 deletions
7
__tests__/fixtures/install/install-file-link-dependencies/a/package.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,7 @@ | ||
{ | ||
"name": "a", | ||
"version": "1.0.2", | ||
"dependencies": { | ||
"b": "*" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-file-link-dependencies/b/index.js
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 @@ | ||
bar; |
4 changes: 4 additions & 0 deletions
4
__tests__/fixtures/install/install-file-link-dependencies/b/package.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,4 @@ | ||
{ | ||
"name": "b", | ||
"version": "1.0.0" | ||
} |
7 changes: 7 additions & 0 deletions
7
__tests__/fixtures/install/install-file-link-dependencies/package.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,7 @@ | ||
{ | ||
"dependencies": { | ||
"a": "file:./a", | ||
"b": "file:./b", | ||
"c": "file:./c" | ||
} | ||
} |
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 @@ | ||
foobar; |
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,5 @@ | ||
{ | ||
"name": "bar", | ||
"version": "0.0.0", | ||
"main": "index.js" | ||
} |
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,7 @@ | ||
{ | ||
"dependencies": { | ||
"test-absolute": "link:/tmp/bar", | ||
"test-relative": "link:bar", | ||
"test-missing": "link:baz" | ||
} | ||
} |
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
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
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,46 @@ | ||
/* @flow */ | ||
|
||
import type {Manifest} from '../../types.js'; | ||
import type {RegistryNames} from '../../registries/index.js'; | ||
import type PackageRequest from '../../package-request.js'; | ||
import ExoticResolver from './exotic-resolver.js'; | ||
import * as util from '../../util/misc.js'; | ||
import * as fs from '../../util/fs.js'; | ||
|
||
const path = require('path'); | ||
|
||
export default class LinkResolver extends ExoticResolver { | ||
constructor(request: PackageRequest, fragment: string) { | ||
super(request, fragment); | ||
this.loc = util.removePrefix(fragment, 'link:'); | ||
} | ||
|
||
loc: string; | ||
|
||
static protocol = 'link'; | ||
|
||
async resolve(): Promise<Manifest> { | ||
let loc = this.loc; | ||
if (!path.isAbsolute(loc)) { | ||
loc = path.join(this.config.cwd, loc); | ||
} | ||
|
||
const name = path.basename(loc); | ||
const registry: RegistryNames = 'npm'; | ||
|
||
const manifest: Manifest = !await fs.exists(loc) | ||
? {name, version: '0.0.0', _registry: registry} | ||
: await this.config.readManifest(loc, this.registry); | ||
|
||
manifest._remote = { | ||
type: 'link', | ||
registry, | ||
hash: null, | ||
reference: loc, | ||
}; | ||
|
||
manifest._uid = manifest.version; | ||
|
||
return manifest; | ||
} | ||
} |
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