@powerlines/plugin-env 0.16.324 → 0.16.325
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/babel/plugin.cjs +2 -2
- package/dist/babel/plugin.mjs +2 -2
- package/dist/babel/plugin.mjs.map +1 -1
- package/dist/helpers/load.d.cts +2 -2
- package/dist/helpers/load.d.mts +2 -2
- package/dist/helpers/schema.cjs +24 -16
- package/dist/helpers/schema.d.cts.map +1 -1
- package/dist/helpers/schema.d.mts.map +1 -1
- package/dist/helpers/schema.mjs +24 -16
- package/dist/helpers/schema.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/babel/plugin.cjs
CHANGED
|
@@ -18,13 +18,13 @@ const envBabelPlugin = (_powerlines_plugin_babel_helpers_create_plugin.createBab
|
|
|
18
18
|
const name = node.name.replace(new RegExp(`^(${context.config.env.prefix.join("|")})_`), "");
|
|
19
19
|
logger.trace({
|
|
20
20
|
meta: { category: "env" },
|
|
21
|
-
message: `Environment variable
|
|
21
|
+
message: `Environment variable \`${name}\` found in ${pass.filename || "unknown file"}.`
|
|
22
22
|
});
|
|
23
23
|
if (name in config && (0, _stryke_type_checks_is_set_object.isSetObject)(config[name]) && !config[name]?.ignore) {
|
|
24
24
|
config[name] ??= {};
|
|
25
25
|
logger.debug({
|
|
26
26
|
meta: { category: "env" },
|
|
27
|
-
message: `The
|
|
27
|
+
message: `The \`${name}\` environment variable is used in the source code file "${pass.filename || "unknown file"}" and will be added to the environment schema's active variables list.`
|
|
28
28
|
});
|
|
29
29
|
context.env.config.active.push(name);
|
|
30
30
|
if (!config[name]?.runtime && (context.config.env.inject && isInjectable || context.config.env.validate)) {
|
package/dist/babel/plugin.mjs
CHANGED
|
@@ -17,13 +17,13 @@ const envBabelPlugin = (createBabelPlugin.Ω = [[() => __ΩEnvPluginContext, "n!
|
|
|
17
17
|
const name = node.name.replace(new RegExp(`^(${context.config.env.prefix.join("|")})_`), "");
|
|
18
18
|
logger.trace({
|
|
19
19
|
meta: { category: "env" },
|
|
20
|
-
message: `Environment variable
|
|
20
|
+
message: `Environment variable \`${name}\` found in ${pass.filename || "unknown file"}.`
|
|
21
21
|
});
|
|
22
22
|
if (name in config && isSetObject(config[name]) && !config[name]?.ignore) {
|
|
23
23
|
config[name] ??= {};
|
|
24
24
|
logger.debug({
|
|
25
25
|
meta: { category: "env" },
|
|
26
|
-
message: `The
|
|
26
|
+
message: `The \`${name}\` environment variable is used in the source code file "${pass.filename || "unknown file"}" and will be added to the environment schema's active variables list.`
|
|
27
27
|
});
|
|
28
28
|
context.env.config.active.push(name);
|
|
29
29
|
if (!config[name]?.runtime && (context.config.env.inject && isInjectable || context.config.env.validate)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../../src/babel/plugin.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { NodePath } from \"@babel/core\";\nimport * as t from \"@babel/types\";\nimport { createBabelPlugin } from \"@powerlines/plugin-babel/helpers/create-plugin\";\nimport { addImport } from \"@powerlines/plugin-babel/helpers/module-helpers\";\nimport { BabelPluginPass } from \"@powerlines/plugin-babel/types/config\";\nimport { getProperties } from \"@powerlines/schema\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport { EnvPluginContext } from \"../types/plugin\";\n\n/*\n * The Powerlines - Environment Configuration Babel Plugin\n *\n * @param babel - The Babel core module\n * @returns The Babel plugin object\n */\nexport const envBabelPlugin = createBabelPlugin<EnvPluginContext>(\n \"env\",\n ({ logger, context }) => {\n const config = getProperties(context.env.config);\n function extractEnv(\n node: t.Identifier,\n pass: BabelPluginPass,\n isInjectable = false\n ) {\n if (node.name) {\n const name = node.name.replace(\n new RegExp(`^(${context.config.env.prefix.join(\"|\")})_`),\n \"\"\n );\n\n logger.trace({\n meta: {\n category: \"env\"\n },\n message: `Environment variable
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../../src/babel/plugin.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { NodePath } from \"@babel/core\";\nimport * as t from \"@babel/types\";\nimport { createBabelPlugin } from \"@powerlines/plugin-babel/helpers/create-plugin\";\nimport { addImport } from \"@powerlines/plugin-babel/helpers/module-helpers\";\nimport { BabelPluginPass } from \"@powerlines/plugin-babel/types/config\";\nimport { getProperties } from \"@powerlines/schema\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport { EnvPluginContext } from \"../types/plugin\";\n\n/*\n * The Powerlines - Environment Configuration Babel Plugin\n *\n * @param babel - The Babel core module\n * @returns The Babel plugin object\n */\nexport const envBabelPlugin = createBabelPlugin<EnvPluginContext>(\n \"env\",\n ({ logger, context }) => {\n const config = getProperties(context.env.config);\n function extractEnv(\n node: t.Identifier,\n pass: BabelPluginPass,\n isInjectable = false\n ) {\n if (node.name) {\n const name = node.name.replace(\n new RegExp(`^(${context.config.env.prefix.join(\"|\")})_`),\n \"\"\n );\n\n logger.trace({\n meta: {\n category: \"env\"\n },\n message: `Environment variable \\`${name}\\` found in ${\n pass.filename || \"unknown file\"\n }.`\n });\n\n if (\n name in config &&\n isSetObject(config[name]) &&\n !config[name]?.ignore\n ) {\n config[name] ??= {} as any;\n\n logger.debug({\n meta: {\n category: \"env\"\n },\n message: `The \\`${name}\\` environment variable is used in the source code file \"${\n pass.filename || \"unknown file\"\n }\" and will be added to the environment schema's active variables list.`\n });\n\n context.env.config.active.push(name);\n if (\n !config[name]?.runtime &&\n ((context.config.env.inject && isInjectable) ||\n context.config.env.validate)\n ) {\n if (\n context.config.env.validate &&\n !config[name]?.required &&\n isUndefined(config[name]?.default)\n ) {\n throw new Error(\n `Environment variable \\`${\n name\n }\\` is missing a default value, but is active in the source code${\n pass.filename ? ` file \\`${pass.filename}\\`` : \"\"\n }.\\n\\nPlease add a default value to the schema, or if this variable is optional, please mark it as optional in the type definition.`\n );\n }\n }\n } else if (context.config.env.validate) {\n throw new Error(\n `Environment variable \\`${name}\\` is active in the source code${\n pass.filename ? ` file \\`${pass.filename}\\`` : \"\"\n }, but is not defined in the \\`config\\` schema. Please check the \\`env.config\\` configuration option. If you are using a custom env schema, please make sure that the configuration variable names match the ones used in the source code.`\n );\n } else {\n logger.warn({\n meta: {\n category: \"env\"\n },\n message: `Environment variable \\`${name}\\` is active in the source code${\n pass.filename ? ` file \\`${pass.filename}\\`` : \"\"\n }, but is not defined in the \\`config\\` schema. If this is intentional, you can ignore this warning. Otherwise, please check the \\`env.config\\` configuration option. If you are using a custom env schema, please make sure that the configuration variable names match the ones used in the source code.`\n });\n }\n }\n }\n\n return {\n visitor: {\n MemberExpression(\n path: NodePath<t.MemberExpression>,\n pass: BabelPluginPass\n ) {\n if (\n path\n .get(\"object\")\n ?.get(\"property\")\n ?.isIdentifier({ name: \"env\" }) &&\n path\n .get(\"object\")\n ?.get(\"object\")\n ?.isIdentifier({ name: \"process\" }) &&\n path.get(\"property\")?.isIdentifier()\n ) {\n // process.env.CONFIG_NAME\n\n const identifier = path.get(\"property\")?.node as t.Identifier;\n if (!identifier.name) {\n return;\n }\n\n extractEnv(identifier, pass, false);\n\n path.replaceWithSourceString(`env.${identifier.name}`);\n addImport(path, {\n module: `${context.config.framework?.name || \"powerlines\"}:env`,\n name: \"env\",\n imported: \"env\"\n });\n } else if (\n path\n .get(\"object\")\n ?.get(\"property\")\n ?.isIdentifier({ name: \"env\" }) &&\n path.get(\"object\")?.get(\"object\")?.isMetaProperty() &&\n path.get(\"property\")?.isIdentifier()\n ) {\n // import.meta.env.CONFIG_NAME\n\n const identifier = path.get(\"property\")?.node as t.Identifier;\n if (!identifier.name) {\n return;\n }\n\n extractEnv(identifier, pass, false);\n\n path.replaceWithSourceString(`env.${identifier.name}`);\n addImport(path, {\n module: `${context.config.framework?.name || \"powerlines\"}:env`,\n name: \"env\",\n imported: \"env\"\n });\n } else if (\n path.get(\"object\")?.isIdentifier({ name: \"env\" }) &&\n path.get(\"property\")?.isIdentifier()\n ) {\n // env.CONFIG_NAME\n\n const identifier = path.get(\"property\")?.node as t.Identifier;\n if (!identifier.name) {\n return;\n }\n\n extractEnv(identifier, pass, false);\n }\n }\n }\n };\n }\n);\n"],"mappings":";;;;;;;;AAEA,SAAS,aAAY,IAAK,MAAC;;CAE1B,OAAK;AACN;4HAaA,QACA,cACM;CACN,MAAQ,SAAC,cAAmB,QAAW,IAAA,MAAO;CAC9C,SAAS,WAAA,MAAkB,MAAO,eAAW,OAAO;EACpD,IAAQ,KAAC,MAAA;GACH,MAAG,OAAA,KAAc,KAAM,QAAQ,IAAI,OAAO,KAAI,QAAI,OAAO,IAAA,OAAA,KAAA,GAAA,EAAA,GAAA,GAAA,EAAA;GACzD,OAAG,MAAA;IACD,MAAC,kBAER;IACM,SAA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;;IAEF,QAAQ,GAAI,QAAO,OAAO,WAAU,QAAA,aAAA;IAClC,MAAC;IACD,UAAQ;GACV,CAAC;EACH,OAAM,IAAA,KAAQ,IAAM,QAAK,GAAA,IAAQ,UAAA,GAAA,aAAA,EAC/B,MAAE,MACJ,CAAC,KAAK,KAAC,IAAA,QAAA,GAAA,IAAA,QAAA,GAAA,eAAA,KAAA,KAAA,IAAA,UAAA,GAAA,aAAA,GAAA;GAEL,MAAK,aAAc,KAAA,IAAS,UAAC,GAAA;GAC7B,IAAI,CAAA,WAAY,MACd;GAEF,WAAO,YAAY,MAAU,KAAE;GAC/B,KAAK,wBAAG,OAAA,WAAA,MAAA;GACR,UAAU,MAAG;IACX,QAAM,GAAK,QAAQ,OAAK,WAAa,QAAC,aAAgB;IACtD,MAAM;IACN,UAAG;GACL,CAAC;EACH,OAAE,IAAA,KAAA,IAAA,QAAA,GAAA,aAAA,EACA,MAAK,MACP,CAAC,KAAC,KAAS,IAAC,UAAK,GAAA,aAAA,GAAA;GAEf,MAAI,aAAe,KAAG,IAAM,UAAQ,GAAA;GACpC,IAAI,CAAC,WAAW,MACf;GAED,WAAW,YAAC,MAAA,KAAA;EACd;CACF,GAAG;EAAC;EAAY;EAAM;EAAA;EAAA;CAAA,CAAA,EACxB,EACF;AACF,GAAG;CAAC;CAAU;CAAI;AAAS,CAAC,CAAC"}
|
package/dist/helpers/load.d.cts
CHANGED
|
@@ -24,11 +24,11 @@ declare function loadEnvFromContext(context: EnvPluginContext, parsed: DotenvPar
|
|
|
24
24
|
ERROR_URL: string | undefined;
|
|
25
25
|
ORGANIZATION: string | undefined;
|
|
26
26
|
PLATFORM: "node" | "browser" | "neutral";
|
|
27
|
-
MODE: "
|
|
27
|
+
MODE: "development" | "test" | "production";
|
|
28
28
|
TEST: boolean;
|
|
29
29
|
DEBUG: boolean;
|
|
30
30
|
STACKTRACE: boolean;
|
|
31
|
-
RUNTIME: "
|
|
31
|
+
RUNTIME: "browser" | "nodejs" | "workerd" | "edge" | undefined;
|
|
32
32
|
ENVIRONMENT: string;
|
|
33
33
|
};
|
|
34
34
|
declare function loadEnv<TEnv extends DotenvParseOutput = DotenvParseOutput>(context: EnvPluginContext, options?: EnvPluginOptions): Promise<TEnv>;
|
package/dist/helpers/load.d.mts
CHANGED
|
@@ -24,11 +24,11 @@ declare function loadEnvFromContext(context: EnvPluginContext, parsed: DotenvPar
|
|
|
24
24
|
ERROR_URL: string | undefined;
|
|
25
25
|
ORGANIZATION: string | undefined;
|
|
26
26
|
PLATFORM: "node" | "browser" | "neutral";
|
|
27
|
-
MODE: "
|
|
27
|
+
MODE: "development" | "test" | "production";
|
|
28
28
|
TEST: boolean;
|
|
29
29
|
DEBUG: boolean;
|
|
30
30
|
STACKTRACE: boolean;
|
|
31
|
-
RUNTIME: "
|
|
31
|
+
RUNTIME: "browser" | "nodejs" | "workerd" | "edge" | undefined;
|
|
32
32
|
ENVIRONMENT: string;
|
|
33
33
|
};
|
|
34
34
|
declare function loadEnv<TEnv extends DotenvParseOutput = DotenvParseOutput>(context: EnvPluginContext, options?: EnvPluginOptions): Promise<TEnv>;
|
package/dist/helpers/schema.cjs
CHANGED
|
@@ -194,14 +194,18 @@ async function extractEnv(context) {
|
|
|
194
194
|
property.alias ??= [];
|
|
195
195
|
const aliases = [...property.alias];
|
|
196
196
|
context.config.env.prefix.forEach(__assignType((prefix) => {
|
|
197
|
-
if (!property.alias.includes(`${prefix}_${property.name}`)) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
197
|
+
if (!property.alias.includes(`${prefix}_${property.name}`)) property.alias.push(`${prefix}_${property.name}`);
|
|
198
|
+
aliases.map(__assignType((alias) => `${prefix}_${alias}`, [
|
|
199
|
+
"alias",
|
|
200
|
+
"",
|
|
201
|
+
"P\"2!\"/\""
|
|
202
|
+
])).forEach(__assignType((prefixedAlias) => {
|
|
203
|
+
if (!property.alias.includes(prefixedAlias)) property.alias.push(prefixedAlias);
|
|
204
|
+
}, [
|
|
205
|
+
"prefixedAlias",
|
|
206
|
+
"",
|
|
207
|
+
"P\"2!\"/\""
|
|
208
|
+
]));
|
|
205
209
|
}, [
|
|
206
210
|
"prefix",
|
|
207
211
|
"",
|
|
@@ -216,14 +220,18 @@ async function extractEnv(context) {
|
|
|
216
220
|
property.alias ??= [];
|
|
217
221
|
const aliases = [...property.alias];
|
|
218
222
|
context.config.env.prefix.forEach(__assignType((prefix) => {
|
|
219
|
-
if (!property.alias.includes(`${prefix}_${property.name}`)) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
223
|
+
if (!property.alias.includes(`${prefix}_${property.name}`)) property.alias.push(`${prefix}_${property.name}`);
|
|
224
|
+
aliases.map(__assignType((alias) => `${prefix}_${alias}`, [
|
|
225
|
+
"alias",
|
|
226
|
+
"",
|
|
227
|
+
"P\"2!\"/\""
|
|
228
|
+
])).forEach(__assignType((prefixedAlias) => {
|
|
229
|
+
if (!property.alias.includes(prefixedAlias)) property.alias.push(prefixedAlias);
|
|
230
|
+
}, [
|
|
231
|
+
"prefixedAlias",
|
|
232
|
+
"",
|
|
233
|
+
"P\"2!\"/\""
|
|
234
|
+
]));
|
|
227
235
|
}, [
|
|
228
236
|
"prefix",
|
|
229
237
|
"",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.cts","names":[],"sources":["../../src/helpers/schema.ts"],"mappings":";;;;;;;AA6CA;;;;iBAAsB,sBAAA,kBACH,iBAAA,EACjB,OAAA,EAAS,QAAA,GAAW,OAAA;;;;;;;iBAiBA,gBAAA,kBAAkC,iBAAA,EACtD,OAAA,EAAS,QAAA,GACR,OAAA,CAAQ,aAAA;;;AAnBkB;AAiB7B;;iBAcsB,iBAAA,kBAAmC,iBAAA,EACvD,OAAA,EAAS,QAAA,GACR,OAAA,CAAQ,aAAA;;;;;;;iBAaK,iBAAA,kBAAmC,gBAAA,EACjD,OAAA,EAAS,QAAQ;AAAA,iBAKH,gBAAA,kBAAkC,gBAAA,EAChD,OAAA,EAAS,QAAQ,EACjB,OAAA;;;;;;AAnCsB;AAYxB;;;iBAsEsB,UAAA,kBAA4B,gBAAA,EAChD,OAAA,EAAS,QAAA,GACR,OAAA;;;;;;;
|
|
1
|
+
{"version":3,"file":"schema.d.cts","names":[],"sources":["../../src/helpers/schema.ts"],"mappings":";;;;;;;AA6CA;;;;iBAAsB,sBAAA,kBACH,iBAAA,EACjB,OAAA,EAAS,QAAA,GAAW,OAAA;;;;;;;iBAiBA,gBAAA,kBAAkC,iBAAA,EACtD,OAAA,EAAS,QAAA,GACR,OAAA,CAAQ,aAAA;;;AAnBkB;AAiB7B;;iBAcsB,iBAAA,kBAAmC,iBAAA,EACvD,OAAA,EAAS,QAAA,GACR,OAAA,CAAQ,aAAA;;;;;;;iBAaK,iBAAA,kBAAmC,gBAAA,EACjD,OAAA,EAAS,QAAQ;AAAA,iBAKH,gBAAA,kBAAkC,gBAAA,EAChD,OAAA,EAAS,QAAQ,EACjB,OAAA;;;;;;AAnCsB;AAYxB;;;iBAsEsB,UAAA,kBAA4B,gBAAA,EAChD,OAAA,EAAS,QAAA,GACR,OAAA;;;;;;;iBAsNmB,QAAA,kBAA0B,gBAAA,EAC9C,OAAA,EAAS,QAAA,GACR,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.mts","names":[],"sources":["../../src/helpers/schema.ts"],"mappings":";;;;;;;AA6CA;;;;iBAAsB,sBAAA,kBACH,iBAAA,EACjB,OAAA,EAAS,QAAA,GAAW,OAAA;;;;;;;iBAiBA,gBAAA,kBAAkC,iBAAA,EACtD,OAAA,EAAS,QAAA,GACR,OAAA,CAAQ,aAAA;;;AAnBkB;AAiB7B;;iBAcsB,iBAAA,kBAAmC,iBAAA,EACvD,OAAA,EAAS,QAAA,GACR,OAAA,CAAQ,aAAA;;;;;;;iBAaK,iBAAA,kBAAmC,gBAAA,EACjD,OAAA,EAAS,QAAQ;AAAA,iBAKH,gBAAA,kBAAkC,gBAAA,EAChD,OAAA,EAAS,QAAQ,EACjB,OAAA;;;;;;AAnCsB;AAYxB;;;iBAsEsB,UAAA,kBAA4B,gBAAA,EAChD,OAAA,EAAS,QAAA,GACR,OAAA;;;;;;;
|
|
1
|
+
{"version":3,"file":"schema.d.mts","names":[],"sources":["../../src/helpers/schema.ts"],"mappings":";;;;;;;AA6CA;;;;iBAAsB,sBAAA,kBACH,iBAAA,EACjB,OAAA,EAAS,QAAA,GAAW,OAAA;;;;;;;iBAiBA,gBAAA,kBAAkC,iBAAA,EACtD,OAAA,EAAS,QAAA,GACR,OAAA,CAAQ,aAAA;;;AAnBkB;AAiB7B;;iBAcsB,iBAAA,kBAAmC,iBAAA,EACvD,OAAA,EAAS,QAAA,GACR,OAAA,CAAQ,aAAA;;;;;;;iBAaK,iBAAA,kBAAmC,gBAAA,EACjD,OAAA,EAAS,QAAQ;AAAA,iBAKH,gBAAA,kBAAkC,gBAAA,EAChD,OAAA,EAAS,QAAQ,EACjB,OAAA;;;;;;AAnCsB;AAYxB;;;iBAsEsB,UAAA,kBAA4B,gBAAA,EAChD,OAAA,EAAS,QAAA,GACR,OAAA;;;;;;;iBAsNmB,QAAA,kBAA0B,gBAAA,EAC9C,OAAA,EAAS,QAAA,GACR,OAAA"}
|
package/dist/helpers/schema.mjs
CHANGED
|
@@ -193,14 +193,18 @@ async function extractEnv(context) {
|
|
|
193
193
|
property.alias ??= [];
|
|
194
194
|
const aliases = [...property.alias];
|
|
195
195
|
context.config.env.prefix.forEach(__assignType((prefix) => {
|
|
196
|
-
if (!property.alias.includes(`${prefix}_${property.name}`)) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
196
|
+
if (!property.alias.includes(`${prefix}_${property.name}`)) property.alias.push(`${prefix}_${property.name}`);
|
|
197
|
+
aliases.map(__assignType((alias) => `${prefix}_${alias}`, [
|
|
198
|
+
"alias",
|
|
199
|
+
"",
|
|
200
|
+
"P\"2!\"/\""
|
|
201
|
+
])).forEach(__assignType((prefixedAlias) => {
|
|
202
|
+
if (!property.alias.includes(prefixedAlias)) property.alias.push(prefixedAlias);
|
|
203
|
+
}, [
|
|
204
|
+
"prefixedAlias",
|
|
205
|
+
"",
|
|
206
|
+
"P\"2!\"/\""
|
|
207
|
+
]));
|
|
204
208
|
}, [
|
|
205
209
|
"prefix",
|
|
206
210
|
"",
|
|
@@ -215,14 +219,18 @@ async function extractEnv(context) {
|
|
|
215
219
|
property.alias ??= [];
|
|
216
220
|
const aliases = [...property.alias];
|
|
217
221
|
context.config.env.prefix.forEach(__assignType((prefix) => {
|
|
218
|
-
if (!property.alias.includes(`${prefix}_${property.name}`)) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
222
|
+
if (!property.alias.includes(`${prefix}_${property.name}`)) property.alias.push(`${prefix}_${property.name}`);
|
|
223
|
+
aliases.map(__assignType((alias) => `${prefix}_${alias}`, [
|
|
224
|
+
"alias",
|
|
225
|
+
"",
|
|
226
|
+
"P\"2!\"/\""
|
|
227
|
+
])).forEach(__assignType((prefixedAlias) => {
|
|
228
|
+
if (!property.alias.includes(prefixedAlias)) property.alias.push(prefixedAlias);
|
|
229
|
+
}, [
|
|
230
|
+
"prefixedAlias",
|
|
231
|
+
"",
|
|
232
|
+
"P\"2!\"/\""
|
|
233
|
+
]));
|
|
226
234
|
}, [
|
|
227
235
|
"prefix",
|
|
228
236
|
"",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","names":[],"sources":["../../src/helpers/schema.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n extract,\n getProperties,\n getPropertiesList,\n isSchema,\n isSchemaObject,\n JsonSchemaObject,\n merge,\n Schema,\n writeSchema\n} from \"@powerlines/schema\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport type { FileReference } from \"@stryke/types/configuration\";\nimport { UnresolvedContext } from \"powerlines\";\nimport { EnvPluginContext, EnvSchema } from \"../types/plugin\";\nimport { loadEnv } from \"./load\";\n\n/**\n * Resolves the runtime type definition file for the environment variables.\n *\n * @param context - The plugin context.\n * @returns The runtime type definition file for the environment variables.\n */\nexport async function resolveRuntimeTypeFile<\n TContext extends UnresolvedContext\n>(context: TContext): Promise<string> {\n const resolved = await context.fs.resolve(\"@powerlines/plugin-env/types/env\");\n if (!resolved) {\n throw new Error(\n `Failed to resolve the runtime type definition file for the environment variables. Please ensure that the \"@powerlines/plugin-env\" package is installed.`\n );\n }\n\n return resolved;\n}\n\n/**\n * Gets the default type definition for the environment variables.\n *\n * @param context - The plugin context.\n * @returns The default type definition for the environment variables.\n */\nexport async function getDefaultConfig<TContext extends UnresolvedContext>(\n context: TContext\n): Promise<FileReference> {\n return {\n file: await resolveRuntimeTypeFile(context),\n export: \"EnvInterface\"\n };\n}\n\n/** Gets the default type definition for the environment secrets.\n *\n * @param context - The plugin context.\n * @returns The default type definition for the environment secrets.\n */\nexport async function getDefaultSecrets<TContext extends UnresolvedContext>(\n context: TContext\n): Promise<FileReference> {\n return {\n file: await resolveRuntimeTypeFile(context),\n export: \"SecretsInterface\"\n };\n}\n\n/**\n * A helper function to get the cache directory path for storing schemas. This function takes a context object as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the `cachePath` property from the context with a subdirectory named \"schemas\". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.\n *\n * @param context - The context object providing access to the cache path.\n * @returns The path to the cache directory for storing schemas, constructed by joining the context's `cachePath` with the \"schemas\" subdirectory.\n */\nexport function getCacheDirectory<TContext extends EnvPluginContext>(\n context: TContext\n): string {\n return joinPaths(context.cachePath, \"env\");\n}\n\nexport function getCacheFilePath<TContext extends EnvPluginContext>(\n context: TContext,\n variant: \"config\" | \"secrets\"\n): string {\n return joinPaths(getCacheDirectory(context), `${variant}.json`);\n}\n\nasync function writeActive<TContext extends EnvPluginContext>(\n context: TContext,\n variant: \"config\" | \"secrets\",\n schema: EnvSchema\n) {\n if (!isSchema(schema)) {\n throw new Error(\n `The provided input is not a valid env schema. A valid schema must have a \"variant\" property indicating the type of the input and a \"schema\" property containing the parsed JSON Schema object.`\n );\n }\n\n await context.fs.write(\n getCacheFilePath(context, variant),\n JSON.stringify(schema.schema)\n );\n}\n\nasync function readActive<TContext extends EnvPluginContext>(\n context: TContext,\n variant: \"config\" | \"secrets\"\n): Promise<string[]> {\n if (!context.fs.existsSync(getCacheFilePath(context, variant))) {\n return [];\n }\n\n const data = await context.fs.read(getCacheFilePath(context, variant));\n if (!data) {\n return [];\n }\n\n return JSON.parse(data);\n}\n\n/**\n * Extracts the environment variables and secrets schema from the provided type definitions in the plugin options, merges them with the default environment variables and secrets schema, and stores the resulting schema in the plugin context for later use during the build process.\n *\n * @remarks\n * This function should be called during the plugin's `config` hook to ensure that the environment variables and secrets schema is available in the plugin context before the build process begins. The resulting schema will be used to validate the loaded environment variables and secrets, as well as to provide type information for the injected environment variables and secrets during the build process.\n *\n * @param context - The plugin context\n * @returns A promise that resolves when the schema has been extracted and stored in the plugin context.\n */\nexport async function extractEnv<TContext extends EnvPluginContext>(\n context: TContext\n): Promise<void> {\n const defaultConfig = await getDefaultConfig(context);\n const defaultSecrets = await getDefaultSecrets(context);\n\n context.debug({\n meta: {\n category: \"env\"\n },\n message: `Environment Variables configuration: ${\n context.config.env.config\n ? JSON.stringify(context.config.env.config, null, 2)\n : \"None\"\n }\\nEnvironment Secret configuration: ${\n context.config.env.secrets\n ? JSON.stringify(context.config.env.secrets, null, 2)\n : \"None\"\n }`\n });\n\n context.env ??= {} as EnvPluginContext[\"env\"];\n context.env.parsed ??= {};\n context.env.injected ??= [];\n\n context.env.config = (await extract(\n context,\n context.config.env.config\n )) as EnvSchema;\n context.env.config.active = await readActive(context, \"config\");\n\n if (\n (isSetString(context.config.env.config) &&\n new RegExp(`${defaultConfig.file}[:#;@]?${defaultConfig.export}`).test(\n context.config.env.config\n ) === false) ||\n (isSetObject(context.config.env.config) &&\n ((context.config.env.config as FileReference).file !==\n defaultConfig.file ||\n (context.config.env.config as FileReference).export !==\n defaultConfig.export))\n ) {\n context.env.config.schema = merge(\n await extract(context, defaultConfig),\n context.env.config\n ) as JsonSchemaObject;\n }\n\n context.env.secrets = (await extract(\n context,\n context.config.env.secrets\n )) as EnvSchema;\n context.env.secrets.active = await readActive(context, \"secrets\");\n\n if (\n (isSetString(context.config.env.secrets) &&\n new RegExp(`${defaultSecrets.file}[:#;@]?${defaultSecrets.export}`).test(\n context.config.env.secrets\n ) === false) ||\n (isSetObject(context.config.env.secrets) &&\n ((context.config.env.secrets as FileReference).file !==\n defaultSecrets.file ||\n (context.config.env.secrets as FileReference).export !==\n defaultSecrets.export))\n ) {\n context.env.secrets.schema = merge(\n await extract(context, defaultSecrets),\n context.env.secrets\n ) as JsonSchemaObject;\n }\n\n const properties = getProperties(context.env.config);\n context.info({\n meta: {\n category: \"env\"\n },\n message: `Environment Variables configuration: ${\n context.config.env.config ? \"\" : \"Defaulted \"\n }${\n context.env.config.variant === \"reflection\"\n ? \"Deepkit type definition\"\n : context.env.config.variant === \"json-schema\"\n ? \"JSON Schema\"\n : context.env.config.variant === \"standard-schema\"\n ? \"Standard Schema\"\n : context.env.config.variant === \"zod3\"\n ? \"Zod v3 schema\"\n : context.env.config.variant === \"valibot\"\n ? \"Valibot schema\"\n : context.env.config.variant === \"untyped\"\n ? \"Untyped configuration\"\n : \"Typescript exported type\"\n }${context.config.env.config ? \" from plugin options\" : \"\"} provided ${\n Object.keys(properties).length\n } parameters\\nEnvironment Secret configuration: ${\n context.config.env.secrets ? \"\" : \"Defaulted \"\n }${\n context.env.secrets.variant === \"reflection\"\n ? \"Deepkit type definition\"\n : context.env.secrets.variant === \"json-schema\"\n ? \"JSON Schema\"\n : context.env.secrets.variant === \"standard-schema\"\n ? \"Standard Schema\"\n : context.env.secrets.variant === \"zod3\"\n ? \"Zod v3 schema\"\n : context.env.secrets.variant === \"valibot\"\n ? \"Valibot schema\"\n : context.env.secrets.variant === \"untyped\"\n ? \"Untyped configuration\"\n : \"Typescript exported type\"\n }${context.config.env.secrets ? \" from plugin options\" : \"\"} provided ${\n context.env.secrets?.schema\n ? getPropertiesList(context.env.secrets).length\n : \"0\"\n } parameters\\nEnvironment variable Prefixes: ${context.config.env.prefix.join(\n \", \"\n )}\\nShould inject values: ${\n context.config.env.inject ? \"Yes\" : \"No\"\n }\\nShould validate configuration: ${\n context.config.env.validate ? \"Yes\" : \"No\"\n }`\n });\n\n const aliases = Object.fromEntries(\n Object.entries(properties).flatMap(\n ([key, prop]) =>\n (isSetArray(prop.alias)\n ? prop.alias?.map(alias => [\n alias,\n {\n ...prop,\n name: alias,\n alias: [...(prop.alias?.filter(a => a !== alias) ?? []), key]\n }\n ])\n : []) as [string, typeof prop][]\n )\n );\n\n context.env.parsed = await loadEnv(context);\n for (const [key, value] of Object.entries(context.env.parsed)) {\n const unprefixedKey = context.config.env.prefix.reduce((ret, prefix) => {\n if (key.replace(/_$/g, \"\").startsWith(prefix)) {\n return key.replace(/_$/g, \"\").slice(prefix.length);\n }\n return ret;\n }, key);\n if (properties[unprefixedKey]) {\n if (!properties[unprefixedKey]?.runtime) {\n const propertySchema = getProperties(context.env.config.schema)?.[\n unprefixedKey\n ];\n if (propertySchema) {\n propertySchema.default = value;\n }\n }\n } else if (aliases[unprefixedKey]) {\n if (!aliases[unprefixedKey]?.runtime) {\n const alias = aliases[unprefixedKey]?.alias?.[0] ?? unprefixedKey;\n const aliasSchema = getProperties(context.env.config.schema)?.[alias];\n if (aliasSchema) {\n aliasSchema.default = value;\n }\n }\n }\n }\n\n if (!isSchemaObject(context.env.config)) {\n throw new Error(\n \"Invalid environment variable schema extracted. Please ensure the `env.types` option points to a valid TypeScript type definition file that exports an interface representing the environment variable schema.\"\n );\n }\n\n getPropertiesList(context.env.config).forEach(property => {\n property.alias ??= [];\n const aliases = [...property.alias];\n context.config.env.prefix.forEach(prefix => {\n if (!property.alias!.includes(`${prefix}_${property.name}`)) {\n property.alias!.push(`${prefix}_${property.name}`);\n property.alias!.push(...aliases.map(alias => `${prefix}_${alias}`));\n }\n });\n });\n\n getPropertiesList(context.env.secrets).forEach(property => {\n property.alias ??= [];\n const aliases = [...property.alias];\n context.config.env.prefix.forEach(prefix => {\n if (!property.alias!.includes(`${prefix}_${property.name}`)) {\n property.alias!.push(`${prefix}_${property.name}`);\n property.alias!.push(...aliases.map(alias => `${prefix}_${alias}`));\n }\n });\n });\n}\n\n/**\n * Writes the environment variables and secrets schema stored in the plugin context to the cache directory for later retrieval during the build process. This function should be called during the plugin's `build` hook after the schema has been extracted and stored in the plugin context to ensure that the active environment variables and secrets are persisted across builds and can be accessed during the build process for validation and injection purposes.\n *\n * @param context - The plugin context containing the environment variables and secrets schema to be written to the cache directory.\n * @returns A promise that resolves when the schema has been successfully written to the cache directory.\n */\nexport async function writeEnv<TContext extends EnvPluginContext>(\n context: TContext\n): Promise<void[]> {\n return Promise.all([\n writeSchema(context, omit(context.env.config, [\"active\"]) as Schema),\n writeSchema(context, omit(context.env.secrets, [\"active\"]) as Schema),\n writeActive(context, \"config\", context.env.config),\n writeActive(context, \"secrets\", context.env.secrets)\n ]);\n}\n"],"mappings":";;;;;;;;;;AAEA,SAAS,aAAY,IAAK,MAAC;;CAE1B,OAAK;AACN;;;;;;;AA+BA,eAAS,uBAAoC,SAAS;CACtD,MAAQ,WAAW,MAAM,QAAO,GAAA,QAAA,kCAAA;gBAE9B,MAAA,IAAA,MAAA,yJAAA;CAED,OAAA;AACD;AACA,uBAAuB,SAAM;CAAA;CAAe;CAAqB;CAAS;AAAA;;;;;;;AAO1E,eAAmB,iBAAA,SAAA;CACjB,OAAK;EACH,MAAC,MAAA,uBAAA,OAAA;EACH,QAAA;;AAEF;AACA,iBAAA,SAAA;CAAA;CAAA;CAAA;CAAA;AAAA;;;;;;AAMA,eAAgB,kBAAwB,SAAQ;CAC9C,OAAA;EACF,MAAO,MAAM,uBAA0B,OAAA;EACrC,QAAS;CACT;AACF;AACA,kBAAgB,SAAA;CAAA;CAAuB;CAAQ;AAAA;;;;;;;AAO/C,SAAU,kBAAqB,SAAO;CACpC,OAAE,UAAY,QAAQ,WAAK,KAAc;AAC3C;AACA,kBAAa,SAAS;CAAA;CAAiB;CAAkB;CAAkB;AAAA;AAC3E,SAAW,iBAAA,SAAA,SAAA;CACT,OAAC,UAAQ,kBAAe,OAAA,GAAA,GAAA,QAAA,MAAA;AAC1B;AACA,iBAAgB,SAAA;CAAA;CAAsB;CAAS;CAAA;CAAA;CAAA;AAAA;AAC/C,eAAa,YAAA,SAAgB,SAAA,QAAA;CAC3B,IAAC,CAAA,SAAA,MAAA,GACH,MAAA,IAAA,MAAA,gMAAA;CAEE,MAAA,QAAA,GAAA,MAAA,iBAAA,SAAA,OAAA,GAAA,KAAA,UAAA,OAAA,MAAA,CAAA;AACF;AACA,YAAC,SAAA;CAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;AAAA;AACD,eAAU,WAAc,SAAQ,SAAO;CACrC,IAA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,cAAA,WAAA;GAClB,IAAG,CAAA,SAAS,MAAA,SAAA,GAAA,OAAA,GAAA,SAAA,MAAA,GAAA;IACf,SAAY,MAAO,KAAO,GAAE,OAAM,GAAA,SAAW,MAAS;;;;;;GAEnD;EACD,GAAC;GAAA;GAAY;GAAA;EAAc,CAAC,CAAA;CAC9B,GAAG;EAAC;EAAY;EAAE;CAAA,CAAA,CAAa;CAC/B,kBAAc,QAAW,IAAA,OAAA,EAAA,QAAA,cAAA,aAAA;EACvB,SAAQ,UAAQ,CAAA;EAChB,MAAC,UAAY,CAAA,GAAO,SAAQ,KAAI;EAChC,QAAI,OAAQ,IAAO,OAAI,QAAU,cAAc,WAAQ;GACrD,IAAE,CAAA,SAAA,MAAkB,SAAE,GAAA,OAAA,GAAA,SAAA,MAAA,GAAA;IACpB,SAAS,MAAM,KAAK,GAAA,OAAU,GAAA,SAAA,MAAe;IAC7C,SAAE,MAAa,KAAC,GAAO,QAAA,IAAA,cAAA,UAAA,GAAA,OAAA,GAAA,SAAA;KAAA;KAAA;KAAA;IAAA,CAAA,CAAA,CAAA;GAC3B;EACA,GAAA;GAAA;GAAY;GAAM;EAAS,CAAC,CAAA;CAC9B,GAAG;EAAC;EAAM;EAAQ;CAAS,CAAA,CAAA;AAC7B;AACA,WAAS,SAAA;CAAA;CAAgB;CAAA;CAAA;AAAA;;;;;;;AAOzB,eAAsB,SAAS,SAAM;;;;;;;AAErC;AACA,SAAK,SAAY;CAAA;CAAQ;CAAW;CAAU;AAAA"}
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":[],"sources":["../../src/helpers/schema.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n extract,\n getProperties,\n getPropertiesList,\n isSchema,\n isSchemaObject,\n JsonSchemaObject,\n merge,\n Schema,\n writeSchema\n} from \"@powerlines/schema\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport type { FileReference } from \"@stryke/types/configuration\";\nimport { UnresolvedContext } from \"powerlines\";\nimport { EnvPluginContext, EnvSchema } from \"../types/plugin\";\nimport { loadEnv } from \"./load\";\n\n/**\n * Resolves the runtime type definition file for the environment variables.\n *\n * @param context - The plugin context.\n * @returns The runtime type definition file for the environment variables.\n */\nexport async function resolveRuntimeTypeFile<\n TContext extends UnresolvedContext\n>(context: TContext): Promise<string> {\n const resolved = await context.fs.resolve(\"@powerlines/plugin-env/types/env\");\n if (!resolved) {\n throw new Error(\n `Failed to resolve the runtime type definition file for the environment variables. Please ensure that the \"@powerlines/plugin-env\" package is installed.`\n );\n }\n\n return resolved;\n}\n\n/**\n * Gets the default type definition for the environment variables.\n *\n * @param context - The plugin context.\n * @returns The default type definition for the environment variables.\n */\nexport async function getDefaultConfig<TContext extends UnresolvedContext>(\n context: TContext\n): Promise<FileReference> {\n return {\n file: await resolveRuntimeTypeFile(context),\n export: \"EnvInterface\"\n };\n}\n\n/** Gets the default type definition for the environment secrets.\n *\n * @param context - The plugin context.\n * @returns The default type definition for the environment secrets.\n */\nexport async function getDefaultSecrets<TContext extends UnresolvedContext>(\n context: TContext\n): Promise<FileReference> {\n return {\n file: await resolveRuntimeTypeFile(context),\n export: \"SecretsInterface\"\n };\n}\n\n/**\n * A helper function to get the cache directory path for storing schemas. This function takes a context object as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the `cachePath` property from the context with a subdirectory named \"schemas\". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.\n *\n * @param context - The context object providing access to the cache path.\n * @returns The path to the cache directory for storing schemas, constructed by joining the context's `cachePath` with the \"schemas\" subdirectory.\n */\nexport function getCacheDirectory<TContext extends EnvPluginContext>(\n context: TContext\n): string {\n return joinPaths(context.cachePath, \"env\");\n}\n\nexport function getCacheFilePath<TContext extends EnvPluginContext>(\n context: TContext,\n variant: \"config\" | \"secrets\"\n): string {\n return joinPaths(getCacheDirectory(context), `${variant}.json`);\n}\n\nasync function writeActive<TContext extends EnvPluginContext>(\n context: TContext,\n variant: \"config\" | \"secrets\",\n schema: EnvSchema\n) {\n if (!isSchema(schema)) {\n throw new Error(\n `The provided input is not a valid env schema. A valid schema must have a \"variant\" property indicating the type of the input and a \"schema\" property containing the parsed JSON Schema object.`\n );\n }\n\n await context.fs.write(\n getCacheFilePath(context, variant),\n JSON.stringify(schema.schema)\n );\n}\n\nasync function readActive<TContext extends EnvPluginContext>(\n context: TContext,\n variant: \"config\" | \"secrets\"\n): Promise<string[]> {\n if (!context.fs.existsSync(getCacheFilePath(context, variant))) {\n return [];\n }\n\n const data = await context.fs.read(getCacheFilePath(context, variant));\n if (!data) {\n return [];\n }\n\n return JSON.parse(data);\n}\n\n/**\n * Extracts the environment variables and secrets schema from the provided type definitions in the plugin options, merges them with the default environment variables and secrets schema, and stores the resulting schema in the plugin context for later use during the build process.\n *\n * @remarks\n * This function should be called during the plugin's `config` hook to ensure that the environment variables and secrets schema is available in the plugin context before the build process begins. The resulting schema will be used to validate the loaded environment variables and secrets, as well as to provide type information for the injected environment variables and secrets during the build process.\n *\n * @param context - The plugin context\n * @returns A promise that resolves when the schema has been extracted and stored in the plugin context.\n */\nexport async function extractEnv<TContext extends EnvPluginContext>(\n context: TContext\n): Promise<void> {\n const defaultConfig = await getDefaultConfig(context);\n const defaultSecrets = await getDefaultSecrets(context);\n\n context.debug({\n meta: {\n category: \"env\"\n },\n message: `Environment Variables configuration: ${\n context.config.env.config\n ? JSON.stringify(context.config.env.config, null, 2)\n : \"None\"\n }\\nEnvironment Secret configuration: ${\n context.config.env.secrets\n ? JSON.stringify(context.config.env.secrets, null, 2)\n : \"None\"\n }`\n });\n\n context.env ??= {} as EnvPluginContext[\"env\"];\n context.env.parsed ??= {};\n context.env.injected ??= [];\n\n context.env.config = (await extract(\n context,\n context.config.env.config\n )) as EnvSchema;\n context.env.config.active = await readActive(context, \"config\");\n\n if (\n (isSetString(context.config.env.config) &&\n new RegExp(`${defaultConfig.file}[:#;@]?${defaultConfig.export}`).test(\n context.config.env.config\n ) === false) ||\n (isSetObject(context.config.env.config) &&\n ((context.config.env.config as FileReference).file !==\n defaultConfig.file ||\n (context.config.env.config as FileReference).export !==\n defaultConfig.export))\n ) {\n context.env.config.schema = merge(\n await extract(context, defaultConfig),\n context.env.config\n ) as JsonSchemaObject;\n }\n\n context.env.secrets = (await extract(\n context,\n context.config.env.secrets\n )) as EnvSchema;\n context.env.secrets.active = await readActive(context, \"secrets\");\n\n if (\n (isSetString(context.config.env.secrets) &&\n new RegExp(`${defaultSecrets.file}[:#;@]?${defaultSecrets.export}`).test(\n context.config.env.secrets\n ) === false) ||\n (isSetObject(context.config.env.secrets) &&\n ((context.config.env.secrets as FileReference).file !==\n defaultSecrets.file ||\n (context.config.env.secrets as FileReference).export !==\n defaultSecrets.export))\n ) {\n context.env.secrets.schema = merge(\n await extract(context, defaultSecrets),\n context.env.secrets\n ) as JsonSchemaObject;\n }\n\n const properties = getProperties(context.env.config);\n context.info({\n meta: {\n category: \"env\"\n },\n message: `Environment Variables configuration: ${\n context.config.env.config ? \"\" : \"Defaulted \"\n }${\n context.env.config.variant === \"reflection\"\n ? \"Deepkit type definition\"\n : context.env.config.variant === \"json-schema\"\n ? \"JSON Schema\"\n : context.env.config.variant === \"standard-schema\"\n ? \"Standard Schema\"\n : context.env.config.variant === \"zod3\"\n ? \"Zod v3 schema\"\n : context.env.config.variant === \"valibot\"\n ? \"Valibot schema\"\n : context.env.config.variant === \"untyped\"\n ? \"Untyped configuration\"\n : \"Typescript exported type\"\n }${context.config.env.config ? \" from plugin options\" : \"\"} provided ${\n Object.keys(properties).length\n } parameters\\nEnvironment Secret configuration: ${\n context.config.env.secrets ? \"\" : \"Defaulted \"\n }${\n context.env.secrets.variant === \"reflection\"\n ? \"Deepkit type definition\"\n : context.env.secrets.variant === \"json-schema\"\n ? \"JSON Schema\"\n : context.env.secrets.variant === \"standard-schema\"\n ? \"Standard Schema\"\n : context.env.secrets.variant === \"zod3\"\n ? \"Zod v3 schema\"\n : context.env.secrets.variant === \"valibot\"\n ? \"Valibot schema\"\n : context.env.secrets.variant === \"untyped\"\n ? \"Untyped configuration\"\n : \"Typescript exported type\"\n }${context.config.env.secrets ? \" from plugin options\" : \"\"} provided ${\n context.env.secrets?.schema\n ? getPropertiesList(context.env.secrets).length\n : \"0\"\n } parameters\\nEnvironment variable Prefixes: ${context.config.env.prefix.join(\n \", \"\n )}\\nShould inject values: ${\n context.config.env.inject ? \"Yes\" : \"No\"\n }\\nShould validate configuration: ${\n context.config.env.validate ? \"Yes\" : \"No\"\n }`\n });\n\n const aliases = Object.fromEntries(\n Object.entries(properties).flatMap(\n ([key, prop]) =>\n (isSetArray(prop.alias)\n ? prop.alias?.map(alias => [\n alias,\n {\n ...prop,\n name: alias,\n alias: [...(prop.alias?.filter(a => a !== alias) ?? []), key]\n }\n ])\n : []) as [string, typeof prop][]\n )\n );\n\n context.env.parsed = await loadEnv(context);\n for (const [key, value] of Object.entries(context.env.parsed)) {\n const unprefixedKey = context.config.env.prefix.reduce((ret, prefix) => {\n if (key.replace(/_$/g, \"\").startsWith(prefix)) {\n return key.replace(/_$/g, \"\").slice(prefix.length);\n }\n return ret;\n }, key);\n if (properties[unprefixedKey]) {\n if (!properties[unprefixedKey]?.runtime) {\n const propertySchema = getProperties(context.env.config.schema)?.[\n unprefixedKey\n ];\n if (propertySchema) {\n propertySchema.default = value;\n }\n }\n } else if (aliases[unprefixedKey]) {\n if (!aliases[unprefixedKey]?.runtime) {\n const alias = aliases[unprefixedKey]?.alias?.[0] ?? unprefixedKey;\n const aliasSchema = getProperties(context.env.config.schema)?.[alias];\n if (aliasSchema) {\n aliasSchema.default = value;\n }\n }\n }\n }\n\n if (!isSchemaObject(context.env.config)) {\n throw new Error(\n \"Invalid environment variable schema extracted. Please ensure the `env.types` option points to a valid TypeScript type definition file that exports an interface representing the environment variable schema.\"\n );\n }\n\n getPropertiesList(context.env.config).forEach(property => {\n property.alias ??= [];\n const aliases = [...property.alias];\n context.config.env.prefix.forEach(prefix => {\n if (!property.alias!.includes(`${prefix}_${property.name}`)) {\n property.alias!.push(`${prefix}_${property.name}`);\n }\n\n aliases\n .map(alias => `${prefix}_${alias}`)\n .forEach(prefixedAlias => {\n if (!property.alias!.includes(prefixedAlias)) {\n property.alias!.push(prefixedAlias);\n }\n });\n });\n });\n\n getPropertiesList(context.env.secrets).forEach(property => {\n property.alias ??= [];\n const aliases = [...property.alias];\n context.config.env.prefix.forEach(prefix => {\n if (!property.alias!.includes(`${prefix}_${property.name}`)) {\n property.alias!.push(`${prefix}_${property.name}`);\n }\n\n aliases\n .map(alias => `${prefix}_${alias}`)\n .forEach(prefixedAlias => {\n if (!property.alias!.includes(prefixedAlias)) {\n property.alias!.push(prefixedAlias);\n }\n });\n });\n });\n}\n\n/**\n * Writes the environment variables and secrets schema stored in the plugin context to the cache directory for later retrieval during the build process. This function should be called during the plugin's `build` hook after the schema has been extracted and stored in the plugin context to ensure that the active environment variables and secrets are persisted across builds and can be accessed during the build process for validation and injection purposes.\n *\n * @param context - The plugin context containing the environment variables and secrets schema to be written to the cache directory.\n * @returns A promise that resolves when the schema has been successfully written to the cache directory.\n */\nexport async function writeEnv<TContext extends EnvPluginContext>(\n context: TContext\n): Promise<void[]> {\n return Promise.all([\n writeSchema(context, omit(context.env.config, [\"active\"]) as Schema),\n writeSchema(context, omit(context.env.secrets, [\"active\"]) as Schema),\n writeActive(context, \"config\", context.env.config),\n writeActive(context, \"secrets\", context.env.secrets)\n ]);\n}\n"],"mappings":";;;;;;;;;;AAEA,SAAS,aAAY,IAAK,MAAC;;CAE1B,OAAK;AACN;;;;;;;AA+BA,eAAS,uBAAoC,SAAS;CACtD,MAAQ,WAAW,MAAM,QAAO,GAAA,QAAA,kCAAA;gBAE9B,MAAA,IAAA,MAAA,yJAAA;CAED,OAAA;AACD;AACA,uBAAuB,SAAM;CAAA;CAAe;CAAqB;CAAS;AAAA;;;;;;;AAO1E,eAAmB,iBAAA,SAAA;CACjB,OAAK;EACH,MAAC,MAAA,uBAAA,OAAA;EACH,QAAA;;AAEF;AACA,iBAAA,SAAA;CAAA;CAAA;CAAA;CAAA;AAAA;;;;;;AAMA,eAAgB,kBAAwB,SAAQ;CAC9C,OAAA;EACF,MAAO,MAAM,uBAA0B,OAAA;EACrC,QAAS;CACT;AACF;AACA,kBAAgB,SAAA;CAAA;CAAuB;CAAQ;AAAA;;;;;;;AAO/C,SAAU,kBAAqB,SAAO;CACpC,OAAE,UAAY,QAAQ,WAAK,KAAc;AAC3C;AACA,kBAAa,SAAS;CAAA;CAAiB;CAAkB;CAAkB;AAAA;AAC3E,SAAW,iBAAA,SAAA,SAAA;CACT,OAAC,UAAQ,kBAAe,OAAA,GAAA,GAAA,QAAA,MAAA;AAC1B;AACA,iBAAgB,SAAA;CAAA;CAAsB;CAAS;CAAA;CAAA;CAAA;AAAA;AAC/C,eAAa,YAAA,SAAgB,SAAA,QAAA;CAC3B,IAAC,CAAA,SAAA,MAAA,GACH,MAAA,IAAA,MAAA,gMAAA;CAEE,MAAA,QAAA,GAAA,MAAA,iBAAA,SAAA,OAAA,GAAA,KAAA,UAAA,OAAA,MAAA,CAAA;AACF;AACA,YAAC,SAAA;CAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;AAAA;AACD,eAAU,WAAc,SAAQ,SAAO;CACrC,IAAE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AAA,SAAA,CAAA,QAAA,CAAA,CAAA;EAAA,YAAA,SAAA,UAAA,QAAA,IAAA,MAAA;EAAA,YAAA,SAAA,WAAA,QAAA,IAAA,OAAA;CAAA,CAAA;AAC7B;AACA,SAAS,SAAC;CAAA;CAAe;CAAO;CAAA;AAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -59,7 +59,7 @@ const plugin = __assignType((options = {}) => {
|
|
|
59
59
|
"prefix",
|
|
60
60
|
"",
|
|
61
61
|
"P&F2!&2\"\"/#"
|
|
62
|
-
]), [this.config.framework?.name ? `${(0, _stryke_string_format_constant_case.constantCase)(this.config.framework.name)}` : "POWERLINES"]).
|
|
62
|
+
]), [this.config.framework?.name ? `${(0, _stryke_string_format_constant_case.constantCase)(this.config.framework.name)}` : "POWERLINES"])).toReversed();
|
|
63
63
|
return config;
|
|
64
64
|
},
|
|
65
65
|
configResolved: __assignType(async function configResolved() {
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;YA4CY,MAAA;IACR,GAAA,GAAM,gBAAgB;EAAA;AAAA;;;;cAOb,MAAA,oBAA2B,gBAAA,GAAmB,gBAAA,EACzD,OAAA,GAAS,gBAAA,
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;YA4CY,MAAA;IACR,GAAA,GAAM,gBAAgB;EAAA;AAAA;;;;cAOb,MAAA,oBAA2B,gBAAA,GAAmB,gBAAA,EACzD,OAAA,GAAS,gBAAA,KAyGJ,MAAA,CAAO,QAAA"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;YA4CY,MAAA;IACR,GAAA,GAAM,gBAAgB;EAAA;AAAA;;;;cAOb,MAAA,oBAA2B,gBAAA,GAAmB,gBAAA,EACzD,OAAA,GAAS,gBAAA,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;YA4CY,MAAA;IACR,GAAA,GAAM,gBAAgB;EAAA;AAAA;;;;cAOb,MAAA,oBAA2B,gBAAA,GAAmB,gBAAA,EACzD,OAAA,GAAS,gBAAA,KAyGJ,MAAA,CAAO,QAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -54,7 +54,7 @@ const plugin = __assignType((options = {}) => {
|
|
|
54
54
|
"prefix",
|
|
55
55
|
"",
|
|
56
56
|
"P&F2!&2\"\"/#"
|
|
57
|
-
]), [this.config.framework?.name ? `${constantCase(this.config.framework.name)}` : "POWERLINES"]).
|
|
57
|
+
]), [this.config.framework?.name ? `${constantCase(this.config.framework.name)}` : "POWERLINES"])).toReversed();
|
|
58
58
|
return config;
|
|
59
59
|
},
|
|
60
60
|
configResolved: __assignType(async function configResolved() {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport babel from \"@powerlines/plugin-babel\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport defu from \"defu\";\nimport type { Plugin, UnresolvedContext } from \"powerlines\";\nimport { getDocsOutputPath } from \"powerlines/plugin-utils\";\nimport type { UserConfig as ViteUserConfig } from \"vite\";\nimport { envBabelPlugin } from \"./babel/plugin\";\nimport { EnvDocsFile } from \"./components/docs\";\nimport { EnvBuiltin } from \"./components/env-builtin\";\nimport { env } from \"./helpers/automd-generator\";\nimport {\n extractEnv,\n getDefaultConfig,\n getDefaultSecrets,\n writeEnv\n} from \"./helpers/schema\";\nimport type { EnvPluginContext, EnvPluginOptions } from \"./types/plugin\";\n\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n env?: EnvPluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to inject environment variables into the source code.\n */\nexport const plugin = <TContext extends EnvPluginContext = EnvPluginContext>(\n options: EnvPluginOptions = {}\n) => {\n return [\n babel(options.babel),\n {\n name: \"env\",\n async config() {\n this.debug(\n \"Providing default configuration for the Powerlines `env` build plugin.\"\n );\n\n const config = {\n env: defu(options, {\n validate: false,\n inject: false,\n prefix: []\n }),\n babel: {\n ...options.babel,\n skipTransform: !options.inject,\n plugins: [envBabelPlugin]\n }\n };\n\n config.env.config ??= await getDefaultConfig(this as UnresolvedContext);\n config.env.secrets ??= await getDefaultSecrets(\n this as UnresolvedContext\n );\n\n config.env.prefix = getUnique(\n toArray((config.env.prefix ?? []) as string[])
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport babel from \"@powerlines/plugin-babel\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport defu from \"defu\";\nimport type { Plugin, UnresolvedContext } from \"powerlines\";\nimport { getDocsOutputPath } from \"powerlines/plugin-utils\";\nimport type { UserConfig as ViteUserConfig } from \"vite\";\nimport { envBabelPlugin } from \"./babel/plugin\";\nimport { EnvDocsFile } from \"./components/docs\";\nimport { EnvBuiltin } from \"./components/env-builtin\";\nimport { env } from \"./helpers/automd-generator\";\nimport {\n extractEnv,\n getDefaultConfig,\n getDefaultSecrets,\n writeEnv\n} from \"./helpers/schema\";\nimport type { EnvPluginContext, EnvPluginOptions } from \"./types/plugin\";\n\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n env?: EnvPluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to inject environment variables into the source code.\n */\nexport const plugin = <TContext extends EnvPluginContext = EnvPluginContext>(\n options: EnvPluginOptions = {}\n) => {\n return [\n babel(options.babel),\n {\n name: \"env\",\n async config() {\n this.debug(\n \"Providing default configuration for the Powerlines `env` build plugin.\"\n );\n\n const config = {\n env: defu(options, {\n validate: false,\n inject: false,\n prefix: []\n }),\n babel: {\n ...options.babel,\n skipTransform: !options.inject,\n plugins: [envBabelPlugin]\n }\n };\n\n config.env.config ??= await getDefaultConfig(this as UnresolvedContext);\n config.env.secrets ??= await getDefaultSecrets(\n this as UnresolvedContext\n );\n\n config.env.prefix = getUnique(\n toArray((config.env.prefix ?? []) as string[]).reduce(\n (ret: string[], prefix: string) => {\n const formattedPrefix = constantCase(prefix.replace(/_$/g, \"\"));\n if (!ret.includes(formattedPrefix)) {\n ret.push(formattedPrefix);\n }\n\n return ret;\n },\n [\n this.config.framework?.name\n ? `${constantCase(this.config.framework.name)}`\n : \"POWERLINES\"\n ]\n )\n ).toReversed();\n\n return config;\n },\n async configResolved() {\n this.debug(\n `Environment plugin configuration has been resolved for the Powerlines project.`\n );\n\n await extractEnv(this);\n },\n async prepare() {\n this.debug(\n `Preparing the Environment runtime artifacts for the Powerlines project.`\n );\n\n return render(\n this,\n <EnvBuiltin defaultConfig={this.config.env.defaultConfig} />\n );\n },\n async docs() {\n this.debug(\n `Documenting environment variables configuration values in \"${joinPaths(\n getDocsOutputPath(this.config.root),\n \"env.md\"\n )}\"`\n );\n\n return render(this, <EnvDocsFile levelOffset={0} />);\n },\n async buildEnd() {\n this.debug(\"Writing active environment variables to disk.\");\n\n await writeEnv(this);\n }\n },\n {\n name: \"env:automd-generator\",\n configResolved() {\n return {\n automd: defu(options.automd ?? {}, {\n generators: {\n env: env(this)\n }\n })\n };\n }\n },\n {\n name: \"env:vite\",\n vite: {\n configResolved(this: TContext) {\n return {\n envPrefix: this.config?.env?.prefix\n } as ViteUserConfig;\n }\n }\n },\n automd(options.automd)\n ] as Plugin<TContext>[];\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;CAEE,GAAG,SAAS;;AAEd;;;;;CAqCA,OAAS;EAAA,MAAO,QAAO,KAAA;EAAA;;GAEvB,MAAQ,SAAQ;IACd,KAAS,MAAC,wEAAO;IACf,MAAM,SAAA;KACR,KAAA,KAAA,SAAA;MACF,UAAA;;MAEE,QAAA,CAAA;KACG,CAAA;KACH,OAAA;MACK,GAAM,QAAQ;MACX,eAAC,CAAA,QAAoB;MAC1B,SAAA,CAAA,cAAA;KACG;IACJ;IACA,OAAA,IAAA,WAAA,MAAA,iBAAA,IAAA;IACE,OAAO,IAAI,YAAA,MAAA,kBAAA,IAAA;IACX,OAAM,IAAA,SAAS,UAAA,QAAA,OAAA,IAAA,UAAA,CAAA,CAAA,EAAA,OAAA,cAAA,KAAA,WAAA;KACb,MAAK,kBAAK,aAAA,OAAA,QAAA,OAAA,EAAA,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ACzB,GAAG;CAAC;CAAK;QAAA,CAAA;CAAA;CAAA;AAAA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-env",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.325",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package containing a Powerlines plugin for injecting static .env configuration values to the code so that they're accessible at runtime.",
|
|
6
6
|
"keywords": ["dotenv", "powerlines", "storm-software", "powerlines-plugin"],
|
|
@@ -250,12 +250,12 @@
|
|
|
250
250
|
"@alloy-js/typescript": "^0.23.0",
|
|
251
251
|
"@babel/core": "8.0.0-rc.6",
|
|
252
252
|
"@babel/types": "8.0.0-rc.6",
|
|
253
|
-
"@powerlines/core": "0.48.45",
|
|
254
|
-
"@powerlines/plugin-alloy": "0.26.
|
|
255
|
-
"@powerlines/plugin-automd": "0.1.
|
|
256
|
-
"@powerlines/plugin-babel": "0.13.
|
|
257
|
-
"@powerlines/plugin-plugin": "0.12.
|
|
258
|
-
"@powerlines/schema": "0.11.
|
|
253
|
+
"@powerlines/core": "^0.48.45",
|
|
254
|
+
"@powerlines/plugin-alloy": "0.26.214",
|
|
255
|
+
"@powerlines/plugin-automd": "0.1.582",
|
|
256
|
+
"@powerlines/plugin-babel": "0.13.117",
|
|
257
|
+
"@powerlines/plugin-plugin": "0.12.533",
|
|
258
|
+
"@powerlines/schema": "0.11.103",
|
|
259
259
|
"@storm-software/config-tools": "^1.190.40",
|
|
260
260
|
"@stryke/capnp": "^0.12.111",
|
|
261
261
|
"@stryke/convert": "^0.7.15",
|
|
@@ -270,9 +270,9 @@
|
|
|
270
270
|
"automd": "^0.4.3",
|
|
271
271
|
"c12": "^3.3.4",
|
|
272
272
|
"defu": "^6.1.7",
|
|
273
|
-
"powerlines": "0.47.
|
|
273
|
+
"powerlines": "0.47.121"
|
|
274
274
|
},
|
|
275
275
|
"devDependencies": { "@types/node": "^25.9.1", "vite": "^8.0.16" },
|
|
276
276
|
"publishConfig": { "access": "public" },
|
|
277
|
-
"gitHead": "
|
|
277
|
+
"gitHead": "bdfa278eecd08da55ded957cf92b0c705fb1cfd9"
|
|
278
278
|
}
|