Skip to content

Commit a4daabd

Browse files
feat: support cjs (#804)
* chore: update prettier-plugin-java configuration and dependencies - Refactor package.json to support both ESM and CJS module formats. - Update repository URL to point to the new location. - Replace TypeScript build command with tsdown for improved build process. - Add tsdown configuration file for build settings. - Update dependencies to include tsdown. * chore: enhance prettier-plugin-java package.json for module exports - Add main and module fields to specify entry points for CommonJS and ESM. - Update exports structure to support both import and require formats with correct type definitions. * build: simplify tsdown config and fix JS script imports * build: fix website's plugin dependency for new exports definition --------- Co-authored-by: Jordan Kiesel <jordantkiesel@gmail.com>
1 parent 2879ac5 commit a4daabd

File tree

7 files changed

+437
-12
lines changed

7 files changed

+437
-12
lines changed

benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "node:fs";
22
import path from "node:path";
33
import { bench, do_not_optimize, run } from "mitata";
44
import prettier from "prettier";
5-
import javaPlugin from "../dist/index.js";
5+
import javaPlugin from "../dist/index.mjs";
66

77
const dir = "samples";
88
const files = fs

package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@
77
"license": "Apache-2.0",
88
"type": "module",
99
"exports": {
10-
"types": "./dist/index.d.ts",
11-
"default": "./dist/index.js"
10+
".": {
11+
"import": {
12+
"types": "./dist/index.d.mts",
13+
"default": "./dist/index.mjs"
14+
},
15+
"require": {
16+
"types": "./dist/index.d.cts",
17+
"default": "./dist/index.cjs"
18+
}
19+
}
1220
},
21+
"main": "./dist/index.cjs",
22+
"module": "./dist/index.mjs",
1323
"files": [
1424
"dist"
1525
],
1626
"scripts": {
17-
"build": "tsc && cp src/tree-sitter-java_orchard.wasm dist/",
27+
"build": "tsdown && cp src/tree-sitter-java_orchard.wasm dist/",
1828
"ci": "yarn build && yarn lint && yarn format:validate && yarn test",
1929
"clone-samples": "node scripts/clone-samples.js",
2030
"format:fix": "prettier --write \"**/*.@(js|json|ts)\"",
@@ -65,6 +75,7 @@
6575
"mocha": "^10.8.2",
6676
"prettier": "^3.0.0",
6777
"ts-node": "^10.9.2",
78+
"tsdown": "^0.21.4",
6879
"typescript": "^5.6.3",
6980
"typescript-eslint": "^8.57.0"
7081
},

scripts/update-test-output.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ const updateTestOutput = async () => {
6565
await prettier.__debug.formatDoc(
6666
await prettier.__debug.printToDoc(newExpectedText, {
6767
parser: "java",
68-
plugins: [path.resolve(__dirname, "../dist/index.js")]
68+
plugins: [path.resolve(__dirname, "../dist/index.mjs")]
6969
})
7070
)
7171
);
7272
}
7373
newExpectedText = await prettier.format(newExpectedText, {
7474
parser: "java",
75-
plugins: [path.resolve(__dirname, "../dist/index.js")],
75+
plugins: [path.resolve(__dirname, "../dist/index.mjs")],
7676
tabWidth: 2,
7777
endOfLine: "lf",
7878
...testOptions

tsdown.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from "tsdown";
2+
3+
export default defineConfig({
4+
format: ["esm", "cjs"],
5+
dts: true
6+
});

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@monaco-editor/react": "^4",
2222
"lz-string": "^1",
2323
"prettier": "^3",
24-
"prettier-plugin-java": "file:../dist",
24+
"prettier-plugin-java": "link:..",
2525
"prism-react-renderer": "^2",
2626
"react": "^19",
2727
"react-dom": "^19"

website/yarn.lock

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6218,6 +6218,11 @@ no-case@^3.0.4:
62186218
lower-case "^2.0.2"
62196219
tslib "^2.0.3"
62206220

6221+
node-addon-api@^8.3.1:
6222+
version "8.6.0"
6223+
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-8.6.0.tgz#b22497201b465cd0a92ef2c01074ee5068c79a6d"
6224+
integrity sha512-gBVjCaqDlRUk0EwoPNKzIr9KkS9041G/q31IBShPs1Xz6UTA+EXdZADbzqAJQrpDRq71CIMnOP5VMut3SL0z5Q==
6225+
62216226
node-emoji@^2.1.0:
62226227
version "2.2.0"
62236228
resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-2.2.0.tgz#1d000e3c76e462577895be1b436f4aa2d6760eb0"
@@ -6233,6 +6238,11 @@ node-forge@^1:
62336238
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.2.tgz#d0d2659a26eef778bf84d73e7f55c08144ee7750"
62346239
integrity sha512-6xKiQ+cph9KImrRh0VsjH2d8/GXA4FIMlgU4B757iI1ApvcyA9VlouP0yZJha01V+huImO+kKMU7ih+2+E14fw==
62356240

6241+
node-gyp-build@^4.8.4:
6242+
version "4.8.4"
6243+
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.8.4.tgz#8a70ee85464ae52327772a90d66c6077a900cfc8"
6244+
integrity sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==
6245+
62366246
node-releases@^2.0.19:
62376247
version "2.0.19"
62386248
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.19.tgz#9e445a52950951ec4d177d843af370b411caf314"
@@ -7108,8 +7118,9 @@ postcss@^8.4.21, postcss@^8.4.24, postcss@^8.4.33, postcss@^8.5.4:
71087118
picocolors "^1.1.1"
71097119
source-map-js "^1.2.1"
71107120

7111-
"prettier-plugin-java@file:../dist":
7121+
"prettier-plugin-java@link:..":
71127122
version "0.0.0"
7123+
uid ""
71137124

71147125
prettier@^3:
71157126
version "3.6.2"
@@ -8277,6 +8288,14 @@ totalist@^3.0.0:
82778288
resolved "https://registry.yarnpkg.com/totalist/-/totalist-3.0.1.tgz#ba3a3d600c915b1a97872348f79c127475f6acf8"
82788289
integrity sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ==
82798290

8291+
tree-sitter-java-orchard@0.5.4:
8292+
version "0.5.4"
8293+
resolved "https://registry.yarnpkg.com/tree-sitter-java-orchard/-/tree-sitter-java-orchard-0.5.4.tgz#8c698a57566ff99ce979bf3f53a313f0f7888eec"
8294+
integrity sha512-MpEi4ic9ksqU9CerMt0XXxOJN5CfDsosGrop++4z6Z9XRkT86bu+I/7LCNJS0rrvA5SoY2t98icBeotSaTtY4A==
8295+
dependencies:
8296+
node-addon-api "^8.3.1"
8297+
node-gyp-build "^4.8.4"
8298+
82808299
trim-lines@^3.0.0:
82818300
version "3.0.1"
82828301
resolved "https://registry.yarnpkg.com/trim-lines/-/trim-lines-3.0.1.tgz#d802e332a07df861c48802c04321017b1bd87338"
@@ -8558,6 +8577,11 @@ web-namespaces@^2.0.0:
85588577
resolved "https://registry.yarnpkg.com/web-namespaces/-/web-namespaces-2.0.1.tgz#1010ff7c650eccb2592cebeeaf9a1b253fd40692"
85598578
integrity sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==
85608579

8580+
web-tree-sitter@0.26.6:
8581+
version "0.26.6"
8582+
resolved "https://registry.yarnpkg.com/web-tree-sitter/-/web-tree-sitter-0.26.6.tgz#9e4ed73f1d6fde58e7742cebf89be7eb1f6d3814"
8583+
integrity sha512-fSPR7VBW/fZQdUSp/bXTDLT+i/9dwtbnqgEBMzowrM4U3DzeCwDbY3MKo0584uQxID4m/1xpLflrlT/rLIRPew==
8584+
85618585
webpack-bundle-analyzer@^4.10.2:
85628586
version "4.10.2"
85638587
resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.10.2.tgz#633af2862c213730be3dbdf40456db171b60d5bd"

0 commit comments

Comments
 (0)