Skip to content

Conversation

@JounQin
Copy link
Contributor

@JounQin JounQin commented Apr 8, 2025


go 1.24.1

require (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run go mod tidy.

"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"module-sync": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For require(ESM).

@reteps
Copy link
Owner

reteps commented Apr 9, 2025

@JounQin
Copy link
Contributor Author

JounQin commented Apr 9, 2025

Can we do a dynamic import here?

Could give it a try.

Copy link
Owner

@reteps reteps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets try a dynamic import before doing this.

return fs.readFile(
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
typeof __dirname === 'undefined'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cjs friendly.

"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@pkgr/rollup": "^6.0.2",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need rollup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR bundle cjs?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Maybe a separate build would work:
https://tduyng.com/blog/dual-package-typescript/

npx tsc -p tsconfig.lib.json --module NodeNext --outDir lib/esm
echo '{"type": "module"}' > lib/esm/package.json

npx tsc -p tsconfig.lib.json --module CommonJS --moduleResolution Node --outDir lib/cjs
echo '{"type": "commonjs"}' > lib/cjs/package.json

echo 'Compilation successful'

I'll see if I can play around with this later.

@JounQin JounQin deleted the feat/dual_pkg branch April 9, 2025 00:33
@JounQin
Copy link
Contributor Author

JounQin commented Apr 9, 2025

No need, this package can be ESM only.

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 this pull request may close these issues.

Cannot import dockerfmt

2 participants