@theia/application-package 1.53.0-next.55 → 1.53.0-next.64
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/package.json +3 -3
- package/src/api.ts +21 -21
- package/src/application-package.spec.ts +62 -62
- package/src/application-package.ts +334 -334
- package/src/application-props.ts +306 -306
- package/src/environment.ts +76 -76
- package/src/extension-package-collector.ts +83 -83
- package/src/extension-package.ts +223 -223
- package/src/index.ts +22 -22
- package/src/json-file.ts +25 -25
- package/src/npm-registry.ts +161 -161
package/src/npm-registry.ts
CHANGED
|
@@ -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
|
+
}
|