Skip to content

Commit cb43019

Browse files
authored
Copy webServer from Typescript to VS Code (microsoft#165771)
* Initial draft. Not working. Also not correctly formatted, I'll do that later. * Various fixes It works now * A bit of cleanup * Move webServer to its own directory And prepare for getting rid of dynamicImportCompat.js hack * Remove dynamicImportCompat.js hack * Revert unrelated change * Webpac tsserver.web.js with webServer.ts as entrypoint Instead of using CopyPlugin. 1. Shipping multiple entrypoints in a single file required fixes to build code. 2. There are a couple of warnings from `require` calls in tsserverlibrary.js. Those are not relevant since they're in non-web code, but I haven't figured how to turn them off; they are fully dynamic so `externals` didn't work. * Ignore warnings from dynamic import in tsserver * Add to .vscodeignore files
1 parent 7f9aa05 commit cb43019

File tree

9 files changed

+578
-54
lines changed

9 files changed

+578
-54
lines changed

build/gulpfile.extensions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const compilations = [
6464
'references-view/tsconfig.json',
6565
'simple-browser/tsconfig.json',
6666
'typescript-language-features/test-workspace/tsconfig.json',
67+
'typescript-language-features/web/tsconfig.json',
6768
'typescript-language-features/tsconfig.json',
6869
'vscode-api-tests/tsconfig.json',
6970
'vscode-colorize-tests/tsconfig.json',

build/lib/extensions.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -414,19 +414,14 @@ async function webpackExtensions(taskName, isWatch, webpackConfigLocations) {
414414
const webpackConfigs = [];
415415
for (const { configPath, outputRoot } of webpackConfigLocations) {
416416
const configOrFnOrArray = require(configPath);
417-
function addConfig(configOrFn) {
418-
let config;
419-
if (typeof configOrFn === 'function') {
420-
config = configOrFn({}, {});
417+
function addConfig(configOrFnOrArray) {
418+
for (const configOrFn of Array.isArray(configOrFnOrArray) ? configOrFnOrArray : [configOrFnOrArray]) {
419+
const config = typeof configOrFn === 'function' ? configOrFn({}, {}) : configOrFn;
420+
if (outputRoot) {
421+
config.output.path = path.join(outputRoot, path.relative(path.dirname(configPath), config.output.path));
422+
}
421423
webpackConfigs.push(config);
422424
}
423-
else {
424-
config = configOrFn;
425-
}
426-
if (outputRoot) {
427-
config.output.path = path.join(outputRoot, path.relative(path.dirname(configPath), config.output.path));
428-
}
429-
webpackConfigs.push(configOrFn);
430425
}
431426
addConfig(configOrFnOrArray);
432427
}

build/lib/extensions.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -506,20 +506,14 @@ export async function webpackExtensions(taskName: string, isWatch: boolean, webp
506506

507507
for (const { configPath, outputRoot } of webpackConfigLocations) {
508508
const configOrFnOrArray = require(configPath);
509-
function addConfig(configOrFn: webpack.Configuration | Function) {
510-
let config;
511-
if (typeof configOrFn === 'function') {
512-
config = (configOrFn as Function)({}, {});
509+
function addConfig(configOrFnOrArray: webpack.Configuration | ((env: unknown,args: unknown) => webpack.Configuration) | webpack.Configuration[]) {
510+
for (const configOrFn of Array.isArray(configOrFnOrArray) ? configOrFnOrArray : [configOrFnOrArray]) {
511+
const config = typeof configOrFn === 'function' ? configOrFn({}, {}) : configOrFn;
512+
if (outputRoot) {
513+
config.output!.path = path.join(outputRoot, path.relative(path.dirname(configPath), config.output!.path!));
514+
}
513515
webpackConfigs.push(config);
514-
} else {
515-
config = configOrFn;
516516
}
517-
518-
if (outputRoot) {
519-
config.output.path = path.join(outputRoot, path.relative(path.dirname(configPath), config.output.path));
520-
}
521-
522-
webpackConfigs.push(configOrFn);
523517
}
524518
addConfig(configOrFnOrArray);
525519
}

extensions/.vscodeignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/typescript/lib/tsc.js
2+
node_modules/typescript/lib/typescriptServices.js
3+
node_modules/typescript/lib/tsserverlibrary.js

extensions/postinstall.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ function processRoot() {
2626
function processLib() {
2727
const toDelete = new Set([
2828
'tsc.js',
29-
'tsserverlibrary.js',
3029
'typescriptServices.js',
3130
]);
3231

extensions/typescript-language-features/.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
build/**
22
src/**
3+
web/**
34
test/**
45
test-workspace/**
56
out/**

extensions/typescript-language-features/extension-browser.webpack.config.js

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
'use strict';
99
const CopyPlugin = require('copy-webpack-plugin');
10-
const Terser = require('terser');
11-
const fs = require('fs');
1210
const path = require('path');
1311

1412
const defaultConfig = require('../shared.webpack.config');
@@ -30,8 +28,7 @@ const languages = [
3028
'tr',
3129
'zh-cn',
3230
];
33-
34-
module.exports = withBrowserDefaults({
31+
module.exports = [withBrowserDefaults({
3532
context: __dirname,
3633
entry: {
3734
extension: './src/extension.browser.ts',
@@ -60,30 +57,21 @@ module.exports = withBrowserDefaults({
6057
}))
6158
],
6259
}),
63-
// @ts-ignore
64-
new CopyPlugin({
65-
patterns: [
66-
{
67-
from: '../node_modules/typescript/lib/tsserver.js',
68-
to: 'typescript/tsserver.web.js',
69-
transform: async (content) => {
70-
const dynamicImportCompatPath = path.join(__dirname, '..', 'node_modules', 'typescript', 'lib', 'dynamicImportCompat.js');
71-
const prefix = fs.existsSync(dynamicImportCompatPath) ? fs.readFileSync(dynamicImportCompatPath) : undefined;
72-
const output = await Terser.minify(content.toString());
73-
if (!output.code) {
74-
throw new Error('Terser returned undefined code');
75-
}
76-
77-
if (prefix) {
78-
return prefix.toString() + '\n' + output.code;
79-
}
80-
return output.code;
81-
},
82-
transformPath: (targetPath) => {
83-
return targetPath.replace('tsserver.js', 'tsserver.web.js');
84-
}
85-
}
86-
],
87-
}),
8860
],
89-
});
61+
}), withBrowserDefaults({
62+
context: __dirname,
63+
entry: {
64+
'typescript/tsserver.web': './web/webServer.ts'
65+
},
66+
ignoreWarnings: [/Critical dependency: the request of a dependency is an expression/],
67+
output: {
68+
// all output goes into `dist`.
69+
// packaging depends on that and this must always be like it
70+
filename: '[name].js',
71+
path: path.join(__dirname, 'dist', 'browser'),
72+
libraryTarget: undefined,
73+
},
74+
externals: {
75+
'perf_hooks': 'commonjs perf_hooks',
76+
}
77+
})];
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"outDir": "../../out",
5+
"module": "nodenext",
6+
"moduleDetection": "legacy",
7+
"experimentalDecorators": true,
8+
"types": [
9+
"node"
10+
]
11+
},
12+
"files": [
13+
"webServer.ts"
14+
]
15+
}

0 commit comments

Comments
 (0)