@theia/application-manager 1.53.0-next.4 → 1.53.0-next.55

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.
@@ -49,444 +49,444 @@ class WebpackGenerator extends abstract_generator_1.AbstractGenerator {
49
49
  return this.pck.resolveModulePath(moduleName, path).split(paths.sep).join('/');
50
50
  }
51
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
- }
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
307
  }`)}];`;
308
308
  }
309
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
- ];`)}
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
331
  `;
332
332
  }
333
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
- };
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
490
  `;
491
491
  }
492
492
  }