@theia/application-manager 1.47.1 → 1.48.1

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.
Files changed (38) hide show
  1. package/README.md +25 -25
  2. package/lib/application-package-manager.d.ts +45 -45
  3. package/lib/application-package-manager.js +225 -225
  4. package/lib/application-process.d.ts +19 -19
  5. package/lib/application-process.js +72 -72
  6. package/lib/expose-loader.d.ts +8 -8
  7. package/lib/expose-loader.js +69 -69
  8. package/lib/generator/abstract-generator.d.ts +17 -17
  9. package/lib/generator/abstract-generator.js +57 -57
  10. package/lib/generator/backend-generator.d.ts +7 -7
  11. package/lib/generator/backend-generator.js +196 -196
  12. package/lib/generator/frontend-generator.d.ts +13 -13
  13. package/lib/generator/frontend-generator.d.ts.map +1 -1
  14. package/lib/generator/frontend-generator.js +212 -221
  15. package/lib/generator/frontend-generator.js.map +1 -1
  16. package/lib/generator/index.d.ts +3 -3
  17. package/lib/generator/index.js +21 -21
  18. package/lib/generator/webpack-generator.d.ts +12 -12
  19. package/lib/generator/webpack-generator.d.ts.map +1 -1
  20. package/lib/generator/webpack-generator.js +493 -506
  21. package/lib/generator/webpack-generator.js.map +1 -1
  22. package/lib/index.d.ts +3 -3
  23. package/lib/index.js +21 -21
  24. package/lib/package.spec.js +25 -25
  25. package/lib/rebuild.d.ts +24 -24
  26. package/lib/rebuild.js +309 -309
  27. package/package.json +6 -7
  28. package/src/application-package-manager.ts +263 -263
  29. package/src/application-process.ts +80 -80
  30. package/src/expose-loader.ts +80 -80
  31. package/src/generator/abstract-generator.ts +69 -69
  32. package/src/generator/backend-generator.ts +198 -198
  33. package/src/generator/frontend-generator.ts +222 -231
  34. package/src/generator/index.ts +19 -19
  35. package/src/generator/webpack-generator.ts +501 -514
  36. package/src/index.ts +19 -19
  37. package/src/package.spec.ts +28 -28
  38. package/src/rebuild.ts +345 -345
@@ -1,507 +1,494 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2017 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.WebpackGenerator = void 0;
19
- const paths = require("path");
20
- const fs = require("fs-extra");
21
- const abstract_generator_1 = require("./abstract-generator");
22
- class WebpackGenerator extends abstract_generator_1.AbstractGenerator {
23
- async generate() {
24
- await this.write(this.genConfigPath, this.compileWebpackConfig());
25
- if (!this.pck.isBrowserOnly()) {
26
- await this.write(this.genNodeConfigPath, this.compileNodeWebpackConfig());
27
- }
28
- if (await this.shouldGenerateUserWebpackConfig()) {
29
- await this.write(this.configPath, this.compileUserWebpackConfig());
30
- }
31
- }
32
- async shouldGenerateUserWebpackConfig() {
33
- if (!(await fs.pathExists(this.configPath))) {
34
- return true;
35
- }
36
- const content = await fs.readFile(this.configPath, 'utf8');
37
- return content.indexOf('gen-webpack') === -1;
38
- }
39
- get configPath() {
40
- return this.pck.path('webpack.config.js');
41
- }
42
- get genConfigPath() {
43
- return this.pck.path('gen-webpack.config.js');
44
- }
45
- get genNodeConfigPath() {
46
- return this.pck.path('gen-webpack.node.config.js');
47
- }
48
- resolve(moduleName, path) {
49
- return this.pck.resolveModulePath(moduleName, path).split(paths.sep).join('/');
50
- }
51
- compileWebpackConfig() {
52
- return `/**
53
- * Don't touch this file. It will be regenerated by theia build.
54
- * To customize webpack configuration change ${this.configPath}
55
- */
56
- // @ts-check
57
- const path = require('path');
58
- const webpack = require('webpack');
59
- const yargs = require('yargs');
60
- const resolvePackagePath = require('resolve-package-path');
61
- const CopyWebpackPlugin = require('copy-webpack-plugin');
62
- const CompressionPlugin = require('compression-webpack-plugin')
63
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
64
-
65
- const outputPath = path.resolve(__dirname, 'lib', 'frontend');
66
- const { mode, staticCompression } = yargs.option('mode', {
67
- description: "Mode to use",
68
- choices: ["development", "production"],
69
- default: "production"
70
- }).option('static-compression', {
71
- description: 'Controls whether to enable compression of static artifacts.',
72
- type: 'boolean',
73
- default: true
74
- }).argv;
75
- const development = mode === 'development';
76
-
77
- const plugins = [
78
- new CopyWebpackPlugin({
79
- patterns: [
80
- {
81
- // copy secondary window html file to lib folder
82
- from: path.resolve(__dirname, 'src-gen/frontend/secondary-window.html')
83
- }${this.ifPackage('@theia/plugin-ext', `,
84
- {
85
- // copy webview files to lib folder
86
- from: path.join(resolvePackagePath('@theia/plugin-ext', __dirname), '..', 'src', 'main', 'browser', 'webview', 'pre'),
87
- to: path.resolve(__dirname, 'lib', 'webview', 'pre')
88
- }`)}
89
- ${this.ifPackage('@theia/plugin-ext-vscode', `,
90
- {
91
- // copy frontend plugin host files
92
- from: path.join(resolvePackagePath('@theia/plugin-ext-vscode', __dirname), '..', 'lib', 'node', 'context', 'plugin-vscode-init-fe.js'),
93
- to: path.resolve(__dirname, 'lib', 'frontend', 'context', 'plugin-vscode-init-fe.js')
94
- }`)}
95
- ]
96
- }),
97
- new webpack.ProvidePlugin({
98
- // the Buffer class doesn't exist in the browser but some dependencies rely on it
99
- Buffer: ['buffer', 'Buffer']
100
- })
101
- ];
102
- // it should go after copy-plugin in order to compress monaco as well
103
- if (staticCompression) {
104
- plugins.push(new CompressionPlugin({}));
105
- }
106
-
107
- module.exports = [{
108
- mode,
109
- plugins,
110
- devtool: 'source-map',
111
- entry: {
112
- bundle: path.resolve(__dirname, 'src-gen/frontend/index.js'),
113
- ${this.ifMonaco(() => "'editor.worker': '@theia/monaco-editor-core/esm/vs/editor/editor.worker.js'")}
114
- },
115
- output: {
116
- filename: '[name].js',
117
- path: outputPath,
118
- devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]',
119
- globalObject: 'self'
120
- },
121
- target: 'web',
122
- cache: staticCompression,
123
- module: {
124
- rules: [
125
- {
126
- // Removes the host check in PhosphorJS to enable moving widgets to secondary windows.
127
- test: /widget\\.js$/,
128
- loader: 'string-replace-loader',
129
- include: /node_modules[\\\\/]@phosphor[\\\\/]widgets[\\\\/]lib/,
130
- options: {
131
- multiple: [
132
- {
133
- search: /document\\.body\\.contains\\(widget.node\\)/gm,
134
- replace: 'widget.node.ownerDocument.body.contains(widget.node)'
135
- },
136
- {
137
- search: /\\!document\\.body\\.contains\\(host\\)/gm,
138
- replace: ' !host.ownerDocument.body.contains(host)'
139
- }
140
- ]
141
- }
142
- },
143
- {
144
- test: /\\.css$/,
145
- exclude: /materialcolors\\.css$|\\.useable\\.css$/,
146
- use: ['style-loader', 'css-loader']
147
- },
148
- {
149
- test: /materialcolors\\.css$|\\.useable\\.css$/,
150
- use: [
151
- {
152
- loader: 'style-loader',
153
- options: {
154
- esModule: false,
155
- injectType: 'lazySingletonStyleTag',
156
- attributes: {
157
- id: 'theia-theme'
158
- }
159
- }
160
- },
161
- 'css-loader'
162
- ]
163
- },
164
- {
165
- test: /\\.(ttf|eot|svg)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,
166
- type: 'asset',
167
- parser: {
168
- dataUrlCondition: {
169
- maxSize: 10000,
170
- }
171
- },
172
- generator: {
173
- dataUrl: {
174
- mimetype: 'image/svg+xml'
175
- }
176
- }
177
- },
178
- {
179
- test: /\\.(jpg|png|gif)$/,
180
- type: 'asset/resource',
181
- generator: {
182
- filename: '[hash].[ext]'
183
- }
184
- },
185
- {
186
- // see https://github.com/eclipse-theia/theia/issues/556
187
- test: /source-map-support/,
188
- loader: 'ignore-loader'
189
- },
190
- {
191
- test: /\\.js$/,
192
- enforce: 'pre',
193
- loader: 'source-map-loader',
194
- exclude: /jsonc-parser|fast-plist|onigasm/
195
- },
196
- {
197
- test: /\\.woff(2)?(\\?v=[0-9]\\.[0-9]\\.[0-9])?$/,
198
- type: 'asset',
199
- parser: {
200
- dataUrlCondition: {
201
- maxSize: 10000,
202
- }
203
- },
204
- generator: {
205
- dataUrl: {
206
- mimetype: 'image/svg+xml'
207
- }
208
- }
209
- },
210
- {
211
- test: /node_modules[\\\\|\/](vscode-languageserver-types|vscode-uri|jsonc-parser|vscode-languageserver-protocol)/,
212
- loader: 'umd-compat-loader'
213
- },
214
- {
215
- test: /\\.wasm$/,
216
- type: 'asset/resource'
217
- },
218
- {
219
- test: /\\.plist$/,
220
- type: 'asset/resource'
221
- }
222
- ]
223
- },
224
- resolve: {
225
- fallback: {
226
- 'child_process': false,
227
- 'crypto': false,
228
- 'net': false,
229
- 'path': require.resolve('path-browserify'),
230
- 'process': false,
231
- 'os': false,
232
- 'timers': false
233
- },
234
- extensions: ['.js']
235
- },
236
- stats: {
237
- warnings: true,
238
- children: true
239
- },
240
- ignoreWarnings: [
241
- // Some packages do not have source maps, that's ok
242
- /Failed to parse source map/,
243
- {
244
- // Monaco uses 'require' in a non-standard way
245
- module: /@theia\\/monaco-editor-core/,
246
- message: /require function is used in a way in which dependencies cannot be statically extracted/
247
- }
248
- ]
249
- },
250
- {
251
- mode,
252
- plugins: [
253
- new MiniCssExtractPlugin({
254
- // Options similar to the same options in webpackOptions.output
255
- // both options are optional
256
- filename: "[name].css",
257
- chunkFilename: "[id].css",
258
- }),
259
- ],
260
- devtool: 'source-map',
261
- entry: {
262
- "secondary-window": path.resolve(__dirname, 'src-gen/frontend/secondary-index.js'),
263
- },
264
- output: {
265
- filename: '[name].js',
266
- path: outputPath,
267
- devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]',
268
- globalObject: 'self'
269
- },
270
- target: 'web',
271
- cache: staticCompression,
272
- module: {
273
- rules: [
274
- {
275
- test: /\.css$/i,
276
- use: [MiniCssExtractPlugin.loader, "css-loader"]
277
- }
278
- ]
279
- },
280
- resolve: {
281
- fallback: {
282
- 'child_process': false,
283
- 'crypto': false,
284
- 'net': false,
285
- 'path': require.resolve('path-browserify'),
286
- 'process': false,
287
- 'os': false,
288
- 'timers': false
289
- },
290
- extensions: ['.js']
291
- },
292
- stats: {
293
- warnings: true,
294
- children: true
295
- },
296
- ignoreWarnings: [
297
- {
298
- // Monaco uses 'require' in a non-standard way
299
- module: /@theia\\/monaco-editor-core/,
300
- message: /require function is used in a way in which dependencies cannot be statically extracted/
301
- }
302
- ]
303
- }${this.ifElectron(`, {
304
- mode,
305
- devtool: 'source-map',
306
- entry: {
307
- "preload": path.resolve(__dirname, 'src-gen/frontend/preload.js'),
308
- },
309
- output: {
310
- filename: '[name].js',
311
- path: outputPath,
312
- devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]',
313
- globalObject: 'self'
314
- },
315
- target: 'electron-preload',
316
- cache: staticCompression,
317
- stats: {
318
- warnings: true,
319
- children: true
320
- }
321
- }`)}];`;
322
- }
323
- compileUserWebpackConfig() {
324
- return `/**
325
- * This file can be edited to customize webpack configuration.
326
- * To reset delete this file and rerun theia build again.
327
- */
328
- // @ts-check
329
- const configs = require('./${paths.basename(this.genConfigPath)}');
330
- ${this.ifBrowserOnly('', `const nodeConfig = require('./${paths.basename(this.genNodeConfigPath)}');`)}
331
-
332
- /**
333
- * Expose bundled modules on window.theia.moduleName namespace, e.g.
334
- * window['theia']['@theia/core/lib/common/uri'].
335
- * Such syntax can be used by external code, for instance, for testing.
336
- configs[0].module.rules.push({
337
- test: /\\.js$/,
338
- loader: require.resolve('@theia/application-manager/lib/expose-loader')
339
- }); */
340
-
341
- ${this.ifBrowserOnly('module.exports = configs;', `module.exports = [
342
- ...configs,
343
- nodeConfig.config
344
- ];`)}
345
- `;
346
- }
347
- compileNodeWebpackConfig() {
348
- return `/**
349
- * Don't touch this file. It will be regenerated by theia build.
350
- * To customize webpack configuration change ${this.configPath}
351
- */
352
- // @ts-check
353
- const path = require('path');
354
- const yargs = require('yargs');
355
- const webpack = require('webpack');
356
- const TerserPlugin = require('terser-webpack-plugin');
357
- const NativeWebpackPlugin = require('@theia/native-webpack-plugin');
358
-
359
- const { mode } = yargs.option('mode', {
360
- description: "Mode to use",
361
- choices: ["development", "production"],
362
- default: "production"
363
- }).argv;
364
-
365
- const production = mode === 'production';
366
-
367
- /** @type {import('webpack').EntryObject} */
368
- const commonJsLibraries = {};
369
- for (const [entryPointName, entryPointPath] of Object.entries({
370
- ${this.ifPackage('@theia/plugin-ext', "'backend-init-theia': '@theia/plugin-ext/lib/hosted/node/scanners/backend-init-theia',")}
371
- ${this.ifPackage('@theia/filesystem', "'nsfw-watcher': '@theia/filesystem/lib/node/nsfw-watcher',")}
372
- ${this.ifPackage('@theia/plugin-ext-vscode', "'plugin-vscode-init': '@theia/plugin-ext-vscode/lib/node/plugin-vscode-init',")}
373
- ${this.ifPackage('@theia/api-provider-sample', "'gotd-api-init': '@theia/api-provider-sample/lib/plugin/gotd-api-init',")}
374
- })) {
375
- commonJsLibraries[entryPointName] = {
376
- import: require.resolve(entryPointPath),
377
- library: {
378
- type: 'commonjs2',
379
- },
380
- };
381
- }
382
-
383
- const ignoredResources = new Set();
384
-
385
- if (process.platform !== 'win32') {
386
- ignoredResources.add('@vscode/windows-ca-certs');
387
- ignoredResources.add('@vscode/windows-ca-certs/build/Release/crypt32.node');
388
- }
389
-
390
- const nativePlugin = new NativeWebpackPlugin({
391
- out: 'native',
392
- trash: ${this.ifPackage('@theia/filesystem', 'true', 'false')},
393
- ripgrep: ${this.ifPackage(['@theia/search-in-workspace', '@theia/file-search'], 'true', 'false')},
394
- pty: ${this.ifPackage('@theia/process', 'true', 'false')},
395
- nativeBindings: {
396
- drivelist: 'drivelist/build/Release/drivelist.node'
397
- }
398
- });
399
-
400
- /** @type {import('webpack').Configuration} */
401
- const config = {
402
- mode,
403
- devtool: mode === 'development' ? 'source-map' : false,
404
- target: 'node',
405
- node: {
406
- global: false,
407
- __filename: false,
408
- __dirname: false
409
- },
410
- output: {
411
- filename: '[name].js',
412
- path: path.resolve(__dirname, 'lib', 'backend'),
413
- devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]?[loaders]',
414
- },${this.ifElectron(`
415
- externals: {
416
- electron: 'require("electron")'
417
- },`)}
418
- entry: {
419
- // Main entry point of the Theia application backend:
420
- 'main': require.resolve('./src-gen/backend/main'),
421
- // Theia's IPC mechanism:
422
- 'ipc-bootstrap': require.resolve('@theia/core/lib/node/messaging/ipc-bootstrap'),
423
- ${this.ifPackage('@theia/plugin-ext', () => `// VS Code extension support:
424
- 'plugin-host': require.resolve('@theia/plugin-ext/lib/hosted/node/plugin-host'),`)}
425
- ${this.ifPackage('@theia/plugin-ext-headless', () => `// Theia Headless Plugin support:
426
- 'plugin-host-headless': require.resolve('@theia/plugin-ext-headless/lib/hosted/node/plugin-host-headless'),`)}
427
- ${this.ifPackage('@theia/process', () => `// Make sure the node-pty thread worker can be executed:
428
- 'worker/conoutSocketWorker': require.resolve('node-pty/lib/worker/conoutSocketWorker'),`)}
429
- ${this.ifPackage('@theia/git', () => `// Ensure the git locator process can the started
430
- 'git-locator-host': require.resolve('@theia/git/lib/node/git-locator/git-locator-host'),`)}
431
- ${this.ifElectron("'electron-main': require.resolve('./src-gen/backend/electron-main'),")}
432
- ...commonJsLibraries
433
- },
434
- module: {
435
- rules: [
436
- // Make sure we can still find and load our native addons.
437
- {
438
- test: /\\.node$/,
439
- loader: 'node-loader',
440
- options: {
441
- name: 'native/[name].[ext]'
442
- }
443
- },
444
- {
445
- test: /\\.js$/,
446
- enforce: 'pre',
447
- loader: 'source-map-loader'
448
- },
449
- // jsonc-parser exposes its UMD implementation by default, which
450
- // confuses Webpack leading to missing js in the bundles.
451
- {
452
- test: /node_modules[\\/](jsonc-parser)/,
453
- loader: 'umd-compat-loader'
454
- }
455
- ]
456
- },
457
- plugins: [
458
- // Some native dependencies need special handling
459
- nativePlugin,
460
- // Optional node dependencies can be safely ignored
461
- new webpack.IgnorePlugin({
462
- checkResource: resource => ignoredResources.has(resource)
463
- })
464
- ],
465
- optimization: {
466
- // Split and reuse code across the various entry points
467
- splitChunks: {
468
- chunks: 'all'
469
- },
470
- // Only minimize if we run webpack in production mode
471
- minimize: production,
472
- minimizer: [
473
- new TerserPlugin({
474
- exclude: /^(lib|builtins)\\//
475
- })
476
- ]
477
- },
478
- ignoreWarnings: [
479
- // Some packages do not have source maps, that's ok
480
- /Failed to parse source map/,
481
- // Some packages use dynamic requires, we can safely ignore them (they are handled by the native webpack plugin)
482
- /require function is used in a way in which dependencies cannot be statically extracted/, {
483
- module: /yargs/
484
- }, {
485
- module: /node-pty/
486
- }, {
487
- module: /require-main-filename/
488
- }, {
489
- module: /ws/
490
- }, {
491
- module: /express/
492
- }, {
493
- module: /cross-spawn/
494
- }
495
- ]
496
- };
497
-
498
- module.exports = {
499
- config,
500
- nativePlugin,
501
- ignoredResources
502
- };
503
- `;
504
- }
505
- }
506
- exports.WebpackGenerator = WebpackGenerator;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2017 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.WebpackGenerator = void 0;
19
+ const paths = require("path");
20
+ const fs = require("fs-extra");
21
+ const abstract_generator_1 = require("./abstract-generator");
22
+ class WebpackGenerator extends abstract_generator_1.AbstractGenerator {
23
+ async generate() {
24
+ await this.write(this.genConfigPath, this.compileWebpackConfig());
25
+ if (!this.pck.isBrowserOnly()) {
26
+ await this.write(this.genNodeConfigPath, this.compileNodeWebpackConfig());
27
+ }
28
+ if (await this.shouldGenerateUserWebpackConfig()) {
29
+ await this.write(this.configPath, this.compileUserWebpackConfig());
30
+ }
31
+ }
32
+ async shouldGenerateUserWebpackConfig() {
33
+ if (!(await fs.pathExists(this.configPath))) {
34
+ return true;
35
+ }
36
+ const content = await fs.readFile(this.configPath, 'utf8');
37
+ return content.indexOf('gen-webpack') === -1;
38
+ }
39
+ get configPath() {
40
+ return this.pck.path('webpack.config.js');
41
+ }
42
+ get genConfigPath() {
43
+ return this.pck.path('gen-webpack.config.js');
44
+ }
45
+ get genNodeConfigPath() {
46
+ return this.pck.path('gen-webpack.node.config.js');
47
+ }
48
+ resolve(moduleName, path) {
49
+ return this.pck.resolveModulePath(moduleName, path).split(paths.sep).join('/');
50
+ }
51
+ compileWebpackConfig() {
52
+ return `/**
53
+ * Don't touch this file. It will be regenerated by theia build.
54
+ * To customize webpack configuration change ${this.configPath}
55
+ */
56
+ // @ts-check
57
+ const path = require('path');
58
+ const webpack = require('webpack');
59
+ const yargs = require('yargs');
60
+ const resolvePackagePath = require('resolve-package-path');
61
+ const CopyWebpackPlugin = require('copy-webpack-plugin');
62
+ const CompressionPlugin = require('compression-webpack-plugin')
63
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin')
64
+
65
+ const outputPath = path.resolve(__dirname, 'lib', 'frontend');
66
+ const { mode, staticCompression } = yargs.option('mode', {
67
+ description: "Mode to use",
68
+ choices: ["development", "production"],
69
+ default: "production"
70
+ }).option('static-compression', {
71
+ description: 'Controls whether to enable compression of static artifacts.',
72
+ type: 'boolean',
73
+ default: true
74
+ }).argv;
75
+ const development = mode === 'development';
76
+
77
+ const plugins = [
78
+ new CopyWebpackPlugin({
79
+ patterns: [
80
+ {
81
+ // copy secondary window html file to lib folder
82
+ from: path.resolve(__dirname, 'src-gen/frontend/secondary-window.html')
83
+ }${this.ifPackage('@theia/plugin-ext', `,
84
+ {
85
+ // copy webview files to lib folder
86
+ from: path.join(resolvePackagePath('@theia/plugin-ext', __dirname), '..', 'src', 'main', 'browser', 'webview', 'pre'),
87
+ to: path.resolve(__dirname, 'lib', 'webview', 'pre')
88
+ }`)}
89
+ ${this.ifPackage('@theia/plugin-ext-vscode', `,
90
+ {
91
+ // copy frontend plugin host files
92
+ from: path.join(resolvePackagePath('@theia/plugin-ext-vscode', __dirname), '..', 'lib', 'node', 'context', 'plugin-vscode-init-fe.js'),
93
+ to: path.resolve(__dirname, 'lib', 'frontend', 'context', 'plugin-vscode-init-fe.js')
94
+ }`)}
95
+ ]
96
+ }),
97
+ new webpack.ProvidePlugin({
98
+ // the Buffer class doesn't exist in the browser but some dependencies rely on it
99
+ Buffer: ['buffer', 'Buffer']
100
+ })
101
+ ];
102
+ // it should go after copy-plugin in order to compress monaco as well
103
+ if (staticCompression) {
104
+ plugins.push(new CompressionPlugin({}));
105
+ }
106
+
107
+ module.exports = [{
108
+ mode,
109
+ plugins,
110
+ devtool: 'source-map',
111
+ entry: {
112
+ bundle: path.resolve(__dirname, 'src-gen/frontend/index.js'),
113
+ ${this.ifMonaco(() => "'editor.worker': '@theia/monaco-editor-core/esm/vs/editor/editor.worker.js'")}
114
+ },
115
+ output: {
116
+ filename: '[name].js',
117
+ path: outputPath,
118
+ devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]',
119
+ globalObject: 'self'
120
+ },
121
+ target: 'web',
122
+ cache: staticCompression,
123
+ module: {
124
+ rules: [
125
+ {
126
+ test: /\\.css$/,
127
+ exclude: /materialcolors\\.css$|\\.useable\\.css$/,
128
+ use: ['style-loader', 'css-loader']
129
+ },
130
+ {
131
+ test: /materialcolors\\.css$|\\.useable\\.css$/,
132
+ use: [
133
+ {
134
+ loader: 'style-loader',
135
+ options: {
136
+ esModule: false,
137
+ injectType: 'lazySingletonStyleTag',
138
+ attributes: {
139
+ id: 'theia-theme'
140
+ }
141
+ }
142
+ },
143
+ 'css-loader'
144
+ ]
145
+ },
146
+ {
147
+ test: /\\.(ttf|eot|svg)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,
148
+ type: 'asset',
149
+ parser: {
150
+ dataUrlCondition: {
151
+ maxSize: 10000,
152
+ }
153
+ },
154
+ generator: {
155
+ dataUrl: {
156
+ mimetype: 'image/svg+xml'
157
+ }
158
+ }
159
+ },
160
+ {
161
+ test: /\\.(jpg|png|gif)$/,
162
+ type: 'asset/resource',
163
+ generator: {
164
+ filename: '[hash].[ext]'
165
+ }
166
+ },
167
+ {
168
+ // see https://github.com/eclipse-theia/theia/issues/556
169
+ test: /source-map-support/,
170
+ loader: 'ignore-loader'
171
+ },
172
+ {
173
+ test: /\\.js$/,
174
+ enforce: 'pre',
175
+ loader: 'source-map-loader',
176
+ exclude: /jsonc-parser|fast-plist|onigasm/
177
+ },
178
+ {
179
+ test: /\\.woff(2)?(\\?v=[0-9]\\.[0-9]\\.[0-9])?$/,
180
+ type: 'asset',
181
+ parser: {
182
+ dataUrlCondition: {
183
+ maxSize: 10000,
184
+ }
185
+ },
186
+ generator: {
187
+ dataUrl: {
188
+ mimetype: 'image/svg+xml'
189
+ }
190
+ }
191
+ },
192
+ {
193
+ test: /node_modules[\\\\|\/](vscode-languageserver-types|vscode-uri|jsonc-parser|vscode-languageserver-protocol)/,
194
+ loader: 'umd-compat-loader'
195
+ },
196
+ {
197
+ test: /\\.wasm$/,
198
+ type: 'asset/resource'
199
+ },
200
+ {
201
+ test: /\\.plist$/,
202
+ type: 'asset/resource'
203
+ }
204
+ ]
205
+ },
206
+ resolve: {
207
+ fallback: {
208
+ 'child_process': false,
209
+ 'crypto': false,
210
+ 'net': false,
211
+ 'path': require.resolve('path-browserify'),
212
+ 'process': false,
213
+ 'os': false,
214
+ 'timers': false
215
+ },
216
+ extensions: ['.js']
217
+ },
218
+ stats: {
219
+ warnings: true,
220
+ children: true
221
+ },
222
+ ignoreWarnings: [
223
+ // Some packages do not have source maps, that's ok
224
+ /Failed to parse source map/,
225
+ {
226
+ // Monaco uses 'require' in a non-standard way
227
+ module: /@theia\\/monaco-editor-core/,
228
+ message: /require function is used in a way in which dependencies cannot be statically extracted/
229
+ }
230
+ ]
231
+ },
232
+ {
233
+ mode,
234
+ plugins: [
235
+ new MiniCssExtractPlugin({
236
+ // Options similar to the same options in webpackOptions.output
237
+ // both options are optional
238
+ filename: "[name].css",
239
+ chunkFilename: "[id].css",
240
+ }),
241
+ ],
242
+ devtool: 'source-map',
243
+ entry: {
244
+ "secondary-window": path.resolve(__dirname, 'src-gen/frontend/secondary-index.js'),
245
+ },
246
+ output: {
247
+ filename: '[name].js',
248
+ path: outputPath,
249
+ devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]',
250
+ globalObject: 'self'
251
+ },
252
+ target: 'web',
253
+ cache: staticCompression,
254
+ module: {
255
+ rules: [
256
+ {
257
+ test: /\.css$/i,
258
+ use: [MiniCssExtractPlugin.loader, "css-loader"]
259
+ },
260
+ {
261
+ test: /\.wasm$/,
262
+ type: 'asset/resource'
263
+ }
264
+ ]
265
+ },
266
+ resolve: {
267
+ fallback: {
268
+ 'child_process': false,
269
+ 'crypto': false,
270
+ 'net': false,
271
+ 'path': require.resolve('path-browserify'),
272
+ 'process': false,
273
+ 'os': false,
274
+ 'timers': false
275
+ },
276
+ extensions: ['.js']
277
+ },
278
+ stats: {
279
+ warnings: true,
280
+ children: true
281
+ },
282
+ ignoreWarnings: [
283
+ {
284
+ // Monaco uses 'require' in a non-standard way
285
+ module: /@theia\\/monaco-editor-core/,
286
+ message: /require function is used in a way in which dependencies cannot be statically extracted/
287
+ }
288
+ ]
289
+ }${this.ifElectron(`, {
290
+ mode,
291
+ devtool: 'source-map',
292
+ entry: {
293
+ "preload": path.resolve(__dirname, 'src-gen/frontend/preload.js'),
294
+ },
295
+ output: {
296
+ filename: '[name].js',
297
+ path: outputPath,
298
+ devtoolModuleFilenameTemplate: 'webpack:///[resource-path]?[loaders]',
299
+ globalObject: 'self'
300
+ },
301
+ target: 'electron-preload',
302
+ cache: staticCompression,
303
+ stats: {
304
+ warnings: true,
305
+ children: true
306
+ }
307
+ }`)}];`;
308
+ }
309
+ compileUserWebpackConfig() {
310
+ return `/**
311
+ * This file can be edited to customize webpack configuration.
312
+ * To reset delete this file and rerun theia build again.
313
+ */
314
+ // @ts-check
315
+ const configs = require('./${paths.basename(this.genConfigPath)}');
316
+ ${this.ifBrowserOnly('', `const nodeConfig = require('./${paths.basename(this.genNodeConfigPath)}');`)}
317
+
318
+ /**
319
+ * Expose bundled modules on window.theia.moduleName namespace, e.g.
320
+ * window['theia']['@theia/core/lib/common/uri'].
321
+ * Such syntax can be used by external code, for instance, for testing.
322
+ configs[0].module.rules.push({
323
+ test: /\\.js$/,
324
+ loader: require.resolve('@theia/application-manager/lib/expose-loader')
325
+ }); */
326
+
327
+ ${this.ifBrowserOnly('module.exports = configs;', `module.exports = [
328
+ ...configs,
329
+ nodeConfig.config
330
+ ];`)}
331
+ `;
332
+ }
333
+ compileNodeWebpackConfig() {
334
+ return `/**
335
+ * Don't touch this file. It will be regenerated by theia build.
336
+ * To customize webpack configuration change ${this.configPath}
337
+ */
338
+ // @ts-check
339
+ const path = require('path');
340
+ const yargs = require('yargs');
341
+ const webpack = require('webpack');
342
+ const TerserPlugin = require('terser-webpack-plugin');
343
+ const NativeWebpackPlugin = require('@theia/native-webpack-plugin');
344
+
345
+ const { mode } = yargs.option('mode', {
346
+ description: "Mode to use",
347
+ choices: ["development", "production"],
348
+ default: "production"
349
+ }).argv;
350
+
351
+ const production = mode === 'production';
352
+
353
+ /** @type {import('webpack').EntryObject} */
354
+ const commonJsLibraries = {};
355
+ for (const [entryPointName, entryPointPath] of Object.entries({
356
+ ${this.ifPackage('@theia/plugin-ext', "'backend-init-theia': '@theia/plugin-ext/lib/hosted/node/scanners/backend-init-theia',")}
357
+ ${this.ifPackage('@theia/filesystem', "'nsfw-watcher': '@theia/filesystem/lib/node/nsfw-watcher',")}
358
+ ${this.ifPackage('@theia/plugin-ext-vscode', "'plugin-vscode-init': '@theia/plugin-ext-vscode/lib/node/plugin-vscode-init',")}
359
+ ${this.ifPackage('@theia/api-provider-sample', "'gotd-api-init': '@theia/api-provider-sample/lib/plugin/gotd-api-init',")}
360
+ ${this.ifPackage('@theia/git', "'git-locator-host': '@theia/git/lib/node/git-locator/git-locator-host',")}
361
+ })) {
362
+ commonJsLibraries[entryPointName] = {
363
+ import: require.resolve(entryPointPath),
364
+ library: {
365
+ type: 'commonjs2',
366
+ },
367
+ };
368
+ }
369
+
370
+ const ignoredResources = new Set();
371
+
372
+ if (process.platform !== 'win32') {
373
+ ignoredResources.add('@vscode/windows-ca-certs');
374
+ ignoredResources.add('@vscode/windows-ca-certs/build/Release/crypt32.node');
375
+ }
376
+
377
+ const nativePlugin = new NativeWebpackPlugin({
378
+ out: 'native',
379
+ trash: ${this.ifPackage('@theia/filesystem', 'true', 'false')},
380
+ ripgrep: ${this.ifPackage(['@theia/search-in-workspace', '@theia/file-search'], 'true', 'false')},
381
+ pty: ${this.ifPackage('@theia/process', 'true', 'false')},
382
+ nativeBindings: {
383
+ drivelist: 'drivelist/build/Release/drivelist.node'
384
+ }
385
+ });
386
+
387
+ /** @type {import('webpack').Configuration} */
388
+ const config = {
389
+ mode,
390
+ devtool: mode === 'development' ? 'source-map' : false,
391
+ target: 'node',
392
+ node: {
393
+ global: false,
394
+ __filename: false,
395
+ __dirname: false
396
+ },
397
+ output: {
398
+ filename: '[name].js',
399
+ path: path.resolve(__dirname, 'lib', 'backend'),
400
+ devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]?[loaders]',
401
+ },${this.ifElectron(`
402
+ externals: {
403
+ electron: 'require("electron")'
404
+ },`)}
405
+ entry: {
406
+ // Main entry point of the Theia application backend:
407
+ 'main': require.resolve('./src-gen/backend/main'),
408
+ // Theia's IPC mechanism:
409
+ 'ipc-bootstrap': require.resolve('@theia/core/lib/node/messaging/ipc-bootstrap'),
410
+ ${this.ifPackage('@theia/plugin-ext', () => `// VS Code extension support:
411
+ 'plugin-host': require.resolve('@theia/plugin-ext/lib/hosted/node/plugin-host'),`)}
412
+ ${this.ifPackage('@theia/plugin-ext-headless', () => `// Theia Headless Plugin support:
413
+ 'plugin-host-headless': require.resolve('@theia/plugin-ext-headless/lib/hosted/node/plugin-host-headless'),`)}
414
+ ${this.ifPackage('@theia/process', () => `// Make sure the node-pty thread worker can be executed:
415
+ 'worker/conoutSocketWorker': require.resolve('node-pty/lib/worker/conoutSocketWorker'),`)}
416
+ ${this.ifElectron("'electron-main': require.resolve('./src-gen/backend/electron-main'),")}
417
+ ${this.ifPackage('@theia/dev-container', () => `// VS Code Dev-Container communication:
418
+ 'dev-container-server': require.resolve('@theia/dev-container/lib/dev-container-server/dev-container-server'),`)}
419
+ ...commonJsLibraries
420
+ },
421
+ module: {
422
+ rules: [
423
+ // Make sure we can still find and load our native addons.
424
+ {
425
+ test: /\\.node$/,
426
+ loader: 'node-loader',
427
+ options: {
428
+ name: 'native/[name].[ext]'
429
+ }
430
+ },
431
+ {
432
+ test: /\\.js$/,
433
+ enforce: 'pre',
434
+ loader: 'source-map-loader'
435
+ },
436
+ // jsonc-parser exposes its UMD implementation by default, which
437
+ // confuses Webpack leading to missing js in the bundles.
438
+ {
439
+ test: /node_modules[\\/](jsonc-parser)/,
440
+ loader: 'umd-compat-loader'
441
+ }
442
+ ]
443
+ },
444
+ plugins: [
445
+ // Some native dependencies need special handling
446
+ nativePlugin,
447
+ // Optional node dependencies can be safely ignored
448
+ new webpack.IgnorePlugin({
449
+ checkResource: resource => ignoredResources.has(resource)
450
+ })
451
+ ],
452
+ optimization: {
453
+ // Split and reuse code across the various entry points
454
+ splitChunks: {
455
+ chunks: 'all'
456
+ },
457
+ // Only minimize if we run webpack in production mode
458
+ minimize: production,
459
+ minimizer: [
460
+ new TerserPlugin({
461
+ exclude: /^(lib|builtins)\\//
462
+ })
463
+ ]
464
+ },
465
+ ignoreWarnings: [
466
+ // Some packages do not have source maps, that's ok
467
+ /Failed to parse source map/,
468
+ // Some packages use dynamic requires, we can safely ignore them (they are handled by the native webpack plugin)
469
+ /require function is used in a way in which dependencies cannot be statically extracted/, {
470
+ module: /yargs/
471
+ }, {
472
+ module: /node-pty/
473
+ }, {
474
+ module: /require-main-filename/
475
+ }, {
476
+ module: /ws/
477
+ }, {
478
+ module: /express/
479
+ }, {
480
+ module: /cross-spawn/
481
+ }
482
+ ]
483
+ };
484
+
485
+ module.exports = {
486
+ config,
487
+ nativePlugin,
488
+ ignoredResources
489
+ };
490
+ `;
491
+ }
492
+ }
493
+ exports.WebpackGenerator = WebpackGenerator;
507
494
  //# sourceMappingURL=webpack-generator.js.map