Skip to content

Fix #2822: Respect files package content when using file: dependencies #8249

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<!-- -->
Please add one entry in this file for each change in Yarn's behavior. Use the same format for all entries, including the third-person verb. Make sure you don't add more than one line of text to keep it clean. Thanks!

## Unreleased

- Respects files array when referencing dependencies via `file:`

[#8249](https://github.com/yarnpkg/yarn/pull/8249) - [**Kav**](https://github.com/kav)

## 1.22.2

- Sorts files when running `yarn pack` to produce identical layout on Windows and Unix systems
Expand Down Expand Up @@ -35,15 +41,15 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa
- Allows some dots in binary names again

[#7811](https://github.com/yarnpkg/yarn/pull/7811) - [**Valery Bugakov**](https://github.com/valerybugakov)

- Better error handling on `yarn set version`

[#7848](https://github.com/yarnpkg/yarn/pull/7848) - [**Nick Olinger**](https://github.com/olingern)

- Passes arguments following `--` when running a workspace script (`yarn workspace pkg run command -- arg`)

[#7776](https://github.com/yarnpkg/yarn/pull/7776) - [**Jeff Valore**](https://twitter.com/rally25rs)

- Fixes an issue where the archive paths were incorrectly sanitized

[#7831](https://github.com/yarnpkg/yarn/pull/7831) - [**Maël Nison**](https://twitter.com/arcanis)
Expand All @@ -65,7 +71,7 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa
- Implements `yarn init --install <version>`

[#7723](https://github.com/yarnpkg/yarn/pull/7723) - [**Maël Nison**](https://twitter.com/arcanis)

## 1.19.2

- Folders like `.cache` won't be pruned from the `node_modules` after each install.
Expand Down
30 changes: 28 additions & 2 deletions __tests__/fetchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ test('BaseFetcher.fetch', async () => {
});

test('CopyFetcher.fetch', async () => {
const a = await mkdir('copy-fetcher-a');
const a = await mkdir('copy-fetcher-a-');
await fs.writeFile(path.join(a, 'package.json'), '{}');
await fs.writeFile(path.join(a, 'foo'), 'bar');

const b = await mkdir('copy-fetcher-b');
const b = await mkdir('copy-fetcher-b-');
const fetcher = new CopyFetcher(
b,
{
Expand All @@ -61,6 +61,32 @@ test('CopyFetcher.fetch', async () => {
expect(contentFoo).toBe('bar');
});

test('CopyFetcher.fetch[files]', async () => {
const a = await mkdir('copy-fetcher-a-');
await fs.writeFile(path.join(a, 'package.json'), '{"files":["include"]}');
await fs.writeFile(path.join(a, 'include'), 'bar');
await fs.writeFile(path.join(a, 'exclude'), 'baz');

const b = await mkdir('copy-fetcher-b-');
const fetcher = await new CopyFetcher(
b,
{
type: 'copy',
reference: a,
registry: 'npm',
hash: null,
},
await Config.create(),
);
await fetcher.fetch();
const content = await fs.readFile(path.join(b, 'package.json'));
expect(content).toBe('{"files":["include"]}');
const contentFoo = await fs.readFile(path.join(b, 'include'));
expect(contentFoo).toBe('bar');
const excludeExists = await fs.exists(path.join(b, 'exclude'));
expect(excludeExists).toBe(false);
});

test('GitFetcher.fetch', async () => {
const dir = await mkdir('git-fetcher');
const fetcher = new GitFetcher(
Expand Down
25 changes: 25 additions & 0 deletions src/fetchers/copy-fetcher.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
/* @flow */

import path from 'path';
import type {FetchedOverride} from '../types.js';
import BaseFetcher from './base-fetcher.js';
import * as fs from '../util/fs.js';
import {MessageError} from '../errors.js';

export default class CopyFetcher extends BaseFetcher {
async _fetch(): Promise<FetchedOverride> {
try {
const {files} = await this.config.readManifest(this.reference, this.registry);
if (files) {
await Promise.all(
['package.json'].concat(files).map(fileName => {
const source = path.join(this.reference, fileName);
const destination = path.join(this.dest, fileName);
return fs.copy(source, destination, this.reporter);
}),
);

return {
hash: this.hash || '',
resolved: null,
};
}
} catch (err) {
if (err instanceof MessageError) {
this.reporter.warn(err);
} else {
throw err;
}
}
await fs.copy(this.reference, this.dest, this.reporter);
return {
hash: this.hash || '',
Expand Down