firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.42k stars 136 forks source link

Fix json import #1424

Closed ekohilas closed 1 week ago

ekohilas commented 2 weeks ago

Reopening of #1422

In Node 18.18, the following error occurs:

npx --yes gitlab-ci-local@latest                                                                                                                                                 
file:///Users/username/.npm/_npx/3f18f2096def1b34/node_modules/gitlab-ci-local/src/index.js:13
import packageJson from "../package.json" with { type: "json" };
                                          ^^^^

SyntaxError: Unexpected token 'with'
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:119:18)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:468:14)
    at async link (node:internal/modules/esm/module_job:68:21)

Node.js v18.18.2

This PR fixes the issue by converting json imports to instead use readfilesync and JSON.parse instead, which makes it more explicit and avoids this error.

This fix allows users who may otherwise not be able to update to Node v18.20 overnight to continue using this tool.

Thanks again!

firecow commented 1 week ago

@ANGkeith You sure we wanna keep node 18 support?

ANGkeith commented 1 week ago

hmm not really, but at least for now, does'nt seem like there is too much incompatibility.