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

Yarn Plug'n'Play: Implementation #6382

Merged
merged 206 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
206 commits
Select commit Hold shift + click to select a range
71f1419
Initial pnp implementation
Feb 19, 2018
b942722
Adds the pnp-env directory for quick checks
Feb 19, 2018
efb50be
Improves the "yarn node" command so that it works with pnp
Feb 28, 2018
9ba4b7e
Adds the pnp tests to the pkg-tests testsuite
Feb 28, 2018
3711775
Fixes various issues with the pnp map generation
Feb 28, 2018
51adb4c
Remove the scriptsPrependNodePath option
Mar 1, 2018
961d242
Adds tests to ensure that the lifecycle scripts are called with the r…
Mar 1, 2018
cf9dd1a
Fixes linting
Mar 1, 2018
17e3d68
Improve the error message when an optional required dependency hasn't…
Mar 1, 2018
882055d
Implements lifecycle wrappers
Mar 1, 2018
951bb66
Merge pull request #9 from arcanis/lifecycle-wrappers-remove-option
arcanis Mar 2, 2018
bb7046d
Merge pull request #8 from arcanis/lifecycle-wrappers-tests
arcanis Mar 2, 2018
8a9f113
Merge pull request #7 from arcanis/lifecycle-wrappers-flowlint
arcanis Mar 2, 2018
bed982a
Merge pull request #10 from arcanis/lifecycle-wrappers-improve-pnp-error
arcanis Mar 2, 2018
abaf7f4
Merge pull request #11 from arcanis/lifecycle-wrappers-main
arcanis Mar 2, 2018
0bdb6dd
Adds .pnp.js files to the gitignore
Mar 2, 2018
cf0902c
Merge pull request #12 from arcanis/gitignore-pnp
cpojer Mar 2, 2018
b9f8eaf
Fallbacks to the toplevel dependencies when a transitive dependency c…
Mar 2, 2018
f087c13
Merge pull request #13 from arcanis/pnp-fallback
arcanis Mar 2, 2018
40972bc
Fixes an issue inside the pkg-tests helper
Mar 2, 2018
cf00d52
Improves the fixtures so that they also return info about their dev a…
Mar 2, 2018
26ebad1
Finishes to hide plugnplay behind a yarnrc option (`plugnplay-experim…
Mar 2, 2018
a011d7b
Adds failing tests for pnp peer dependencies
Mar 2, 2018
2c32963
Merge pull request #15 from arcanis/pkg-tests-helper-definition
arcanis Mar 2, 2018
009fc45
Merge pull request #14 from arcanis/dev-peer-fixtures
arcanis Mar 2, 2018
8a94aff
Merge pull request #16 from arcanis/option-plugnplay-experimental
arcanis Mar 2, 2018
20a2a2f
Merge pull request #17 from arcanis/pnp-peer-dependencies-failing
arcanis Mar 2, 2018
e7d2f99
Prettifies the generated pnp files
Mar 5, 2018
08fce0a
Merge pull request #20 from arcanis/prettify-pnp
cpojer Mar 5, 2018
9db30e4
Adds the plugnplay flag to the integrity check
Mar 5, 2018
bdf60d9
Removes the pnp file at link-time if installing with pnp disabled
Mar 5, 2018
7eb4521
Improves pnp maps compatibility
Mar 5, 2018
6d10cc0
Prevents "yarn check" from checking the node_modules existence when u…
Mar 5, 2018
9fa12cd
Adds a missing package to the request cache
Mar 5, 2018
c2f2abe
Merge pull request #21 from arcanis/pnp-integrity
arcanis Mar 5, 2018
6551486
Fixes tests
Mar 6, 2018
da25857
Reimplements the resolution to correctly account for peer dependencies
Mar 6, 2018
8fea70b
Externalizes the creation of proxy scripts
Mar 7, 2018
8e77876
Implements support for `yarn run` within pnp-enabled installations
Mar 9, 2018
e4cd98f
Merge pull request #22 from arcanis/pnp-fix-tests
arcanis Mar 9, 2018
09865d7
Merge pull request #23 from arcanis/better-faster-stronger
arcanis Mar 9, 2018
4a6eb41
Merge pull request #24 from arcanis/portable-proxy-scripts
arcanis Mar 9, 2018
d0a03a8
Merge pull request #25 from arcanis/pnp-yarn-run
arcanis Mar 9, 2018
6daa57c
Makes it possible for dependency binaries to require their own depend…
Mar 9, 2018
968e231
Merge pull request #26 from arcanis/pnp-yarn-run-dependencies
arcanis Mar 9, 2018
fddf91c
Moves the pnp embed api into its own file
Mar 9, 2018
37d6b5a
Merge pull request #27 from arcanis/pnp-api-split
arcanis Mar 9, 2018
2ef5f05
Adds the test folder to Jest error messages
Mar 11, 2018
e8a27c7
Improves peer dependency tests
Mar 11, 2018
062e9f8
Adds tests for require.resolve
Mar 12, 2018
0728eba
Refactors the pnp file
Mar 12, 2018
a5c3e03
Updates the build-webpack script to include a custom resolver
Mar 12, 2018
41f0003
Fixes tests
Mar 12, 2018
5216bae
Merge pull request #28 from arcanis/jest-better-message
arcanis Mar 14, 2018
6b9d3fb
Merge pull request #29 from arcanis/peer-deps-tests
arcanis Mar 14, 2018
667a6c5
Merge pull request #30 from arcanis/require-resolve-tests
arcanis Mar 14, 2018
4e2d492
Merge pull request #31 from arcanis/pnp-file-refactoring
arcanis Mar 14, 2018
3380175
Merge pull request #32 from arcanis/webpack-resolver
arcanis Mar 14, 2018
4f34c0e
Merge pull request #33 from arcanis/fix-tests
arcanis Mar 14, 2018
ff25ef9
Generates virtual when using peer dependencies
Mar 15, 2018
11ebf79
Refactors the generated pnp files to use the newly generated maps
Mar 16, 2018
cf362e5
Adds tests for workspaces
Mar 16, 2018
4b491e0
Implements Module._findPath
Mar 16, 2018
b8e3b40
Fixes top level detection
Mar 16, 2018
a67372e
Merge pull request #39 from arcanis/virtual-packages
arcanis Mar 19, 2018
a878fbe
Merge pull request #35 from arcanis/pnp-refactor-find
arcanis Mar 19, 2018
b9a16b4
Merge pull request #36 from arcanis/module-findpath
arcanis Mar 19, 2018
49aa987
Merge pull request #37 from arcanis/fix-top-level-detection
arcanis Mar 19, 2018
91a2050
Implements workspaces support in pnp
Mar 21, 2018
2c3abee
Merge pull request #40 from arcanis/pnp-workspaces
arcanis Mar 22, 2018
82e00e6
Automatically adds workspaces as dependencies of the top-level
Mar 23, 2018
fd745e7
Updates the cache path to include the 'node_modules' string
Mar 23, 2018
ff45d9a
Prevents pnp from bootstrapping when running non-pnp-installed scripts
Mar 23, 2018
bf2a116
Installs peer dependencies symlinks inside a project folder
Mar 23, 2018
3818f46
Merge pull request #41 from arcanis/auto-workspace-dependencies
arcanis Mar 27, 2018
7bf140b
Merge pull request #42 from arcanis/node-modules-cache
arcanis Mar 27, 2018
66b2252
Merge pull request #43 from arcanis/fix-npm-run
arcanis Mar 27, 2018
1bd53fb
Merge pull request #44 from arcanis/per-project-virtual-deps
arcanis Mar 27, 2018
b1d59c1
Adds a sample application that showcases webpack, babel, react, jest
Apr 4, 2018
71a8a56
Ignores the .pnp directory
Apr 4, 2018
85f3e6d
Implements a blacklist that throws nicer errors when a package is req…
Apr 4, 2018
ebf93b3
Changes the order the locations are matched to package locators
Apr 4, 2018
406affa
Automatically adds packages as dependencies of themselves if possible
Apr 4, 2018
a58e77b
Updates the node resolution
Apr 4, 2018
824798f
Ensures that binaries are set as executable in the cache
Apr 6, 2018
67edc56
Disables integrity checks when running under pnp
Apr 12, 2018
b2256f4
Makes the .pnp.js file an actual executable that can be used as a res…
Apr 12, 2018
5e55ef1
Merge pull request #48 from arcanis/sample-app
arcanis Apr 16, 2018
96eb983
Merge pull request #47 from arcanis/ignore-pnp
arcanis Apr 16, 2018
f452a03
Merge pull request #46 from arcanis/location-blacklist
arcanis Apr 16, 2018
7be256a
Merge pull request #51 from arcanis/location-to-locator-match-order
arcanis Apr 16, 2018
f4ea197
Merge pull request #50 from arcanis/implicit-self
arcanis Apr 16, 2018
211dbcc
Merge pull request #49 from arcanis/node-resolution-improvements
arcanis Apr 16, 2018
a5cef0d
Merge pull request #52 from arcanis/chmod-bins
arcanis Apr 16, 2018
ff91c43
Merge pull request #53 from arcanis/pnp-no-integrity
arcanis Apr 16, 2018
764c666
Merge pull request #54 from arcanis/pnp-executable
arcanis Apr 16, 2018
155a2a9
Removes pnp-env
Apr 16, 2018
8ddc6f3
Merge remote-tracking branch 'yarnpkg/master'
Apr 16, 2018
159380f
Merge pull request #55 from arcanis/rm-pnp-env
arcanis Apr 16, 2018
0561fba
Merge pull request #56 from arcanis/yarnpkg-merge
arcanis Apr 16, 2018
7ce0c98
Fixes a few tests
Apr 16, 2018
b1fb4fb
Merge pull request #57 from arcanis/fix-bugs
arcanis Apr 17, 2018
532403b
Merge remote-tracking branch 'yarnpkg/master'
Apr 25, 2018
aa4168c
Merge remote-tracking branch 'yarnpkg/master'
Apr 30, 2018
1821693
Fixes snapshots
Apr 30, 2018
be9641a
Fixes the lockfile not being written when using pnp
Apr 25, 2018
7552c6b
Fixes the `yarn node` command being incorrectly forwarded arguments
Apr 25, 2018
1cb1af8
Uses symlinks instead of a script for bin indirection to allow callin…
Apr 25, 2018
bb2244a
Adds a `yarn bin <name>` command that returns the path of the specifi…
Apr 25, 2018
75eb881
Implements an --into option to yarn node/yarn run
Apr 25, 2018
8a41330
Implements the `--pnp` option
Apr 25, 2018
e3426c5
Adds new tests for checking that packages are correctly locked
Apr 30, 2018
8e04f9d
Merge pull request #58 from arcanis/fix-lockfile
arcanis May 1, 2018
2ffb593
Merge pull request #59 from arcanis/fix-yarn-node
arcanis May 1, 2018
ffcef36
Merge pull request #60 from arcanis/bin-symlinks
arcanis May 1, 2018
76bb4d7
Merge pull request #61 from arcanis/yarn-bin-name
arcanis May 1, 2018
dd09a6c
Merge pull request #62 from arcanis/opt-into
arcanis May 1, 2018
f6f719a
Merge pull request #63 from arcanis/pnp-option
arcanis May 1, 2018
8cbc12c
Merge pull request #67 from arcanis/lock-tests
arcanis May 1, 2018
666de0f
Bugfixes
May 1, 2018
2f82e75
Fixes workspace registration
May 1, 2018
4494106
Uses --enable-pnp (alias --pnp) and --disable-pnp
May 3, 2018
5ddadbc
Merge pull request #68 from arcanis/bugfixes
arcanis May 9, 2018
f4aa5c4
Merge pull request #69 from arcanis/workspace-registration-fix
arcanis May 9, 2018
87d0ea2
Merge pull request #70 from arcanis/instalconfig-pnp
arcanis May 9, 2018
4ba0073
Adds the issuer into the error messages when requesting a package one…
May 9, 2018
e447dc9
Implements extendedQualifiedPathResolution
May 11, 2018
a1959f4
Merge pull request #71 from arcanis/via-issuer
arcanis May 24, 2018
f6f1cc7
Merge pull request #72 from arcanis/extended-qualified-path-resolution
arcanis May 24, 2018
34669c8
Merge remote-tracking branch 'origin/via-issuer'
May 24, 2018
355efd1
Changes the return of the pnp daemon to return json data
May 29, 2018
c9f3000
Merge pull request #73 from arcanis/json-output
arcanis May 29, 2018
c2cc8cb
Implements custom shebangs for the pnp file
May 30, 2018
96bbb61
Merge pull request #74 from arcanis/shebang
arcanis May 31, 2018
5183077
Changes the return of the pnp-exposed functions to return null with b…
May 31, 2018
cf35187
Merge pull request #75 from arcanis/builtins
arcanis Jun 11, 2018
5911b1a
Merge remote-tracking branch 'yarnpkg/master'
Jun 11, 2018
5b1d56a
Merge remote-tracking branch 'yarnpkg/master'
Jun 11, 2018
07f1cbb
Various fixes & improvements
Jun 12, 2018
679deb0
Adds a test, prettier, fixes a test
Jun 12, 2018
ee96006
Don't iterate on the registries
Jun 12, 2018
3b47060
Merge pull request #76 from arcanis/various-fixes
arcanis Jun 13, 2018
b69efe4
Merge remote-tracking branch 'yarnpkg/master'
Jun 13, 2018
d29120d
Renames YARN_PLUGNPLAY_EXPERIMENTAL into YARN_PLUGNPLAY_OVERRIDE
Jun 21, 2018
7cf5c8e
Avoids touching the .pnp.js file when it doesn't need to change
Jun 21, 2018
be34944
Merge pull request #77 from arcanis/env-override
arcanis Jun 26, 2018
87ffdd7
Merge pull request #78 from arcanis/avoid-overwrite
arcanis Jun 26, 2018
bae51f5
Reworks the cache path to contain the "node_modules/<pkg-name>" string
Jun 21, 2018
4501644
Merge pull request #79 from arcanis/node-modules-cache
arcanis Jun 26, 2018
60752b5
Shims resolve#isCore
Jun 26, 2018
3ba32a3
Merge pull request #81 from arcanis/resolve-is-core
cpojer Jun 26, 2018
9d132be
Improves error messages
Jun 26, 2018
8484400
Merge pull request #82 from arcanis/better-error-messages
arcanis Jun 26, 2018
254c8a0
Fixes the environment cast to allow passing false/0
Jul 2, 2018
a63e850
Merge pull request #83 from arcanis/fix-cast
arcanis Jul 2, 2018
1645e22
Implements a pnp blacklist settings
Jul 10, 2018
1a8f7aa
Merge pull request #84 from arcanis/ignore-regex
arcanis Jul 12, 2018
c2c3142
Fixes the fallback resolution to use _resolveFilename instead of _fin…
Jul 12, 2018
2c2ccfd
Fixes fallback relative path resolution
Jul 12, 2018
3c14719
Merge pull request #85 from arcanis/fallback-resolution-fix
arcanis Jul 12, 2018
6e46e78
Implements require.cache
Jul 16, 2018
1dc047d
Merge pull request #86 from arcanis/require-cache
arcanis Jul 19, 2018
225976f
Merge remote-tracking branch 'yarnpkg/master'
Aug 8, 2018
d5b12f1
Merge pull request #88 from arcanis/merge-080818
cpojer Aug 8, 2018
1a498f8
Prevents pnp from being enabled on Windows
Aug 10, 2018
f5374de
Merge pull request #90 from arcanis/disable-win32
arcanis Aug 15, 2018
8923227
Merge remote-tracking branch 'yarnpkg/master'
Aug 15, 2018
03fcd14
Merge remote-tracking branch 'yarnpkg/master'
Aug 17, 2018
df61b90
Removes absolute paths from the pnp files
Aug 10, 2018
30f1860
Merge pull request #89 from arcanis/relative-pnp-file
arcanis Aug 21, 2018
f46a763
Implements a super basic offline cache integration
Aug 15, 2018
304f4ea
Merge pull request #91 from arcanis/offline-cache
arcanis Aug 23, 2018
b9ee7d9
Merge pull request #93 from arcanis/relative-pnp-file
arcanis Aug 23, 2018
6e15b0b
Merge remote-tracking branch 'yarnpkg/master'
Aug 23, 2018
dba71ee
feat(pnp): eject package command (#92)
imsnif Aug 24, 2018
428f9ae
Fixes yarn bin
Aug 24, 2018
b8f4796
Merge pull request #94 from arcanis/fix-yarn-bin
arcanis Aug 24, 2018
bdef391
Preserves the node_modules components in zip paths
Aug 24, 2018
6ee42c1
Fixes the offline cache
Aug 29, 2018
9dbb226
Merge pull request #95 from arcanis/offline-cache-fixes
arcanis Aug 31, 2018
143a462
Adds a VERSIONS field into the generated resolver
Sep 6, 2018
d1f46ea
Exposes the "extensions" option to "resolveRequest"
Sep 6, 2018
2d94b06
Renames yarn eject into yarn unplug
Sep 6, 2018
9bd6143
Merge pull request #98 from arcanis/eject-into-unplug
arcanis Sep 6, 2018
c72bf0f
Merge pull request #96 from arcanis/resolverequest-extensions
arcanis Sep 6, 2018
dc9e82d
Merge pull request #97 from arcanis/versioning
arcanis Sep 6, 2018
6492fed
Tweaks yarn unplug
Sep 7, 2018
f1c8a1b
Removes packageMainEntry from the package information
Sep 10, 2018
8b8e4f5
Merge pull request #100 from arcanis/remove-main-entry
arcanis Sep 11, 2018
d78961c
Makes "unplug" print the list of unplugged packages
Sep 10, 2018
6a609ee
Merge pull request #99 from arcanis/unplug-clear
arcanis Sep 11, 2018
48c8640
Merge remote-tracking branch 'yarnpkg/master'
Sep 13, 2018
56bc811
Unplugs postinstall packages automatically
Sep 14, 2018
41a9743
Renames things
Sep 24, 2018
02bd204
Adds a warning on Windows to notify that PnP settings are ignored at …
Sep 24, 2018
e7c7aa1
Fixes the default shebang
Sep 24, 2018
7cd35f1
Exports pnpapi
Sep 24, 2018
d9a7104
Reworks the resolve shim to only affect liftoff
Sep 24, 2018
77ffbbd
Guards the pnp file against fs extensions
Sep 24, 2018
6309d1f
Fixes the resolve shim
Sep 24, 2018
84358aa
Fixes a broken test
Sep 24, 2018
e1559bb
Re-enables the focus tests
Sep 24, 2018
4325ca1
Stops relying on bash for test scripts
Sep 24, 2018
48328a6
Fixes nohoist
Sep 24, 2018
f17f25e
Revert "Fixes a broken test"
Sep 24, 2018
2cf11d4
Ensures that the getPackageInformation function returns an absolute path
Sep 24, 2018
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
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"stage-0"
],
"plugins": [
["babel-plugin-inline-import", { "extensions": [ ".tpl.js" ] }],
["transform-inline-imports-commonjs"],
["transform-runtime", { "polyfill": false, "regenerator": true }]
]
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ test/fixtures/**/.fbkpm
/__tests__/fixtures/request-cache/GET/localhost/.bin
.idea
.yarn-meta
.pnp.js
.pnp
/packages/lockfile/index.js
.vscode/
2 changes: 1 addition & 1 deletion __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ test('changes the cache path when bumping the cache version', () =>

await mockConstants(config, {CACHE_VERSION: 42}, async config => {
await cache(config, reporter, {}, ['dir']);
expect((JSON.parse(String(inOut.read())): any).data).toMatch(/[\\\/]v42[\\\/]?$/);
expect((JSON.parse(String(inOut.read())): any).data).toMatch(/[\\\/]v42([\\\/].*)?$/);
});
}));

Expand Down
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions __tests__/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ test('relative cache folder', async () => {

const [stdoutOutput, _] = await runYarn(['cache', 'dir'], {cwd: `${base}/sub`});

// The dirname is to remove the "v2" part
expect(await fs.realpath(path.dirname(stdoutOutput.toString()))).toEqual(await fs.realpath(`${base}/foo`));
});

Expand Down
10 changes: 5 additions & 5 deletions __tests__/lifecycle-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ async function execCommand(cmd: string, packageName: string, env = process.env):

test.concurrent('should add the global yarnrc arguments to the command line', async () => {
const stdout = await execCommand('cache dir', 'yarnrc-cli');
expect(stdout.replace(/\\/g, '/')).toMatch(/^(C:)?\/tmp\/foobar\/v[0-9]+\n$/);
expect(stdout.replace(/\\/g, '/')).toMatch(/^(C:)?\/tmp\/foobar\/v[0-9]+(\/.*)?\n$/);
});

test.concurrent(
'should add the command-specific yarnrc arguments to the command line if the command name matches',
async () => {
const stdout = await execCommand('cache dir', 'yarnrc-cli-command-specific-ok');
expect(stdout.replace(/\\/g, '/')).toMatch(/^(C:)?\/tmp\/foobar\/v[0-9]+\n$/);
expect(stdout.replace(/\\/g, '/')).toMatch(/^(C:)?\/tmp\/foobar\/v[0-9]+(\/.*)?\n$/);
},
);

test.concurrent("should not add the command-specific yarnrc arguments if the command name doesn't match", async () => {
const stdout = await execCommand('cache dir', 'yarnrc-cli-command-specific-ko');
expect(stdout.replace(/\\/g, '/')).not.toMatch(/^(C:)?\/tmp\/foobar\/v[0-9]+\n$/);
expect(stdout.replace(/\\/g, '/')).not.toMatch(/^(C:)?\/tmp\/foobar\/v[0-9]+(\/.*)?\n$/);
});

test.concurrent('should allow overriding the yarnrc values from the command line', async () => {
const stdout = await execCommand('cache dir --cache-folder /tmp/toto', 'yarnrc-cli');
expect(stdout.replace(/\\/g, '/')).toMatch(/^(C:)?\/tmp\/toto\/v[0-9]+\n$/);
expect(stdout.replace(/\\/g, '/')).toMatch(/^(C:)?\/tmp\/toto\/v[0-9]+(\/.*)?\n$/);
});

// Test disabled for now, cf rc.js
test.concurrent('should resolve the yarnrc values relative to where the file lives', async () => {
const stdout = await execCommand('cache dir', 'yarnrc-cli-relative');
expect(stdout.replace(/\\/g, '/')).toMatch(/^(C:)?(\/[^\/]+)+\/foobar\/hello\/world\/v[0-9]+\n$/);
expect(stdout.replace(/\\/g, '/')).toMatch(/^(C:)?(\/[^\/]+)+\/foobar\/hello\/world\/v[0-9]+(\/.*)?\n$/);
});

test.concurrent(
Expand Down
6 changes: 3 additions & 3 deletions __tests__/package-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;

const path = require('path');

// regexp which verifies that cache path contains semver + hash
const cachePathRe = /-\d+\.\d+\.\d+-[\dabcdef]{40}$/;
// regexp which verifies that the cache path contains a path component ending with semver + hash
const cachePathRe = /-\d+\.\d+\.\d+-[\dabcdef]{40}[\\\/]/;

async function createEnv(configOptions): Object {
const lockfile = new Lockfile();
Expand Down Expand Up @@ -82,7 +82,7 @@ addTest(
'@foo/bar@1.2.3',
'npm',
async cacheFolder => {
const folder = path.join(cacheFolder, 'npm-@foo', 'bar');
const folder = path.join(cacheFolder, 'npm-@foo-bar', 'node_modules', '@foo', 'bar');
await fs.mkdirp(folder);
await fs.writeFile(
path.join(folder, constants.METADATA_FILENAME),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"babel-eslint": "^7.2.3",
"babel-loader": "^6.2.5",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-inline-import": "^2.0.6",
"babel-plugin-transform-builtin-extend": "^1.1.2",
"babel-plugin-transform-inline-imports-commonjs": "^1.0.0",
"babel-plugin-transform-runtime": "^6.4.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/pkg-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"babel-preset-env": "^1.6.1",
"babel-preset-flow": "^6.23.0",
"flow-bin": "^0.66.0",
"jest": "^22.3.0",
"jest": "^23.0.0",
"prettier": "^1.10.2"
},
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions packages/pkg-tests/pkg-tests-core/sources/utils/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ exports.readJson = async function readJson(source: string): Promise<any> {
}
};

exports.chmod = function chmod(target: string, mod: number): Promise<void> {
return fs.chmod(target, mod);
exports.chmod = async function chmod(target: string, mod: number): Promise<void> {
await fs.chmod(target, mod);
};

exports.realpath = function realpath(source: string): Promise<string> {
return fs.realpath(source);
};

exports.makeFakeBinary = async function(
Expand Down
45 changes: 37 additions & 8 deletions packages/pkg-tests/pkg-tests-core/sources/utils/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export type PackageRunDriver = (

export type PackageDriver = any;

let whitelist = new Map();

exports.setPackageWhitelist = async function whitelistPackages(
packages: Map<string, Set<string>>,
fn: () => Promise<void>,
) {
whitelist = packages;
await fn();
whitelist = new Map();
};

exports.getPackageRegistry = function getPackageRegistry(): Promise<PackageRegistry> {
if (getPackageRegistry.promise) {
return getPackageRegistry.promise;
Expand Down Expand Up @@ -182,7 +193,12 @@ exports.startPackageServer = function startPackageServer(): Promise<string> {
return processError(res, 404, `Package not found: ${name}`);
}

const versions = Array.from(packageEntry.keys());
let versions = Array.from(packageEntry.keys());

const whitelistedVersions = whitelist.get(name);
if (whitelistedVersions) {
versions = versions.filter(version => whitelistedVersions.has(version));
}

const data = JSON.stringify({
name,
Expand Down Expand Up @@ -300,29 +316,42 @@ exports.generatePkgDriver = function generatePkgDriver({runDriver}: {|runDriver:
}

return async function(): Promise<void> {
const path = await fsUtils.createTemporaryFolder();
const path = await fsUtils.realpath(await fsUtils.createTemporaryFolder());

const registryUrl = await exports.startPackageServer();

// Writes a new package.json file into our temporary directory
await fsUtils.writeJson(`${path}/package.json`, await deepResolve(packageJson));

const run = (...args) => {
let callDefinition = {};

if (args.length > 0 && typeof args[args.length - 1] === 'object') {
callDefinition = args.pop();
}

return runDriver(path, args, {
registryUrl,
...definition,
...subDefinition,
...callDefinition,
});
};

const source = async script => {
return JSON.parse((await run('node', '-p', `JSON.stringify(${script})`)).stdout.toString());
return JSON.parse((await run('node', '-p', `JSON.stringify((() => ${script})())`)).stdout.toString());
};

await fn({
path,
run,
source,
});
try {
await fn({
path,
run,
source,
});
} catch (error) {
error.message = `Temporary fixture folder: ${path}\n\n` + error.message;
throw error;
}
};
};

Expand Down
8 changes: 5 additions & 3 deletions packages/pkg-tests/pkg-tests-fixtures/default-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

console.log(process.cwd());
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

const secret = require('./secret');

console.log(secret);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node

const noDeps = require('no-deps');

console.log(noDeps.name);
console.log(noDeps.version);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

for (let t = 2; t < process.argv.length; ++t) {
console.log(process.argv[t]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "has-bin-entries",
"version": "1.0.0",
"bin": {
"has-bin-entries": "./bin.js",
"has-bin-entries-with-require": "./bin-with-require.js",
"has-bin-entries-with-relative-require": "./bin-with-relative-require.js",
"has-bin-entries-get-pwd": "./bin-get-pwd.js"
},
"dependencies": {
"no-deps": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 42;
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of Object.keys(module.exports.dependencies || {})) {
module.exports.dependencies[key] = require(key);
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Loading