@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.
Files changed (38) hide show
  1. package/README.md +25 -25
  2. package/lib/api.d.ts +5 -5
  3. package/lib/api.js +23 -23
  4. package/lib/application-package.d.ts +88 -82
  5. package/lib/application-package.d.ts.map +1 -1
  6. package/lib/application-package.js +262 -232
  7. package/lib/application-package.js.map +1 -1
  8. package/lib/application-package.spec.d.ts +1 -1
  9. package/lib/application-package.spec.js +57 -57
  10. package/lib/application-props.d.ts +172 -171
  11. package/lib/application-props.d.ts.map +1 -1
  12. package/lib/application-props.js +102 -101
  13. package/lib/application-props.js.map +1 -1
  14. package/lib/environment.d.ts +39 -39
  15. package/lib/environment.js +73 -73
  16. package/lib/extension-package-collector.d.ts +15 -15
  17. package/lib/extension-package-collector.js +76 -76
  18. package/lib/extension-package.d.ts +65 -63
  19. package/lib/extension-package.d.ts.map +1 -1
  20. package/lib/extension-package.js +176 -176
  21. package/lib/extension-package.js.map +1 -1
  22. package/lib/index.d.ts +6 -6
  23. package/lib/index.js +33 -33
  24. package/lib/json-file.d.ts +3 -3
  25. package/lib/json-file.js +26 -26
  26. package/lib/npm-registry.d.ts +73 -73
  27. package/lib/npm-registry.js +101 -101
  28. package/package.json +5 -5
  29. package/src/api.ts +21 -21
  30. package/src/application-package.spec.ts +62 -62
  31. package/src/application-package.ts +334 -297
  32. package/src/application-props.ts +264 -263
  33. package/src/environment.ts +76 -76
  34. package/src/extension-package-collector.ts +83 -83
  35. package/src/extension-package.ts +223 -221
  36. package/src/index.ts +22 -22
  37. package/src/json-file.ts +25 -25
  38. package/src/npm-registry.ts +161 -161
package/lib/json-file.js CHANGED
@@ -1,27 +1,27 @@
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.readJsonFile = exports.writeJsonFile = void 0;
19
- const fs = require("fs");
20
- const writeJsonFile = require("write-json-file");
21
- exports.writeJsonFile = writeJsonFile;
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- function readJsonFile(path) {
24
- return JSON.parse(fs.readFileSync(path, { encoding: 'utf-8' }));
25
- }
26
- exports.readJsonFile = readJsonFile;
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.readJsonFile = exports.writeJsonFile = void 0;
19
+ const fs = require("fs");
20
+ const writeJsonFile = require("write-json-file");
21
+ exports.writeJsonFile = writeJsonFile;
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ function readJsonFile(path) {
24
+ return JSON.parse(fs.readFileSync(path, { encoding: 'utf-8' }));
25
+ }
26
+ exports.readJsonFile = readJsonFile;
27
27
  //# sourceMappingURL=json-file.js.map
@@ -1,74 +1,74 @@
1
- import * as nano from 'nano';
2
- import { NodeRequestService } from '@theia/request/lib/node-request-service';
3
- import { NpmRegistryProps } from './application-props';
4
- export interface IChangeStream {
5
- on(event: 'data', cb: (change: {
6
- id: string;
7
- }) => void): void;
8
- destroy(): void;
9
- }
10
- export interface Author {
11
- name: string;
12
- email: string;
13
- }
14
- export interface Maintainer {
15
- username: string;
16
- email: string;
17
- }
18
- export interface Dependencies {
19
- [name: string]: string | undefined;
20
- }
21
- export interface NodePackage {
22
- name?: string;
23
- version?: string;
24
- description?: string;
25
- publisher?: Maintainer;
26
- author?: string | Author;
27
- maintainers?: Maintainer[];
28
- keywords?: string[];
29
- dependencies?: Dependencies;
30
- peerDependencies?: Dependencies;
31
- [property: string]: any;
32
- }
33
- export interface PublishedNodePackage extends NodePackage {
34
- name: string;
35
- version: string;
36
- }
37
- export declare namespace PublishedNodePackage {
38
- function is(pck: NodePackage | undefined): pck is PublishedNodePackage;
39
- }
40
- export interface ViewResult {
41
- 'dist-tags': {
42
- [tag: string]: string;
43
- };
44
- 'versions': {
45
- [version: string]: NodePackage;
46
- };
47
- 'readme': string;
48
- [key: string]: any;
49
- }
50
- export declare function sortByKey(object: {
51
- [key: string]: any;
52
- }): {
53
- [key: string]: any;
54
- };
55
- export declare class NpmRegistryOptions {
56
- /**
57
- * Default: false.
58
- */
59
- readonly watchChanges: boolean;
60
- }
61
- export declare class NpmRegistry {
62
- readonly props: NpmRegistryProps;
63
- protected readonly options: NpmRegistryOptions;
64
- protected changes?: nano.ChangesReaderScope;
65
- protected readonly index: Map<string, Promise<ViewResult>>;
66
- protected request: NodeRequestService;
67
- constructor(options?: Partial<NpmRegistryOptions>);
68
- updateProps(props?: Partial<NpmRegistryProps>): void;
69
- protected resetIndex(): void;
70
- protected invalidate(name: string): void;
71
- view(name: string): Promise<ViewResult>;
72
- protected doView(name: string): Promise<ViewResult>;
73
- }
1
+ import * as nano from 'nano';
2
+ import { NodeRequestService } from '@theia/request/lib/node-request-service';
3
+ import { NpmRegistryProps } from './application-props';
4
+ export interface IChangeStream {
5
+ on(event: 'data', cb: (change: {
6
+ id: string;
7
+ }) => void): void;
8
+ destroy(): void;
9
+ }
10
+ export interface Author {
11
+ name: string;
12
+ email: string;
13
+ }
14
+ export interface Maintainer {
15
+ username: string;
16
+ email: string;
17
+ }
18
+ export interface Dependencies {
19
+ [name: string]: string | undefined;
20
+ }
21
+ export interface NodePackage {
22
+ name?: string;
23
+ version?: string;
24
+ description?: string;
25
+ publisher?: Maintainer;
26
+ author?: string | Author;
27
+ maintainers?: Maintainer[];
28
+ keywords?: string[];
29
+ dependencies?: Dependencies;
30
+ peerDependencies?: Dependencies;
31
+ [property: string]: any;
32
+ }
33
+ export interface PublishedNodePackage extends NodePackage {
34
+ name: string;
35
+ version: string;
36
+ }
37
+ export declare namespace PublishedNodePackage {
38
+ function is(pck: NodePackage | undefined): pck is PublishedNodePackage;
39
+ }
40
+ export interface ViewResult {
41
+ 'dist-tags': {
42
+ [tag: string]: string;
43
+ };
44
+ 'versions': {
45
+ [version: string]: NodePackage;
46
+ };
47
+ 'readme': string;
48
+ [key: string]: any;
49
+ }
50
+ export declare function sortByKey(object: {
51
+ [key: string]: any;
52
+ }): {
53
+ [key: string]: any;
54
+ };
55
+ export declare class NpmRegistryOptions {
56
+ /**
57
+ * Default: false.
58
+ */
59
+ readonly watchChanges: boolean;
60
+ }
61
+ export declare class NpmRegistry {
62
+ readonly props: NpmRegistryProps;
63
+ protected readonly options: NpmRegistryOptions;
64
+ protected changes?: nano.ChangesReaderScope;
65
+ protected readonly index: Map<string, Promise<ViewResult>>;
66
+ protected request: NodeRequestService;
67
+ constructor(options?: Partial<NpmRegistryOptions>);
68
+ updateProps(props?: Partial<NpmRegistryProps>): void;
69
+ protected resetIndex(): void;
70
+ protected invalidate(name: string): void;
71
+ view(name: string): Promise<ViewResult>;
72
+ protected doView(name: string): Promise<ViewResult>;
73
+ }
74
74
  //# sourceMappingURL=npm-registry.d.ts.map
@@ -1,102 +1,102 @@
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.NpmRegistry = exports.NpmRegistryOptions = exports.sortByKey = exports.PublishedNodePackage = void 0;
19
- /* eslint-disable @typescript-eslint/no-explicit-any */
20
- const nano = require("nano");
21
- const request_1 = require("@theia/request");
22
- const node_request_service_1 = require("@theia/request/lib/node-request-service");
23
- const application_props_1 = require("./application-props");
24
- var PublishedNodePackage;
25
- (function (PublishedNodePackage) {
26
- function is(pck) {
27
- return !!pck && !!pck.name && !!pck.version;
28
- }
29
- PublishedNodePackage.is = is;
30
- })(PublishedNodePackage = exports.PublishedNodePackage || (exports.PublishedNodePackage = {}));
31
- function sortByKey(object) {
32
- return Object.keys(object).sort().reduce((sorted, key) => {
33
- sorted[key] = object[key];
34
- return sorted;
35
- }, {});
36
- }
37
- exports.sortByKey = sortByKey;
38
- class NpmRegistryOptions {
39
- }
40
- exports.NpmRegistryOptions = NpmRegistryOptions;
41
- class NpmRegistry {
42
- constructor(options) {
43
- this.props = { ...application_props_1.NpmRegistryProps.DEFAULT };
44
- this.index = new Map();
45
- this.options = {
46
- watchChanges: false,
47
- ...options
48
- };
49
- this.resetIndex();
50
- this.request = new node_request_service_1.NodeRequestService();
51
- }
52
- updateProps(props) {
53
- const oldRegistry = this.props.registry;
54
- Object.assign(this.props, props);
55
- const newRegistry = this.props.registry;
56
- if (oldRegistry !== newRegistry) {
57
- this.resetIndex();
58
- }
59
- }
60
- resetIndex() {
61
- this.index.clear();
62
- if (this.options.watchChanges && this.props.registry === application_props_1.NpmRegistryProps.DEFAULT.registry) {
63
- if (this.changes) {
64
- this.changes.stop();
65
- }
66
- // Invalidate index with NPM registry web hooks
67
- this.changes = nano('https://replicate.npmjs.com').use('registry').changesReader;
68
- this.changes.get({}).on('change', change => this.invalidate(change.id));
69
- }
70
- }
71
- invalidate(name) {
72
- if (this.index.delete(name)) {
73
- this.view(name);
74
- }
75
- }
76
- view(name) {
77
- const indexed = this.index.get(name);
78
- if (indexed) {
79
- return indexed;
80
- }
81
- const result = this.doView(name);
82
- this.index.set(name, result);
83
- result.catch(() => this.index.delete(name));
84
- return result;
85
- }
86
- async doView(name) {
87
- let url = this.props.registry;
88
- if (name[0] === '@') {
89
- url += '@' + encodeURIComponent(name.substring(1));
90
- }
91
- else {
92
- url += encodeURIComponent(name);
93
- }
94
- const response = await this.request.request({ url });
95
- if (response.res.statusCode !== 200) {
96
- throw new Error(`HTTP ${response.res.statusCode}: for ${url}`);
97
- }
98
- return request_1.RequestContext.asJson(response);
99
- }
100
- }
101
- exports.NpmRegistry = NpmRegistry;
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.NpmRegistry = exports.NpmRegistryOptions = exports.sortByKey = exports.PublishedNodePackage = void 0;
19
+ /* eslint-disable @typescript-eslint/no-explicit-any */
20
+ const nano = require("nano");
21
+ const request_1 = require("@theia/request");
22
+ const node_request_service_1 = require("@theia/request/lib/node-request-service");
23
+ const application_props_1 = require("./application-props");
24
+ var PublishedNodePackage;
25
+ (function (PublishedNodePackage) {
26
+ function is(pck) {
27
+ return !!pck && !!pck.name && !!pck.version;
28
+ }
29
+ PublishedNodePackage.is = is;
30
+ })(PublishedNodePackage = exports.PublishedNodePackage || (exports.PublishedNodePackage = {}));
31
+ function sortByKey(object) {
32
+ return Object.keys(object).sort().reduce((sorted, key) => {
33
+ sorted[key] = object[key];
34
+ return sorted;
35
+ }, {});
36
+ }
37
+ exports.sortByKey = sortByKey;
38
+ class NpmRegistryOptions {
39
+ }
40
+ exports.NpmRegistryOptions = NpmRegistryOptions;
41
+ class NpmRegistry {
42
+ constructor(options) {
43
+ this.props = { ...application_props_1.NpmRegistryProps.DEFAULT };
44
+ this.index = new Map();
45
+ this.options = {
46
+ watchChanges: false,
47
+ ...options
48
+ };
49
+ this.resetIndex();
50
+ this.request = new node_request_service_1.NodeRequestService();
51
+ }
52
+ updateProps(props) {
53
+ const oldRegistry = this.props.registry;
54
+ Object.assign(this.props, props);
55
+ const newRegistry = this.props.registry;
56
+ if (oldRegistry !== newRegistry) {
57
+ this.resetIndex();
58
+ }
59
+ }
60
+ resetIndex() {
61
+ this.index.clear();
62
+ if (this.options.watchChanges && this.props.registry === application_props_1.NpmRegistryProps.DEFAULT.registry) {
63
+ if (this.changes) {
64
+ this.changes.stop();
65
+ }
66
+ // Invalidate index with NPM registry web hooks
67
+ this.changes = nano('https://replicate.npmjs.com').use('registry').changesReader;
68
+ this.changes.get({}).on('change', change => this.invalidate(change.id));
69
+ }
70
+ }
71
+ invalidate(name) {
72
+ if (this.index.delete(name)) {
73
+ this.view(name);
74
+ }
75
+ }
76
+ view(name) {
77
+ const indexed = this.index.get(name);
78
+ if (indexed) {
79
+ return indexed;
80
+ }
81
+ const result = this.doView(name);
82
+ this.index.set(name, result);
83
+ result.catch(() => this.index.delete(name));
84
+ return result;
85
+ }
86
+ async doView(name) {
87
+ let url = this.props.registry;
88
+ if (name[0] === '@') {
89
+ url += '@' + encodeURIComponent(name.substring(1));
90
+ }
91
+ else {
92
+ url += encodeURIComponent(name);
93
+ }
94
+ const response = await this.request.request({ url });
95
+ if (response.res.statusCode !== 200) {
96
+ throw new Error(`HTTP ${response.res.statusCode}: for ${url}`);
97
+ }
98
+ return request_1.RequestContext.asJson(response);
99
+ }
100
+ }
101
+ exports.NpmRegistry = NpmRegistry;
102
102
  //# sourceMappingURL=npm-registry.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theia/application-package",
3
- "version": "1.45.1",
3
+ "version": "1.46.0-next.72+4a275b29d",
4
4
  "description": "Theia application package API.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -29,23 +29,23 @@
29
29
  "watch": "theiaext watch"
30
30
  },
31
31
  "dependencies": {
32
- "@theia/request": "1.45.1",
32
+ "@theia/request": "1.46.0-next.72+4a275b29d",
33
33
  "@types/fs-extra": "^4.0.2",
34
34
  "@types/semver": "^7.5.0",
35
35
  "@types/write-json-file": "^2.2.1",
36
36
  "deepmerge": "^4.2.2",
37
37
  "fs-extra": "^4.0.2",
38
38
  "is-electron": "^2.1.0",
39
- "nano": "^9.0.5",
39
+ "nano": "^10.1.3",
40
40
  "resolve-package-path": "^4.0.3",
41
41
  "semver": "^7.5.4",
42
42
  "write-json-file": "^2.2.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@theia/ext-scripts": "1.45.1"
45
+ "@theia/ext-scripts": "1.46.0"
46
46
  },
47
47
  "nyc": {
48
48
  "extends": "../../configs/nyc.json"
49
49
  },
50
- "gitHead": "3837c50544190b80d0ad8e87aa9fa9f286c70fcc"
50
+ "gitHead": "4a275b29d0db6c81190488c7f76cb667da05ef19"
51
51
  }
package/src/api.ts CHANGED
@@ -1,21 +1,21 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 Ericsson 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
- /**
18
- * The default supported API version the framework supports.
19
- * The version should be in the format `x.y.z`.
20
- */
21
- export const DEFAULT_SUPPORTED_API_VERSION = '1.84.2';
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 Ericsson 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
+ /**
18
+ * The default supported API version the framework supports.
19
+ * The version should be in the format `x.y.z`.
20
+ */
21
+ export const DEFAULT_SUPPORTED_API_VERSION = '1.85.1';
@@ -1,62 +1,62 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2020 Maksim Ryzhikov 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 assert from 'assert';
18
- import * as temp from 'temp';
19
- import * as fs from 'fs-extra';
20
- import * as path from 'path';
21
- import { ApplicationPackage } from './application-package';
22
- import { ApplicationProps } from './application-props';
23
- import * as sinon from 'sinon';
24
-
25
- const track = temp.track();
26
- const sandbox = sinon.createSandbox();
27
-
28
- describe('application-package', function (): void {
29
- after((): void => {
30
- sandbox.restore();
31
- track.cleanupSync();
32
- });
33
-
34
- it('should print warning if user set unknown target in package.json and use browser as a default value', function (): void {
35
- const warn = sandbox.stub(console, 'warn');
36
- const root = createProjectWithTarget('foo');
37
- const applicationPackage = new ApplicationPackage({ projectPath: root });
38
- assert.deepStrictEqual(applicationPackage.target, ApplicationProps.ApplicationTarget.browser);
39
- assert.deepStrictEqual(warn.called, true);
40
- });
41
-
42
- it('should set target from package.json', function (): void {
43
- const target = 'electron';
44
- const root = createProjectWithTarget(target);
45
- const applicationPackage = new ApplicationPackage({ projectPath: root });
46
- assert.deepStrictEqual(applicationPackage.target, target);
47
- });
48
-
49
- it('should prefer target from passed options over target from package.json', function (): void {
50
- const pckTarget = 'electron';
51
- const optTarget = 'browser';
52
- const root = createProjectWithTarget(pckTarget);
53
- const applicationPackage = new ApplicationPackage({ projectPath: root, appTarget: optTarget });
54
- assert.deepStrictEqual(applicationPackage.target, optTarget);
55
- });
56
-
57
- function createProjectWithTarget(target: string): string {
58
- const root = track.mkdirSync('foo-project');
59
- fs.writeFileSync(path.join(root, 'package.json'), `{"theia": {"target": "${target}"}}`);
60
- return root;
61
- }
62
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2020 Maksim Ryzhikov 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 assert from 'assert';
18
+ import * as temp from 'temp';
19
+ import * as fs from 'fs-extra';
20
+ import * as path from 'path';
21
+ import { ApplicationPackage } from './application-package';
22
+ import { ApplicationProps } from './application-props';
23
+ import * as sinon from 'sinon';
24
+
25
+ const track = temp.track();
26
+ const sandbox = sinon.createSandbox();
27
+
28
+ describe('application-package', function (): void {
29
+ after((): void => {
30
+ sandbox.restore();
31
+ track.cleanupSync();
32
+ });
33
+
34
+ it('should print warning if user set unknown target in package.json and use browser as a default value', function (): void {
35
+ const warn = sandbox.stub(console, 'warn');
36
+ const root = createProjectWithTarget('foo');
37
+ const applicationPackage = new ApplicationPackage({ projectPath: root });
38
+ assert.deepStrictEqual(applicationPackage.target, ApplicationProps.ApplicationTarget.browser);
39
+ assert.deepStrictEqual(warn.called, true);
40
+ });
41
+
42
+ it('should set target from package.json', function (): void {
43
+ const target = 'electron';
44
+ const root = createProjectWithTarget(target);
45
+ const applicationPackage = new ApplicationPackage({ projectPath: root });
46
+ assert.deepStrictEqual(applicationPackage.target, target);
47
+ });
48
+
49
+ it('should prefer target from passed options over target from package.json', function (): void {
50
+ const pckTarget = 'electron';
51
+ const optTarget = 'browser';
52
+ const root = createProjectWithTarget(pckTarget);
53
+ const applicationPackage = new ApplicationPackage({ projectPath: root, appTarget: optTarget });
54
+ assert.deepStrictEqual(applicationPackage.target, optTarget);
55
+ });
56
+
57
+ function createProjectWithTarget(target: string): string {
58
+ const root = track.mkdirSync('foo-project');
59
+ fs.writeFileSync(path.join(root, 'package.json'), `{"theia": {"target": "${target}"}}`);
60
+ return root;
61
+ }
62
+ });