@twin.org/node-core 0.0.2-next.22 â 0.0.2-next.24
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/index.cjs +46 -5
- package/dist/esm/index.mjs +46 -5
- package/docs/changelog.md +14 -0
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -15,6 +15,7 @@ var cliCore = require('@twin.org/cli-core');
|
|
|
15
15
|
var rightsManagementRestClient = require('@twin.org/rights-management-rest-client');
|
|
16
16
|
var engineServer = require('@twin.org/engine-server');
|
|
17
17
|
var modules = require('@twin.org/modules');
|
|
18
|
+
var node_child_process = require('node:child_process');
|
|
18
19
|
var dotenv = require('dotenv');
|
|
19
20
|
var engine = require('@twin.org/engine');
|
|
20
21
|
var engineCore = require('@twin.org/engine-core');
|
|
@@ -958,14 +959,22 @@ async function configureLogging(coreConfig, envVars) {
|
|
|
958
959
|
additionalConnectorCount++;
|
|
959
960
|
}
|
|
960
961
|
}
|
|
962
|
+
// If more than one logging connector, then we need to add a multi connector
|
|
963
|
+
// and set it as the default one
|
|
961
964
|
if (additionalConnectorCount > 1) {
|
|
962
|
-
coreConfig.types.loggingConnector
|
|
965
|
+
coreConfig.types.loggingConnector.push({
|
|
963
966
|
type: engineTypes.LoggingConnectorType.Multi,
|
|
964
967
|
options: {
|
|
965
968
|
loggingConnectorTypes
|
|
966
|
-
}
|
|
969
|
+
},
|
|
970
|
+
isDefault: true
|
|
967
971
|
});
|
|
968
972
|
}
|
|
973
|
+
else if (additionalConnectorCount > 0) {
|
|
974
|
+
// If only one connector, then we set it as the default one
|
|
975
|
+
coreConfig.types.loggingConnector[coreConfig.types.loggingConnector.length - 1].isDefault =
|
|
976
|
+
true;
|
|
977
|
+
}
|
|
969
978
|
if (additionalConnectorCount > 0) {
|
|
970
979
|
coreConfig.types.loggingComponent ??= [];
|
|
971
980
|
// We set the isDefault flag so that other components will get this service by default
|
|
@@ -1974,6 +1983,7 @@ async function start(nodeOptions, nodeEngineConfig, envVars) {
|
|
|
1974
1983
|
|
|
1975
1984
|
// Copyright 2024 IOTA Stiftung.
|
|
1976
1985
|
// SPDX-License-Identifier: Apache-2.0.
|
|
1986
|
+
const moduleCache = {};
|
|
1977
1987
|
/**
|
|
1978
1988
|
* Run the TWIN Node server.
|
|
1979
1989
|
* @param nodeOptions Optional configuration options for running the server.
|
|
@@ -1984,7 +1994,7 @@ async function run(nodeOptions) {
|
|
|
1984
1994
|
nodeOptions ??= {};
|
|
1985
1995
|
const serverInfo = {
|
|
1986
1996
|
name: nodeOptions?.serverName ?? "TWIN Node Server",
|
|
1987
|
-
version: nodeOptions?.serverVersion ?? "0.0.2-next.
|
|
1997
|
+
version: nodeOptions?.serverVersion ?? "0.0.2-next.24" // x-release-please-version
|
|
1988
1998
|
};
|
|
1989
1999
|
cliCore.CLIDisplay.header(serverInfo.name, serverInfo.version, "đŠī¸ ");
|
|
1990
2000
|
if (!core.Is.stringValue(nodeOptions?.executionDirectory)) {
|
|
@@ -2127,6 +2137,12 @@ async function buildConfiguration(processEnv, options, serverInfo) {
|
|
|
2127
2137
|
*/
|
|
2128
2138
|
function overrideModuleImport(executionDirectory) {
|
|
2129
2139
|
modules.ModuleHelper.overrideImport(async (moduleName) => {
|
|
2140
|
+
if (moduleCache[moduleName]) {
|
|
2141
|
+
return {
|
|
2142
|
+
module: moduleCache[moduleName],
|
|
2143
|
+
useDefault: false
|
|
2144
|
+
};
|
|
2145
|
+
}
|
|
2130
2146
|
// If the module path for example when dynamically loading
|
|
2131
2147
|
// modules looks like a local file then we try to resolve
|
|
2132
2148
|
// using the local file system
|
|
@@ -2143,13 +2159,38 @@ function overrideModuleImport(executionDirectory) {
|
|
|
2143
2159
|
if (exists) {
|
|
2144
2160
|
// If the module exists then we can load it, otherwise
|
|
2145
2161
|
// we fallback to regular handling to see if that can import it
|
|
2162
|
+
const module = await import(process.platform === "win32" ? `file://${localFilename}` : localFilename);
|
|
2163
|
+
moduleCache[moduleName] = module;
|
|
2164
|
+
return {
|
|
2165
|
+
module,
|
|
2166
|
+
useDefault: false
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
try {
|
|
2171
|
+
// Try and load from node_modules manually
|
|
2172
|
+
// This is needed for some environments where
|
|
2173
|
+
// the module resolution doesn't work as expected
|
|
2174
|
+
const npmRoot = node_child_process.execSync("npm root").toString().trim().replace(/\\/g, "/");
|
|
2175
|
+
const packageJson = await loadJsonFile(path.resolve(npmRoot, moduleName, "package.json"));
|
|
2176
|
+
const mainFile = packageJson?.module ?? packageJson?.main ?? "index.js";
|
|
2177
|
+
const modulePath = path.resolve(npmRoot, moduleName, mainFile);
|
|
2178
|
+
const exists = await fileExists(modulePath);
|
|
2179
|
+
if (exists) {
|
|
2180
|
+
const module = await import(process.platform === "win32" ? `file://${modulePath}` : modulePath);
|
|
2181
|
+
moduleCache[moduleName] = module;
|
|
2146
2182
|
return {
|
|
2147
|
-
module
|
|
2183
|
+
module,
|
|
2148
2184
|
useDefault: false
|
|
2149
2185
|
};
|
|
2150
2186
|
}
|
|
2151
2187
|
}
|
|
2152
|
-
|
|
2188
|
+
catch {
|
|
2189
|
+
// We just fallback to default handling if not possible
|
|
2190
|
+
}
|
|
2191
|
+
// We don't appear to be able to manually resolve this module
|
|
2192
|
+
// So we let the default handling take care of it
|
|
2193
|
+
// This will allow built-in modules and regular node_modules to load as normal
|
|
2153
2194
|
return {
|
|
2154
2195
|
useDefault: true
|
|
2155
2196
|
};
|
package/dist/esm/index.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { CLIDisplay } from '@twin.org/cli-core';
|
|
|
13
13
|
import { PolicyNegotiationPointClient, DataAccessPointClient } from '@twin.org/rights-management-rest-client';
|
|
14
14
|
import { addDefaultRestPaths, addDefaultSocketPaths, EngineServer } from '@twin.org/engine-server';
|
|
15
15
|
import { ModuleHelper } from '@twin.org/modules';
|
|
16
|
+
import { execSync } from 'node:child_process';
|
|
16
17
|
import * as dotenv from 'dotenv';
|
|
17
18
|
import { Engine } from '@twin.org/engine';
|
|
18
19
|
import { FileStateStorage } from '@twin.org/engine-core';
|
|
@@ -937,14 +938,22 @@ async function configureLogging(coreConfig, envVars) {
|
|
|
937
938
|
additionalConnectorCount++;
|
|
938
939
|
}
|
|
939
940
|
}
|
|
941
|
+
// If more than one logging connector, then we need to add a multi connector
|
|
942
|
+
// and set it as the default one
|
|
940
943
|
if (additionalConnectorCount > 1) {
|
|
941
|
-
coreConfig.types.loggingConnector
|
|
944
|
+
coreConfig.types.loggingConnector.push({
|
|
942
945
|
type: LoggingConnectorType.Multi,
|
|
943
946
|
options: {
|
|
944
947
|
loggingConnectorTypes
|
|
945
|
-
}
|
|
948
|
+
},
|
|
949
|
+
isDefault: true
|
|
946
950
|
});
|
|
947
951
|
}
|
|
952
|
+
else if (additionalConnectorCount > 0) {
|
|
953
|
+
// If only one connector, then we set it as the default one
|
|
954
|
+
coreConfig.types.loggingConnector[coreConfig.types.loggingConnector.length - 1].isDefault =
|
|
955
|
+
true;
|
|
956
|
+
}
|
|
948
957
|
if (additionalConnectorCount > 0) {
|
|
949
958
|
coreConfig.types.loggingComponent ??= [];
|
|
950
959
|
// We set the isDefault flag so that other components will get this service by default
|
|
@@ -1953,6 +1962,7 @@ async function start(nodeOptions, nodeEngineConfig, envVars) {
|
|
|
1953
1962
|
|
|
1954
1963
|
// Copyright 2024 IOTA Stiftung.
|
|
1955
1964
|
// SPDX-License-Identifier: Apache-2.0.
|
|
1965
|
+
const moduleCache = {};
|
|
1956
1966
|
/**
|
|
1957
1967
|
* Run the TWIN Node server.
|
|
1958
1968
|
* @param nodeOptions Optional configuration options for running the server.
|
|
@@ -1963,7 +1973,7 @@ async function run(nodeOptions) {
|
|
|
1963
1973
|
nodeOptions ??= {};
|
|
1964
1974
|
const serverInfo = {
|
|
1965
1975
|
name: nodeOptions?.serverName ?? "TWIN Node Server",
|
|
1966
|
-
version: nodeOptions?.serverVersion ?? "0.0.2-next.
|
|
1976
|
+
version: nodeOptions?.serverVersion ?? "0.0.2-next.24" // x-release-please-version
|
|
1967
1977
|
};
|
|
1968
1978
|
CLIDisplay.header(serverInfo.name, serverInfo.version, "đŠī¸ ");
|
|
1969
1979
|
if (!Is.stringValue(nodeOptions?.executionDirectory)) {
|
|
@@ -2106,6 +2116,12 @@ async function buildConfiguration(processEnv, options, serverInfo) {
|
|
|
2106
2116
|
*/
|
|
2107
2117
|
function overrideModuleImport(executionDirectory) {
|
|
2108
2118
|
ModuleHelper.overrideImport(async (moduleName) => {
|
|
2119
|
+
if (moduleCache[moduleName]) {
|
|
2120
|
+
return {
|
|
2121
|
+
module: moduleCache[moduleName],
|
|
2122
|
+
useDefault: false
|
|
2123
|
+
};
|
|
2124
|
+
}
|
|
2109
2125
|
// If the module path for example when dynamically loading
|
|
2110
2126
|
// modules looks like a local file then we try to resolve
|
|
2111
2127
|
// using the local file system
|
|
@@ -2122,13 +2138,38 @@ function overrideModuleImport(executionDirectory) {
|
|
|
2122
2138
|
if (exists) {
|
|
2123
2139
|
// If the module exists then we can load it, otherwise
|
|
2124
2140
|
// we fallback to regular handling to see if that can import it
|
|
2141
|
+
const module = await import(process.platform === "win32" ? `file://${localFilename}` : localFilename);
|
|
2142
|
+
moduleCache[moduleName] = module;
|
|
2143
|
+
return {
|
|
2144
|
+
module,
|
|
2145
|
+
useDefault: false
|
|
2146
|
+
};
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
try {
|
|
2150
|
+
// Try and load from node_modules manually
|
|
2151
|
+
// This is needed for some environments where
|
|
2152
|
+
// the module resolution doesn't work as expected
|
|
2153
|
+
const npmRoot = execSync("npm root").toString().trim().replace(/\\/g, "/");
|
|
2154
|
+
const packageJson = await loadJsonFile(path.resolve(npmRoot, moduleName, "package.json"));
|
|
2155
|
+
const mainFile = packageJson?.module ?? packageJson?.main ?? "index.js";
|
|
2156
|
+
const modulePath = path.resolve(npmRoot, moduleName, mainFile);
|
|
2157
|
+
const exists = await fileExists(modulePath);
|
|
2158
|
+
if (exists) {
|
|
2159
|
+
const module = await import(process.platform === "win32" ? `file://${modulePath}` : modulePath);
|
|
2160
|
+
moduleCache[moduleName] = module;
|
|
2125
2161
|
return {
|
|
2126
|
-
module
|
|
2162
|
+
module,
|
|
2127
2163
|
useDefault: false
|
|
2128
2164
|
};
|
|
2129
2165
|
}
|
|
2130
2166
|
}
|
|
2131
|
-
|
|
2167
|
+
catch {
|
|
2168
|
+
// We just fallback to default handling if not possible
|
|
2169
|
+
}
|
|
2170
|
+
// We don't appear to be able to manually resolve this module
|
|
2171
|
+
// So we let the default handling take care of it
|
|
2172
|
+
// This will allow built-in modules and regular node_modules to load as normal
|
|
2132
2173
|
return {
|
|
2133
2174
|
useDefault: true
|
|
2134
2175
|
};
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @twin.org/node-core - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.24](https://github.com/twinfoundation/node/compare/node-core-v0.0.2-next.23...node-core-v0.0.2-next.24) (2025-10-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add isDefault flag to logging connectors ([358e839](https://github.com/twinfoundation/node/commit/358e8394819dab9832d3a9ebfac74b897b7d5f40))
|
|
9
|
+
|
|
10
|
+
## [0.0.2-next.23](https://github.com/twinfoundation/node/compare/node-core-v0.0.2-next.22...node-core-v0.0.2-next.23) (2025-10-07)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add module cache and improve resolution ([482be05](https://github.com/twinfoundation/node/commit/482be056c37a598033250ea8a7288a33cf3470b4))
|
|
16
|
+
|
|
3
17
|
## [0.0.2-next.22](https://github.com/twinfoundation/node/compare/node-core-v0.0.2-next.21...node-core-v0.0.2-next.22) (2025-10-07)
|
|
4
18
|
|
|
5
19
|
|