diff --git a/__tests__/__snapshots__/normalize-manifest.js.snap b/__tests__/__snapshots__/normalize-manifest.js.snap index c5a78707da..24932f8f13 100644 --- a/__tests__/__snapshots__/normalize-manifest.js.snap +++ b/__tests__/__snapshots__/normalize-manifest.js.snap @@ -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", ] `; @@ -142,56 +172,69 @@ 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", ] @@ -199,18 +242,21 @@ Array [ 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", ] diff --git a/__tests__/commands/pack.js b/__tests__/commands/pack.js index cd825c67b8..6403e6c768 100644 --- a/__tests__/commands/pack.js +++ b/__tests__/commands/pack.js @@ -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; @@ -44,6 +45,30 @@ export async function getFilesFromArchive(source, destination): Promise ({ + 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 => { return runPack([], {}, 'minimal', async (config): Promise => { const {cwd} = config; @@ -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 => { + return runPack([], {}, 'files-exclude-with-global-dotfile', async (config): Promise => { + 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 => { + return runPack([], {}, 'non-existant-files-in-global-dotfile', async (config): Promise => { + 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 => { + return runPack([], {}, 'files-exclude-with-local-and-global-dotfile', async (config): Promise => { + 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, > => { diff --git a/__tests__/fixtures/pack/files-exclude-with-global-dotfile/a.js b/__tests__/fixtures/pack/files-exclude-with-global-dotfile/a.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-exclude-with-global-dotfile/a.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-exclude-with-global-dotfile/b.js b/__tests__/fixtures/pack/files-exclude-with-global-dotfile/b.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-exclude-with-global-dotfile/b.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-exclude-with-global-dotfile/c.js b/__tests__/fixtures/pack/files-exclude-with-global-dotfile/c.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-exclude-with-global-dotfile/c.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-exclude-with-global-dotfile/index.js b/__tests__/fixtures/pack/files-exclude-with-global-dotfile/index.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-exclude-with-global-dotfile/index.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-exclude-with-global-dotfile/package.json b/__tests__/fixtures/pack/files-exclude-with-global-dotfile/package.json new file mode 100644 index 0000000000..50e9f8944a --- /dev/null +++ b/__tests__/fixtures/pack/files-exclude-with-global-dotfile/package.json @@ -0,0 +1,6 @@ +{ + "name": "files-exclude-with-global-dotfile", + "version": "1.0.0", + "main": "index.js", + "license": "MIT" +} diff --git a/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/.gitignore b/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/.gitignore new file mode 100644 index 0000000000..44001cd1bc --- /dev/null +++ b/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/.gitignore @@ -0,0 +1 @@ +a.js \ No newline at end of file diff --git a/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/b.js b/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/b.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/b.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/c.js b/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/c.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/c.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/index.js b/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/index.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/index.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/package.json b/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/package.json new file mode 100644 index 0000000000..34c6ab8b72 --- /dev/null +++ b/__tests__/fixtures/pack/files-exclude-with-local-and-global-dotfile/package.json @@ -0,0 +1,6 @@ +{ + "name": "files-exclude-with-local-and-global-dotfile", + "version": "1.0.0", + "main": "index.js", + "license": "MIT" +} diff --git a/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/a.js b/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/a.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/a.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/b.js b/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/b.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/b.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/d.js b/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/d.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/d.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/index.js b/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/index.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/index.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/package.json b/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/package.json new file mode 100644 index 0000000000..ce24743cdd --- /dev/null +++ b/__tests__/fixtures/pack/non-existant-files-in-global-dotfile/package.json @@ -0,0 +1,6 @@ +{ + "name": "non-existant-files-in-global-dotfile", + "version": "1.0.0", + "main": "index.js", + "license": "MIT" +} diff --git a/__tests__/fixtures/request-cache/GET/gitlab.com/leanlabsio/kanban/raw/f139bd887dea8e48c46fd7fcfe42b5ffc53d79dd/package.json.bin b/__tests__/fixtures/request-cache/GET/gitlab.com/leanlabsio/kanban/raw/f139bd887dea8e48c46fd7fcfe42b5ffc53d79dd/package.json.bin new file mode 100644 index 0000000000..ea13616e8c --- /dev/null +++ b/__tests__/fixtures/request-cache/GET/gitlab.com/leanlabsio/kanban/raw/f139bd887dea8e48c46fd7fcfe42b5ffc53d79dd/package.json.bin @@ -0,0 +1,56 @@ +HTTP/1.1 200 OK +Server: nginx +Date: Thu, 14 Feb 2019 06:18:39 GMT +Content-Type: text/plain; charset=utf-8 +Content-Length: 1181 +Cache-Control: max-age=3600, public +Content-Disposition: inline +Etag: W/"78309fbf8af4479c47eca65b0c5e3f51" +X-Content-Type-Options: nosniff +X-Frame-Options: DENY +X-Request-Id: DGv7xhQoZl1 +X-Runtime: 0.074204 +X-Ua-Compatible: IE=edge +X-Xss-Protection: 1; mode=block +Strict-Transport-Security: max-age=31536000 +Content-Security-Policy: object-src 'none'; worker-src https://assets.gitlab-static.net https://gl-canary.global.ssl.fastly.net https://gitlab.com blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://assets.gitlab-static.net https://gl-canary.global.ssl.fastly.net https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://www.gstatic.com/recaptcha/ https://apis.google.com; style-src 'self' 'unsafe-inline' https://assets.gitlab-static.net https://gl-canary.global.ssl.fastly.net; img-src * data: blob:; frame-src 'self' https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://content.googleapis.com https://content-compute.googleapis.com https://content-cloudbilling.googleapis.com https://content-cloudresourcemanager.googleapis.com https://*.codesandbox.io; frame-ancestors 'self'; connect-src 'self' https://assets.gitlab-static.net https://gl-canary.global.ssl.fastly.net wss://gitlab.com https://sentry.gitlab.net https://customers.gitlab.com https://snowplow.trx.gitlab.net + +{ + "name": "kanban", + "version": "0.0.1", + "repository": "gitlab.com/leanlabsio/kanban", + "scripts": { + "install": "npm install", + "build": "grunt build", + "watch": "grunt watch" + }, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-cli": "~0.1.13", + "grunt-contrib-copy": "^0.5.0", + "grunt-contrib-concat": "~0.5.0", + "grunt-contrib-watch": "~0.5.3", + "grunt-contrib-uglify": "~0.7.0", + "grunt-sass": "1.0.0", + "grunt-contrib-connect": "~0.8.0", + "grunt-connect-proxy": "~0.1.11" + }, + "dependencies": { + "angular": "=1.5.6", + "angular-lodash": "https://github.com/EMSSConsulting/angular-lodash.git#68a726c", + "foundation-sites": "5.5.2", + "angular-foundation": "https://github.com/pineconellc/angular-foundation.git#8f3f260", + "angular-loading-bar": "=0.5.2", + "angular-storage": "=0.0.6", + "angular-ui-router": "=0.3.0", + "angularjs-datepicker": "=0.2.15", + "font-awesome": "=4.6.3", + "markdown-it": "=5.0.2", + "markdown-it-emoji": "=1.1.0", + "ng-sortable": "=1.3.6", + "sass-flex-mixin": "=1.0.3", + "lodash": "=4.13.1", + "twemoji": "=2.1.0", + "angular-file-upload": "=2.3.4" + } +} diff --git a/__tests__/util/filter.js b/__tests__/util/filter.js index 9c6a749b9a..81c2e38fb3 100644 --- a/__tests__/util/filter.js +++ b/__tests__/util/filter.js @@ -38,7 +38,12 @@ test('ignoreLinesToRegex', () => { {base: '.', isNegation: false, pattern: 'e#', regex: /^(?:e#)$/i}, {base: '.', isNegation: false, pattern: 'f # ', regex: /^(?:f #)$/i}, {base: '.', isNegation: false, pattern: 'g# ', regex: /^(?:g#)$/i}, - {base: '.', isNegation: false, pattern: 'h # foo', regex: /^(?:h # foo)$/i}, + { + base: '.', + isNegation: false, + pattern: 'h # foo', + regex: /^(?:h # foo)$/i, + }, {base: '.', isNegation: false, pattern: 'i# foo', regex: /^(?:i# foo)$/i}, { base: '.', @@ -64,22 +69,115 @@ test('ignoreLinesToRegex', () => { test('filterOverridenGitignores', () => { expect( filterOverridenGitignores([ - {relative: '.gitignore', basename: '.gitignore', absolute: '/home/user/p/.gitignore', mtime: 0}, - {relative: '.npmignore', basename: '.npmignore', absolute: '/home/user/p/.npmignore', mtime: 0}, - {relative: 'docs', basename: 'lib', absolute: '/home/user/p/docs', mtime: 0}, - {relative: 'docs/file.txt', basename: 'file.txt', absolute: '/home/user/p/docs/file.txt', mtime: 0}, - {relative: 'index.js', basename: 'index.js', absolute: '/home/user/p/index.js', mtime: 0}, - {relative: 'lib', basename: 'lib', absolute: '/home/user/p/lib', mtime: 0}, - {relative: 'lib/.gitignore', basename: '.gitignore', absolute: '/home/user/p/lib/.gitignore', mtime: 0}, - {relative: 'lib/index.js', basename: 'index.js', absolute: '/home/user/p/lib/index.js', mtime: 0}, - {relative: 'README.md', basename: 'README.md', absolute: '/home/user/p/README.md', mtime: 0}, - {relative: 'src', basename: 'src', absolute: '/home/user/p/src', mtime: 0}, - {relative: 'src/.yarnignore', basename: '.yarnignore', absolute: '/home/user/p/src/.yarnignore', mtime: 0}, - {relative: 'src/app.js', basename: 'app.js', absolute: '/home/user/p/src/app.js', mtime: 0}, + { + relative: '.gitignore', + basename: '.gitignore', + absolute: '/home/user/p/.gitignore', + mtime: 0, + }, + { + relative: '.npmignore', + basename: '.npmignore', + absolute: '/home/user/p/.npmignore', + mtime: 0, + }, + { + relative: '.gitignore_global', + basename: '.gitignore_global', + absolute: '/home/user/p/.gitignore_global', + mtime: 0, + }, + { + relative: 'docs', + basename: 'lib', + absolute: '/home/user/p/docs', + mtime: 0, + }, + { + relative: 'docs/file.txt', + basename: 'file.txt', + absolute: '/home/user/p/docs/file.txt', + mtime: 0, + }, + { + relative: 'index.js', + basename: 'index.js', + absolute: '/home/user/p/index.js', + mtime: 0, + }, + { + relative: 'lib', + basename: 'lib', + absolute: '/home/user/p/lib', + mtime: 0, + }, + { + relative: 'lib/.gitignore', + basename: '.gitignore', + absolute: '/home/user/p/lib/.gitignore', + mtime: 0, + }, + { + relative: 'lib/index.js', + basename: 'index.js', + absolute: '/home/user/p/lib/index.js', + mtime: 0, + }, + { + relative: 'README.md', + basename: 'README.md', + absolute: '/home/user/p/README.md', + mtime: 0, + }, + { + relative: 'src', + basename: 'src', + absolute: '/home/user/p/src', + mtime: 0, + }, + { + relative: 'src/.yarnignore', + basename: '.yarnignore', + absolute: '/home/user/p/src/.yarnignore', + mtime: 0, + }, + { + relative: 'src/app.js', + basename: 'app.js', + absolute: '/home/user/p/src/app.js', + mtime: 0, + }, ]), ).toEqual([ - {relative: '.npmignore', basename: '.npmignore', absolute: '/home/user/p/.npmignore', mtime: 0}, - {relative: 'lib/.gitignore', basename: '.gitignore', absolute: '/home/user/p/lib/.gitignore', mtime: 0}, - {relative: 'src/.yarnignore', basename: '.yarnignore', absolute: '/home/user/p/src/.yarnignore', mtime: 0}, + { + absolute: '/home/user/p/.gitignore', + basename: '.gitignore', + mtime: 0, + relative: '.gitignore', + }, + { + absolute: '/home/user/p/.npmignore', + basename: '.npmignore', + mtime: 0, + relative: '.npmignore', + }, + { + absolute: '/home/user/p/.gitignore_global', + basename: '.gitignore_global', + mtime: 0, + relative: '.gitignore_global', + }, + { + absolute: '/home/user/p/lib/.gitignore', + basename: '.gitignore', + mtime: 0, + relative: 'lib/.gitignore', + }, + { + absolute: '/home/user/p/src/.yarnignore', + basename: '.yarnignore', + mtime: 0, + relative: 'src/.yarnignore', + }, ]); }); diff --git a/src/cli/commands/pack.js b/src/cli/commands/pack.js index c84e107387..bb6c2713f5 100644 --- a/src/cli/commands/pack.js +++ b/src/cli/commands/pack.js @@ -6,6 +6,8 @@ import type {IgnoreFilter} from '../../util/filter.js'; import * as fs from '../../util/fs.js'; import {sortFilter, ignoreLinesToRegex, filterOverridenGitignores} from '../../util/filter.js'; import {MessageError} from '../../errors.js'; +import {spawn as spawnGit} from '../../util/git/git-spawn.js'; +import {lstat} from '../../util/fs'; const zlib = require('zlib'); const path = require('path'); @@ -38,6 +40,7 @@ const DEFAULT_IGNORE = ignoreLinesToRegex([ '.yarnrc', '.npmignore', '.gitignore', + '.gitignore_global', '.DS_Store', ]); @@ -55,7 +58,7 @@ export async function packTarball( ): Promise { const pkg = await config.readRootManifest(); const {bundleDependencies, main, files: onlyFiles} = pkg; - + const globalGitIgnoreFile = await spawnGit(['config', '--global', 'core.excludesfile']); // include required files let filters: Array = NEVER_IGNORE.slice(); // include default filters unless `files` is used @@ -66,6 +69,10 @@ export async function packTarball( filters = filters.concat(ignoreLinesToRegex(['!/' + main])); } + if (globalGitIgnoreFile) { + filters = filters.concat(ignoreLinesToRegex([globalGitIgnoreFile])); + } + // include bundleDependencies let bundleDependenciesFiles = []; if (bundleDependencies) { @@ -93,13 +100,25 @@ export async function packTarball( } const files = await fs.walk(config.cwd, null, new Set(FOLDERS_IGNORE)); + + if (globalGitIgnoreFile) { + const stat = await lstat(globalGitIgnoreFile); + const loc = path.resolve(globalGitIgnoreFile); + const basename = path.basename(globalGitIgnoreFile); + files.push({ + relative: basename, + basename, + absolute: loc, + mtime: +stat.mtime, + }); + } + const dotIgnoreFiles = filterOverridenGitignores(files); // create ignores for (const file of dotIgnoreFiles) { const raw = await fs.readFile(file.absolute); const lines = raw.split('\n'); - const regexes = ignoreLinesToRegex(lines, path.dirname(file.relative)); filters = filters.concat(regexes); } diff --git a/src/util/filter.js b/src/util/filter.js index c9dc03cdf3..9a291670de 100644 --- a/src/util/filter.js +++ b/src/util/filter.js @@ -2,7 +2,6 @@ import type {WalkFiles} from './fs.js'; import {removeSuffix} from './misc.js'; - const mm = require('micromatch'); const path = require('path'); @@ -90,7 +89,6 @@ export function sortFilter( parts.pop(); } } - return {ignoreFiles, keepFiles}; } @@ -152,10 +150,11 @@ export function ignoreLinesToRegex(lines: Array, base: string = '.'): Ar } export function filterOverridenGitignores(files: WalkFiles): WalkFiles { - const IGNORE_FILENAMES = ['.yarnignore', '.npmignore', '.gitignore']; - const GITIGNORE_NAME = IGNORE_FILENAMES[2]; + const IGNORE_FILENAMES = ['.yarnignore', '.npmignore', '.gitignore', '.gitignore_global']; + const LOCAL_GIT_IGNORE = IGNORE_FILENAMES[2]; + const GLOBAL_GITIGNORE = IGNORE_FILENAMES[3]; return files.filter(file => IGNORE_FILENAMES.indexOf(file.basename) > -1).reduce((acc: WalkFiles, file) => { - if (file.basename !== GITIGNORE_NAME) { + if (file.basename !== LOCAL_GIT_IGNORE || file.basename !== GLOBAL_GITIGNORE) { return [...acc, file]; } else { //don't include .gitignore if .npmignore or .yarnignore are present