@theia/application-manager 1.48.0 → 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.
@@ -1,198 +1,198 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2017 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { EOL } from 'os';
18
- import { AbstractGenerator } from './abstract-generator';
19
-
20
- export class BackendGenerator extends AbstractGenerator {
21
-
22
- async generate(): Promise<void> {
23
- if (this.pck.isBrowserOnly()) {
24
- // no backend generation in case of browser-only target
25
- return;
26
- }
27
- const backendModules = this.pck.targetBackendModules;
28
- await this.write(this.pck.backend('server.js'), this.compileServer(backendModules));
29
- await this.write(this.pck.backend('main.js'), this.compileMain(backendModules));
30
- if (this.pck.isElectron()) {
31
- await this.write(this.pck.backend('electron-main.js'), this.compileElectronMain(this.pck.targetElectronMainModules));
32
- }
33
- }
34
-
35
- protected compileElectronMain(electronMainModules?: Map<string, string>): string {
36
- return `// @ts-check
37
-
38
- require('reflect-metadata');
39
-
40
- // Useful for Electron/NW.js apps as GUI apps on macOS doesn't inherit the \`$PATH\` define
41
- // in your dotfiles (.bashrc/.bash_profile/.zshrc/etc).
42
- // https://github.com/electron/electron/issues/550#issuecomment-162037357
43
- // https://github.com/eclipse-theia/theia/pull/3534#issuecomment-439689082
44
- require('fix-path')();
45
-
46
- // Workaround for https://github.com/electron/electron/issues/9225. Chrome has an issue where
47
- // in certain locales (e.g. PL), image metrics are wrongly computed. We explicitly set the
48
- // LC_NUMERIC to prevent this from happening (selects the numeric formatting category of the
49
- // C locale, http://en.cppreference.com/w/cpp/locale/LC_categories).
50
- if (process.env.LC_ALL) {
51
- process.env.LC_ALL = 'C';
52
- }
53
- process.env.LC_NUMERIC = 'C';
54
-
55
- const { default: electronMainApplicationModule } = require('@theia/core/lib/electron-main/electron-main-application-module');
56
- const { ElectronMainApplication, ElectronMainApplicationGlobals } = require('@theia/core/lib/electron-main/electron-main-application');
57
- const { Container } = require('inversify');
58
- const { resolve } = require('path');
59
- const { app } = require('electron');
60
-
61
- const config = ${this.prettyStringify(this.pck.props.frontend.config)};
62
- const isSingleInstance = ${this.pck.props.backend.config.singleInstance === true ? 'true' : 'false'};
63
-
64
- (async () => {
65
- if (isSingleInstance && !app.requestSingleInstanceLock()) {
66
- // There is another instance running, exit now. The other instance will request focus.
67
- app.quit();
68
- return;
69
- }
70
-
71
- const container = new Container();
72
- container.load(electronMainApplicationModule);
73
- container.bind(ElectronMainApplicationGlobals).toConstantValue({
74
- THEIA_APP_PROJECT_PATH: resolve(__dirname, '..', '..'),
75
- THEIA_BACKEND_MAIN_PATH: resolve(__dirname, 'main.js'),
76
- THEIA_FRONTEND_HTML_PATH: resolve(__dirname, '..', '..', 'lib', 'frontend', 'index.html'),
77
- });
78
-
79
- function load(raw) {
80
- return Promise.resolve(raw.default).then(module =>
81
- container.load(module)
82
- );
83
- }
84
-
85
- async function start() {
86
- const application = container.get(ElectronMainApplication);
87
- await application.start(config);
88
- }
89
-
90
- try {
91
- ${Array.from(electronMainModules?.values() ?? [], jsModulePath => `\
92
- await load(require('${jsModulePath}'));`).join(EOL)}
93
- await start();
94
- } catch (reason) {
95
- if (typeof reason !== 'number') {
96
- console.error('Failed to start the electron application.');
97
- if (reason) {
98
- console.error(reason);
99
- }
100
- }
101
- app.quit();
102
- };
103
- })();
104
- `;
105
- }
106
-
107
- protected compileServer(backendModules: Map<string, string>): string {
108
- return `// @ts-check
109
- require('reflect-metadata');${this.ifElectron(`
110
-
111
- // Patch electron version if missing, see https://github.com/eclipse-theia/theia/pull/7361#pullrequestreview-377065146
112
- if (typeof process.versions.electron === 'undefined' && typeof process.env.THEIA_ELECTRON_VERSION === 'string') {
113
- process.versions.electron = process.env.THEIA_ELECTRON_VERSION;
114
- }`)}
115
-
116
- // Erase the ELECTRON_RUN_AS_NODE variable from the environment, else Electron apps started using Theia will pick it up.
117
- if ('ELECTRON_RUN_AS_NODE' in process.env) {
118
- delete process.env.ELECTRON_RUN_AS_NODE;
119
- }
120
-
121
- const path = require('path');
122
- const express = require('express');
123
- const { Container } = require('inversify');
124
- const { BackendApplication, BackendApplicationServer, CliManager } = require('@theia/core/lib/node');
125
- const { backendApplicationModule } = require('@theia/core/lib/node/backend-application-module');
126
- const { messagingBackendModule } = require('@theia/core/lib/node/messaging/messaging-backend-module');
127
- const { loggerBackendModule } = require('@theia/core/lib/node/logger-backend-module');
128
-
129
- const container = new Container();
130
- container.load(backendApplicationModule);
131
- container.load(messagingBackendModule);
132
- container.load(loggerBackendModule);
133
-
134
- function defaultServeStatic(app) {
135
- app.use(express.static(path.resolve(__dirname, '../../lib/frontend')))
136
- }
137
-
138
- function load(raw) {
139
- return Promise.resolve(raw).then(
140
- module => container.load(module.default)
141
- );
142
- }
143
-
144
- async function start(port, host, argv = process.argv) {
145
- if (!container.isBound(BackendApplicationServer)) {
146
- container.bind(BackendApplicationServer).toConstantValue({ configure: defaultServeStatic });
147
- }
148
- let result = undefined;
149
- await container.get(CliManager).initializeCli(argv.slice(2),
150
- () => container.get(BackendApplication).configured,
151
- async () => {
152
- result = container.get(BackendApplication).start(port, host);
153
- });
154
- if (result) {
155
- return result;
156
- } else {
157
- return Promise.reject(0);
158
- }
159
- }
160
-
161
- module.exports = async (port, host, argv) => {
162
- try {
163
- ${Array.from(backendModules.values(), jsModulePath => `\
164
- await load(require('${jsModulePath}'));`).join(EOL)}
165
- return await start(port, host, argv);
166
- } catch (error) {
167
- if (typeof error !== 'number') {
168
- console.error('Failed to start the backend application:');
169
- console.error(error);
170
- process.exitCode = 1;
171
- }
172
- throw error;
173
- }
174
- }
175
- `;
176
- }
177
-
178
- protected compileMain(backendModules: Map<string, string>): string {
179
- return `// @ts-check
180
- const { BackendApplicationConfigProvider } = require('@theia/core/lib/node/backend-application-config-provider');
181
- const main = require('@theia/core/lib/node/main');
182
-
183
- BackendApplicationConfigProvider.set(${this.prettyStringify(this.pck.props.backend.config)});
184
-
185
- const serverModule = require('./server');
186
- const serverAddress = main.start(serverModule());
187
-
188
- serverAddress.then((addressInfo) => {
189
- if (process && process.send && addressInfo) {
190
- process.send(addressInfo);
191
- }
192
- });
193
-
194
- globalThis.serverAddress = serverAddress;
195
- `;
196
- }
197
-
198
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2017 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { EOL } from 'os';
18
+ import { AbstractGenerator } from './abstract-generator';
19
+
20
+ export class BackendGenerator extends AbstractGenerator {
21
+
22
+ async generate(): Promise<void> {
23
+ if (this.pck.isBrowserOnly()) {
24
+ // no backend generation in case of browser-only target
25
+ return;
26
+ }
27
+ const backendModules = this.pck.targetBackendModules;
28
+ await this.write(this.pck.backend('server.js'), this.compileServer(backendModules));
29
+ await this.write(this.pck.backend('main.js'), this.compileMain(backendModules));
30
+ if (this.pck.isElectron()) {
31
+ await this.write(this.pck.backend('electron-main.js'), this.compileElectronMain(this.pck.targetElectronMainModules));
32
+ }
33
+ }
34
+
35
+ protected compileElectronMain(electronMainModules?: Map<string, string>): string {
36
+ return `// @ts-check
37
+
38
+ require('reflect-metadata');
39
+
40
+ // Useful for Electron/NW.js apps as GUI apps on macOS doesn't inherit the \`$PATH\` define
41
+ // in your dotfiles (.bashrc/.bash_profile/.zshrc/etc).
42
+ // https://github.com/electron/electron/issues/550#issuecomment-162037357
43
+ // https://github.com/eclipse-theia/theia/pull/3534#issuecomment-439689082
44
+ require('fix-path')();
45
+
46
+ // Workaround for https://github.com/electron/electron/issues/9225. Chrome has an issue where
47
+ // in certain locales (e.g. PL), image metrics are wrongly computed. We explicitly set the
48
+ // LC_NUMERIC to prevent this from happening (selects the numeric formatting category of the
49
+ // C locale, http://en.cppreference.com/w/cpp/locale/LC_categories).
50
+ if (process.env.LC_ALL) {
51
+ process.env.LC_ALL = 'C';
52
+ }
53
+ process.env.LC_NUMERIC = 'C';
54
+
55
+ const { default: electronMainApplicationModule } = require('@theia/core/lib/electron-main/electron-main-application-module');
56
+ const { ElectronMainApplication, ElectronMainApplicationGlobals } = require('@theia/core/lib/electron-main/electron-main-application');
57
+ const { Container } = require('inversify');
58
+ const { resolve } = require('path');
59
+ const { app } = require('electron');
60
+
61
+ const config = ${this.prettyStringify(this.pck.props.frontend.config)};
62
+ const isSingleInstance = ${this.pck.props.backend.config.singleInstance === true ? 'true' : 'false'};
63
+
64
+ (async () => {
65
+ if (isSingleInstance && !app.requestSingleInstanceLock()) {
66
+ // There is another instance running, exit now. The other instance will request focus.
67
+ app.quit();
68
+ return;
69
+ }
70
+
71
+ const container = new Container();
72
+ container.load(electronMainApplicationModule);
73
+ container.bind(ElectronMainApplicationGlobals).toConstantValue({
74
+ THEIA_APP_PROJECT_PATH: resolve(__dirname, '..', '..'),
75
+ THEIA_BACKEND_MAIN_PATH: resolve(__dirname, 'main.js'),
76
+ THEIA_FRONTEND_HTML_PATH: resolve(__dirname, '..', '..', 'lib', 'frontend', 'index.html'),
77
+ });
78
+
79
+ function load(raw) {
80
+ return Promise.resolve(raw.default).then(module =>
81
+ container.load(module)
82
+ );
83
+ }
84
+
85
+ async function start() {
86
+ const application = container.get(ElectronMainApplication);
87
+ await application.start(config);
88
+ }
89
+
90
+ try {
91
+ ${Array.from(electronMainModules?.values() ?? [], jsModulePath => `\
92
+ await load(require('${jsModulePath}'));`).join(EOL)}
93
+ await start();
94
+ } catch (reason) {
95
+ if (typeof reason !== 'number') {
96
+ console.error('Failed to start the electron application.');
97
+ if (reason) {
98
+ console.error(reason);
99
+ }
100
+ }
101
+ app.quit();
102
+ };
103
+ })();
104
+ `;
105
+ }
106
+
107
+ protected compileServer(backendModules: Map<string, string>): string {
108
+ return `// @ts-check
109
+ require('reflect-metadata');${this.ifElectron(`
110
+
111
+ // Patch electron version if missing, see https://github.com/eclipse-theia/theia/pull/7361#pullrequestreview-377065146
112
+ if (typeof process.versions.electron === 'undefined' && typeof process.env.THEIA_ELECTRON_VERSION === 'string') {
113
+ process.versions.electron = process.env.THEIA_ELECTRON_VERSION;
114
+ }`)}
115
+
116
+ // Erase the ELECTRON_RUN_AS_NODE variable from the environment, else Electron apps started using Theia will pick it up.
117
+ if ('ELECTRON_RUN_AS_NODE' in process.env) {
118
+ delete process.env.ELECTRON_RUN_AS_NODE;
119
+ }
120
+
121
+ const path = require('path');
122
+ const express = require('express');
123
+ const { Container } = require('inversify');
124
+ const { BackendApplication, BackendApplicationServer, CliManager } = require('@theia/core/lib/node');
125
+ const { backendApplicationModule } = require('@theia/core/lib/node/backend-application-module');
126
+ const { messagingBackendModule } = require('@theia/core/lib/node/messaging/messaging-backend-module');
127
+ const { loggerBackendModule } = require('@theia/core/lib/node/logger-backend-module');
128
+
129
+ const container = new Container();
130
+ container.load(backendApplicationModule);
131
+ container.load(messagingBackendModule);
132
+ container.load(loggerBackendModule);
133
+
134
+ function defaultServeStatic(app) {
135
+ app.use(express.static(path.resolve(__dirname, '../../lib/frontend')))
136
+ }
137
+
138
+ function load(raw) {
139
+ return Promise.resolve(raw).then(
140
+ module => container.load(module.default)
141
+ );
142
+ }
143
+
144
+ async function start(port, host, argv = process.argv) {
145
+ if (!container.isBound(BackendApplicationServer)) {
146
+ container.bind(BackendApplicationServer).toConstantValue({ configure: defaultServeStatic });
147
+ }
148
+ let result = undefined;
149
+ await container.get(CliManager).initializeCli(argv.slice(2),
150
+ () => container.get(BackendApplication).configured,
151
+ async () => {
152
+ result = container.get(BackendApplication).start(port, host);
153
+ });
154
+ if (result) {
155
+ return result;
156
+ } else {
157
+ return Promise.reject(0);
158
+ }
159
+ }
160
+
161
+ module.exports = async (port, host, argv) => {
162
+ try {
163
+ ${Array.from(backendModules.values(), jsModulePath => `\
164
+ await load(require('${jsModulePath}'));`).join(EOL)}
165
+ return await start(port, host, argv);
166
+ } catch (error) {
167
+ if (typeof error !== 'number') {
168
+ console.error('Failed to start the backend application:');
169
+ console.error(error);
170
+ process.exitCode = 1;
171
+ }
172
+ throw error;
173
+ }
174
+ }
175
+ `;
176
+ }
177
+
178
+ protected compileMain(backendModules: Map<string, string>): string {
179
+ return `// @ts-check
180
+ const { BackendApplicationConfigProvider } = require('@theia/core/lib/node/backend-application-config-provider');
181
+ const main = require('@theia/core/lib/node/main');
182
+
183
+ BackendApplicationConfigProvider.set(${this.prettyStringify(this.pck.props.backend.config)});
184
+
185
+ const serverModule = require('./server');
186
+ const serverAddress = main.start(serverModule());
187
+
188
+ serverAddress.then((addressInfo) => {
189
+ if (process && process.send && addressInfo) {
190
+ process.send(addressInfo);
191
+ }
192
+ });
193
+
194
+ globalThis.serverAddress = serverAddress;
195
+ `;
196
+ }
197
+
198
+ }