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

Prevents gitignore files from being read when files is used #532

Merged
merged 2 commits into from
Oct 15, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ describe(`Commands`, () => {
}),
);

test(
`it should ignore root .gitignore files when using the 'files' field`,
makeTemporaryEnv({
files: [
`lib`,
],
}, async ({path, run, source}) => {
await fsUtils.writeFile(`${path}/.gitignore`, `lib`);

await run(`install`);

await fsUtils.writeFile(`${path}/lib/foo.js`);

const {stdout} = await run(`pack`, `--dry-run`);
await expect(stdout).toMatch(/lib\/foo\.js/);
}),
);

test(
`it shouldn't add the cache to the package files`,
makeTemporaryEnv({}, async ({path, run, source}) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"tar-stream": "^2.0.1"
},
"version": "2.0.0-rc.4",
"nextVersion": {
"semver": "2.0.0-rc.5",
"nonce": "3390682135047771"
},
"repository": {
"type": "git",
"url": "ssh://git@github.com/yarnpkg/berry.git"
Expand Down
16 changes: 10 additions & 6 deletions packages/plugin-pack/sources/packUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,23 @@ export async function genPackList(workspace: Workspace) {
else if (workspace.manifest.module)
ignoreList.accept.push(ppath.resolve(PortablePath.root, workspace.manifest.module));

if (workspace.manifest.files !== null) {
const hasExplicitFileList = workspace.manifest.files !== null;
if (hasExplicitFileList) {
ignoreList.reject.push(`/*`);

for (const pattern of workspace.manifest.files) {
for (const pattern of workspace.manifest.files!) {
addIgnorePattern(ignoreList.accept, pattern, {cwd: PortablePath.root});
}
}

return await walk(workspace.cwd, {
hasExplicitFileList,
globalList,
ignoreList,
});
}

async function walk(initialCwd: PortablePath, {globalList, ignoreList}: {globalList: IgnoreList, ignoreList: IgnoreList}) {
async function walk(initialCwd: PortablePath, {hasExplicitFileList, globalList, ignoreList}: {hasExplicitFileList: boolean, globalList: IgnoreList, ignoreList: IgnoreList}) {
const list: PortablePath[] = [];

const cwdFs = new JailFS(initialCwd);
Expand All @@ -238,9 +240,11 @@ async function walk(initialCwd: PortablePath, {globalList, ignoreList}: {globalL
let hasGitIgnore = false;
let hasNpmIgnore = false;

for (const entry of entries) {
hasGitIgnore = hasGitIgnore || entry === `.gitignore`;
hasNpmIgnore = hasNpmIgnore || entry === `.npmignore`;
if (!hasExplicitFileList || cwd !== PortablePath.root) {
for (const entry of entries) {
hasGitIgnore = hasGitIgnore || entry === `.gitignore`;
hasNpmIgnore = hasNpmIgnore || entry === `.npmignore`;
}
}

const localIgnoreList = hasNpmIgnore
Expand Down
4 changes: 4 additions & 0 deletions packages/yarnpkg-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"name": "@yarnpkg/cli",
"version": "2.0.0-rc.9",
"nextVersion": {
"semver": "2.0.0-rc.10",
"nonce": "3585046797413477"
},
"main": "./sources/index.ts",
"dependencies": {
"@yarnpkg/core": "workspace:2.0.0-rc.9",
Expand Down