JamieMason / shrinkpack

Fast, resilient, reproducible builds with npm install.
https://www.npmjs.com/package/shrinkpack
MIT License
793 stars 38 forks source link

Handle local (file:) dependencies #84

Closed tmchng closed 2 years ago

tmchng commented 7 years ago

My project has dependency structure that looks like this: MainProject --> local_module_a --> local_module_b

Directory looks like this:

MainProject/
    package.json
    custom_modules/
        local_module_a/
            package.json
            custom_modules/
                local_module_b/

MainProject/package.json:

dependencies: {
  "local_module_a": "file: ./custom_modules/local_module_a"
}

local_module_a/package.json:

dependencies: {
  "local_module_b": "file: ./custom_modules/local_module_b"
}

After running shrinkpack, I saw that the local_modules are packed into tarballs, with shrinkwrap entries that look like the following:

...
  "local_module_a": {
    "version": "0.0.1",
    "from": "custom_modules/local_module_a,
    "resolved": "./node_shrinkwrap/local_module_a-0.0.1.tar"
  }
  "local_module_b": {
    "version": "0.0.1",
    "from": "custom_modules/local_module_a/custom_modules/local_module_b,
    "resolved": "./node_shrinkwrap/local_module_b-0.0.1.tar"
  }

When I run npm install, I get the following error:

44920 silly fetchOtherPackageData local_module_b@file:./custom_modules/local_module_b
44921 silly cache add args [ 'local_module_b@file:./custom_modules/local_module_b', null ]
44922 verbose cache add spec local_module_b@file:./custom_modules/local_module_b
44923 silly cache add parsed spec Result {
44923 silly cache add   raw: 'local_module_b@file:./custom_modules/local_module_b',
44923 silly cache add   scope: null,
44923 silly cache add   escapedName: 'local_module_b',
44923 silly cache add   name: 'local_module_b',
44923 silly cache add   rawSpec: 'file:./custom_modules/local_module_b',
44923 silly cache add   spec: '/Users/workspace/MainProject/node_shrinkwrap/local_module_a-0.0.1.tar/custom_modules/local_module_b',
44923 silly cache add   type: 'local' }
44924 error addLocal Could not install /Users/tmchng/workspace/MainProject/node_shrinkwrap/local_module_a-0.0.1.tar/custom_modules/local_module_b
44925 silly fetchPackageMetaData Error: ENOTDIR: not a directory, open '/Users/tmchng/workspace/MainProject/node_shrinkwrap/local_module_a-0.0.1.tar/custom_modules/local_module_b'
44925 silly fetchPackageMetaData     at Error (native)
44925 silly fetchPackageMetaData  error for local_module_b@file:./custom_modules/local_module_b { Error: ENOTDIR: not a directory, open '/Users/tmchng/workspace/MainProject/node_shrinkwrap/local_module_a-0.0.1.tar/custom_modules/local_module_b'
44925 silly fetchPackageMetaData     at Error (native)
44925 silly fetchPackageMetaData   errno: -20,
44925 silly fetchPackageMetaData   code: 'ENOTDIR',
44925 silly fetchPackageMetaData   syscall: 'open',
44925 silly fetchPackageMetaData   path: '/Users/tmchng/workspace/MainProject/node_shrinkwrap/local_module_a-0.0.1.tar/custom_modules/local_module_b' }
44926 silly rollbackFailedOptional Starting
44927 silly rollbackFailedOptional Finishing
44928 silly runTopLevelLifecycles Finishing
44929 silly install printInstalled
44930 verbose stack Error: ENOTDIR: not a directory, open '/Users/tmchng/workspace/MainProject/node_shrinkwrap/local_module_a-0.0.1.tar/custom_modules/local_module_b'
44930 verbose stack     at Error (native)
44931 verbose cwd /Users/tmchng/workspace/MainProject
44932 error Darwin 14.5.0
44933 error argv "/Users/tmchng/.nvm/versions/node/v6.11.0/bin/node" "/Users/tinghaoc/.nvm/versions/node/v6.11.0/bin/npm" "install"
44934 error node v6.11.0
44935 error npm  v3.10.10
44936 error path /Users/tmchng/workspace/MainProject/node_shrinkwrap/local_module_a-0.0.1.tar/custom_modules/local_module_b
44937 error code ENOTDIR
44938 error errno -20
44939 error syscall open
44940 error ENOTDIR: not a directory, open '/Users/tmchng/workspace/MainProject/node_shrinkwrap/local_module_a-0.0.1.tar/custom_modules/local_module_b'
44941 error If you need help, you may report this error at:
44941 error     <https://github.com/npm/npm/issues>
44942 verbose exit [ -20, true ]

I then tried editing the npm-shrinkwrap.json file and change local_module's resolved path to "file: ./..." instead of tarballs, and npm install ran successfully.

The modified shrinkwrap entries:

...
  "local_module_a": {
    "version": "0.0.1",
    "resolved": "file:./custom_modules/local_module_a
  }
  "local_module_b": {
    "version": "0.0.1",
    "resolved": "file:./custom_modules/local_module_a/custom_modules/local_module_b
  }

I'm using node v6.11.0 / npm v3.10.10

JamieMason commented 7 years ago

Thanks @tmchng, this is a valid use case but not one that I've accounted for so far. This would be a new feature and one that I'm happy to add when I next get time to work on shrinkpack.

JamieMason commented 6 years ago

This is still known about and will be picked up in the new codebase after #83 is released.

JamieMason commented 2 years ago

shrinkpack@0.19.0 has been released which adds support for npm 7 and up. This should now be working as I think this was related to the npm 5 issues.