@theia/application-manager 1.48.1 → 1.48.2
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/README.md +25 -25
- package/lib/application-package-manager.d.ts +45 -45
- package/lib/application-package-manager.js +225 -225
- package/lib/application-process.d.ts +19 -19
- package/lib/application-process.js +72 -72
- package/lib/expose-loader.d.ts +8 -8
- package/lib/expose-loader.js +69 -69
- package/lib/generator/abstract-generator.d.ts +17 -17
- package/lib/generator/abstract-generator.js +57 -57
- package/lib/generator/backend-generator.d.ts +7 -7
- package/lib/generator/backend-generator.js +196 -196
- package/lib/generator/frontend-generator.d.ts +13 -13
- package/lib/generator/frontend-generator.js +212 -212
- package/lib/generator/index.d.ts +3 -3
- package/lib/generator/index.js +21 -21
- package/lib/generator/webpack-generator.d.ts +12 -12
- package/lib/generator/webpack-generator.js +493 -493
- package/lib/index.d.ts +3 -3
- package/lib/index.js +21 -21
- package/lib/package.spec.js +25 -25
- package/lib/rebuild.d.ts +24 -24
- package/lib/rebuild.js +309 -309
- package/package.json +6 -6
- package/src/application-package-manager.ts +263 -263
- package/src/application-process.ts +80 -80
- package/src/expose-loader.ts +80 -80
- package/src/generator/abstract-generator.ts +69 -69
- package/src/generator/backend-generator.ts +198 -198
- package/src/generator/frontend-generator.ts +222 -222
- package/src/generator/index.ts +19 -19
- package/src/generator/webpack-generator.ts +501 -501
- package/src/index.ts +19 -19
- package/src/package.spec.ts +28 -28
- package/src/rebuild.ts +345 -345
package/README.md
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
<div align='center'>
|
|
2
|
-
|
|
3
|
-
<br />
|
|
4
|
-
|
|
5
|
-
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
|
|
6
|
-
|
|
7
|
-
<h2>ECLIPSE THEIA - APPLICATION-MANAGER</h2>
|
|
8
|
-
|
|
9
|
-
<hr />
|
|
10
|
-
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
## Additional Information
|
|
14
|
-
|
|
15
|
-
- [Theia - GitHub](https://github.com/eclipse-theia/theia)
|
|
16
|
-
- [Theia - Website](https://theia-ide.org/)
|
|
17
|
-
|
|
18
|
-
## License
|
|
19
|
-
|
|
20
|
-
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
|
|
21
|
-
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
|
|
22
|
-
|
|
23
|
-
## Trademark
|
|
24
|
-
"Theia" is a trademark of the Eclipse Foundation
|
|
25
|
-
https://www.eclipse.org/theia
|
|
1
|
+
<div align='center'>
|
|
2
|
+
|
|
3
|
+
<br />
|
|
4
|
+
|
|
5
|
+
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
|
|
6
|
+
|
|
7
|
+
<h2>ECLIPSE THEIA - APPLICATION-MANAGER</h2>
|
|
8
|
+
|
|
9
|
+
<hr />
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## Additional Information
|
|
14
|
+
|
|
15
|
+
- [Theia - GitHub](https://github.com/eclipse-theia/theia)
|
|
16
|
+
- [Theia - Website](https://theia-ide.org/)
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
|
|
21
|
+
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
|
|
22
|
+
|
|
23
|
+
## Trademark
|
|
24
|
+
"Theia" is a trademark of the Eclipse Foundation
|
|
25
|
+
https://www.eclipse.org/theia
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as cp from 'child_process';
|
|
3
|
-
import { ApplicationPackage, ApplicationPackageOptions } from '@theia/application-package';
|
|
4
|
-
import { ApplicationProcess } from './application-process';
|
|
5
|
-
import { GeneratorOptions } from './generator/abstract-generator';
|
|
6
|
-
import yargs = require('yargs');
|
|
7
|
-
declare module 'semver' {
|
|
8
|
-
function minVersion(range: string): string;
|
|
9
|
-
}
|
|
10
|
-
export declare class ApplicationPackageManager {
|
|
11
|
-
static defineGeneratorOptions<T>(cli: yargs.Argv<T>): yargs.Argv<T & {
|
|
12
|
-
mode: 'development' | 'production';
|
|
13
|
-
splitFrontend?: boolean;
|
|
14
|
-
}>;
|
|
15
|
-
readonly pck: ApplicationPackage;
|
|
16
|
-
/** application process */
|
|
17
|
-
readonly process: ApplicationProcess;
|
|
18
|
-
/** manager process */
|
|
19
|
-
protected readonly __process: ApplicationProcess;
|
|
20
|
-
constructor(options: ApplicationPackageOptions);
|
|
21
|
-
protected remove(fsPath: string): Promise<void>;
|
|
22
|
-
clean(): Promise<void>;
|
|
23
|
-
prepare(): Promise<void>;
|
|
24
|
-
generate(options?: GeneratorOptions): Promise<void>;
|
|
25
|
-
copy(): Promise<void>;
|
|
26
|
-
build(args?: string[], options?: GeneratorOptions): Promise<void>;
|
|
27
|
-
start(args?: string[]): cp.ChildProcess;
|
|
28
|
-
startBrowserOnly(args: string[]): cp.ChildProcess;
|
|
29
|
-
adjustBrowserOnlyArgs(args: string[]): Readonly<{
|
|
30
|
-
command: string;
|
|
31
|
-
mainArgs: string[];
|
|
32
|
-
options: cp.SpawnOptions;
|
|
33
|
-
}>;
|
|
34
|
-
startElectron(args: string[]): cp.ChildProcess;
|
|
35
|
-
startBrowser(args: string[]): cp.ChildProcess;
|
|
36
|
-
/**
|
|
37
|
-
* Inject Theia's Electron-specific dependencies into the application's package.json.
|
|
38
|
-
*
|
|
39
|
-
* Only overwrite the Electron range if the current minimum supported version is lower than the recommended one.
|
|
40
|
-
*/
|
|
41
|
-
protected prepareElectron(): Promise<void>;
|
|
42
|
-
protected insertAlphabetically<T extends Record<string, string>>(object: T, key: string, value: string): T;
|
|
43
|
-
private adjustArgs;
|
|
44
|
-
private get forkOptions();
|
|
45
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as cp from 'child_process';
|
|
3
|
+
import { ApplicationPackage, ApplicationPackageOptions } from '@theia/application-package';
|
|
4
|
+
import { ApplicationProcess } from './application-process';
|
|
5
|
+
import { GeneratorOptions } from './generator/abstract-generator';
|
|
6
|
+
import yargs = require('yargs');
|
|
7
|
+
declare module 'semver' {
|
|
8
|
+
function minVersion(range: string): string;
|
|
9
|
+
}
|
|
10
|
+
export declare class ApplicationPackageManager {
|
|
11
|
+
static defineGeneratorOptions<T>(cli: yargs.Argv<T>): yargs.Argv<T & {
|
|
12
|
+
mode: 'development' | 'production';
|
|
13
|
+
splitFrontend?: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
readonly pck: ApplicationPackage;
|
|
16
|
+
/** application process */
|
|
17
|
+
readonly process: ApplicationProcess;
|
|
18
|
+
/** manager process */
|
|
19
|
+
protected readonly __process: ApplicationProcess;
|
|
20
|
+
constructor(options: ApplicationPackageOptions);
|
|
21
|
+
protected remove(fsPath: string): Promise<void>;
|
|
22
|
+
clean(): Promise<void>;
|
|
23
|
+
prepare(): Promise<void>;
|
|
24
|
+
generate(options?: GeneratorOptions): Promise<void>;
|
|
25
|
+
copy(): Promise<void>;
|
|
26
|
+
build(args?: string[], options?: GeneratorOptions): Promise<void>;
|
|
27
|
+
start(args?: string[]): cp.ChildProcess;
|
|
28
|
+
startBrowserOnly(args: string[]): cp.ChildProcess;
|
|
29
|
+
adjustBrowserOnlyArgs(args: string[]): Readonly<{
|
|
30
|
+
command: string;
|
|
31
|
+
mainArgs: string[];
|
|
32
|
+
options: cp.SpawnOptions;
|
|
33
|
+
}>;
|
|
34
|
+
startElectron(args: string[]): cp.ChildProcess;
|
|
35
|
+
startBrowser(args: string[]): cp.ChildProcess;
|
|
36
|
+
/**
|
|
37
|
+
* Inject Theia's Electron-specific dependencies into the application's package.json.
|
|
38
|
+
*
|
|
39
|
+
* Only overwrite the Electron range if the current minimum supported version is lower than the recommended one.
|
|
40
|
+
*/
|
|
41
|
+
protected prepareElectron(): Promise<void>;
|
|
42
|
+
protected insertAlphabetically<T extends Record<string, string>>(object: T, key: string, value: string): T;
|
|
43
|
+
private adjustArgs;
|
|
44
|
+
private get forkOptions();
|
|
45
|
+
}
|
|
46
46
|
//# sourceMappingURL=application-package-manager.d.ts.map
|
|
@@ -1,226 +1,226 @@
|
|
|
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.ApplicationPackageManager = void 0;
|
|
19
|
-
const path = require("path");
|
|
20
|
-
const fs = require("fs-extra");
|
|
21
|
-
const semver = require("semver");
|
|
22
|
-
const application_package_1 = require("@theia/application-package");
|
|
23
|
-
const generator_1 = require("./generator");
|
|
24
|
-
const application_process_1 = require("./application-process");
|
|
25
|
-
class AbortError extends Error {
|
|
26
|
-
constructor(...args) {
|
|
27
|
-
super(...args);
|
|
28
|
-
Object.setPrototypeOf(this, AbortError.prototype);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
class ApplicationPackageManager {
|
|
32
|
-
constructor(options) {
|
|
33
|
-
this.pck = new application_package_1.ApplicationPackage(options);
|
|
34
|
-
this.process = new application_process_1.ApplicationProcess(this.pck, options.projectPath);
|
|
35
|
-
this.__process = new application_process_1.ApplicationProcess(this.pck, path.join(__dirname, '..'));
|
|
36
|
-
}
|
|
37
|
-
static defineGeneratorOptions(cli) {
|
|
38
|
-
return cli
|
|
39
|
-
.option('mode', {
|
|
40
|
-
description: 'Generation mode to use',
|
|
41
|
-
choices: ['development', 'production'],
|
|
42
|
-
default: 'production',
|
|
43
|
-
})
|
|
44
|
-
.option('split-frontend', {
|
|
45
|
-
description: 'Split frontend modules into separate chunks. By default enabled in the `development` mode and disabled in the `production` mode.',
|
|
46
|
-
type: 'boolean'
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async remove(fsPath) {
|
|
50
|
-
if (await fs.pathExists(fsPath)) {
|
|
51
|
-
await fs.remove(fsPath);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async clean() {
|
|
55
|
-
const webpackGenerator = new generator_1.WebpackGenerator(this.pck);
|
|
56
|
-
await Promise.all([
|
|
57
|
-
this.remove(this.pck.lib()),
|
|
58
|
-
this.remove(this.pck.srcGen()),
|
|
59
|
-
this.remove(webpackGenerator.genConfigPath),
|
|
60
|
-
this.remove(webpackGenerator.genNodeConfigPath)
|
|
61
|
-
]);
|
|
62
|
-
}
|
|
63
|
-
async prepare() {
|
|
64
|
-
if (this.pck.isElectron()) {
|
|
65
|
-
await this.prepareElectron();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async generate(options = {}) {
|
|
69
|
-
try {
|
|
70
|
-
await this.prepare();
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
if (error instanceof AbortError) {
|
|
74
|
-
console.warn(error.message);
|
|
75
|
-
process.exit(1);
|
|
76
|
-
}
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
await Promise.all([
|
|
80
|
-
new generator_1.WebpackGenerator(this.pck, options).generate(),
|
|
81
|
-
new generator_1.BackendGenerator(this.pck, options).generate(),
|
|
82
|
-
new generator_1.FrontendGenerator(this.pck, options).generate(),
|
|
83
|
-
]);
|
|
84
|
-
}
|
|
85
|
-
async copy() {
|
|
86
|
-
await fs.ensureDir(this.pck.lib('frontend'));
|
|
87
|
-
await fs.copy(this.pck.frontend('index.html'), this.pck.lib('frontend', 'index.html'));
|
|
88
|
-
}
|
|
89
|
-
async build(args = [], options = {}) {
|
|
90
|
-
await this.generate(options);
|
|
91
|
-
await this.copy();
|
|
92
|
-
return this.__process.run('webpack', args);
|
|
93
|
-
}
|
|
94
|
-
start(args = []) {
|
|
95
|
-
if (this.pck.isElectron()) {
|
|
96
|
-
return this.startElectron(args);
|
|
97
|
-
}
|
|
98
|
-
else if (this.pck.isBrowserOnly()) {
|
|
99
|
-
return this.startBrowserOnly(args);
|
|
100
|
-
}
|
|
101
|
-
return this.startBrowser(args);
|
|
102
|
-
}
|
|
103
|
-
startBrowserOnly(args) {
|
|
104
|
-
const { command, mainArgs, options } = this.adjustBrowserOnlyArgs(args);
|
|
105
|
-
return this.__process.spawnBin(command, mainArgs, options);
|
|
106
|
-
}
|
|
107
|
-
adjustBrowserOnlyArgs(args) {
|
|
108
|
-
let { mainArgs, options } = this.adjustArgs(args);
|
|
109
|
-
// first parameter: path to generated frontend
|
|
110
|
-
// second parameter: disable cache to support watching
|
|
111
|
-
mainArgs = ['lib/frontend', '-c-1', ...mainArgs];
|
|
112
|
-
const portIndex = mainArgs.findIndex(v => v.startsWith('--port'));
|
|
113
|
-
if (portIndex === -1) {
|
|
114
|
-
mainArgs.push('--port=3000');
|
|
115
|
-
}
|
|
116
|
-
return { command: 'http-server', mainArgs, options };
|
|
117
|
-
}
|
|
118
|
-
startElectron(args) {
|
|
119
|
-
// If possible, pass the project root directory to electron rather than the script file so that Electron
|
|
120
|
-
// can determine the app name. This requires that the package.json has a main field.
|
|
121
|
-
let appPath = this.pck.projectPath;
|
|
122
|
-
if (!this.pck.pck.main) {
|
|
123
|
-
// Try the bundled electron app first
|
|
124
|
-
appPath = this.pck.lib('backend', 'electron-main.js');
|
|
125
|
-
if (!fs.existsSync(appPath)) {
|
|
126
|
-
// Fallback to the generated electron app in src-gen
|
|
127
|
-
appPath = this.pck.backend('electron-main.js');
|
|
128
|
-
}
|
|
129
|
-
console.warn(`WARNING: ${this.pck.packagePath} does not have a "main" entry.\n` +
|
|
130
|
-
'Please add the following line:\n' +
|
|
131
|
-
' "main": "lib/backend/electron-main.js"');
|
|
132
|
-
}
|
|
133
|
-
const { mainArgs, options } = this.adjustArgs([appPath, ...args]);
|
|
134
|
-
const electronCli = require.resolve('electron/cli.js', { paths: [this.pck.projectPath] });
|
|
135
|
-
return this.__process.fork(electronCli, mainArgs, options);
|
|
136
|
-
}
|
|
137
|
-
startBrowser(args) {
|
|
138
|
-
const { mainArgs, options } = this.adjustArgs(args);
|
|
139
|
-
// The backend must be a process group leader on UNIX in order to kill the tree later.
|
|
140
|
-
// See https://nodejs.org/api/child_process.html#child_process_options_detached
|
|
141
|
-
options.detached = process.platform !== 'win32';
|
|
142
|
-
// Try the bundled backend app first
|
|
143
|
-
let mainPath = this.pck.lib('backend', 'main.js');
|
|
144
|
-
if (!fs.existsSync(mainPath)) {
|
|
145
|
-
// Fallback to the generated backend file in src-gen
|
|
146
|
-
mainPath = this.pck.backend('main.js');
|
|
147
|
-
}
|
|
148
|
-
return this.__process.fork(mainPath, mainArgs, options);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Inject Theia's Electron-specific dependencies into the application's package.json.
|
|
152
|
-
*
|
|
153
|
-
* Only overwrite the Electron range if the current minimum supported version is lower than the recommended one.
|
|
154
|
-
*/
|
|
155
|
-
async prepareElectron() {
|
|
156
|
-
let theiaElectron;
|
|
157
|
-
try {
|
|
158
|
-
theiaElectron = await Promise.resolve().then(() => require('@theia/electron'));
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
if (error.code === 'ERR_MODULE_NOT_FOUND') {
|
|
162
|
-
throw new AbortError('Please install @theia/electron as part of your Theia Electron application');
|
|
163
|
-
}
|
|
164
|
-
throw error;
|
|
165
|
-
}
|
|
166
|
-
const expectedRange = theiaElectron.electronRange;
|
|
167
|
-
const appPackageJsonPath = this.pck.path('package.json');
|
|
168
|
-
const appPackageJson = await fs.readJSON(appPackageJsonPath);
|
|
169
|
-
if (!appPackageJson.devDependencies) {
|
|
170
|
-
appPackageJson.devDependencies = {};
|
|
171
|
-
}
|
|
172
|
-
const currentRange = appPackageJson.devDependencies.electron;
|
|
173
|
-
if (!currentRange || semver.compare(semver.minVersion(currentRange), semver.minVersion(expectedRange)) < 0) {
|
|
174
|
-
// Update the range with the recommended one and write it on disk.
|
|
175
|
-
appPackageJson.devDependencies = this.insertAlphabetically(appPackageJson.devDependencies, 'electron', expectedRange);
|
|
176
|
-
await fs.writeJSON(appPackageJsonPath, appPackageJson, { spaces: 2 });
|
|
177
|
-
throw new AbortError('Updated dependencies, please run "install" again');
|
|
178
|
-
}
|
|
179
|
-
if (!theiaElectron.electronVersion || !semver.satisfies(theiaElectron.electronVersion, currentRange)) {
|
|
180
|
-
throw new AbortError('Dependencies are out of sync, please run "install" again');
|
|
181
|
-
}
|
|
182
|
-
const ffmpeg = await Promise.resolve().then(() => require('@theia/ffmpeg'));
|
|
183
|
-
await ffmpeg.replaceFfmpeg();
|
|
184
|
-
await ffmpeg.checkFfmpeg();
|
|
185
|
-
}
|
|
186
|
-
insertAlphabetically(object, key, value) {
|
|
187
|
-
const updated = {};
|
|
188
|
-
for (const property of Object.keys(object)) {
|
|
189
|
-
if (property.localeCompare(key) > 0) {
|
|
190
|
-
updated[key] = value;
|
|
191
|
-
}
|
|
192
|
-
updated[property] = object[property];
|
|
193
|
-
}
|
|
194
|
-
if (!(key in updated)) {
|
|
195
|
-
updated[key] = value;
|
|
196
|
-
}
|
|
197
|
-
return updated;
|
|
198
|
-
}
|
|
199
|
-
adjustArgs(args, forkOptions = {}) {
|
|
200
|
-
const options = {
|
|
201
|
-
...this.forkOptions,
|
|
202
|
-
forkOptions
|
|
203
|
-
};
|
|
204
|
-
const mainArgs = [...args];
|
|
205
|
-
const inspectIndex = mainArgs.findIndex(v => v.startsWith('--inspect'));
|
|
206
|
-
if (inspectIndex !== -1) {
|
|
207
|
-
const inspectArg = mainArgs.splice(inspectIndex, 1)[0];
|
|
208
|
-
options.execArgv = ['--nolazy', inspectArg];
|
|
209
|
-
}
|
|
210
|
-
return {
|
|
211
|
-
mainArgs,
|
|
212
|
-
options
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
get forkOptions() {
|
|
216
|
-
return {
|
|
217
|
-
stdio: [0, 1, 2, 'ipc'],
|
|
218
|
-
env: {
|
|
219
|
-
...process.env,
|
|
220
|
-
THEIA_PARENT_PID: String(process.pid)
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
exports.ApplicationPackageManager = ApplicationPackageManager;
|
|
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.ApplicationPackageManager = void 0;
|
|
19
|
+
const path = require("path");
|
|
20
|
+
const fs = require("fs-extra");
|
|
21
|
+
const semver = require("semver");
|
|
22
|
+
const application_package_1 = require("@theia/application-package");
|
|
23
|
+
const generator_1 = require("./generator");
|
|
24
|
+
const application_process_1 = require("./application-process");
|
|
25
|
+
class AbortError extends Error {
|
|
26
|
+
constructor(...args) {
|
|
27
|
+
super(...args);
|
|
28
|
+
Object.setPrototypeOf(this, AbortError.prototype);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class ApplicationPackageManager {
|
|
32
|
+
constructor(options) {
|
|
33
|
+
this.pck = new application_package_1.ApplicationPackage(options);
|
|
34
|
+
this.process = new application_process_1.ApplicationProcess(this.pck, options.projectPath);
|
|
35
|
+
this.__process = new application_process_1.ApplicationProcess(this.pck, path.join(__dirname, '..'));
|
|
36
|
+
}
|
|
37
|
+
static defineGeneratorOptions(cli) {
|
|
38
|
+
return cli
|
|
39
|
+
.option('mode', {
|
|
40
|
+
description: 'Generation mode to use',
|
|
41
|
+
choices: ['development', 'production'],
|
|
42
|
+
default: 'production',
|
|
43
|
+
})
|
|
44
|
+
.option('split-frontend', {
|
|
45
|
+
description: 'Split frontend modules into separate chunks. By default enabled in the `development` mode and disabled in the `production` mode.',
|
|
46
|
+
type: 'boolean'
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async remove(fsPath) {
|
|
50
|
+
if (await fs.pathExists(fsPath)) {
|
|
51
|
+
await fs.remove(fsPath);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async clean() {
|
|
55
|
+
const webpackGenerator = new generator_1.WebpackGenerator(this.pck);
|
|
56
|
+
await Promise.all([
|
|
57
|
+
this.remove(this.pck.lib()),
|
|
58
|
+
this.remove(this.pck.srcGen()),
|
|
59
|
+
this.remove(webpackGenerator.genConfigPath),
|
|
60
|
+
this.remove(webpackGenerator.genNodeConfigPath)
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
async prepare() {
|
|
64
|
+
if (this.pck.isElectron()) {
|
|
65
|
+
await this.prepareElectron();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async generate(options = {}) {
|
|
69
|
+
try {
|
|
70
|
+
await this.prepare();
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error instanceof AbortError) {
|
|
74
|
+
console.warn(error.message);
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
await Promise.all([
|
|
80
|
+
new generator_1.WebpackGenerator(this.pck, options).generate(),
|
|
81
|
+
new generator_1.BackendGenerator(this.pck, options).generate(),
|
|
82
|
+
new generator_1.FrontendGenerator(this.pck, options).generate(),
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
async copy() {
|
|
86
|
+
await fs.ensureDir(this.pck.lib('frontend'));
|
|
87
|
+
await fs.copy(this.pck.frontend('index.html'), this.pck.lib('frontend', 'index.html'));
|
|
88
|
+
}
|
|
89
|
+
async build(args = [], options = {}) {
|
|
90
|
+
await this.generate(options);
|
|
91
|
+
await this.copy();
|
|
92
|
+
return this.__process.run('webpack', args);
|
|
93
|
+
}
|
|
94
|
+
start(args = []) {
|
|
95
|
+
if (this.pck.isElectron()) {
|
|
96
|
+
return this.startElectron(args);
|
|
97
|
+
}
|
|
98
|
+
else if (this.pck.isBrowserOnly()) {
|
|
99
|
+
return this.startBrowserOnly(args);
|
|
100
|
+
}
|
|
101
|
+
return this.startBrowser(args);
|
|
102
|
+
}
|
|
103
|
+
startBrowserOnly(args) {
|
|
104
|
+
const { command, mainArgs, options } = this.adjustBrowserOnlyArgs(args);
|
|
105
|
+
return this.__process.spawnBin(command, mainArgs, options);
|
|
106
|
+
}
|
|
107
|
+
adjustBrowserOnlyArgs(args) {
|
|
108
|
+
let { mainArgs, options } = this.adjustArgs(args);
|
|
109
|
+
// first parameter: path to generated frontend
|
|
110
|
+
// second parameter: disable cache to support watching
|
|
111
|
+
mainArgs = ['lib/frontend', '-c-1', ...mainArgs];
|
|
112
|
+
const portIndex = mainArgs.findIndex(v => v.startsWith('--port'));
|
|
113
|
+
if (portIndex === -1) {
|
|
114
|
+
mainArgs.push('--port=3000');
|
|
115
|
+
}
|
|
116
|
+
return { command: 'http-server', mainArgs, options };
|
|
117
|
+
}
|
|
118
|
+
startElectron(args) {
|
|
119
|
+
// If possible, pass the project root directory to electron rather than the script file so that Electron
|
|
120
|
+
// can determine the app name. This requires that the package.json has a main field.
|
|
121
|
+
let appPath = this.pck.projectPath;
|
|
122
|
+
if (!this.pck.pck.main) {
|
|
123
|
+
// Try the bundled electron app first
|
|
124
|
+
appPath = this.pck.lib('backend', 'electron-main.js');
|
|
125
|
+
if (!fs.existsSync(appPath)) {
|
|
126
|
+
// Fallback to the generated electron app in src-gen
|
|
127
|
+
appPath = this.pck.backend('electron-main.js');
|
|
128
|
+
}
|
|
129
|
+
console.warn(`WARNING: ${this.pck.packagePath} does not have a "main" entry.\n` +
|
|
130
|
+
'Please add the following line:\n' +
|
|
131
|
+
' "main": "lib/backend/electron-main.js"');
|
|
132
|
+
}
|
|
133
|
+
const { mainArgs, options } = this.adjustArgs([appPath, ...args]);
|
|
134
|
+
const electronCli = require.resolve('electron/cli.js', { paths: [this.pck.projectPath] });
|
|
135
|
+
return this.__process.fork(electronCli, mainArgs, options);
|
|
136
|
+
}
|
|
137
|
+
startBrowser(args) {
|
|
138
|
+
const { mainArgs, options } = this.adjustArgs(args);
|
|
139
|
+
// The backend must be a process group leader on UNIX in order to kill the tree later.
|
|
140
|
+
// See https://nodejs.org/api/child_process.html#child_process_options_detached
|
|
141
|
+
options.detached = process.platform !== 'win32';
|
|
142
|
+
// Try the bundled backend app first
|
|
143
|
+
let mainPath = this.pck.lib('backend', 'main.js');
|
|
144
|
+
if (!fs.existsSync(mainPath)) {
|
|
145
|
+
// Fallback to the generated backend file in src-gen
|
|
146
|
+
mainPath = this.pck.backend('main.js');
|
|
147
|
+
}
|
|
148
|
+
return this.__process.fork(mainPath, mainArgs, options);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Inject Theia's Electron-specific dependencies into the application's package.json.
|
|
152
|
+
*
|
|
153
|
+
* Only overwrite the Electron range if the current minimum supported version is lower than the recommended one.
|
|
154
|
+
*/
|
|
155
|
+
async prepareElectron() {
|
|
156
|
+
let theiaElectron;
|
|
157
|
+
try {
|
|
158
|
+
theiaElectron = await Promise.resolve().then(() => require('@theia/electron'));
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error.code === 'ERR_MODULE_NOT_FOUND') {
|
|
162
|
+
throw new AbortError('Please install @theia/electron as part of your Theia Electron application');
|
|
163
|
+
}
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
const expectedRange = theiaElectron.electronRange;
|
|
167
|
+
const appPackageJsonPath = this.pck.path('package.json');
|
|
168
|
+
const appPackageJson = await fs.readJSON(appPackageJsonPath);
|
|
169
|
+
if (!appPackageJson.devDependencies) {
|
|
170
|
+
appPackageJson.devDependencies = {};
|
|
171
|
+
}
|
|
172
|
+
const currentRange = appPackageJson.devDependencies.electron;
|
|
173
|
+
if (!currentRange || semver.compare(semver.minVersion(currentRange), semver.minVersion(expectedRange)) < 0) {
|
|
174
|
+
// Update the range with the recommended one and write it on disk.
|
|
175
|
+
appPackageJson.devDependencies = this.insertAlphabetically(appPackageJson.devDependencies, 'electron', expectedRange);
|
|
176
|
+
await fs.writeJSON(appPackageJsonPath, appPackageJson, { spaces: 2 });
|
|
177
|
+
throw new AbortError('Updated dependencies, please run "install" again');
|
|
178
|
+
}
|
|
179
|
+
if (!theiaElectron.electronVersion || !semver.satisfies(theiaElectron.electronVersion, currentRange)) {
|
|
180
|
+
throw new AbortError('Dependencies are out of sync, please run "install" again');
|
|
181
|
+
}
|
|
182
|
+
const ffmpeg = await Promise.resolve().then(() => require('@theia/ffmpeg'));
|
|
183
|
+
await ffmpeg.replaceFfmpeg();
|
|
184
|
+
await ffmpeg.checkFfmpeg();
|
|
185
|
+
}
|
|
186
|
+
insertAlphabetically(object, key, value) {
|
|
187
|
+
const updated = {};
|
|
188
|
+
for (const property of Object.keys(object)) {
|
|
189
|
+
if (property.localeCompare(key) > 0) {
|
|
190
|
+
updated[key] = value;
|
|
191
|
+
}
|
|
192
|
+
updated[property] = object[property];
|
|
193
|
+
}
|
|
194
|
+
if (!(key in updated)) {
|
|
195
|
+
updated[key] = value;
|
|
196
|
+
}
|
|
197
|
+
return updated;
|
|
198
|
+
}
|
|
199
|
+
adjustArgs(args, forkOptions = {}) {
|
|
200
|
+
const options = {
|
|
201
|
+
...this.forkOptions,
|
|
202
|
+
forkOptions
|
|
203
|
+
};
|
|
204
|
+
const mainArgs = [...args];
|
|
205
|
+
const inspectIndex = mainArgs.findIndex(v => v.startsWith('--inspect'));
|
|
206
|
+
if (inspectIndex !== -1) {
|
|
207
|
+
const inspectArg = mainArgs.splice(inspectIndex, 1)[0];
|
|
208
|
+
options.execArgv = ['--nolazy', inspectArg];
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
mainArgs,
|
|
212
|
+
options
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
get forkOptions() {
|
|
216
|
+
return {
|
|
217
|
+
stdio: [0, 1, 2, 'ipc'],
|
|
218
|
+
env: {
|
|
219
|
+
...process.env,
|
|
220
|
+
THEIA_PARENT_PID: String(process.pid)
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.ApplicationPackageManager = ApplicationPackageManager;
|
|
226
226
|
//# sourceMappingURL=application-package-manager.js.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as cp from 'child_process';
|
|
3
|
-
import { ApplicationPackage } from '@theia/application-package';
|
|
4
|
-
export declare class ApplicationProcess {
|
|
5
|
-
protected readonly pck: ApplicationPackage;
|
|
6
|
-
protected readonly binProjectPath: string;
|
|
7
|
-
protected readonly defaultOptions: {
|
|
8
|
-
cwd: string;
|
|
9
|
-
env: NodeJS.ProcessEnv;
|
|
10
|
-
};
|
|
11
|
-
constructor(pck: ApplicationPackage, binProjectPath: string);
|
|
12
|
-
spawn(command: string, args?: string[], options?: cp.SpawnOptions): cp.ChildProcess;
|
|
13
|
-
fork(modulePath: string, args?: string[], options?: cp.ForkOptions): cp.ChildProcess;
|
|
14
|
-
canRun(command: string): boolean;
|
|
15
|
-
run(command: string, args: string[], options?: cp.SpawnOptions): Promise<void>;
|
|
16
|
-
spawnBin(command: string, args: string[], options?: cp.SpawnOptions): cp.ChildProcess;
|
|
17
|
-
protected resolveBin(command: string): string;
|
|
18
|
-
protected promisify(command: string, p: cp.ChildProcess): Promise<void>;
|
|
19
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as cp from 'child_process';
|
|
3
|
+
import { ApplicationPackage } from '@theia/application-package';
|
|
4
|
+
export declare class ApplicationProcess {
|
|
5
|
+
protected readonly pck: ApplicationPackage;
|
|
6
|
+
protected readonly binProjectPath: string;
|
|
7
|
+
protected readonly defaultOptions: {
|
|
8
|
+
cwd: string;
|
|
9
|
+
env: NodeJS.ProcessEnv;
|
|
10
|
+
};
|
|
11
|
+
constructor(pck: ApplicationPackage, binProjectPath: string);
|
|
12
|
+
spawn(command: string, args?: string[], options?: cp.SpawnOptions): cp.ChildProcess;
|
|
13
|
+
fork(modulePath: string, args?: string[], options?: cp.ForkOptions): cp.ChildProcess;
|
|
14
|
+
canRun(command: string): boolean;
|
|
15
|
+
run(command: string, args: string[], options?: cp.SpawnOptions): Promise<void>;
|
|
16
|
+
spawnBin(command: string, args: string[], options?: cp.SpawnOptions): cp.ChildProcess;
|
|
17
|
+
protected resolveBin(command: string): string;
|
|
18
|
+
protected promisify(command: string, p: cp.ChildProcess): Promise<void>;
|
|
19
|
+
}
|
|
20
20
|
//# sourceMappingURL=application-process.d.ts.map
|