@theia/application-manager 1.75.0-next.46 → 1.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/application-package-manager.d.ts.map +1 -1
- package/lib/application-package-manager.js +5 -9
- package/lib/application-package-manager.js.map +1 -1
- package/lib/generator/bundler-generator.d.ts +7 -8
- package/lib/generator/bundler-generator.d.ts.map +1 -1
- package/lib/generator/bundler-generator.js +32 -563
- package/lib/generator/bundler-generator.js.map +1 -1
- package/lib/generator/frontend-generator.d.ts.map +1 -1
- package/lib/generator/frontend-generator.js +1 -3
- package/lib/generator/frontend-generator.js.map +1 -1
- package/package.json +7 -29
- package/src/application-package-manager.ts +5 -8
- package/src/generator/bundler-generator.ts +36 -568
- package/src/generator/frontend-generator.ts +1 -3
- package/lib/expose-loader.d.ts +0 -9
- package/lib/expose-loader.d.ts.map +0 -1
- package/lib/expose-loader.js +0 -73
- package/lib/expose-loader.js.map +0 -1
- package/src/expose-loader.ts +0 -83
|
@@ -16,51 +16,33 @@
|
|
|
16
16
|
// *****************************************************************************
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.BundlerGenerator = void 0;
|
|
19
|
-
const paths = require("path");
|
|
20
19
|
const fs = require("fs-extra");
|
|
21
20
|
const abstract_generator_1 = require("./abstract-generator");
|
|
22
21
|
class BundlerGenerator extends abstract_generator_1.AbstractGenerator {
|
|
23
22
|
async generate() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (await this.shouldGenerateUserESBuildConfig()) {
|
|
33
|
-
await this.write(this.esbuildPath, this.compileESBuildUserConfig());
|
|
23
|
+
await this.warnAboutWebpackConfig();
|
|
24
|
+
await this.write(this.genESBuildBrowserPath, this.compileESBuildBrowserConfig());
|
|
25
|
+
if (!this.pck.isBrowserOnly()) {
|
|
26
|
+
await this.write(this.genESBuildNodePath, this.compileESBuildNodeConfig());
|
|
27
|
+
if (this.pck.isElectron()) {
|
|
28
|
+
await this.write(this.genESBuildElectronPath, this.compileESBuildElectronConfig());
|
|
34
29
|
}
|
|
35
30
|
}
|
|
36
|
-
|
|
37
|
-
await this.write(this.
|
|
38
|
-
if (!this.pck.isBrowserOnly()) {
|
|
39
|
-
await this.write(this.genNodeConfigPath, this.compileNodeWebpackConfig());
|
|
40
|
-
}
|
|
41
|
-
if (await this.shouldGenerateUserWebpackConfig()) {
|
|
42
|
-
await this.write(this.configPath, this.compileUserWebpackConfig());
|
|
43
|
-
}
|
|
31
|
+
if (await this.shouldGenerateUserESBuildConfig()) {
|
|
32
|
+
await this.write(this.esbuildPath, this.compileESBuildUserConfig());
|
|
44
33
|
}
|
|
45
34
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Warns about a `webpack.config.js` left over from Theia < 1.75.0. Such a file is no longer
|
|
37
|
+
* read, so any customization it contains no longer has an effect. Without this warning,
|
|
38
|
+
* adopters would only notice through a differently behaving bundle.
|
|
39
|
+
*/
|
|
40
|
+
async warnAboutWebpackConfig() {
|
|
41
|
+
if (await fs.pathExists(this.webpackConfigPath)) {
|
|
42
|
+
console.warn(`Ignoring '${this.webpackConfigPath}': webpack bundling was removed in Theia 1.75.0, '${this.esbuildPath}' is used instead.`);
|
|
43
|
+
console.warn('Port any customization to the esbuild configuration and delete the webpack files. See the migration guide for details: '
|
|
44
|
+
+ 'https://github.com/eclipse-theia/theia/blob/master/doc/Migration.md');
|
|
50
45
|
}
|
|
51
|
-
// If a webpack file already exists, prefer webpack
|
|
52
|
-
if (await fs.pathExists(this.configPath)) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
// Otherwise, prefer ESBuild (for performance)
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
async shouldGenerateUserWebpackConfig() {
|
|
59
|
-
if (!(await fs.pathExists(this.configPath))) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
const content = await fs.readFile(this.configPath, 'utf8');
|
|
63
|
-
return !content.includes('gen-webpack');
|
|
64
46
|
}
|
|
65
47
|
async shouldGenerateUserESBuildConfig() {
|
|
66
48
|
if (!(await fs.pathExists(this.esbuildPath))) {
|
|
@@ -69,15 +51,9 @@ class BundlerGenerator extends abstract_generator_1.AbstractGenerator {
|
|
|
69
51
|
const content = await fs.readFile(this.esbuildPath, 'utf8');
|
|
70
52
|
return !content.includes('gen-esbuild');
|
|
71
53
|
}
|
|
72
|
-
get
|
|
54
|
+
get webpackConfigPath() {
|
|
73
55
|
return this.pck.path('webpack.config.js');
|
|
74
56
|
}
|
|
75
|
-
get genConfigPath() {
|
|
76
|
-
return this.pck.path('gen-webpack.config.js');
|
|
77
|
-
}
|
|
78
|
-
get genNodeConfigPath() {
|
|
79
|
-
return this.pck.path('gen-webpack.node.config.js');
|
|
80
|
-
}
|
|
81
57
|
get esbuildPath() {
|
|
82
58
|
return this.pck.path('esbuild.mjs');
|
|
83
59
|
}
|
|
@@ -90,522 +66,6 @@ class BundlerGenerator extends abstract_generator_1.AbstractGenerator {
|
|
|
90
66
|
get genESBuildElectronPath() {
|
|
91
67
|
return this.pck.path('gen-esbuild.electron.mjs');
|
|
92
68
|
}
|
|
93
|
-
compileWebpackConfig() {
|
|
94
|
-
return `/**
|
|
95
|
-
* Don't touch this file. It will be regenerated by theia build.
|
|
96
|
-
* To customize webpack configuration change ${this.configPath}
|
|
97
|
-
*/
|
|
98
|
-
// @ts-check
|
|
99
|
-
const path = require('path');
|
|
100
|
-
const webpack = require('webpack');
|
|
101
|
-
const yargs = require('yargs');
|
|
102
|
-
const resolvePackagePath = require('resolve-package-path');
|
|
103
|
-
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
104
|
-
const CompressionPlugin = require('compression-webpack-plugin');
|
|
105
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
106
|
-
const { MonacoWebpackPlugin } = require('@theia/bundle-plugin');
|
|
107
|
-
|
|
108
|
-
const outputPath = path.resolve(__dirname, 'lib', 'frontend');
|
|
109
|
-
const { mode, staticCompression } = yargs.option('mode', {
|
|
110
|
-
description: "Mode to use",
|
|
111
|
-
choices: ["development", "production"],
|
|
112
|
-
default: "production"
|
|
113
|
-
}).option('static-compression', {
|
|
114
|
-
description: 'Controls whether to enable compression of static artifacts.',
|
|
115
|
-
type: 'boolean',
|
|
116
|
-
default: true
|
|
117
|
-
}).argv;
|
|
118
|
-
const development = mode === 'development';
|
|
119
|
-
|
|
120
|
-
const plugins = [
|
|
121
|
-
new CopyWebpackPlugin({
|
|
122
|
-
patterns: [
|
|
123
|
-
{
|
|
124
|
-
// copy secondary window html file to lib folder
|
|
125
|
-
from: path.resolve(__dirname, 'src-gen/frontend/secondary-window.html')
|
|
126
|
-
}${this.ifPackage('@theia/plugin-ext', `,
|
|
127
|
-
{
|
|
128
|
-
// copy webview files to lib folder
|
|
129
|
-
from: path.join(resolvePackagePath('@theia/plugin-ext', __dirname), '..', 'src', 'main', 'browser', 'webview', 'pre'),
|
|
130
|
-
to: path.resolve(__dirname, 'lib', 'webview', 'pre')
|
|
131
|
-
}`)}
|
|
132
|
-
${this.ifPackage('@theia/plugin-ext-vscode', `,
|
|
133
|
-
{
|
|
134
|
-
// copy frontend plugin host files
|
|
135
|
-
from: path.join(resolvePackagePath('@theia/plugin-ext-vscode', __dirname), '..', 'lib', 'node', 'context', 'plugin-vscode-init-fe.js'),
|
|
136
|
-
to: path.resolve(__dirname, 'lib', 'frontend', 'context', 'plugin-vscode-init-fe.js')
|
|
137
|
-
}`)}
|
|
138
|
-
${this.ifPackage('@theia/terminal', `,
|
|
139
|
-
{
|
|
140
|
-
// copy shell integration scripts
|
|
141
|
-
from: path.join(resolvePackagePath('@theia/terminal', __dirname), '..', 'src', 'node', 'shell-integrations'),
|
|
142
|
-
to: path.resolve(__dirname, 'lib', 'backend', 'shell-integrations')
|
|
143
|
-
}`)}
|
|
144
|
-
]
|
|
145
|
-
}),
|
|
146
|
-
new webpack.ProvidePlugin({
|
|
147
|
-
// the Buffer class doesn't exist in the browser but some dependencies rely on it
|
|
148
|
-
Buffer: ['buffer', 'Buffer']
|
|
149
|
-
}),
|
|
150
|
-
new MonacoWebpackPlugin()
|
|
151
|
-
];
|
|
152
|
-
// it should go after copy-plugin in order to compress monaco as well
|
|
153
|
-
if (staticCompression) {
|
|
154
|
-
plugins.push(new CompressionPlugin({}));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
module.exports = [{
|
|
158
|
-
mode,
|
|
159
|
-
plugins,
|
|
160
|
-
devtool: 'source-map',
|
|
161
|
-
entry: {
|
|
162
|
-
bundle: path.resolve(__dirname, 'src-gen/frontend/index.js'),
|
|
163
|
-
${this.ifPackage('@theia/plugin-ext', "'plugin-worker': '@theia/plugin-ext/lib/hosted/browser/worker/worker-main.js',")}
|
|
164
|
-
},
|
|
165
|
-
output: {
|
|
166
|
-
filename: '[name].js',
|
|
167
|
-
path: outputPath,
|
|
168
|
-
devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]',
|
|
169
|
-
globalObject: 'self'
|
|
170
|
-
},
|
|
171
|
-
target: 'web',
|
|
172
|
-
cache: staticCompression,
|
|
173
|
-
module: {
|
|
174
|
-
rules: [
|
|
175
|
-
{
|
|
176
|
-
test: /\\.css$/,
|
|
177
|
-
use: ['style-loader', 'css-loader']
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
test: /\\.(ttf|eot|svg)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,
|
|
181
|
-
type: 'asset',
|
|
182
|
-
parser: {
|
|
183
|
-
dataUrlCondition: {
|
|
184
|
-
maxSize: 10000,
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
generator: {
|
|
188
|
-
dataUrl: {
|
|
189
|
-
mimetype: 'image/svg+xml'
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
test: /\\.(jpg|png|gif)$/,
|
|
195
|
-
type: 'asset/resource',
|
|
196
|
-
generator: {
|
|
197
|
-
filename: '[hash].[ext]'
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
// see https://github.com/eclipse-theia/theia/issues/556
|
|
202
|
-
test: /source-map-support/,
|
|
203
|
-
loader: 'ignore-loader'
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
test: /\\.d\\.ts$/,
|
|
207
|
-
loader: 'ignore-loader'
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
test: /\\.js$/,
|
|
211
|
-
enforce: 'pre',
|
|
212
|
-
loader: 'source-map-loader',
|
|
213
|
-
exclude: /jsonc-parser|fast-plist|onigasm/
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
test: /\\.woff(2)?(\\?v=[0-9]\\.[0-9]\\.[0-9])?$/,
|
|
217
|
-
type: 'asset',
|
|
218
|
-
parser: {
|
|
219
|
-
dataUrlCondition: {
|
|
220
|
-
maxSize: 10000,
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
generator: {
|
|
224
|
-
dataUrl: {
|
|
225
|
-
mimetype: 'image/svg+xml'
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
test: /node_modules[\\\\|\/](vscode-languageserver-types|vscode-uri|jsonc-parser|vscode-languageserver-protocol)/,
|
|
231
|
-
loader: 'umd-compat-loader'
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
test: /\\.wasm$/,
|
|
235
|
-
type: 'asset/resource'
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
test: /\\.plist$/,
|
|
239
|
-
type: 'asset/resource'
|
|
240
|
-
}
|
|
241
|
-
]
|
|
242
|
-
},
|
|
243
|
-
resolve: {
|
|
244
|
-
fallback: {
|
|
245
|
-
'child_process': false,
|
|
246
|
-
'crypto': false,
|
|
247
|
-
'net': false,
|
|
248
|
-
'path': require.resolve('path-browserify'),
|
|
249
|
-
'process': false,
|
|
250
|
-
'os': false,
|
|
251
|
-
'timers': false
|
|
252
|
-
},
|
|
253
|
-
${this.ifMonaco(() => `alias: {
|
|
254
|
-
// Replace Monaco's nls module with Theia's localization-aware version.
|
|
255
|
-
// ESM exports are immutable so we cannot override localize/localize2 at runtime.
|
|
256
|
-
// Using the resolved absolute path ensures that both external imports
|
|
257
|
-
// (e.g. '@theia/monaco-editor-core/esm/vs/nls') and internal relative
|
|
258
|
-
// imports within Monaco (e.g. '../nls.js') are redirected.
|
|
259
|
-
[path.join(resolvePackagePath('@theia/monaco-editor-core', __dirname), '..', 'esm', 'vs', 'nls.js')]:
|
|
260
|
-
path.join(resolvePackagePath('@theia/monaco', __dirname), '..', 'lib', 'browser', 'monaco-nls.js')
|
|
261
|
-
},`)}
|
|
262
|
-
extensions: ['.js']
|
|
263
|
-
},
|
|
264
|
-
stats: {
|
|
265
|
-
warnings: true,
|
|
266
|
-
children: true
|
|
267
|
-
},
|
|
268
|
-
ignoreWarnings: [
|
|
269
|
-
// Some packages do not have source maps, that's ok
|
|
270
|
-
/Failed to parse source map/,
|
|
271
|
-
{
|
|
272
|
-
// Monaco uses 'require' in a non-standard way
|
|
273
|
-
module: /@theia\\/monaco-editor-core/,
|
|
274
|
-
message: /require function is used in a way in which dependencies cannot be statically extracted/
|
|
275
|
-
}
|
|
276
|
-
]
|
|
277
|
-
},
|
|
278
|
-
${this.ifMonaco(() => `{
|
|
279
|
-
// The Monaco editor worker must be built separately without the NLS alias.
|
|
280
|
-
// The NLS alias redirects to monaco-nls.ts which imports from @theia/core,
|
|
281
|
-
// and those modules are not available in the web worker context.
|
|
282
|
-
mode,
|
|
283
|
-
devtool: 'source-map',
|
|
284
|
-
entry: {
|
|
285
|
-
'editor.worker': '@theia/monaco-editor-core/esm/vs/editor/common/services/editorWebWorkerMain.js'
|
|
286
|
-
},
|
|
287
|
-
output: {
|
|
288
|
-
filename: '[name].js',
|
|
289
|
-
path: outputPath,
|
|
290
|
-
devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]',
|
|
291
|
-
globalObject: 'self'
|
|
292
|
-
},
|
|
293
|
-
target: 'webworker',
|
|
294
|
-
cache: staticCompression,
|
|
295
|
-
resolve: {
|
|
296
|
-
extensions: ['.js']
|
|
297
|
-
},
|
|
298
|
-
ignoreWarnings: [
|
|
299
|
-
{
|
|
300
|
-
module: /@theia\\/monaco-editor-core/,
|
|
301
|
-
message: /require function is used in a way in which dependencies cannot be statically extracted/
|
|
302
|
-
}
|
|
303
|
-
]
|
|
304
|
-
},`)}
|
|
305
|
-
{
|
|
306
|
-
mode,
|
|
307
|
-
plugins: [
|
|
308
|
-
new MiniCssExtractPlugin({
|
|
309
|
-
// Options similar to the same options in webpackOptions.output
|
|
310
|
-
// both options are optional
|
|
311
|
-
filename: "[name].css",
|
|
312
|
-
chunkFilename: "[id].css",
|
|
313
|
-
}),
|
|
314
|
-
new MonacoWebpackPlugin(),
|
|
315
|
-
],
|
|
316
|
-
devtool: 'source-map',
|
|
317
|
-
entry: {
|
|
318
|
-
"secondary-window": path.resolve(__dirname, 'src-gen/frontend/secondary-index.js'),
|
|
319
|
-
},
|
|
320
|
-
output: {
|
|
321
|
-
filename: '[name].js',
|
|
322
|
-
path: outputPath,
|
|
323
|
-
devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]',
|
|
324
|
-
globalObject: 'self'
|
|
325
|
-
},
|
|
326
|
-
target: 'web',
|
|
327
|
-
cache: staticCompression,
|
|
328
|
-
module: {
|
|
329
|
-
rules: [
|
|
330
|
-
{
|
|
331
|
-
test: /\.css$/i,
|
|
332
|
-
use: [MiniCssExtractPlugin.loader, "css-loader"]
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
test: /\.wasm$/,
|
|
336
|
-
type: 'asset/resource'
|
|
337
|
-
}
|
|
338
|
-
]
|
|
339
|
-
},
|
|
340
|
-
resolve: {
|
|
341
|
-
fallback: {
|
|
342
|
-
'child_process': false,
|
|
343
|
-
'crypto': false,
|
|
344
|
-
'net': false,
|
|
345
|
-
'path': require.resolve('path-browserify'),
|
|
346
|
-
'process': false,
|
|
347
|
-
'os': false,
|
|
348
|
-
'timers': false
|
|
349
|
-
},
|
|
350
|
-
${this.ifMonaco(() => `alias: {
|
|
351
|
-
// Replace Monaco's nls module with Theia's localization-aware version.
|
|
352
|
-
// ESM exports are immutable so we cannot override localize/localize2 at runtime.
|
|
353
|
-
// Using the resolved absolute path ensures that both external imports
|
|
354
|
-
// (e.g. '@theia/monaco-editor-core/esm/vs/nls') and internal relative
|
|
355
|
-
// imports within Monaco (e.g. '../nls.js') are redirected.
|
|
356
|
-
[path.join(resolvePackagePath('@theia/monaco-editor-core', __dirname), '..', 'esm', 'vs', 'nls.js')]:
|
|
357
|
-
path.join(resolvePackagePath('@theia/monaco', __dirname), '..', 'lib', 'browser', 'monaco-nls.js')
|
|
358
|
-
},`)}
|
|
359
|
-
extensions: ['.js']
|
|
360
|
-
},
|
|
361
|
-
stats: {
|
|
362
|
-
warnings: true,
|
|
363
|
-
children: true
|
|
364
|
-
},
|
|
365
|
-
ignoreWarnings: [
|
|
366
|
-
{
|
|
367
|
-
// Monaco uses 'require' in a non-standard way
|
|
368
|
-
module: /@theia\\/monaco-editor-core/,
|
|
369
|
-
message: /require function is used in a way in which dependencies cannot be statically extracted/
|
|
370
|
-
}
|
|
371
|
-
]
|
|
372
|
-
}${this.ifElectron(`, {
|
|
373
|
-
mode,
|
|
374
|
-
devtool: 'source-map',
|
|
375
|
-
entry: {
|
|
376
|
-
"preload": path.resolve(__dirname, 'src-gen/frontend/preload.js'),
|
|
377
|
-
},
|
|
378
|
-
output: {
|
|
379
|
-
filename: '[name].js',
|
|
380
|
-
path: outputPath,
|
|
381
|
-
devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]',
|
|
382
|
-
globalObject: 'self'
|
|
383
|
-
},
|
|
384
|
-
target: 'electron-preload',
|
|
385
|
-
cache: staticCompression,
|
|
386
|
-
stats: {
|
|
387
|
-
warnings: true,
|
|
388
|
-
children: true
|
|
389
|
-
}
|
|
390
|
-
}`)}];`;
|
|
391
|
-
}
|
|
392
|
-
compileUserWebpackConfig() {
|
|
393
|
-
return `/**
|
|
394
|
-
* This file can be edited to customize webpack configuration.
|
|
395
|
-
* To reset delete this file and rerun theia build again.
|
|
396
|
-
*/
|
|
397
|
-
// @ts-check
|
|
398
|
-
const configs = require('./${paths.basename(this.genConfigPath)}');
|
|
399
|
-
${this.ifBrowserOnly('', `const nodeConfig = require('./${paths.basename(this.genNodeConfigPath)}');`)}
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Expose bundled modules on window.theia.moduleName namespace, e.g.
|
|
403
|
-
* window['theia']['@theia/core/lib/common/uri'].
|
|
404
|
-
* Such syntax can be used by external code, for instance, for testing.
|
|
405
|
-
configs[0].module.rules.push({
|
|
406
|
-
test: /\\.js$/,
|
|
407
|
-
loader: require.resolve('@theia/application-manager/lib/expose-loader')
|
|
408
|
-
}); */
|
|
409
|
-
|
|
410
|
-
${this.ifBrowserOnly('module.exports = configs;', `module.exports = [
|
|
411
|
-
...configs,
|
|
412
|
-
nodeConfig.config
|
|
413
|
-
];`)}
|
|
414
|
-
`;
|
|
415
|
-
}
|
|
416
|
-
compileNodeWebpackConfig() {
|
|
417
|
-
return `/**
|
|
418
|
-
* Don't touch this file. It will be regenerated by theia build.
|
|
419
|
-
* To customize webpack configuration change ${this.configPath}
|
|
420
|
-
*/
|
|
421
|
-
// @ts-check
|
|
422
|
-
const path = require('path');
|
|
423
|
-
const yargs = require('yargs');
|
|
424
|
-
const webpack = require('webpack');
|
|
425
|
-
const TerserPlugin = require('terser-webpack-plugin');
|
|
426
|
-
const { NativeWebpackPlugin, MonacoWebpackPlugin } = require('@theia/bundle-plugin');
|
|
427
|
-
|
|
428
|
-
const { mode } = yargs.option('mode', {
|
|
429
|
-
description: "Mode to use",
|
|
430
|
-
choices: ["development", "production"],
|
|
431
|
-
default: "production"
|
|
432
|
-
}).argv;
|
|
433
|
-
|
|
434
|
-
const production = mode === 'production';
|
|
435
|
-
|
|
436
|
-
/** @type {import('webpack').EntryObject} */
|
|
437
|
-
const commonJsLibraries = {};
|
|
438
|
-
for (const [entryPointName, entryPointPath] of Object.entries({
|
|
439
|
-
${this.ifPackage('@theia/plugin-ext', "'backend-init-theia': '@theia/plugin-ext/lib/hosted/node/scanners/backend-init-theia',")}
|
|
440
|
-
${this.ifPackage('@theia/filesystem', "'parcel-watcher': '@theia/filesystem/lib/node/parcel-watcher',")}
|
|
441
|
-
${this.ifPackage('@theia/plugin-ext-vscode', "'plugin-vscode-init': '@theia/plugin-ext-vscode/lib/node/plugin-vscode-init',")}
|
|
442
|
-
${this.ifPackage('@theia/api-provider-sample', "'gotd-api-init': '@theia/api-provider-sample/lib/plugin/gotd-api-init',")}
|
|
443
|
-
})) {
|
|
444
|
-
commonJsLibraries[entryPointName] = {
|
|
445
|
-
import: require.resolve(entryPointPath),
|
|
446
|
-
library: {
|
|
447
|
-
type: 'commonjs2',
|
|
448
|
-
},
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
const ignoredResources = new Set();
|
|
453
|
-
|
|
454
|
-
if (process.platform !== 'win32') {
|
|
455
|
-
ignoredResources.add('@vscode/windows-ca-certs');
|
|
456
|
-
ignoredResources.add('@vscode/windows-ca-certs/build/Release/crypt32.node');
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
const nativePlugin = new NativeWebpackPlugin({
|
|
460
|
-
out: 'native',
|
|
461
|
-
trash: ${this.ifPackage('@theia/filesystem', 'true', 'false')},
|
|
462
|
-
ripgrep: ${this.ifPackage(['@theia/search-in-workspace', '@theia/file-search'], 'true', 'false')},
|
|
463
|
-
pty: ${this.ifPackage('@theia/process', 'true', 'false')},
|
|
464
|
-
nativeBindings: {
|
|
465
|
-
drivelist: 'drivelist/build/Release/drivelist.node'
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
${this.ifPackage('@theia/process', () => `// Ensure that node-pty is correctly hoisted
|
|
470
|
-
try {
|
|
471
|
-
require.resolve('node-pty');
|
|
472
|
-
} catch {
|
|
473
|
-
console.error('"node-pty" dependency is not installed correctly. Ensure that it is available in the root node_modules directory.');
|
|
474
|
-
console.error('Exiting webpack build process.');
|
|
475
|
-
process.exit(1);
|
|
476
|
-
}`)}
|
|
477
|
-
|
|
478
|
-
/** @type {import('webpack').Configuration} */
|
|
479
|
-
const config = {
|
|
480
|
-
mode,
|
|
481
|
-
devtool: mode === 'development' ? 'source-map' : false,
|
|
482
|
-
target: 'node',
|
|
483
|
-
node: {
|
|
484
|
-
global: false,
|
|
485
|
-
__filename: false,
|
|
486
|
-
__dirname: false
|
|
487
|
-
},
|
|
488
|
-
resolve: {
|
|
489
|
-
extensions: ['.js', '.json', '.wasm', '.node'],
|
|
490
|
-
},
|
|
491
|
-
output: {
|
|
492
|
-
filename: '[name].js',
|
|
493
|
-
path: path.resolve(__dirname, 'lib', 'backend'),
|
|
494
|
-
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]?[loaders]',
|
|
495
|
-
},${this.ifElectron(`
|
|
496
|
-
externals: {
|
|
497
|
-
electron: 'require("electron")'
|
|
498
|
-
},`)}
|
|
499
|
-
entry: {
|
|
500
|
-
// Main entry point of the Theia application backend:
|
|
501
|
-
'main': require.resolve('./src-gen/backend/main'),
|
|
502
|
-
// Theia's IPC mechanism:
|
|
503
|
-
'ipc-bootstrap': require.resolve('@theia/core/lib/node/messaging/ipc-bootstrap'),
|
|
504
|
-
${this.ifPackage('@theia/plugin-ext', () => `// VS Code extension support:
|
|
505
|
-
'plugin-host': require.resolve('@theia/plugin-ext/lib/hosted/node/plugin-host'),`)}
|
|
506
|
-
${this.ifPackage('@theia/plugin-ext-headless', () => `// Theia Headless Plugin support:
|
|
507
|
-
'plugin-host-headless': require.resolve('@theia/plugin-ext-headless/lib/hosted/node/plugin-host-headless'),`)}
|
|
508
|
-
${this.ifPackage('@theia/process', () => `// Make sure the node-pty thread workers can be executed:
|
|
509
|
-
'worker/conoutSocketWorker': require.resolve('node-pty/lib/worker/conoutSocketWorker'),
|
|
510
|
-
'conpty_console_list_agent': require.resolve('node-pty/lib/conpty_console_list_agent'),`)}
|
|
511
|
-
${this.ifElectron("'electron-main': require.resolve('./src-gen/backend/electron-main'),")}
|
|
512
|
-
${this.ifPackage('@theia/dev-container', () => `// VS Code Dev-Container communication:
|
|
513
|
-
'dev-container-server': require.resolve('@theia/dev-container/lib/dev-container-server/dev-container-server'),`)}
|
|
514
|
-
...commonJsLibraries
|
|
515
|
-
},
|
|
516
|
-
module: {
|
|
517
|
-
rules: [
|
|
518
|
-
// Make sure we can still find and load our native addons.
|
|
519
|
-
{
|
|
520
|
-
test: /\\.node$/,
|
|
521
|
-
loader: 'node-loader',
|
|
522
|
-
options: {
|
|
523
|
-
name: 'native/[name].[ext]'
|
|
524
|
-
}
|
|
525
|
-
},
|
|
526
|
-
{
|
|
527
|
-
test: /\\.d\\.ts$/,
|
|
528
|
-
loader: 'ignore-loader'
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
test: /\\.js$/,
|
|
532
|
-
enforce: 'pre',
|
|
533
|
-
loader: 'source-map-loader'
|
|
534
|
-
},
|
|
535
|
-
// node-pty uses a dynamic require which needs to be rewritten to work with webpack.
|
|
536
|
-
{
|
|
537
|
-
test: /node_modules[/\\\\]node-pty[/\\\\]lib[/\\\\]utils\.js$/,
|
|
538
|
-
loader: 'string-replace-loader',
|
|
539
|
-
options: {
|
|
540
|
-
search: /require\\(/,
|
|
541
|
-
replace: '__non_webpack_require__(',
|
|
542
|
-
flags: 'g'
|
|
543
|
-
}
|
|
544
|
-
},
|
|
545
|
-
// jsonc-parser exposes its UMD implementation by default, which
|
|
546
|
-
// confuses Webpack leading to missing js in the bundles.
|
|
547
|
-
{
|
|
548
|
-
test: /node_modules[\\/](jsonc-parser)/,
|
|
549
|
-
loader: 'umd-compat-loader'
|
|
550
|
-
}
|
|
551
|
-
]
|
|
552
|
-
},
|
|
553
|
-
plugins: [
|
|
554
|
-
// Some native dependencies need special handling
|
|
555
|
-
nativePlugin,
|
|
556
|
-
// Optional node dependencies can be safely ignored
|
|
557
|
-
new webpack.IgnorePlugin({
|
|
558
|
-
checkResource: resource => ignoredResources.has(resource)
|
|
559
|
-
}),
|
|
560
|
-
new MonacoWebpackPlugin()
|
|
561
|
-
],
|
|
562
|
-
optimization: {
|
|
563
|
-
// Split and reuse code across the various entry points
|
|
564
|
-
splitChunks: {
|
|
565
|
-
chunks: 'all'
|
|
566
|
-
},
|
|
567
|
-
// Only minimize if we run webpack in production mode
|
|
568
|
-
minimize: production,
|
|
569
|
-
minimizer: [
|
|
570
|
-
new TerserPlugin({
|
|
571
|
-
exclude: /^(lib|builtins)\\//${this.ifPackage(['@theia/scanoss', '@theia/ai-anthropic', '@theia/ai-openai'], () => `,
|
|
572
|
-
terserOptions: {
|
|
573
|
-
keep_classnames: /AbortSignal/
|
|
574
|
-
}`)}
|
|
575
|
-
})
|
|
576
|
-
]
|
|
577
|
-
},
|
|
578
|
-
ignoreWarnings: [
|
|
579
|
-
// Some packages do not have source maps, that's ok
|
|
580
|
-
/Failed to parse source map/,
|
|
581
|
-
// require with expressions are not supported
|
|
582
|
-
/the request of a dependency is an expression/,
|
|
583
|
-
// Some packages use dynamic requires, we can safely ignore them (they are handled by the native webpack plugin)
|
|
584
|
-
/require function is used in a way in which dependencies cannot be statically extracted/, {
|
|
585
|
-
module: /yargs/
|
|
586
|
-
}, {
|
|
587
|
-
module: /node-pty/
|
|
588
|
-
}, {
|
|
589
|
-
module: /require-main-filename/
|
|
590
|
-
}, {
|
|
591
|
-
module: /ws/
|
|
592
|
-
}, {
|
|
593
|
-
module: /express/
|
|
594
|
-
}, {
|
|
595
|
-
module: /cross-spawn/
|
|
596
|
-
}, {
|
|
597
|
-
module: /@parcel\\/watcher/
|
|
598
|
-
}
|
|
599
|
-
]
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
module.exports = {
|
|
603
|
-
config,
|
|
604
|
-
nativePlugin,
|
|
605
|
-
ignoredResources
|
|
606
|
-
};
|
|
607
|
-
`;
|
|
608
|
-
}
|
|
609
69
|
compileESBuildBrowserConfig() {
|
|
610
70
|
return `/**
|
|
611
71
|
* Don't touch this file. It will be regenerated by theia build.
|
|
@@ -613,7 +73,7 @@ module.exports = {
|
|
|
613
73
|
*/
|
|
614
74
|
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
|
|
615
75
|
import { copy } from 'esbuild-plugin-copy';
|
|
616
|
-
import { monacoNlsPlugin, problemMatcherPlugin, sourceMapPathsPlugin } from '@theia/bundle-plugin';
|
|
76
|
+
import { compressAssetsPlugin, monacoNlsPlugin, problemMatcherPlugin, sourceMapPathsPlugin } from '@theia/bundle-plugin';
|
|
617
77
|
import yargs from 'yargs';
|
|
618
78
|
import { hideBin } from 'yargs/helpers';
|
|
619
79
|
import resolvePackagePath from 'resolve-package-path';
|
|
@@ -626,7 +86,7 @@ export function join(...parts) {
|
|
|
626
86
|
return path.join(...parts).replace(/\\\\/g, '/');
|
|
627
87
|
}
|
|
628
88
|
|
|
629
|
-
const { mode, watch } = yargs(hideBin(process.argv)).option('mode', {
|
|
89
|
+
const { mode, watch, staticCompression } = yargs(hideBin(process.argv)).option('mode', {
|
|
630
90
|
description: "Mode to use",
|
|
631
91
|
choices: ["development", "production"],
|
|
632
92
|
default: "production"
|
|
@@ -634,13 +94,20 @@ const { mode, watch } = yargs(hideBin(process.argv)).option('mode', {
|
|
|
634
94
|
description: 'Controls whether to enable watch mode',
|
|
635
95
|
type: 'boolean',
|
|
636
96
|
default: false
|
|
97
|
+
}).option('static-compression', {
|
|
98
|
+
description: ${this.ifElectron("'Controls whether to emit gzipped copies of the frontend assets. Disabled by default for Electron applications.'", "'Controls whether to emit gzipped copies of the frontend assets. Enabled by default in production mode.'")},
|
|
99
|
+
type: 'boolean'
|
|
637
100
|
}).argv;
|
|
638
101
|
|
|
639
102
|
const production = mode === 'production';
|
|
640
103
|
const sourcemap = production ? false : 'linked';
|
|
641
104
|
const minify = production;
|
|
105
|
+
${this.ifElectron(`// Electron loads the frontend from the local backend over loopback, where gzip saves nothing
|
|
106
|
+
// while the compressed copies still add to the size of the packaged application.
|
|
107
|
+
const compression = staticCompression ?? false;`, `// Compressing on every rebuild would slow down watch mode, so this only pays off for production builds.
|
|
108
|
+
const compression = staticCompression ?? production;`)}
|
|
642
109
|
|
|
643
|
-
export { mode, watch, sourcemap, minify };
|
|
110
|
+
export { mode, watch, sourcemap, minify, compression };
|
|
644
111
|
|
|
645
112
|
/**
|
|
646
113
|
* @type {Record<string, import('esbuild').Loader>}
|
|
@@ -708,7 +175,9 @@ export const browserOptions = {
|
|
|
708
175
|
}`)}
|
|
709
176
|
]
|
|
710
177
|
}),
|
|
711
|
-
sourceMapPathsPlugin()
|
|
178
|
+
sourceMapPathsPlugin(),
|
|
179
|
+
// Keep last: it compresses whatever the preceding plugins emitted.
|
|
180
|
+
compressAssetsPlugin({ compress: compression })
|
|
712
181
|
]
|
|
713
182
|
};
|
|
714
183
|
`;
|