@siddharatha/adapter-node-rolldown 1.1.5 → 1.1.7

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/files/env.js CHANGED
@@ -1,94 +1,29 @@
1
- import process from 'node:process';
2
-
3
- /* global ENV_PREFIX */
4
-
1
+ //#region src/env.js
5
2
  const expected = new Set([
6
- 'SOCKET_PATH',
7
- 'HOST',
8
- 'PORT',
9
- 'ORIGIN',
10
- 'XFF_DEPTH',
11
- 'ADDRESS_HEADER',
12
- 'PROTOCOL_HEADER',
13
- 'HOST_HEADER',
14
- 'PORT_HEADER',
15
- 'BODY_SIZE_LIMIT',
16
- 'SHUTDOWN_TIMEOUT',
17
- 'IDLE_TIMEOUT',
18
- 'KEEP_ALIVE_TIMEOUT',
19
- 'HEADERS_TIMEOUT'
3
+ "SOCKET_PATH",
4
+ "HOST",
5
+ "PORT",
6
+ "ORIGIN",
7
+ "XFF_DEPTH",
8
+ "ADDRESS_HEADER",
9
+ "PROTOCOL_HEADER",
10
+ "HOST_HEADER",
11
+ "BODY_SIZE_LIMIT"
20
12
  ]);
21
-
22
- const expected_unprefixed = new Set(['LISTEN_PID', 'LISTEN_FDS']);
23
-
24
13
  if (ENV_PREFIX) {
25
- for (const name in process.env) {
26
- if (name.startsWith(ENV_PREFIX)) {
27
- const unprefixed = name.slice(ENV_PREFIX.length);
28
- if (!expected.has(unprefixed)) {
29
- throw new Error(
30
- `You should change envPrefix (${ENV_PREFIX}) to avoid conflicts with existing environment variables — unexpectedly saw ${name}`
31
- );
32
- }
33
- }
34
- }
14
+ for (const name in process.env) if (name.startsWith(ENV_PREFIX)) {
15
+ const unprefixed = name.slice(ENV_PREFIX.length);
16
+ if (!expected.has(unprefixed)) throw new Error(`You should change envPrefix (${ENV_PREFIX}) to avoid conflicts with existing environment variables — unexpectedly saw ${name}`);
17
+ }
35
18
  }
36
-
37
19
  /**
38
- * @param {string} name
39
- * @param {any} fallback
40
- */
20
+ * @param {string} name
21
+ * @param {any} fallback
22
+ */
41
23
  function env(name, fallback) {
42
- const prefix = expected_unprefixed.has(name) ? '' : ENV_PREFIX;
43
- const prefixed = prefix + name;
44
- return prefixed in process.env ? process.env[prefixed] : fallback;
45
- }
46
-
47
- const integer_regexp = /^\d+$/;
48
-
49
- /**
50
- * Throw a consistently-structured parsing error for environment variables.
51
- * @param {string} name
52
- * @param {any} value
53
- * @param {string} description
54
- * @returns {never}
55
- */
56
- function parsing_error(name, value, description) {
57
- throw new Error(
58
- `Invalid value for environment variable ${name}: ${JSON.stringify(value)} (${description})`
59
- );
60
- }
61
-
62
- /**
63
- * Check the environment for a timeout value (non-negative integer) in seconds.
64
- * @param {string} name
65
- * @param {number} [fallback]
66
- * @returns {number | undefined}
67
- */
68
- function timeout_env(name, fallback) {
69
- const raw = env(name, fallback);
70
- if (!raw) {
71
- return fallback;
72
- }
73
-
74
- if (!integer_regexp.test(raw)) {
75
- parsing_error(name, raw, 'should be a non-negative integer');
76
- }
77
-
78
- const parsed = Number.parseInt(raw, 10);
79
-
80
- // We don't technically need to check `Number.isNaN` because the value already passed the regexp test.
81
- // However, just in case there's some new codepath introduced somewhere down the line, it's probably good
82
- // to stick this in here.
83
- if (Number.isNaN(parsed)) {
84
- parsing_error(name, raw, 'should be a non-negative integer');
85
- }
86
-
87
- if (parsed < 0) {
88
- parsing_error(name, raw, 'should be a non-negative integer');
89
- }
90
-
91
- return parsed;
24
+ const prefixed = ENV_PREFIX + name;
25
+ return prefixed in process.env ? process.env[prefixed] : fallback;
92
26
  }
93
27
 
94
- export { env, timeout_env };
28
+ //#endregion
29
+ export { env };