nathanjhood / esbuild-scripts

esbuild-flavoured 'react-scripts'.
Other
0 stars 0 forks source link

Windows pipeline keeps freezing on 'Start' job #4

Closed nathanjhood closed 1 day ago

nathanjhood commented 1 day ago

As title.

I left the workflow running yesterday and clogged in this morning to see the Windows job failed after 5 hours of run time!

Just tried a re-run and had a similar stalling behaviour on the same step, same runner machine, etc.

My first thought is perhaps the positional args are not Win-friendly... but, the other steps such as yarn dev do pass.

A few things to do:

nathanjhood commented 1 day ago

Just tried on the Windows machine. Some wierd behaviour:

C:\<***>\esbuild-scripts [main ≡]> node ./dist/cli.js build
parseEnv('.env')
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

It might be the parsed cwd step failing. Need to do some debugging. Either way, the callback logic is getting messy and needs a rethink.

nathanjhood commented 1 day ago

Got it - so, by attempting to execute the file directly via hashbang, the Windows platform (when using Bash, per the pipeline, unlike above) attempts to open the script as some sort of media file type.

****@**** MINGW64 ~/esbuild-scripts (main)
$ yarn start build
yarn run v1.22.22
$ ./dist/cli.js build

The above results in the JS file being opened in my code editor, due to being associated with those file extensions :)

Using Bash on Windows; pointing Node at the script re-creates the error from Powershell:

****@**** MINGW64 ~/esbuild-scripts (main)
$ node ./dist/cli.js build
parseEnv('.env.local')
parseEnv('.env')
'C:/Program' is not recognized as an internal or external command,
operable program or batch file.

Obviously, Bash does not wish to parse the Windows-style path syntax.

nathanjhood commented 1 day ago

Located the problematic var:

joinedRtArgs

These are the flags and args that were originally passed to the underlying node instance; for example, when running a script via tsx these would be something psuedo-like this:

[
  'C:\\Program Files\\nodejs\\bin\\node.exe',
  '--require',
  'C:\\<path\\to\\project>\\node_modules\\tsx\\loader\\index.cjs',
  '--import',
  '<more stuff like the above, with possible broken paths...>'
]

I had already wondered whether these args should be tested somehow and parsed a bit further, but the logic could get unwieldy. The idea is to pass whatever runtime you're already using to run the chosen script with; with it's passed-in args and flags in tact.

This seems a bit messy, but parseArgs's tokenizing feature should make quite easy work of this. If the token is an --import or --require, optionally first use fs.existsSync to confirm the dependency is on disk (else, exit with a you need to yarn install first message ) and then parse it with path.resolve, to get the required format.

This is where the Promises and callbacks might turn out to be a regret. Let's see.

nathanjhood commented 1 day ago

Think I got it... thanks to this

Seems to be a spawn-specific thing. Adding extra string quotations and setting shell: false and we're passing on Powershell and Bash at home - when calling via tsx or node.

Let's see what the pipeline does.

nathanjhood commented 1 day ago

Still frozen when calling directly (instead of via node/tsx)... investigating.

nathanjhood commented 1 day ago

Turns out it's a fairly common thing with shebangs, Windows, and cmd.exe and the parser being called at runtime...

Pause for thought:

Remedy:

To validate the former, I'll need to consume this repo as an npm package, and it's not quiet in shape for that enough until I finish paths.ts

If the Windows pipeline succeeds by calling node/tsx directly, I will consider this a closed issue. It can be revisited if ever it turns out to be problematic later.