Skip to content

Build with tsc instead of tsup #842

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

Merged
merged 4 commits into from
Mar 18, 2025

Conversation

nwalters512
Copy link
Contributor

As reported in #836 (comment), my previous changes from #670 broke the ability for this package to be tree-shaken.

This PR takes the other approach I had proposed in #604: it runs tsc twice, once to produce a CJS build and once to produce an ESM one. It writes a package.json file containing {"type": "commonjs"} to dist/cjs/package.json so that the files in that directory are treated as CJS.

Since #670 introduced an exports field, the internal changes to paths shouldn't be visible to consumers, so this should be safe to release as a patch or minor version. That said, I wouldn't blame you if you wanted to release this as a major version to play it safe.

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@nene
Copy link
Collaborator

nene commented Mar 16, 2025 via email

@nene nene merged commit 6d8757d into sql-formatter-org:master Mar 18, 2025
2 checks passed
@@ -63,9 +63,10 @@
"prepare": "yarn clean && yarn grammar && yarn fix && yarn check && yarn build",
"pre-commit": "npm-run-all --parallel ts:changes lint:changes",
"grammar": "nearleyc src/parser/grammar.ne -o src/parser/grammar.ts",
"build:tsup": "tsup src/index.ts --format cjs,esm --sourcemap --dts",
"build:cjs": "tsc -p tsconfig.cjs.json && echo \"{\"type\": \"commonjs\"}\" > dist/cjs/package.json",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm... I think this doesn't work quite as intended. I generates a file containing:

{type: commonjs}

which isn't valid JSON. I tweaked it a bit: 14e5daf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch! Sorry about that.

@nene
Copy link
Collaborator

nene commented Mar 18, 2025

So I merged this in and released as 15.5.0-beta.1. Then fixed the package.json issue and released 15.5.0-beta.2.

@nwalters512 nwalters512 deleted the native-tsc-build branch March 18, 2025 12:25
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.

2 participants