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

Bundle with tsup #670

Merged
merged 2 commits into from
Nov 23, 2023
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/sql-formatter.min.cjs');
const { format, supportedDialects } = require('../dist/index.cjs');
const fs = require('fs');
const tty = require('tty');
const { version } = require('../package.json');
Expand Down
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
"version": "14.0.0",
"description": "Format whitespace in a SQL query to make it more readable",
"license": "MIT",
"main": "dist/sql-formatter.min.cjs",
"main": "dist/index.cjs",
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 now uses the un-minified, non-UMD bundle. I think this is ok; unpkg will continue using the minified+UMD bundle produced by webpack.

"module": "dist/index.js",
"unpkg": "dist/sql-formatter.min.js",
"module": "lib/index.js",
"types": "lib/src/index.d.ts",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the types field both here and in exports lets TypeScript resolve the correct types by filename.

"exports": {
"./package.json": "./package.json",
".": {
"types": "./lib/src/index.d.ts",
"import": "./lib/index.js",
"require": "./dist/sql-formatter.min.cjs"
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"bin": {
Expand Down Expand Up @@ -64,10 +62,9 @@
"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:babel": "babel src --out-dir lib --extensions .ts --source-maps",
"build:types": "tsc --emitDeclarationOnly --isolatedModules",
"build:minified": "webpack --config webpack.prod.js && cp dist/sql-formatter.min.cjs dist/sql-formatter.min.js",
"build": "yarn grammar && npm-run-all --parallel build:babel build:types build:minified",
"build:tsup": "tsup src/index.ts --format cjs,esm --sourcemap --dts",
"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",
"release": "release-it"
},
"repository": {
Expand Down Expand Up @@ -113,6 +110,7 @@
"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
21 changes: 18 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@ export { supportedDialects, format, formatDialect } from './sqlFormatter.js';
export { expandPhrases } from './expandPhrases.js';
export { ConfigError } from './validateConfig.js';

// Intentionally use "export *" syntax here to make sure when adding a new SQL dialect
// we wouldn't forget to expose it in our public API.
export * from './allDialects.js';
// When adding a new dialect, be sure to add it to the list of exports below.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the export * was necessary because esbuild transformed it into code that wasn't statically analyzable for tree shaking. If desired, I can look into adding a test that asserts that this file has all the necessary language imports?

export { bigquery } from './languages/bigquery/bigquery.formatter.js';
export { db2 } from './languages/db2/db2.formatter.js';
export { db2i } from './languages/db2i/db2i.formatter.js';
export { hive } from './languages/hive/hive.formatter.js';
export { mariadb } from './languages/mariadb/mariadb.formatter.js';
export { mysql } from './languages/mysql/mysql.formatter.js';
export { n1ql } from './languages/n1ql/n1ql.formatter.js';
export { plsql } from './languages/plsql/plsql.formatter.js';
export { postgresql } from './languages/postgresql/postgresql.formatter.js';
export { redshift } from './languages/redshift/redshift.formatter.js';
export { spark } from './languages/spark/spark.formatter.js';
export { sqlite } from './languages/sqlite/sqlite.formatter.js';
export { sql } from './languages/sql/sql.formatter.js';
export { trino } from './languages/trino/trino.formatter.js';
export { transactsql } from './languages/transactsql/transactsql.formatter.js';
export { singlestoredb } from './languages/singlestoredb/singlestoredb.formatter.js';
export { snowflake } from './languages/snowflake/snowflake.formatter.js';

// NB! To re-export types the "export type" syntax is required by webpack.
// Otherwise webpack build will fail.
Expand Down
Loading
Loading