JamieMason / shrinkpack

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

install shrinkpack locally #100

Closed mbykov closed 4 months ago

mbykov commented 4 months ago

Description

I can not install shrinkpack without --global option, but I have to.

Suggested Solution

Help Needed

May be there is some method how to install and use shrinkpack locally?

When I have tried, it wrote "no package-lock.json or npm-shrinkwrap.json found"

If I create a symlink to /usr/local/bin, it wrote the same

JamieMason commented 4 months ago

Hi, You should be able to do this, it is the recommended way to install ~syncpack~ shrinkpack.

Let's install ~syncpack~ shrinkpack into a brand new, empty Node.js project;

# make some throw away folder
mkdir temp
# navigate to it
cd temp
# turn it into a Node.js project
npm init -y
# install syncpack
npm install --save-dev shrinkpack

What happens when you run these commands? (Or the equivalent commands if you are on Windows).

mbykov commented 4 months ago

temp> npm install --save-dev syncpack ? Why syncpack? temp> npm install --save-dev syncpack 130 ... up to date, audited 244 packages in 2s .... temp> npm install --save-dev shrinkpack ... added 145 packages, and audited 244 packages in 6s

temp> ./node_modules/.bin/shrinkpack node_modules - (I run it locally) ! no package-lock.json or npm-shrinkwrap.json found

JamieMason commented 4 months ago

Why syncpack?

My mistake, I had just been replying to issues on my other project syncpack before replying to you.

It is saying that "no package-lock.json or npm-shrinkwrap.json found", this could be because those files do not exist in the temp directory.

If you run ls -lah in the temp directory, what is listed?

mbykov commented 4 months ago

Jamie, ls -la is ok. I've done a dozen of tests

temp> ls -la итого 116 drwxr-xr-x 3 michael michael 4096 мая 7 21:08 . drwxr-xr-x 9 michael michael 4096 мая 7 21:07 .. drwxr-xr-x 198 michael michael 4096 мая 7 21:09 node_modules -rw-r--r-- 1 michael michael 301 мая 7 21:09 package.json -rw-r--r-- 1 michael michael 101553 мая 7 21:13 package-lock.json

JamieMason commented 4 months ago

Thanks @mbykov, I just tried it myself and it all seemed to work

``` [] ~/Dev/temp npm init -y Wrote to /Users/jmason/Dev/temp/package.json: { "name": "temp", "version": "0.0.0", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "Jamie Mason (https://github.com/JamieMason)", "license": "MIT", "description": "" } [] ~/Dev/temp ydd shrinkpack ✔ Choose the agent › npm npm warn deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs added 139 packages, and audited 140 packages in 4s 4 packages are looking for funding run `npm fund` for details found 0 vulnerabilities [] ~/Dev/temp node_modules/.bin/shrinkpack --help Usage: shrinkpack [options] [directory] Options: -V, --version output the version number -h, --help display help for command Icons: + Added - Removed i Information 12:34 Time Taken [] ~/Dev/temp node_modules/.bin/shrinkpack . ↓ @gar/promisify@1.1.3 ↓ @npmcli/fs@1.1.1 ↓ @npmcli/git@2.1.0 ↓ @npmcli/installed-package-contents@1.0.7 ↓ @npmcli/move-file@1.1.2 ↓ @npmcli/node-gyp@1.0.3 ↓ @npmcli/promise-spawn@1.3.2 ↓ @npmcli/run-script@2.0.0 ↓ @tootallnate/once@1.1.2 ↓ abbrev@1.1.1 ↓ agent-base@6.0.2 ↓ agentkeepalive@4.5.0 ↓ aggregate-error@3.1.0 ↓ ansi-regex@5.0.1 ↓ aproba@2.0.0 ↓ are-we-there-yet@3.0.1 ↓ balanced-match@1.0.2 ↓ brace-expansion@1.1.11 ↓ browserify-zlib@0.1.4 ↓ buffer-from@1.1.2 ↓ builtins@1.0.3 ↓ cacache@15.3.0 ↓ chownr@2.0.0 ↓ clean-stack@2.2.0 ↓ color-support@1.1.3 ↓ commander@8.3.0 ↓ concat-map@0.0.1 ↓ console-control-strings@1.1.0 ↓ core-util-is@1.0.3 ↓ debug@4.3.4 ↓ delegates@1.0.0 ↓ duplexify@3.7.1 ↓ readable-stream@2.3.8 ↓ safe-buffer@5.1.2 ↓ string_decoder@1.1.1 ↓ emoji-regex@8.0.0 ↓ encoding@0.1.13 ↓ end-of-stream@1.4.4 ↓ env-paths@2.2.1 ↓ err-code@2.0.3 ↓ fs-minipass@2.1.0 ↓ fs.realpath@1.0.0 ↓ gauge@4.0.4 ↓ glob@7.2.3 ↓ graceful-fs@4.2.11 ↓ gunzip-maybe@1.4.2 ↓ has-unicode@2.0.1 ↓ hosted-git-info@4.1.0 ↓ http-cache-semantics@4.1.1 ↓ http-proxy-agent@4.0.1 ↓ https-proxy-agent@5.0.1 ↓ humanize-ms@1.2.1 ↓ iconv-lite@0.6.3 ↓ ignore-walk@4.0.1 ↓ imurmurhash@0.1.4 ↓ indent-string@4.0.0 ↓ infer-owner@1.0.4 ↓ inflight@1.0.6 ↓ inherits@2.0.4 ↓ ip-address@9.0.5 ↓ is-deflate@1.0.0 ↓ is-fullwidth-code-point@3.0.0 ↓ is-gzip@1.0.0 ↓ is-lambda@1.0.1 ↓ isarray@1.0.0 ↓ isexe@2.0.0 ↓ jsbn@1.1.0 ↓ json-parse-even-better-errors@2.3.1 ↓ jsonparse@1.3.1 ↓ lru-cache@6.0.0 ↓ make-fetch-happen@9.1.0 ↓ minimatch@3.1.2 ↓ minipass@3.3.6 ↓ minipass-collect@1.0.2 ↓ minipass-fetch@1.4.1 ↓ minipass-flush@1.0.5 ↓ minipass-json-stream@1.0.1 ↓ minipass-pipeline@1.2.4 ↓ minipass-sized@1.0.3 ↓ minizlib@2.1.2 ↓ mkdirp@1.0.4 ↓ ms@2.1.2 ↓ negotiator@0.6.3 ↓ node-gyp@8.4.1 ↓ nopt@5.0.0 ↓ npm-bundled@1.1.2 ↓ npm-install-checks@4.0.0 ↓ npm-normalize-package-bin@1.0.1 ↓ npm-package-arg@8.1.5 ↓ npm-packlist@3.0.0 ↓ npm-pick-manifest@6.1.1 ↓ npm-registry-fetch@11.0.0 ↓ npmlog@6.0.2 ↓ once@1.4.0 ↓ p-map@4.0.0 ↓ pacote@12.0.2 ↓ pako@0.2.9 ↓ path-is-absolute@1.0.1 ↓ peek-stream@1.1.3 ↓ picocolors@1.0.0 ↓ process-nextick-args@2.0.1 ↓ promise-inflight@1.0.1 ↓ promise-retry@2.0.1 ↓ pump@2.0.1 ↓ pumpify@1.5.1 ↓ read-package-json-fast@2.0.3 ↓ readable-stream@3.6.2 ↓ retry@0.12.0 ↓ rimraf@3.0.2 ↓ safe-buffer@5.2.1 ↓ safer-buffer@2.1.2 ↓ semver@7.6.1 ↓ set-blocking@2.0.0 ↓ shrinkpack@0.20.0 ↓ signal-exit@3.0.7 ↓ smart-buffer@4.2.0 ↓ socks@2.8.3 ↓ socks-proxy-agent@6.2.1 ↓ sprintf-js@1.1.3 ↓ ssri@8.0.1 ↓ stream-shift@1.0.3 ↓ string_decoder@1.3.0 ↓ string-width@4.2.3 ↓ strip-ansi@6.0.1 ↓ tar@6.2.1 ↓ minipass@5.0.0 ↓ through2@2.0.5 ↓ readable-stream@2.3.8 ↓ safe-buffer@5.1.2 ↓ string_decoder@1.1.1 ↓ unique-filename@1.1.1 ↓ unique-slug@2.0.2 ↓ util-deprecate@1.0.2 ↓ validate-npm-package-name@3.0.0 ↓ which@2.0.2 ↓ wide-align@1.1.5 ↓ wrappy@1.0.2 ↓ xtend@4.0.2 ↓ yallist@4.0.0 shrinkpack +139 -0 00:05 [] ~/Dev/temp ```

BUT, I just noticed something, you are running the command on the node_modules directory but it should be run against the root of your project like so.

- ./node_modules/.bin/shrinkpack node_modules
+ ./node_modules/.bin/shrinkpack .

I think if you make that change it should be ok.

mbykov commented 4 months ago

Yes, great! So:

$ npm i shrinkpack (locally) $ ./node_modules/.bin/shrinkpack . (<- this . does the trick!)

Thank you!

JamieMason commented 4 months ago

You're welcome 👍 I've not worked on shrinkpack for a long time, so you may run into issues if anything major has changed in npm since then.