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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/sql-formatter-cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict';

const { format, supportedDialects } = require('../dist/index.cjs');
const { format, supportedDialects } = require('../dist/cjs/index.js');
const fs = require('fs');
const path = require('path');
const tty = require('tty');
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"version": "15.4.11",
"description": "Format whitespace in a SQL query to make it more readable",
"license": "MIT",
"main": "dist/index.cjs",
"module": "dist/index.js",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"unpkg": "dist/sql-formatter.min.js",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.cjs"
}
},
"bin": {
Expand Down Expand Up @@ -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.

"build:esm": "tsc -p tsconfig.esm.json",
"build:webpack": "webpack --config webpack.prod.js && cp dist/sql-formatter.min.cjs dist/sql-formatter.min.js",
"build": "yarn grammar && npm-run-all --parallel build:tsup build:webpack",
"build": "yarn grammar && npm-run-all --parallel build:cjs build:esm build:webpack",
"release": "release-it"
},
"repository": {
Expand Down Expand Up @@ -111,7 +112,6 @@
"rimraf": "^3.0.2",
"ts-jest": "^28.0.5",
"ts-loader": "^9.3.1",
"tsup": "^8.0.1",
"typescript": "^4.7.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.9.1",
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist/cjs",
"module": "CommonJS"
},
"include": ["src"]
}
8 changes: 8 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist/esm",
"module": "NodeNext"
},
"include": ["src"]
}
9 changes: 5 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "es6",
"lib": ["es6", "dom"],
"rootDirs": ["src"],
"outDir": "lib",
"baseUrl": "./",
"sourceMap": true,
"declaration": true,
"esModuleInterop": true,
"strict": true /* enable all strict type-checking options */,
/* Additional Checks */
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */
// Enable all strict type-checking options.
"strict": true,
// Report error when not all code paths in function return a value.
"noImplicitReturns": true
},
"include": ["src", "test", "static"],
"exclude": ["node_modules"]
Expand Down
13 changes: 12 additions & 1 deletion webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ export default {
{
test: /\.ts$/u,
exclude: /node_modules/u,
use: ['babel-loader', 'ts-loader'],
use: [
'babel-loader',
{
loader: 'ts-loader',
options: {
// Prevent `ts-loader` from emitting types to the `lib` directory.
// This also disables type-checking, which is already performed
// independently of the webpack build process.
transpileOnly: true,
},
},
],
},
{
test: /\.js$/u,
Expand Down
Loading