@theia/application-package 1.45.1 → 1.46.0-next.72
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/api.d.ts +5 -5
- package/lib/api.js +23 -23
- package/lib/application-package.d.ts +88 -82
- package/lib/application-package.d.ts.map +1 -1
- package/lib/application-package.js +262 -232
- package/lib/application-package.js.map +1 -1
- package/lib/application-package.spec.d.ts +1 -1
- package/lib/application-package.spec.js +57 -57
- package/lib/application-props.d.ts +172 -171
- package/lib/application-props.d.ts.map +1 -1
- package/lib/application-props.js +102 -101
- package/lib/application-props.js.map +1 -1
- package/lib/environment.d.ts +39 -39
- package/lib/environment.js +73 -73
- package/lib/extension-package-collector.d.ts +15 -15
- package/lib/extension-package-collector.js +76 -76
- package/lib/extension-package.d.ts +65 -63
- package/lib/extension-package.d.ts.map +1 -1
- package/lib/extension-package.js +176 -176
- package/lib/extension-package.js.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.js +33 -33
- package/lib/json-file.d.ts +3 -3
- package/lib/json-file.js +26 -26
- package/lib/npm-registry.d.ts +73 -73
- package/lib/npm-registry.js +101 -101
- package/package.json +5 -5
- package/src/api.ts +21 -21
- package/src/application-package.spec.ts +62 -62
- package/src/application-package.ts +334 -297
- package/src/application-props.ts +264 -263
- package/src/environment.ts +76 -76
- package/src/extension-package-collector.ts +83 -83
- package/src/extension-package.ts +223 -221
- package/src/index.ts +22 -22
- package/src/json-file.ts +25 -25
- package/src/npm-registry.ts +161 -161
|
@@ -1,297 +1,334 @@
|
|
|
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 * as paths from 'path';
|
|
18
|
-
import { readJsonFile, writeJsonFile } from './json-file';
|
|
19
|
-
import { NpmRegistry, NodePackage, PublishedNodePackage, sortByKey } from './npm-registry';
|
|
20
|
-
import { Extension, ExtensionPackage, ExtensionPackageOptions, RawExtensionPackage } from './extension-package';
|
|
21
|
-
import { ExtensionPackageCollector } from './extension-package-collector';
|
|
22
|
-
import { ApplicationProps } from './application-props';
|
|
23
|
-
import deepmerge = require('deepmerge');
|
|
24
|
-
import resolvePackagePath = require('resolve-package-path');
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
-
export type ApplicationLog = (message?: any, ...optionalParams: any[]) => void;
|
|
28
|
-
export class ApplicationPackageOptions {
|
|
29
|
-
readonly projectPath: string;
|
|
30
|
-
readonly log?: ApplicationLog;
|
|
31
|
-
readonly error?: ApplicationLog;
|
|
32
|
-
readonly registry?: NpmRegistry;
|
|
33
|
-
readonly appTarget?: ApplicationProps.Target;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type ApplicationModuleResolver = (modulePath: string) => string;
|
|
37
|
-
|
|
38
|
-
export class ApplicationPackage {
|
|
39
|
-
readonly projectPath: string;
|
|
40
|
-
readonly log: ApplicationLog;
|
|
41
|
-
readonly error: ApplicationLog;
|
|
42
|
-
|
|
43
|
-
constructor(
|
|
44
|
-
protected readonly options: ApplicationPackageOptions
|
|
45
|
-
) {
|
|
46
|
-
this.projectPath = options.projectPath;
|
|
47
|
-
this.log = options.log || console.log.bind(console);
|
|
48
|
-
this.error = options.error || console.error.bind(console);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected _registry: NpmRegistry | undefined;
|
|
52
|
-
get registry(): NpmRegistry {
|
|
53
|
-
if (this._registry) {
|
|
54
|
-
return this._registry;
|
|
55
|
-
}
|
|
56
|
-
this._registry = this.options.registry || new NpmRegistry();
|
|
57
|
-
this._registry.updateProps(this.props);
|
|
58
|
-
return this._registry;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get target(): ApplicationProps.Target {
|
|
62
|
-
return this.props.target;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
protected _props: ApplicationProps | undefined;
|
|
66
|
-
get props(): ApplicationProps {
|
|
67
|
-
if (this._props) {
|
|
68
|
-
return this._props;
|
|
69
|
-
}
|
|
70
|
-
const theia = this.pck.theia || {};
|
|
71
|
-
|
|
72
|
-
if (this.options.appTarget) {
|
|
73
|
-
theia.target = this.options.appTarget;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (theia.target && !(
|
|
77
|
-
const defaultTarget = ApplicationProps.ApplicationTarget.browser;
|
|
78
|
-
console.warn(`Unknown application target '${theia.target}', '${defaultTarget}' to be used instead`);
|
|
79
|
-
theia.target = defaultTarget;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return this._props = deepmerge(ApplicationProps.DEFAULT, theia);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
protected _pck: NodePackage | undefined;
|
|
86
|
-
get pck(): NodePackage {
|
|
87
|
-
if (this._pck) {
|
|
88
|
-
return this._pck;
|
|
89
|
-
}
|
|
90
|
-
return this._pck = readJsonFile(this.packagePath);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
protected _frontendModules: Map<string, string> | undefined;
|
|
94
|
-
protected _frontendPreloadModules: Map<string, string> | undefined;
|
|
95
|
-
protected _frontendElectronModules: Map<string, string> | undefined;
|
|
96
|
-
protected _secondaryWindowModules: Map<string, string> | undefined;
|
|
97
|
-
protected _backendModules: Map<string, string> | undefined;
|
|
98
|
-
protected _backendElectronModules: Map<string, string> | undefined;
|
|
99
|
-
protected _electronMainModules: Map<string, string> | undefined;
|
|
100
|
-
protected _preloadModules: Map<string, string> | undefined;
|
|
101
|
-
protected _extensionPackages: ReadonlyArray<ExtensionPackage> | undefined;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Extension packages in the topological order.
|
|
105
|
-
*/
|
|
106
|
-
get extensionPackages(): ReadonlyArray<ExtensionPackage> {
|
|
107
|
-
if (!this._extensionPackages) {
|
|
108
|
-
const collector = new ExtensionPackageCollector(
|
|
109
|
-
(raw: PublishedNodePackage, options: ExtensionPackageOptions = {}) => this.newExtensionPackage(raw, options),
|
|
110
|
-
this.resolveModule
|
|
111
|
-
);
|
|
112
|
-
this._extensionPackages = collector.collect(this.pck);
|
|
113
|
-
}
|
|
114
|
-
return this._extensionPackages;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
getExtensionPackage(extension: string): ExtensionPackage | undefined {
|
|
118
|
-
return this.extensionPackages.find(pck => pck.name === extension);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async findExtensionPackage(extension: string): Promise<ExtensionPackage | undefined> {
|
|
122
|
-
return this.getExtensionPackage(extension) || this.resolveExtensionPackage(extension);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Resolve an extension name to its associated package
|
|
127
|
-
* @param extension the name of the extension's package as defined in "dependencies" (might be aliased)
|
|
128
|
-
* @returns the extension package
|
|
129
|
-
*/
|
|
130
|
-
async resolveExtensionPackage(extension: string): Promise<ExtensionPackage | undefined> {
|
|
131
|
-
const raw = await RawExtensionPackage.view(this.registry, extension);
|
|
132
|
-
return raw ? this.newExtensionPackage(raw, { alias: extension }) : undefined;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
protected newExtensionPackage(raw: PublishedNodePackage, options: ExtensionPackageOptions = {}): ExtensionPackage {
|
|
136
|
-
return new ExtensionPackage(raw, this.registry, options);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
get frontendPreloadModules(): Map<string, string> {
|
|
140
|
-
return this._frontendPreloadModules ??= this.computeModules('frontendPreload');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
get
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return this.
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return this.
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
this.
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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 * as paths from 'path';
|
|
18
|
+
import { readJsonFile, writeJsonFile } from './json-file';
|
|
19
|
+
import { NpmRegistry, NodePackage, PublishedNodePackage, sortByKey } from './npm-registry';
|
|
20
|
+
import { Extension, ExtensionPackage, ExtensionPackageOptions, RawExtensionPackage } from './extension-package';
|
|
21
|
+
import { ExtensionPackageCollector } from './extension-package-collector';
|
|
22
|
+
import { ApplicationProps } from './application-props';
|
|
23
|
+
import deepmerge = require('deepmerge');
|
|
24
|
+
import resolvePackagePath = require('resolve-package-path');
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
export type ApplicationLog = (message?: any, ...optionalParams: any[]) => void;
|
|
28
|
+
export class ApplicationPackageOptions {
|
|
29
|
+
readonly projectPath: string;
|
|
30
|
+
readonly log?: ApplicationLog;
|
|
31
|
+
readonly error?: ApplicationLog;
|
|
32
|
+
readonly registry?: NpmRegistry;
|
|
33
|
+
readonly appTarget?: ApplicationProps.Target;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type ApplicationModuleResolver = (modulePath: string) => string;
|
|
37
|
+
|
|
38
|
+
export class ApplicationPackage {
|
|
39
|
+
readonly projectPath: string;
|
|
40
|
+
readonly log: ApplicationLog;
|
|
41
|
+
readonly error: ApplicationLog;
|
|
42
|
+
|
|
43
|
+
constructor(
|
|
44
|
+
protected readonly options: ApplicationPackageOptions
|
|
45
|
+
) {
|
|
46
|
+
this.projectPath = options.projectPath;
|
|
47
|
+
this.log = options.log || console.log.bind(console);
|
|
48
|
+
this.error = options.error || console.error.bind(console);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
protected _registry: NpmRegistry | undefined;
|
|
52
|
+
get registry(): NpmRegistry {
|
|
53
|
+
if (this._registry) {
|
|
54
|
+
return this._registry;
|
|
55
|
+
}
|
|
56
|
+
this._registry = this.options.registry || new NpmRegistry();
|
|
57
|
+
this._registry.updateProps(this.props);
|
|
58
|
+
return this._registry;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get target(): ApplicationProps.Target {
|
|
62
|
+
return this.props.target;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected _props: ApplicationProps | undefined;
|
|
66
|
+
get props(): ApplicationProps {
|
|
67
|
+
if (this._props) {
|
|
68
|
+
return this._props;
|
|
69
|
+
}
|
|
70
|
+
const theia = this.pck.theia || {};
|
|
71
|
+
|
|
72
|
+
if (this.options.appTarget) {
|
|
73
|
+
theia.target = this.options.appTarget;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (theia.target && !(Object.values(ApplicationProps.ApplicationTarget).includes(theia.target))) {
|
|
77
|
+
const defaultTarget = ApplicationProps.ApplicationTarget.browser;
|
|
78
|
+
console.warn(`Unknown application target '${theia.target}', '${defaultTarget}' to be used instead`);
|
|
79
|
+
theia.target = defaultTarget;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return this._props = deepmerge(ApplicationProps.DEFAULT, theia);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
protected _pck: NodePackage | undefined;
|
|
86
|
+
get pck(): NodePackage {
|
|
87
|
+
if (this._pck) {
|
|
88
|
+
return this._pck;
|
|
89
|
+
}
|
|
90
|
+
return this._pck = readJsonFile(this.packagePath);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
protected _frontendModules: Map<string, string> | undefined;
|
|
94
|
+
protected _frontendPreloadModules: Map<string, string> | undefined;
|
|
95
|
+
protected _frontendElectronModules: Map<string, string> | undefined;
|
|
96
|
+
protected _secondaryWindowModules: Map<string, string> | undefined;
|
|
97
|
+
protected _backendModules: Map<string, string> | undefined;
|
|
98
|
+
protected _backendElectronModules: Map<string, string> | undefined;
|
|
99
|
+
protected _electronMainModules: Map<string, string> | undefined;
|
|
100
|
+
protected _preloadModules: Map<string, string> | undefined;
|
|
101
|
+
protected _extensionPackages: ReadonlyArray<ExtensionPackage> | undefined;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Extension packages in the topological order.
|
|
105
|
+
*/
|
|
106
|
+
get extensionPackages(): ReadonlyArray<ExtensionPackage> {
|
|
107
|
+
if (!this._extensionPackages) {
|
|
108
|
+
const collector = new ExtensionPackageCollector(
|
|
109
|
+
(raw: PublishedNodePackage, options: ExtensionPackageOptions = {}) => this.newExtensionPackage(raw, options),
|
|
110
|
+
this.resolveModule
|
|
111
|
+
);
|
|
112
|
+
this._extensionPackages = collector.collect(this.pck);
|
|
113
|
+
}
|
|
114
|
+
return this._extensionPackages;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
getExtensionPackage(extension: string): ExtensionPackage | undefined {
|
|
118
|
+
return this.extensionPackages.find(pck => pck.name === extension);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async findExtensionPackage(extension: string): Promise<ExtensionPackage | undefined> {
|
|
122
|
+
return this.getExtensionPackage(extension) || this.resolveExtensionPackage(extension);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Resolve an extension name to its associated package
|
|
127
|
+
* @param extension the name of the extension's package as defined in "dependencies" (might be aliased)
|
|
128
|
+
* @returns the extension package
|
|
129
|
+
*/
|
|
130
|
+
async resolveExtensionPackage(extension: string): Promise<ExtensionPackage | undefined> {
|
|
131
|
+
const raw = await RawExtensionPackage.view(this.registry, extension);
|
|
132
|
+
return raw ? this.newExtensionPackage(raw, { alias: extension }) : undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
protected newExtensionPackage(raw: PublishedNodePackage, options: ExtensionPackageOptions = {}): ExtensionPackage {
|
|
136
|
+
return new ExtensionPackage(raw, this.registry, options);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
get frontendPreloadModules(): Map<string, string> {
|
|
140
|
+
return this._frontendPreloadModules ??= this.computeModules('frontendPreload');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get frontendOnlyPreloadModules(): Map<string, string> {
|
|
144
|
+
if (!this._frontendPreloadModules) {
|
|
145
|
+
this._frontendPreloadModules = this.computeModules('frontendOnlyPreload', 'frontendPreload');
|
|
146
|
+
}
|
|
147
|
+
return this._frontendPreloadModules;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get frontendModules(): Map<string, string> {
|
|
151
|
+
return this._frontendModules ??= this.computeModules('frontend');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
get frontendOnlyModules(): Map<string, string> {
|
|
155
|
+
if (!this._frontendModules) {
|
|
156
|
+
this._frontendModules = this.computeModules('frontendOnly', 'frontend');
|
|
157
|
+
}
|
|
158
|
+
return this._frontendModules;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
get frontendElectronModules(): Map<string, string> {
|
|
162
|
+
return this._frontendElectronModules ??= this.computeModules('frontendElectron', 'frontend');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
get secondaryWindowModules(): Map<string, string> {
|
|
166
|
+
return this._secondaryWindowModules ??= this.computeModules('secondaryWindow');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
get backendModules(): Map<string, string> {
|
|
170
|
+
return this._backendModules ??= this.computeModules('backend');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
get backendElectronModules(): Map<string, string> {
|
|
174
|
+
return this._backendElectronModules ??= this.computeModules('backendElectron', 'backend');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
get electronMainModules(): Map<string, string> {
|
|
178
|
+
return this._electronMainModules ??= this.computeModules('electronMain');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
get preloadModules(): Map<string, string> {
|
|
182
|
+
return this._preloadModules ??= this.computeModules('preload');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
protected computeModules<P extends keyof Extension, S extends keyof Extension = P>(primary: P, secondary?: S): Map<string, string> {
|
|
186
|
+
const result = new Map<string, string>();
|
|
187
|
+
let moduleIndex = 1;
|
|
188
|
+
for (const extensionPackage of this.extensionPackages) {
|
|
189
|
+
const extensions = extensionPackage.theiaExtensions;
|
|
190
|
+
if (extensions) {
|
|
191
|
+
for (const extension of extensions) {
|
|
192
|
+
const modulePath = extension[primary] || (secondary && extension[secondary]);
|
|
193
|
+
if (typeof modulePath === 'string') {
|
|
194
|
+
const extensionPath = paths.join(extensionPackage.name, modulePath).split(paths.sep).join('/');
|
|
195
|
+
result.set(`${primary}_${moduleIndex}`, extensionPath);
|
|
196
|
+
moduleIndex = moduleIndex + 1;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
relative(path: string): string {
|
|
205
|
+
return paths.relative(this.projectPath, path);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
path(...segments: string[]): string {
|
|
209
|
+
return paths.resolve(this.projectPath, ...segments);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
get packagePath(): string {
|
|
213
|
+
return this.path('package.json');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
lib(...segments: string[]): string {
|
|
217
|
+
return this.path('lib', ...segments);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
srcGen(...segments: string[]): string {
|
|
221
|
+
return this.path('src-gen', ...segments);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
backend(...segments: string[]): string {
|
|
225
|
+
return this.srcGen('backend', ...segments);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
bundledBackend(...segments: string[]): string {
|
|
229
|
+
return this.path('backend', 'bundle', ...segments);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
frontend(...segments: string[]): string {
|
|
233
|
+
return this.srcGen('frontend', ...segments);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
isBrowser(): boolean {
|
|
237
|
+
return this.target === ApplicationProps.ApplicationTarget.browser;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
isElectron(): boolean {
|
|
241
|
+
return this.target === ApplicationProps.ApplicationTarget.electron;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
isBrowserOnly(): boolean {
|
|
245
|
+
return this.target === ApplicationProps.ApplicationTarget.browserOnly;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
ifBrowser<T>(value: T): T | undefined;
|
|
249
|
+
ifBrowser<T>(value: T, defaultValue: T): T;
|
|
250
|
+
ifBrowser<T>(value: T, defaultValue?: T): T | undefined {
|
|
251
|
+
return this.isBrowser() ? value : defaultValue;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
ifElectron<T>(value: T): T | undefined;
|
|
255
|
+
ifElectron<T>(value: T, defaultValue: T): T;
|
|
256
|
+
ifElectron<T>(value: T, defaultValue?: T): T | undefined {
|
|
257
|
+
return this.isElectron() ? value : defaultValue;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
ifBrowserOnly<T>(value: T): T | undefined;
|
|
261
|
+
ifBrowserOnly<T>(value: T, defaultValue: T): T;
|
|
262
|
+
ifBrowserOnly<T>(value: T, defaultValue?: T): T | undefined {
|
|
263
|
+
return this.isBrowserOnly() ? value : defaultValue;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
get targetBackendModules(): Map<string, string> {
|
|
267
|
+
if (this.isBrowserOnly()) {
|
|
268
|
+
return new Map();
|
|
269
|
+
}
|
|
270
|
+
return this.ifBrowser(this.backendModules, this.backendElectronModules);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
get targetFrontendModules(): Map<string, string> {
|
|
274
|
+
if (this.isBrowserOnly()) {
|
|
275
|
+
return this.frontendOnlyModules;
|
|
276
|
+
}
|
|
277
|
+
return this.ifBrowser(this.frontendModules, this.frontendElectronModules);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
get targetFrontendPreloadModules(): Map<string, string> {
|
|
281
|
+
if (this.isBrowserOnly()) {
|
|
282
|
+
return this.frontendOnlyPreloadModules;
|
|
283
|
+
}
|
|
284
|
+
return this.frontendPreloadModules;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
get targetElectronMainModules(): Map<string, string> {
|
|
288
|
+
return this.ifElectron(this.electronMainModules, new Map());
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
setDependency(name: string, version: string | undefined): boolean {
|
|
292
|
+
const dependencies = this.pck.dependencies || {};
|
|
293
|
+
const currentVersion = dependencies[name];
|
|
294
|
+
if (currentVersion === version) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
if (version) {
|
|
298
|
+
dependencies[name] = version;
|
|
299
|
+
} else {
|
|
300
|
+
delete dependencies[name];
|
|
301
|
+
}
|
|
302
|
+
this.pck.dependencies = sortByKey(dependencies);
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
save(): Promise<void> {
|
|
307
|
+
return writeJsonFile(this.packagePath, this.pck, {
|
|
308
|
+
detectIndent: true
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
protected _moduleResolver: undefined | ApplicationModuleResolver;
|
|
313
|
+
/**
|
|
314
|
+
* A node module resolver in the context of the application package.
|
|
315
|
+
*/
|
|
316
|
+
get resolveModule(): ApplicationModuleResolver {
|
|
317
|
+
if (!this._moduleResolver) {
|
|
318
|
+
const resolutionPaths = this.packagePath || process.cwd();
|
|
319
|
+
this._moduleResolver = modulePath => {
|
|
320
|
+
const resolved = resolvePackagePath(modulePath, resolutionPaths);
|
|
321
|
+
if (!resolved) {
|
|
322
|
+
throw new Error('Could not resolve module: ' + modulePath);
|
|
323
|
+
}
|
|
324
|
+
return resolved;
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
return this._moduleResolver!;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
resolveModulePath(moduleName: string, ...segments: string[]): string {
|
|
331
|
+
return paths.resolve(this.resolveModule(moduleName + '/package.json'), '..', ...segments);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
}
|