From fd7dbbc216d9a4b10fcea64e1b0ff534254c9954 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Tue, 12 Dec 2023 17:25:01 +0100 Subject: [PATCH] chore: remove prettier, just use strings --- README.md | 11 ---- packages/snippetz-plugin-undici/package.json | 1 - .../scalar-snippetz-plugin-undici-0.0.0.tgz | Bin 0 -> 2456 bytes .../snippetz-plugin-undici/src/undici.test.ts | 54 ++++++++---------- packages/snippetz-plugin-undici/src/undici.ts | 13 +++-- packages/snippetz/package.json | 1 - packages/snippetz/scalar-snippetz-0.0.0.tgz | Bin 0 -> 2493 bytes packages/snippetz/src/format.test.ts | 13 ----- packages/snippetz/src/format.ts | 18 ------ packages/snippetz/src/snippetz.test.ts | 4 +- packages/snippetz/src/snippetz.ts | 3 +- pnpm-lock.yaml | 13 ----- tsconfig.json | 3 +- 13 files changed, 37 insertions(+), 97 deletions(-) create mode 100644 packages/snippetz-plugin-undici/scalar-snippetz-plugin-undici-0.0.0.tgz create mode 100644 packages/snippetz/scalar-snippetz-0.0.0.tgz delete mode 100644 packages/snippetz/src/format.test.ts delete mode 100644 packages/snippetz/src/format.ts diff --git a/README.md b/README.md index 112bf31..d65157f 100644 --- a/README.md +++ b/README.md @@ -51,17 +51,6 @@ const source = undici({ console.log(source.code) ``` -### Format the source code - -```js -import { format } from '@scalar/snippetz' - -console.log(format({ - target: 'js', - code: `const answer= 42 ;` -})) -``` - ## Community We are API nerds. You too? Let’s chat on Discord: diff --git a/packages/snippetz-plugin-undici/package.json b/packages/snippetz-plugin-undici/package.json index d76b2a7..746e452 100644 --- a/packages/snippetz-plugin-undici/package.json +++ b/packages/snippetz-plugin-undici/package.json @@ -17,7 +17,6 @@ "vitest": "^1.0.4" }, "dependencies": { - "prettier": "^3.1.1", "@scalar/snippetz": "workspace:*" }, "files": [ diff --git a/packages/snippetz-plugin-undici/scalar-snippetz-plugin-undici-0.0.0.tgz b/packages/snippetz-plugin-undici/scalar-snippetz-plugin-undici-0.0.0.tgz new file mode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G;y zmH%(iP8vOEGLMFw8b&=D-^c8FD4^gKp;E#k+*N697^gHIG0xSS0uDnO)BZhN$0QWg zx3C6K3ef<(p*)ndKtw>odl=)R1qwucL0Bly(g}EI!az>>avoEAAns&sAfXS0^T=Za z^?@IG$%uwR9kzmeDB(~LLkea$l`xCSh)+piun^=}HUxJ}45LJzSn7BEsKWvldO_k# zAF|+X$kB0H zy>n9+m*^r+)n)%yUu>2+31~H#$lt^k~$CD9dO{(>GT@)v!>I5)3eTLyX&I)1612; zv<^FH#XWIbJsYhe4cyLJm9a6U&g(i4tw41m#+;)*`1G7FGmVWdE$|<_h7!b(*NFD}`l<8MD1Q zz5jo08UClgwtTbo+BROm|MFJ3w0!?x#z%q`{=Y$!Z|c;MomqvKzO0jP7iY(XV3utB zr>XLxK$7(5ftu#i+XFhLp-)4P$s@t^#ijY_mI*2!H<=XqM;X;@rLQi{Pf`=#m_2x; zEET)Fo$-hy?nf!TjDI;@is~1ka&Q}kD%qGcnNl;SQz{p8UZ}4FwDV7SK8~pnjK)f0 z)1I@vJax1A$yKWR7^Gil33(482QTvpl!KRa>>6yZsB*V~G*~G5`S50OIoi literal 0 HcmV?d00001 diff --git a/packages/snippetz-plugin-undici/src/undici.test.ts b/packages/snippetz-plugin-undici/src/undici.test.ts index adee068..8692a10 100644 --- a/packages/snippetz-plugin-undici/src/undici.test.ts +++ b/packages/snippetz-plugin-undici/src/undici.test.ts @@ -7,7 +7,7 @@ describe('undici', () => { url: 'https://example.com', }) - expect(source.code).toContain(`import { request } from "undici"`) + expect(source.code).toContain(`import { request } from 'undici'`) }) it('returns a basic request', () => { @@ -15,10 +15,9 @@ describe('undici', () => { url: 'https://example.com', }) - expect(source.code).toBe(`import { request } from "undici" - -const { statusCode, headers, body } = await request("https://example.com") + expect(source.code).toBe(`import { request } from 'undici' +const { statusCode, headers, body } = await request('https://example.com') `) }) @@ -28,12 +27,11 @@ const { statusCode, headers, body } = await request("https://example.com") method: 'post', }) - expect(source.code).toBe(`import { request } from "undici" + expect(source.code).toBe(`import { request } from 'undici' -const { statusCode, headers, body } = await request("https://example.com", { - "method": "POST" +const { statusCode, headers, body } = await request('https://example.com', { + 'method': 'POST' }) - `) }) @@ -48,14 +46,13 @@ const { statusCode, headers, body } = await request("https://example.com", { ], }) - expect(source.code).toBe(`import { request } from "undici" + expect(source.code).toBe(`import { request } from 'undici' -const { statusCode, headers, body } = await request("https://example.com", { - "headers": { - "Content-Type": "application/json" +const { statusCode, headers, body } = await request('https://example.com', { + 'headers': { + 'Content-Type': 'application/json' } }) - `) }) @@ -76,17 +73,16 @@ const { statusCode, headers, body } = await request("https://example.com", { }, }) - expect(source.code).toBe(`import { request } from "undici" + expect(source.code).toBe(`import { request } from 'undici' -const { statusCode, headers, body } = await request("https://example.com", { - "headers": { - "Content-Type": "application/json" +const { statusCode, headers, body } = await request('https://example.com', { + 'headers': { + 'Content-Type': 'application/json' }, - "body": { - "hello": "world" + 'body': { + 'hello': 'world' } }) - `) }) @@ -111,14 +107,13 @@ const { statusCode, headers, body } = await request("https://example.com", { ], }) - expect(source.code).toBe(`import { request } from "undici" + expect(source.code).toBe(`import { request } from 'undici' -const { statusCode, headers, body } = await request("https://example.com?foo=bar&bar=foo", { - "headers": { - "Content-Type": "application/json" +const { statusCode, headers, body } = await request('https://example.com?foo=bar&bar=foo', { + 'headers': { + 'Content-Type': 'application/json' } }) - `) }) @@ -137,14 +132,13 @@ const { statusCode, headers, body } = await request("https://example.com?foo=bar ], }) - expect(source.code).toBe(`import { request } from "undici" + expect(source.code).toBe(`import { request } from 'undici' -const { statusCode, headers, body } = await request("https://example.com", { - "headers": { - "Set-Cookie": "foo=bar; bar=foo" +const { statusCode, headers, body } = await request('https://example.com', { + 'headers': { + 'Set-Cookie': 'foo=bar; bar=foo' } }) - `) }) }) diff --git a/packages/snippetz-plugin-undici/src/undici.ts b/packages/snippetz-plugin-undici/src/undici.ts index 97b06ba..ba3af24 100644 --- a/packages/snippetz-plugin-undici/src/undici.ts +++ b/packages/snippetz-plugin-undici/src/undici.ts @@ -9,6 +9,12 @@ function arrayToObject(items: any) { }, {}) } +export function formatAsJavaScriptObject(data: Record) { + return JSON.stringify(data, null, 2) + .replaceAll(`'`, `\'`) + .replaceAll(`"`, `'`) +} + export function undici(request: Partial): Source { // Defaults const normalizedRequest = { @@ -73,14 +79,13 @@ export function undici(request: Partial): Source { // Transform to JSON const jsonOptions = Object.keys(options).length - ? `, ${JSON.stringify(options, null, 2)}` + ? `, ${formatAsJavaScriptObject(options)}` : '' // Code Template - const code = `import { request } from "undici" - -const { statusCode, headers, body } = await request("${normalizedRequest.url}${queryString}"${jsonOptions}) + const code = `import { request } from 'undici' +const { statusCode, headers, body } = await request('${normalizedRequest.url}${queryString}'${jsonOptions}) ` // Create an AST diff --git a/packages/snippetz/package.json b/packages/snippetz/package.json index d5778e3..8787b49 100644 --- a/packages/snippetz/package.json +++ b/packages/snippetz/package.json @@ -15,7 +15,6 @@ "vitest": "^1.0.4" }, "dependencies": { - "prettier": "^3.1.1" }, "files": [ "dist" diff --git a/packages/snippetz/scalar-snippetz-0.0.0.tgz b/packages/snippetz/scalar-snippetz-0.0.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..aee2df9a06552724fc92e800f33c8baac9076791 GIT binary patch literal 2493 zcmV;u2}1TCiwFP!000006YU%QbJ{ree)eDS>bq%SM|FUZbOy?H1#ufs38X-_*U98& zjS-1jV|#5mX_n=Gzb8wEgoLIuN7A`nzhuCYp7cJX_hCsyuJ^?~XFC&~h#ekG*jFo^ zO)T$o@{g@SrBd0i*FkH zZ1P4umQGF0kV!Uia!-S1VAW!tp(Yw7(bB}v{c!C1qYIv7Vy}t~@#mij^QQ!rcWVBU zc&_ipJ4wK!h>1VUv(|h;gq0D-Z$$?maysSmqFfR<4!Jo8Bq45jZl(zX?7&g?&Ab`H z5-ZQWFh~T%t$sE$mKQTuuu_ovKAE2muV>@Xw?sI^zQOs(JwI#AFI_)n4f80QI&-lo zH~CbKG!5gD8jS-F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@R4?t3fLy(_TP0nc5i4u3XKQs zzgDTgTC@M^{%&#p|0HnajG)Us79`9tI$?Aj^YaS(c- zn2IZzF1W!2+$0G-?#k;_lh8|NED)~Rir_v=pd>CBm_yyeEN4U}%=HZ(fNaZ~;EIcj zFclCpb%7ekAix99PbZRxyxHe7t|`dwncRtigQf{eAo(QnwmYB7ZcN|`_Ocph*K`4+_#e$rGXf><4 zDYl04c>Ak#FE!6VB8*Tl4t{-F)S{@c+AizC_UrX=?K-%EanMm8BtbotV-MwENA{p|h(+3Vy3XhmG2S|(o*eUSe*hGY>0sn^ zPP%je$0vj1{?JD92RLlc>Af8w75m8UjVz>!bzuLB1sEREZdZ~r=m~N^ko-ZXfBb3S zygMAhVZVD|V`bY$&S<-9D^e&_r%Rn90tfVnzO%DleH>+ANHoPAd_1&em83`UzcX_B zJt;<~-y03ENKnebXxa6nGqefNfisi}c{}JI5ksmId-StGuwTzsqexZ5troa*xQw)yk_P{yzoCR6jek zGaGRCCrt91@aljN%!-A7s#a$AvP%6ROw~=;B`G_CdhaV75z)0#WY`sb4xLuqFnCvVPwueM~>T0UYy?agfJoT2C+ z&2402br(FNr}TV--Z4tZ~ye|?XBl0o`ZJ7tXe3^XVQJ0T9S+nHWD2{gvD4>7>9uNKtPEUsd H06+i$Y)0uQ literal 0 HcmV?d00001 diff --git a/packages/snippetz/src/format.test.ts b/packages/snippetz/src/format.test.ts deleted file mode 100644 index c92acbc..0000000 --- a/packages/snippetz/src/format.test.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { expect, describe, it } from 'vitest' -import { format } from './format' - -describe('format', async () => { - it('formats basic JS', async () => { - expect( - await format({ - target: 'javascript', - code: 'const answer=42', - }) - ).toBe(`const answer = 42\n`) - }) -}) diff --git a/packages/snippetz/src/format.ts b/packages/snippetz/src/format.ts deleted file mode 100644 index e14c038..0000000 --- a/packages/snippetz/src/format.ts +++ /dev/null @@ -1,18 +0,0 @@ -import babel from 'prettier/plugins/babel' -import estree from 'prettier/plugins/estree' -import * as prettier from 'prettier' - -export async function format(source: any) { - const target = source.target - - if (target === 'javascript') { - return await prettier.format(source.code, { - semi: false, - parser: 'babel', - plugins: [babel, estree], - singleQuote: true, - }) - } - - throw new Error(`Unsupported target: ${source.target}`) -} diff --git a/packages/snippetz/src/snippetz.test.ts b/packages/snippetz/src/snippetz.test.ts index fcf9de2..769237d 100644 --- a/packages/snippetz/src/snippetz.test.ts +++ b/packages/snippetz/src/snippetz.test.ts @@ -3,9 +3,9 @@ import { snippetz } from './snippetz' describe('snippetz', async () => { it('formats basic JS', async () => { - const snippet = await snippetz().get({ + const snippet = snippetz().get({ target: 'javascript', - code: 'const answer=42', + code: 'const answer = 42\n', }) expect(snippet).toBe(`const answer = 42\n`) diff --git a/packages/snippetz/src/snippetz.ts b/packages/snippetz/src/snippetz.ts index 83c9bda..fa1b5ba 100644 --- a/packages/snippetz/src/snippetz.ts +++ b/packages/snippetz/src/snippetz.ts @@ -1,4 +1,3 @@ -import { format } from './format' import type { Source } from './types' export type SnippetOptions = {} @@ -13,7 +12,7 @@ export function snippetz() { ...options, } - return format(source) + return source.code }, } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c614667..c901d38 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -47,10 +47,6 @@ importers: version: 1.8.25(typescript@5.3.3) packages/snippetz: - dependencies: - prettier: - specifier: ^3.1.1 - version: 3.1.1 devDependencies: '@vitest/ui': specifier: ^1.0.4 @@ -70,9 +66,6 @@ importers: '@scalar/snippetz': specifier: workspace:* version: link:../snippetz - prettier: - specifier: ^3.1.1 - version: 3.1.1 devDependencies: '@types/har-format': specifier: ^1.2.15 @@ -2416,12 +2409,6 @@ packages: hasBin: true dev: true - /prettier@3.1.1: - resolution: {integrity: sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==} - engines: {node: '>=14'} - hasBin: true - dev: false - /pretty-format@29.7.0: resolution: {integrity: sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} diff --git a/tsconfig.json b/tsconfig.json index 1ba2bf5..8ca4130 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,12 +3,11 @@ "target": "ES2020", "useDefineForClassFields": true, "module": "ESNext", - "lib": ["ES2020", "DOM", "DOM.Iterable"], + "lib": ["ES2021", "DOM", "DOM.Iterable"], "skipLibCheck": true, /* Bundler mode */ "moduleResolution": "bundler", - "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true,