Skip to content

Commit

Permalink
fix: link peer deps should handle scope package path (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Apr 20, 2023
1 parent 9cd91e8 commit 8176d5d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/install_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ async function _install(parentDir, pkg, ancestors, options, context) {
const key = `install:${peer.name}@${peer.version}`;
const c = options.cache[key];
if (c) {
const linkDir = path.join(realPkgDir, `../${c.package.name}`);
// scoped package
const relativePath = pkg.name && pkg.name.startsWith('@') ?
`../../${c.package.name}` : `../${c.package.name}`;
const linkDir = path.join(realPkgDir, relativePath);
const relative = await utils.forceSymlink(c.dir, linkDir);
debug('%s link peer package(%s@%s) %s => %s, parentDir: %s',
displayName, c.package.name, c.package.version, linkDir, relative, realPkgDir);
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/hotfix-emotion-react/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
console.log(
require.resolve('@emotion/react'),
!!require('@emotion/react')
);
11 changes: 11 additions & 0 deletions test/fixtures/hotfix-emotion-react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "hotfix-emotion-react",
"version": "1.0.0",
"scripts": {
"postinstall": "node index.js"
},
"dependencies": {
"@emotion/react": "latest",
"react": "latest"
}
}
10 changes: 10 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ describe('test/index.test.js', () => {
assert(await exists(path.join(root, 'node_modules/.store/@babel+preset-react@7.18.6/node_modules/@babel/plugin-transform-react-jsx')));
});

it('should install @emotion/react with react, fix link pear deps bug', async () => {
const root = helper.fixtures('hotfix-emotion-react');
await rimraf(path.join(root, 'node_modules'));
await npminstall({
root,
});
assert(await isInstallDone(path.join(root, 'node_modules/@emotion/react')));
assert.equal(require(path.join(root, 'node_modules/@emotion/react/package.json')).name, '@emotion/react');
});

it('should npminstall with options.pkgs', async () => {
await npminstall({
root: tmp,
Expand Down

0 comments on commit 8176d5d

Please sign in to comment.