storyblok / field-plugin

Create and deploy Storyblok Field Plugin
https://www.storyblok.com/docs/plugins/field-plugins/introduction
25 stars 3 forks source link

fix(cli): replace __dirname #281

Closed eunjae-lee closed 11 months ago

eunjae-lee commented 11 months ago

What?

This PR replaces __dirname with something else.

Why?

I ran yarn bump-version, but got this error:

➜ yarn bump-version
/Users/eunjae/workspace/field-plugin/packages/cli/config.ts:38
export const TEMPLATES_PATH = resolve(__dirname, 'templates')
                                      ^

ReferenceError: __dirname is not defined in ES module scope
    at <anonymous> (/Users/eunjae/workspace/field-plugin/packages/cli/config.ts:38:39)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.16.0

I'm not sure if I understand this issue 100% exactly. From my understanding, our library and the CLI gets transpiled to CJS. So using __dirname doesn't cause any problem.

However, when running bump-version.ts, it's run in ESM scope. And __dirname doesn't exist there. To work around this issue, we're not using __dirname any more, and replace it another way. However I didn't replace all the other __dirname occurrences in vite config files, and etc (that won't be executed in ESM scope).

How to test? (optional)

vercel[bot] commented 11 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plugin-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 9:16am
BibiSebi commented 11 months ago

Interesting, thank you for the explanation.