@theia/application-package 1.48.1 → 1.48.3

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,76 +1,76 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 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
- const isElectron: () => boolean = require('is-electron');
18
-
19
- /**
20
- * The electron specific environment.
21
- */
22
- class ElectronEnv {
23
-
24
- /**
25
- * Environment variable that can be accessed on the `process` to check if running in electron or not.
26
- */
27
- readonly THEIA_ELECTRON_VERSION = 'THEIA_ELECTRON_VERSION';
28
-
29
- /**
30
- * `true` if running in electron. Otherwise, `false`.
31
- *
32
- * Can be called from both the `main` and the render process. Also works for forked cluster workers.
33
- */
34
- is(): boolean {
35
- return isElectron();
36
- }
37
-
38
- /**
39
- * `true` if running in Electron in development mode. Otherwise, `false`.
40
- *
41
- * Cannot be used from the browser. From the browser, it is always `false`.
42
- */
43
- isDevMode(): boolean {
44
- return this.is()
45
- && typeof process !== 'undefined'
46
- // `defaultApp` does not exist on the Node.js API, but on electron (`electron.d.ts`).
47
- && ((process as any).defaultApp || /node_modules[/\\]electron[/\\]/.test(process.execPath)); // eslint-disable-line @typescript-eslint/no-explicit-any
48
- }
49
-
50
- /**
51
- * Creates and return with a new environment object which always contains the `ELECTRON_RUN_AS_NODE: 1` property pair.
52
- * This should be used to `spawn` and `fork` a new Node.js process from the Node.js shipped with Electron. Otherwise, a new Electron
53
- * process will be spawned which [has side-effects](https://github.com/eclipse-theia/theia/issues/5385).
54
- *
55
- * If called from the backend and the `env` argument is not defined, it falls back to `process.env` such as Node.js behaves
56
- * with the [`SpawnOptions`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).
57
- * If `env` is defined, it will be shallow-copied.
58
- *
59
- * Calling this function from the frontend does not make any sense, hence throw an error.
60
- */
61
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
- runAsNodeEnv(env?: any): any & { ELECTRON_RUN_AS_NODE: 1 } {
63
- if (typeof process === 'undefined') {
64
- throw new Error("'process' cannot be undefined.");
65
- }
66
- return {
67
- ...(env === undefined ? process.env : env),
68
- ELECTRON_RUN_AS_NODE: 1
69
- };
70
- }
71
-
72
- }
73
-
74
- const electron = new ElectronEnv();
75
- const environment: Readonly<{ electron: ElectronEnv }> = { electron };
76
- export { environment };
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 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
+ const isElectron: () => boolean = require('is-electron');
18
+
19
+ /**
20
+ * The electron specific environment.
21
+ */
22
+ class ElectronEnv {
23
+
24
+ /**
25
+ * Environment variable that can be accessed on the `process` to check if running in electron or not.
26
+ */
27
+ readonly THEIA_ELECTRON_VERSION = 'THEIA_ELECTRON_VERSION';
28
+
29
+ /**
30
+ * `true` if running in electron. Otherwise, `false`.
31
+ *
32
+ * Can be called from both the `main` and the render process. Also works for forked cluster workers.
33
+ */
34
+ is(): boolean {
35
+ return isElectron();
36
+ }
37
+
38
+ /**
39
+ * `true` if running in Electron in development mode. Otherwise, `false`.
40
+ *
41
+ * Cannot be used from the browser. From the browser, it is always `false`.
42
+ */
43
+ isDevMode(): boolean {
44
+ return this.is()
45
+ && typeof process !== 'undefined'
46
+ // `defaultApp` does not exist on the Node.js API, but on electron (`electron.d.ts`).
47
+ && ((process as any).defaultApp || /node_modules[/\\]electron[/\\]/.test(process.execPath)); // eslint-disable-line @typescript-eslint/no-explicit-any
48
+ }
49
+
50
+ /**
51
+ * Creates and return with a new environment object which always contains the `ELECTRON_RUN_AS_NODE: 1` property pair.
52
+ * This should be used to `spawn` and `fork` a new Node.js process from the Node.js shipped with Electron. Otherwise, a new Electron
53
+ * process will be spawned which [has side-effects](https://github.com/eclipse-theia/theia/issues/5385).
54
+ *
55
+ * If called from the backend and the `env` argument is not defined, it falls back to `process.env` such as Node.js behaves
56
+ * with the [`SpawnOptions`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).
57
+ * If `env` is defined, it will be shallow-copied.
58
+ *
59
+ * Calling this function from the frontend does not make any sense, hence throw an error.
60
+ */
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+ runAsNodeEnv(env?: any): any & { ELECTRON_RUN_AS_NODE: 1 } {
63
+ if (typeof process === 'undefined') {
64
+ throw new Error("'process' cannot be undefined.");
65
+ }
66
+ return {
67
+ ...(env === undefined ? process.env : env),
68
+ ELECTRON_RUN_AS_NODE: 1
69
+ };
70
+ }
71
+
72
+ }
73
+
74
+ const electron = new ElectronEnv();
75
+ const environment: Readonly<{ electron: ElectronEnv }> = { electron };
76
+ export { environment };
@@ -1,83 +1,83 @@
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
- import { readJsonFile } from './json-file';
18
- import { NodePackage, PublishedNodePackage } from './npm-registry';
19
- import { ExtensionPackage, ExtensionPackageOptions, RawExtensionPackage } from './extension-package';
20
-
21
- export class ExtensionPackageCollector {
22
-
23
- protected readonly sorted: ExtensionPackage[] = [];
24
- protected readonly visited = new Map<string, boolean>();
25
-
26
- constructor(
27
- protected readonly extensionPackageFactory: (raw: PublishedNodePackage, options?: ExtensionPackageOptions) => ExtensionPackage,
28
- protected readonly resolveModule: (modulePath: string) => string
29
- ) { }
30
-
31
- protected root: NodePackage;
32
- collect(pck: NodePackage): ReadonlyArray<ExtensionPackage> {
33
- this.root = pck;
34
- this.collectPackages(pck);
35
- return this.sorted;
36
- }
37
-
38
- protected collectPackages(pck: NodePackage): void {
39
- for (const [dependency, versionRange] of [
40
- ...Object.entries(pck.dependencies ?? {}),
41
- ...Object.entries(pck.peerDependencies ?? {})
42
- ]) {
43
- this.collectPackage(dependency, versionRange!);
44
- }
45
- }
46
-
47
- protected parent: ExtensionPackage | undefined;
48
- protected collectPackagesWithParent(pck: NodePackage, parent: ExtensionPackage): void {
49
- const current = this.parent;
50
- this.parent = parent;
51
- this.collectPackages(pck);
52
- this.parent = current;
53
- }
54
-
55
- protected collectPackage(name: string, versionRange: string): void {
56
- if (this.visited.has(name)) {
57
- return;
58
- }
59
- this.visited.set(name, true);
60
-
61
- let packagePath: string | undefined;
62
- try {
63
- packagePath = this.resolveModule(name);
64
- } catch {
65
- console.debug(`Failed to resolve module: ${name}`);
66
- }
67
- if (!packagePath) {
68
- return;
69
- }
70
- const pck: NodePackage = readJsonFile(packagePath);
71
- if (RawExtensionPackage.is(pck)) {
72
- const parent = this.parent;
73
- const version = pck.version;
74
- const transitive = !(name in this.root.dependencies!);
75
- pck.installed = { packagePath, version, parent, transitive };
76
- pck.version = versionRange;
77
- const extensionPackage = this.extensionPackageFactory(pck, { alias: name });
78
- this.collectPackagesWithParent(pck, extensionPackage);
79
- this.sorted.push(extensionPackage);
80
- }
81
- }
82
-
83
- }
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
+ import { readJsonFile } from './json-file';
18
+ import { NodePackage, PublishedNodePackage } from './npm-registry';
19
+ import { ExtensionPackage, ExtensionPackageOptions, RawExtensionPackage } from './extension-package';
20
+
21
+ export class ExtensionPackageCollector {
22
+
23
+ protected readonly sorted: ExtensionPackage[] = [];
24
+ protected readonly visited = new Map<string, boolean>();
25
+
26
+ constructor(
27
+ protected readonly extensionPackageFactory: (raw: PublishedNodePackage, options?: ExtensionPackageOptions) => ExtensionPackage,
28
+ protected readonly resolveModule: (modulePath: string) => string
29
+ ) { }
30
+
31
+ protected root: NodePackage;
32
+ collect(pck: NodePackage): ReadonlyArray<ExtensionPackage> {
33
+ this.root = pck;
34
+ this.collectPackages(pck);
35
+ return this.sorted;
36
+ }
37
+
38
+ protected collectPackages(pck: NodePackage): void {
39
+ for (const [dependency, versionRange] of [
40
+ ...Object.entries(pck.dependencies ?? {}),
41
+ ...Object.entries(pck.peerDependencies ?? {})
42
+ ]) {
43
+ this.collectPackage(dependency, versionRange!);
44
+ }
45
+ }
46
+
47
+ protected parent: ExtensionPackage | undefined;
48
+ protected collectPackagesWithParent(pck: NodePackage, parent: ExtensionPackage): void {
49
+ const current = this.parent;
50
+ this.parent = parent;
51
+ this.collectPackages(pck);
52
+ this.parent = current;
53
+ }
54
+
55
+ protected collectPackage(name: string, versionRange: string): void {
56
+ if (this.visited.has(name)) {
57
+ return;
58
+ }
59
+ this.visited.set(name, true);
60
+
61
+ let packagePath: string | undefined;
62
+ try {
63
+ packagePath = this.resolveModule(name);
64
+ } catch {
65
+ console.debug(`Failed to resolve module: ${name}`);
66
+ }
67
+ if (!packagePath) {
68
+ return;
69
+ }
70
+ const pck: NodePackage = readJsonFile(packagePath);
71
+ if (RawExtensionPackage.is(pck)) {
72
+ const parent = this.parent;
73
+ const version = pck.version;
74
+ const transitive = !(name in this.root.dependencies!);
75
+ pck.installed = { packagePath, version, parent, transitive };
76
+ pck.version = versionRange;
77
+ const extensionPackage = this.extensionPackageFactory(pck, { alias: name });
78
+ this.collectPackagesWithParent(pck, extensionPackage);
79
+ this.sorted.push(extensionPackage);
80
+ }
81
+ }
82
+
83
+ }