Skip to content

Commit

Permalink
feat(pack): exclude "global" gitignore folders/files
Browse files Browse the repository at this point in the history
  • Loading branch information
cacheflow committed Feb 14, 2019
1 parent b3d136f commit bb52cab
Show file tree
Hide file tree
Showing 21 changed files with 355 additions and 26 deletions.
52 changes: 49 additions & 3 deletions __tests__/__snapshots__/normalize-manifest.js.snap
Expand Up @@ -2,138 +2,168 @@

exports[`author object normalize: author object normalize 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`author string: author string 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`authors file to contributors: authors file to contributors 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`bin string: bin string 1`] = `
Array [
"../../../../../package.json: No license field",
"foo: No license field",
]
`;

exports[`binding.gyp scripts.install: binding.gyp scripts.install 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`bugs string: bugs string 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`bundledDependencies alias: bundledDependencies alias 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`clean version with v: clean version with v 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`clean version: clean version 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`contributors array expand: contributors array expand 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`dedupe all trivial dependencies: dedupe all trivial dependencies 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`dedupe dependencies root: dedupe dependencies root 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
"\\"dependencies\\" has dependency \\"foobar\\" with range \\"2.0.0\\" that collides with a dependency in \\"devDependencies\\" of the same name with version \\"1.0.0\\"",
]
`;

exports[`dedupe dependencies: dedupe dependencies 1`] = `Array []`;
exports[`dedupe dependencies: dedupe dependencies 1`] = `
Array [
"../../../../../package.json: No license field",
]
`;

exports[`dedupe optionalDependencies root: dedupe optionalDependencies root 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
"\\"optionalDependencies\\" has dependency \\"foobar\\" with range \\"1.0.0\\" that collides with a dependency in \\"dependencies\\" of the same name with version \\"2.0.0\\"",
]
`;

exports[`dedupe optionalDependencies: dedupe optionalDependencies 1`] = `Array []`;
exports[`dedupe optionalDependencies: dedupe optionalDependencies 1`] = `
Array [
"../../../../../package.json: No license field",
]
`;

exports[`dedupe single trivial dependency: dedupe single trivial dependency 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`empty bin string: empty bin string 1`] = `
Array [
"../../../../../package.json: No license field",
"foo: No license field",
]
`;

exports[`engines array: engines array 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`explode directories.bin: explode directories.bin 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`explode directories.man: explode directories.man 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`extract description: extract description 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`homepage string: homepage string 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`hosted git repository url: hosted git repository url 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`keywords string: keywords string 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;
Expand All @@ -142,75 +172,91 @@ exports[`license warnings should not be thrown with global commands: license war

exports[`maintainers array expand: maintainers array expand 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`man string: man string 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`name: name 1`] = `
Array [
"../../../../../package.json: No license field",
"foobar: No license field",
]
`;

exports[`readme: readme 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`repository string: repository string 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`scoped bin string: scoped bin string 1`] = `
Array [
"../../../../../package.json: No license field",
"@scope/foo: No license field",
]
`;

exports[`server scripts.start: server scripts.start 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`valid license: valid license 1`] = `Array []`;
exports[`valid license: valid license 1`] = `
Array [
"../../../../../package.json: No license field",
]
`;

exports[`version: version 1`] = `
Array [
"../../../../../package.json: No license field",
"No license field",
]
`;

exports[`warn builtin module collision: warn builtin module collision 1`] = `
Array [
"../../../../../package.json: No license field",
"fs: \\"fs\\" is also the name of a node core module",
"fs: No license field",
]
`;

exports[`warn empty string invalid license: warn empty string invalid license 1`] = `
Array [
"../../../../../package.json: No license field",
"License should be a valid SPDX license expression",
]
`;

exports[`warn invalid license: warn invalid license 1`] = `
Array [
"../../../../../package.json: No license field",
"License should be a valid SPDX license expression",
]
`;

exports[`warn typo: warn typo 1`] = `
Array [
"../../../../../package.json: No license field",
"Potential typo \\"dependancies\\", did you mean \\"dependencies\\"?",
"No license field",
]
Expand Down
70 changes: 70 additions & 0 deletions __tests__/commands/pack.js
Expand Up @@ -3,6 +3,7 @@ import * as fs from '../../src/util/fs.js';
import {run as pack} from '../../src/cli/commands/pack.js';
import {ConsoleReporter} from '../../src/reporters/index.js';
import {run as buildRun} from './_helpers.js';
const rimraf = require('rimraf');

jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;

Expand Down Expand Up @@ -44,6 +45,30 @@ export async function getFilesFromArchive(source, destination): Promise<Array<st
return files;
}

const mockGlobalGitIgnoreFolder = path.resolve(__dirname, '..', 'fixtures', 'pack', 'excluded-global-gitignore');

const mockGlobalGitIgnoreFile = path.resolve(mockGlobalGitIgnoreFolder, '.gitignore_global');

jest.mock('../../src/util/git/git-spawn.js', () => ({
spawn: jest.fn(async ([command]) => {
switch (command) {
case 'config':
return `${mockGlobalGitIgnoreFile}`;
}
const res = await Promise.resolve('');
return res;
}),
}));

beforeAll(() => {
fs2.mkdirSync(mockGlobalGitIgnoreFolder);
fs2.writeFileSync(mockGlobalGitIgnoreFile, 'c.js', 'utf-8');
});

afterAll(() => {
rimraf.sync(mockGlobalGitIgnoreFolder);
});

test.concurrent('pack should work with a minimal example', (): Promise<void> => {
return runPack([], {}, 'minimal', async (config): Promise<void> => {
const {cwd} = config;
Expand Down Expand Up @@ -147,6 +172,51 @@ test.concurrent('pack should exclude all dotfiles if not in files and files not
});
});

test.concurrent('pack should exclude all files in global dotfiles', (): Promise<void> => {
return runPack([], {}, 'files-exclude-with-global-dotfile', async (config): Promise<void> => {
const {cwd} = config;
const files = await getFilesFromArchive(
path.join(cwd, 'files-exclude-with-global-dotfile-v1.0.0.tgz'),
path.join(cwd, 'files-exclude-with-global-dotfile-v1.0.0'),
);
expect(files.indexOf('c.js')).toEqual(-1);
});
});

test.concurrent('pack should not exclude non-existant files included in global dotfiles', (): Promise<void> => {
return runPack([], {}, 'non-existant-files-in-global-dotfile', async (config): Promise<void> => {
const {cwd} = config;
const files = await getFilesFromArchive(
path.join(cwd, 'non-existant-files-in-global-dotfile-v1.0.0.tgz'),
path.join(cwd, 'non-existant-files-in-global-dotfile-v1.0.0'),
);
expect(files).toEqual([
'.yarn-cache',
'.yarn-cache/v3',
'.yarn-cache/v3/.tmp',
'.yarn-global',
'.yarn-link',
'a.js',
'b.js',
'd.js',
'index.js',
'package.json',
]);
});
});

test.concurrent('pack should remove files from both local and global dotfiles', (): Promise<void> => {
return runPack([], {}, 'files-exclude-with-local-and-global-dotfile', async (config): Promise<void> => {
const {cwd} = config;
const files = await getFilesFromArchive(
path.join(cwd, 'files-exclude-with-local-and-global-dotfile-v1.0.0.tgz'),
path.join(cwd, 'files-exclude-with-local-and-global-dotfile-v1.0.0'),
);
expect(files.indexOf('a.js')).toEqual(-1);
expect(files.indexOf('c.js')).toEqual(-1);
});
});

test.concurrent('pack should exclude all files in dot-directories if not in files and files not empty', (): Promise<
void,
> => {
Expand Down
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
@@ -0,0 +1,6 @@
{
"name": "files-exclude-with-global-dotfile",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
@@ -0,0 +1 @@
a.js
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
@@ -0,0 +1,6 @@
{
"name": "files-exclude-with-local-and-global-dotfile",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');

0 comments on commit bb52cab

Please sign in to comment.