@matter/nodejs 0.11.4 → 0.11.5-alpha.0-20241109-2e3dccaa9
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/dist/cjs/config.d.ts +80 -0
- package/dist/cjs/config.d.ts.map +1 -0
- package/dist/cjs/config.js +164 -0
- package/dist/cjs/config.js.map +6 -0
- package/dist/cjs/environment/NodeJsEnvironment.d.ts +5 -2
- package/dist/cjs/environment/NodeJsEnvironment.d.ts.map +1 -1
- package/dist/cjs/environment/NodeJsEnvironment.js +28 -9
- package/dist/cjs/environment/NodeJsEnvironment.js.map +1 -1
- package/dist/esm/config.d.ts +80 -0
- package/dist/esm/config.d.ts.map +1 -0
- package/dist/esm/config.js +144 -0
- package/dist/esm/config.js.map +6 -0
- package/dist/esm/environment/NodeJsEnvironment.d.ts +5 -2
- package/dist/esm/environment/NodeJsEnvironment.d.ts.map +1 -1
- package/dist/esm/environment/NodeJsEnvironment.js +28 -9
- package/dist/esm/environment/NodeJsEnvironment.js.map +1 -1
- package/package.json +20 -10
- package/src/config.ts +184 -0
- package/src/environment/NodeJsEnvironment.ts +33 -10
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022-2024 Matter.js Authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export declare class NodeJsAlreadyInitializedError extends Error {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for Node.js environment bootstrap.
|
|
10
|
+
*
|
|
11
|
+
* You may modify these values but you must do it before loading any other matter.js code that triggers environment
|
|
12
|
+
* initialization. Any other import from "@matter/nodejs" or "@matter/main" triggers this initialization.
|
|
13
|
+
*
|
|
14
|
+
* Note that with (non-transpiled) ESM, imports are considered "static" so you cannot load this file with any of the
|
|
15
|
+
* imports mentioned above. The easiest way to do this is to perform configuration in a separate file:
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* import { config } from "@matter/nodejs/config";
|
|
19
|
+
*
|
|
20
|
+
* config.initializeStorage = false;
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Then ensure you import this file before any other matter.js import. This relies on ESM's deterministic load order to
|
|
24
|
+
* run the configuration logic first.
|
|
25
|
+
*
|
|
26
|
+
* If you require more dynamic configuration you will need to bootstrap your application logic using a dynamic import
|
|
27
|
+
* after configuration. This is typically unnecessary because most of matter.js is configurable via higher-level means
|
|
28
|
+
* once the environment starts.
|
|
29
|
+
*/
|
|
30
|
+
export declare const config: {
|
|
31
|
+
isInitialized: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The name of the default environment. This primarily affects the default storage path.
|
|
34
|
+
*/
|
|
35
|
+
defaultEnvironmentName: string;
|
|
36
|
+
/**
|
|
37
|
+
* The default storage path. Located in the user's home directory by default.
|
|
38
|
+
*/
|
|
39
|
+
defaultStoragePath: string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The default configuration file. Only relevant if {@link loadConfigFile} is true. If relative, resolved from
|
|
42
|
+
* {@link defaultStoragePath}.
|
|
43
|
+
*/
|
|
44
|
+
defaultConfigFilePath: string;
|
|
45
|
+
/**
|
|
46
|
+
* Enables mapping of {@link process.argv} to matter.js environment variables (default: true).
|
|
47
|
+
*/
|
|
48
|
+
loadProcessArgv: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Enables mapping of {@link process.argv} to matter.js environment variables (default: true).
|
|
51
|
+
*/
|
|
52
|
+
loadProcessEnv: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Enables loading of configuration file into matter.js environment variables (default: true).
|
|
55
|
+
*/
|
|
56
|
+
loadConfigFile: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Enables automatic initialization of storage on startup (default: true).
|
|
59
|
+
*
|
|
60
|
+
* If you disable this you must initialize environmental storage manually for components that rely on it.
|
|
61
|
+
*/
|
|
62
|
+
initializeStorage: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Enables handling of SIGINT, SIGTERM and SIGUSR2 (depending on platform; default: true).
|
|
65
|
+
*/
|
|
66
|
+
trapProcessSignals: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Enables handling of unhandled errors. This includes both uncaught exceptions and unhandled rejections.
|
|
69
|
+
*
|
|
70
|
+
* If this is enabled, the process will still terminate ungracefully but matter.js will attempt to ensure logging
|
|
71
|
+
* of full error details beforehand.
|
|
72
|
+
*/
|
|
73
|
+
trapUnhandledErrors: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Enables control of {@link process.exitCode}. If set, matter.js will set the exit code for the process when
|
|
76
|
+
* the environment terminates.
|
|
77
|
+
*/
|
|
78
|
+
setProcessExitCodeOnError: boolean;
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH,qBAAa,6BAA8B,SAAQ,KAAK;CAAG;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,MAAM;;IAOf;;OAEG;;IAUH;;OAEG;;IAUH;;;OAGG;;IAUH;;OAEG;;IAUH;;OAEG;;IAUH;;OAEG;;IAUH;;;;OAIG;;IAUH;;OAEG;;IAUH;;;;;OAKG;;IAUH;;;OAGG;;CASN,CAAC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var config_exports = {};
|
|
20
|
+
__export(config_exports, {
|
|
21
|
+
NodeJsAlreadyInitializedError: () => NodeJsAlreadyInitializedError,
|
|
22
|
+
config: () => config
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(config_exports);
|
|
25
|
+
/**
|
|
26
|
+
* @license
|
|
27
|
+
* Copyright 2022-2024 Matter.js Authors
|
|
28
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
29
|
+
*/
|
|
30
|
+
let isInitialized = false;
|
|
31
|
+
let defaultEnvironmentName = "default";
|
|
32
|
+
let defaultStoragePath = void 0;
|
|
33
|
+
let defaultConfigFilePath = "config.json";
|
|
34
|
+
let loadProcessArgv = true;
|
|
35
|
+
let loadProcessEnv = true;
|
|
36
|
+
let loadConfigFile = true;
|
|
37
|
+
let initializeStorage = true;
|
|
38
|
+
let trapProcessSignals = true;
|
|
39
|
+
let trapUnhandledErrors = true;
|
|
40
|
+
let setProcessExitCodeOnError = true;
|
|
41
|
+
class NodeJsAlreadyInitializedError extends Error {
|
|
42
|
+
}
|
|
43
|
+
const config = {
|
|
44
|
+
set isInitialized(value) {
|
|
45
|
+
if (value) {
|
|
46
|
+
isInitialized = true;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* The name of the default environment. This primarily affects the default storage path.
|
|
51
|
+
*/
|
|
52
|
+
get defaultEnvironmentName() {
|
|
53
|
+
return defaultEnvironmentName;
|
|
54
|
+
},
|
|
55
|
+
set defaultEnvironmentName(value) {
|
|
56
|
+
assertUninitialized("defaultEnvironmentName");
|
|
57
|
+
defaultEnvironmentName = value;
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* The default storage path. Located in the user's home directory by default.
|
|
61
|
+
*/
|
|
62
|
+
get defaultStoragePath() {
|
|
63
|
+
return defaultStoragePath;
|
|
64
|
+
},
|
|
65
|
+
set defaultStoragePath(value) {
|
|
66
|
+
assertUninitialized("defaultStoragePath");
|
|
67
|
+
defaultStoragePath = value;
|
|
68
|
+
},
|
|
69
|
+
/**
|
|
70
|
+
* The default configuration file. Only relevant if {@link loadConfigFile} is true. If relative, resolved from
|
|
71
|
+
* {@link defaultStoragePath}.
|
|
72
|
+
*/
|
|
73
|
+
get defaultConfigFilePath() {
|
|
74
|
+
return defaultConfigFilePath;
|
|
75
|
+
},
|
|
76
|
+
set defaultConfigFilePath(value) {
|
|
77
|
+
assertUninitialized("defaultConfigFilePath");
|
|
78
|
+
defaultConfigFilePath = value;
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Enables mapping of {@link process.argv} to matter.js environment variables (default: true).
|
|
82
|
+
*/
|
|
83
|
+
get loadProcessArgv() {
|
|
84
|
+
return loadProcessArgv;
|
|
85
|
+
},
|
|
86
|
+
set loadProcessArgv(value) {
|
|
87
|
+
assertUninitialized("parseProcessArgv");
|
|
88
|
+
loadProcessArgv = value;
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Enables mapping of {@link process.argv} to matter.js environment variables (default: true).
|
|
92
|
+
*/
|
|
93
|
+
get loadProcessEnv() {
|
|
94
|
+
return loadProcessEnv;
|
|
95
|
+
},
|
|
96
|
+
set loadProcessEnv(value) {
|
|
97
|
+
assertUninitialized("loadProcessEnv");
|
|
98
|
+
loadProcessEnv = value;
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Enables loading of configuration file into matter.js environment variables (default: true).
|
|
102
|
+
*/
|
|
103
|
+
get loadConfigFile() {
|
|
104
|
+
return loadConfigFile;
|
|
105
|
+
},
|
|
106
|
+
set loadConfigFile(value) {
|
|
107
|
+
assertUninitialized("loadConfigFile");
|
|
108
|
+
loadConfigFile = value;
|
|
109
|
+
},
|
|
110
|
+
/**
|
|
111
|
+
* Enables automatic initialization of storage on startup (default: true).
|
|
112
|
+
*
|
|
113
|
+
* If you disable this you must initialize environmental storage manually for components that rely on it.
|
|
114
|
+
*/
|
|
115
|
+
get initializeStorage() {
|
|
116
|
+
return initializeStorage;
|
|
117
|
+
},
|
|
118
|
+
set initializeStorage(value) {
|
|
119
|
+
assertUninitialized("initializeStorage");
|
|
120
|
+
initializeStorage = value;
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* Enables handling of SIGINT, SIGTERM and SIGUSR2 (depending on platform; default: true).
|
|
124
|
+
*/
|
|
125
|
+
get trapProcessSignals() {
|
|
126
|
+
return trapProcessSignals;
|
|
127
|
+
},
|
|
128
|
+
set trapProcessSignals(value) {
|
|
129
|
+
assertUninitialized("trapProcessSignals");
|
|
130
|
+
trapProcessSignals = value;
|
|
131
|
+
},
|
|
132
|
+
/**
|
|
133
|
+
* Enables handling of unhandled errors. This includes both uncaught exceptions and unhandled rejections.
|
|
134
|
+
*
|
|
135
|
+
* If this is enabled, the process will still terminate ungracefully but matter.js will attempt to ensure logging
|
|
136
|
+
* of full error details beforehand.
|
|
137
|
+
*/
|
|
138
|
+
get trapUnhandledErrors() {
|
|
139
|
+
return trapUnhandledErrors;
|
|
140
|
+
},
|
|
141
|
+
set trapUnhandledErrors(value) {
|
|
142
|
+
assertUninitialized("trapUnhandledErrors");
|
|
143
|
+
trapUnhandledErrors = value;
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* Enables control of {@link process.exitCode}. If set, matter.js will set the exit code for the process when
|
|
147
|
+
* the environment terminates.
|
|
148
|
+
*/
|
|
149
|
+
get setProcessExitCodeOnError() {
|
|
150
|
+
return setProcessExitCodeOnError;
|
|
151
|
+
},
|
|
152
|
+
set setProcessExitCodeOnError(value) {
|
|
153
|
+
assertUninitialized("setProcessExit");
|
|
154
|
+
setProcessExitCodeOnError = value;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
function assertUninitialized(name) {
|
|
158
|
+
if (isInitialized) {
|
|
159
|
+
throw new NodeJsAlreadyInitializedError(
|
|
160
|
+
`Cannot set config property "${name}" because Node.js environment is already initialized`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/config.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,IAAI,gBAAgB;AACpB,IAAI,yBAAyB;AAC7B,IAAI,qBAAyC;AAC7C,IAAI,wBAAwB;AAC5B,IAAI,kBAAkB;AACtB,IAAI,iBAAiB;AACrB,IAAI,iBAAiB;AACrB,IAAI,oBAAoB;AACxB,IAAI,qBAAqB;AACzB,IAAI,sBAAsB;AAC1B,IAAI,4BAA4B;AAEzB,MAAM,sCAAsC,MAAM;AAAC;AAwBnD,MAAM,SAAS;AAAA,EAClB,IAAI,cAAc,OAAgB;AAC9B,QAAI,OAAO;AACP,sBAAgB;AAAA,IACpB;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,yBAAyB;AACzB,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,uBAAuB,OAAe;AACtC,wBAAoB,wBAAwB;AAC5C,6BAAyB;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,qBAAqB;AACrB,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,mBAAmB,OAA2B;AAC9C,wBAAoB,oBAAoB;AACxC,yBAAqB;AAAA,EACzB;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4B;AAAA,EAChC;AACJ;AAEA,SAAS,oBAAoB,MAAc;AACvC,MAAI,eAAe;AACf,UAAM,IAAI;AAAA,MACN,+BAA+B,IAAI;AAAA,IACvC;AAAA,EACJ;AACJ;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -15,7 +15,9 @@ import { Environment, VariableService } from "#general";
|
|
|
15
15
|
*
|
|
16
16
|
* You can modify this behavior:
|
|
17
17
|
*
|
|
18
|
-
* -
|
|
18
|
+
* - Explicitly (see {@link config})
|
|
19
|
+
*
|
|
20
|
+
* - Via configuration (file, command line or system environment variables)
|
|
19
21
|
*
|
|
20
22
|
* - By modifying {@link Environment.default}
|
|
21
23
|
*
|
|
@@ -45,7 +47,7 @@ export declare function loadConfigFile(vars: VariableService): {
|
|
|
45
47
|
configVars: any;
|
|
46
48
|
};
|
|
47
49
|
export declare function getDefaults(vars: VariableService): {
|
|
48
|
-
environment:
|
|
50
|
+
environment: string;
|
|
49
51
|
path: {
|
|
50
52
|
root: string;
|
|
51
53
|
config: string;
|
|
@@ -53,6 +55,7 @@ export declare function getDefaults(vars: VariableService): {
|
|
|
53
55
|
runtime: {
|
|
54
56
|
signals: boolean;
|
|
55
57
|
exitcode: boolean;
|
|
58
|
+
unhandlederrors: boolean;
|
|
56
59
|
};
|
|
57
60
|
};
|
|
58
61
|
//# sourceMappingURL=NodeJsEnvironment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeJsEnvironment.d.ts","sourceRoot":"","sources":["../../../src/environment/NodeJsEnvironment.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"NodeJsEnvironment.d.ts","sourceRoot":"","sources":["../../../src/environment/NodeJsEnvironment.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACH,WAAW,EAMX,eAAe,EAClB,MAAM,UAAU,CAAC;AASlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,iBAAiB,gBAoBhC;AAgED,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe;;;EAsBnD;AAoBD,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe;;;;;;;;;;;EAiBhD"}
|
|
@@ -23,6 +23,7 @@ __export(NodeJsEnvironment_exports, {
|
|
|
23
23
|
loadConfigFile: () => loadConfigFile
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(NodeJsEnvironment_exports);
|
|
26
|
+
var import_config = require("#config.js");
|
|
26
27
|
var import_general = require("#general");
|
|
27
28
|
var import_fs = require("fs");
|
|
28
29
|
var import_promises = require("fs/promises");
|
|
@@ -46,17 +47,28 @@ function NodeJsEnvironment() {
|
|
|
46
47
|
env.vars.set("logger.format", import_general.LogFormat.ANSI);
|
|
47
48
|
}
|
|
48
49
|
import_NodeJsActionTracer.NodeJsActionTracer.configure(env);
|
|
50
|
+
import_config.config.isInitialized = true;
|
|
49
51
|
return env;
|
|
50
52
|
}
|
|
51
53
|
function loadVariables(env) {
|
|
52
54
|
const vars = env.vars;
|
|
53
55
|
vars.addConfigStyle(getDefaults(vars));
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
if (import_config.config.loadProcessArgv) {
|
|
57
|
+
vars.addUnixEnvStyle(process.env);
|
|
58
|
+
}
|
|
59
|
+
if (import_config.config.loadProcessEnv) {
|
|
60
|
+
vars.addArgvStyle(process.argv);
|
|
61
|
+
}
|
|
56
62
|
const { configPath, configVars } = loadConfigFile(vars);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
if (import_config.config.loadConfigFile) {
|
|
64
|
+
vars.addConfigStyle(configVars);
|
|
65
|
+
}
|
|
66
|
+
if (import_config.config.loadProcessArgv) {
|
|
67
|
+
vars.addUnixEnvStyle(process.env);
|
|
68
|
+
}
|
|
69
|
+
if (import_config.config.loadProcessEnv) {
|
|
70
|
+
vars.addArgvStyle(process.argv);
|
|
71
|
+
}
|
|
60
72
|
vars.persistConfigValue = async (name, value) => {
|
|
61
73
|
if (value === void 0) {
|
|
62
74
|
delete configVars[name];
|
|
@@ -70,6 +82,9 @@ function configureRuntime(env) {
|
|
|
70
82
|
env.set(import_ProcessManager.ProcessManager, processManager);
|
|
71
83
|
}
|
|
72
84
|
function configureStorage(env) {
|
|
85
|
+
if (!import_config.config.initializeStorage) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
73
88
|
const service = env.get(import_general.StorageService);
|
|
74
89
|
env.vars.use(() => {
|
|
75
90
|
service.location = env.vars.get("storage.path", env.vars.get("path.root", "."));
|
|
@@ -99,6 +114,9 @@ function loadConfigFile(vars) {
|
|
|
99
114
|
return { configPath, configVars };
|
|
100
115
|
}
|
|
101
116
|
function getDefaultRoot(envName) {
|
|
117
|
+
if (import_config.config.defaultStoragePath !== void 0) {
|
|
118
|
+
return import_config.config.defaultStoragePath;
|
|
119
|
+
}
|
|
102
120
|
let matterDir;
|
|
103
121
|
if (process.platform === "win32") {
|
|
104
122
|
matterDir = (0, import_path.resolve)(process.env.APPDATA ?? ".", "matter");
|
|
@@ -111,9 +129,9 @@ function getDefaultRoot(envName) {
|
|
|
111
129
|
return matterDir;
|
|
112
130
|
}
|
|
113
131
|
function getDefaults(vars) {
|
|
114
|
-
const envName = vars.get("environment",
|
|
132
|
+
const envName = vars.get("environment", import_config.config.defaultEnvironmentName);
|
|
115
133
|
const rootPath = vars.get("path.root", getDefaultRoot(envName));
|
|
116
|
-
const configPath = (0, import_path.resolve)(rootPath, vars.get("path.config",
|
|
134
|
+
const configPath = (0, import_path.resolve)(rootPath, vars.get("path.config", import_config.config.defaultConfigFilePath));
|
|
117
135
|
return {
|
|
118
136
|
environment: envName,
|
|
119
137
|
path: {
|
|
@@ -121,8 +139,9 @@ function getDefaults(vars) {
|
|
|
121
139
|
config: configPath
|
|
122
140
|
},
|
|
123
141
|
runtime: {
|
|
124
|
-
signals:
|
|
125
|
-
exitcode:
|
|
142
|
+
signals: import_config.config.trapProcessSignals,
|
|
143
|
+
exitcode: import_config.config.setProcessExitCodeOnError,
|
|
144
|
+
unhandlederrors: import_config.config.trapUnhandledErrors
|
|
126
145
|
}
|
|
127
146
|
};
|
|
128
147
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/environment/NodeJsEnvironment.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,qBAQO;AACP,gBAAyC;AACzC,sBAA0B;AAC1B,kBAAwB;AACxB,2BAA8B;AAC9B,qCAAwC;AACxC,gCAAmC;AACnC,4BAA+B;
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,oBAAuB;AACvB,qBAQO;AACP,gBAAyC;AACzC,sBAA0B;AAC1B,kBAAwB;AACxB,2BAA8B;AAC9B,qCAAwC;AACxC,gCAAmC;AACnC,4BAA+B;AAtB/B;AAAA;AAAA;AAAA;AAAA;AA6DO,SAAS,oBAAoB;AAChC,QAAM,MAAM,IAAI,2BAAY,SAAS;AAErC,gBAAc,GAAG;AACjB,mBAAiB,GAAG;AACpB,mBAAiB,GAAG;AACpB,mBAAiB,GAAG;AAKpB,MAAI,CAAC,IAAI,KAAK,IAAI,eAAe,KAAK,sBAAO,WAAW,yBAAU,SAAS,QAAQ,OAAO,OAAO;AAC7F,QAAI,KAAK,IAAI,iBAAiB,yBAAU,IAAI;AAAA,EAChD;AAEA,+CAAmB,UAAU,GAAG;AAEhC,uBAAO,gBAAgB;AAEvB,SAAO;AACX;AAEA,SAAS,cAAc,KAAkB;AACrC,QAAM,OAAO,IAAI;AAGjB,OAAK,eAAe,YAAY,IAAI,CAAC;AAGrC,MAAI,qBAAO,iBAAiB;AACxB,SAAK,gBAAgB,QAAQ,GAAG;AAAA,EACpC;AACA,MAAI,qBAAO,gBAAgB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
+
* Copyright 2022-2024 Matter.js Authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export declare class NodeJsAlreadyInitializedError extends Error {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for Node.js environment bootstrap.
|
|
10
|
+
*
|
|
11
|
+
* You may modify these values but you must do it before loading any other matter.js code that triggers environment
|
|
12
|
+
* initialization. Any other import from "@matter/nodejs" or "@matter/main" triggers this initialization.
|
|
13
|
+
*
|
|
14
|
+
* Note that with (non-transpiled) ESM, imports are considered "static" so you cannot load this file with any of the
|
|
15
|
+
* imports mentioned above. The easiest way to do this is to perform configuration in a separate file:
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* import { config } from "@matter/nodejs/config";
|
|
19
|
+
*
|
|
20
|
+
* config.initializeStorage = false;
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Then ensure you import this file before any other matter.js import. This relies on ESM's deterministic load order to
|
|
24
|
+
* run the configuration logic first.
|
|
25
|
+
*
|
|
26
|
+
* If you require more dynamic configuration you will need to bootstrap your application logic using a dynamic import
|
|
27
|
+
* after configuration. This is typically unnecessary because most of matter.js is configurable via higher-level means
|
|
28
|
+
* once the environment starts.
|
|
29
|
+
*/
|
|
30
|
+
export declare const config: {
|
|
31
|
+
isInitialized: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The name of the default environment. This primarily affects the default storage path.
|
|
34
|
+
*/
|
|
35
|
+
defaultEnvironmentName: string;
|
|
36
|
+
/**
|
|
37
|
+
* The default storage path. Located in the user's home directory by default.
|
|
38
|
+
*/
|
|
39
|
+
defaultStoragePath: string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The default configuration file. Only relevant if {@link loadConfigFile} is true. If relative, resolved from
|
|
42
|
+
* {@link defaultStoragePath}.
|
|
43
|
+
*/
|
|
44
|
+
defaultConfigFilePath: string;
|
|
45
|
+
/**
|
|
46
|
+
* Enables mapping of {@link process.argv} to matter.js environment variables (default: true).
|
|
47
|
+
*/
|
|
48
|
+
loadProcessArgv: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Enables mapping of {@link process.argv} to matter.js environment variables (default: true).
|
|
51
|
+
*/
|
|
52
|
+
loadProcessEnv: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Enables loading of configuration file into matter.js environment variables (default: true).
|
|
55
|
+
*/
|
|
56
|
+
loadConfigFile: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Enables automatic initialization of storage on startup (default: true).
|
|
59
|
+
*
|
|
60
|
+
* If you disable this you must initialize environmental storage manually for components that rely on it.
|
|
61
|
+
*/
|
|
62
|
+
initializeStorage: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Enables handling of SIGINT, SIGTERM and SIGUSR2 (depending on platform; default: true).
|
|
65
|
+
*/
|
|
66
|
+
trapProcessSignals: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Enables handling of unhandled errors. This includes both uncaught exceptions and unhandled rejections.
|
|
69
|
+
*
|
|
70
|
+
* If this is enabled, the process will still terminate ungracefully but matter.js will attempt to ensure logging
|
|
71
|
+
* of full error details beforehand.
|
|
72
|
+
*/
|
|
73
|
+
trapUnhandledErrors: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Enables control of {@link process.exitCode}. If set, matter.js will set the exit code for the process when
|
|
76
|
+
* the environment terminates.
|
|
77
|
+
*/
|
|
78
|
+
setProcessExitCodeOnError: boolean;
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH,qBAAa,6BAA8B,SAAQ,KAAK;CAAG;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,MAAM;;IAOf;;OAEG;;IAUH;;OAEG;;IAUH;;;OAGG;;IAUH;;OAEG;;IAUH;;OAEG;;IAUH;;OAEG;;IAUH;;;;OAIG;;IAUH;;OAEG;;IAUH;;;;;OAKG;;IAUH;;;OAGG;;CASN,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022-2024 Matter.js Authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
let isInitialized = false;
|
|
7
|
+
let defaultEnvironmentName = "default";
|
|
8
|
+
let defaultStoragePath = void 0;
|
|
9
|
+
let defaultConfigFilePath = "config.json";
|
|
10
|
+
let loadProcessArgv = true;
|
|
11
|
+
let loadProcessEnv = true;
|
|
12
|
+
let loadConfigFile = true;
|
|
13
|
+
let initializeStorage = true;
|
|
14
|
+
let trapProcessSignals = true;
|
|
15
|
+
let trapUnhandledErrors = true;
|
|
16
|
+
let setProcessExitCodeOnError = true;
|
|
17
|
+
class NodeJsAlreadyInitializedError extends Error {
|
|
18
|
+
}
|
|
19
|
+
const config = {
|
|
20
|
+
set isInitialized(value) {
|
|
21
|
+
if (value) {
|
|
22
|
+
isInitialized = true;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
* The name of the default environment. This primarily affects the default storage path.
|
|
27
|
+
*/
|
|
28
|
+
get defaultEnvironmentName() {
|
|
29
|
+
return defaultEnvironmentName;
|
|
30
|
+
},
|
|
31
|
+
set defaultEnvironmentName(value) {
|
|
32
|
+
assertUninitialized("defaultEnvironmentName");
|
|
33
|
+
defaultEnvironmentName = value;
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* The default storage path. Located in the user's home directory by default.
|
|
37
|
+
*/
|
|
38
|
+
get defaultStoragePath() {
|
|
39
|
+
return defaultStoragePath;
|
|
40
|
+
},
|
|
41
|
+
set defaultStoragePath(value) {
|
|
42
|
+
assertUninitialized("defaultStoragePath");
|
|
43
|
+
defaultStoragePath = value;
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* The default configuration file. Only relevant if {@link loadConfigFile} is true. If relative, resolved from
|
|
47
|
+
* {@link defaultStoragePath}.
|
|
48
|
+
*/
|
|
49
|
+
get defaultConfigFilePath() {
|
|
50
|
+
return defaultConfigFilePath;
|
|
51
|
+
},
|
|
52
|
+
set defaultConfigFilePath(value) {
|
|
53
|
+
assertUninitialized("defaultConfigFilePath");
|
|
54
|
+
defaultConfigFilePath = value;
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Enables mapping of {@link process.argv} to matter.js environment variables (default: true).
|
|
58
|
+
*/
|
|
59
|
+
get loadProcessArgv() {
|
|
60
|
+
return loadProcessArgv;
|
|
61
|
+
},
|
|
62
|
+
set loadProcessArgv(value) {
|
|
63
|
+
assertUninitialized("parseProcessArgv");
|
|
64
|
+
loadProcessArgv = value;
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Enables mapping of {@link process.argv} to matter.js environment variables (default: true).
|
|
68
|
+
*/
|
|
69
|
+
get loadProcessEnv() {
|
|
70
|
+
return loadProcessEnv;
|
|
71
|
+
},
|
|
72
|
+
set loadProcessEnv(value) {
|
|
73
|
+
assertUninitialized("loadProcessEnv");
|
|
74
|
+
loadProcessEnv = value;
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Enables loading of configuration file into matter.js environment variables (default: true).
|
|
78
|
+
*/
|
|
79
|
+
get loadConfigFile() {
|
|
80
|
+
return loadConfigFile;
|
|
81
|
+
},
|
|
82
|
+
set loadConfigFile(value) {
|
|
83
|
+
assertUninitialized("loadConfigFile");
|
|
84
|
+
loadConfigFile = value;
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Enables automatic initialization of storage on startup (default: true).
|
|
88
|
+
*
|
|
89
|
+
* If you disable this you must initialize environmental storage manually for components that rely on it.
|
|
90
|
+
*/
|
|
91
|
+
get initializeStorage() {
|
|
92
|
+
return initializeStorage;
|
|
93
|
+
},
|
|
94
|
+
set initializeStorage(value) {
|
|
95
|
+
assertUninitialized("initializeStorage");
|
|
96
|
+
initializeStorage = value;
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* Enables handling of SIGINT, SIGTERM and SIGUSR2 (depending on platform; default: true).
|
|
100
|
+
*/
|
|
101
|
+
get trapProcessSignals() {
|
|
102
|
+
return trapProcessSignals;
|
|
103
|
+
},
|
|
104
|
+
set trapProcessSignals(value) {
|
|
105
|
+
assertUninitialized("trapProcessSignals");
|
|
106
|
+
trapProcessSignals = value;
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* Enables handling of unhandled errors. This includes both uncaught exceptions and unhandled rejections.
|
|
110
|
+
*
|
|
111
|
+
* If this is enabled, the process will still terminate ungracefully but matter.js will attempt to ensure logging
|
|
112
|
+
* of full error details beforehand.
|
|
113
|
+
*/
|
|
114
|
+
get trapUnhandledErrors() {
|
|
115
|
+
return trapUnhandledErrors;
|
|
116
|
+
},
|
|
117
|
+
set trapUnhandledErrors(value) {
|
|
118
|
+
assertUninitialized("trapUnhandledErrors");
|
|
119
|
+
trapUnhandledErrors = value;
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Enables control of {@link process.exitCode}. If set, matter.js will set the exit code for the process when
|
|
123
|
+
* the environment terminates.
|
|
124
|
+
*/
|
|
125
|
+
get setProcessExitCodeOnError() {
|
|
126
|
+
return setProcessExitCodeOnError;
|
|
127
|
+
},
|
|
128
|
+
set setProcessExitCodeOnError(value) {
|
|
129
|
+
assertUninitialized("setProcessExit");
|
|
130
|
+
setProcessExitCodeOnError = value;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
function assertUninitialized(name) {
|
|
134
|
+
if (isInitialized) {
|
|
135
|
+
throw new NodeJsAlreadyInitializedError(
|
|
136
|
+
`Cannot set config property "${name}" because Node.js environment is already initialized`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export {
|
|
141
|
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A,EAKA,IAAI,iBAAiB;AACjB,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,eAAe,OAAgB;AAC/B,wBAAoB,gBAAgB;AACpC,qBAAiB;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,iBAAiB;AACjB,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,eAAe,OAAgB;AAC/B,wBAAoB,gBAAgB;AACpC,qBAAiB;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,oBAAoB;AACpB,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,kBAAkB,OAAgB;AAClC,wBAAoB,mBAAmB;AACvC,wBAAoB;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,qBAAqB;AACrB,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,mBAAmB,OAAgB;AACnC,wBAAoB,oBAAoB;AACxC,yBAAqB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAI,sBAAsB;AACtB,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,oBAAoB,OAAgB;AACpC,wBAAoB,qBAAqB;AACzC,0BAAsB;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,4BAA4B;AAC5B,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,0BAA0B,OAAgB;AAC1C,wBAAoB,gBAAgB;AACpC,gCAA4B;AAAA,EAChC;AACJ;AAEA,SAAS,oBAAoB,MAAc;AACvC,MAAI,eAAe;AACf,UAAM,IAAI;AAAA,MACN,+BAA+B,IAAI;AAAA,IACvC;AAAA,EACJ;AACJ;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -15,7 +15,9 @@ import { Environment, VariableService } from "#general";
|
|
|
15
15
|
*
|
|
16
16
|
* You can modify this behavior:
|
|
17
17
|
*
|
|
18
|
-
* -
|
|
18
|
+
* - Explicitly (see {@link config})
|
|
19
|
+
*
|
|
20
|
+
* - Via configuration (file, command line or system environment variables)
|
|
19
21
|
*
|
|
20
22
|
* - By modifying {@link Environment.default}
|
|
21
23
|
*
|
|
@@ -45,7 +47,7 @@ export declare function loadConfigFile(vars: VariableService): {
|
|
|
45
47
|
configVars: any;
|
|
46
48
|
};
|
|
47
49
|
export declare function getDefaults(vars: VariableService): {
|
|
48
|
-
environment:
|
|
50
|
+
environment: string;
|
|
49
51
|
path: {
|
|
50
52
|
root: string;
|
|
51
53
|
config: string;
|
|
@@ -53,6 +55,7 @@ export declare function getDefaults(vars: VariableService): {
|
|
|
53
55
|
runtime: {
|
|
54
56
|
signals: boolean;
|
|
55
57
|
exitcode: boolean;
|
|
58
|
+
unhandlederrors: boolean;
|
|
56
59
|
};
|
|
57
60
|
};
|
|
58
61
|
//# sourceMappingURL=NodeJsEnvironment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeJsEnvironment.d.ts","sourceRoot":"","sources":["../../../src/environment/NodeJsEnvironment.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"NodeJsEnvironment.d.ts","sourceRoot":"","sources":["../../../src/environment/NodeJsEnvironment.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACH,WAAW,EAMX,eAAe,EAClB,MAAM,UAAU,CAAC;AASlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,iBAAiB,gBAoBhC;AAgED,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe;;;EAsBnD;AAoBD,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe;;;;;;;;;;;EAiBhD"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2022-2024 Matter.js Authors
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { config } from "#config.js";
|
|
6
7
|
import {
|
|
7
8
|
Environment,
|
|
8
9
|
ImplementationError,
|
|
@@ -28,17 +29,28 @@ function NodeJsEnvironment() {
|
|
|
28
29
|
env.vars.set("logger.format", LogFormat.ANSI);
|
|
29
30
|
}
|
|
30
31
|
NodeJsActionTracer.configure(env);
|
|
32
|
+
config.isInitialized = true;
|
|
31
33
|
return env;
|
|
32
34
|
}
|
|
33
35
|
function loadVariables(env) {
|
|
34
36
|
const vars = env.vars;
|
|
35
37
|
vars.addConfigStyle(getDefaults(vars));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
if (config.loadProcessArgv) {
|
|
39
|
+
vars.addUnixEnvStyle(process.env);
|
|
40
|
+
}
|
|
41
|
+
if (config.loadProcessEnv) {
|
|
42
|
+
vars.addArgvStyle(process.argv);
|
|
43
|
+
}
|
|
38
44
|
const { configPath, configVars } = loadConfigFile(vars);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
if (config.loadConfigFile) {
|
|
46
|
+
vars.addConfigStyle(configVars);
|
|
47
|
+
}
|
|
48
|
+
if (config.loadProcessArgv) {
|
|
49
|
+
vars.addUnixEnvStyle(process.env);
|
|
50
|
+
}
|
|
51
|
+
if (config.loadProcessEnv) {
|
|
52
|
+
vars.addArgvStyle(process.argv);
|
|
53
|
+
}
|
|
42
54
|
vars.persistConfigValue = async (name, value) => {
|
|
43
55
|
if (value === void 0) {
|
|
44
56
|
delete configVars[name];
|
|
@@ -52,6 +64,9 @@ function configureRuntime(env) {
|
|
|
52
64
|
env.set(ProcessManager, processManager);
|
|
53
65
|
}
|
|
54
66
|
function configureStorage(env) {
|
|
67
|
+
if (!config.initializeStorage) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
55
70
|
const service = env.get(StorageService);
|
|
56
71
|
env.vars.use(() => {
|
|
57
72
|
service.location = env.vars.get("storage.path", env.vars.get("path.root", "."));
|
|
@@ -81,6 +96,9 @@ function loadConfigFile(vars) {
|
|
|
81
96
|
return { configPath, configVars };
|
|
82
97
|
}
|
|
83
98
|
function getDefaultRoot(envName) {
|
|
99
|
+
if (config.defaultStoragePath !== void 0) {
|
|
100
|
+
return config.defaultStoragePath;
|
|
101
|
+
}
|
|
84
102
|
let matterDir;
|
|
85
103
|
if (process.platform === "win32") {
|
|
86
104
|
matterDir = resolve(process.env.APPDATA ?? ".", "matter");
|
|
@@ -93,9 +111,9 @@ function getDefaultRoot(envName) {
|
|
|
93
111
|
return matterDir;
|
|
94
112
|
}
|
|
95
113
|
function getDefaults(vars) {
|
|
96
|
-
const envName = vars.get("environment",
|
|
114
|
+
const envName = vars.get("environment", config.defaultEnvironmentName);
|
|
97
115
|
const rootPath = vars.get("path.root", getDefaultRoot(envName));
|
|
98
|
-
const configPath = resolve(rootPath, vars.get("path.config",
|
|
116
|
+
const configPath = resolve(rootPath, vars.get("path.config", config.defaultConfigFilePath));
|
|
99
117
|
return {
|
|
100
118
|
environment: envName,
|
|
101
119
|
path: {
|
|
@@ -103,8 +121,9 @@ function getDefaults(vars) {
|
|
|
103
121
|
config: configPath
|
|
104
122
|
},
|
|
105
123
|
runtime: {
|
|
106
|
-
signals:
|
|
107
|
-
exitcode:
|
|
124
|
+
signals: config.trapProcessSignals,
|
|
125
|
+
exitcode: config.setProcessExitCodeOnError,
|
|
126
|
+
unhandlederrors: config.trapUnhandledErrors
|
|
108
127
|
}
|
|
109
128
|
};
|
|
110
129
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/environment/NodeJsEnvironment.ts"],
|
|
4
|
-
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEG;AACP,SAAS,YAAY,oBAAoB;AACzC,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;AACxC,SAAS,0BAA0B;AACnC,SAAS,sBAA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,WAAO,OAAO;AAAA,EAClB;AACA,MAAI;AACJ,MAAI,QAAQ,aAAa,SAAS;AAC9B,gBAAY,QAAQ,QAAQ,IAAI,WAAW,KAAK,QAAQ;AAAA,EAC5D,OAAO;AACH,gBAAY,QAAQ,QAAQ,IAAI,QAAQ,KAAK,SAAS;AAAA,EAC1D;AAEA,MAAI,YAAY,WAAW;AACvB,gBAAY,GAAG,SAAS,IAAI,OAAO;AAAA,EACvC;AAEA,SAAO;AACX;AAEO,SAAS,YAAY,MAAuB;AAC/C,QAAM,UAAU,KAAK,IAAI,eAAe,OAAO,sBAAsB;AACrE,QAAM,WAAW,KAAK,IAAI,aAAa,eAAe,OAAO,CAAC;AAC9D,QAAM,aAAa,QAAQ,UAAU,KAAK,IAAI,eAAe,OAAO,qBAAqB,CAAC;AAE1F,SAAO;AAAA,IACH,aAAa;AAAA,IACb,MAAM;AAAA,MACF,MAAM;AAAA,MACN,QAAQ;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACL,SAAS,OAAO;AAAA,MAChB,UAAU,OAAO;AAAA,MACjB,iBAAiB,OAAO;AAAA,IAC5B;AAAA,EACJ;AACJ;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matter/nodejs",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5-alpha.0-20241109-2e3dccaa9",
|
|
4
4
|
"description": "Node.js platform support for matter.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"iot",
|
|
@@ -44,18 +44,18 @@
|
|
|
44
44
|
"#*": "./src/*"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@matter/general": "0.11.
|
|
48
|
-
"@matter/node": "0.11.
|
|
49
|
-
"@matter/protocol": "0.11.
|
|
50
|
-
"@matter/types": "0.11.
|
|
47
|
+
"@matter/general": "0.11.5-alpha.0-20241109-2e3dccaa9",
|
|
48
|
+
"@matter/node": "0.11.5-alpha.0-20241109-2e3dccaa9",
|
|
49
|
+
"@matter/protocol": "0.11.5-alpha.0-20241109-2e3dccaa9",
|
|
50
|
+
"@matter/types": "0.11.5-alpha.0-20241109-2e3dccaa9",
|
|
51
51
|
"node-localstorage": "^3.0.5"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@matter/model": "0.11.
|
|
55
|
-
"@matter/protocol": "0.11.
|
|
56
|
-
"@matter/tools": "0.11.
|
|
57
|
-
"@matter/testing": "0.11.
|
|
58
|
-
"@project-chip/matter.js": "0.11.
|
|
54
|
+
"@matter/model": "0.11.5-alpha.0-20241109-2e3dccaa9",
|
|
55
|
+
"@matter/protocol": "0.11.5-alpha.0-20241109-2e3dccaa9",
|
|
56
|
+
"@matter/tools": "0.11.5-alpha.0-20241109-2e3dccaa9",
|
|
57
|
+
"@matter/testing": "0.11.5-alpha.0-20241109-2e3dccaa9",
|
|
58
|
+
"@project-chip/matter.js": "0.11.5-alpha.0-20241109-2e3dccaa9",
|
|
59
59
|
"@types/bytebuffer": "^5.0.49",
|
|
60
60
|
"@types/node-localstorage": "^1.3.3"
|
|
61
61
|
},
|
|
@@ -78,6 +78,16 @@
|
|
|
78
78
|
"types": "./dist/cjs/index.d.ts",
|
|
79
79
|
"default": "./dist/cjs/index.js"
|
|
80
80
|
}
|
|
81
|
+
},
|
|
82
|
+
"./config": {
|
|
83
|
+
"import": {
|
|
84
|
+
"types": "./dist/esm/config.d.ts",
|
|
85
|
+
"default": "./dist/esm/config.js"
|
|
86
|
+
},
|
|
87
|
+
"require": {
|
|
88
|
+
"types": "./dist/cjs/config.d.ts",
|
|
89
|
+
"default": "./dist/cjs/config.js"
|
|
90
|
+
}
|
|
81
91
|
}
|
|
82
92
|
},
|
|
83
93
|
"types": "dist/esm/index.d.ts",
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022-2024 Matter.js Authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
let isInitialized = false;
|
|
8
|
+
let defaultEnvironmentName = "default";
|
|
9
|
+
let defaultStoragePath: string | undefined = undefined;
|
|
10
|
+
let defaultConfigFilePath = "config.json";
|
|
11
|
+
let loadProcessArgv = true;
|
|
12
|
+
let loadProcessEnv = true;
|
|
13
|
+
let loadConfigFile = true;
|
|
14
|
+
let initializeStorage = true;
|
|
15
|
+
let trapProcessSignals = true;
|
|
16
|
+
let trapUnhandledErrors = true;
|
|
17
|
+
let setProcessExitCodeOnError = true;
|
|
18
|
+
|
|
19
|
+
export class NodeJsAlreadyInitializedError extends Error {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for Node.js environment bootstrap.
|
|
23
|
+
*
|
|
24
|
+
* You may modify these values but you must do it before loading any other matter.js code that triggers environment
|
|
25
|
+
* initialization. Any other import from "@matter/nodejs" or "@matter/main" triggers this initialization.
|
|
26
|
+
*
|
|
27
|
+
* Note that with (non-transpiled) ESM, imports are considered "static" so you cannot load this file with any of the
|
|
28
|
+
* imports mentioned above. The easiest way to do this is to perform configuration in a separate file:
|
|
29
|
+
*
|
|
30
|
+
* ```
|
|
31
|
+
* import { config } from "@matter/nodejs/config";
|
|
32
|
+
*
|
|
33
|
+
* config.initializeStorage = false;
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Then ensure you import this file before any other matter.js import. This relies on ESM's deterministic load order to
|
|
37
|
+
* run the configuration logic first.
|
|
38
|
+
*
|
|
39
|
+
* If you require more dynamic configuration you will need to bootstrap your application logic using a dynamic import
|
|
40
|
+
* after configuration. This is typically unnecessary because most of matter.js is configurable via higher-level means
|
|
41
|
+
* once the environment starts.
|
|
42
|
+
*/
|
|
43
|
+
export const config = {
|
|
44
|
+
set isInitialized(value: boolean) {
|
|
45
|
+
if (value) {
|
|
46
|
+
isInitialized = true;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The name of the default environment. This primarily affects the default storage path.
|
|
52
|
+
*/
|
|
53
|
+
get defaultEnvironmentName() {
|
|
54
|
+
return defaultEnvironmentName;
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
set defaultEnvironmentName(value: string) {
|
|
58
|
+
assertUninitialized("defaultEnvironmentName");
|
|
59
|
+
defaultEnvironmentName = value;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The default storage path. Located in the user's home directory by default.
|
|
64
|
+
*/
|
|
65
|
+
get defaultStoragePath() {
|
|
66
|
+
return defaultStoragePath;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
set defaultStoragePath(value: string | undefined) {
|
|
70
|
+
assertUninitialized("defaultStoragePath");
|
|
71
|
+
defaultStoragePath = value;
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The default configuration file. Only relevant if {@link loadConfigFile} is true. If relative, resolved from
|
|
76
|
+
* {@link defaultStoragePath}.
|
|
77
|
+
*/
|
|
78
|
+
get defaultConfigFilePath() {
|
|
79
|
+
return defaultConfigFilePath;
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
set defaultConfigFilePath(value: string) {
|
|
83
|
+
assertUninitialized("defaultConfigFilePath");
|
|
84
|
+
defaultConfigFilePath = value;
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Enables mapping of {@link process.argv} to matter.js environment variables (default: true).
|
|
89
|
+
*/
|
|
90
|
+
get loadProcessArgv() {
|
|
91
|
+
return loadProcessArgv;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
set loadProcessArgv(value: boolean) {
|
|
95
|
+
assertUninitialized("parseProcessArgv");
|
|
96
|
+
loadProcessArgv = value;
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Enables mapping of {@link process.argv} to matter.js environment variables (default: true).
|
|
101
|
+
*/
|
|
102
|
+
get loadProcessEnv() {
|
|
103
|
+
return loadProcessEnv;
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
set loadProcessEnv(value: boolean) {
|
|
107
|
+
assertUninitialized("loadProcessEnv");
|
|
108
|
+
loadProcessEnv = value;
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Enables loading of configuration file into matter.js environment variables (default: true).
|
|
113
|
+
*/
|
|
114
|
+
get loadConfigFile() {
|
|
115
|
+
return loadConfigFile;
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
set loadConfigFile(value: boolean) {
|
|
119
|
+
assertUninitialized("loadConfigFile");
|
|
120
|
+
loadConfigFile = value;
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Enables automatic initialization of storage on startup (default: true).
|
|
125
|
+
*
|
|
126
|
+
* If you disable this you must initialize environmental storage manually for components that rely on it.
|
|
127
|
+
*/
|
|
128
|
+
get initializeStorage() {
|
|
129
|
+
return initializeStorage;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
set initializeStorage(value: boolean) {
|
|
133
|
+
assertUninitialized("initializeStorage");
|
|
134
|
+
initializeStorage = value;
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Enables handling of SIGINT, SIGTERM and SIGUSR2 (depending on platform; default: true).
|
|
139
|
+
*/
|
|
140
|
+
get trapProcessSignals() {
|
|
141
|
+
return trapProcessSignals;
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
set trapProcessSignals(value: boolean) {
|
|
145
|
+
assertUninitialized("trapProcessSignals");
|
|
146
|
+
trapProcessSignals = value;
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Enables handling of unhandled errors. This includes both uncaught exceptions and unhandled rejections.
|
|
151
|
+
*
|
|
152
|
+
* If this is enabled, the process will still terminate ungracefully but matter.js will attempt to ensure logging
|
|
153
|
+
* of full error details beforehand.
|
|
154
|
+
*/
|
|
155
|
+
get trapUnhandledErrors() {
|
|
156
|
+
return trapUnhandledErrors;
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
set trapUnhandledErrors(value: boolean) {
|
|
160
|
+
assertUninitialized("trapUnhandledErrors");
|
|
161
|
+
trapUnhandledErrors = value;
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Enables control of {@link process.exitCode}. If set, matter.js will set the exit code for the process when
|
|
166
|
+
* the environment terminates.
|
|
167
|
+
*/
|
|
168
|
+
get setProcessExitCodeOnError() {
|
|
169
|
+
return setProcessExitCodeOnError;
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
set setProcessExitCodeOnError(value: boolean) {
|
|
173
|
+
assertUninitialized("setProcessExit");
|
|
174
|
+
setProcessExitCodeOnError = value;
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
function assertUninitialized(name: string) {
|
|
179
|
+
if (isInitialized) {
|
|
180
|
+
throw new NodeJsAlreadyInitializedError(
|
|
181
|
+
`Cannot set config property "${name}" because Node.js environment is already initialized`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { config } from "#config.js";
|
|
7
8
|
import {
|
|
8
9
|
Environment,
|
|
9
10
|
ImplementationError,
|
|
@@ -32,7 +33,9 @@ import { ProcessManager } from "./ProcessManager.js";
|
|
|
32
33
|
*
|
|
33
34
|
* You can modify this behavior:
|
|
34
35
|
*
|
|
35
|
-
* -
|
|
36
|
+
* - Explicitly (see {@link config})
|
|
37
|
+
*
|
|
38
|
+
* - Via configuration (file, command line or system environment variables)
|
|
36
39
|
*
|
|
37
40
|
* - By modifying {@link Environment.default}
|
|
38
41
|
*
|
|
@@ -73,6 +76,8 @@ export function NodeJsEnvironment() {
|
|
|
73
76
|
|
|
74
77
|
NodeJsActionTracer.configure(env);
|
|
75
78
|
|
|
79
|
+
config.isInitialized = true;
|
|
80
|
+
|
|
76
81
|
return env;
|
|
77
82
|
}
|
|
78
83
|
|
|
@@ -83,16 +88,26 @@ function loadVariables(env: Environment) {
|
|
|
83
88
|
vars.addConfigStyle(getDefaults(vars));
|
|
84
89
|
|
|
85
90
|
// Preload environment and argv so we can use it to find config file
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
if (config.loadProcessArgv) {
|
|
92
|
+
vars.addUnixEnvStyle(process.env);
|
|
93
|
+
}
|
|
94
|
+
if (config.loadProcessEnv) {
|
|
95
|
+
vars.addArgvStyle(process.argv);
|
|
96
|
+
}
|
|
88
97
|
|
|
89
98
|
// Load config files
|
|
90
99
|
const { configPath, configVars } = loadConfigFile(vars);
|
|
91
|
-
|
|
100
|
+
if (config.loadConfigFile) {
|
|
101
|
+
vars.addConfigStyle(configVars);
|
|
102
|
+
}
|
|
92
103
|
|
|
93
104
|
// Reload environment and argv so they override config
|
|
94
|
-
|
|
95
|
-
|
|
105
|
+
if (config.loadProcessArgv) {
|
|
106
|
+
vars.addUnixEnvStyle(process.env);
|
|
107
|
+
}
|
|
108
|
+
if (config.loadProcessEnv) {
|
|
109
|
+
vars.addArgvStyle(process.argv);
|
|
110
|
+
}
|
|
96
111
|
|
|
97
112
|
// Enable persistent configuration values
|
|
98
113
|
vars.persistConfigValue = async (name: string, value: VariableService.Value) => {
|
|
@@ -110,6 +125,10 @@ function configureRuntime(env: Environment) {
|
|
|
110
125
|
}
|
|
111
126
|
|
|
112
127
|
function configureStorage(env: Environment) {
|
|
128
|
+
if (!config.initializeStorage) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
113
132
|
const service = env.get(StorageService);
|
|
114
133
|
|
|
115
134
|
env.vars.use(() => {
|
|
@@ -149,6 +168,9 @@ export function loadConfigFile(vars: VariableService) {
|
|
|
149
168
|
}
|
|
150
169
|
|
|
151
170
|
function getDefaultRoot(envName: string) {
|
|
171
|
+
if (config.defaultStoragePath !== undefined) {
|
|
172
|
+
return config.defaultStoragePath;
|
|
173
|
+
}
|
|
152
174
|
let matterDir;
|
|
153
175
|
if (process.platform === "win32") {
|
|
154
176
|
matterDir = resolve(process.env.APPDATA ?? ".", "matter");
|
|
@@ -164,9 +186,9 @@ function getDefaultRoot(envName: string) {
|
|
|
164
186
|
}
|
|
165
187
|
|
|
166
188
|
export function getDefaults(vars: VariableService) {
|
|
167
|
-
const envName = vars.get("environment",
|
|
189
|
+
const envName = vars.get("environment", config.defaultEnvironmentName);
|
|
168
190
|
const rootPath = vars.get("path.root", getDefaultRoot(envName));
|
|
169
|
-
const configPath = resolve(rootPath, vars.get("path.config",
|
|
191
|
+
const configPath = resolve(rootPath, vars.get("path.config", config.defaultConfigFilePath));
|
|
170
192
|
|
|
171
193
|
return {
|
|
172
194
|
environment: envName,
|
|
@@ -175,8 +197,9 @@ export function getDefaults(vars: VariableService) {
|
|
|
175
197
|
config: configPath,
|
|
176
198
|
},
|
|
177
199
|
runtime: {
|
|
178
|
-
signals:
|
|
179
|
-
exitcode:
|
|
200
|
+
signals: config.trapProcessSignals,
|
|
201
|
+
exitcode: config.setProcessExitCodeOnError,
|
|
202
|
+
unhandlederrors: config.trapUnhandledErrors,
|
|
180
203
|
},
|
|
181
204
|
};
|
|
182
205
|
}
|