Skip to content

Commit fddd8dd

Browse files
committed
Optimize build scripts and replace heavy dependencies with lightweight alternatives
- remove reliance on ts-node - before we even start building a lot of time elapses [Pasted text] - update the `apps/editor/.vscodeignore` [Pasted text] - exclude things that don't have to be included in build `apps/editor/.vscodeignore` [Pasted text] - drop dependence on joplin/turndown for something more popular, perhaps the official package, or something entirely different - remove dompurify - replace jsdom with Linkedom ├── apps │ ├── browser │ │ ├── package.json │ │ ├── scripts │ │ │ └── build.mjs │ │ └── vite.config.ts │ └── editor │ ├── .gitignore │ ├── .vscodeignore │ ├── package.json │ ├── package.nls.json │ ├── scripts │ │ └── build.mjs │ ├── src │ │ ├── commands │ │ │ └── code-at-cursor-command │ │ │ └── utils │ │ │ └── perform-code-at-cursor.ts │ │ ├── env.d.ts │ │ └── views │ │ ├── chats │ │ │ └── frontend │ │ │ └── App.tsx │ │ ├── prompt │ │ │ ├── backend │ │ │ │ ├── message-handlers │ │ │ │ │ └── handle-open-website.ts │ │ │ │ └── utils │ │ │ │ └── website-fetcher.ts │ │ │ └── frontend │ │ │ └── App.tsx │ │ └── settings │ │ └── frontend │ │ └── App.tsx │ ├── tsconfig.json │ └── vite.config.ts └── packages └── ui └── src ├── components │ └── editor │ ├── common │ │ ├── Icon │ │ │ └── Icon.tsx │ │ └── Scrollable │ │ └── Scrollable.tsx │ └── settings-view │ └── Layout │ └── Layout.tsx └── styles └── global.scss
1 parent 2abd7f1 commit fddd8dd

11 files changed

Lines changed: 896 additions & 670 deletions

File tree

‎apps/browser/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "browser",
33
"scripts": {
4-
"build": "tsc --noEmit && node scripts/build.mjs && ts-node scripts/create-firefox-build.ts && ts-node scripts/create-zip-archives.ts",
4+
"build": "tsc --noEmit && node scripts/build.mjs && node scripts/create-firefox-build.ts && node scripts/create-zip-archives.ts",
55
"watch": "node scripts/build.mjs --watch",
66
"typecheck": "tsc --noEmit",
77
"bump": "node scripts/bump.js"
@@ -15,7 +15,6 @@
1515
"archiver": "6.0.2",
1616
"baseline-browser-mapping": "2.11.35",
1717
"sass": "1.93.3",
18-
"ts-node": "10.9.2",
1918
"vite": "8.3.6",
2019
"webextension-polyfill": "0.12.0"
2120
},

‎apps/browser/scripts/build.mjs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
const start_time = Date.now()
2+
console.log('Building...')
3+
14
import * as fs from 'node:fs'
25
import * as path from 'node:path'
36
import { fileURLToPath } from 'node:url'
4-
import { build } from 'vite'
7+
8+
const { build } = await import('vite')
59

610
const app_dir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
711

@@ -12,9 +16,6 @@ const mode = is_watch ? 'development' : 'production'
1216
process.env.NODE_ENV = mode
1317

1418
const run = async () => {
15-
const start_time = Date.now()
16-
console.log('Building...')
17-
1819
if (!is_watch) {
1920
fs.rmSync(path.join(app_dir, 'dist'), { recursive: true, force: true })
2021
}

‎apps/editor/.vscodeignore‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
src
22
.gitignore
33
tsconfig.json
4-
__mocks__
5-
jest.config.js
4+
jest.config.js
5+
.env*
6+
tsconfig.tsbuildinfo
7+
vite.config.ts
8+
scripts
9+
package*

‎apps/editor/package.json‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "Markdown prompts for chatbots, APIs, and CLIs with seamless integration",
55
"version": "2026.1107.399",
66
"scripts": {
7-
"build": "npx vsce package --no-dependencies",
8-
"vscode:prepublish": "rimraf out && npm run compile",
7+
"build": "vsce package --no-dependencies",
8+
"vscode:prepublish": "npm run compile",
99
"compile": "node scripts/build.mjs",
1010
"watch": "node scripts/build.mjs --watch",
1111
"typecheck": "tsc --noEmit",
@@ -1359,41 +1359,32 @@
13591359
}
13601360
},
13611361
"devDependencies": {
1362-
"@types/dompurify": "3.0.5",
1363-
"@types/he": "1.2.3",
1364-
"@types/jsdom": "21.1.7",
13651362
"@types/node": "20.x",
13661363
"@types/react": "18.2.60",
13671364
"@types/react-dom": "18.2.19",
13681365
"@types/turndown": "5.0.5",
13691366
"@types/vscode": "1.96.0",
13701367
"@types/ws": "8.18.1",
1368+
"@vscode/vsce": "4.1.0",
13711369
"sass-embedded": "1.89.2",
1372-
"ts-node": "10.9.2",
1373-
"typed-css-modules": "0.9.1",
13741370
"vite": "8.3.6"
13751371
},
13761372
"dependencies": {
1377-
"@joplin/turndown": "4.0.81",
1378-
"@joplin/turndown-plugin-gfm": "1.0.63",
13791373
"@mozilla/readability": "0.6.0",
13801374
"@vscode/codicons": "0.0.46-38",
13811375
"axios": "1.21.0",
13821376
"classnames": "2.5.1",
13831377
"dayjs": "1.11.10",
13841378
"diff": "8.0.4",
1385-
"dompurify": "3.4.17",
13861379
"dotenv": "16.4.5",
13871380
"glob": "14.0.4",
1388-
"he": "1.2.0",
13891381
"ignore": "6.0.2",
1390-
"jsdom": "24.0.0",
1382+
"linkedom": "0.18.12",
13911383
"marked": "17.0.1",
1392-
"path-browserify": "1.0.1",
13931384
"react": "18.2.0",
13941385
"react-dom": "18.2.0",
1395-
"rimraf": "6.0.1",
13961386
"simplebar-react": "3.3.1",
1387+
"turndown": "7.2.5",
13971388
"ui": "workspace:*",
13981389
"ws": "8.21.3"
13991390
}

‎apps/editor/scripts/build.mjs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
const start_time = Date.now()
2+
console.log('Building...')
3+
14
import * as fs from 'node:fs'
25
import * as path from 'node:path'
36
import { fileURLToPath } from 'node:url'
47
import { spawn } from 'node:child_process'
5-
import { build } from 'vite'
8+
9+
const { build } = await import('vite')
610

711
const app_dir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
812

@@ -30,8 +34,6 @@ const clean = () => {
3034
}
3135

3236
const run = async () => {
33-
const start_time = Date.now()
34-
console.log('Building...')
3537
clean()
3638

3739
if (is_watch) {

‎apps/editor/src/commands/code-at-cursor-command/utils/perform-code-at-cursor.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from 'vscode'
22
import axios from 'axios'
3-
import he from 'he'
43
import { send_llm_message } from '../../../utils/send-llm-message'
54
import {
65
code_at_cursor_output_formatting,
@@ -422,7 +421,7 @@ export const perform_code_at_cursor = async (params: {
422421
}
423422
}
424423

425-
let decoded_completion = he.decode(extracted_content.trim())
424+
let decoded_completion = extracted_content.trim()
426425

427426
if (decoded_completion.startsWith('```')) {
428427
const first_newline = decoded_completion.indexOf('\n')
@@ -612,7 +611,7 @@ export const perform_code_at_cursor = async (params: {
612611
extracted_content = remaining_text
613612
}
614613

615-
let decoded_completion = he.decode(extracted_content.trim())
614+
let decoded_completion = extracted_content.trim()
616615

617616
if (decoded_completion.startsWith('```')) {
618617
const first_newline = decoded_completion.indexOf('\n')

‎apps/editor/src/env.d.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
declare module '@joplin/turndown'
2-
declare module '@joplin/turndown-plugin-gfm'
3-
41
declare function acquireVsCodeApi(): {
52
postMessage(message: any): void
63
setState(state: any): void

‎apps/editor/src/views/prompt/backend/message-handlers/handle-open-website.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import * as vscode from 'vscode'
22
import { OpenWebsiteMessage } from '../../types/messages'
33
import * as fs from 'fs'
44
import { marked } from 'marked'
5-
import { JSDOM } from 'jsdom'
6-
import createDOMPurify from 'dompurify'
75
import { PromptViewProvider } from '../prompt-view-provider'
86
import { PersistentPromptStorage } from '../utils/persistent-prompt-storage'
97

@@ -47,10 +45,7 @@ export const handle_open_website = async (
4745

4846
if (id && fs.existsSync(file_path)) {
4947
const markdown = fs.readFileSync(file_path, 'utf8')
50-
const raw_html = await marked.parse(markdown)
51-
const window = new JSDOM('').window
52-
const DOMPurify = createDOMPurify(window as any)
53-
const html = DOMPurify.sanitize(raw_html)
48+
const html = await marked.parse(markdown)
5449

5550
const webview_panel = vscode.window.createWebviewPanel(
5651
'websitePreview',

‎apps/editor/src/views/prompt/backend/utils/website-fetcher.ts‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import axios from 'axios'
2-
import { JSDOM } from 'jsdom'
2+
import { parseHTML } from 'linkedom'
33
import * as dns from 'dns'
44
import * as http from 'http'
55
import * as https from 'https'
66
import { Readability, isProbablyReaderable } from '@mozilla/readability'
7-
import TurndownServiceJoplin from '@joplin/turndown'
8-
import * as turndownPluginGfm from '@joplin/turndown-plugin-gfm'
9-
import type TurndownService from 'turndown'
7+
import TurndownService from 'turndown'
108

119
const remove_markdown_images = (text: string) => {
1210
const without_images = text.replace(/!\[([^\]]*)\]\(([^)]*)\)/g, '')
1311
return without_images.replace(/\n{3,}/g, '\n\n')
1412
}
1513

1614
const create_turndown_service = () => {
17-
const turndown_service: TurndownService = new TurndownServiceJoplin({
15+
const turndown_service = new TurndownService({
1816
codeBlockStyle: 'fenced'
1917
})
20-
turndown_service.use(turndownPluginGfm.gfm)
2118
turndown_service.addRule('fencedCodeBlock', {
2219
filter: (node: any, options: any) => {
2320
return (
@@ -189,8 +186,10 @@ export const fetch_website = async (
189186

190187
if (response.status === 200 && typeof response.data === 'string') {
191188
const html = response.data
192-
const dom = new JSDOM(html, { url })
193-
const doc = dom.window.document
189+
const { document: doc } = parseHTML(html)
190+
try {
191+
Object.defineProperty(doc, 'documentURI', { value: url })
192+
} catch {}
194193

195194
doc.querySelectorAll('pre').forEach((pre) => {
196195
const code = pre.querySelector('code')
@@ -229,15 +228,17 @@ export const fetch_website = async (
229228
}
230229
})
231230

232-
if (isProbablyReaderable(doc)) {
233-
const reader = new Readability(doc, { keepClasses: true })
231+
if (isProbablyReaderable(doc as any)) {
232+
const reader = new Readability(doc as any, { keepClasses: true })
234233
const article = reader.parse()
235234

236235
if (article && article.content) {
237236
const turndown_service = create_turndown_service()
238-
const article_dom = new JSDOM(article.content)
237+
const { document: article_doc } = parseHTML(
238+
`<!DOCTYPE html><html><body>${article.content}</body></html>`
239+
)
239240
let content = turndown_service.turndown(
240-
article_dom.window.document.body
241+
(article_doc.body || article_doc.documentElement) as any
241242
)
242243
content = remove_markdown_images(content)
243244

0 commit comments

Comments
 (0)