Permalink
Browse files

fix: packages can require themself

node_modules structure changed
  • Loading branch information...
1 parent f678dd5 commit 59cd8cbede82a6830bd9310d6b8648b65c47df10 @zkochan zkochan committed Jan 11, 2017
Showing with 20 additions and 10 deletions.
  1. +9 −9 README.md
  2. +3 −1 src/install/installMultiple.ts
  3. +8 −0 test/install.ts
View
@@ -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/
```
@@ -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/<pkgname>. 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) {
View
@@ -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'))
+})

0 comments on commit 59cd8cb

Please sign in to comment.