@theia/application-package 1.45.0 → 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
@@ -1,161 +1,161 @@
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
- /* eslint-disable @typescript-eslint/no-explicit-any */
18
- import * as nano from 'nano';
19
- import { RequestContext } from '@theia/request';
20
- import { NodeRequestService } from '@theia/request/lib/node-request-service';
21
- import { NpmRegistryProps } from './application-props';
22
-
23
- export interface IChangeStream {
24
- on(event: 'data', cb: (change: { id: string }) => void): void;
25
- destroy(): void;
26
- }
27
-
28
- export interface Author {
29
- name: string;
30
- email: string;
31
- }
32
-
33
- export interface Maintainer {
34
- username: string;
35
- email: string;
36
- }
37
-
38
- export interface Dependencies {
39
- [name: string]: string | undefined;
40
- }
41
-
42
- export interface NodePackage {
43
- name?: string;
44
- version?: string;
45
- description?: string;
46
- publisher?: Maintainer;
47
- author?: string | Author;
48
- maintainers?: Maintainer[];
49
- keywords?: string[];
50
- dependencies?: Dependencies;
51
- peerDependencies?: Dependencies;
52
- [property: string]: any;
53
- }
54
-
55
- export interface PublishedNodePackage extends NodePackage {
56
- name: string;
57
- version: string;
58
- }
59
- export namespace PublishedNodePackage {
60
- export function is(pck: NodePackage | undefined): pck is PublishedNodePackage {
61
- return !!pck && !!pck.name && !!pck.version;
62
- }
63
- }
64
-
65
- export interface ViewResult {
66
- 'dist-tags': {
67
- [tag: string]: string
68
- }
69
- 'versions': {
70
- [version: string]: NodePackage
71
- },
72
- 'readme': string;
73
- [key: string]: any
74
- }
75
-
76
- export function sortByKey(object: { [key: string]: any }): {
77
- [key: string]: any;
78
- } {
79
- return Object.keys(object).sort().reduce((sorted, key) => {
80
- sorted[key] = object[key];
81
- return sorted;
82
- }, {} as { [key: string]: any });
83
- }
84
-
85
- export class NpmRegistryOptions {
86
- /**
87
- * Default: false.
88
- */
89
- readonly watchChanges: boolean;
90
- }
91
-
92
- export class NpmRegistry {
93
-
94
- readonly props: NpmRegistryProps = { ...NpmRegistryProps.DEFAULT };
95
- protected readonly options: NpmRegistryOptions;
96
-
97
- protected changes?: nano.ChangesReaderScope;
98
- protected readonly index = new Map<string, Promise<ViewResult>>();
99
-
100
- protected request: NodeRequestService;
101
-
102
- constructor(options?: Partial<NpmRegistryOptions>) {
103
- this.options = {
104
- watchChanges: false,
105
- ...options
106
- };
107
- this.resetIndex();
108
- this.request = new NodeRequestService();
109
- }
110
-
111
- updateProps(props?: Partial<NpmRegistryProps>): void {
112
- const oldRegistry = this.props.registry;
113
- Object.assign(this.props, props);
114
- const newRegistry = this.props.registry;
115
- if (oldRegistry !== newRegistry) {
116
- this.resetIndex();
117
- }
118
- }
119
- protected resetIndex(): void {
120
- this.index.clear();
121
- if (this.options.watchChanges && this.props.registry === NpmRegistryProps.DEFAULT.registry) {
122
- if (this.changes) {
123
- this.changes.stop();
124
- }
125
- // Invalidate index with NPM registry web hooks
126
- this.changes = nano('https://replicate.npmjs.com').use('registry').changesReader;
127
- this.changes.get({}).on('change', change => this.invalidate(change.id));
128
- }
129
- }
130
- protected invalidate(name: string): void {
131
- if (this.index.delete(name)) {
132
- this.view(name);
133
- }
134
- }
135
-
136
- view(name: string): Promise<ViewResult> {
137
- const indexed = this.index.get(name);
138
- if (indexed) {
139
- return indexed;
140
- }
141
- const result = this.doView(name);
142
- this.index.set(name, result);
143
- result.catch(() => this.index.delete(name));
144
- return result;
145
- }
146
-
147
- protected async doView(name: string): Promise<ViewResult> {
148
- let url = this.props.registry;
149
- if (name[0] === '@') {
150
- url += '@' + encodeURIComponent(name.substring(1));
151
- } else {
152
- url += encodeURIComponent(name);
153
- }
154
- const response = await this.request.request({ url });
155
- if (response.res.statusCode !== 200) {
156
- throw new Error(`HTTP ${response.res.statusCode}: for ${url}`);
157
- }
158
- return RequestContext.asJson<ViewResult>(response);
159
- }
160
-
161
- }
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
+ /* eslint-disable @typescript-eslint/no-explicit-any */
18
+ import * as nano from 'nano';
19
+ import { RequestContext } from '@theia/request';
20
+ import { NodeRequestService } from '@theia/request/lib/node-request-service';
21
+ import { NpmRegistryProps } from './application-props';
22
+
23
+ export interface IChangeStream {
24
+ on(event: 'data', cb: (change: { id: string }) => void): void;
25
+ destroy(): void;
26
+ }
27
+
28
+ export interface Author {
29
+ name: string;
30
+ email: string;
31
+ }
32
+
33
+ export interface Maintainer {
34
+ username: string;
35
+ email: string;
36
+ }
37
+
38
+ export interface Dependencies {
39
+ [name: string]: string | undefined;
40
+ }
41
+
42
+ export interface NodePackage {
43
+ name?: string;
44
+ version?: string;
45
+ description?: string;
46
+ publisher?: Maintainer;
47
+ author?: string | Author;
48
+ maintainers?: Maintainer[];
49
+ keywords?: string[];
50
+ dependencies?: Dependencies;
51
+ peerDependencies?: Dependencies;
52
+ [property: string]: any;
53
+ }
54
+
55
+ export interface PublishedNodePackage extends NodePackage {
56
+ name: string;
57
+ version: string;
58
+ }
59
+ export namespace PublishedNodePackage {
60
+ export function is(pck: NodePackage | undefined): pck is PublishedNodePackage {
61
+ return !!pck && !!pck.name && !!pck.version;
62
+ }
63
+ }
64
+
65
+ export interface ViewResult {
66
+ 'dist-tags': {
67
+ [tag: string]: string
68
+ }
69
+ 'versions': {
70
+ [version: string]: NodePackage
71
+ },
72
+ 'readme': string;
73
+ [key: string]: any
74
+ }
75
+
76
+ export function sortByKey(object: { [key: string]: any }): {
77
+ [key: string]: any;
78
+ } {
79
+ return Object.keys(object).sort().reduce((sorted, key) => {
80
+ sorted[key] = object[key];
81
+ return sorted;
82
+ }, {} as { [key: string]: any });
83
+ }
84
+
85
+ export class NpmRegistryOptions {
86
+ /**
87
+ * Default: false.
88
+ */
89
+ readonly watchChanges: boolean;
90
+ }
91
+
92
+ export class NpmRegistry {
93
+
94
+ readonly props: NpmRegistryProps = { ...NpmRegistryProps.DEFAULT };
95
+ protected readonly options: NpmRegistryOptions;
96
+
97
+ protected changes?: nano.ChangesReaderScope;
98
+ protected readonly index = new Map<string, Promise<ViewResult>>();
99
+
100
+ protected request: NodeRequestService;
101
+
102
+ constructor(options?: Partial<NpmRegistryOptions>) {
103
+ this.options = {
104
+ watchChanges: false,
105
+ ...options
106
+ };
107
+ this.resetIndex();
108
+ this.request = new NodeRequestService();
109
+ }
110
+
111
+ updateProps(props?: Partial<NpmRegistryProps>): void {
112
+ const oldRegistry = this.props.registry;
113
+ Object.assign(this.props, props);
114
+ const newRegistry = this.props.registry;
115
+ if (oldRegistry !== newRegistry) {
116
+ this.resetIndex();
117
+ }
118
+ }
119
+ protected resetIndex(): void {
120
+ this.index.clear();
121
+ if (this.options.watchChanges && this.props.registry === NpmRegistryProps.DEFAULT.registry) {
122
+ if (this.changes) {
123
+ this.changes.stop();
124
+ }
125
+ // Invalidate index with NPM registry web hooks
126
+ this.changes = nano('https://replicate.npmjs.com').use('registry').changesReader;
127
+ this.changes.get({}).on('change', change => this.invalidate(change.id));
128
+ }
129
+ }
130
+ protected invalidate(name: string): void {
131
+ if (this.index.delete(name)) {
132
+ this.view(name);
133
+ }
134
+ }
135
+
136
+ view(name: string): Promise<ViewResult> {
137
+ const indexed = this.index.get(name);
138
+ if (indexed) {
139
+ return indexed;
140
+ }
141
+ const result = this.doView(name);
142
+ this.index.set(name, result);
143
+ result.catch(() => this.index.delete(name));
144
+ return result;
145
+ }
146
+
147
+ protected async doView(name: string): Promise<ViewResult> {
148
+ let url = this.props.registry;
149
+ if (name[0] === '@') {
150
+ url += '@' + encodeURIComponent(name.substring(1));
151
+ } else {
152
+ url += encodeURIComponent(name);
153
+ }
154
+ const response = await this.request.request({ url });
155
+ if (response.res.statusCode !== 200) {
156
+ throw new Error(`HTTP ${response.res.statusCode}: for ${url}`);
157
+ }
158
+ return RequestContext.asJson<ViewResult>(response);
159
+ }
160
+
161
+ }