Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using process.cwd is problematic #159

Open
segevfiner opened this issue May 29, 2024 · 3 comments · May be fixed by #161
Open

Using process.cwd is problematic #159

segevfiner opened this issue May 29, 2024 · 3 comments · May be fixed by #161

Comments

@segevfiner
Copy link
Contributor

The cwd is something that is for the user to use and not necessarily where the app files are, the code should use __dirname instead, possibly correcting for the relative path of where pino gets bundled into the root of the out dir.

@segevfiner
Copy link
Contributor Author

Ohhh great, and the ESM fallback is also not working and throwing: Uncaught SyntaxError: Cannot use 'import.meta' outside a module due to using import.meta inside new Function as far as I can tell...

@segevfiner
Copy link
Contributor Author

And building pino to ESM with esbuild fails Error: Dynamic require of "os" is not supported due to evanw/esbuild#1921.

Why oh why does the JS ecosystem suck so bad...

@segevfiner
Copy link
Contributor Author

segevfiner commented May 29, 2024

Trying to generate different code depending on initialOptions.format seems to fail as import.meta.url causes esbuild to interpret the resulting pino.js code wrong and think it is ESM or something so it fails to find it's exports... We might need a virtual module to workaround this... Perhaps using a virtual module in the first place and requiring the user to import it is simpler anyhow, it also means you won't have to deal with sourcemaps which are currently broken for the pino.js module due to adding code to it...

Code I tried
        if (currentBuild.initialOptions.format === 'esm') {
          functionDeclaration = `
            function pinoBundlerAbsolutePath(p) {
              return new URL(p, import.meta.url).pathname;
            }
          `
        } else {
          functionDeclaration = `
            function pinoBundlerAbsolutePath(p) {
              return require('path').join(__dirname, p);
            }
          `
        }

@segevfiner segevfiner linked a pull request May 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant