tweaselORG / appstraction

An abstraction layer for common instrumentation functions (e.g. installing and starting apps, setting preferences, etc.) on Android and iOS.
MIT License
4 stars 1 forks source link

`postinstall` is broken on Windows #118

Open baltpeter opened 11 months ago

baltpeter commented 11 months ago

Error (this was when running npm i -g tweasel-cli):

npm ERR! code 1
npm ERR! path C:\Users\root\AppData\Roaming\npm\node_modules\tweasel-cli\node_modules\appstraction
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node scripts/postinstall.js; andromatic-install -p platform-tools 'build-tools;33.0.2'
npm ERR! node:internal/modules/cjs/loader:1078
npm ERR!   throw err;
npm ERR!   ^
npm ERR!
npm ERR! Error: Cannot find module 'C:\Users\root\AppData\Roaming\npm\node_modules\tweasel-cli\node_modules\appstraction\scripts\postinstall.js;'
npm ERR!     at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
npm ERR!     at Module._load (node:internal/modules/cjs/loader:920:27)
npm ERR!     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
npm ERR!     at node:internal/main/run_main_module:23:47 {
npm ERR!   code: 'MODULE_NOT_FOUND',
npm ERR!   requireStack: []
npm ERR! }
npm ERR!
npm ERR! Node.js v18.15.0

Full debug log: 2023-07-12T21_42_03_073Z-debug-0.log

baltpeter commented 11 months ago

As a workaround you can install like this: npm i appstraction --ignore-scripts.

This will skip the postinstall script and not preinstall the dependencies. But that isn't much of a problem. They are installed on demand anyway.

zner0L commented 11 months ago

It seems like the error is caused by the semicolon being considered part of the path in Powershell. If I separate the semicolon from the path with a space, the postinstall script runs.

zner0L commented 10 months ago

Aha, apparently npm on Windows doesn’t understand the semicolon at all and treats the second command as arguments of the first. Here is a minimal version to reproduce that:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "postinstall": "echo 'first'; echo 'second'"
  }
}

On Windows 10 PowerShell, we get:

PS C:\Users\user\Documents\test> npm run postinstall

> test@1.0.0 postinstall
> echo 'first'; echo 'second'

'first'; echo 'second'

While on a Fedora zsh this runs like expected:

❯ npm run postinstall

> test@1.0.0 postinstall
> echo 'first'; echo 'second'

first
second

It should be noted that this is not an issue with PowerShell, as this runs it just fine:

PS C:\Users\user\Documents\test> echo 'first'; echo 'second'
first
second

The problem is that the normal Windows cmd does not recognize ; a a special character. Windows uses & for that. && should work on both machines, though, so maybe let’s use that.

zner0L commented 10 months ago

The examples for Android seem to run fine on Windows, after I fixed the install.