@theia/application-package 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.
@@ -1,263 +1,263 @@
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.ApplicationPackage = exports.ApplicationPackageOptions = void 0;
19
- const paths = require("path");
20
- const json_file_1 = require("./json-file");
21
- const npm_registry_1 = require("./npm-registry");
22
- const extension_package_1 = require("./extension-package");
23
- const extension_package_collector_1 = require("./extension-package-collector");
24
- const application_props_1 = require("./application-props");
25
- const deepmerge = require("deepmerge");
26
- const resolvePackagePath = require("resolve-package-path");
27
- class ApplicationPackageOptions {
28
- }
29
- exports.ApplicationPackageOptions = ApplicationPackageOptions;
30
- class ApplicationPackage {
31
- constructor(options) {
32
- this.options = options;
33
- this.projectPath = options.projectPath;
34
- this.log = options.log || console.log.bind(console);
35
- this.error = options.error || console.error.bind(console);
36
- }
37
- get registry() {
38
- if (this._registry) {
39
- return this._registry;
40
- }
41
- this._registry = this.options.registry || new npm_registry_1.NpmRegistry();
42
- this._registry.updateProps(this.props);
43
- return this._registry;
44
- }
45
- get target() {
46
- return this.props.target;
47
- }
48
- get props() {
49
- if (this._props) {
50
- return this._props;
51
- }
52
- const theia = this.pck.theia || {};
53
- if (this.options.appTarget) {
54
- theia.target = this.options.appTarget;
55
- }
56
- if (theia.target && !(Object.values(application_props_1.ApplicationProps.ApplicationTarget).includes(theia.target))) {
57
- const defaultTarget = application_props_1.ApplicationProps.ApplicationTarget.browser;
58
- console.warn(`Unknown application target '${theia.target}', '${defaultTarget}' to be used instead`);
59
- theia.target = defaultTarget;
60
- }
61
- return this._props = deepmerge(application_props_1.ApplicationProps.DEFAULT, theia);
62
- }
63
- get pck() {
64
- if (this._pck) {
65
- return this._pck;
66
- }
67
- return this._pck = (0, json_file_1.readJsonFile)(this.packagePath);
68
- }
69
- /**
70
- * Extension packages in the topological order.
71
- */
72
- get extensionPackages() {
73
- if (!this._extensionPackages) {
74
- const collector = new extension_package_collector_1.ExtensionPackageCollector((raw, options = {}) => this.newExtensionPackage(raw, options), this.resolveModule);
75
- this._extensionPackages = collector.collect(this.pck);
76
- }
77
- return this._extensionPackages;
78
- }
79
- getExtensionPackage(extension) {
80
- return this.extensionPackages.find(pck => pck.name === extension);
81
- }
82
- async findExtensionPackage(extension) {
83
- return this.getExtensionPackage(extension) || this.resolveExtensionPackage(extension);
84
- }
85
- /**
86
- * Resolve an extension name to its associated package
87
- * @param extension the name of the extension's package as defined in "dependencies" (might be aliased)
88
- * @returns the extension package
89
- */
90
- async resolveExtensionPackage(extension) {
91
- const raw = await extension_package_1.RawExtensionPackage.view(this.registry, extension);
92
- return raw ? this.newExtensionPackage(raw, { alias: extension }) : undefined;
93
- }
94
- newExtensionPackage(raw, options = {}) {
95
- return new extension_package_1.ExtensionPackage(raw, this.registry, options);
96
- }
97
- get frontendPreloadModules() {
98
- var _a;
99
- return (_a = this._frontendPreloadModules) !== null && _a !== void 0 ? _a : (this._frontendPreloadModules = this.computeModules('frontendPreload'));
100
- }
101
- get frontendOnlyPreloadModules() {
102
- if (!this._frontendPreloadModules) {
103
- this._frontendPreloadModules = this.computeModules('frontendOnlyPreload', 'frontendPreload');
104
- }
105
- return this._frontendPreloadModules;
106
- }
107
- get frontendModules() {
108
- var _a;
109
- return (_a = this._frontendModules) !== null && _a !== void 0 ? _a : (this._frontendModules = this.computeModules('frontend'));
110
- }
111
- get frontendOnlyModules() {
112
- if (!this._frontendModules) {
113
- this._frontendModules = this.computeModules('frontendOnly', 'frontend');
114
- }
115
- return this._frontendModules;
116
- }
117
- get frontendElectronModules() {
118
- var _a;
119
- return (_a = this._frontendElectronModules) !== null && _a !== void 0 ? _a : (this._frontendElectronModules = this.computeModules('frontendElectron', 'frontend'));
120
- }
121
- get secondaryWindowModules() {
122
- var _a;
123
- return (_a = this._secondaryWindowModules) !== null && _a !== void 0 ? _a : (this._secondaryWindowModules = this.computeModules('secondaryWindow'));
124
- }
125
- get backendModules() {
126
- var _a;
127
- return (_a = this._backendModules) !== null && _a !== void 0 ? _a : (this._backendModules = this.computeModules('backend'));
128
- }
129
- get backendElectronModules() {
130
- var _a;
131
- return (_a = this._backendElectronModules) !== null && _a !== void 0 ? _a : (this._backendElectronModules = this.computeModules('backendElectron', 'backend'));
132
- }
133
- get electronMainModules() {
134
- var _a;
135
- return (_a = this._electronMainModules) !== null && _a !== void 0 ? _a : (this._electronMainModules = this.computeModules('electronMain'));
136
- }
137
- get preloadModules() {
138
- var _a;
139
- return (_a = this._preloadModules) !== null && _a !== void 0 ? _a : (this._preloadModules = this.computeModules('preload'));
140
- }
141
- computeModules(primary, secondary) {
142
- const result = new Map();
143
- let moduleIndex = 1;
144
- for (const extensionPackage of this.extensionPackages) {
145
- const extensions = extensionPackage.theiaExtensions;
146
- if (extensions) {
147
- for (const extension of extensions) {
148
- const modulePath = extension[primary] || (secondary && extension[secondary]);
149
- if (typeof modulePath === 'string') {
150
- const extensionPath = paths.join(extensionPackage.name, modulePath).split(paths.sep).join('/');
151
- result.set(`${primary}_${moduleIndex}`, extensionPath);
152
- moduleIndex = moduleIndex + 1;
153
- }
154
- }
155
- }
156
- }
157
- return result;
158
- }
159
- relative(path) {
160
- return paths.relative(this.projectPath, path);
161
- }
162
- path(...segments) {
163
- return paths.resolve(this.projectPath, ...segments);
164
- }
165
- get packagePath() {
166
- return this.path('package.json');
167
- }
168
- lib(...segments) {
169
- return this.path('lib', ...segments);
170
- }
171
- srcGen(...segments) {
172
- return this.path('src-gen', ...segments);
173
- }
174
- backend(...segments) {
175
- return this.srcGen('backend', ...segments);
176
- }
177
- bundledBackend(...segments) {
178
- return this.path('backend', 'bundle', ...segments);
179
- }
180
- frontend(...segments) {
181
- return this.srcGen('frontend', ...segments);
182
- }
183
- isBrowser() {
184
- return this.target === application_props_1.ApplicationProps.ApplicationTarget.browser;
185
- }
186
- isElectron() {
187
- return this.target === application_props_1.ApplicationProps.ApplicationTarget.electron;
188
- }
189
- isBrowserOnly() {
190
- return this.target === application_props_1.ApplicationProps.ApplicationTarget.browserOnly;
191
- }
192
- ifBrowser(value, defaultValue) {
193
- return this.isBrowser() ? value : defaultValue;
194
- }
195
- ifElectron(value, defaultValue) {
196
- return this.isElectron() ? value : defaultValue;
197
- }
198
- ifBrowserOnly(value, defaultValue) {
199
- return this.isBrowserOnly() ? value : defaultValue;
200
- }
201
- get targetBackendModules() {
202
- if (this.isBrowserOnly()) {
203
- return new Map();
204
- }
205
- return this.ifBrowser(this.backendModules, this.backendElectronModules);
206
- }
207
- get targetFrontendModules() {
208
- if (this.isBrowserOnly()) {
209
- return this.frontendOnlyModules;
210
- }
211
- return this.ifBrowser(this.frontendModules, this.frontendElectronModules);
212
- }
213
- get targetFrontendPreloadModules() {
214
- if (this.isBrowserOnly()) {
215
- return this.frontendOnlyPreloadModules;
216
- }
217
- return this.frontendPreloadModules;
218
- }
219
- get targetElectronMainModules() {
220
- return this.ifElectron(this.electronMainModules, new Map());
221
- }
222
- setDependency(name, version) {
223
- const dependencies = this.pck.dependencies || {};
224
- const currentVersion = dependencies[name];
225
- if (currentVersion === version) {
226
- return false;
227
- }
228
- if (version) {
229
- dependencies[name] = version;
230
- }
231
- else {
232
- delete dependencies[name];
233
- }
234
- this.pck.dependencies = (0, npm_registry_1.sortByKey)(dependencies);
235
- return true;
236
- }
237
- save() {
238
- return (0, json_file_1.writeJsonFile)(this.packagePath, this.pck, {
239
- detectIndent: true
240
- });
241
- }
242
- /**
243
- * A node module resolver in the context of the application package.
244
- */
245
- get resolveModule() {
246
- if (!this._moduleResolver) {
247
- const resolutionPaths = this.packagePath || process.cwd();
248
- this._moduleResolver = modulePath => {
249
- const resolved = resolvePackagePath(modulePath, resolutionPaths);
250
- if (!resolved) {
251
- throw new Error('Could not resolve module: ' + modulePath);
252
- }
253
- return resolved;
254
- };
255
- }
256
- return this._moduleResolver;
257
- }
258
- resolveModulePath(moduleName, ...segments) {
259
- return paths.resolve(this.resolveModule(moduleName + '/package.json'), '..', ...segments);
260
- }
261
- }
262
- exports.ApplicationPackage = ApplicationPackage;
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.ApplicationPackage = exports.ApplicationPackageOptions = void 0;
19
+ const paths = require("path");
20
+ const json_file_1 = require("./json-file");
21
+ const npm_registry_1 = require("./npm-registry");
22
+ const extension_package_1 = require("./extension-package");
23
+ const extension_package_collector_1 = require("./extension-package-collector");
24
+ const application_props_1 = require("./application-props");
25
+ const deepmerge = require("deepmerge");
26
+ const resolvePackagePath = require("resolve-package-path");
27
+ class ApplicationPackageOptions {
28
+ }
29
+ exports.ApplicationPackageOptions = ApplicationPackageOptions;
30
+ class ApplicationPackage {
31
+ constructor(options) {
32
+ this.options = options;
33
+ this.projectPath = options.projectPath;
34
+ this.log = options.log || console.log.bind(console);
35
+ this.error = options.error || console.error.bind(console);
36
+ }
37
+ get registry() {
38
+ if (this._registry) {
39
+ return this._registry;
40
+ }
41
+ this._registry = this.options.registry || new npm_registry_1.NpmRegistry();
42
+ this._registry.updateProps(this.props);
43
+ return this._registry;
44
+ }
45
+ get target() {
46
+ return this.props.target;
47
+ }
48
+ get props() {
49
+ if (this._props) {
50
+ return this._props;
51
+ }
52
+ const theia = this.pck.theia || {};
53
+ if (this.options.appTarget) {
54
+ theia.target = this.options.appTarget;
55
+ }
56
+ if (theia.target && !(Object.values(application_props_1.ApplicationProps.ApplicationTarget).includes(theia.target))) {
57
+ const defaultTarget = application_props_1.ApplicationProps.ApplicationTarget.browser;
58
+ console.warn(`Unknown application target '${theia.target}', '${defaultTarget}' to be used instead`);
59
+ theia.target = defaultTarget;
60
+ }
61
+ return this._props = deepmerge(application_props_1.ApplicationProps.DEFAULT, theia);
62
+ }
63
+ get pck() {
64
+ if (this._pck) {
65
+ return this._pck;
66
+ }
67
+ return this._pck = (0, json_file_1.readJsonFile)(this.packagePath);
68
+ }
69
+ /**
70
+ * Extension packages in the topological order.
71
+ */
72
+ get extensionPackages() {
73
+ if (!this._extensionPackages) {
74
+ const collector = new extension_package_collector_1.ExtensionPackageCollector((raw, options = {}) => this.newExtensionPackage(raw, options), this.resolveModule);
75
+ this._extensionPackages = collector.collect(this.pck);
76
+ }
77
+ return this._extensionPackages;
78
+ }
79
+ getExtensionPackage(extension) {
80
+ return this.extensionPackages.find(pck => pck.name === extension);
81
+ }
82
+ async findExtensionPackage(extension) {
83
+ return this.getExtensionPackage(extension) || this.resolveExtensionPackage(extension);
84
+ }
85
+ /**
86
+ * Resolve an extension name to its associated package
87
+ * @param extension the name of the extension's package as defined in "dependencies" (might be aliased)
88
+ * @returns the extension package
89
+ */
90
+ async resolveExtensionPackage(extension) {
91
+ const raw = await extension_package_1.RawExtensionPackage.view(this.registry, extension);
92
+ return raw ? this.newExtensionPackage(raw, { alias: extension }) : undefined;
93
+ }
94
+ newExtensionPackage(raw, options = {}) {
95
+ return new extension_package_1.ExtensionPackage(raw, this.registry, options);
96
+ }
97
+ get frontendPreloadModules() {
98
+ var _a;
99
+ return (_a = this._frontendPreloadModules) !== null && _a !== void 0 ? _a : (this._frontendPreloadModules = this.computeModules('frontendPreload'));
100
+ }
101
+ get frontendOnlyPreloadModules() {
102
+ if (!this._frontendPreloadModules) {
103
+ this._frontendPreloadModules = this.computeModules('frontendOnlyPreload', 'frontendPreload');
104
+ }
105
+ return this._frontendPreloadModules;
106
+ }
107
+ get frontendModules() {
108
+ var _a;
109
+ return (_a = this._frontendModules) !== null && _a !== void 0 ? _a : (this._frontendModules = this.computeModules('frontend'));
110
+ }
111
+ get frontendOnlyModules() {
112
+ if (!this._frontendModules) {
113
+ this._frontendModules = this.computeModules('frontendOnly', 'frontend');
114
+ }
115
+ return this._frontendModules;
116
+ }
117
+ get frontendElectronModules() {
118
+ var _a;
119
+ return (_a = this._frontendElectronModules) !== null && _a !== void 0 ? _a : (this._frontendElectronModules = this.computeModules('frontendElectron', 'frontend'));
120
+ }
121
+ get secondaryWindowModules() {
122
+ var _a;
123
+ return (_a = this._secondaryWindowModules) !== null && _a !== void 0 ? _a : (this._secondaryWindowModules = this.computeModules('secondaryWindow'));
124
+ }
125
+ get backendModules() {
126
+ var _a;
127
+ return (_a = this._backendModules) !== null && _a !== void 0 ? _a : (this._backendModules = this.computeModules('backend'));
128
+ }
129
+ get backendElectronModules() {
130
+ var _a;
131
+ return (_a = this._backendElectronModules) !== null && _a !== void 0 ? _a : (this._backendElectronModules = this.computeModules('backendElectron', 'backend'));
132
+ }
133
+ get electronMainModules() {
134
+ var _a;
135
+ return (_a = this._electronMainModules) !== null && _a !== void 0 ? _a : (this._electronMainModules = this.computeModules('electronMain'));
136
+ }
137
+ get preloadModules() {
138
+ var _a;
139
+ return (_a = this._preloadModules) !== null && _a !== void 0 ? _a : (this._preloadModules = this.computeModules('preload'));
140
+ }
141
+ computeModules(primary, secondary) {
142
+ const result = new Map();
143
+ let moduleIndex = 1;
144
+ for (const extensionPackage of this.extensionPackages) {
145
+ const extensions = extensionPackage.theiaExtensions;
146
+ if (extensions) {
147
+ for (const extension of extensions) {
148
+ const modulePath = extension[primary] || (secondary && extension[secondary]);
149
+ if (typeof modulePath === 'string') {
150
+ const extensionPath = paths.join(extensionPackage.name, modulePath).split(paths.sep).join('/');
151
+ result.set(`${primary}_${moduleIndex}`, extensionPath);
152
+ moduleIndex = moduleIndex + 1;
153
+ }
154
+ }
155
+ }
156
+ }
157
+ return result;
158
+ }
159
+ relative(path) {
160
+ return paths.relative(this.projectPath, path);
161
+ }
162
+ path(...segments) {
163
+ return paths.resolve(this.projectPath, ...segments);
164
+ }
165
+ get packagePath() {
166
+ return this.path('package.json');
167
+ }
168
+ lib(...segments) {
169
+ return this.path('lib', ...segments);
170
+ }
171
+ srcGen(...segments) {
172
+ return this.path('src-gen', ...segments);
173
+ }
174
+ backend(...segments) {
175
+ return this.srcGen('backend', ...segments);
176
+ }
177
+ bundledBackend(...segments) {
178
+ return this.path('backend', 'bundle', ...segments);
179
+ }
180
+ frontend(...segments) {
181
+ return this.srcGen('frontend', ...segments);
182
+ }
183
+ isBrowser() {
184
+ return this.target === application_props_1.ApplicationProps.ApplicationTarget.browser;
185
+ }
186
+ isElectron() {
187
+ return this.target === application_props_1.ApplicationProps.ApplicationTarget.electron;
188
+ }
189
+ isBrowserOnly() {
190
+ return this.target === application_props_1.ApplicationProps.ApplicationTarget.browserOnly;
191
+ }
192
+ ifBrowser(value, defaultValue) {
193
+ return this.isBrowser() ? value : defaultValue;
194
+ }
195
+ ifElectron(value, defaultValue) {
196
+ return this.isElectron() ? value : defaultValue;
197
+ }
198
+ ifBrowserOnly(value, defaultValue) {
199
+ return this.isBrowserOnly() ? value : defaultValue;
200
+ }
201
+ get targetBackendModules() {
202
+ if (this.isBrowserOnly()) {
203
+ return new Map();
204
+ }
205
+ return this.ifBrowser(this.backendModules, this.backendElectronModules);
206
+ }
207
+ get targetFrontendModules() {
208
+ if (this.isBrowserOnly()) {
209
+ return this.frontendOnlyModules;
210
+ }
211
+ return this.ifBrowser(this.frontendModules, this.frontendElectronModules);
212
+ }
213
+ get targetFrontendPreloadModules() {
214
+ if (this.isBrowserOnly()) {
215
+ return this.frontendOnlyPreloadModules;
216
+ }
217
+ return this.frontendPreloadModules;
218
+ }
219
+ get targetElectronMainModules() {
220
+ return this.ifElectron(this.electronMainModules, new Map());
221
+ }
222
+ setDependency(name, version) {
223
+ const dependencies = this.pck.dependencies || {};
224
+ const currentVersion = dependencies[name];
225
+ if (currentVersion === version) {
226
+ return false;
227
+ }
228
+ if (version) {
229
+ dependencies[name] = version;
230
+ }
231
+ else {
232
+ delete dependencies[name];
233
+ }
234
+ this.pck.dependencies = (0, npm_registry_1.sortByKey)(dependencies);
235
+ return true;
236
+ }
237
+ save() {
238
+ return (0, json_file_1.writeJsonFile)(this.packagePath, this.pck, {
239
+ detectIndent: true
240
+ });
241
+ }
242
+ /**
243
+ * A node module resolver in the context of the application package.
244
+ */
245
+ get resolveModule() {
246
+ if (!this._moduleResolver) {
247
+ const resolutionPaths = this.packagePath || process.cwd();
248
+ this._moduleResolver = modulePath => {
249
+ const resolved = resolvePackagePath(modulePath, resolutionPaths);
250
+ if (!resolved) {
251
+ throw new Error('Could not resolve module: ' + modulePath);
252
+ }
253
+ return resolved;
254
+ };
255
+ }
256
+ return this._moduleResolver;
257
+ }
258
+ resolveModulePath(moduleName, ...segments) {
259
+ return paths.resolve(this.resolveModule(moduleName + '/package.json'), '..', ...segments);
260
+ }
261
+ }
262
+ exports.ApplicationPackage = ApplicationPackage;
263
263
  //# sourceMappingURL=application-package.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=application-package.spec.d.ts.map
@@ -1,58 +1,58 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2020 Maksim Ryzhikov 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
- const assert = require("assert");
19
- const temp = require("temp");
20
- const fs = require("fs-extra");
21
- const path = require("path");
22
- const application_package_1 = require("./application-package");
23
- const application_props_1 = require("./application-props");
24
- const sinon = require("sinon");
25
- const track = temp.track();
26
- const sandbox = sinon.createSandbox();
27
- describe('application-package', function () {
28
- after(() => {
29
- sandbox.restore();
30
- track.cleanupSync();
31
- });
32
- it('should print warning if user set unknown target in package.json and use browser as a default value', function () {
33
- const warn = sandbox.stub(console, 'warn');
34
- const root = createProjectWithTarget('foo');
35
- const applicationPackage = new application_package_1.ApplicationPackage({ projectPath: root });
36
- assert.deepStrictEqual(applicationPackage.target, application_props_1.ApplicationProps.ApplicationTarget.browser);
37
- assert.deepStrictEqual(warn.called, true);
38
- });
39
- it('should set target from package.json', function () {
40
- const target = 'electron';
41
- const root = createProjectWithTarget(target);
42
- const applicationPackage = new application_package_1.ApplicationPackage({ projectPath: root });
43
- assert.deepStrictEqual(applicationPackage.target, target);
44
- });
45
- it('should prefer target from passed options over target from package.json', function () {
46
- const pckTarget = 'electron';
47
- const optTarget = 'browser';
48
- const root = createProjectWithTarget(pckTarget);
49
- const applicationPackage = new application_package_1.ApplicationPackage({ projectPath: root, appTarget: optTarget });
50
- assert.deepStrictEqual(applicationPackage.target, optTarget);
51
- });
52
- function createProjectWithTarget(target) {
53
- const root = track.mkdirSync('foo-project');
54
- fs.writeFileSync(path.join(root, 'package.json'), `{"theia": {"target": "${target}"}}`);
55
- return root;
56
- }
57
- });
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2020 Maksim Ryzhikov 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
+ const assert = require("assert");
19
+ const temp = require("temp");
20
+ const fs = require("fs-extra");
21
+ const path = require("path");
22
+ const application_package_1 = require("./application-package");
23
+ const application_props_1 = require("./application-props");
24
+ const sinon = require("sinon");
25
+ const track = temp.track();
26
+ const sandbox = sinon.createSandbox();
27
+ describe('application-package', function () {
28
+ after(() => {
29
+ sandbox.restore();
30
+ track.cleanupSync();
31
+ });
32
+ it('should print warning if user set unknown target in package.json and use browser as a default value', function () {
33
+ const warn = sandbox.stub(console, 'warn');
34
+ const root = createProjectWithTarget('foo');
35
+ const applicationPackage = new application_package_1.ApplicationPackage({ projectPath: root });
36
+ assert.deepStrictEqual(applicationPackage.target, application_props_1.ApplicationProps.ApplicationTarget.browser);
37
+ assert.deepStrictEqual(warn.called, true);
38
+ });
39
+ it('should set target from package.json', function () {
40
+ const target = 'electron';
41
+ const root = createProjectWithTarget(target);
42
+ const applicationPackage = new application_package_1.ApplicationPackage({ projectPath: root });
43
+ assert.deepStrictEqual(applicationPackage.target, target);
44
+ });
45
+ it('should prefer target from passed options over target from package.json', function () {
46
+ const pckTarget = 'electron';
47
+ const optTarget = 'browser';
48
+ const root = createProjectWithTarget(pckTarget);
49
+ const applicationPackage = new application_package_1.ApplicationPackage({ projectPath: root, appTarget: optTarget });
50
+ assert.deepStrictEqual(applicationPackage.target, optTarget);
51
+ });
52
+ function createProjectWithTarget(target) {
53
+ const root = track.mkdirSync('foo-project');
54
+ fs.writeFileSync(path.join(root, 'package.json'), `{"theia": {"target": "${target}"}}`);
55
+ return root;
56
+ }
57
+ });
58
58
  //# sourceMappingURL=application-package.spec.js.map