Skip to content
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

Ref #2165 - file-resolver should invalidate cache with a new hash #2860

Merged
merged 3 commits into from
Apr 24, 2017
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: 8 additions & 1 deletion __tests__/commands/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ test('dir', async (): Promise<void> => {
test('clean', async (): Promise<void> => {
await runInstall({}, 'artifacts-finds-and-saves', async (config): Promise<void> => {
let files = await fs.readdir(config.cacheFolder);
expect(files.length).toEqual(2); // we need to add one .tmp folder
// Asserting cache size is 1...
// we need to add one for the .tmp folder
//
// Per #2860, file: protocol installs may add the same package to the cache
// multiple times if it is installed with a force flag or has an install script.
// We'll add another for a total of 3 because this particular fixture has
// an install script.
expect(files.length).toEqual(3);

const out = new stream.PassThrough();
const reporter = new reporters.JSONReporter({stdout: out});
Expand Down
30 changes: 27 additions & 3 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ test.concurrent('install file: protocol with relative paths', (): Promise<void>
});
});

test.concurrent('install file: protocol without cache', async (): Promise<void> => {
test.concurrent('install file: protocol without force retains installed package', async (): Promise<void> => {
const fixturesLoc = path.join(__dirname, '..', '..', 'fixtures', 'install');
const compLoc = path.join(fixturesLoc, 'install-file-without-cache', 'comp', 'index.js');

Expand All @@ -280,12 +280,11 @@ test.concurrent('install file: protocol without cache', async (): Promise<void>
'foo\n',
);

await fs.writeFile(compLoc, 'bar\n');
await fs.writeFile(path.join(config.cwd, 'comp', 'index.js'), 'bar\n');

const reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();

// TODO: This should actually be equal. See https://github.com/yarnpkg/yarn/pull/2443.
expect(
await fs.readFile(path.join(config.cwd, 'node_modules', 'comp', 'index.js')),
).not.toEqual(
Expand All @@ -294,6 +293,31 @@ test.concurrent('install file: protocol without cache', async (): Promise<void>
});
});

test.concurrent('install file: protocol with force re-installs local package', async (): Promise<void> => {
const fixturesLoc = path.join(__dirname, '..', '..', 'fixtures', 'install');
const compLoc = path.join(fixturesLoc, 'install-file-without-cache', 'comp', 'index.js');

await fs.writeFile(compLoc, 'foo\n');
await runInstall({}, 'install-file-without-cache', async (config, reporter) => {
expect(
await fs.readFile(path.join(config.cwd, 'node_modules', 'comp', 'index.js')),
).toEqual(
'foo\n',
);

await fs.writeFile(path.join(config.cwd, 'comp', 'index.js'), 'bar\n');

const reinstall = new Install({force: true}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();

expect(
await fs.readFile(path.join(config.cwd, 'node_modules', 'comp', 'index.js')),
).toEqual(
'bar\n',
);
});
});

test.concurrent('install file: local packages with local dependencies', async (): Promise<void> => {
await runInstall({}, 'install-file-local-dependency', async (config, reporter) => {
const reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"strip-bom": "^3.0.0",
"tar-fs": "^1.15.1",
"tar-stream": "^1.5.2",
"uuid": "^3.0.1",
"v8-compile-cache": "^1.1.0",
"validate-npm-package-license": "^3.0.1"
},
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const NPM_REGISTRY = /http[s]:\/\/registry.npmjs.org/g;

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

export const noArguments = true;

Expand Down Expand Up @@ -98,7 +99,7 @@ class ImportResolver extends BaseResolver {
info._remote = {
type: 'copy',
registry: this.registry,
hash: null,
hash: `${uuid.v4()}-${new Date().getTime()}`,
reference: loc,
};
return info;
Expand Down
5 changes: 3 additions & 2 deletions src/resolvers/exotics/file-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as fs from '../../util/fs.js';

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

type Dependencies = {
[key: string]: string
Expand Down Expand Up @@ -40,7 +41,7 @@ export default class FileResolver extends ExoticResolver {
manifest._remote = {
type: 'copy',
registry,
hash: null,
hash: `${uuid.v4()}-${new Date().getTime()}`,
reference: loc,
};

Expand All @@ -49,7 +50,7 @@ export default class FileResolver extends ExoticResolver {
// Normalize relative paths; if anything changes, make a copy of the manifest
const dependencies = this.normalizeDependencyPaths(manifest.dependencies, loc);
const optionalDependencies = this.normalizeDependencyPaths(manifest.optionalDependencies, loc);

if (dependencies !== manifest.dependencies || optionalDependencies !== manifest.optionalDependencies) {
const _manifest = Object.assign({}, manifest);
if (dependencies != null) {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4519,7 +4519,7 @@ [email protected], util@^0.10.3:
dependencies:
inherits "2.0.1"

uuid@^3.0.0:
uuid@^3.0.0, uuid@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"

Expand Down