@naturalcycles/nodejs-lib 15.98.0 → 15.99.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.
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import 'dotenv/config';
2
+ export {};
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import 'dotenv/config';
3
2
  import { dimGrey } from '../colors/colors.js';
4
3
  import { runScript } from '../script/runScript.js';
5
4
  import { secretsDecrypt } from '../secret/secrets-decrypt.util.js';
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import 'dotenv/config';
2
+ export {};
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import 'dotenv/config';
3
2
  import { dimGrey } from '../colors/colors.js';
4
3
  import { runScript } from '../script/runScript.js';
5
4
  import { secretsEncrypt } from '../secret/secrets-encrypt.util.js';
package/dist/fs/fs2.js CHANGED
@@ -53,7 +53,6 @@ class FS2 {
53
53
  }
54
54
  async readJsonAsync(filePath) {
55
55
  const str = await fsp.readFile(filePath, 'utf8');
56
- // eslint-disable-next-line @typescript-eslint/return-await
57
56
  return _jsonParse(str);
58
57
  }
59
58
  writeFile(filePath, data) {
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './buffer/buffer.util.js';
2
2
  export * from './diff/tableDiff.js';
3
3
  export * from './infra/process.util.js';
4
4
  export * from './log/log.util.js';
5
+ export * from './node.util.js';
5
6
  export * from './security/crypto.util.js';
6
7
  export * from './security/hash.util.js';
7
8
  export * from './security/id.util.js';
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ export * from './buffer/buffer.util.js';
2
2
  export * from './diff/tableDiff.js';
3
3
  export * from './infra/process.util.js';
4
4
  export * from './log/log.util.js';
5
+ export * from './node.util.js';
5
6
  export * from './security/crypto.util.js';
6
7
  export * from './security/hash.util.js';
7
8
  export * from './security/id.util.js';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns true if load was successful
3
+ */
4
+ export declare function loadEnvFileIfExists(path?: string): boolean;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Returns true if load was successful
3
+ */
4
+ export function loadEnvFileIfExists(path = '.env') {
5
+ try {
6
+ process.loadEnvFile(path);
7
+ return true;
8
+ }
9
+ catch (err) {
10
+ if (err.code === 'ENOENT') {
11
+ // gracefully ignore that the file does not exist
12
+ return false;
13
+ }
14
+ throw err;
15
+ }
16
+ }
@@ -1,4 +1,3 @@
1
- import 'dotenv/config';
2
1
  import type { CommonLogger } from '@naturalcycles/js-lib/log';
3
2
  export interface RunScriptOptions {
4
3
  /**
@@ -1,9 +1,10 @@
1
- import 'dotenv/config';
2
1
  import os from 'node:os';
3
2
  import { pDelay } from '@naturalcycles/js-lib/promise/pDelay.js';
4
3
  import { setGlobalStringifyFunction } from '@naturalcycles/js-lib/string/stringify.js';
5
4
  import { dimGrey } from '../colors/colors.js';
5
+ import { loadEnvFileIfExists } from '../node.util.js';
6
6
  import { inspectStringifyFn } from '../string/inspect.js';
7
+ loadEnvFileIfExists();
7
8
  const { DEBUG_RUN_SCRIPT } = process.env;
8
9
  /**
9
10
  * Use it in your top-level scripts like this:
@@ -1,7 +1,6 @@
1
- import fs from 'node:fs';
1
+ import fs, { globSync } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { _assert } from '@naturalcycles/js-lib/error/assert.js';
4
- import { globSync } from 'tinyglobby';
5
4
  import { dimGrey, yellow } from '../colors/colors.js';
6
5
  import { fs2 } from '../fs/fs2.js';
7
6
  import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js';
@@ -11,7 +11,7 @@ const secretMap = {};
11
11
  * Does NOT delete previous secrets from secretMap.
12
12
  */
13
13
  export function loadSecretsFromEnv() {
14
- // require('dotenv').config() // ensure .env is loaded
14
+ // loadEnvFileIfExists() // ensure .env is loaded
15
15
  const secrets = {};
16
16
  Object.keys(process.env)
17
17
  .filter(k => k.toUpperCase().startsWith('SECRET_'))
@@ -4,7 +4,6 @@ import { _deepCopy, _mapObject, Set2 } from '@naturalcycles/js-lib/object';
4
4
  import { _substringAfterLast } from '@naturalcycles/js-lib/string';
5
5
  import { Ajv2020 } from 'ajv/dist/2020.js';
6
6
  import { validTLDs } from '../tlds.js';
7
- /* eslint-disable @typescript-eslint/prefer-string-starts-ends-with */
8
7
  // oxlint-disable unicorn/prefer-code-point
9
8
  const AJV_OPTIONS = {
10
9
  removeAdditional: true,
@@ -1,5 +1,3 @@
1
- /* eslint-disable id-denylist */
2
- // oxlint-disable max-lines
3
1
  import { _isObject, _isUndefined, _numberEnumValues, _stringEnumValues, getEnumType, } from '@naturalcycles/js-lib';
4
2
  import { _uniq } from '@naturalcycles/js-lib/array';
5
3
  import { _assert, _try } from '@naturalcycles/js-lib/error';
@@ -822,7 +820,7 @@ export class JObject extends JBuilder {
822
820
  /**
823
821
  * Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
824
822
  */
825
- // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
823
+ // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
826
824
  dbEntity() {
827
825
  return this.extend({
828
826
  id: j.string(),
@@ -872,7 +870,7 @@ export class JObjectInfer extends JBuilder {
872
870
  /**
873
871
  * Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
874
872
  */
875
- // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
873
+ // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
876
874
  dbEntity() {
877
875
  return this.extend({
878
876
  id: j.string(),
@@ -5,7 +5,7 @@ import { hideBin } from 'yargs/helpers';
5
5
  * Quick yargs helper to make it work in esm.
6
6
  * It also allows to not have yargs and `@types/yargs` to be declared as dependencies.
7
7
  */
8
- // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
8
+ // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
9
9
  export function _yargs() {
10
10
  return yargs(hideBin(process.argv));
11
11
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.98.0",
4
+ "version": "15.99.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@standard-schema/spec": "^1",
@@ -9,7 +9,6 @@
9
9
  "@types/yargs": "^16",
10
10
  "ajv": "^8",
11
11
  "ansis": "^4",
12
- "dotenv": "^17",
13
12
  "jsonwebtoken": "^9",
14
13
  "lru-cache": "^11",
15
14
  "tinyglobby": "^0.2",
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import 'dotenv/config'
4
3
  import { dimGrey } from '../colors/colors.js'
5
4
  import { runScript } from '../script/runScript.js'
6
5
  import type { DecryptCLIOptions } from '../secret/secrets-decrypt.util.js'
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import 'dotenv/config'
4
3
  import { dimGrey } from '../colors/colors.js'
5
4
  import { runScript } from '../script/runScript.js'
6
5
  import type { EncryptCLIOptions } from '../secret/secrets-encrypt.util.js'
package/src/fs/fs2.ts CHANGED
@@ -62,7 +62,6 @@ class FS2 {
62
62
 
63
63
  async readJsonAsync<T = unknown>(filePath: string): Promise<T> {
64
64
  const str = await fsp.readFile(filePath, 'utf8')
65
- // eslint-disable-next-line @typescript-eslint/return-await
66
65
  return _jsonParse(str)
67
66
  }
68
67
 
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from './buffer/buffer.util.js'
2
2
  export * from './diff/tableDiff.js'
3
3
  export * from './infra/process.util.js'
4
4
  export * from './log/log.util.js'
5
+ export * from './node.util.js'
5
6
  export * from './security/crypto.util.js'
6
7
  export * from './security/hash.util.js'
7
8
  export * from './security/id.util.js'
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Returns true if load was successful
3
+ */
4
+ export function loadEnvFileIfExists(path = '.env'): boolean {
5
+ try {
6
+ process.loadEnvFile(path)
7
+ return true
8
+ } catch (err) {
9
+ if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
10
+ // gracefully ignore that the file does not exist
11
+ return false
12
+ }
13
+
14
+ throw err
15
+ }
16
+ }
@@ -1,12 +1,14 @@
1
- import 'dotenv/config'
2
1
  import os from 'node:os'
3
2
  import type { CommonLogger } from '@naturalcycles/js-lib/log'
4
3
  import { pDelay } from '@naturalcycles/js-lib/promise/pDelay.js'
5
4
  import { setGlobalStringifyFunction } from '@naturalcycles/js-lib/string/stringify.js'
6
5
  import type { AnyObject } from '@naturalcycles/js-lib/types'
7
6
  import { dimGrey } from '../colors/colors.js'
7
+ import { loadEnvFileIfExists } from '../node.util.js'
8
8
  import { inspectStringifyFn } from '../string/inspect.js'
9
9
 
10
+ loadEnvFileIfExists()
11
+
10
12
  export interface RunScriptOptions {
11
13
  /**
12
14
  * @default false
@@ -1,7 +1,6 @@
1
- import fs from 'node:fs'
1
+ import fs, { globSync } from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { _assert } from '@naturalcycles/js-lib/error/assert.js'
4
- import { globSync } from 'tinyglobby'
5
4
  import { dimGrey, yellow } from '../colors/colors.js'
6
5
  import { fs2 } from '../fs/fs2.js'
7
6
  import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js'
@@ -15,7 +15,7 @@ const secretMap: StringMap = {}
15
15
  * Does NOT delete previous secrets from secretMap.
16
16
  */
17
17
  export function loadSecretsFromEnv(): void {
18
- // require('dotenv').config() // ensure .env is loaded
18
+ // loadEnvFileIfExists() // ensure .env is loaded
19
19
 
20
20
  const secrets: StringMap = {}
21
21
  Object.keys(process.env)
@@ -50,12 +50,9 @@ export interface ReadableTyped<T = unknown> extends Readable {
50
50
  }
51
51
 
52
52
  // oxlint-disable no-unused-vars
53
- // eslint-disable-next-line @typescript-eslint/naming-convention
54
53
  export interface WritableTyped<_T> extends Writable {}
55
54
 
56
- // eslint-disable-next-line @typescript-eslint/naming-convention
57
55
  export interface TransformTyped<_IN = unknown, _OUT = unknown> extends Transform {}
58
- // oxlint-enable
59
56
 
60
57
  export interface TransformOptions {
61
58
  /**
@@ -15,7 +15,6 @@ import type {
15
15
  JsonSchemaStringEmailOptions,
16
16
  } from './jSchema.js'
17
17
 
18
- /* eslint-disable @typescript-eslint/prefer-string-starts-ends-with */
19
18
  // oxlint-disable unicorn/prefer-code-point
20
19
 
21
20
  const AJV_OPTIONS: Options = {
@@ -1,6 +1,3 @@
1
- /* eslint-disable id-denylist */
2
- // oxlint-disable max-lines
3
-
4
1
  import type { ValidationFunction, ValidationFunctionResult } from '@naturalcycles/js-lib'
5
2
  import {
6
3
  _isObject,
@@ -1122,7 +1119,7 @@ export class JObject<OUT extends AnyObject, Opt extends boolean = false> extends
1122
1119
  /**
1123
1120
  * Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
1124
1121
  */
1125
- // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
1122
+ // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
1126
1123
  dbEntity() {
1127
1124
  return this.extend({
1128
1125
  id: j.string(),
@@ -1229,7 +1226,7 @@ export class JObjectInfer<
1229
1226
  /**
1230
1227
  * Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
1231
1228
  */
1232
- // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
1229
+ // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
1233
1230
  dbEntity() {
1234
1231
  return this.extend({
1235
1232
  id: j.string(),
@@ -6,7 +6,7 @@ import { hideBin } from 'yargs/helpers'
6
6
  * Quick yargs helper to make it work in esm.
7
7
  * It also allows to not have yargs and `@types/yargs` to be declared as dependencies.
8
8
  */
9
- // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
9
+ // oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
10
10
  export function _yargs() {
11
11
  return yargs(hideBin(process.argv))
12
12
  }