From 71ff65a9f76c42f312b2d4f1eb33ebaaf6d551a2 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Thu, 7 Nov 2024 03:38:56 +0800 Subject: [PATCH] chore(vscode): share `@vue/language-core` between build files --- extensions/vscode/package.json | 2 +- extensions/vscode/scripts/build.js | 20 ++++++++++++++++---- extensions/vscode/src/nodeClientMain.ts | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 1f3af07bbd..1b47dc5253 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -88,7 +88,7 @@ ], "typescriptServerPlugins": [ { - "name": "typescript-vue-plugin-bundle", + "name": "typescript-vue-plugin-pack", "enableForWorkspaceTypeScriptVersions": true, "configNamespace": "typescript" } diff --git a/extensions/vscode/scripts/build.js b/extensions/vscode/scripts/build.js index 8a1c4bc27e..43fc18e834 100644 --- a/extensions/vscode/scripts/build.js +++ b/extensions/vscode/scripts/build.js @@ -6,7 +6,8 @@ require('esbuild').context({ entryPoints: { 'dist/client': './out/nodeClientMain.js', 'dist/server': './node_modules/@vue/language-server/bin/vue-language-server.js', - 'node_modules/typescript-vue-plugin-bundle/index': './node_modules/@vue/typescript-plugin/index.js', + 'node_modules/vue-language-core-pack/index': './node_modules/@vue/language-core/index.js', + 'node_modules/typescript-vue-plugin-pack/index': './node_modules/@vue/typescript-plugin/index.js', }, bundle: true, metafile: process.argv.includes('--metafile'), @@ -22,13 +23,24 @@ require('esbuild').context({ name: 'umd2esm', setup(build) { build.onResolve({ filter: /^(vscode-.*-languageservice|jsonc-parser)/ }, args => { - const pathUmdMay = require.resolve(args.path, { paths: [args.resolveDir] }) + const pathUmdMay = require.resolve(args.path, { paths: [args.resolveDir] }); // Call twice the replace is to solve the problem of the path in Windows - const pathEsm = pathUmdMay.replace('/umd/', '/esm/').replace('\\umd\\', '\\esm\\') - return { path: pathEsm } + const pathEsm = pathUmdMay.replace('/umd/', '/esm/').replace('\\umd\\', '\\esm\\'); + return { path: pathEsm }; }) }, }, + { + name: 'resolve-share-module', + setup(build) { + build.onResolve({ filter: /^@vue\/language-core$/ }, () => { + return { + path: 'vue-language-core-pack', + external: true, + }; + }); + }, + }, { name: 'schemas', setup(build) { diff --git a/extensions/vscode/src/nodeClientMain.ts b/extensions/vscode/src/nodeClientMain.ts index cf8359722c..ab29d80594 100644 --- a/extensions/vscode/src/nodeClientMain.ts +++ b/extensions/vscode/src/nodeClientMain.ts @@ -150,7 +150,7 @@ try { if (!enabledTypeScriptPlugin.value) { text = text.replace( 'for(const e of n.contributes.typescriptServerPlugins', - s => s + `.filter(p=>p.name!=='typescript-vue-plugin-bundle')` + s => s + `.filter(p=>p.name!=='typescript-vue-plugin-pack')` ); } else if (enabledHybridMode.value) { // patch readPlugins @@ -158,7 +158,7 @@ try { 'languages:Array.isArray(e.languages)', [ 'languages:', - `e.name==='typescript-vue-plugin-bundle'?[${config.server.includeLanguages + `e.name==='typescript-vue-plugin-pack'?[${config.server.includeLanguages .map(lang => `'${lang}'`) .join(',')}]`, ':Array.isArray(e.languages)'