Skip to content

Hoisting support in NodeModulesFS#500

Merged
arcanis merged 77 commits intomasterfrom
hoist
Nov 25, 2019
Merged

Hoisting support in NodeModulesFS#500
arcanis merged 77 commits intomasterfrom
hoist

Conversation

@larixer
Copy link
Copy Markdown
Member

@larixer larixer commented Oct 1, 2019

What's the problem this PR addresses?

This is an ongoing work to add hoisting support to NodeModulesFS and pnpify. The PR is just created as a heads up, the development is on early stages now.

How did you fix it?

At the moment draft abstract hoister has been implemented to the degree that some unit tests pass (the code quality and docs are still TBD). It is a divide and conquer algorithm with weights earlier discussed on discord.

@larixer larixer requested a review from arcanis November 22, 2019 10:40
Copy link
Copy Markdown
Member

@arcanis arcanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good to me - I left a few comments here and there to be sure we don't lose some context over the time, but the code is fairly understandable if we spend the time so I'm not too worried.

I'll rebase and merge, followups can be made in other PRs. Thanks for your incredible work!

Comment on lines +76 to +86
private persistPath(dir: PortablePath) {
const pathStack = [];
let curPath = dir;
while (!this.baseFs.existsSync(curPath)) {
pathStack.push(curPath);
curPath = ppath.dirname(curPath);
}
for (const fullPath of pathStack.reverse()) {
this.baseFs.mkdirSync(fullPath);
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would mkdir with recursive: true work?

Comment on lines +389 to +393
try {
fsDirList = await this.baseFs.readdirPromise(pnpPath.resolvedPath);
} catch (e) {
// Ignore errors
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned on Discord: some packages (like fsevents) seem to generate their own physical node_modules folders somehow, which then need to be concatenated with the virtual content.

* /home/user/project/node_modules/foo -> {target: '/home/user/project/.yarn/.cache/foo.zip/node_modules/foo', linkType: 'HARD'}
* /home/user/project/node_modules/bar -> {target: '/home/user/project/packages/bar', linkType: 'SOFT'}
*/
export type NodeModulesTree = Map<PortablePath, {dirList: Set<Filename>} | {dirList?: undefined, target: PortablePath, linkType: LinkType}>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dirList?: undefined 🤔


for (const [name, reference] of pkg.packageDependencies) {
if (reference !== null) {
const locator = typeof reference === 'string' ? {name, reference} : {name: reference[0], reference: reference[1]};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const locator = typeof reference === 'string' ? {name, reference} : {name: reference[0], reference: reference[1]};
const locator = pnp.getLocator(name, reference);

(new utility)

const allDepIds = new Set([...deps, ...peerDeps]);
for (const depId of allDepIds) {
const depPkg = packageInfos[depId];
if (depPkg) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is it false? Is it just for TS to be happy (if so I'd prefer an assertion)?

@arcanis arcanis merged commit 86afc2b into master Nov 25, 2019
@larixer larixer deleted the hoist branch November 25, 2019 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants