Skip to content

Commit d5fceec

Browse files
committed
[hygiene] Prettier 3 upgrade
1 parent d916191 commit d5fceec

File tree

5 files changed

+45
-25
lines changed

5 files changed

+45
-25
lines changed

build/common.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,9 @@ export const compileModule = async (
329329
'fs',
330330
'fs/promises',
331331
'path',
332-
'prettier',
332+
'prettier/standalone',
333+
'prettier/plugins/estree',
334+
'prettier/plugins/typescript',
333335
'react',
334336
'react-dom',
335337
'url',
@@ -475,7 +477,7 @@ export const compileDocsAndAssets = async (api = true, pages = true) => {
475477
await makeDir(TMP_DIR);
476478
await esbuild.build({
477479
entryPoints: ['site/build.ts'],
478-
external: ['tinydocs', 'react', 'yjs', 'prettier'],
480+
external: ['tinydocs', 'react', 'yjs', '@prettier/sync'],
479481
target: 'esnext',
480482
bundle: true,
481483
outfile: './tmp/build.js',

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"editablevalueview",
4343
"erwinkn",
4444
"esbuild",
45+
"estree",
4546
"etting",
4647
"evenr",
4748
"fdfontes",

package.json

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,12 @@
212212
},
213213
"devDependencies": {
214214
"@automerge/automerge": "^2.1.0-alpha.6",
215-
"@babel/cli": "^7.22.10",
216-
"@babel/core": "^7.22.11",
217-
"@babel/preset-env": "^7.22.14",
218-
"@babel/preset-react": "^7.22.5",
219-
"@babel/preset-typescript": "^7.22.11",
215+
"@babel/cli": "^7.22.15",
216+
"@babel/core": "^7.22.15",
217+
"@babel/preset-env": "^7.22.15",
218+
"@babel/preset-react": "^7.22.15",
219+
"@babel/preset-typescript": "^7.22.15",
220+
"@prettier/sync": "^0.3.0",
220221
"@rollup/plugin-image": "^3.0.2",
221222
"@rollup/plugin-replace": "^5.0.2",
222223
"@rollup/plugin-terser": "^0.4.3",
@@ -227,14 +228,14 @@
227228
"@types/jest": "^29.5.4",
228229
"@types/jest-environment-puppeteer": "^5.0.3",
229230
"@types/less": "^3.0.4",
230-
"@types/node": "^20.5.7",
231+
"@types/node": "^20.5.9",
231232
"@types/puppeteer": "^5.4.7",
232233
"@types/react": "^18.2.21",
233234
"@types/react-dom": "^18.2.7",
234-
"@types/react-test-renderer": "^18.0.0",
235+
"@types/react-test-renderer": "^18.0.1",
235236
"@types/tmp": "^0.2.3",
236-
"@typescript-eslint/eslint-plugin": "^6.5.0",
237-
"@typescript-eslint/parser": "^6.5.0",
237+
"@typescript-eslint/eslint-plugin": "^6.6.0",
238+
"@typescript-eslint/parser": "^6.6.0",
238239
"@vlcn.io/crsqlite-wasm": "^0.14.0",
239240
"asciichart": "^1.5.25",
240241
"automerge-repo": "^0.1.0",
@@ -244,7 +245,7 @@
244245
"babel-preset-minify": "^0.5.2",
245246
"buffer-replace": "^1.0.0",
246247
"country-flag-emoji-json": "^2.0.0",
247-
"cspell": "^7.2.0",
248+
"cspell": "^7.3.2",
248249
"esbuild": "^0.19.2",
249250
"eslint": "^8.48.0",
250251
"eslint-config-prettier": "^9.0.0",
@@ -263,7 +264,7 @@
263264
"jest-fetch-mock": "^3.0.3",
264265
"jest-puppeteer": "^9.0.0",
265266
"less": "^4.2.0",
266-
"prettier": "^2.8.8",
267+
"prettier": "^3.0.3",
267268
"puppeteer": "^21.1.1",
268269
"react": "^18.2.0",
269270
"react-dom": "^18.2.0",
@@ -272,20 +273,20 @@
272273
"rollup-plugin-esbuild": "^5.0.0",
273274
"rollup-plugin-gzip": "^3.1.0",
274275
"rollup-plugin-preserve-shebang": "^1.0.1",
275-
"rollup-plugin-prettier": "^3.0.0",
276+
"rollup-plugin-prettier": "^4.0.0",
276277
"sqlite3": "^5.1.6",
277278
"tinybase": "file:./",
278279
"tinydocs": "^0.1.32",
279280
"tmp": "^0.2.1",
280-
"ts-unused-exports": "^10.0.0",
281+
"ts-unused-exports": "^10.0.1",
281282
"typescript": "5.2.2",
282283
"yjs": "^13.6.7"
283284
},
284285
"peerDependencies": {
285286
"@sqlite.org/sqlite-wasm": "^3.42.0-build4",
286287
"@vlcn.io/crsqlite-wasm": "^0.14.0",
287288
"automerge-repo": "^0.1.0",
288-
"prettier": ">2.8.8",
289+
"prettier": "^3.0.3",
289290
"react": "^18.2.0",
290291
"react-dom": "^18.2.0",
291292
"sqlite3": "^5.1.6",

site/ui/ExecutablePen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {NoPropComponent, useBaseUrl, usePageNode} from 'tinydocs';
22
import React from 'react';
3-
import prettier from 'prettier';
3+
import prettier from '@prettier/sync';
44

55
const SCRIPTS_REGEX = /<script.*?<\/script>/gms;
66
const SRC_REGEX = /(?<=src=['"]).*?(?=['"])/gms;

src/tools.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ import {
77
Tools,
88
createTools as createToolsDecl,
99
} from './types/tools.d';
10-
import {arrayEvery, arrayLength, arrayMap} from './common/array';
10+
import {arrayEvery, arrayLength, arrayMap, arrayPush} from './common/array';
1111
import {formatJsDoc, length} from './tools/common/code';
1212
import {objFreeze, objIsEmpty} from './common/obj';
1313
import {collForEach} from './common/coll';
1414
import {getCreateFunction} from './common/definable';
1515
import {getStoreApi as getStoreApiImpl} from './tools/api/api';
1616
import {jsonParse} from './common/json';
17+
import {promiseAll} from './common/other';
1718

1819
type CellMeta = [string, IdMap<number>, [number, Cell?], number];
1920

21+
const PRETTIER = 'prettier/';
22+
const PRETTIER_PLUGINS = PRETTIER + 'plugins/';
23+
2024
const prettierConfig = {
2125
parser: 'typescript',
2226
singleQuote: true,
@@ -130,17 +134,29 @@ export const createTools = getCreateFunction((store: Store): Tools => {
130134
module: string,
131135
): Promise<[string, string, string, string]> => {
132136
const extensions = ['d.ts', 'ts', 'd.ts', 'tsx'];
133-
let format: (str: string, _config: any) => string;
137+
const plugins: any[] = [];
138+
let format: (str: string, _config: any) => Promise<string>;
134139
try {
135-
format = (await import('prettier')).format;
140+
format = (await import(PRETTIER + 'standalone')).format;
141+
arrayPush(
142+
plugins,
143+
await import(PRETTIER_PLUGINS + 'estree'),
144+
await import(PRETTIER_PLUGINS + 'typescript'),
145+
);
136146
} catch (e) {
137-
format = (str) => str;
147+
format = async (str) => str;
138148
}
139-
return arrayMap(getStoreApi(module), (file, f) =>
140-
formatJsDoc(
141-
format(file, {...prettierConfig, filepath: `_.${extensions[f]}`}),
149+
return (await promiseAll(
150+
arrayMap(getStoreApi(module), async (file, f) =>
151+
formatJsDoc(
152+
await format(file, {
153+
...prettierConfig,
154+
plugins,
155+
filepath: `_.${extensions[f]}`,
156+
}),
157+
),
142158
),
143-
) as [string, string, string, string];
159+
)) as [string, string, string, string];
144160
};
145161

146162
const getStore = (): Store => store;

0 commit comments

Comments
 (0)