From 3174b5dbd04b877fc249cd41d5f09158bb4b3f93 Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Wed, 6 Jun 2018 15:52:04 -0700 Subject: [PATCH 1/5] Rename bundledDependencies to bundleDependencies --- src/cli/commands/pack.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cli/commands/pack.js b/src/cli/commands/pack.js index 7d68627b1d..559c701e95 100644 --- a/src/cli/commands/pack.js +++ b/src/cli/commands/pack.js @@ -53,7 +53,7 @@ export async function packTarball( {mapHeader}: {mapHeader?: Object => Object} = {}, ): Promise { const pkg = await config.readRootManifest(); - const {bundledDependencies, main, files: onlyFiles} = pkg; + const {bundleDependencies, main, files: onlyFiles} = pkg; // include required files let filters: Array = NEVER_IGNORE.slice(); @@ -65,10 +65,10 @@ export async function packTarball( filters = filters.concat(ignoreLinesToRegex(['!/' + main])); } - // include bundledDependencies - if (bundledDependencies) { + // include bundleDependencies + if (bundleDependencies) { const folder = config.getFolder(pkg); - filters = ignoreLinesToRegex(bundledDependencies.map((name): string => `!${folder}/${name}`), '.'); + filters = ignoreLinesToRegex(bundleDependencies.map((name): string => `!${folder}/${name}`), '.'); } // `files` field From 6650642f558283d222a1c4ce33abf04b5d785eb2 Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Wed, 6 Jun 2018 20:44:37 -0700 Subject: [PATCH 2/5] bundleDependencies respected during pack Walk the bundleDependency tree and include the related files. --- package.json | 1 + src/cli/commands/pack.js | 17 +++++++++-- yarn.lock | 61 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index ca6b76db9f..fd95f0bac3 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dnscache": "^1.0.1", "glob": "^7.1.1", "gunzip-maybe": "^1.4.0", + "hash-for-dep": "^1.2.3", "ini": "^1.3.4", "inquirer": "^3.0.1", "invariant": "^2.2.0", diff --git a/src/cli/commands/pack.js b/src/cli/commands/pack.js index 559c701e95..e294d5c1b4 100644 --- a/src/cli/commands/pack.js +++ b/src/cli/commands/pack.js @@ -11,6 +11,7 @@ const zlib = require('zlib'); const path = require('path'); const tar = require('tar-fs'); const fs2 = require('fs'); +const depsFor = require('hash-for-dep/lib/deps-for'); const FOLDERS_IGNORE = [ // never allow version control folders @@ -66,9 +67,16 @@ export async function packTarball( } // include bundleDependencies + let bundleDependenciesFiles = []; if (bundleDependencies) { - const folder = config.getFolder(pkg); - filters = ignoreLinesToRegex(bundleDependencies.map((name): string => `!${folder}/${name}`), '.'); + for (const dependency of bundleDependencies) { + const dependencyList = depsFor(dependency, config.cwd); + + for (const dep of dependencyList) { + const filesForBundledDep = await fs.walk(dep.baseDir, null, new Set(FOLDERS_IGNORE)); + bundleDependenciesFiles = bundleDependenciesFiles.concat(filesForBundledDep); + } + } } // `files` field @@ -109,6 +117,11 @@ export async function packTarball( // apply filters sortFilter(files, filters, keepFiles, possibleKeepFiles, ignoredFiles); + // add the files for the bundled dependencies to the set of files to keep + bundleDependenciesFiles.forEach(file => { + keepFiles.add(path.relative(config.cwd, file.absolute)); + }); + return packWithIgnoreAndHeaders( config.cwd, name => { diff --git a/yarn.lock b/yarn.lock index cdb3bfc04e..a2386304b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1254,6 +1254,13 @@ braces@^2.3.0, braces@^2.3.1: split-string "^3.0.2" to-regex "^3.0.1" +broccoli-kitchen-sink-helpers@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/broccoli-kitchen-sink-helpers/-/broccoli-kitchen-sink-helpers-0.3.1.tgz#77c7c18194b9664163ec4fcee2793444926e0c06" + dependencies: + glob "^5.0.10" + mkdirp "^0.5.1" + brorand@^1.0.1: version "1.1.0" resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f" @@ -2883,6 +2890,16 @@ glob@^4.3.1: minimatch "^2.0.1" once "^1.3.0" +glob@^5.0.10: + version "5.0.15" + resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1" + dependencies: + inflight "^1.0.4" + inherits "2" + minimatch "2 || 3" + once "^1.3.0" + path-is-absolute "^1.0.0" + glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2: version "7.1.2" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" @@ -3202,6 +3219,15 @@ hash-base@^2.0.0: dependencies: inherits "^2.0.1" +hash-for-dep@^1.2.3: + version "1.2.3" + resolved "https://registry.yarnpkg.com/hash-for-dep/-/hash-for-dep-1.2.3.tgz#5ec69fca32c23523972d52acb5bb65ffc3664cab" + dependencies: + broccoli-kitchen-sink-helpers "^0.3.1" + heimdalljs "^0.2.3" + heimdalljs-logger "^0.1.7" + resolve "^1.4.0" + hash.js@^1.0.0, hash.js@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.0.3.tgz#1332ff00156c0a0ffdd8236013d07b77a0451573" @@ -3226,6 +3252,19 @@ hawk@~6.0.2: hoek "4.x.x" sntp "2.x.x" +heimdalljs-logger@^0.1.7: + version "0.1.9" + resolved "https://registry.yarnpkg.com/heimdalljs-logger/-/heimdalljs-logger-0.1.9.tgz#d76ada4e45b7bb6f786fc9c010a68eb2e2faf176" + dependencies: + debug "^2.2.0" + heimdalljs "^0.2.0" + +heimdalljs@^0.2.0, heimdalljs@^0.2.3: + version "0.2.5" + resolved "https://registry.yarnpkg.com/heimdalljs/-/heimdalljs-0.2.5.tgz#6aa54308eee793b642cff9cf94781445f37730ac" + dependencies: + rsvp "~3.2.1" + hmac-drbg@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" @@ -4559,18 +4598,18 @@ minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" +"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + dependencies: + brace-expansion "^1.1.7" + minimatch@^2.0.1: version "2.0.10" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-2.0.10.tgz#8d087c39c6b38c001b97fca7ce6d0e1e80afbac7" dependencies: brace-expansion "^1.0.0" -minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4: - version "3.0.4" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" - dependencies: - brace-expansion "^1.1.7" - minimatch@~0.2.11: version "0.2.14" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.2.14.tgz#c74e780574f63c6f9a090e90efbe6ef53a6a756a" @@ -5552,6 +5591,12 @@ resolve@^1.1.6, resolve@^1.1.7: dependencies: path-parse "^1.0.5" +resolve@^1.4.0: + version "1.7.1" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.7.1.tgz#aadd656374fd298aee895bc026b8297418677fd3" + dependencies: + path-parse "^1.0.5" + restore-cursor@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-1.0.1.tgz#34661f46886327fed2991479152252df92daa541" @@ -5607,6 +5652,10 @@ ripemd160@^2.0.0, ripemd160@^2.0.1: hash-base "^2.0.0" inherits "^2.0.1" +rsvp@~3.2.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.2.1.tgz#07cb4a5df25add9e826ebc67dcc9fd89db27d84a" + run-async@^2.2.0: version "2.3.0" resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0" From 4cd93458db7b7f8d26c03036c0b5788f3f3e268a Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Sun, 10 Jun 2018 10:08:28 -0700 Subject: [PATCH 3/5] Unskip test for bundledDependencies --- __tests__/commands/pack.js | 6 ++++-- .../pack/bundled-dependencies/node_modules/a/package.json | 7 +++++++ .../pack/bundled-dependencies/node_modules/b/package.json | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 __tests__/fixtures/pack/bundled-dependencies/node_modules/a/package.json create mode 100644 __tests__/fixtures/pack/bundled-dependencies/node_modules/b/package.json diff --git a/__tests__/commands/pack.js b/__tests__/commands/pack.js index caff3b438e..a1ad0db983 100644 --- a/__tests__/commands/pack.js +++ b/__tests__/commands/pack.js @@ -160,8 +160,7 @@ test.concurrent('pack should exclude all files in dot-directories if not in file }); }); -// Broken: https://github.com/yarnpkg/yarn/issues/2636 -test.skip('pack should include bundled dependencies', (): Promise => { +test.concurrent('pack should include bundled dependencies', (): Promise => { return runPack([], {}, 'bundled-dependencies', async (config): Promise => { const {cwd} = config; const files = await getFilesFromArchive( @@ -171,6 +170,9 @@ test.skip('pack should include bundled dependencies', (): Promise => { const expected = [ 'index.js', 'package.json', + 'node_modules', + 'node_modules/a', + 'node_modules/b', path.join('node_modules', 'a', 'package.json'), path.join('node_modules', 'b', 'package.json'), ]; diff --git a/__tests__/fixtures/pack/bundled-dependencies/node_modules/a/package.json b/__tests__/fixtures/pack/bundled-dependencies/node_modules/a/package.json new file mode 100644 index 0000000000..be5b70f271 --- /dev/null +++ b/__tests__/fixtures/pack/bundled-dependencies/node_modules/a/package.json @@ -0,0 +1,7 @@ +{ + "name": "a", + "version": "1.0.0", + "dependencies": { + "b": "file:../b" + } +} diff --git a/__tests__/fixtures/pack/bundled-dependencies/node_modules/b/package.json b/__tests__/fixtures/pack/bundled-dependencies/node_modules/b/package.json new file mode 100644 index 0000000000..c2d84cc127 --- /dev/null +++ b/__tests__/fixtures/pack/bundled-dependencies/node_modules/b/package.json @@ -0,0 +1,4 @@ +{ + "name": "b", + "version": "1.0.0" +} From babda3511924a4950b01932cd63baba0d0ff0afe Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Mon, 11 Jun 2018 14:15:27 -0700 Subject: [PATCH 4/5] Fixing test case as os.tempdir would return a symlink --- src/cli/commands/pack.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cli/commands/pack.js b/src/cli/commands/pack.js index e294d5c1b4..c84e107387 100644 --- a/src/cli/commands/pack.js +++ b/src/cli/commands/pack.js @@ -118,9 +118,10 @@ export async function packTarball( sortFilter(files, filters, keepFiles, possibleKeepFiles, ignoredFiles); // add the files for the bundled dependencies to the set of files to keep - bundleDependenciesFiles.forEach(file => { - keepFiles.add(path.relative(config.cwd, file.absolute)); - }); + for (const file of bundleDependenciesFiles) { + const realPath = await fs.realpath(config.cwd); + keepFiles.add(path.relative(realPath, file.absolute)); + } return packWithIgnoreAndHeaders( config.cwd, From 9479172ddff95fc37cb34dc037c4dfe1de8ff198 Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Mon, 11 Jun 2018 22:23:31 -0700 Subject: [PATCH 5/5] Make tests pass on windows --- __tests__/commands/pack.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/commands/pack.js b/__tests__/commands/pack.js index a1ad0db983..cd825c67b8 100644 --- a/__tests__/commands/pack.js +++ b/__tests__/commands/pack.js @@ -171,8 +171,8 @@ test.concurrent('pack should include bundled dependencies', (): Promise => 'index.js', 'package.json', 'node_modules', - 'node_modules/a', - 'node_modules/b', + path.join('node_modules', 'a'), + path.join('node_modules', 'b'), path.join('node_modules', 'a', 'package.json'), path.join('node_modules', 'b', 'package.json'), ];