Skip to content

Support pnpm-style directory layout #53

@Toxaris

Description

@Toxaris

napi-postinstall expects to require.resolve the optional dependencies of another package, but in a pnpm-style directory layout, a package can only require.resolve its own dependencies.

Details:

We are using a pnpm-style directory layout in a build sandbox that doesn't have internet access, and as part of updating Jest we run into an issue with the use of napi-postinstall in unrs-resolver.

The platform is linux-x64-gnu so we need the @unrs/resolver-binding-linux-x64-gnu package. We checked the build sandbox and see that this package is indeed installed as an optional dependency of unrs-resolver.

However, due to the pnpm-style directory-layout, it is not visible to the require.resolve in line 331 of src/index.ts.

That is, we have the following directory structure in our build sandbox:

  • a/node_modules/unrs-resolver contains the unrs-resolver package
  • a/node_modules/@unrs/resolver-binding-linux-x64-gnu is a symlink to b/node_modules/@unrs-resolver-binding-linux-x64-gnu
  • a/node_modules/napi-postinstall is a symlink to c/node_modules/napi-postinstall
  • b/node_modules/@unrs/resolver-binding-linux-x64-gnu contains the @unrs/resolver-binding-linux-x64-gnu package
  • c/node_modules/napi-postinstall contains the napi-postinstall package

So the optional dependency has been correctly installed into a/node_modules, but the require.resolve is in a file below c/node_nodules and cannot see it. The fallback to download the package also fails due to the missing Internet access in the build sandbox (rightly so, because we don't want to download random files during the build).

We are creating the pnpm-style directory layout with our own tooling, but it should be possible to also reproduce this with pnpm by setting hoist to false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions