Skip to content

Commit

Permalink
Revert "fix(nm): Properly hoist nested workspaces (yarnpkg#3438)"
Browse files Browse the repository at this point in the history
This reverts commit ab203be.
  • Loading branch information
quickgiant committed Sep 27, 2022
1 parent 8a82356 commit ba59190
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 350 deletions.
1 change: 0 additions & 1 deletion .github/workflows/e2e-nm-babel-workflow.yml
Expand Up @@ -51,6 +51,5 @@ jobs:
source scripts/e2e-setup-ci.sh nm
git clone https://github.com/babel/babel.git
cd babel
yarn config unset yarnPath
NM_DEBUG_LEVEL=1 yarn
shell: bash
2 changes: 0 additions & 2 deletions CHANGELOG.md
Expand Up @@ -39,8 +39,6 @@ Yarn now accepts sponsorships! Please give a look at our [OpenCollective](https:
- Direct portal dependencies for `node_modules` installs will now be given priority during hoisting, preventing cases when indirect regular dependencies would block the way for direct portal dependencies.
- The `pnpify` binary can now be used from inside directories containing spaces.
- The CLI bundles built from sources will now output the commit hash instead of the tree hash, as part of their `--version` string.
- Nested workspaces are properly hoisted by `node-modules` linker.
- Self-referencing symlinks won't be created for anonymous workspaces when using the `node-modules` linker, since they cannot be used from the code anyway.
- The cache is now fully atomic when moving files across devices, and is more efficient in general.
- The PnP patch will now properly pick up changes to the `fs` module, allowing users to patch it.
- When using PnP, `require.resolve('pnpapi')` will be handled correctly even when using `exports`.
Expand Down
115 changes: 6 additions & 109 deletions packages/acceptance-tests/pkg-tests-specs/sources/node-modules.test.ts
Expand Up @@ -743,17 +743,19 @@ describe(`Node_Modules`, () => {
{
nodeLinker: `node-modules`,
},
async ({path, run}) => {
async ({path, run, source}) => {
await writeJson(npath.toPortablePath(`${path}/foo/package.json`), {
name: `foo`,
version: `1.0.0`,
workspaces: [`bar`],
dependencies: {
bar: `workspace:*`,
'no-deps': `1.0.0`,
},
});
await writeJson(npath.toPortablePath(`${path}/foo/bar/package.json`), {
name: `bar`,
version: `1.0.0`,
workspaces: [`bar`],
peerDependencies: {
'no-deps': `*`,
},
Expand Down Expand Up @@ -1390,13 +1392,13 @@ describe(`Node_Modules`, () => {


test(
`should fallback to dependencies if the parent doesn't provide the peer dependency`,
`it should fallback to dependencies if the parent doesn't provide the peer dependency`,
makeTemporaryEnv(
{},
{
nodeLinker: `node-modules`,
},
async ({path, run}) => {
async ({path, run, source}) => {
const appPath = ppath.join(path, `lib-1` as Filename);
const libPath = ppath.join(path, `lib-2` as Filename);

Expand Down Expand Up @@ -1432,109 +1434,4 @@ describe(`Node_Modules`, () => {
},
),
);

it(`should not create self-referencing symlinks for anonymous workspaces`,
makeTemporaryEnv(
{
},
{
nodeLinker: `node-modules`,
},
async ({path, run}) => {
await run(`install`);

const entries = await xfs.readdirPromise(ppath.join(path, `node_modules` as Filename), {withFileTypes: true});
let symlinkCount = 0;
for (const entry of entries) {
if (entry.isSymbolicLink()) {
symlinkCount++;
}
}

expect(symlinkCount).toBe(0);
},
),
);

it(`should properly hoist nested workspaces`,
makeTemporaryEnv(
{
workspaces: [`ws`, `ws/nested1`, `ws/nested1/nested2`],
dependencies: {
ws: `workspace:*`,
nested1: `workspace:*`,
nested2: `workspace:*`,
},
},
{
nodeLinker: `node-modules`,
},
async ({path, run, source}) => {
await xfs.mkdirpPromise(ppath.join(path, `ws/nested1/nested2` as PortablePath));

await xfs.writeJsonPromise(ppath.join(path, `ws/${Filename.manifest}` as PortablePath), {
name: `ws`,
dependencies: {
[`no-deps`]: `1.0.0`,
},
});

await xfs.writeJsonPromise(ppath.join(path, `ws/nested1/${Filename.manifest}` as PortablePath), {
name: `nested1`,
dependencies: {
[`no-deps`]: `2.0.0`,
},
});

await xfs.writeJsonPromise(ppath.join(path, `ws/nested1/nested2/${Filename.manifest}` as PortablePath), {
name: `nested2`,
dependencies: {
[`no-deps`]: `2.0.0`,
},
});

await run(`install`);

await expect(source(`require('no-deps')`)).resolves.toMatchObject({
version: `1.0.0`,
});
await expect(source(`require('module').createRequire(require.resolve('nested1/package.json') + '/..')('no-deps')`)).resolves.toMatchObject({
version: `2.0.0`,
});
},
),
);

it(`should install project when portal is pointing to a workspace`,
makeTemporaryEnv(
{
workspaces: [`ws1`, `ws2`],
},
{
nodeLinker: `node-modules`,
},
async ({path, run, source}) => {
await xfs.mkdirpPromise(ppath.join(path, `ws1` as PortablePath));
await xfs.writeJsonPromise(ppath.join(path, `ws1/${Filename.manifest}` as PortablePath), {
name: `ws1`,
devDependencies: {
[`no-deps`]: `1.0.0`,
},
});
await xfs.mkdirpPromise(ppath.join(path, `ws2` as PortablePath));
await xfs.writeJsonPromise(ppath.join(path, `ws2/${Filename.manifest}` as PortablePath), {
name: `ws2`,
devDependencies: {
[`ws1`]: `portal:../ws1`,
},
});

await run(`install`);

await expect(source(`require('no-deps')`)).resolves.toMatchObject({
version: `1.0.0`,
});
},
),
);
});

0 comments on commit ba59190

Please sign in to comment.