Skip to content

feat: make it dual package friendly - #7

Closed
JounQin wants to merge 1 commit into
reteps:mainfrom
JounQin:feat/dual_pkg
Closed

JounQin wants to merge 1 commit into
reteps:mainfrom
JounQin:feat/dual_pkg

Conversation

@JounQin

@JounQin JounQin commented Apr 8, 2025 •

Copy link
Copy Markdown
Contributor

Comment thread go.mod

go 1.24.1

require (

Copy link
Copy Markdown
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.

Comment thread js/package.json
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"module-sync": {

Copy link
Copy Markdown
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).

@JounQin

JounQin commented Apr 9, 2025

Copy link
Copy Markdown
Contributor Author

Can we do a dynamic import here?

Could give it a try.

@reteps reteps left a comment

Copy link
Copy Markdown
Owner

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.

Comment thread js/index.ts
return fs.readFile(
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
typeof __dirname === 'undefined'

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cjs friendly.

Comment thread js/package.json
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@pkgr/rollup": "^6.0.2",

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

JounQin commented Apr 9, 2025

Copy link
Copy Markdown
Contributor Author

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