Skip to content

Commit d0d28a6

Browse files
authored
Reapply building of web server (microsoft#166391)
* Reapply building of web server Revert 8b4642a * Fix critical dep error
1 parent ada0a06 commit d0d28a6

File tree

9 files changed

+633
-100
lines changed

9 files changed

+633
-100
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: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function fromLocalWebpack(extensionPath, webpackConfigFileName) {
104104
// check for a webpack configuration files, then invoke webpack
105105
// and merge its output with the files stream.
106106
const webpackConfigLocations = glob.sync(path.join(extensionPath, '**', webpackConfigFileName), { ignore: ['**/node_modules'] });
107-
const webpackStreams = webpackConfigLocations.map(webpackConfigPath => {
107+
const webpackStreams = webpackConfigLocations.flatMap(webpackConfigPath => {
108108
const webpackDone = (err, stats) => {
109109
fancyLog(`Bundled extension: ${ansiColors.yellow(path.join(path.basename(extensionPath), path.relative(extensionPath, webpackConfigPath)))}...`);
110110
if (err) {
@@ -118,27 +118,30 @@ function fromLocalWebpack(extensionPath, webpackConfigFileName) {
118118
result.emit('error', compilation.warnings.join('\n'));
119119
}
120120
};
121-
const webpackConfig = {
122-
...require(webpackConfigPath),
123-
...{ mode: 'production' }
124-
};
125-
const relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
126-
return webpackGulp(webpackConfig, webpack, webpackDone)
127-
.pipe(es.through(function (data) {
128-
data.stat = data.stat || {};
129-
data.base = extensionPath;
130-
this.emit('data', data);
131-
}))
132-
.pipe(es.through(function (data) {
133-
// source map handling:
134-
// * rewrite sourceMappingURL
135-
// * save to disk so that upload-task picks this up
136-
const contents = data.contents.toString('utf8');
137-
data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
138-
return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`;
139-
}), 'utf8');
140-
this.emit('data', data);
141-
}));
121+
const exportedConfig = require(webpackConfigPath);
122+
return (Array.isArray(exportedConfig) ? exportedConfig : [exportedConfig]).map(config => {
123+
const webpackConfig = {
124+
...config,
125+
...{ mode: 'production' }
126+
};
127+
const relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
128+
return webpackGulp(webpackConfig, webpack, webpackDone)
129+
.pipe(es.through(function (data) {
130+
data.stat = data.stat || {};
131+
data.base = extensionPath;
132+
this.emit('data', data);
133+
}))
134+
.pipe(es.through(function (data) {
135+
// source map handling:
136+
// * rewrite sourceMappingURL
137+
// * save to disk so that upload-task picks this up
138+
const contents = data.contents.toString('utf8');
139+
data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
140+
return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`;
141+
}), 'utf8');
142+
this.emit('data', data);
143+
}));
144+
});
142145
});
143146
es.merge(...webpackStreams, es.readArray(files))
144147
// .pipe(es.through(function (data) {
@@ -414,19 +417,14 @@ async function webpackExtensions(taskName, isWatch, webpackConfigLocations) {
414417
const webpackConfigs = [];
415418
for (const { configPath, outputRoot } of webpackConfigLocations) {
416419
const configOrFnOrArray = require(configPath);
417-
function addConfig(configOrFn) {
418-
let config;
419-
if (typeof configOrFn === 'function') {
420-
config = configOrFn({}, {});
420+
function addConfig(configOrFnOrArray) {
421+
for (const configOrFn of Array.isArray(configOrFnOrArray) ? configOrFnOrArray : [configOrFnOrArray]) {
422+
const config = typeof configOrFn === 'function' ? configOrFn({}, {}) : configOrFn;
423+
if (outputRoot) {
424+
config.output.path = path.join(outputRoot, path.relative(path.dirname(configPath), config.output.path));
425+
}
421426
webpackConfigs.push(config);
422427
}
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);
430428
}
431429
addConfig(configOrFnOrArray);
432430
}

build/lib/extensions.ts

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function fromLocalWebpack(extensionPath: string, webpackConfigFileName: string):
121121
{ ignore: ['**/node_modules'] }
122122
));
123123

124-
const webpackStreams = webpackConfigLocations.map(webpackConfigPath => {
124+
const webpackStreams = webpackConfigLocations.flatMap(webpackConfigPath => {
125125

126126
const webpackDone = (err: any, stats: any) => {
127127
fancyLog(`Bundled extension: ${ansiColors.yellow(path.join(path.basename(extensionPath), path.relative(extensionPath, webpackConfigPath)))}...`);
@@ -137,29 +137,32 @@ function fromLocalWebpack(extensionPath: string, webpackConfigFileName: string):
137137
}
138138
};
139139

140-
const webpackConfig = {
141-
...require(webpackConfigPath),
142-
...{ mode: 'production' }
143-
};
144-
const relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
145-
146-
return webpackGulp(webpackConfig, webpack, webpackDone)
147-
.pipe(es.through(function (data) {
148-
data.stat = data.stat || {};
149-
data.base = extensionPath;
150-
this.emit('data', data);
151-
}))
152-
.pipe(es.through(function (data: File) {
153-
// source map handling:
154-
// * rewrite sourceMappingURL
155-
// * save to disk so that upload-task picks this up
156-
const contents = (<Buffer>data.contents).toString('utf8');
157-
data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
158-
return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`;
159-
}), 'utf8');
160-
161-
this.emit('data', data);
162-
}));
140+
const exportedConfig = require(webpackConfigPath);
141+
return (Array.isArray(exportedConfig) ? exportedConfig : [exportedConfig]).map(config => {
142+
const webpackConfig = {
143+
...config,
144+
...{ mode: 'production' }
145+
};
146+
const relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
147+
148+
return webpackGulp(webpackConfig, webpack, webpackDone)
149+
.pipe(es.through(function (data) {
150+
data.stat = data.stat || {};
151+
data.base = extensionPath;
152+
this.emit('data', data);
153+
}))
154+
.pipe(es.through(function (data: File) {
155+
// source map handling:
156+
// * rewrite sourceMappingURL
157+
// * save to disk so that upload-task picks this up
158+
const contents = (<Buffer>data.contents).toString('utf8');
159+
data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
160+
return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`;
161+
}), 'utf8');
162+
163+
this.emit('data', data);
164+
}));
165+
});
163166
});
164167

165168
es.merge(...webpackStreams, es.readArray(files))
@@ -506,20 +509,14 @@ export async function webpackExtensions(taskName: string, isWatch: boolean, webp
506509

507510
for (const { configPath, outputRoot } of webpackConfigLocations) {
508511
const configOrFnOrArray = require(configPath);
509-
function addConfig(configOrFn: webpack.Configuration | Function) {
510-
let config;
511-
if (typeof configOrFn === 'function') {
512-
config = (configOrFn as Function)({}, {});
512+
function addConfig(configOrFnOrArray: webpack.Configuration | ((env: unknown, args: unknown) => webpack.Configuration) | webpack.Configuration[]) {
513+
for (const configOrFn of Array.isArray(configOrFnOrArray) ? configOrFnOrArray : [configOrFnOrArray]) {
514+
const config = typeof configOrFn === 'function' ? configOrFn({}, {}) : configOrFn;
515+
if (outputRoot) {
516+
config.output!.path = path.join(outputRoot, path.relative(path.dirname(configPath), config.output!.path!));
517+
}
513518
webpackConfigs.push(config);
514-
} else {
515-
config = configOrFn;
516519
}
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);
523520
}
524521
addConfig(configOrFnOrArray);
525522
}

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: 21 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,24 @@ 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+
module: {
67+
exprContextCritical: false,
68+
},
69+
ignoreWarnings: [/Critical dependency: the request of a dependency is an expression/],
70+
output: {
71+
// all output goes into `dist`.
72+
// packaging depends on that and this must always be like it
73+
filename: '[name].js',
74+
path: path.join(__dirname, 'dist', 'browser'),
75+
libraryTarget: undefined,
76+
},
77+
externals: {
78+
'perf_hooks': 'commonjs perf_hooks',
79+
}
80+
})];
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)