From 59cd8cbede82a6830bd9310d6b8648b65c47df10 Mon Sep 17 00:00:00 2001 From: zkochan Date: Wed, 11 Jan 2017 08:45:14 +0200 Subject: [PATCH] fix: packages can require themself node_modules structure changed --- README.md | 18 +++++++++--------- src/install/installMultiple.ts | 4 +++- test/install.ts | 8 ++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 52c31da295..09806de021 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ See [store layout](docs/store-layout.md) for an explanation. -> - a symlink (or junction on Windows) ~/.store - ├─ chalk/1.1.1/ + ├─ chalk/1.1.1/node_modules/chalk/ | ├─ index.js | └─ package.json - ├─ ansi-styles/2.1.0/ + ├─ ansi-styles/2.1.0/node_modules/chalk/ | ├─ index.js | └─ package.json - └─ has-ansi/2.0.0/ + └─ has-ansi/2.0.0/node_modules/chalk/ ├─ index.js └─ package.json . @@ -52,14 +52,14 @@ See [store layout](docs/store-layout.md) for an explanation. | | ├─ node_modules/ | | | ├─ ansi-styles/ -> ../../ansi-styles/2.1.0/ | | | └─ has-ansi/ -> ../../has-ansi/2.0.0/ - | | ├─ index.js => ~/.store/chalk/1.1.1/index.js - | | └─ package.json => ~/.store/chalk/1.1.1/package.json + | | ├─ index.js => ~/.store/chalk/1.1.1/node_modules/chalk/index.js + | | └─ package.json => ~/.store/chalk/1.1.1/node_modules/chalk/package.json | ├─ has-ansi/2.0.0/ - | | ├─ index.js => ~/.store/has-ansi/2.0.0/index.js - | | └─ package.js => ~/.store/has-ansi/2.0.0/package.json + | | ├─ index.js => ~/.store/has-ansi/2.0.0/node_modules/has-ansi/index.js + | | └─ package.js => ~/.store/has-ansi/2.0.0/node_modules/has-ansi/package.json | └─ ansi-styles/2.1.0/ - | ├─ index.js => ~/.store/ansi-styles/2.1.0/index.js - | └─ package.js => ~/.store/ansi-styles/2.1.0/package.json + | ├─ index.js => ~/.store/ansi-styles/2.1.0/node_modules/ansi-styles/index.js + | └─ package.js => ~/.store/ansi-styles/2.1.0/node_modules/ansi-styles/package.json └─ chalk/ -> ./.resolutions/chalk/1.1.1/ ``` diff --git a/src/install/installMultiple.ts b/src/install/installMultiple.ts index 389ff844ba..1ba43bddb3 100644 --- a/src/install/installMultiple.ts +++ b/src/install/installMultiple.ts @@ -118,7 +118,9 @@ async function install (pkgRawSpec: string, modules: string, ctx: InstallContext optional: options.optional === true, pkg, // TODO: what about bundled/cached deps? - hardlinkedLocation: path.join(options.nodeModulesStore, fetchedPkg.id), + // The package realpath should be under node_modules/. This way, babel-runtime@5 can + // require('babel-runtime') within itself. + hardlinkedLocation: path.join(options.nodeModulesStore, fetchedPkg.id, 'node_modules', pkg.name), }) if (dependency.fromCache || keypath.indexOf(dependency.id) !== -1) { diff --git a/test/install.ts b/test/install.ts index bec7c61f46..645119308e 100644 --- a/test/install.ts +++ b/test/install.ts @@ -841,3 +841,11 @@ test('shrinkwrap locks npm dependencies', async function (t) { t.equal(pkg.version, '100.0.0', 'dependency specified in shrinkwrap.yaml is installed') }) + +test('self-require should work', async function (t) { + const project = prepare(t) + + await installPkgs(['uses-pkg-with-self-usage'], testDefaults()) + + t.ok(project.requireModule('uses-pkg-with-self-usage')) +})