@twin.org/node-core 0.0.2-next.7 → 0.0.2-next.8
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
CHANGED
|
@@ -12,6 +12,7 @@ var walletModels = require('@twin.org/wallet-models');
|
|
|
12
12
|
var promises = require('node:fs/promises');
|
|
13
13
|
var path = require('node:path');
|
|
14
14
|
var engineServer = require('@twin.org/engine-server');
|
|
15
|
+
var modules = require('@twin.org/modules');
|
|
15
16
|
var dotenv = require('dotenv');
|
|
16
17
|
var engine = require('@twin.org/engine');
|
|
17
18
|
var engineCore = require('@twin.org/engine-core');
|
|
@@ -1727,7 +1728,7 @@ async function run(nodeOptions) {
|
|
|
1727
1728
|
nodeOptions ??= {};
|
|
1728
1729
|
const serverInfo = {
|
|
1729
1730
|
name: nodeOptions?.serverName ?? "TWIN Node Server",
|
|
1730
|
-
version: nodeOptions?.serverVersion ?? "0.0.2-next.
|
|
1731
|
+
version: nodeOptions?.serverVersion ?? "0.0.2-next.8" // x-release-please-version
|
|
1731
1732
|
};
|
|
1732
1733
|
console.log(`\u001B[4m🌩️ ${serverInfo.name} v${serverInfo.version}\u001B[24m\n`);
|
|
1733
1734
|
if (!core.Is.stringValue(nodeOptions?.executionDirectory)) {
|
|
@@ -1757,6 +1758,7 @@ async function run(nodeOptions) {
|
|
|
1757
1758
|
}
|
|
1758
1759
|
nodeOptions.envPrefix ??= "TWIN_NODE_";
|
|
1759
1760
|
console.info("Environment Prefix:", nodeOptions.envPrefix);
|
|
1761
|
+
overrideModuleImport(nodeOptions.executionDirectory ?? "");
|
|
1760
1762
|
const { engineServerConfig, nodeEnvVars: envVars } = await buildConfiguration(process.env, nodeOptions, serverInfo);
|
|
1761
1763
|
console.info();
|
|
1762
1764
|
const startResult = await start(nodeOptions, engineServerConfig, envVars);
|
|
@@ -1851,6 +1853,40 @@ async function buildConfiguration(processEnv, options, serverInfo) {
|
|
|
1851
1853
|
}
|
|
1852
1854
|
return { engineServerConfig, nodeEnvVars: envVars };
|
|
1853
1855
|
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Override module imports to use local files where possible.
|
|
1858
|
+
* @param executionDirectory The execution directory for resolving local module paths.
|
|
1859
|
+
*/
|
|
1860
|
+
function overrideModuleImport(executionDirectory) {
|
|
1861
|
+
modules.ModuleHelper.overrideImport(async (moduleName) => {
|
|
1862
|
+
// If the module path for example when dynamically loading
|
|
1863
|
+
// modules looks like a local file then we try to resolve
|
|
1864
|
+
// using the local file system
|
|
1865
|
+
const isLocal = modules.ModuleHelper.isLocalModule(moduleName);
|
|
1866
|
+
if (isLocal) {
|
|
1867
|
+
// See if we can just resolve the filename locally
|
|
1868
|
+
let localFilename = path.resolve(moduleName);
|
|
1869
|
+
let exists = await fileExists(localFilename);
|
|
1870
|
+
if (!exists) {
|
|
1871
|
+
// Doesn't exist in the current directory, try the execution directory
|
|
1872
|
+
localFilename = path.resolve(executionDirectory, moduleName);
|
|
1873
|
+
exists = await fileExists(localFilename);
|
|
1874
|
+
}
|
|
1875
|
+
if (exists) {
|
|
1876
|
+
// If the module exists then we can load it, otherwise
|
|
1877
|
+
// we fallback to regular handling to see if that can import it
|
|
1878
|
+
return {
|
|
1879
|
+
module: await import(process.platform === "win32" ? `file://${localFilename}` : localFilename),
|
|
1880
|
+
useDefault: false
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
// The filename doesn't look like a local module, so just use default handling
|
|
1885
|
+
return {
|
|
1886
|
+
useDefault: true
|
|
1887
|
+
};
|
|
1888
|
+
});
|
|
1889
|
+
}
|
|
1854
1890
|
|
|
1855
1891
|
exports.NodeFeatures = NodeFeatures;
|
|
1856
1892
|
exports.bootstrap = bootstrap;
|
|
@@ -1869,5 +1905,6 @@ exports.getFeatures = getFeatures;
|
|
|
1869
1905
|
exports.initialiseLocales = initialiseLocales;
|
|
1870
1906
|
exports.loadJsonFile = loadJsonFile;
|
|
1871
1907
|
exports.loadTextFile = loadTextFile;
|
|
1908
|
+
exports.overrideModuleImport = overrideModuleImport;
|
|
1872
1909
|
exports.run = run;
|
|
1873
1910
|
exports.start = start;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { WalletConnectorFactory } from '@twin.org/wallet-models';
|
|
|
10
10
|
import { readFile, stat } from 'node:fs/promises';
|
|
11
11
|
import path from 'node:path';
|
|
12
12
|
import { addDefaultRestPaths, addDefaultSocketPaths, EngineServer } from '@twin.org/engine-server';
|
|
13
|
+
import { ModuleHelper } from '@twin.org/modules';
|
|
13
14
|
import * as dotenv from 'dotenv';
|
|
14
15
|
import { Engine } from '@twin.org/engine';
|
|
15
16
|
import { FileStateStorage } from '@twin.org/engine-core';
|
|
@@ -1706,7 +1707,7 @@ async function run(nodeOptions) {
|
|
|
1706
1707
|
nodeOptions ??= {};
|
|
1707
1708
|
const serverInfo = {
|
|
1708
1709
|
name: nodeOptions?.serverName ?? "TWIN Node Server",
|
|
1709
|
-
version: nodeOptions?.serverVersion ?? "0.0.2-next.
|
|
1710
|
+
version: nodeOptions?.serverVersion ?? "0.0.2-next.8" // x-release-please-version
|
|
1710
1711
|
};
|
|
1711
1712
|
console.log(`\u001B[4m🌩️ ${serverInfo.name} v${serverInfo.version}\u001B[24m\n`);
|
|
1712
1713
|
if (!Is.stringValue(nodeOptions?.executionDirectory)) {
|
|
@@ -1736,6 +1737,7 @@ async function run(nodeOptions) {
|
|
|
1736
1737
|
}
|
|
1737
1738
|
nodeOptions.envPrefix ??= "TWIN_NODE_";
|
|
1738
1739
|
console.info("Environment Prefix:", nodeOptions.envPrefix);
|
|
1740
|
+
overrideModuleImport(nodeOptions.executionDirectory ?? "");
|
|
1739
1741
|
const { engineServerConfig, nodeEnvVars: envVars } = await buildConfiguration(process.env, nodeOptions, serverInfo);
|
|
1740
1742
|
console.info();
|
|
1741
1743
|
const startResult = await start(nodeOptions, engineServerConfig, envVars);
|
|
@@ -1830,5 +1832,39 @@ async function buildConfiguration(processEnv, options, serverInfo) {
|
|
|
1830
1832
|
}
|
|
1831
1833
|
return { engineServerConfig, nodeEnvVars: envVars };
|
|
1832
1834
|
}
|
|
1835
|
+
/**
|
|
1836
|
+
* Override module imports to use local files where possible.
|
|
1837
|
+
* @param executionDirectory The execution directory for resolving local module paths.
|
|
1838
|
+
*/
|
|
1839
|
+
function overrideModuleImport(executionDirectory) {
|
|
1840
|
+
ModuleHelper.overrideImport(async (moduleName) => {
|
|
1841
|
+
// If the module path for example when dynamically loading
|
|
1842
|
+
// modules looks like a local file then we try to resolve
|
|
1843
|
+
// using the local file system
|
|
1844
|
+
const isLocal = ModuleHelper.isLocalModule(moduleName);
|
|
1845
|
+
if (isLocal) {
|
|
1846
|
+
// See if we can just resolve the filename locally
|
|
1847
|
+
let localFilename = path.resolve(moduleName);
|
|
1848
|
+
let exists = await fileExists(localFilename);
|
|
1849
|
+
if (!exists) {
|
|
1850
|
+
// Doesn't exist in the current directory, try the execution directory
|
|
1851
|
+
localFilename = path.resolve(executionDirectory, moduleName);
|
|
1852
|
+
exists = await fileExists(localFilename);
|
|
1853
|
+
}
|
|
1854
|
+
if (exists) {
|
|
1855
|
+
// If the module exists then we can load it, otherwise
|
|
1856
|
+
// we fallback to regular handling to see if that can import it
|
|
1857
|
+
return {
|
|
1858
|
+
module: await import(process.platform === "win32" ? `file://${localFilename}` : localFilename),
|
|
1859
|
+
useDefault: false
|
|
1860
|
+
};
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
// The filename doesn't look like a local module, so just use default handling
|
|
1864
|
+
return {
|
|
1865
|
+
useDefault: true
|
|
1866
|
+
};
|
|
1867
|
+
});
|
|
1868
|
+
}
|
|
1833
1869
|
|
|
1834
|
-
export { NodeFeatures, bootstrap, bootstrapAuth, bootstrapBlobEncryption, bootstrapImmutableProofMethod, bootstrapNodeIdentity, bootstrapNodeUser, bootstrapSynchronisedStorage, buildConfiguration, buildEngineConfiguration, buildEngineServerConfiguration, fileExists, getExecutionDirectory, getFeatures, initialiseLocales, loadJsonFile, loadTextFile, run, start };
|
|
1870
|
+
export { NodeFeatures, bootstrap, bootstrapAuth, bootstrapBlobEncryption, bootstrapImmutableProofMethod, bootstrapNodeIdentity, bootstrapNodeUser, bootstrapSynchronisedStorage, buildConfiguration, buildEngineConfiguration, buildEngineServerConfiguration, fileExists, getExecutionDirectory, getFeatures, initialiseLocales, loadJsonFile, loadTextFile, overrideModuleImport, run, start };
|
package/dist/types/node.d.ts
CHANGED
|
@@ -24,3 +24,8 @@ export declare function buildConfiguration(processEnv: {
|
|
|
24
24
|
};
|
|
25
25
|
engineServerConfig: IEngineServerConfig;
|
|
26
26
|
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Override module imports to use local files where possible.
|
|
29
|
+
* @param executionDirectory The execution directory for resolving local module paths.
|
|
30
|
+
*/
|
|
31
|
+
export declare function overrideModuleImport(executionDirectory: string): void;
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @twin.org/node-core - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.8](https://github.com/twinfoundation/node/compare/node-core-v0.0.2-next.7...node-core-v0.0.2-next.8) (2025-08-27)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add module override for better local import resolution ([ba00d17](https://github.com/twinfoundation/node/commit/ba00d17beea0a9a1851c89ad7c6a33256051c818))
|
|
9
|
+
|
|
3
10
|
## [0.0.2-next.7](https://github.com/twinfoundation/node/compare/node-core-v0.0.2-next.6...node-core-v0.0.2-next.7) (2025-08-26)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Function: overrideModuleImport()
|
|
2
|
+
|
|
3
|
+
> **overrideModuleImport**(`executionDirectory`): `void`
|
|
4
|
+
|
|
5
|
+
Override module imports to use local files where possible.
|
|
6
|
+
|
|
7
|
+
## Parameters
|
|
8
|
+
|
|
9
|
+
### executionDirectory
|
|
10
|
+
|
|
11
|
+
`string`
|
|
12
|
+
|
|
13
|
+
The execution directory for resolving local module paths.
|
|
14
|
+
|
|
15
|
+
## Returns
|
|
16
|
+
|
|
17
|
+
`void`
|
package/docs/reference/index.md
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
- [buildEngineServerConfiguration](functions/buildEngineServerConfiguration.md)
|
|
29
29
|
- [run](functions/run.md)
|
|
30
30
|
- [buildConfiguration](functions/buildConfiguration.md)
|
|
31
|
+
- [overrideModuleImport](functions/overrideModuleImport.md)
|
|
31
32
|
- [start](functions/start.md)
|
|
32
33
|
- [initialiseLocales](functions/initialiseLocales.md)
|
|
33
34
|
- [getExecutionDirectory](functions/getExecutionDirectory.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/node-core",
|
|
3
|
-
"version": "0.0.2-next.
|
|
3
|
+
"version": "0.0.2-next.8",
|
|
4
4
|
"description": "TWIN Node Core for serving APIs using the specified configuration",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"@twin.org/entity": "next",
|
|
28
28
|
"@twin.org/entity-storage-models": "next",
|
|
29
29
|
"@twin.org/identity-models": "next",
|
|
30
|
+
"@twin.org/modules": "next",
|
|
30
31
|
"@twin.org/vault-models": "next",
|
|
31
32
|
"@twin.org/wallet-models": "next",
|
|
32
33
|
"dotenv": "17.2.1",
|