Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ test.concurrent('install file: protocol', (): Promise<void> => {
});
});

test.concurrent('install with file: protocol as default', (): Promise<void> => {
return runInstall({noLockfile: true}, 'install-file-as-default', async (config) => {
assert.equal(
await fs.readFile(path.join(config.cwd, 'node_modules', 'foo', 'index.js')),
'foobar\n',
);
});
});

test.concurrent('install everything when flat is enabled', (): Promise<void> => {
return runInstall({noLockfile: true, flat: true}, 'install-file', async (config) => {
assert.equal(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foobar
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "bar",
"version": "0.0.0",
"main": "index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"foo": "bar"
}
}
4 changes: 4 additions & 0 deletions __tests__/fixtures/install/install-file-as-default/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"foo@file:bar":
version "0.0.0"
24 changes: 23 additions & 1 deletion src/package-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {entries} from './util/misc.js';
import * as constants from './constants.js';
import * as versionUtil from './util/version.js';
import * as resolvers from './resolvers/index.js';
import * as fs from './util/fs.js';

const path = require('path');
const invariant = require('invariant');
const semver = require('semver');

Expand Down Expand Up @@ -98,7 +100,7 @@ export default class PackageRequest {
*/

async findVersionOnRegistry(pattern: string): Promise<Manifest> {
const {range, name} = PackageRequest.normalizePattern(pattern);
const {range, name} = await this.normalize(pattern);

const exoticResolver = PackageRequest.getExoticResolver(range);
if (exoticResolver) {
Expand Down Expand Up @@ -135,6 +137,26 @@ export default class PackageRequest {
}
}

async normalizeRange(pattern: string): Promise<string> {
if (pattern.includes(':') ||
pattern.includes('@') ||
PackageRequest.getExoticResolver(pattern)) {
return Promise.resolve(pattern);
}

if (await fs.exists(path.join(this.config.cwd, pattern))) {
return Promise.resolve(`file:${pattern}`);
}

return Promise.resolve(pattern);
}

async normalize(pattern: string): any {
const {name, range, hasVersion} = PackageRequest.normalizePattern(pattern);
const newRange = await this.normalizeRange(range);
return {name, range: newRange, hasVersion};
}

/**
* Explode and normalize a pattern into it's name and range.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const access: (path: string, mode?: number) => Promise<void> = promisify(
export const stat: (path: string) => Promise<fs.Stats> = promisify(fs.stat);
export const unlink: (path: string) => Promise<void> = promisify(require('rimraf'));
export const mkdirp: (path: string) => Promise<void> = promisify(require('mkdirp'));
export const exists: (path: string) => Promise<boolean> = promisify(fs.exists, true);
export const exists: (path: string) => Promise<boolean> = promisify(fs.exists, true);
export const lstat: (path: string) => Promise<fs.Stats> = promisify(fs.lstat);
export const chmod: (path: string, mode: number | string) => Promise<void> = promisify(fs.chmod);
export const link: (path: string) => Promise<fs.Stats> = promisify(fs.link);
Expand Down