Skip to content

Commit fa85375

Browse files
fix(vscode): fix build and publish, reduce extension size (#2207)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 593b9f8 commit fa85375

File tree

13 files changed

+300
-649
lines changed

13 files changed

+300
-649
lines changed

eslint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ export default antfu({
2020
'vue/no-v-text-v-html-on-component',
2121
'vue/component-name-in-template-casing',
2222
'jsonc/sort-array-values',
23+
'pnpm/yaml-no-duplicate-catalog-item',
2324
)
2425
.override('antfu/pnpm/package-json', {
2526
ignores: [
2627
'packages/create-theme/template/package.json',
2728
'packages/create-app/template/package.json',
29+
// VSCE and OVSX do not support pnpm catalog when reading `@types/vscode`'s version.
30+
'packages/vscode/package.json',
2831
],
2932
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"lint-staged": "catalog:dev",
5757
"mermaid": "catalog:frontend",
5858
"playwright-chromium": "catalog:dev",
59-
"prettier": "catalog:frontend",
59+
"prettier": "catalog:dev",
6060
"prettier-plugin-slidev": "catalog:dev",
6161
"rimraf": "catalog:dev",
6262
"shiki": "catalog:frontend",

packages/client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"monaco-editor": "catalog:monaco",
5656
"nanotar": "catalog:frontend",
5757
"pptxgenjs": "catalog:prod",
58-
"prettier": "catalog:frontend",
5958
"recordrtc": "catalog:frontend",
6059
"shiki": "catalog:frontend",
6160
"shiki-magic-move": "catalog:frontend",

packages/slidev/node/vite/extendConfig.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const INCLUDE_GLOBAL = [
1111
'@typescript/ata',
1212
'file-saver',
1313
'lz-string',
14-
'prettier',
1514
'recordrtc',
1615
'typescript',
1716
'yaml',

packages/vscode/.vscodeignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ language-server/**
55
scripts/**
66
src/**
77
tsdown.config.ts
8-
*.map
8+
**/*.map
9+
syntaxes/codeblock-patch.ts
10+
syntaxes/slidev.example.md
11+
syntaxes/tsconfig.json
12+
syntaxes/.vscode

packages/vscode/language-server/import-meta-url.ts

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

packages/vscode/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"main": "./dist/index.cjs",
1919
"icon": "dist/res/logo.png",
2020
"engines": {
21-
"vscode": "^1.89.0"
21+
"vscode": "^1.99.0"
2222
},
2323
"activationEvents": [
2424
"onStartupFinished"
@@ -601,7 +601,7 @@
601601
"publish": "tsx scripts/publish.ts",
602602
"pack": "vsce package --no-dependencies",
603603
"prepare": "tsx scripts/schema.ts",
604-
"build": "tsdown --env.NODE_ENV production --treeshake",
604+
"build": "tsdown --env.NODE_ENV production --treeshake --minify",
605605
"dev": "nr prepare && tsdown --watch ./src --watch ./language-server --env.NODE_ENV development",
606606
"vscode:prepublish": "nr build"
607607
},
@@ -610,13 +610,13 @@
610610
"@slidev/parser": "workspace:*",
611611
"@slidev/types": "workspace:*",
612612
"@types/node": "catalog:types",
613-
"@types/vscode": "catalog:types",
613+
"@types/vscode": "^1.99.0",
614614
"@volar/language-server": "catalog:vscode",
615615
"@volar/vscode": "catalog:vscode",
616616
"get-port-please": "catalog:prod",
617617
"mlly": "catalog:prod",
618618
"ovsx": "catalog:dev",
619-
"prettier": "catalog:frontend",
619+
"prettier": "catalog:vscode",
620620
"reactive-vscode": "catalog:vscode",
621621
"tm-grammars": "catalog:frontend",
622622
"ts-json-schema-generator": "catalog:vscode",

packages/vscode/scripts/publish.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Options } from 'tinyexec'
12
import fs from 'node:fs/promises'
23
import process from 'node:process'
34
import { x } from 'tinyexec'
@@ -23,11 +24,19 @@ async function publish() {
2324

2425
console.log('Publishing VS Code extension...')
2526

26-
await x('npm', ['run', 'build'], { nodeOptions: { cwd: root, stdio: 'inherit' } })
27+
const options: Partial<Options> = {
28+
nodeOptions: {
29+
cwd: root,
30+
stdio: 'inherit',
31+
},
32+
throwOnError: true,
33+
}
34+
35+
await x('npm', ['run', 'build'], options)
2736
console.log('\nPublish to VSCE...\n')
28-
await x('npx', ['@vscode/vsce', 'publish', '--no-dependencies', '-p', process.env.VSCE_TOKEN!], { nodeOptions: { cwd: root, stdio: 'inherit' } })
37+
await x('npx', ['@vscode/vsce', 'publish', '--no-dependencies', '-p', process.env.VSCE_TOKEN!], options)
2938
console.log('\nPublish to OVSE...\n')
30-
await x('npx', ['ovsx', 'publish', '--no-dependencies', '-p', process.env.OVSX_TOKEN!], { nodeOptions: { cwd: root, stdio: 'inherit' } })
39+
await x('npx', ['ovsx', 'publish', '--no-dependencies', '-p', process.env.OVSX_TOKEN!], options)
3140
}
3241

3342
publish()

packages/vscode/syntaxes/codeblock-patch.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import { readFileSync } from 'node:fs'
2-
import { join } from 'node:path'
3-
4-
const Markdown = JSON.parse(
5-
readFileSync(join(import.meta.dirname, '../node_modules/tm-grammars/grammars/markdown.json'), 'utf8'),
6-
)
1+
import Markdown from 'tm-grammars/grammars/markdown.json' with { type: 'json' }
72

83
const base = {
94
$schema: 'https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json',

packages/vscode/tsdown.config.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { copyFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs'
1+
import { existsSync } from 'node:fs'
2+
import { copyFile, mkdir, writeFile } from 'node:fs/promises'
23
import { join } from 'node:path'
34
import process from 'node:process'
45
import { fileURLToPath } from 'node:url'
@@ -7,51 +8,51 @@ import { defineConfig } from 'tsdown'
78
import { generateCodeblockPatch } from './syntaxes/codeblock-patch.ts'
89

910
export default defineConfig({
10-
// @ts-expect-error `entry` is valid option
1111
entry: {
1212
'index': 'src/index.ts',
1313
'language-server': 'language-server/bin.ts',
1414
},
1515
format: 'cjs',
16-
target: 'node18',
16+
target: 'node20',
1717
clean: true,
1818
minify: process.env.NODE_ENV === 'production',
1919
sourcemap: true,
2020
external: [
2121
'vscode',
2222
],
23-
shims: ['./language-server/import-meta-url.ts'],
24-
define: {
25-
'import.meta.url': 'import_meta_url',
26-
},
2723
alias: {
2824
'@slidev/parser/fs': fileURLToPath(new URL('../parser/src/fs.ts', import.meta.url)),
2925
'@slidev/parser/core': fileURLToPath(new URL('../parser/src/core.ts', import.meta.url)),
3026
'@slidev/parser/types': fileURLToPath(new URL('../parser/src/types.ts', import.meta.url)),
3127
'@slidev/parser': fileURLToPath(new URL('../parser/src/index.ts', import.meta.url)),
3228
},
33-
plugins: [{
34-
name: 'umd2esm',
35-
setup(build: any) {
36-
build.onResolve({ filter: /^(vscode-.*-languageservice|jsonc-parser)/ }, async (args: any) => {
37-
const pathUmdMay = await resolvePath(args.path, { url: args.resolveDir })
38-
// Call twice the replace is to solve the problem of the path in Windows
39-
const pathEsm = pathUmdMay.replace('/umd/', '/esm/').replace('\\umd\\', '\\esm\\')
40-
return { path: pathEsm }
41-
})
29+
plugins: [
30+
{
31+
name: 'umd2esm',
32+
resolveId: {
33+
filter: {
34+
id: /^(vscode-.*-languageservice|vscode-languageserver-types|jsonc-parser)/,
35+
},
36+
async handler(source, importer) {
37+
const pathUmdMay = await resolvePath(source, { url: importer })
38+
// Call twice the replace is to solve the problem of the path in Windows
39+
const pathEsm = pathUmdMay.replace('/umd/', '/esm/').replace('\\umd\\', '\\esm\\')
40+
return { id: pathEsm }
41+
},
42+
},
4243
},
43-
}],
44+
],
4445
async onSuccess() {
4546
const assetsDir = join(import.meta.dirname, '../../assets')
4647
const resDir = join(import.meta.dirname, './dist/res')
4748

4849
if (!existsSync(resDir))
49-
mkdirSync(resDir, { recursive: true })
50+
await mkdir(resDir, { recursive: true })
5051

5152
for (const file of ['logo-mono.svg', 'logo-mono-dark.svg', 'logo.png', 'logo.svg'])
52-
copyFileSync(join(assetsDir, file), join(resDir, file))
53+
await copyFile(join(assetsDir, file), join(resDir, file))
5354

54-
writeFileSync(
55+
await writeFile(
5556
join(import.meta.dirname, 'syntaxes/codeblock-patch.json'),
5657
JSON.stringify(generateCodeblockPatch(), null, 2),
5758
)

0 commit comments

Comments
 (0)