cspotcode / npm-pwsh

Install PowerShell via npm for use in npm scripts or elsewhere.
12 stars 5 forks source link

Doesn't work with pnpm package manager #14

Closed fearthecowboy closed 5 years ago

fearthecowboy commented 5 years ago

I'm getting errors when installing via pnpm -- which I only used because a project was using it.

some of what went wrong. Not sure this helps...

registry.npmjs.org/get-powershell/0.1.1  | postinstall$ node ./npm_lifecycle_postinstall.js
registry.npmjs.org/get-powershell/0.1.1  | postinstall:   syscall: 'lstat',
registry.npmjs.org/get-powershell/0.1.1  | postinstall:   path: 'C:\\work\\2018\\autorest.incubator\\common\\temp\\node_modules\\.registry.npmjs.org\\get-powe
registry.npmjs.org/get-powershell/0.1.1  | postinstall: Exited with 1
 ERROR  get-powershell@0.1.1 postinstall: `node ./npm_lifecycle_postinstall.js`
Exit status 1
at Error: get-powershell
at <anonymous>            Users/garretts/.rush/pnpm-2.15.1/node_modules/pnpm/lib/node_modules/@zkochan/npm-lifecycle/index.js:301     var er = new Error('Exit…
at emitTwo                events.js:126
at emit                   events.js:214
at <anonymous>            Users/garretts/.rush/pnpm-2.15.1/node_modules/pnpm/lib/node_modules/@zkochan/npm-lifecycle/lib/spawn.js:55  cooked.emit('close', cod…
at emitTwo                events.js:126
at emit                   events.js:214
at maybeClose             internal/child_process.js:915
at on                     internal/child_process.js:336
at emitOne                events.js:116
at emit                   events.js:211

The command failed:
 C:\work\2018\autorest.incubator\common\temp\pnpm-local\node_modules\.bin\pnpm install --no-optional --store C:\work\2018\autorest.incubator\common\temp\pnpm-st
ore --no-lock --no-prefer-frozen-shrinkwrap --strict-peer-dependencies
fearthecowboy commented 5 years ago

Yarn, does work, and rather well.

cspotcode commented 5 years ago

Thanks for the log output. However, it appears truncated. Can you post the full install log? Usually get-powershell does some logging, but it looks like what you posted is output from pnpm that happens after my code has already finished.

fearthecowboy commented 5 years ago

I couldn't get much more out of it.


file:../npm-get-powershell/get-powershell-0.1.1.tgz | postinstall$ node ./npm_lifecycle_postinstall.js
file:../npm-get-powershell/get-powershell-0.1.1.tgz | postinstall:   syscall: 'lstat',
file:../npm-get-powershell/get-powershell-0.1.1.tgz | postinstall:   path: 'C:\\work\\2018\\test-pnpm\\node_modules\\.local\\C%3A%2Fwork%2F2018%2Fnpm-get-powershell%2Fget-powershell-0.1.1.tgz\\node_modules\\.bin\\pwsh.cmd' }
file:../npm-get-powershell/get-powershell-0.1.1.tgz | postinstall: Exited with 1
 ERROR  get-powershell@0.1.1 postinstall: `node ./npm_lifecycle_postinstall.js`
Exit status 1
at Error: get-powershell
at <anonymous>            Users/garretts/AppData/Local/nvs/node/8.12.0/x64/node_modules/pnpm/lib/node_modules/@zkochan/npm-lifecycle/index.js:301     var er = new Error('Exit…
at emitTwo                events.js:126
at emit                   events.js:214
at <anonymous>            Users/garretts/AppData/Local/nvs/node/8.12.0/x64/node_modules/pnpm/lib/node_modules/@zkochan/npm-lifecycle/lib/spawn.js:55  cooked.emit('close', cod…
at emitTwo                events.js:126
at emit                   events.js:214
at maybeClose             internal/child_process.js:915
at on                     internal/child_process.js:336
at emitOne                events.js:116
at emit                   events.js:211
C:\work\2018\test-pnpm> dir .\node_modules\.local\C%3A%2Fwork%2F2018%2Fnpm-get-powershell%2Fget-powershell-0.1.1.tgz\node_modules\

it should be easy enough to reproduce:

npm install -g pnpm
mkdir ./test-it
cd ./test-it
pnpm install get-powershell
# or pnpm install ../path/to/npm-get-powershell/get-powershell-0.1.1.tgz

And it'll fail.

As far as I can tell, pnpm is doing some weird stuff with the .bin folder (it isn't where getNpmBinDirectory() expects it) and the script fails later on.

I hacked in a quick and dirty:

 // Local installation: find the local node_modules/.bin
    else {
        if(process.env.npm_lifecycle_event) {
           // get the path to the .bin folder 
           const p = Path.resolve(__root, '../.bin');
           // force-create it.
            fs.mkdirSync(p);

           // write a couple empty files to make the rest of the script happy
            fs.writeFileSync(`${p}/pwsh.cmd`,"");
            fs.writeFileSync(`${p}/pwsh`,"");

            // return as normal.
            return Path.resolve(p);
        } else {
            // This only happens when we're testing
            return Path.resolve(__root, 'test-bin');
        }
    }

That got it working, but only because it fakes out the .bin detection enough to do the right thing.

fearthecowboy commented 5 years ago

I think pnpm likes to install things in an isolated location, let the installation finish, and then move things into place.. (don't quote me on that) ...

oh... it likes to symlink everything once it's done:

S C:\work\2018\test-pnpm> junction -s *

Junction v1.06 - Windows junction creator and reparse point viewer
Copyright (C) 2000-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

\\?\C:\work\2018\test-pnpm\node_modules\get-powershell: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.local\C%3A%2Fwork%2F2018%2Fnpm-get-powershell%2Fget-powershell-0.1.1.tgz\node_modules\get-powershell
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.local\C%3A%2Fwork%2F2018%2Fnpm-get-powershell%2Fget-powershell-0.1.1.tgz\node_modules\get-powershell\

\\?\C:\work\2018\test-pnpm\node_modules\.local\C%3A%2Fwork%2F2018%2Fnpm-get-powershell%2Fget-powershell-0.1.1.tgz\node_modules\tar: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\tar\4.4.6\node_modules\tar
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\tar\4.4.6\node_modules\tar\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\fs-minipass\1.2.5\node_modules\minipass: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minipass\2.3.4\node_modules\minipass
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minipass\2.3.4\node_modules\minipass\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minipass\2.3.4\node_modules\safe-buffer: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\safe-buffer\5.1.2\node_modules\safe-buffer
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\safe-buffer\5.1.2\node_modules\safe-buffer\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minipass\2.3.4\node_modules\yallist: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\yallist\3.0.2\node_modules\yallist
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\yallist\3.0.2\node_modules\yallist\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minizlib\1.1.0\node_modules\minipass: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minipass\2.3.4\node_modules\minipass
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minipass\2.3.4\node_modules\minipass\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\mkdirp\0.5.1\node_modules\minimist: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minimist\0.0.8\node_modules\minimist
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minimist\0.0.8\node_modules\minimist\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\tar\4.4.6\node_modules\chownr: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\chownr\1.1.1\node_modules\chownr
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\chownr\1.1.1\node_modules\chownr\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\tar\4.4.6\node_modules\fs-minipass: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\fs-minipass\1.2.5\node_modules\fs-minipass
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\fs-minipass\1.2.5\node_modules\fs-minipass\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\tar\4.4.6\node_modules\minipass: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minipass\2.3.4\node_modules\minipass
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minipass\2.3.4\node_modules\minipass\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\tar\4.4.6\node_modules\minizlib: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minizlib\1.1.0\node_modules\minizlib
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\minizlib\1.1.0\node_modules\minizlib\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\tar\4.4.6\node_modules\mkdirp: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\mkdirp\0.5.1\node_modules\mkdirp
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\mkdirp\0.5.1\node_modules\mkdirp\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\tar\4.4.6\node_modules\safe-buffer: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\safe-buffer\5.1.2\node_modules\safe-buffer
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\safe-buffer\5.1.2\node_modules\safe-buffer\

\\?\C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\tar\4.4.6\node_modules\yallist: JUNCTION
   Print Name     : C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\yallist\3.0.2\node_modules\yallist
   Substitute Name: C:\work\2018\test-pnpm\node_modules\.registry.npmjs.org\yallist\3.0.2\node_modules\yallist\

PS C:\work\2018\test-pnpm>
cspotcode commented 5 years ago

Thank you, now that I repro it myself, I see what you mean. No output.

I'm guessing fs.realpathSync(linkPath) is failing. That's the only time I actually access that directory myself, and it's not even necessary now that I look at the code again. I'll add a graceful fallback, test, and if it works, push a new version.

fearthecowboy commented 5 years ago

Any progress on that? I've got some hacks in place on my project, but i have to push to CI soon, and the hacks won't work there. ... ( 😁 🚀 🏆 🍻 🤕 )

cspotcode commented 5 years ago

Fix is written (was only a couple lines) but I won't be able to publish till Wednesday afternoon. I've gotta sanity-check that the new tests are passing. Writing automated tests for these package managers sucks on my machine, because package installations touch boatloads of files, and my corporate-mandated virus scanner decides it's gotta check ALL of them. No joke, it just about kills my laptop, and I can't afford that till my on-call rotation ends. :(

I pushed the code so you can take a look. In the meantime, you might be able to install from a .tgz that you make yourself. I'm not sure.

fearthecowboy commented 5 years ago

You could always publish it and tag it 'preview' so that it doesn't show up for anyone.

Yeah, I hear you with the virus scanners... the worst part is, it's not the scan time that's the problem, it's per file overhead.

That's why I wrote the static-link package to make it so when AutoRest installs, all it's code is in a single file (and the code doesn't know it's repackaged)... we run it in CI so much that it was killing us.

Brought down the install time (on windows) from 80 seconds to less than five.

fearthecowboy commented 5 years ago

Any chance we have of getting this published as a package? I really need to take a dependency on it in my CI environment, and inserting a .tgz there is gonna kill me.

Even tagging it with a special tag would be ok.

Otherwise, I'd have to fork it and publish it under an organization (to keep it out of the global pkg repo); and I'd rather not do that.

cspotcode commented 5 years ago

Yep, I'll be at the office in 1/2 he, then I can run a publish.

On Wed, Oct 24, 2018, 12:29 PM Garrett Serack notifications@github.com wrote:

Any chance we have of getting this published as a package? I really need to take a dependency on it in my CI environment, and inserting a .tgz there is gonna kill me.

Even tagging it with a special tag would be ok.

Otherwise, I'd have to fork it and publish it under an organization (to keep it out of the global pkg repo); and I'd rather not do that.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/cspotcode/npm-get-powershell/issues/14#issuecomment-432730151, or mute the thread https://github.com/notifications/unsubscribe-auth/AAW-uCltuyZsFLgQa8dAce7-B-ozmHyrks5uoJVmgaJpZM4XK-zx .