Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(vscode): use unjs/unbuild for bundling #4998

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4362e9c
chore: use unbuild
KermanX Nov 8, 2024
0f72495
fix
KermanX Nov 8, 2024
6c064d2
chore: remove scripts/build.js
KermanX Nov 8, 2024
575099a
Merge branch 'master' into chore/use-unbuild
KermanX Nov 8, 2024
0d16758
fix: .vscodeignore
KermanX Nov 8, 2024
6f1b173
fix
KermanX Nov 8, 2024
cdc604e
chore: update
KermanX Nov 8, 2024
46a38bd
add sonda report
KermanX Nov 9, 2024
13daf63
fix
KermanX Nov 9, 2024
2b9f8c4
chore: update
KermanX Nov 12, 2024
e0ab5f9
Merge branch 'master' into chore/use-unbuild
KermanX Dec 15, 2024
9f9a758
chore: update
KermanX Dec 15, 2024
fc2416d
fix
KermanX Dec 15, 2024
d377ade
chore: rename `vscode.js` to `vscode-dev-shim.js`
KermanX Dec 15, 2024
02af765
chore: update
KermanX Dec 15, 2024
516e1b6
fix: should build vue-typescript-plugin-pack
KermanX Dec 15, 2024
7868ce6
fix: use .ts as entry
KermanX Dec 15, 2024
3a180c7
chore: update sonda
KermanX Dec 15, 2024
5764d83
fix!!!
KermanX Dec 17, 2024
2887372
Merge branch 'master' into chore/use-unbuild
KermanX Dec 17, 2024
0460fbc
Merge branch 'master' into pr/4998
johnsoncodehk Dec 18, 2024
af30711
Update pnpm-lock.yaml
johnsoncodehk Dec 18, 2024
e64ff70
refactor(language-service): process references data at runtime to red…
KazariEX Dec 18, 2024
9b11d91
Merge branch 'master' into pr/4998
johnsoncodehk Dec 18, 2024
b3235c9
use `rollup-plugin-visualizer` instead of `sonda`
KermanX Dec 18, 2024
ef6c85d
Merge branch 'master' into pr/4998
johnsoncodehk Dec 18, 2024
866159b
Merge branch 'master' into chore/use-unbuild
KermanX Dec 18, 2024
b17e82d
Merge branch 'chore/use-unbuild' of https://github.com/KermanX/vuejs-…
KermanX Dec 18, 2024
6eceeb6
Merge branch 'master' of https://github.com/vuejs/language-tools into…
KermanX Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
"outFiles": [
"${workspaceRoot}/**/*.js"
],
"preLaunchTask": {
"type": "npm",
"script": "watch"
}
},
{
"name": "Launch Web Client",
Expand All @@ -33,10 +29,6 @@
"outFiles": [
"${workspaceRoot}/**/*.js"
],
"preLaunchTask": {
"type": "npm",
"script": "watch"
}
},
{
"name": "Attach to Language Server",
Expand Down
16 changes: 0 additions & 16 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@
"problemMatcher": [
"$tsc"
]
},
{
"type": "npm",
"script": "watch",
"isBackground": true,
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "dedicated",
"reveal": "never"
},
"problemMatcher": [
"$tsc-watch"
]
}
]
}
6 changes: 5 additions & 1 deletion extensions/vscode/.vscodeignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
out
scripts
src
tests
tsconfig.*
build.config.ts
vscode-dev-shim.js
meta.json
stats.html
dist/**/*.mjs
dist/**/*.d.ts
dist/**/*.map
16 changes: 8 additions & 8 deletions extensions/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ Finally you need to make VS Code recognize your new extension and automatically

<!-- commands -->

| Command | Title |
| ------------------------------ | ------------------------------------------------------ |
| `vue.action.restartServer` | Vue: Restart Vue and TS servers |
| `vue.action.doctor` | Vue: Doctor |
| `vue.action.writeVirtualFiles` | Vue (Debug): Write Virtual Files |
| `vue.action.splitEditors` | Vue: Split &lt;script&gt;, <template>, <style> Editors |
| `vue.findAllFileReferences` | Vue: Find File References via Vue Language Server |
| Command | Title |
| ------------------------------ | ------------------------------------------------- |
| `vue.action.restartServer` | Vue: Restart Vue and TS servers |
| `vue.action.doctor` | Vue: Doctor |
| `vue.action.writeVirtualFiles` | Vue (Debug): Write Virtual Files |
| `vue.action.splitEditors` | Vue: Split <script>, <template>, <style> Editors |
| `vue.findAllFileReferences` | Vue: Find File References via Vue Language Server |

<!-- commands -->

Expand All @@ -292,7 +292,7 @@ Finally you need to make VS Code recognize your new extension and automatically
| `vue.complete.casing.props` | Preferred attr name case. | `string` | `"autoKebab"` |
| `vue.complete.defineAssignment` | Auto add `const props = ` before `defineProps` when selecting the completion item `props`. (also `emit` and `slots`) | `boolean` | `true` |
| `vue.autoInsert.dotValue` | Auto-complete Ref value with `.value`. | `boolean` | `false` |
| `vue.autoInsert.bracketSpacing` | Auto add space between double curly brackets: {{&vert;}} -&gt; {{ | }} | `boolean` | `true` |
| `vue.autoInsert.bracketSpacing` | Auto add space between double curly brackets: {{|}} -> {{ | }} | `boolean` | `true` |
| `vue.inlayHints.destructuredProps` | Show inlay hints for destructured props. | `boolean` | `false` |
| `vue.inlayHints.missingProps` | Show inlay hints for missing required props. | `boolean` | `false` |
| `vue.inlayHints.inlineHandlerLeading` | Show inlay hints for event argument in inline handlers. | `boolean` | `false` |
Expand Down
121 changes: 121 additions & 0 deletions extensions/vscode/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineBuildConfig } from 'unbuild';
import { visualizer } from 'rollup-plugin-visualizer';

const __dirname = fileURLToPath(new URL('.', import.meta.url));
const languageServiceDataRE = /\/language-service\/data\/.*\.json$/;

export default defineBuildConfig([
{
entries: [
{
builder: 'rollup',
input: 'src/nodeClientMain.ts',
name: 'client',
},
{
builder: 'rollup',
input: './node_modules/@vue/language-server/node.ts',
name: 'server',
},
{
builder: 'rollup',
input: './node_modules/@vue/typescript-plugin/index.ts',
name: 'plugin',
},
{
builder: 'copy',
input: './node_modules/@vue/language-core/schemas',
outDir: './dist/schemas',
},
],
failOnWarn: false,
outDir: 'dist',
externals: ['vscode'],
replace: {
'globalThis.__VOLAR_DEV_FS__': 'undefined',
'process.env.NODE_ENV': '"production"',
},
sourcemap: true,
rollup: {
emitCJS: true,
esbuild: {
target: 'ES2021',
},
commonjs: {
transformMixedEsModules: true,
exclude: [/\.json$/],
},
json: {
compact: true,
preferConst: true,
exclude: languageServiceDataRE,
},
inlineDependencies: true,
},
stubOptions: {
jiti: {
alias: {
vscode: join(__dirname, 'vscode-dev-shim.js'),
},
sourceMaps: true,
fsCache: false,
},
},
hooks: {
'rollup:options'(_ctx, options) {
options.plugins = [
// Load language-service data as `JSON.parse(serialized)`
// See https://v8.dev/blog/cost-of-javascript-2019#json
{
name: 'language-service-data',
transform: {
order: 'pre',
handler(code: string, id: string) {
if (languageServiceDataRE.test(id.replaceAll('\\', '/'))) {
const minimal = JSON.stringify(JSON.parse(code));
const escaped = minimal.replaceAll(/[$`\\]/g, c => `\\${c}`);
return {
code: `export default JSON.parse(\`${escaped}\`)`,
map: { mappings: '' },
};
}
}
}
},

visualizer(),

...options.plugins,
];

// Only emit CJS
if (!Array.isArray(options.output)) throw new Error('Unreachable');
options.output = options.output.filter((option) => option.format === 'cjs');
if (options.output.length !== 1) throw new Error('Unreachable');
},

'build:done'(ctx) {
// Create the entry point for the TypeScript plugin
const typescriptPluginRoot = join(__dirname, 'node_modules/vue-typescript-plugin-pack');
mkdirSync(typescriptPluginRoot, { recursive: true });
writeFileSync(join(typescriptPluginRoot, 'index.js'), 'module.exports = require("../../dist/plugin.cjs");');

// Patch the stub files
if (ctx.options.stub) {
// Patch the stub file
const stubFilePath = join(__dirname, 'dist/client.cjs');
const originalStub = readFileSync(stubFilePath, 'utf-8');
const newStub = [
`globalThis.__VOLAR_DEV_VSCODE__ = require('vscode');`,
`globalThis.__VOLAR_DEV_FS__ = require('node:fs');`,
originalStub,
].join('\n');
writeFileSync(stubFilePath, newStub);
}
},
},
},
]);
5 changes: 0 additions & 5 deletions extensions/vscode/client.js

This file was deleted.

13 changes: 8 additions & 5 deletions extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"onLanguage:markdown",
"onLanguage:html"
],
"main": "./client.js",
"main": "./dist/client.cjs",
"browser": "./web.js",
"capabilities": {
"virtualWorkspaces": {
Expand Down Expand Up @@ -551,10 +551,10 @@
]
},
"scripts": {
"prebuild": "pnpm run postinstall && pnpm -C ../.. run build",
"build": "node scripts/build",
"build:minify": "pnpm run build -- --minify",
"watch": "pnpm run build -- --watch",
"__prebuild": "pnpm run postinstall && pnpm -C ../.. run build",
"build": "unbuild",
"build:minify": "pnpm run build --minify",
"dev": "unbuild --stub",
"pack": "pnpm run build:minify && vsce package",
"pack:next": "pnpm run build && vsce package",
"release": "pnpm run build:minify && vsce publish",
Expand All @@ -563,6 +563,7 @@
"postinstall": "vscode-ext-gen --scope vue"
},
"devDependencies": {
"@types/node": "latest",
"@types/semver": "^7.5.3",
"@types/vscode": "^1.82.0",
"@volar/vscode": "~2.4.11",
Expand All @@ -573,7 +574,9 @@
"esbuild": "latest",
"esbuild-visualizer": "latest",
"reactive-vscode": "^0.2.9",
"rollup-plugin-visualizer": "^5.12.0",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that you've replaced sonda with rollup-plugin-visualizer. I will not try to convince you to use sonda, but if this was a technical decision, could you share the reason? I would appreciate your feedback so I can improve it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @filipsobol, first of all thank you for developing sonda. One of the reasons is that we want the PR to keep the most relevant changes so that it has a greater chance of being merged. Another reason is that the output file treemap is paginated in Sonda, and we cannot visually check whether the modules that need to be shared by multiple files have been correctly split.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this gives me some interesting ideas 🤔

Another reason is that the output file treemap is paginated in Sonda, and we cannot visually check whether the modules that need to be shared by multiple files have been correctly split.

By visual check, do you mean manual or automated visual check? You should be able to switch between chunks using the dropdown menu in the upper-left corner, but I can imagine that it may require extra work or even problems in automated tests (e.g. if it visually compares two reports).

"semver": "^7.5.4",
"unbuild": "^3.0.1",
"vscode-ext-gen": "^0.5.0",
"vscode-tmlanguage-snapshot": "latest"
}
Expand Down
93 changes: 0 additions & 93 deletions extensions/vscode/scripts/build.js

This file was deleted.

5 changes: 0 additions & 5 deletions extensions/vscode/server.js

This file was deleted.

9 changes: 4 additions & 5 deletions extensions/vscode/src/nodeClientMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createLabsInfo } from '@volar/vscode';
import * as lsp from '@volar/vscode/node';
import * as protocol from '@vue/language-server/protocol';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { defineExtension, executeCommand, extensionContext, onDeactivate } from 'reactive-vscode';
import * as vscode from 'vscode';
import { config } from './config';
Expand Down Expand Up @@ -51,7 +52,7 @@ export const { activate, deactivate } = defineExtension(async () => {
}
}

let serverModule = vscode.Uri.joinPath(context.extensionUri, 'server.js');
let serverModule = vscode.Uri.joinPath(context.extensionUri, 'dist/server.cjs');

const runOptions: lsp.ForkOptions = {};
if (config.server.maxOldSpaceSize) {
Expand Down Expand Up @@ -137,12 +138,10 @@ try {
'vscode.typescript-language-features'
)!;
const readFileSync = fs.readFileSync;
const extensionJsPath = require.resolve('./dist/extension.js', {
paths: [tsExtension.extensionPath],
});
const extensionJsPath = path.join(tsExtension.extensionPath, './dist/extension.js');

// @ts-expect-error
fs.readFileSync = (...args) => {
(globalThis.__VOLAR_DEV_FS__ || require('fs')).readFileSync = (...args) => {
if (args[0] === extensionJsPath) {
// @ts-expect-error
let text = readFileSync(...args) as string;
Expand Down
2 changes: 0 additions & 2 deletions extensions/vscode/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "out",
"rootDir": "src",
"module": "CommonJS",
"moduleResolution": "Node"
},
Expand Down
Loading
Loading