@agnostack/env 1.4.0-beta.1 → 2.0.0-beta.1
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/LICENSE +1 -0
- package/dist/display.d.ts +3 -3
- package/dist/display.js +3 -0
- package/dist/env.d.ts +15 -21
- package/dist/env.js +44 -6
- package/dist/esm/display.js +3 -0
- package/dist/esm/env.js +44 -6
- package/dist/esm/project.js +24 -0
- package/dist/project.d.ts +39 -17
- package/dist/project.js +24 -0
- package/package.json +33 -33
package/LICENSE
CHANGED
package/dist/display.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function ensureStringOnly(string:
|
|
2
|
-
export function stringNotEmptyOnly(stringable:
|
|
3
|
-
export function stringEmptyOnly(stringable:
|
|
1
|
+
export function ensureStringOnly(string: unknown): string;
|
|
2
|
+
export function stringNotEmptyOnly(stringable: unknown): boolean;
|
|
3
|
+
export function stringEmptyOnly(stringable: unknown): boolean;
|
package/dist/display.js
CHANGED
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stringEmptyOnly = exports.stringNotEmptyOnly = exports.ensureStringOnly = void 0;
|
|
4
4
|
// HMMM: what if 'string' is an object?
|
|
5
|
+
/** @param {unknown} string @returns {string} */
|
|
5
6
|
const ensureStringOnly = (string) => (
|
|
6
7
|
// eslint-disable-next-line eqeqeq
|
|
7
8
|
(string != undefined) ? `${string}` : '');
|
|
8
9
|
exports.ensureStringOnly = ensureStringOnly;
|
|
10
|
+
/** @param {unknown} stringable @returns {boolean} */
|
|
9
11
|
const stringNotEmptyOnly = (stringable) => {
|
|
10
12
|
const string = (0, exports.ensureStringOnly)(stringable);
|
|
11
13
|
return ((string.length > 0) && !['null', 'undefined'].includes(string));
|
|
12
14
|
};
|
|
13
15
|
exports.stringNotEmptyOnly = stringNotEmptyOnly;
|
|
16
|
+
/** @param {unknown} stringable @returns {boolean} */
|
|
14
17
|
const stringEmptyOnly = (stringable) => (!(0, exports.stringNotEmptyOnly)(stringable));
|
|
15
18
|
exports.stringEmptyOnly = stringEmptyOnly;
|
package/dist/env.d.ts
CHANGED
|
@@ -5,36 +5,30 @@ export namespace ENV_PREFIX {
|
|
|
5
5
|
let DEFAULT: string;
|
|
6
6
|
}
|
|
7
7
|
export const ENV_PREFIXES: string[];
|
|
8
|
-
export function nextKeyValidator(envKey:
|
|
9
|
-
export function lowerKeyValidator(envKey:
|
|
10
|
-
export function publicKeyValidator(envKey:
|
|
11
|
-
export function cleanLowerEnv(_env:
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
export function cleanPublicEnv(_env: any, keyValidator?: (envKey: any) => boolean): {
|
|
15
|
-
[x: string]: any;
|
|
16
|
-
};
|
|
8
|
+
export function nextKeyValidator(envKey: string): boolean;
|
|
9
|
+
export function lowerKeyValidator(envKey: string): boolean;
|
|
10
|
+
export function publicKeyValidator(envKey: string): boolean;
|
|
11
|
+
export function cleanLowerEnv(_env: Record<string, string | undefined> | undefined, keyValidator?: (envKey: string) => boolean): Record<string, string | undefined>;
|
|
12
|
+
export function cleanPublicEnv(_env: Record<string, string | undefined> | undefined, keyValidator?: (envKey: string) => boolean): Record<string, string | undefined>;
|
|
17
13
|
export function parseEnvData(_env?: NodeJS.ProcessEnv): {
|
|
18
14
|
env: Record<string, string> & {
|
|
19
15
|
ENVIRONMENT: string;
|
|
20
16
|
};
|
|
21
|
-
nextEnv:
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
publicEnv: {
|
|
25
|
-
[x: string]: any;
|
|
26
|
-
};
|
|
17
|
+
nextEnv: Record<string, string | undefined>;
|
|
18
|
+
publicEnv: Record<string, string | undefined>;
|
|
27
19
|
stringifiedEnv: Record<string, string>;
|
|
28
|
-
argParams:
|
|
20
|
+
argParams: {
|
|
21
|
+
[x: string]: string | undefined;
|
|
22
|
+
};
|
|
29
23
|
params: {
|
|
30
|
-
[x: string]: string;
|
|
24
|
+
[x: string]: string | undefined;
|
|
31
25
|
ENVIRONMENT: string;
|
|
32
26
|
};
|
|
33
27
|
args: string[];
|
|
34
28
|
};
|
|
35
|
-
export function getPublicEnvValue(publicEnv:
|
|
36
|
-
export function replaceEnvTemplate(replaceable:
|
|
37
|
-
env?:
|
|
29
|
+
export function getPublicEnvValue(publicEnv: Record<string, string | undefined> | undefined, key: string): string | undefined;
|
|
30
|
+
export function replaceEnvTemplate(replaceable: unknown, { env: _env, template, callback, }?: {
|
|
31
|
+
env?: Record<string, string | undefined>;
|
|
38
32
|
template?: RegExp;
|
|
39
|
-
callback?: (replacedValue:
|
|
33
|
+
callback?: (replacedValue: string, replaceable: string) => string;
|
|
40
34
|
}): string;
|
package/dist/env.js
CHANGED
|
@@ -20,38 +20,60 @@ exports.ENV_PREFIX = {
|
|
|
20
20
|
DEFAULT: 'PUBLIC_',
|
|
21
21
|
};
|
|
22
22
|
exports.ENV_PREFIXES = Object.values(exports.ENV_PREFIX);
|
|
23
|
+
/** @param {string} envKey @returns {boolean} */
|
|
23
24
|
const nextKeyValidator = (envKey) => (
|
|
24
25
|
// NOTE: not allowed by NEXT: https://nextjs.org/docs/messages/env-key-not-allowed
|
|
25
26
|
!(envKey.startsWith('__') || envKey.startsWith('NODE_')));
|
|
26
27
|
exports.nextKeyValidator = nextKeyValidator;
|
|
28
|
+
/** @param {string} envKey @returns {boolean} */
|
|
27
29
|
const lowerKeyValidator = (envKey) => ((0, exports.nextKeyValidator)(envKey) &&
|
|
28
30
|
/^[^A-Z]*$/.test(envKey));
|
|
29
31
|
exports.lowerKeyValidator = lowerKeyValidator;
|
|
32
|
+
/** @param {string} envKey @returns {boolean} */
|
|
30
33
|
const publicKeyValidator = (envKey) => (exports.ENV_PREFIXES.some((envPrefix) => envKey === null || envKey === void 0 ? void 0 : envKey.startsWith(envPrefix)) ||
|
|
31
34
|
['NODE_ENV', 'PORT', 'ENVIRONMENT', 'DEBUG', 'SCOPES', 'SHOPIFY_API_SCOPES'].includes(envKey));
|
|
32
35
|
exports.publicKeyValidator = publicKeyValidator;
|
|
33
36
|
// TODO: move to processBatch???
|
|
37
|
+
/** @param {Record<string, string | undefined> | undefined} _env @returns {Record<string, string>} */
|
|
34
38
|
const stringifyEnv = (_env) => (Object.entries(_env !== null && _env !== void 0 ? _env : {}).reduce((__env, [key, val]) => (Object.assign(Object.assign({}, __env), {
|
|
35
39
|
// NOTE: DefinePlugin requires stringified
|
|
36
40
|
[key]: JSON.stringify(val) })), /** @type {Record<string, string>} */ ({})));
|
|
37
41
|
// TODO: move to processBatch???
|
|
42
|
+
/**
|
|
43
|
+
* @param {Record<string, string | undefined> | undefined} _env
|
|
44
|
+
* @param {(envKey: string) => boolean} [keyValidator]
|
|
45
|
+
* @returns {Record<string, string | undefined>}
|
|
46
|
+
*/
|
|
38
47
|
const cleanEnv = (_env, keyValidator = exports.nextKeyValidator) => (Object.entries(_env !== null && _env !== void 0 ? _env : []).reduce((__env, [key, val]) => (Object.assign(Object.assign({}, __env), keyValidator(key) && {
|
|
39
48
|
[key]: val,
|
|
40
|
-
})), /** @type {Record<string, string>} */ ({})));
|
|
49
|
+
})), /** @type {Record<string, string | undefined>} */ ({})));
|
|
50
|
+
/**
|
|
51
|
+
* @param {Record<string, string | undefined> | undefined} _env
|
|
52
|
+
* @param {(envKey: string) => boolean} [keyValidator]
|
|
53
|
+
* @returns {Record<string, string | undefined>}
|
|
54
|
+
*/
|
|
41
55
|
const cleanLowerEnv = (_env, keyValidator = exports.lowerKeyValidator) => (cleanEnv(process.env, keyValidator));
|
|
42
56
|
exports.cleanLowerEnv = cleanLowerEnv;
|
|
57
|
+
/**
|
|
58
|
+
* @param {Record<string, string | undefined> | undefined} _env
|
|
59
|
+
* @param {(envKey: string) => boolean} [keyValidator]
|
|
60
|
+
* @returns {Record<string, string | undefined>}
|
|
61
|
+
*/
|
|
43
62
|
const cleanPublicEnv = (_env, keyValidator = exports.publicKeyValidator) => (cleanEnv(_env, keyValidator));
|
|
44
63
|
exports.cleanPublicEnv = cleanPublicEnv;
|
|
45
64
|
const parseEnvData = (_env = process.env) => {
|
|
65
|
+
var _a;
|
|
46
66
|
const { ENVIRONMENT, SITE_ENV, BUILD_ENV, NODE_ENV } = _env;
|
|
47
|
-
|
|
67
|
+
// NOTE: the trailing ?? mirrors the 'development' already last in the list — find() is always
|
|
68
|
+
// satisfied by it, but the fallback is what lets this type as string rather than string|undefined.
|
|
69
|
+
const _environment = (_a = [SITE_ENV, BUILD_ENV, NODE_ENV, 'development'].find((value) => (0, display_js_1.stringNotEmptyOnly)(value))) !== null && _a !== void 0 ? _a : 'development';
|
|
48
70
|
// NOTE: annotated so the index signature survives the spread — without it consumers get
|
|
49
71
|
// a type with only ENVIRONMENT on it and every other `env.SOME_VAR` lookup is an error.
|
|
50
72
|
/** @type {Record<string, string> & { ENVIRONMENT: string }} */
|
|
51
73
|
const mergedEnv = Object.assign(Object.assign({}, _env), {
|
|
52
74
|
// NOTE: intentionally giving precedence to ENVIRONMENT
|
|
53
75
|
ENVIRONMENT: ENVIRONMENT || _environment });
|
|
54
|
-
const
|
|
76
|
+
const _b = process.argv.reduce(({ args: _args, argParams: _argParams, }, arg) => {
|
|
55
77
|
var _a, _b, _c, _d, _e;
|
|
56
78
|
// NOTE: split on the FIRST '=' only — everything after it is the value, verbatim.
|
|
57
79
|
// Splitting on every '=' truncated any value that contained one, so `--context=env=prod`
|
|
@@ -67,12 +89,13 @@ const parseEnvData = (_env = process.env) => {
|
|
|
67
89
|
argParams: _argParams,
|
|
68
90
|
};
|
|
69
91
|
}
|
|
92
|
+
/** @type {[string, string | undefined]} */
|
|
70
93
|
let entry = [_param, _value];
|
|
71
94
|
// NOTE: this handles serverless args similar to "--param=env=development" — the value is
|
|
72
95
|
// itself a key=value pair, so it splits on its own first '=' for the same reason.
|
|
73
96
|
if (_param === 'param') {
|
|
74
97
|
const valueSeparatorIndex = (_e = (_d = _value === null || _value === void 0 ? void 0 : _value.indexOf) === null || _d === void 0 ? void 0 : _d.call(_value, '=')) !== null && _e !== void 0 ? _e : -1;
|
|
75
|
-
if (valueSeparatorIndex > 0) {
|
|
98
|
+
if (_value && (valueSeparatorIndex > 0)) {
|
|
76
99
|
entry = [_value.slice(0, valueSeparatorIndex), _value.slice(valueSeparatorIndex + 1)];
|
|
77
100
|
}
|
|
78
101
|
}
|
|
@@ -89,14 +112,20 @@ const parseEnvData = (_env = process.env) => {
|
|
|
89
112
|
}, {
|
|
90
113
|
args: /** @type {string[]} */ ([]),
|
|
91
114
|
argParams: /** @type {Record<string, string>} */ ({}),
|
|
92
|
-
}), { argParams } =
|
|
115
|
+
}), { argParams } = _b, output = __rest(_b, ["argParams"]);
|
|
93
116
|
const nextEnv = cleanEnv(mergedEnv);
|
|
94
117
|
const publicEnv = (0, exports.cleanPublicEnv)(mergedEnv);
|
|
95
118
|
return Object.assign(Object.assign({}, output), { env: mergedEnv, nextEnv,
|
|
96
119
|
publicEnv, stringifiedEnv: stringifyEnv(publicEnv), argParams, params: Object.assign(Object.assign({}, mergedEnv), argParams) });
|
|
97
120
|
};
|
|
98
121
|
exports.parseEnvData = parseEnvData;
|
|
122
|
+
/**
|
|
123
|
+
* @param {Record<string, string | undefined> | undefined} publicEnv
|
|
124
|
+
* @param {string} key
|
|
125
|
+
* @returns {string | undefined}
|
|
126
|
+
*/
|
|
99
127
|
const getPublicEnvValue = (publicEnv, key) => {
|
|
128
|
+
/** @type {string | undefined} */
|
|
100
129
|
let envValue;
|
|
101
130
|
if ((0, display_js_1.stringEmptyOnly)(key) || !publicEnv) {
|
|
102
131
|
return envValue;
|
|
@@ -128,6 +157,15 @@ const getPublicEnvValue = (publicEnv, key) => {
|
|
|
128
157
|
return envValue;
|
|
129
158
|
};
|
|
130
159
|
exports.getPublicEnvValue = getPublicEnvValue;
|
|
160
|
+
/**
|
|
161
|
+
* @param {unknown} replaceable
|
|
162
|
+
* @param {{
|
|
163
|
+
* env?: Record<string, string | undefined>,
|
|
164
|
+
* template?: RegExp,
|
|
165
|
+
* callback?: (replacedValue: string, replaceable: string) => string,
|
|
166
|
+
* }} [options]
|
|
167
|
+
* @returns {string}
|
|
168
|
+
*/
|
|
131
169
|
const replaceEnvTemplate = (replaceable, { env: _env = process.env, template = /\{\{process\.env\.(\w+)\}\}/g,
|
|
132
170
|
// NOTE: the second arg is the matched token — declared so the default's signature matches
|
|
133
171
|
// how it is actually invoked below, even though the default ignores it.
|
|
@@ -136,6 +174,6 @@ callback = (replacedValue, _replaceable) => replacedValue, } = {}) => ((0, displ
|
|
|
136
174
|
if ((0, display_js_1.stringEmptyOnly)(replacedValue)) {
|
|
137
175
|
return replaceable;
|
|
138
176
|
}
|
|
139
|
-
return callback(replacedValue, replaceable);
|
|
177
|
+
return callback(/** @type {string} */ (replacedValue), replaceable);
|
|
140
178
|
}));
|
|
141
179
|
exports.replaceEnvTemplate = replaceEnvTemplate;
|
package/dist/esm/display.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// HMMM: what if 'string' is an object?
|
|
2
|
+
/** @param {unknown} string @returns {string} */
|
|
2
3
|
export const ensureStringOnly = (string) => (
|
|
3
4
|
// eslint-disable-next-line eqeqeq
|
|
4
5
|
(string != undefined) ? `${string}` : '');
|
|
6
|
+
/** @param {unknown} stringable @returns {boolean} */
|
|
5
7
|
export const stringNotEmptyOnly = (stringable) => {
|
|
6
8
|
const string = ensureStringOnly(stringable);
|
|
7
9
|
return ((string.length > 0) && !['null', 'undefined'].includes(string));
|
|
8
10
|
};
|
|
11
|
+
/** @param {unknown} stringable @returns {boolean} */
|
|
9
12
|
export const stringEmptyOnly = (stringable) => (!stringNotEmptyOnly(stringable));
|
package/dist/esm/env.js
CHANGED
|
@@ -17,33 +17,55 @@ export const ENV_PREFIX = {
|
|
|
17
17
|
DEFAULT: 'PUBLIC_',
|
|
18
18
|
};
|
|
19
19
|
export const ENV_PREFIXES = Object.values(ENV_PREFIX);
|
|
20
|
+
/** @param {string} envKey @returns {boolean} */
|
|
20
21
|
export const nextKeyValidator = (envKey) => (
|
|
21
22
|
// NOTE: not allowed by NEXT: https://nextjs.org/docs/messages/env-key-not-allowed
|
|
22
23
|
!(envKey.startsWith('__') || envKey.startsWith('NODE_')));
|
|
24
|
+
/** @param {string} envKey @returns {boolean} */
|
|
23
25
|
export const lowerKeyValidator = (envKey) => (nextKeyValidator(envKey) &&
|
|
24
26
|
/^[^A-Z]*$/.test(envKey));
|
|
27
|
+
/** @param {string} envKey @returns {boolean} */
|
|
25
28
|
export const publicKeyValidator = (envKey) => (ENV_PREFIXES.some((envPrefix) => envKey === null || envKey === void 0 ? void 0 : envKey.startsWith(envPrefix)) ||
|
|
26
29
|
['NODE_ENV', 'PORT', 'ENVIRONMENT', 'DEBUG', 'SCOPES', 'SHOPIFY_API_SCOPES'].includes(envKey));
|
|
27
30
|
// TODO: move to processBatch???
|
|
31
|
+
/** @param {Record<string, string | undefined> | undefined} _env @returns {Record<string, string>} */
|
|
28
32
|
const stringifyEnv = (_env) => (Object.entries(_env !== null && _env !== void 0 ? _env : {}).reduce((__env, [key, val]) => (Object.assign(Object.assign({}, __env), {
|
|
29
33
|
// NOTE: DefinePlugin requires stringified
|
|
30
34
|
[key]: JSON.stringify(val) })), /** @type {Record<string, string>} */ ({})));
|
|
31
35
|
// TODO: move to processBatch???
|
|
36
|
+
/**
|
|
37
|
+
* @param {Record<string, string | undefined> | undefined} _env
|
|
38
|
+
* @param {(envKey: string) => boolean} [keyValidator]
|
|
39
|
+
* @returns {Record<string, string | undefined>}
|
|
40
|
+
*/
|
|
32
41
|
const cleanEnv = (_env, keyValidator = nextKeyValidator) => (Object.entries(_env !== null && _env !== void 0 ? _env : []).reduce((__env, [key, val]) => (Object.assign(Object.assign({}, __env), keyValidator(key) && {
|
|
33
42
|
[key]: val,
|
|
34
|
-
})), /** @type {Record<string, string>} */ ({})));
|
|
43
|
+
})), /** @type {Record<string, string | undefined>} */ ({})));
|
|
44
|
+
/**
|
|
45
|
+
* @param {Record<string, string | undefined> | undefined} _env
|
|
46
|
+
* @param {(envKey: string) => boolean} [keyValidator]
|
|
47
|
+
* @returns {Record<string, string | undefined>}
|
|
48
|
+
*/
|
|
35
49
|
export const cleanLowerEnv = (_env, keyValidator = lowerKeyValidator) => (cleanEnv(process.env, keyValidator));
|
|
50
|
+
/**
|
|
51
|
+
* @param {Record<string, string | undefined> | undefined} _env
|
|
52
|
+
* @param {(envKey: string) => boolean} [keyValidator]
|
|
53
|
+
* @returns {Record<string, string | undefined>}
|
|
54
|
+
*/
|
|
36
55
|
export const cleanPublicEnv = (_env, keyValidator = publicKeyValidator) => (cleanEnv(_env, keyValidator));
|
|
37
56
|
export const parseEnvData = (_env = process.env) => {
|
|
57
|
+
var _a;
|
|
38
58
|
const { ENVIRONMENT, SITE_ENV, BUILD_ENV, NODE_ENV } = _env;
|
|
39
|
-
|
|
59
|
+
// NOTE: the trailing ?? mirrors the 'development' already last in the list — find() is always
|
|
60
|
+
// satisfied by it, but the fallback is what lets this type as string rather than string|undefined.
|
|
61
|
+
const _environment = (_a = [SITE_ENV, BUILD_ENV, NODE_ENV, 'development'].find((value) => stringNotEmptyOnly(value))) !== null && _a !== void 0 ? _a : 'development';
|
|
40
62
|
// NOTE: annotated so the index signature survives the spread — without it consumers get
|
|
41
63
|
// a type with only ENVIRONMENT on it and every other `env.SOME_VAR` lookup is an error.
|
|
42
64
|
/** @type {Record<string, string> & { ENVIRONMENT: string }} */
|
|
43
65
|
const mergedEnv = Object.assign(Object.assign({}, _env), {
|
|
44
66
|
// NOTE: intentionally giving precedence to ENVIRONMENT
|
|
45
67
|
ENVIRONMENT: ENVIRONMENT || _environment });
|
|
46
|
-
const
|
|
68
|
+
const _b = process.argv.reduce(({ args: _args, argParams: _argParams, }, arg) => {
|
|
47
69
|
var _a, _b, _c, _d, _e;
|
|
48
70
|
// NOTE: split on the FIRST '=' only — everything after it is the value, verbatim.
|
|
49
71
|
// Splitting on every '=' truncated any value that contained one, so `--context=env=prod`
|
|
@@ -59,12 +81,13 @@ export const parseEnvData = (_env = process.env) => {
|
|
|
59
81
|
argParams: _argParams,
|
|
60
82
|
};
|
|
61
83
|
}
|
|
84
|
+
/** @type {[string, string | undefined]} */
|
|
62
85
|
let entry = [_param, _value];
|
|
63
86
|
// NOTE: this handles serverless args similar to "--param=env=development" — the value is
|
|
64
87
|
// itself a key=value pair, so it splits on its own first '=' for the same reason.
|
|
65
88
|
if (_param === 'param') {
|
|
66
89
|
const valueSeparatorIndex = (_e = (_d = _value === null || _value === void 0 ? void 0 : _value.indexOf) === null || _d === void 0 ? void 0 : _d.call(_value, '=')) !== null && _e !== void 0 ? _e : -1;
|
|
67
|
-
if (valueSeparatorIndex > 0) {
|
|
90
|
+
if (_value && (valueSeparatorIndex > 0)) {
|
|
68
91
|
entry = [_value.slice(0, valueSeparatorIndex), _value.slice(valueSeparatorIndex + 1)];
|
|
69
92
|
}
|
|
70
93
|
}
|
|
@@ -81,13 +104,19 @@ export const parseEnvData = (_env = process.env) => {
|
|
|
81
104
|
}, {
|
|
82
105
|
args: /** @type {string[]} */ ([]),
|
|
83
106
|
argParams: /** @type {Record<string, string>} */ ({}),
|
|
84
|
-
}), { argParams } =
|
|
107
|
+
}), { argParams } = _b, output = __rest(_b, ["argParams"]);
|
|
85
108
|
const nextEnv = cleanEnv(mergedEnv);
|
|
86
109
|
const publicEnv = cleanPublicEnv(mergedEnv);
|
|
87
110
|
return Object.assign(Object.assign({}, output), { env: mergedEnv, nextEnv,
|
|
88
111
|
publicEnv, stringifiedEnv: stringifyEnv(publicEnv), argParams, params: Object.assign(Object.assign({}, mergedEnv), argParams) });
|
|
89
112
|
};
|
|
113
|
+
/**
|
|
114
|
+
* @param {Record<string, string | undefined> | undefined} publicEnv
|
|
115
|
+
* @param {string} key
|
|
116
|
+
* @returns {string | undefined}
|
|
117
|
+
*/
|
|
90
118
|
export const getPublicEnvValue = (publicEnv, key) => {
|
|
119
|
+
/** @type {string | undefined} */
|
|
91
120
|
let envValue;
|
|
92
121
|
if (stringEmptyOnly(key) || !publicEnv) {
|
|
93
122
|
return envValue;
|
|
@@ -118,6 +147,15 @@ export const getPublicEnvValue = (publicEnv, key) => {
|
|
|
118
147
|
}
|
|
119
148
|
return envValue;
|
|
120
149
|
};
|
|
150
|
+
/**
|
|
151
|
+
* @param {unknown} replaceable
|
|
152
|
+
* @param {{
|
|
153
|
+
* env?: Record<string, string | undefined>,
|
|
154
|
+
* template?: RegExp,
|
|
155
|
+
* callback?: (replacedValue: string, replaceable: string) => string,
|
|
156
|
+
* }} [options]
|
|
157
|
+
* @returns {string}
|
|
158
|
+
*/
|
|
121
159
|
export const replaceEnvTemplate = (replaceable, { env: _env = process.env, template = /\{\{process\.env\.(\w+)\}\}/g,
|
|
122
160
|
// NOTE: the second arg is the matched token — declared so the default's signature matches
|
|
123
161
|
// how it is actually invoked below, even though the default ignores it.
|
|
@@ -126,5 +164,5 @@ callback = (replacedValue, _replaceable) => replacedValue, } = {}) => (ensureStr
|
|
|
126
164
|
if (stringEmptyOnly(replacedValue)) {
|
|
127
165
|
return replaceable;
|
|
128
166
|
}
|
|
129
|
-
return callback(replacedValue, replaceable);
|
|
167
|
+
return callback(/** @type {string} */ (replacedValue), replaceable);
|
|
130
168
|
}));
|
package/dist/esm/project.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ensureStringOnly } from './display.js';
|
|
2
|
+
/** @param {unknown} _name */
|
|
2
3
|
export const parseProjectName = (_name) => {
|
|
3
4
|
var _a;
|
|
4
5
|
const name = ensureStringOnly(_name);
|
|
@@ -11,6 +12,29 @@ export const parseProjectName = (_name) => {
|
|
|
11
12
|
projectName,
|
|
12
13
|
};
|
|
13
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* The subset of a package.json this reads. Everything is optional — callers pass raw
|
|
17
|
+
* manifests, and the parser is deliberately tolerant of a missing or partial object.
|
|
18
|
+
*
|
|
19
|
+
* @typedef {object} PackageInfo
|
|
20
|
+
* @property {string} [name]
|
|
21
|
+
* @property {string} [version]
|
|
22
|
+
* @property {string[]} [keywords]
|
|
23
|
+
* @property {string} [owner]
|
|
24
|
+
* @property {string} [appName]
|
|
25
|
+
* @property {string} [siteName]
|
|
26
|
+
* @property {string} [shortName]
|
|
27
|
+
* @property {string} [siteHandle]
|
|
28
|
+
* @property {string} [siteAuthor]
|
|
29
|
+
* @property {Record<string, string>} [dependencies]
|
|
30
|
+
* @property {Record<string, string>} [devDependencies]
|
|
31
|
+
* @property {Record<string, string>} [peerDependencies]
|
|
32
|
+
* @property {Record<string, string>} [optionalDependencies]
|
|
33
|
+
* @property {string[]} [bundleDependencies]
|
|
34
|
+
* @property {string[]} [bundledDependencies]
|
|
35
|
+
* @property {string[]} [browserDependencies]
|
|
36
|
+
*/
|
|
37
|
+
/** @param {PackageInfo} [packageInfo] */
|
|
14
38
|
export const parsePackageInfo = (packageInfo) => {
|
|
15
39
|
const { version, keywords, shortName, siteHandle, siteAuthor, devDependencies, peerDependencies, bundleDependencies, bundledDependencies = bundleDependencies, dependencies: runtimeDependencies, optionalDependencies, browserDependencies, name: _name, owner: _appOwner, appName: _appName, siteName: _siteName, } = packageInfo !== null && packageInfo !== void 0 ? packageInfo : {};
|
|
16
40
|
const { name, organization, projectName } = parseProjectName(_name);
|
package/dist/project.d.ts
CHANGED
|
@@ -1,24 +1,46 @@
|
|
|
1
|
-
export function parseProjectName(_name:
|
|
1
|
+
export function parseProjectName(_name: unknown): {
|
|
2
2
|
name: string;
|
|
3
3
|
parts: string[];
|
|
4
4
|
organization: string;
|
|
5
5
|
projectName: string;
|
|
6
6
|
};
|
|
7
|
-
export function parsePackageInfo(packageInfo
|
|
8
|
-
keywords:
|
|
9
|
-
appOwner:
|
|
10
|
-
appName:
|
|
11
|
-
version:
|
|
12
|
-
siteName:
|
|
13
|
-
shortName:
|
|
14
|
-
siteHandle:
|
|
15
|
-
siteAuthor:
|
|
7
|
+
export function parsePackageInfo(packageInfo?: PackageInfo): [{
|
|
8
|
+
keywords: string[] | undefined;
|
|
9
|
+
appOwner: string;
|
|
10
|
+
appName: string;
|
|
11
|
+
version: string | undefined;
|
|
12
|
+
siteName: string;
|
|
13
|
+
shortName: string | undefined;
|
|
14
|
+
siteHandle: string | undefined;
|
|
15
|
+
siteAuthor: string | undefined;
|
|
16
16
|
companyName: string;
|
|
17
17
|
projectName: string;
|
|
18
|
-
devDependencies:
|
|
19
|
-
peerDependencies:
|
|
20
|
-
bundledDependencies:
|
|
21
|
-
runtimeDependencies:
|
|
22
|
-
browserDependencies:
|
|
23
|
-
optionalDependencies:
|
|
24
|
-
}, string, string];
|
|
18
|
+
devDependencies: Record<string, string> | undefined;
|
|
19
|
+
peerDependencies: Record<string, string> | undefined;
|
|
20
|
+
bundledDependencies: string[] | undefined;
|
|
21
|
+
runtimeDependencies: Record<string, string> | undefined;
|
|
22
|
+
browserDependencies: string[] | undefined;
|
|
23
|
+
optionalDependencies: Record<string, string> | undefined;
|
|
24
|
+
}, string | undefined, string];
|
|
25
|
+
/**
|
|
26
|
+
* The subset of a package.json this reads. Everything is optional — callers pass raw
|
|
27
|
+
* manifests, and the parser is deliberately tolerant of a missing or partial object.
|
|
28
|
+
*/
|
|
29
|
+
export type PackageInfo = {
|
|
30
|
+
name?: string | undefined;
|
|
31
|
+
version?: string | undefined;
|
|
32
|
+
keywords?: string[] | undefined;
|
|
33
|
+
owner?: string | undefined;
|
|
34
|
+
appName?: string | undefined;
|
|
35
|
+
siteName?: string | undefined;
|
|
36
|
+
shortName?: string | undefined;
|
|
37
|
+
siteHandle?: string | undefined;
|
|
38
|
+
siteAuthor?: string | undefined;
|
|
39
|
+
dependencies?: Record<string, string> | undefined;
|
|
40
|
+
devDependencies?: Record<string, string> | undefined;
|
|
41
|
+
peerDependencies?: Record<string, string> | undefined;
|
|
42
|
+
optionalDependencies?: Record<string, string> | undefined;
|
|
43
|
+
bundleDependencies?: string[] | undefined;
|
|
44
|
+
bundledDependencies?: string[] | undefined;
|
|
45
|
+
browserDependencies?: string[] | undefined;
|
|
46
|
+
};
|
package/dist/project.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parsePackageInfo = exports.parseProjectName = void 0;
|
|
4
4
|
const display_js_1 = require("./display.js");
|
|
5
|
+
/** @param {unknown} _name */
|
|
5
6
|
const parseProjectName = (_name) => {
|
|
6
7
|
var _a;
|
|
7
8
|
const name = (0, display_js_1.ensureStringOnly)(_name);
|
|
@@ -15,6 +16,29 @@ const parseProjectName = (_name) => {
|
|
|
15
16
|
};
|
|
16
17
|
};
|
|
17
18
|
exports.parseProjectName = parseProjectName;
|
|
19
|
+
/**
|
|
20
|
+
* The subset of a package.json this reads. Everything is optional — callers pass raw
|
|
21
|
+
* manifests, and the parser is deliberately tolerant of a missing or partial object.
|
|
22
|
+
*
|
|
23
|
+
* @typedef {object} PackageInfo
|
|
24
|
+
* @property {string} [name]
|
|
25
|
+
* @property {string} [version]
|
|
26
|
+
* @property {string[]} [keywords]
|
|
27
|
+
* @property {string} [owner]
|
|
28
|
+
* @property {string} [appName]
|
|
29
|
+
* @property {string} [siteName]
|
|
30
|
+
* @property {string} [shortName]
|
|
31
|
+
* @property {string} [siteHandle]
|
|
32
|
+
* @property {string} [siteAuthor]
|
|
33
|
+
* @property {Record<string, string>} [dependencies]
|
|
34
|
+
* @property {Record<string, string>} [devDependencies]
|
|
35
|
+
* @property {Record<string, string>} [peerDependencies]
|
|
36
|
+
* @property {Record<string, string>} [optionalDependencies]
|
|
37
|
+
* @property {string[]} [bundleDependencies]
|
|
38
|
+
* @property {string[]} [bundledDependencies]
|
|
39
|
+
* @property {string[]} [browserDependencies]
|
|
40
|
+
*/
|
|
41
|
+
/** @param {PackageInfo} [packageInfo] */
|
|
18
42
|
const parsePackageInfo = (packageInfo) => {
|
|
19
43
|
const { version, keywords, shortName, siteHandle, siteAuthor, devDependencies, peerDependencies, bundleDependencies, bundledDependencies = bundleDependencies, dependencies: runtimeDependencies, optionalDependencies, browserDependencies, name: _name, owner: _appOwner, appName: _appName, siteName: _siteName, } = packageInfo !== null && packageInfo !== void 0 ? packageInfo : {};
|
|
20
44
|
const { name, organization, projectName } = (0, exports.parseProjectName)(_name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agnostack/env",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"author": "agnoStack Dev <developers@agnostack.com> (https://agnostack.com)",
|
|
5
5
|
"owner": "agnoStack",
|
|
6
6
|
"description": "Please contact agnoStack via info@agnostack.com for any questions",
|
|
@@ -36,52 +36,52 @@
|
|
|
36
36
|
"*.md"
|
|
37
37
|
],
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
39
|
+
"node": ">=22.x"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"tsc": "npx -p typescript tsc",
|
|
43
|
-
"watch": "yarn tsc -w",
|
|
44
|
-
"prebuild": "yarn tsc
|
|
45
|
-
"build": "yarn tsc && yarn tsc -p tsconfig.esm.json && node scripts/write-esm-pkg.mjs",
|
|
46
|
-
"clean": "
|
|
43
|
+
"watch": "yarn tsc -p tsconfig.build.json -w",
|
|
44
|
+
"prebuild": "yarn tsc -b tsconfig.build.json --clean && node scripts/clean.mjs dist _storage",
|
|
45
|
+
"build": "yarn tsc -p tsconfig.build.json && yarn tsc -p tsconfig.esm.json && node scripts/write-esm-pkg.mjs",
|
|
46
|
+
"clean": "node scripts/clean.mjs dist node_modules _storage",
|
|
47
47
|
"clean:install": "yarn clean && yarn install --force",
|
|
48
|
-
"lint": "eslint
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
48
|
+
"lint:fix": "eslint . --fix",
|
|
49
|
+
"lint": "eslint .",
|
|
50
|
+
"typecheck": "yarn tsc",
|
|
51
|
+
"verify:dist": "node scripts/verify-dist.mjs",
|
|
52
|
+
"test:watch": "vitest",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"release": "semantic-release",
|
|
52
55
|
"release:debug": "yarn release --debug",
|
|
53
|
-
"
|
|
56
|
+
"prepublishOnly": "yarn verify:dist",
|
|
57
|
+
"prepare": "husky"
|
|
54
58
|
},
|
|
55
59
|
"lint-staged": {
|
|
56
60
|
"{src,test,types}/**/*.{js,ts}": [
|
|
57
61
|
"eslint --fix"
|
|
58
62
|
]
|
|
59
63
|
},
|
|
64
|
+
"sideEffects": false,
|
|
60
65
|
"devDependencies": {
|
|
61
|
-
"@commitlint/cli": "
|
|
62
|
-
"@commitlint/config-conventional": "
|
|
66
|
+
"@commitlint/cli": "19.x",
|
|
67
|
+
"@commitlint/config-conventional": "19.x",
|
|
68
|
+
"@eslint/js": "9.x",
|
|
63
69
|
"@semantic-release/changelog": "6.0.3",
|
|
64
70
|
"@semantic-release/git": "10.0.1",
|
|
65
|
-
"@semantic-release/github": "
|
|
66
|
-
"@semantic-release/npm": "
|
|
67
|
-
"@semantic-release/release-notes-generator": "
|
|
68
|
-
"@types/
|
|
69
|
-
"@
|
|
70
|
-
"@typescript-eslint/
|
|
71
|
-
"
|
|
72
|
-
"eslint": "
|
|
73
|
-
"
|
|
74
|
-
"husky": "
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"ts-jest": "29.x",
|
|
80
|
-
"typescript": "5.4.2"
|
|
81
|
-
},
|
|
82
|
-
"resolutions": {
|
|
83
|
-
"**/npm": "10.8.2",
|
|
84
|
-
"**/rimraf": "4.4.1"
|
|
71
|
+
"@semantic-release/github": "11.x",
|
|
72
|
+
"@semantic-release/npm": "12.x",
|
|
73
|
+
"@semantic-release/release-notes-generator": "14.x",
|
|
74
|
+
"@types/node": "22.x",
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "8.x",
|
|
76
|
+
"@typescript-eslint/parser": "8.x",
|
|
77
|
+
"eslint": "9.x",
|
|
78
|
+
"eslint-plugin-import": "2.x",
|
|
79
|
+
"globals": "16.x",
|
|
80
|
+
"husky": "9.x",
|
|
81
|
+
"lint-staged": "15.x",
|
|
82
|
+
"semantic-release": "25.x",
|
|
83
|
+
"typescript": "5.9.3",
|
|
84
|
+
"vitest": "3.x"
|
|
85
85
|
},
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public"
|