@theia/application-package 1.47.1 → 1.48.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,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.47.1",
3
+ "version": "1.48.1",
4
4
  "description": "Theia application package API.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -29,7 +29,7 @@
29
29
  "watch": "theiaext watch"
30
30
  },
31
31
  "dependencies": {
32
- "@theia/request": "1.47.1",
32
+ "@theia/request": "1.48.1",
33
33
  "@types/fs-extra": "^4.0.2",
34
34
  "@types/semver": "^7.5.0",
35
35
  "@types/write-json-file": "^2.2.1",
@@ -43,10 +43,10 @@
43
43
  "write-json-file": "^2.2.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@theia/ext-scripts": "1.47.1"
46
+ "@theia/ext-scripts": "1.48.1"
47
47
  },
48
48
  "nyc": {
49
49
  "extends": "../../configs/nyc.json"
50
50
  },
51
- "gitHead": "ddc29054061700e54fe819f147a7ec335a6d8037"
51
+ "gitHead": "04c631933dfd14f58d1df5b9b28dd5596c84ec04"
52
52
  }
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.86.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.87.2';
@@ -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
+ });