fauna-labs / fauna-schema-migrate

The Fauna Schema Migrate tool helps you set up Fauna resources as code and perform schema migrations.
MIT No Attribution
88 stars 11 forks source link

Prevent module system errors from commonjs in the default config file #117

Closed zioroboco closed 6 months ago

zioroboco commented 2 years ago

If fauna-schema-migrate init is run in a project which has already indicated that it is using esmodules (by setting "type": "module" in the nearest package.json file), the resulting default .fauna-migrate.js file will be treated as an esmodule by the node runtime.

Since the generated file uses commonjs modules, this causes an immediate runtime error.

By changing the file extension to .cjs, we're telling the node runtime to expect commonjs modules in this file regardless of whether the parent project is using esmodules.

An alternative approach would be to match the parent project's module system in the generated code.