Skip to content

Commit

Permalink
Copy webServer from Typescript to VS Code (#165771)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sandersn authored Nov 14, 2022
1 parent 7f9aa05 commit cb43019
Show file tree
Hide file tree
Showing 9 changed files with 578 additions and 54 deletions.
1 change: 1 addition & 0 deletions build/gulpfile.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const compilations = [
'references-view/tsconfig.json',
'simple-browser/tsconfig.json',
'typescript-language-features/test-workspace/tsconfig.json',
'typescript-language-features/web/tsconfig.json',
'typescript-language-features/tsconfig.json',
'vscode-api-tests/tsconfig.json',
'vscode-colorize-tests/tsconfig.json',
Expand Down
17 changes: 6 additions & 11 deletions build/lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,19 +414,14 @@ async function webpackExtensions(taskName, isWatch, webpackConfigLocations) {
const webpackConfigs = [];
for (const { configPath, outputRoot } of webpackConfigLocations) {
const configOrFnOrArray = require(configPath);
function addConfig(configOrFn) {
let config;
if (typeof configOrFn === 'function') {
config = configOrFn({}, {});
function addConfig(configOrFnOrArray) {
for (const configOrFn of Array.isArray(configOrFnOrArray) ? configOrFnOrArray : [configOrFnOrArray]) {
const config = typeof configOrFn === 'function' ? configOrFn({}, {}) : configOrFn;
if (outputRoot) {
config.output.path = path.join(outputRoot, path.relative(path.dirname(configPath), config.output.path));
}
webpackConfigs.push(config);
}
else {
config = configOrFn;
}
if (outputRoot) {
config.output.path = path.join(outputRoot, path.relative(path.dirname(configPath), config.output.path));
}
webpackConfigs.push(configOrFn);
}
addConfig(configOrFnOrArray);
}
Expand Down
18 changes: 6 additions & 12 deletions build/lib/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,20 +506,14 @@ export async function webpackExtensions(taskName: string, isWatch: boolean, webp

for (const { configPath, outputRoot } of webpackConfigLocations) {
const configOrFnOrArray = require(configPath);
function addConfig(configOrFn: webpack.Configuration | Function) {
let config;
if (typeof configOrFn === 'function') {
config = (configOrFn as Function)({}, {});
function addConfig(configOrFnOrArray: webpack.Configuration | ((env: unknown,args: unknown) => webpack.Configuration) | webpack.Configuration[]) {
for (const configOrFn of Array.isArray(configOrFnOrArray) ? configOrFnOrArray : [configOrFnOrArray]) {
const config = typeof configOrFn === 'function' ? configOrFn({}, {}) : configOrFn;
if (outputRoot) {
config.output!.path = path.join(outputRoot, path.relative(path.dirname(configPath), config.output!.path!));
}
webpackConfigs.push(config);
} else {
config = configOrFn;
}

if (outputRoot) {
config.output.path = path.join(outputRoot, path.relative(path.dirname(configPath), config.output.path));
}

webpackConfigs.push(configOrFn);
}
addConfig(configOrFnOrArray);
}
Expand Down
3 changes: 3 additions & 0 deletions extensions/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/typescript/lib/tsc.js
node_modules/typescript/lib/typescriptServices.js
node_modules/typescript/lib/tsserverlibrary.js
1 change: 0 additions & 1 deletion extensions/postinstall.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function processRoot() {
function processLib() {
const toDelete = new Set([
'tsc.js',
'tsserverlibrary.js',
'typescriptServices.js',
]);

Expand Down
1 change: 1 addition & 0 deletions extensions/typescript-language-features/.vscodeignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build/**
src/**
web/**
test/**
test-workspace/**
out/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

'use strict';
const CopyPlugin = require('copy-webpack-plugin');
const Terser = require('terser');
const fs = require('fs');
const path = require('path');

const defaultConfig = require('../shared.webpack.config');
Expand All @@ -30,8 +28,7 @@ const languages = [
'tr',
'zh-cn',
];

module.exports = withBrowserDefaults({
module.exports = [withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/extension.browser.ts',
Expand Down Expand Up @@ -60,30 +57,21 @@ module.exports = withBrowserDefaults({
}))
],
}),
// @ts-ignore
new CopyPlugin({
patterns: [
{
from: '../node_modules/typescript/lib/tsserver.js',
to: 'typescript/tsserver.web.js',
transform: async (content) => {
const dynamicImportCompatPath = path.join(__dirname, '..', 'node_modules', 'typescript', 'lib', 'dynamicImportCompat.js');
const prefix = fs.existsSync(dynamicImportCompatPath) ? fs.readFileSync(dynamicImportCompatPath) : undefined;
const output = await Terser.minify(content.toString());
if (!output.code) {
throw new Error('Terser returned undefined code');
}

if (prefix) {
return prefix.toString() + '\n' + output.code;
}
return output.code;
},
transformPath: (targetPath) => {
return targetPath.replace('tsserver.js', 'tsserver.web.js');
}
}
],
}),
],
});
}), withBrowserDefaults({
context: __dirname,
entry: {
'typescript/tsserver.web': './web/webServer.ts'
},
ignoreWarnings: [/Critical dependency: the request of a dependency is an expression/],
output: {
// all output goes into `dist`.
// packaging depends on that and this must always be like it
filename: '[name].js',
path: path.join(__dirname, 'dist', 'browser'),
libraryTarget: undefined,
},
externals: {
'perf_hooks': 'commonjs perf_hooks',
}
})];
15 changes: 15 additions & 0 deletions extensions/typescript-language-features/web/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../../out",
"module": "nodenext",
"moduleDetection": "legacy",
"experimentalDecorators": true,
"types": [
"node"
]
},
"files": [
"webServer.ts"
]
}
Loading

1 comment on commit cb43019

@jeanp413
Copy link
Contributor

@jeanp413 jeanp413 commented on cb43019 Nov 15, 2022

Choose a reason for hiding this comment

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

Web build is broken here cc @sandersn @mjbvz

Please sign in to comment.