Skip to content

Commit 5a816c9

Browse files
authored
feat: support prettier v3 (#195)
* feat: support prettier v3 * chore: fix prettier versions range in peerDependencies issue: #194
1 parent afd080b commit 5a816c9

34 files changed

Lines changed: 1052 additions & 1514 deletions
File renamed without changes.

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
node: [12.x, 14.x, 16.x, 18.x]
17-
prettier: [2.1, 2.2, 2.4, latest]
16+
node: [14.x, 16.x, 18.x, 20.x]
17+
prettier: [3.0]
1818

1919
steps:
2020
- uses: actions/checkout@v2

babel.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

jest.config.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
// @ts-check
22

3-
"use strict";
4-
53
/** @type {import('@jest/types').Config.InitialOptions} */
64
const config = {
7-
preset: 'ts-jest/presets/js-with-babel',
8-
globals: {
9-
"ts-jest": {
10-
useESM: true,
11-
},
12-
},
13-
moduleNameMapper: {
14-
"^(\\.{1,2}\\/.*)\\.js$": "$1",
15-
},
16-
transformIgnorePatterns: ['node_modules/(?!(mdast-util-from-markdown))/'],
5+
runner: 'jest-light-runner'
176
};
187

19-
module.exports = config;
8+
export default config;

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33
"version": "0.4.2",
44
"description": "A Prettier plugin to format JSDoc comments.",
55
"private": false,
6-
"workspaces": {
7-
"prettier-plugin-fake": "./prettier-plugin-fake"
6+
"type": "module",
7+
"exports": {
8+
".": {
9+
"types": "./dist/types.d.ts",
10+
"default": "./dist/index.js"
11+
}
812
},
9-
"main": "dist/index.js",
10-
"module": "dist/index.min.mjs",
13+
"browser": "dist/index.umd.min.js",
1114
"unpkg": "dist/index.umd.min.js",
1215
"types": "dist/index.d.ts",
1316
"files": [
1417
"dist/index.js",
15-
"dist/index.min.mjs",
1618
"dist/index.umd.min.js",
1719
"dist/index.d.ts"
1820
],
1921
"scripts": {
2022
"prepare": "yarn build",
2123
"lint": "eslint --ext '.ts' ./src",
22-
"test": "yarn build --test && jest",
24+
"test": "yarn build --test && NODE_OPTIONS=\"--loader ts-node/esm\" jest",
2325
"release": "standard-version && yarn publish && git push --follow-tags origin master",
2426
"prettierAll": "prettier --write \"**/*.ts\"",
2527
"clean": "rm -fr dist",
@@ -42,8 +44,6 @@
4244
"url": "git+https://github.com/hosseinmd/prettier-plugin-jsdoc.git"
4345
},
4446
"devDependencies": {
45-
"@babel/core": "^7.18.5",
46-
"@babel/preset-env": "^7.18.2",
4747
"@commitlint/config-conventional": "^14.1.0",
4848
"@rollup/plugin-commonjs": "^21.0.3",
4949
"@rollup/plugin-json": "^4.1.0",
@@ -52,30 +52,30 @@
5252
"@types/mdast": "^3.0.10",
5353
"@typescript-eslint/eslint-plugin": "^5.3.0",
5454
"@typescript-eslint/parser": "^5.3.0",
55-
"babel-jest": "^28.1.1",
5655
"commitlint": "^14.1.0",
5756
"eslint": "^8.1.0",
5857
"eslint-config-prettier": "^8.5.0",
5958
"eslint-plugin-prettier": "^4.0.0",
6059
"husky": "^7.0.4",
6160
"jest": "^27.5.1",
61+
"jest-light-runner": "^0.5.0",
6262
"jest-specific-snapshot": "^5.0.0",
63-
"prettier": "^2.6.1",
63+
"prettier": "^3.0.0",
6464
"rollup": "^2.70.1",
6565
"standard-version": "^9.3.2",
6666
"terser": "^5.12.1",
67-
"ts-jest": "^27.1.4",
67+
"ts-node": "^10.9.1",
6868
"typescript": "^4.4.4"
6969
},
7070
"peerDependencies": {
71-
"prettier": ">=2.1.2"
71+
"prettier": "^3.0.0"
7272
},
7373
"dependencies": {
7474
"binary-searching": "^2.0.5",
7575
"comment-parser": "^1.3.1",
7676
"mdast-util-from-markdown": "^1.2.0"
7777
},
7878
"engines": {
79-
"node": ">=12.0.0"
79+
"node": ">=14.13.1 || >=16.0.0"
8080
}
8181
}

prettier-plugin-fake/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { parsers: typescriptParsers } = require("prettier/parser-typescript");
1+
import { parsers as typescriptParsers } from "prettier/plugins/typescript";
22

33
/**
44
*
@@ -8,14 +8,14 @@ const { parsers: typescriptParsers } = require("prettier/parser-typescript");
88
*/
99
const preprocess = (text, options) => {
1010
if (
11-
options.plugins.find((plugin) => plugin.name === "prettier-plugin-fake")
11+
options.plugins.find((plugin) => plugin.name?.includes("prettier-plugin-fake"))
1212
) {
1313
return `//prettier-plugin-fake\n${text}`;
1414
}
1515
return text;
1616
};
1717

18-
exports.parsers = {
18+
export const parsers = {
1919
typescript: {
2020
...typescriptParsers.typescript,
2121
preprocess: typescriptParsers.typescript.preprocess
@@ -25,8 +25,8 @@ exports.parsers = {
2525
options,
2626
)
2727
: preprocess,
28-
parse: (text, parsers, options) => {
29-
const ast = typescriptParsers.typescript.parse(text, parsers, options);
28+
parse: (text, options) => {
29+
const ast = typescriptParsers.typescript.parse(text, options);
3030
if (ast.comments) {
3131
ast.comments[0].value = "PRETTIER-PLUGIN-FAKE";
3232
}

prettier-plugin-fake/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "prettier-plugin-fake",
33
"version": "1.1.1",
44
"private": true,
5-
"main": "index.js",
5+
"type": "module",
66
"files": [
77
"index.js"
88
]
9-
}
9+
}

rollup.config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,14 @@ import json from "@rollup/plugin-json";
66
// ignore all bare imports from node_modules
77
// which are not relative and not absolute
88
const external = (id) =>
9-
!id.startsWith("mdast-util-from-markdown") &&
10-
!id.startsWith("mdast-util-to-string") &&
11-
!id.startsWith("micromark") &&
12-
!id.startsWith("decode-named-character-reference") &&
13-
!id.startsWith("character-entities") &&
14-
!id.startsWith("unist-util-stringify-position") &&
159
id.startsWith(".") === false &&
1610
path.isAbsolute(id) === false;
1711

1812
export default {
1913
input: "./dist/index.js",
2014
output: {
2115
file: "dist/index.js",
22-
format: "commonjs",
16+
format: "esm",
2317
},
2418
external,
2519
plugins: [

script.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ function $(commands) {
1818
const lint = "npm run clean && npm run lint && tsc --project tsconfig.json";
1919

2020
const bundleEsm = "rollup --config rollup.config.js";
21-
const bundleEsmMin =
22-
"terser --ecma 6 --compress --mangle --module -o dist/index.min.mjs -- dist/index.js && gzip -9 -c dist/index.min.mjs > dist/index.min.mjs.gz";
2321
const bundleUmd =
2422
"rollup dist/index.js --file dist/index.umd.js --format umd --name sayHello";
2523
const bundleUmdMin =
@@ -30,7 +28,6 @@ const buildStats =
3028
$(`${lint}`);
3129
$(`${bundleEsm}`);
3230
if (!__TEST__) {
33-
$(`${bundleEsmMin}`);
3431
$(`${bundleUmd}`);
3532
$(`${bundleUmdMin}`);
3633
$(`${buildStats}`);

src/create-language.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)