@naturalcycles/nodejs-lib 13.43.0 → 13.44.0

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.
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runScript = runScript;
4
4
  const tslib_1 = require("tslib");
5
5
  const node_os_1 = tslib_1.__importDefault(require("node:os"));
6
- const node_util_1 = require("node:util");
7
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
+ const colors_1 = require("../colors/colors");
8
8
  const inspect_1 = require("../string/inspect");
9
9
  const { DEBUG_RUN_SCRIPT } = process.env;
10
10
  /**
@@ -26,6 +26,7 @@ const { DEBUG_RUN_SCRIPT } = process.env;
26
26
  * Set env DEBUG_RUN_SCRIPT for extra debugging.
27
27
  */
28
28
  function runScript(fn, opt = {}) {
29
+ require('dotenv').config();
29
30
  logEnvironment();
30
31
  (0, js_lib_1.setGlobalStringifyFunction)(inspect_1.inspectStringifyFn);
31
32
  const { logger = console, noExit, registerUncaughtExceptionHandlers = true } = opt;
@@ -66,13 +67,13 @@ function runScript(fn, opt = {}) {
66
67
  })();
67
68
  }
68
69
  function logEnvironment() {
69
- const { platform, arch, versions: { node }, env: { CPU_LIMIT, NODE_OPTIONS = 'not defined' }, } = process;
70
+ const { platform, arch, versions: { node }, env: { CPU_LIMIT, NODE_OPTIONS }, } = process;
70
71
  const cpuLimit = Number(CPU_LIMIT) || undefined;
71
72
  const availableParallelism = node_os_1.default.availableParallelism?.();
72
73
  const cpus = node_os_1.default.cpus().length;
73
- console.log(dimGrey(Object.entries({
74
+ console.log((0, colors_1.dimGrey)(Object.entries({
74
75
  node: `${node} ${platform} ${arch}`,
75
- NODE_OPTIONS,
76
+ NODE_OPTIONS: NODE_OPTIONS || 'not defined',
76
77
  cpus,
77
78
  availableParallelism,
78
79
  cpuLimit,
@@ -86,6 +87,3 @@ function logEnvironment() {
86
87
  console.warn(`It looks like you're using "max_old_space_size" syntax with underscores instead of dashes - it's WRONG and doesn't work in environment variables. Strongly advised to rename it to "max-old-space-size"`);
87
88
  }
88
89
  }
89
- function dimGrey(s) {
90
- return (0, node_util_1.styleText)(['dim', 'grey'], s);
91
- }
@@ -11,8 +11,9 @@ if (!workerFile) {
11
11
 
12
12
  try {
13
13
  // require('esbuild-register') // alternative
14
- require('ts-node/register/transpile-only')
15
- require('tsconfig-paths/register')
14
+ // require('ts-node/register/transpile-only')
15
+ require('tsx/cjs/api').register() // https://tsx.is/dev-api/register-cjs
16
+ // require('tsconfig-paths/register')
16
17
  } catch {} // require if exists
17
18
 
18
19
  const { WorkerClass } = require(workerFile)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.43.0",
3
+ "version": "13.44.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@naturalcycles/bench-lib": "^3",
42
- "@naturalcycles/dev-lib": "^16",
42
+ "@naturalcycles/dev-lib": "^17",
43
43
  "@types/node": "^22",
44
44
  "@types/through2-concurrent": "^2",
45
45
  "@vitest/coverage-v8": "^3",
@@ -1,7 +1,7 @@
1
1
  import os from 'node:os'
2
- import { styleText } from 'node:util'
3
2
  import type { CommonLogger } from '@naturalcycles/js-lib'
4
3
  import { pDelay, setGlobalStringifyFunction } from '@naturalcycles/js-lib'
4
+ import { dimGrey } from '../colors/colors'
5
5
  import { inspectStringifyFn } from '../string/inspect'
6
6
 
7
7
  export interface RunScriptOptions {
@@ -45,6 +45,7 @@ const { DEBUG_RUN_SCRIPT } = process.env
45
45
  * Set env DEBUG_RUN_SCRIPT for extra debugging.
46
46
  */
47
47
  export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {}): void {
48
+ require('dotenv').config()
48
49
  logEnvironment()
49
50
  setGlobalStringifyFunction(inspectStringifyFn)
50
51
 
@@ -95,7 +96,7 @@ function logEnvironment(): void {
95
96
  platform,
96
97
  arch,
97
98
  versions: { node },
98
- env: { CPU_LIMIT, NODE_OPTIONS = 'not defined' },
99
+ env: { CPU_LIMIT, NODE_OPTIONS },
99
100
  } = process
100
101
 
101
102
  const cpuLimit = Number(CPU_LIMIT) || undefined
@@ -105,7 +106,7 @@ function logEnvironment(): void {
105
106
  dimGrey(
106
107
  Object.entries({
107
108
  node: `${node} ${platform} ${arch}`,
108
- NODE_OPTIONS,
109
+ NODE_OPTIONS: NODE_OPTIONS || 'not defined',
109
110
  cpus,
110
111
  availableParallelism,
111
112
  cpuLimit,
@@ -125,7 +126,3 @@ function logEnvironment(): void {
125
126
  )
126
127
  }
127
128
  }
128
-
129
- function dimGrey(s: string): string {
130
- return styleText(['dim', 'grey'], s)
131
- }
@@ -11,8 +11,9 @@ if (!workerFile) {
11
11
 
12
12
  try {
13
13
  // require('esbuild-register') // alternative
14
- require('ts-node/register/transpile-only')
15
- require('tsconfig-paths/register')
14
+ // require('ts-node/register/transpile-only')
15
+ require('tsx/cjs/api').register() // https://tsx.is/dev-api/register-cjs
16
+ // require('tsconfig-paths/register')
16
17
  } catch {} // require if exists
17
18
 
18
19
  const { WorkerClass } = require(workerFile)