@powerlines/plugin-env 0.15.205 → 0.16.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/dist/babel/plugin.cjs +1 -1
- package/dist/babel/plugin.mjs +1 -1
- package/dist/babel/plugin.mjs.map +1 -1
- package/dist/helpers/reflect.cjs +28 -6
- package/dist/helpers/reflect.d.cts +22 -0
- package/dist/helpers/reflect.d.cts.map +1 -1
- package/dist/helpers/reflect.d.mts +22 -0
- package/dist/helpers/reflect.d.mts.map +1 -1
- package/dist/helpers/reflect.mjs +28 -6
- package/dist/helpers/reflect.mjs.map +1 -1
- package/dist/index.cjs +13 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +13 -6
- package/dist/index.mjs.map +1 -1
- package/dist/types/plugin.cjs +8 -2
- package/dist/types/plugin.d.cts +13 -0
- package/dist/types/plugin.d.cts.map +1 -1
- package/dist/types/plugin.d.mts +13 -0
- package/dist/types/plugin.d.mts.map +1 -1
- package/dist/types/plugin.mjs +8 -2
- package/dist/types/plugin.mjs.map +1 -1
- package/package.json +3 -3
package/dist/babel/plugin.cjs
CHANGED
|
@@ -63,7 +63,7 @@ const envBabelPlugin = (__powerlines_plugin_babel_helpers_create_plugin.createBa
|
|
|
63
63
|
if (envProperty.isValueRequired() && value === void 0) throw new Error(`Environment variable \`${name}\` is not defined in the .env configuration files`);
|
|
64
64
|
return (0, __powerlines_deepkit_utilities.stringifyDefaultValue)(envProperty, value);
|
|
65
65
|
}
|
|
66
|
-
} else throw new Error(`The "${name}" environment variable is not defined in the \`env\` type definition, but is used in the source code file ${pass.filename ? pass.filename : "unknown"}.
|
|
66
|
+
} else if (context.config.env.validate) throw new Error(`The "${name}" environment variable is not defined in the \`env\` type definition, but is used in the source code file ${pass.filename ? pass.filename : "unknown"}.
|
|
67
67
|
|
|
68
68
|
The following environment configuration names are defined in the \`env\` type definition: \n${context.env.types.env?.getPropertyNames().sort(__assignType((a, b) => String(a).localeCompare(String(b)), [
|
|
69
69
|
"a",
|
package/dist/babel/plugin.mjs
CHANGED
|
@@ -62,7 +62,7 @@ const envBabelPlugin = (createBabelPlugin.Ω = [[() => __ΩEnvPluginContext, "n!
|
|
|
62
62
|
if (envProperty.isValueRequired() && value === void 0) throw new Error(`Environment variable \`${name}\` is not defined in the .env configuration files`);
|
|
63
63
|
return stringifyDefaultValue(envProperty, value);
|
|
64
64
|
}
|
|
65
|
-
} else throw new Error(`The "${name}" environment variable is not defined in the \`env\` type definition, but is used in the source code file ${pass.filename ? pass.filename : "unknown"}.
|
|
65
|
+
} else if (context.config.env.validate) throw new Error(`The "${name}" environment variable is not defined in the \`env\` type definition, but is used in the source code file ${pass.filename ? pass.filename : "unknown"}.
|
|
66
66
|
|
|
67
67
|
The following environment configuration names are defined in the \`env\` type definition: \n${context.env.types.env?.getPropertyNames().sort(__assignType((a, b) => String(a).localeCompare(String(b)), [
|
|
68
68
|
"a",
|
|
@@ -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 { stringifyDefaultValue } from \"@powerlines/deepkit/utilities\";\n\nimport { createBabelPlugin } from \"@powerlines/plugin-babel/helpers/create-plugin\";\nimport { addImport } from \"@powerlines/plugin-babel/helpers/module-helpers\";\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { BabelPluginPass } from \"powerlines/types/babel\";\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 ({ log, context }) => {\n function extractEnv(\n node: t.Identifier,\n pass: BabelPluginPass,\n isInjectable = false\n ) {\n const envTypesAliasProperties = context.env.types.env\n ?.getProperties()\n .filter(prop => prop.getAlias().length > 0);\n\n if (node.name) {\n const prefix = context.config.env.prefix.find(\n pre =>\n node.name &&\n node.name.startsWith(pre) &&\n (context.env.types.env?.hasProperty(\n node.name.replace(`${pre}_`, \"\")\n ) ||\n envTypesAliasProperties.some(prop =>\n prop.getAlias().includes(node.name.replace(`${pre}_`, \"\"))\n ))\n );\n\n let name = node.name;\n if (prefix) {\n name = node.name.replace(`${prefix}_`, \"\");\n }\n\n log(\n LogLevelLabel.TRACE,\n `Environment variable ${name} found in ${\n pass.filename || \"unknown file\"\n }.`\n );\n\n if (\n context.env.types.env?.hasProperty(name) ||\n envTypesAliasProperties.some(prop => prop.getAlias().includes(name))\n ) {\n const envProperty = context.env.types.env.hasProperty(name)\n ? context.env.types.env.getProperty(name)\n : envTypesAliasProperties.find(prop =>\n prop.getAlias().includes(name)\n );\n if (!envProperty || envProperty.isIgnored()) {\n return;\n }\n\n if (!context.env.used.env.hasProperty(name)) {\n log(\n LogLevelLabel.DEBUG,\n `Adding \"${name}\" environment variables found in \"${\n pass.filename || \"unknown file\"\n }\" to used environment configuration reflection object.`\n );\n\n context.env.used.env.addProperty(envProperty.property);\n }\n\n if (context.config.env.inject && isInjectable) {\n let value = context.env.parsed?.[name];\n if (value === undefined) {\n const prefix = context.config.env.prefix.find(pre => {\n return context.env.parsed[`${pre.replace(/_$/g, \"\")}_${name}`];\n });\n if (prefix) {\n value =\n context.env.parsed[`${prefix.replace(/_$/g, \"\")}_${name}`];\n }\n }\n\n value ??= envProperty.getDefaultValue();\n\n if (envProperty.isValueRequired() && value === undefined) {\n throw new Error(\n `Environment variable \\`${name}\\` is not defined in the .env configuration files`\n );\n }\n\n return stringifyDefaultValue(envProperty, value);\n }\n } else {\n throw new Error(\n `The \"${name}\" environment variable is not defined in the \\`env\\` type definition, but is used in the source code file ${\n pass.filename ? pass.filename : \"unknown\"\n }.\n\n The following environment configuration names are defined in the \\`env\\` type definition: \\n${context.env.types.env\n ?.getPropertyNames()\n .sort((a, b) => String(a).localeCompare(String(b)))\n .map(\n typeDef =>\n ` - ${String(typeDef)} ${\n envTypesAliasProperties.some(\n prop =>\n prop.getNameAsString() === String(typeDef) &&\n prop.getAlias().length > 0\n )\n ? `(Alias: ${envTypesAliasProperties\n ?.find(\n prop => prop.getNameAsString() === String(typeDef)\n )\n ?.getAlias()\n .join(\", \")})`\n : \"\"\n }`\n )\n .join(\n \"\\n\"\n )} \\n\\nUsing the following env prefix: \\n${context.config.env.prefix\n .map(prefix => ` - ${prefix}`)\n .join(\n \"\\n\"\n )} \\n\\nPlease check your \\`env\\` configuration option. If you are using a custom dotenv type definition, please make sure that the configuration names match the ones in the code. \\n\\n`\n );\n }\n }\n\n return undefined;\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 || \"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 || \"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":";;;;;;;;;AAIA,SAAS,aAAa,IAAI,MAAM;AAC5B,IAAG,SAAS;AACZ,QAAO;;AA8BX,MAAa,kBAAW,kBAAA,IAAA,CAAA,OAAA,qBAAA,KAAA,CAAA,EAAA,kBAAA,OAAA,cAAA,EAAA,KAAA,cAAA;CACpB,SAAS,WAAU,MAAA,MAAA,eAAA,OAAA;EACf,MAAM,0BAAU,QAAA,IAAA,MAAA,KACV,eAAa,CACd,OAAO,cAAK,SAAA,KAAA,UAAA,CAAA,SAAA,GAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;AACnB,MAAA,KAAA,MAAA;GACM,MAAM,SAAS,QAAQ,OAAO,IAAI,OAAO,KAAK,cAAA,QAAA,KAAA,QAC1C,KAAK,KAAG,WAAA,IAAA,KACP,QAAQ,IAAI,MAAM,KAAK,YAAW,KAAA,KAAA,QAAA,GAAA,IAAA,IAAA,GAAA,CAAA;;;;;;;;;GAEvC,IAAI,OAAK,KAAA;AACT,OAAI,OACD,QAAA,KAAA,KAAA,QAAA,GAAA,OAAA,IAAA,GAAA;AAEH,OAAI,cAAc,OAAO,wBAAE,KAAA,YAAA,KAAA,YAAA,eAAA,GAAA;AAC3B,OAAI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,cAAW,YAAI,MAAA,MAAA;AACf,QAAK,wBAAY,OAAA,WAAA,OAAA;AACjB,aAAG,MAAA;IACN,QAAA,GAAA,QAAA,OAAA,aAAA,aAAA;IACL,MAAA;IACK,UAAA;IACA,CAAA;aAEQ,KAAK,IAAI,SAAO,EAAA,aAAA,EAAA,MAAA,OAAA,CAAA,IACxB,KAAA,IAAA,WAAA,EAAA,cAAA,EAAA;GAEG,MAAM,aAAa,KAAK,IAAI,WAAW,EAAE;AAClD,OAAA,CAAA,WAAA,KACH;;;IAIJ;QAAA;EAAA;QAAA;EAAA;EAAA;EAAA;EAAA,CAAA,IAEC;GACF;CAAC;CAAU;CAAC;CAAA,CAAA,CAAA"}
|
|
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 { stringifyDefaultValue } from \"@powerlines/deepkit/utilities\";\n\nimport { createBabelPlugin } from \"@powerlines/plugin-babel/helpers/create-plugin\";\nimport { addImport } from \"@powerlines/plugin-babel/helpers/module-helpers\";\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { BabelPluginPass } from \"powerlines/types/babel\";\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 ({ log, context }) => {\n function extractEnv(\n node: t.Identifier,\n pass: BabelPluginPass,\n isInjectable = false\n ) {\n const envTypesAliasProperties = context.env.types.env\n ?.getProperties()\n .filter(prop => prop.getAlias().length > 0);\n\n if (node.name) {\n const prefix = context.config.env.prefix.find(\n pre =>\n node.name &&\n node.name.startsWith(pre) &&\n (context.env.types.env?.hasProperty(\n node.name.replace(`${pre}_`, \"\")\n ) ||\n envTypesAliasProperties.some(prop =>\n prop.getAlias().includes(node.name.replace(`${pre}_`, \"\"))\n ))\n );\n\n let name = node.name;\n if (prefix) {\n name = node.name.replace(`${prefix}_`, \"\");\n }\n\n log(\n LogLevelLabel.TRACE,\n `Environment variable ${name} found in ${\n pass.filename || \"unknown file\"\n }.`\n );\n\n if (\n context.env.types.env?.hasProperty(name) ||\n envTypesAliasProperties.some(prop => prop.getAlias().includes(name))\n ) {\n const envProperty = context.env.types.env.hasProperty(name)\n ? context.env.types.env.getProperty(name)\n : envTypesAliasProperties.find(prop =>\n prop.getAlias().includes(name)\n );\n if (!envProperty || envProperty.isIgnored()) {\n return;\n }\n\n if (!context.env.used.env.hasProperty(name)) {\n log(\n LogLevelLabel.DEBUG,\n `Adding \"${name}\" environment variables found in \"${\n pass.filename || \"unknown file\"\n }\" to used environment configuration reflection object.`\n );\n\n context.env.used.env.addProperty(envProperty.property);\n }\n\n if (context.config.env.inject && isInjectable) {\n let value = context.env.parsed?.[name];\n if (value === undefined) {\n const prefix = context.config.env.prefix.find(pre => {\n return context.env.parsed[`${pre.replace(/_$/g, \"\")}_${name}`];\n });\n if (prefix) {\n value =\n context.env.parsed[`${prefix.replace(/_$/g, \"\")}_${name}`];\n }\n }\n\n value ??= envProperty.getDefaultValue();\n\n if (envProperty.isValueRequired() && value === undefined) {\n throw new Error(\n `Environment variable \\`${name}\\` is not defined in the .env configuration files`\n );\n }\n\n return stringifyDefaultValue(envProperty, value);\n }\n } else if (context.config.env.validate) {\n throw new Error(\n `The \"${name}\" environment variable is not defined in the \\`env\\` type definition, but is used in the source code file ${\n pass.filename ? pass.filename : \"unknown\"\n }.\n\n The following environment configuration names are defined in the \\`env\\` type definition: \\n${context.env.types.env\n ?.getPropertyNames()\n .sort((a, b) => String(a).localeCompare(String(b)))\n .map(\n typeDef =>\n ` - ${String(typeDef)} ${\n envTypesAliasProperties.some(\n prop =>\n prop.getNameAsString() === String(typeDef) &&\n prop.getAlias().length > 0\n )\n ? `(Alias: ${envTypesAliasProperties\n ?.find(\n prop => prop.getNameAsString() === String(typeDef)\n )\n ?.getAlias()\n .join(\", \")})`\n : \"\"\n }`\n )\n .join(\n \"\\n\"\n )} \\n\\nUsing the following env prefix: \\n${context.config.env.prefix\n .map(prefix => ` - ${prefix}`)\n .join(\n \"\\n\"\n )} \\n\\nPlease check your \\`env\\` configuration option. If you are using a custom dotenv type definition, please make sure that the configuration names match the ones in the code. \\n\\n`\n );\n }\n }\n\n return undefined;\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 || \"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 || \"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":";;;;;;;;;AAIA,SAAS,aAAa,IAAI,MAAM;AAC5B,IAAG,SAAS;AACZ,QAAO;;AA8BX,MAAa,kBAAW,kBAAA,IAAA,CAAA,OAAA,qBAAA,KAAA,CAAA,EAAA,kBAAA,OAAA,cAAA,EAAA,KAAA,cAAA;CACpB,SAAS,WAAU,MAAA,MAAA,eAAA,OAAA;EACf,MAAM,0BAAU,QAAA,IAAA,MAAA,KACV,eAAa,CACd,OAAO,cAAK,SAAA,KAAA,UAAA,CAAA,SAAA,GAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;AACnB,MAAA,KAAA,MAAA;GACM,MAAM,SAAS,QAAQ,OAAO,IAAI,OAAO,KAAK,cAAA,QAAA,KAAA,QAC1C,KAAK,KAAG,WAAA,IAAA,KACP,QAAQ,IAAI,MAAM,KAAK,YAAW,KAAA,KAAA,QAAA,GAAA,IAAA,IAAA,GAAA,CAAA;;;;;;;;;GAEvC,IAAI,OAAK,KAAA;AACT,OAAI,OACD,QAAA,KAAA,KAAA,QAAA,GAAA,OAAA,IAAA,GAAA;AAEH,OAAI,cAAc,OAAO,wBAAE,KAAA,YAAA,KAAA,YAAA,eAAA,GAAA;AAC3B,OAAI,QAAQ,IAAI,MAAM,KAAK,YAAQ,KAAA,IAC/B,wBAAwB,KAAK,cAAA,SAAA,KAAA,UAAA,CAAA,SAAA,KAAA,EAAA;IAAA;IAAA;IAAA;IAAA,CAAA,CAAA,EAAA;IAC9B,MAAA,cAAA,QAAA,IAAA,M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,KAAK,IAAI,SAAO,EAAA,aAAA,EAAA,MAAA,OAAA,CAAA,IACxB,KAAA,IAAA,WAAA,EAAA,cAAA,EAAA;GAEG,MAAM,aAAa,KAAK,IAAI,WAAW,EAAE;AAClD,OAAA,CAAA,WAAA,KACH;;;IAIJ;QAAA;EAAA;QAAA;EAAA;EAAA;EAAA;EAAA,CAAA,IAEC;GACF;CAAC;CAAU;CAAC;CAAA,CAAA,CAAA"}
|
package/dist/helpers/reflect.cjs
CHANGED
|
@@ -208,17 +208,27 @@ createSecretsReflection.__type = [
|
|
|
208
208
|
"createSecretsReflection",
|
|
209
209
|
"Pn!2\"n#2$>%P\"7&/'"
|
|
210
210
|
];
|
|
211
|
+
/**
|
|
212
|
+
* Reflects the environment configuration type definition from the provided file and name, and merges it with the default environment configuration reflection and the currently used environment configuration reflection.
|
|
213
|
+
*
|
|
214
|
+
* @remarks
|
|
215
|
+
* The resulting reflection will contain the structure of the expected environment variables as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default environment configuration reflection.
|
|
216
|
+
*
|
|
217
|
+
* @param context - The plugin context
|
|
218
|
+
* @param file - The file path to reflect the environment configuration type definition from
|
|
219
|
+
* @param name - The name of the type definition to reflect the environment configuration from, if the file contains multiple type definitions. If not provided, the first type definition found in the file will be used.
|
|
220
|
+
* @returns A reflection of the environment configuration type definition, merged with the default environment configuration reflection and the currently used environment configuration reflection. The resulting reflection will contain the structure of the expected environment variables as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default environment configuration reflection.
|
|
221
|
+
*/
|
|
211
222
|
async function reflectEnv(context, file, name) {
|
|
212
223
|
let config;
|
|
213
224
|
if (file) config = (0, __powerlines_deepkit_vendor_type.resolveClassType)(await (0, __powerlines_deepkit_reflect_type.reflectType)(context, {
|
|
214
225
|
file: !require_is_parent_path.isParentPath(file, context.workspaceConfig.workspaceRoot) ? require_join_paths.joinPaths(context.workspaceConfig.workspaceRoot, file) : file,
|
|
215
226
|
name
|
|
216
227
|
}));
|
|
217
|
-
const defaultConfigType = await (0, __powerlines_deepkit_reflect_type.reflectType)(context, await require_helpers_persistence.getEnvDefaultTypeDefinition(context));
|
|
218
228
|
return mergeEnvReflections(context, [
|
|
219
229
|
await require_helpers_persistence.readEnvTypeReflection(context, "env"),
|
|
220
230
|
config,
|
|
221
|
-
(0, __powerlines_deepkit_vendor_type.resolveClassType)(
|
|
231
|
+
(0, __powerlines_deepkit_vendor_type.resolveClassType)(await (0, __powerlines_deepkit_reflect_type.reflectType)(context, await require_helpers_persistence.getEnvDefaultTypeDefinition(context)))
|
|
222
232
|
].filter(Boolean));
|
|
223
233
|
}
|
|
224
234
|
reflectEnv.__type = [
|
|
@@ -227,19 +237,30 @@ reflectEnv.__type = [
|
|
|
227
237
|
"file",
|
|
228
238
|
"name",
|
|
229
239
|
"reflectEnv",
|
|
230
|
-
"
|
|
240
|
+
"Reflects the environment configuration type definition from the provided file and name, and merges it with the default environment configuration reflection and the currently used environment configuration reflection.",
|
|
241
|
+
"Pn!2\"&2#8&2$8\"/%?&"
|
|
231
242
|
];
|
|
243
|
+
/**
|
|
244
|
+
* Reflects the secrets configuration type definition from the provided file and name, and merges it with the default secrets configuration reflection and the currently used secrets configuration reflection.
|
|
245
|
+
*
|
|
246
|
+
* @remarks
|
|
247
|
+
* The resulting reflection will contain the structure of the expected environment secrets as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default secrets configuration reflection.
|
|
248
|
+
*
|
|
249
|
+
* @param context - The plugin context
|
|
250
|
+
* @param file - The file path to reflect the secrets configuration type definition from
|
|
251
|
+
* @param name - The name of the type definition to reflect the secrets configuration from, if the file contains multiple type definitions. If not provided, the first type definition found in the file will be used.
|
|
252
|
+
* @returns A reflection of the secrets configuration type definition, merged with the default secrets configuration reflection and the currently used secrets configuration reflection. The resulting reflection will contain the structure of the expected environment secrets as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default secrets configuration reflection.
|
|
253
|
+
*/
|
|
232
254
|
async function reflectSecrets(context, file, name) {
|
|
233
255
|
let config;
|
|
234
256
|
if (file) config = (0, __powerlines_deepkit_vendor_type.resolveClassType)(await (0, __powerlines_deepkit_reflect_type.reflectType)(context, {
|
|
235
257
|
file: !require_is_parent_path.isParentPath(file, context.workspaceConfig.workspaceRoot) ? require_join_paths.joinPaths(context.workspaceConfig.workspaceRoot, file) : file,
|
|
236
258
|
name
|
|
237
259
|
}));
|
|
238
|
-
const defaultSecretsType = await (0, __powerlines_deepkit_reflect_type.reflectType)(context, await require_helpers_persistence.getSecretsDefaultTypeDefinition(context));
|
|
239
260
|
return mergeSecretsReflections(context, [
|
|
240
261
|
await require_helpers_persistence.readSecretsReflection(context),
|
|
241
262
|
config,
|
|
242
|
-
(0, __powerlines_deepkit_vendor_type.resolveClassType)(
|
|
263
|
+
(0, __powerlines_deepkit_vendor_type.resolveClassType)(await (0, __powerlines_deepkit_reflect_type.reflectType)(context, await require_helpers_persistence.getSecretsDefaultTypeDefinition(context)))
|
|
243
264
|
].filter(Boolean));
|
|
244
265
|
}
|
|
245
266
|
reflectSecrets.__type = [
|
|
@@ -248,7 +269,8 @@ reflectSecrets.__type = [
|
|
|
248
269
|
"file",
|
|
249
270
|
"name",
|
|
250
271
|
"reflectSecrets",
|
|
251
|
-
"
|
|
272
|
+
"Reflects the secrets configuration type definition from the provided file and name, and merges it with the default secrets configuration reflection and the currently used secrets configuration reflection.",
|
|
273
|
+
"Pn!2\"&2#8&2$8\"/%?&"
|
|
252
274
|
];
|
|
253
275
|
|
|
254
276
|
//#endregion
|
|
@@ -39,7 +39,29 @@ declare class BaseSecrets implements SecretsInterface {
|
|
|
39
39
|
}
|
|
40
40
|
declare function createEnvReflection(context: EnvPluginContext, options?: CreateEnvReflectionOptions): ReflectionClass<any>;
|
|
41
41
|
declare function createSecretsReflection(context: EnvPluginContext, options?: CreateEnvReflectionOptions): ReflectionClass<any>;
|
|
42
|
+
/**
|
|
43
|
+
* Reflects the environment configuration type definition from the provided file and name, and merges it with the default environment configuration reflection and the currently used environment configuration reflection.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* The resulting reflection will contain the structure of the expected environment variables as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default environment configuration reflection.
|
|
47
|
+
*
|
|
48
|
+
* @param context - The plugin context
|
|
49
|
+
* @param file - The file path to reflect the environment configuration type definition from
|
|
50
|
+
* @param name - The name of the type definition to reflect the environment configuration from, if the file contains multiple type definitions. If not provided, the first type definition found in the file will be used.
|
|
51
|
+
* @returns A reflection of the environment configuration type definition, merged with the default environment configuration reflection and the currently used environment configuration reflection. The resulting reflection will contain the structure of the expected environment variables as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default environment configuration reflection.
|
|
52
|
+
*/
|
|
42
53
|
declare function reflectEnv(context: EnvPluginContext, file?: string, name?: string): Promise<ReflectionClass<any>>;
|
|
54
|
+
/**
|
|
55
|
+
* Reflects the secrets configuration type definition from the provided file and name, and merges it with the default secrets configuration reflection and the currently used secrets configuration reflection.
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* The resulting reflection will contain the structure of the expected environment secrets as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default secrets configuration reflection.
|
|
59
|
+
*
|
|
60
|
+
* @param context - The plugin context
|
|
61
|
+
* @param file - The file path to reflect the secrets configuration type definition from
|
|
62
|
+
* @param name - The name of the type definition to reflect the secrets configuration from, if the file contains multiple type definitions. If not provided, the first type definition found in the file will be used.
|
|
63
|
+
* @returns A reflection of the secrets configuration type definition, merged with the default secrets configuration reflection and the currently used secrets configuration reflection. The resulting reflection will contain the structure of the expected environment secrets as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default secrets configuration reflection.
|
|
64
|
+
*/
|
|
43
65
|
declare function reflectSecrets(context: EnvPluginContext, file?: string, name?: string): Promise<ReflectionClass<any>>;
|
|
44
66
|
declare type __ΩCreateEnvReflectionOptions = any[];
|
|
45
67
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflect.d.cts","names":[],"sources":["../../src/helpers/reflect.ts"],"sourcesContent":[],"mappings":";;;;;iBAuCgB,mBAAA,UACL,+BACI,yBACZ;iBAQa,uBAAA,UACL,+BACI,yBACZ;AAda,UAsBC,0BAAA,CAtBkB;EACxB,IAAA,CAAA,EAsBF,iBAtBE,GAsBkB,SAtBlB;EACI,eAAA,CAAA,EAsBK,eAtBL,CAAA,GAAA,CAAA;;AACG,cAwBL,OAAA,YAAmB,YAxBd,CAAA;EAQF,QAAA,EAAA,MAAA;EACL,WAAA,EAAA,MAAA;EACI,QAAA,EAAA,MAAA;EACZ,eAAA,EAAA,MAAA;EAAe,cAAA,EAAA,MAAA;EAQD,UAAA,EAAA,MAAA;EACR,WAAA,EAAA,MAAA;EAAoB,YAAA,EAAA,MAAA;EACT,QAAA,EAAA,MAAA,GAAA,SAAA,GAAA,SAAA;EAAe,IAAA,EAAA,aAAA,GAAA,MAAA,GAAA,YAAA;EAGtB,WAAQ,EAAA,MAAA;EAgDR,KAAA,EAAA,OAAY;EAIT,IAAA,EAAA,OAAA;EACL,OAAA,EAAA,OAAA;EACA,QAAA,EAAA,OAAA;EACR,WAAA,EAAA,MAAA,GAAA,OAAA;EAAe,eAAA,EAAA,MAAA,GAAA,OAAA;EAyCF,UAAA,EAAA,OAAA;EACL,kBAAA,EAAA,OAAA;EACA,SAAA,EAAA,MAAA;EACR,gBAAA,EAAA,MAAA;EAAe,cAAA,EAAA,MAAA;
|
|
1
|
+
{"version":3,"file":"reflect.d.cts","names":[],"sources":["../../src/helpers/reflect.ts"],"sourcesContent":[],"mappings":";;;;;iBAuCgB,mBAAA,UACL,+BACI,yBACZ;iBAQa,uBAAA,UACL,+BACI,yBACZ;AAda,UAsBC,0BAAA,CAtBkB;EACxB,IAAA,CAAA,EAsBF,i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
declare function createEnvReflection(context: EnvPluginContext, options?: CreateEnvReflectionOptions): ReflectionClass<any>;
|
|
41
41
|
declare function createSecretsReflection(context: EnvPluginContext, options?: CreateEnvReflectionOptions): ReflectionClass<any>;
|
|
42
|
+
/**
|
|
43
|
+
* Reflects the environment configuration type definition from the provided file and name, and merges it with the default environment configuration reflection and the currently used environment configuration reflection.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* The resulting reflection will contain the structure of the expected environment variables as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default environment configuration reflection.
|
|
47
|
+
*
|
|
48
|
+
* @param context - The plugin context
|
|
49
|
+
* @param file - The file path to reflect the environment configuration type definition from
|
|
50
|
+
* @param name - The name of the type definition to reflect the environment configuration from, if the file contains multiple type definitions. If not provided, the first type definition found in the file will be used.
|
|
51
|
+
* @returns A reflection of the environment configuration type definition, merged with the default environment configuration reflection and the currently used environment configuration reflection. The resulting reflection will contain the structure of the expected environment variables as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default environment configuration reflection.
|
|
52
|
+
*/
|
|
42
53
|
declare function reflectEnv(context: EnvPluginContext, file?: string, name?: string): Promise<ReflectionClass<any>>;
|
|
54
|
+
/**
|
|
55
|
+
* Reflects the secrets configuration type definition from the provided file and name, and merges it with the default secrets configuration reflection and the currently used secrets configuration reflection.
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* The resulting reflection will contain the structure of the expected environment secrets as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default secrets configuration reflection.
|
|
59
|
+
*
|
|
60
|
+
* @param context - The plugin context
|
|
61
|
+
* @param file - The file path to reflect the secrets configuration type definition from
|
|
62
|
+
* @param name - The name of the type definition to reflect the secrets configuration from, if the file contains multiple type definitions. If not provided, the first type definition found in the file will be used.
|
|
63
|
+
* @returns A reflection of the secrets configuration type definition, merged with the default secrets configuration reflection and the currently used secrets configuration reflection. The resulting reflection will contain the structure of the expected environment secrets as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default secrets configuration reflection.
|
|
64
|
+
*/
|
|
43
65
|
declare function reflectSecrets(context: EnvPluginContext, file?: string, name?: string): Promise<ReflectionClass<any>>;
|
|
44
66
|
declare type __ΩCreateEnvReflectionOptions = any[];
|
|
45
67
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflect.d.mts","names":[],"sources":["../../src/helpers/reflect.ts"],"sourcesContent":[],"mappings":";;;;;iBAuCgB,mBAAA,UACL,+BACI,yBACZ;iBAQa,uBAAA,UACL,+BACI,yBACZ;AAda,UAsBC,0BAAA,CAtBkB;EACxB,IAAA,CAAA,EAsBF,iBAtBE,GAsBkB,SAtBlB;EACI,eAAA,CAAA,EAsBK,eAtBL,CAAA,GAAA,CAAA;;AACG,cAwBL,OAAA,YAAmB,YAxBd,CAAA;EAQF,QAAA,EAAA,MAAA;EACL,WAAA,EAAA,MAAA;EACI,QAAA,EAAA,MAAA;EACZ,eAAA,EAAA,MAAA;EAAe,cAAA,EAAA,MAAA;EAQD,UAAA,EAAA,MAAA;EACR,WAAA,EAAA,MAAA;EAAoB,YAAA,EAAA,MAAA;EACT,QAAA,EAAA,MAAA,GAAA,SAAA,GAAA,SAAA;EAAe,IAAA,EAAA,aAAA,GAAA,MAAA,GAAA,YAAA;EAGtB,WAAQ,EAAA,MAAA;EAgDR,KAAA,EAAA,OAAY;EAIT,IAAA,EAAA,OAAA;EACL,OAAA,EAAA,OAAA;EACA,QAAA,EAAA,OAAA;EACR,WAAA,EAAA,MAAA,GAAA,OAAA;EAAe,eAAA,EAAA,MAAA,GAAA,OAAA;EAyCF,UAAA,EAAA,OAAA;EACL,kBAAA,EAAA,OAAA;EACA,SAAA,EAAA,MAAA;EACR,gBAAA,EAAA,MAAA;EAAe,cAAA,EAAA,MAAA;
|
|
1
|
+
{"version":3,"file":"reflect.d.mts","names":[],"sources":["../../src/hel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;iBAzCW,UAAA,UACX,iDAEI,QAAA;;;;;;;;;;;;iBAqCO,cAAA,UACX,iDAEI,QAAA"}
|
package/dist/helpers/reflect.mjs
CHANGED
|
@@ -207,17 +207,27 @@ createSecretsReflection.__type = [
|
|
|
207
207
|
"createSecretsReflection",
|
|
208
208
|
"Pn!2\"n#2$>%P\"7&/'"
|
|
209
209
|
];
|
|
210
|
+
/**
|
|
211
|
+
* Reflects the environment configuration type definition from the provided file and name, and merges it with the default environment configuration reflection and the currently used environment configuration reflection.
|
|
212
|
+
*
|
|
213
|
+
* @remarks
|
|
214
|
+
* The resulting reflection will contain the structure of the expected environment variables as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default environment configuration reflection.
|
|
215
|
+
*
|
|
216
|
+
* @param context - The plugin context
|
|
217
|
+
* @param file - The file path to reflect the environment configuration type definition from
|
|
218
|
+
* @param name - The name of the type definition to reflect the environment configuration from, if the file contains multiple type definitions. If not provided, the first type definition found in the file will be used.
|
|
219
|
+
* @returns A reflection of the environment configuration type definition, merged with the default environment configuration reflection and the currently used environment configuration reflection. The resulting reflection will contain the structure of the expected environment variables as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default environment configuration reflection.
|
|
220
|
+
*/
|
|
210
221
|
async function reflectEnv(context, file, name) {
|
|
211
222
|
let config;
|
|
212
223
|
if (file) config = resolveClassType(await reflectType(context, {
|
|
213
224
|
file: !isParentPath(file, context.workspaceConfig.workspaceRoot) ? joinPaths(context.workspaceConfig.workspaceRoot, file) : file,
|
|
214
225
|
name
|
|
215
226
|
}));
|
|
216
|
-
const defaultConfigType = await reflectType(context, await getEnvDefaultTypeDefinition(context));
|
|
217
227
|
return mergeEnvReflections(context, [
|
|
218
228
|
await readEnvTypeReflection(context, "env"),
|
|
219
229
|
config,
|
|
220
|
-
resolveClassType(
|
|
230
|
+
resolveClassType(await reflectType(context, await getEnvDefaultTypeDefinition(context)))
|
|
221
231
|
].filter(Boolean));
|
|
222
232
|
}
|
|
223
233
|
reflectEnv.__type = [
|
|
@@ -226,19 +236,30 @@ reflectEnv.__type = [
|
|
|
226
236
|
"file",
|
|
227
237
|
"name",
|
|
228
238
|
"reflectEnv",
|
|
229
|
-
"
|
|
239
|
+
"Reflects the environment configuration type definition from the provided file and name, and merges it with the default environment configuration reflection and the currently used environment configuration reflection.",
|
|
240
|
+
"Pn!2\"&2#8&2$8\"/%?&"
|
|
230
241
|
];
|
|
242
|
+
/**
|
|
243
|
+
* Reflects the secrets configuration type definition from the provided file and name, and merges it with the default secrets configuration reflection and the currently used secrets configuration reflection.
|
|
244
|
+
*
|
|
245
|
+
* @remarks
|
|
246
|
+
* The resulting reflection will contain the structure of the expected environment secrets as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default secrets configuration reflection.
|
|
247
|
+
*
|
|
248
|
+
* @param context - The plugin context
|
|
249
|
+
* @param file - The file path to reflect the secrets configuration type definition from
|
|
250
|
+
* @param name - The name of the type definition to reflect the secrets configuration from, if the file contains multiple type definitions. If not provided, the first type definition found in the file will be used.
|
|
251
|
+
* @returns A reflection of the secrets configuration type definition, merged with the default secrets configuration reflection and the currently used secrets configuration reflection. The resulting reflection will contain the structure of the expected environment secrets as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default secrets configuration reflection.
|
|
252
|
+
*/
|
|
231
253
|
async function reflectSecrets(context, file, name) {
|
|
232
254
|
let config;
|
|
233
255
|
if (file) config = resolveClassType(await reflectType(context, {
|
|
234
256
|
file: !isParentPath(file, context.workspaceConfig.workspaceRoot) ? joinPaths(context.workspaceConfig.workspaceRoot, file) : file,
|
|
235
257
|
name
|
|
236
258
|
}));
|
|
237
|
-
const defaultSecretsType = await reflectType(context, await getSecretsDefaultTypeDefinition(context));
|
|
238
259
|
return mergeSecretsReflections(context, [
|
|
239
260
|
await readSecretsReflection(context),
|
|
240
261
|
config,
|
|
241
|
-
resolveClassType(
|
|
262
|
+
resolveClassType(await reflectType(context, await getSecretsDefaultTypeDefinition(context)))
|
|
242
263
|
].filter(Boolean));
|
|
243
264
|
}
|
|
244
265
|
reflectSecrets.__type = [
|
|
@@ -247,7 +268,8 @@ reflectSecrets.__type = [
|
|
|
247
268
|
"file",
|
|
248
269
|
"name",
|
|
249
270
|
"reflectSecrets",
|
|
250
|
-
"
|
|
271
|
+
"Reflects the secrets configuration type definition from the provided file and name, and merges it with the default secrets configuration reflection and the currently used secrets configuration reflection.",
|
|
272
|
+
"Pn!2\"&2#8&2$8\"/%?&"
|
|
251
273
|
];
|
|
252
274
|
|
|
253
275
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflect.mjs","names":[],"sources":["../../src/helpers/reflect.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 { reflectType } from \"@powerlines/deepkit/reflect-type\";\nimport {\n merge,\n ReflectionClass,\n ReflectionKind,\n resolveClassType,\n TypeClass,\n TypeObjectLiteral\n} from \"@powerlines/deepkit/vendor/type\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { EnvPluginContext } from \"../types/plugin\";\nimport { EnvInterface, SecretsInterface } from \"../types/runtime\";\nimport {\n getEnvDefaultTypeDefinition,\n getSecretsDefaultTypeDefinition,\n readEnvTypeReflection,\n readSecretsReflection\n} from \"./persistence\";\n\nexport function mergeEnvReflections(\n context: EnvPluginContext,\n reflections: ReflectionClass<any>[]\n): ReflectionClass<any> {\n const reflection = createEnvReflection(context, {\n type: merge(reflections.map(reflection => reflection.type))\n });\n\n return reflection;\n}\n\nexport function mergeSecretsReflections(\n context: EnvPluginContext,\n reflections: ReflectionClass<any>[]\n): ReflectionClass<any> {\n const reflection = createSecretsReflection(context, {\n type: merge(reflections.map(reflection => reflection.type))\n });\n\n return reflection;\n}\n\nexport interface CreateEnvReflectionOptions {\n type?: TypeObjectLiteral | TypeClass;\n superReflection?: ReflectionClass<any>;\n}\n\nexport class BaseEnv implements EnvInterface {\n APP_NAME!: string;\n\n APP_VERSION!: string;\n\n BUILD_ID!: string;\n\n BUILD_TIMESTAMP!: string;\n\n BUILD_CHECKSUM!: string;\n\n RELEASE_ID!: string;\n\n RELEASE_TAG!: string;\n\n ORGANIZATION!: string;\n\n PLATFORM: \"node\" | \"browser\" | \"neutral\" = \"neutral\";\n\n MODE: \"development\" | \"test\" | \"production\" = \"production\";\n\n ENVIRONMENT!: string;\n\n DEBUG: boolean = false;\n\n TEST: boolean = false;\n\n MINIMAL: boolean = false;\n\n NO_COLOR: boolean = false;\n\n FORCE_COLOR: number | boolean = false;\n\n FORCE_HYPERLINK: number | boolean = false;\n\n STACKTRACE: boolean = false;\n\n INCLUDE_ERROR_DATA: boolean = false;\n\n ERROR_URL!: string;\n\n DEFAULT_TIMEZONE!: string;\n\n DEFAULT_LOCALE!: string;\n\n CI: boolean = false;\n}\n\nexport class BaseSecrets implements SecretsInterface {\n ENCRYPTION_KEY!: string;\n}\n\nexport function createEnvReflection(\n context: EnvPluginContext,\n options: CreateEnvReflectionOptions = {}\n): ReflectionClass<any> {\n const parent =\n options.superReflection ??\n new ReflectionClass({\n kind: ReflectionKind.class,\n description: `The base environment configuration definition for the ${titleCase(\n context.config.name\n )} project.`,\n classType: BaseEnv,\n types: [],\n implements: [\n {\n kind: ReflectionKind.objectLiteral,\n typeName: \"EnvInterface\",\n description: `The environment configuration interface definition for the ${titleCase(\n context.config.name\n )} project.`,\n types: []\n }\n ]\n });\n parent.name = \"Env\";\n\n const result = new ReflectionClass(\n options.type ?? {\n kind: ReflectionKind.objectLiteral,\n typeName: \"Env\",\n description: `A schema describing the list of available environment variables that can be used by the ${\n context.config.name\n ? `${titleCase(context.config.name)} application`\n : \"application\"\n }.`,\n types: []\n },\n parent\n );\n result.name = \"Env\";\n\n return result;\n}\n\nexport function createSecretsReflection(\n context: EnvPluginContext,\n options: CreateEnvReflectionOptions = {}\n): ReflectionClass<any> {\n const parent =\n options.superReflection ??\n new ReflectionClass({\n kind: ReflectionKind.class,\n description: `The base secrets configuration definition for the ${titleCase(\n context.config.name\n )} project.`,\n classType: BaseSecrets,\n types: [],\n implements: [\n {\n kind: ReflectionKind.objectLiteral,\n typeName: \"SecretsInterface\",\n description: `The secrets configuration interface definition for the ${titleCase(\n context.config.name\n )} project.`,\n types: []\n }\n ]\n });\n parent.name = \"Secrets\";\n\n const result = new ReflectionClass(\n options.type ?? {\n kind: ReflectionKind.objectLiteral,\n typeName: \"Secrets\",\n description: `A schema describing the list of available environment secrets that can be used by the ${\n context.config.name\n ? `${titleCase(context.config.name)} application`\n : \"application\"\n }.`,\n types: []\n },\n parent\n );\n result.name = \"Secrets\";\n\n return result;\n}\n\nexport async function reflectEnv(\n context: EnvPluginContext,\n file?: string,\n name?: string\n) {\n let config: ReflectionClass<any> | undefined;\n if (file) {\n const configType = await reflectType(context, {\n file: !isParentPath(file, context.workspaceConfig.workspaceRoot)\n ? joinPaths(context.workspaceConfig.workspaceRoot, file)\n : file,\n name\n });\n\n config = resolveClassType(configType);\n }\n\n const defaultConfigType = await reflectType(\n context,\n await getEnvDefaultTypeDefinition(context)\n );\n\n const reflection = await readEnvTypeReflection(context, \"env\");\n\n // const defaultConfig = resolveClassType(defaultConfigType);\n // if (config) {\n // defaultConfig.getProperties().forEach(prop => {\n // if (!config!.hasProperty(prop.getName())) {\n // config!.addProperty(prop.property);\n // }\n // });\n // } else {\n // config = defaultConfig;\n // }\n\n return mergeEnvReflections(\n context,\n [reflection, config, resolveClassType(defaultConfigType)].filter(\n Boolean\n ) as ReflectionClass<any>[]\n );\n}\n\nexport async function reflectSecrets(\n context: EnvPluginContext,\n file?: string,\n name?: string\n) {\n let config: ReflectionClass<any> | undefined;\n if (file) {\n const configType = await reflectType(context, {\n file: !isParentPath(file, context.workspaceConfig.workspaceRoot)\n ? joinPaths(context.workspaceConfig.workspaceRoot, file)\n : file,\n name\n });\n\n config = resolveClassType(configType);\n }\n\n const defaultSecretsType = await reflectType(\n context,\n await getSecretsDefaultTypeDefinition(context)\n );\n\n const reflection = await readSecretsReflection(context);\n\n // const defaultConfig = resolveClassType(defaultConfigType);\n // if (config) {\n // defaultConfig.getProperties().forEach(prop => {\n // if (!config!.hasProperty(prop.getName())) {\n // config!.addProperty(prop.property);\n // }\n // });\n // } else {\n // config = defaultConfig;\n // }\n\n return mergeSecretsReflections(\n context,\n [reflection, config, resolveClassType(defaultSecretsType)].filter(\n Boolean\n ) as ReflectionClass<any>[]\n );\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAS,aAAa,IAAI,MAAM;AAC5B,IAAG,SAAS;AACZ,QAAO;;AAyBX,SAAgB,oBAAM,SAAA,aAAA;AAIlB,uCAFI,MAAM,MAAM,YAAY,IAAG,cAAA,eAAA,WAAA,MAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA,EAC9B,CAAC;;AAGN,oBAAoB,SAAS;OAAO;CAAc;OAAA;CAAA;OAAA;CAAA;CAAA;CAAA;AAClD,SAAgB,wBAAwB,SAAS,aAAa;AAI9D,QAHI,wBAAA,SAAA;;;;OAEC,CAAC;;AAGN,wBAAwB,SAAS;OAAM;CAAA;OAAA;CAAA;OAAA;CAAA;CAAA;CAAA;AACvC,MAAM,gCAAqB;OAAA;OAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;AAE3B,IAAa,UAAb,MAAqB;CASjB,WAAW;CACX,OAAO;;CAGP,OAAO;CACP,UAAU;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AAkB;CAAU"}
|
|
1
|
+
{"version":3,"file":"reflect.mjs","names":[],"sources":["../../src/helpers/reflect.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 { reflectType } from \"@powerlines/deepkit/reflect-type\";\nimport {\n merge,\n ReflectionClass,\n ReflectionKind,\n resolveClassType,\n TypeClass,\n TypeObjectLiteral\n} from \"@powerlines/deepkit/vendor/type\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { EnvPluginContext } from \"../types/plugin\";\nimport { EnvInterface, SecretsInterface } from \"../types/runtime\";\nimport {\n getEnvDefaultTypeDefinition,\n getSecretsDefaultTypeDefinition,\n readEnvTypeReflection,\n readSecretsReflection\n} from \"./persistence\";\n\nexport function mergeEnvReflections(\n context: EnvPluginContext,\n reflections: ReflectionClass<any>[]\n): ReflectionClass<any> {\n const reflection = createEnvReflection(context, {\n type: merge(reflections.map(reflection => reflection.type))\n });\n\n return reflection;\n}\n\nexport function mergeSecretsReflections(\n context: EnvPluginContext,\n reflections: ReflectionClass<any>[]\n): ReflectionClass<any> {\n const reflection = createSecretsReflection(context, {\n type: merge(reflections.map(reflection => reflection.type))\n });\n\n return reflection;\n}\n\nexport interface CreateEnvReflectionOptions {\n type?: TypeObjectLiteral | TypeClass;\n superReflection?: ReflectionClass<any>;\n}\n\nexport class BaseEnv implements EnvInterface {\n APP_NAME!: string;\n\n APP_VERSION!: string;\n\n BUILD_ID!: string;\n\n BUILD_TIMESTAMP!: string;\n\n BUILD_CHECKSUM!: string;\n\n RELEASE_ID!: string;\n\n RELEASE_TAG!: string;\n\n ORGANIZATION!: string;\n\n PLATFORM: \"node\" | \"browser\" | \"neutral\" = \"neutral\";\n\n MODE: \"development\" | \"test\" | \"production\" = \"production\";\n\n ENVIRONMENT!: string;\n\n DEBUG: boolean = false;\n\n TEST: boolean = false;\n\n MINIMAL: boolean = false;\n\n NO_COLOR: boolean = false;\n\n FORCE_COLOR: number | boolean = false;\n\n FORCE_HYPERLINK: number | boolean = false;\n\n STACKTRACE: boolean = false;\n\n INCLUDE_ERROR_DATA: boolean = false;\n\n ERROR_URL!: string;\n\n DEFAULT_TIMEZONE!: string;\n\n DEFAULT_LOCALE!: string;\n\n CI: boolean = false;\n}\n\nexport class BaseSecrets implements SecretsInterface {\n ENCRYPTION_KEY!: string;\n}\n\nexport function createEnvReflection(\n context: EnvPluginContext,\n options: CreateEnvReflectionOptions = {}\n): ReflectionClass<any> {\n const parent =\n options.superReflection ??\n new ReflectionClass({\n kind: ReflectionKind.class,\n description: `The base environment configuration definition for the ${titleCase(\n context.config.name\n )} project.`,\n classType: BaseEnv,\n types: [],\n implements: [\n {\n kind: ReflectionKind.objectLiteral,\n typeName: \"EnvInterface\",\n description: `The environment configuration interface definition for the ${titleCase(\n context.config.name\n )} project.`,\n types: []\n }\n ]\n });\n parent.name = \"Env\";\n\n const result = new ReflectionClass(\n options.type ?? {\n kind: ReflectionKind.objectLiteral,\n typeName: \"Env\",\n description: `A schema describing the list of available environment variables that can be used by the ${\n context.config.name\n ? `${titleCase(context.config.name)} application`\n : \"application\"\n }.`,\n types: []\n },\n parent\n );\n result.name = \"Env\";\n\n return result;\n}\n\nexport function createSecretsReflection(\n context: EnvPluginContext,\n options: CreateEnvReflectionOptions = {}\n): ReflectionClass<any> {\n const parent =\n options.superReflection ??\n new ReflectionClass({\n kind: ReflectionKind.class,\n description: `The base secrets configuration definition for the ${titleCase(\n context.config.name\n )} project.`,\n classType: BaseSecrets,\n types: [],\n implements: [\n {\n kind: ReflectionKind.objectLiteral,\n typeName: \"SecretsInterface\",\n description: `The secrets configuration interface definition for the ${titleCase(\n context.config.name\n )} project.`,\n types: []\n }\n ]\n });\n parent.name = \"Secrets\";\n\n const result = new ReflectionClass(\n options.type ?? {\n kind: ReflectionKind.objectLiteral,\n typeName: \"Secrets\",\n description: `A schema describing the list of available environment secrets that can be used by the ${\n context.config.name\n ? `${titleCase(context.config.name)} application`\n : \"application\"\n }.`,\n types: []\n },\n parent\n );\n result.name = \"Secrets\";\n\n return result;\n}\n\n/**\n * Reflects the environment configuration type definition from the provided file and name, and merges it with the default environment configuration reflection and the currently used environment configuration reflection.\n *\n * @remarks\n * The resulting reflection will contain the structure of the expected environment variables as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default environment configuration reflection.\n *\n * @param context - The plugin context\n * @param file - The file path to reflect the environment configuration type definition from\n * @param name - The name of the type definition to reflect the environment configuration from, if the file contains multiple type definitions. If not provided, the first type definition found in the file will be used.\n * @returns A reflection of the environment configuration type definition, merged with the default environment configuration reflection and the currently used environment configuration reflection. The resulting reflection will contain the structure of the expected environment variables as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default environment configuration reflection.\n */\nexport async function reflectEnv(\n context: EnvPluginContext,\n file?: string,\n name?: string\n) {\n let config: ReflectionClass<any> | undefined;\n if (file) {\n const configType = await reflectType(context, {\n file: !isParentPath(file, context.workspaceConfig.workspaceRoot)\n ? joinPaths(context.workspaceConfig.workspaceRoot, file)\n : file,\n name\n });\n\n config = resolveClassType(configType);\n }\n\n return mergeEnvReflections(\n context,\n [\n await readEnvTypeReflection(context, \"env\"),\n config,\n resolveClassType(\n await reflectType(context, await getEnvDefaultTypeDefinition(context))\n )\n ].filter(Boolean) as ReflectionClass<any>[]\n );\n}\n\n/**\n * Reflects the secrets configuration type definition from the provided file and name, and merges it with the default secrets configuration reflection and the currently used secrets configuration reflection.\n *\n * @remarks\n * The resulting reflection will contain the structure of the expected environment secrets as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default secrets configuration reflection.\n *\n * @param context - The plugin context\n * @param file - The file path to reflect the secrets configuration type definition from\n * @param name - The name of the type definition to reflect the secrets configuration from, if the file contains multiple type definitions. If not provided, the first type definition found in the file will be used.\n * @returns A reflection of the secrets configuration type definition, merged with the default secrets configuration reflection and the currently used secrets configuration reflection. The resulting reflection will contain the structure of the expected environment secrets as defined by the type definitions provided in the plugin configuration, as well as any additional properties that are currently used in the source code and defined in the default secrets configuration reflection.\n */\nexport async function reflectSecrets(\n context: EnvPluginContext,\n file?: string,\n name?: string\n) {\n let config: ReflectionClass<any> | undefined;\n if (file) {\n const configType = await reflectType(context, {\n file: !isParentPath(file, context.workspaceConfig.workspaceRoot)\n ? joinPaths(context.workspaceConfig.workspaceRoot, file)\n : file,\n name\n });\n\n config = resolveClassType(configType);\n }\n\n return mergeSecretsReflections(\n context,\n [\n await readSecretsReflection(context),\n config,\n resolveClassType(\n await reflectType(\n context,\n await getSecretsDefaultTypeDefinition(context)\n )\n )\n ].filter(Boolean) as ReflectionClass<any>[]\n );\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAS,aAAa,IAAI,MAAM;AAC5B,IAAG,SAAS;AACZ,QAAO;;AAyBX,SAAgB,oBAAM,SAAA,aAAA;AAIlB,uCAFI,MAAM,MAAM,YAAY,IAAG,cAAA,eAAA,WAAA,MAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA,EAC9B,CAAC;;AAGN,oBAAoB,SAAS;OAAO;CAAc;OAAA;CAAA;OAAA;CAAA;CAAA;CAAA;AAClD,SAAgB,wBAAwB,SAAS,aAAa;AAI9D,QAHI,wBAAA,SAAA;;;;OAEC,CAAC;;AAGN,wBAAwB,SAAS;OAAM;CAAA;OAAA;CAAA;OAAA;CAAA;CAAA;CAAA;AACvC,MAAM,gCAAqB;OAAA;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nB,CAAC,OAAG,QAAA,CAAA;;AAET,eAAK,SAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,6 @@ const require_types_runtime = require('./types/runtime.cjs');
|
|
|
4
4
|
const require_types_plugin = require('./types/plugin.cjs');
|
|
5
5
|
require('./types/index.cjs');
|
|
6
6
|
const require_join_paths = require('./node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/join-paths.cjs');
|
|
7
|
-
const require_is_parent_path = require('./node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/is-parent-path.cjs');
|
|
8
7
|
const require_helpers_reflect = require('./helpers/reflect.cjs');
|
|
9
8
|
const require_helpers_persistence = require('./helpers/persistence.cjs');
|
|
10
9
|
const require_helpers_template_helpers = require('./helpers/template-helpers.cjs');
|
|
@@ -50,6 +49,8 @@ const plugin = (options = {}) => {
|
|
|
50
49
|
const config = {
|
|
51
50
|
env: require_defu.defu(options, {
|
|
52
51
|
types: {},
|
|
52
|
+
validate: false,
|
|
53
|
+
inject: false,
|
|
53
54
|
prefix: []
|
|
54
55
|
}),
|
|
55
56
|
transform: { babel: { plugins: [require_babel_plugin.envBabelPlugin] } }
|
|
@@ -58,12 +59,14 @@ const plugin = (options = {}) => {
|
|
|
58
59
|
else {
|
|
59
60
|
this.warn("The `env.types` configuration parameter was not provided. Please ensure this is expected.");
|
|
60
61
|
const envDefaultTypeDefinition = await require_helpers_persistence.getEnvDefaultTypeDefinition(this);
|
|
61
|
-
|
|
62
|
+
const file = await this.fs.resolve(envDefaultTypeDefinition.file);
|
|
63
|
+
if (file) config.env.types = require_parse_type_definition.parseTypeDefinition(`${file}#${envDefaultTypeDefinition.name}`);
|
|
62
64
|
}
|
|
63
65
|
if (config.env.secrets) config.env.secrets = require_parse_type_definition.parseTypeDefinition(config.env.secrets);
|
|
64
66
|
else {
|
|
65
67
|
const secretsDefaultTypeDefinition = await require_helpers_persistence.getSecretsDefaultTypeDefinition(this);
|
|
66
|
-
|
|
68
|
+
const file = await this.fs.resolve(secretsDefaultTypeDefinition.file);
|
|
69
|
+
if (file) config.env.secrets = require_parse_type_definition.parseTypeDefinition(`${file}#${secretsDefaultTypeDefinition.name}`);
|
|
67
70
|
}
|
|
68
71
|
config.env.prefix = require_to_array.toArray(config.env.prefix ?? []).reduce((ret, prefix) => {
|
|
69
72
|
const formattedPrefix = (0, __stryke_string_format_constant_case.constantCase)(prefix);
|
|
@@ -82,7 +85,11 @@ const plugin = (options = {}) => {
|
|
|
82
85
|
},
|
|
83
86
|
async configResolved() {
|
|
84
87
|
this.debug(`Environment plugin configuration has been resolved for the Powerlines project.`);
|
|
85
|
-
this.env = require_defu.defu({
|
|
88
|
+
this.env = require_defu.defu({
|
|
89
|
+
parsed: await require_helpers_load.loadEnv(this, this.config.env),
|
|
90
|
+
validate: !!this.config.env.validate,
|
|
91
|
+
inject: !!this.config.env.inject
|
|
92
|
+
}, this.env ?? {}, {
|
|
86
93
|
types: { env: {} },
|
|
87
94
|
used: {
|
|
88
95
|
env: {},
|
|
@@ -99,10 +106,10 @@ const plugin = (options = {}) => {
|
|
|
99
106
|
if ((0, __stryke_fs_exists.existsSync)(require_helpers_persistence.getEnvReflectionsPath(this, "secrets"))) this.env.used.secrets = await require_helpers_persistence.readSecretsReflection(this);
|
|
100
107
|
} else {
|
|
101
108
|
this.debug(`Starting environment configuration reflection initialization.`);
|
|
102
|
-
this.env.types.env = await require_helpers_reflect.reflectEnv(this, this.config.env.types?.file
|
|
109
|
+
this.env.types.env = await require_helpers_reflect.reflectEnv(this, this.config.env.types?.file, this.config.env.types?.name);
|
|
103
110
|
if (!this.env.types.env) throw new Error("Failed to find the environment configuration type reflection in the context.");
|
|
104
111
|
await require_helpers_persistence.writeEnvTypeReflection(this, this.env.types.env, "env");
|
|
105
|
-
this.env.types.secrets = await require_helpers_reflect.reflectSecrets(this, this.config.env.secrets?.file
|
|
112
|
+
this.env.types.secrets = await require_helpers_reflect.reflectSecrets(this, this.config.env.secrets?.file, this.config.env.secrets?.name);
|
|
106
113
|
if (!this.env.types.secrets) throw new Error("Failed to find the secrets configuration type reflection in the context.");
|
|
107
114
|
await require_helpers_persistence.writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
|
|
108
115
|
this.debug(`Resolved ${this.env.types.env.getProperties().length ?? 0} environment configuration parameters and ${this.env.types.secrets?.getProperties().length ?? 0} secret configuration parameters`);
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;cAmEa,0BAA2B,mBAAmB,4BAChD,qBA6UJ,OAAO"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;cAmEa,0BAA2B,mBAAmB,4BAChD,qBA6UJ,OAAO"}
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { __ΩEnvInterface, __ΩSecretsInterface } from "./types/runtime.mjs";
|
|
|
2
2
|
import { __ΩEnvPluginContext, __ΩEnvPluginOptions, __ΩEnvPluginResolvedConfig, __ΩEnvPluginUserConfig, __ΩEnvType } from "./types/plugin.mjs";
|
|
3
3
|
import "./types/index.mjs";
|
|
4
4
|
import { joinPaths } from "./node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/join-paths.mjs";
|
|
5
|
-
import { isParentPath } from "./node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/is-parent-path.mjs";
|
|
6
5
|
import { BaseEnv, BaseSecrets, __ΩCreateEnvReflectionOptions, createEnvReflection, createSecretsReflection, mergeEnvReflections, mergeSecretsReflections, reflectEnv, reflectSecrets } from "./helpers/reflect.mjs";
|
|
7
6
|
import { getEnvDefaultTypeDefinition, getEnvReflectionsPath, getEnvTypeReflectionsPath, getSecretsDefaultTypeDefinition, readEnvReflection, readEnvTypeReflection, readSecretsReflection, resolveRuntimeTypeFile, writeEnvReflection, writeEnvReflectionSync, writeEnvTypeReflection } from "./helpers/persistence.mjs";
|
|
8
7
|
import { createTemplateReflection } from "./helpers/template-helpers.mjs";
|
|
@@ -45,6 +44,8 @@ const plugin = (options = {}) => {
|
|
|
45
44
|
const config = {
|
|
46
45
|
env: defu(options, {
|
|
47
46
|
types: {},
|
|
47
|
+
validate: false,
|
|
48
|
+
inject: false,
|
|
48
49
|
prefix: []
|
|
49
50
|
}),
|
|
50
51
|
transform: { babel: { plugins: [envBabelPlugin] } }
|
|
@@ -53,12 +54,14 @@ const plugin = (options = {}) => {
|
|
|
53
54
|
else {
|
|
54
55
|
this.warn("The `env.types` configuration parameter was not provided. Please ensure this is expected.");
|
|
55
56
|
const envDefaultTypeDefinition = await getEnvDefaultTypeDefinition(this);
|
|
56
|
-
|
|
57
|
+
const file = await this.fs.resolve(envDefaultTypeDefinition.file);
|
|
58
|
+
if (file) config.env.types = parseTypeDefinition(`${file}#${envDefaultTypeDefinition.name}`);
|
|
57
59
|
}
|
|
58
60
|
if (config.env.secrets) config.env.secrets = parseTypeDefinition(config.env.secrets);
|
|
59
61
|
else {
|
|
60
62
|
const secretsDefaultTypeDefinition = await getSecretsDefaultTypeDefinition(this);
|
|
61
|
-
|
|
63
|
+
const file = await this.fs.resolve(secretsDefaultTypeDefinition.file);
|
|
64
|
+
if (file) config.env.secrets = parseTypeDefinition(`${file}#${secretsDefaultTypeDefinition.name}`);
|
|
62
65
|
}
|
|
63
66
|
config.env.prefix = toArray(config.env.prefix ?? []).reduce((ret, prefix) => {
|
|
64
67
|
const formattedPrefix = constantCase(prefix);
|
|
@@ -77,7 +80,11 @@ const plugin = (options = {}) => {
|
|
|
77
80
|
},
|
|
78
81
|
async configResolved() {
|
|
79
82
|
this.debug(`Environment plugin configuration has been resolved for the Powerlines project.`);
|
|
80
|
-
this.env = defu({
|
|
83
|
+
this.env = defu({
|
|
84
|
+
parsed: await loadEnv(this, this.config.env),
|
|
85
|
+
validate: !!this.config.env.validate,
|
|
86
|
+
inject: !!this.config.env.inject
|
|
87
|
+
}, this.env ?? {}, {
|
|
81
88
|
types: { env: {} },
|
|
82
89
|
used: {
|
|
83
90
|
env: {},
|
|
@@ -94,10 +101,10 @@ const plugin = (options = {}) => {
|
|
|
94
101
|
if (existsSync(getEnvReflectionsPath(this, "secrets"))) this.env.used.secrets = await readSecretsReflection(this);
|
|
95
102
|
} else {
|
|
96
103
|
this.debug(`Starting environment configuration reflection initialization.`);
|
|
97
|
-
this.env.types.env = await reflectEnv(this, this.config.env.types?.file
|
|
104
|
+
this.env.types.env = await reflectEnv(this, this.config.env.types?.file, this.config.env.types?.name);
|
|
98
105
|
if (!this.env.types.env) throw new Error("Failed to find the environment configuration type reflection in the context.");
|
|
99
106
|
await writeEnvTypeReflection(this, this.env.types.env, "env");
|
|
100
|
-
this.env.types.secrets = await reflectSecrets(this, this.config.env.secrets?.file
|
|
107
|
+
this.env.types.secrets = await reflectSecrets(this, this.config.env.secrets?.file, this.config.env.secrets?.name);
|
|
101
108
|
if (!this.env.types.secrets) throw new Error("Failed to find the secrets configuration type reflection in the context.");
|
|
102
109
|
await writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
|
|
103
110
|
this.debug(`Resolved ${this.env.types.env.getProperties().length ?? 0} environment configuration parameters and ${this.env.types.secrets?.getProperties().length ?? 0} secret configuration parameters`);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["ReflectionClass","ReflectionKind","alloy","render","automd","babel","parseTypeDefinition","toArray","ENV_PREFIXES","existsSync","isParentPath","joinPaths","constantCase","defu","envBabelPlugin","EnvDocsFile","EnvBuiltin","env","getDocsOutputPath","loadEnv","getEnvDefaultTypeDefinition","getEnvReflectionsPath","getEnvTypeReflectionsPath","getSecretsDefaultTypeDefinition","readEnvReflection","readEnvTypeReflection","readSecretsReflection","writeEnvReflection","writeEnvTypeReflection","reflectEnv","reflectSecrets","plugin","options","name","config","debug","types","prefix","transform","plugins","warn","envDefaultTypeDefinition","file","secrets","secretsDefaultTypeDefinition","reduce","ret","formattedPrefix","includes","push","framework","filter","Boolean","replace","configResolved","parsed","used","injected","command","skipCache","persistedMeta","checksum","meta","workspaceConfig","workspaceRoot","projectRoot","undefined","Error","getProperties","length","envWithAlias","prop","getAlias","Object","entries","forEach","key","value","unprefixedKey","startsWith","slice","aliasKey","find","reverse","hasProperty","getProperty","setDefaultValue","kind","objectLiteral","typeName","description","prepare","_self$","result","_$createComponent","defaultConfig","reflection","order","handler","trace","docs","levelOffset","buildEnd","reflectionPath","generators","vite","envPrefix"],"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 {\n ReflectionClass,\n ReflectionKind\n} from \"@powerlines/deepkit/vendor/type\";\nimport alloy from \"@powerlines/plugin-alloy\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport babel from \"@powerlines/plugin-babel\";\nimport { parseTypeDefinition } from \"@stryke/convert/parse-type-definition\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { ENV_PREFIXES } from \"@stryke/env/types\";\nimport { existsSync } from \"@stryke/fs/exists\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport {\n TypeDefinition,\n TypeDefinitionParameter\n} from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines/types/plugin\";\nimport type { UserConfig as ViteUserConfig } from \"vite\";\nimport { envBabelPlugin } from \"./babel/plugin\";\nimport { EnvDocsFile } from \"./components/docs\";\nimport { EnvBuiltin } from \"./components/env\";\nimport { env } from \"./helpers/automd-generator\";\nimport { getDocsOutputPath } from \"./helpers/docs-helper\";\nimport { loadEnv } from \"./helpers/load\";\nimport {\n getEnvDefaultTypeDefinition,\n getEnvReflectionsPath,\n getEnvTypeReflectionsPath,\n getSecretsDefaultTypeDefinition,\n readEnvReflection,\n readEnvTypeReflection,\n readSecretsReflection,\n writeEnvReflection,\n writeEnvTypeReflection\n} from \"./helpers/persistence\";\nimport { reflectEnv, reflectSecrets } from \"./helpers/reflect\";\nimport { EnvPluginContext, EnvPluginOptions } from \"./types/plugin\";\n\nexport * from \"./babel\";\nexport * from \"./components\";\nexport * from \"./helpers\";\nexport * from \"./types\";\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 alloy(options.alloy),\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 types: {} as TypeDefinitionParameter,\n prefix: []\n }),\n transform: {\n babel: {\n plugins: [envBabelPlugin]\n }\n }\n };\n\n if (config.env.types) {\n config.env.types = parseTypeDefinition(\n config.env.types\n ) as TypeDefinition;\n } else {\n this.warn(\n \"The `env.types` configuration parameter was not provided. Please ensure this is expected.\"\n );\n\n const envDefaultTypeDefinition =\n await getEnvDefaultTypeDefinition(this);\n config.env.types = parseTypeDefinition(\n `${envDefaultTypeDefinition.file}#${envDefaultTypeDefinition.name}`\n ) as TypeDefinition;\n }\n\n if (config.env.secrets) {\n config.env.secrets = parseTypeDefinition(\n config.env.secrets\n ) as TypeDefinition;\n } else {\n const secretsDefaultTypeDefinition =\n await getSecretsDefaultTypeDefinition(this);\n config.env.secrets = parseTypeDefinition(\n `${secretsDefaultTypeDefinition.file}#${\n secretsDefaultTypeDefinition.name\n }`\n ) as TypeDefinition;\n }\n\n config.env.prefix = toArray(\n (config.env.prefix ?? []) as string[]\n ).reduce(\n (ret: string[], prefix: string) => {\n const formattedPrefix = constantCase(prefix);\n if (!ret.includes(formattedPrefix)) {\n ret.push(formattedPrefix);\n }\n\n return ret;\n },\n [\n ...ENV_PREFIXES,\n \"POWERLINES_\",\n this.config.framework &&\n this.config.framework !== \"powerlines\" &&\n `${constantCase(this.config.framework)}_`\n ].filter(Boolean) as string[]\n );\n\n config.env.prefix = toArray(config.env.prefix).reduce((ret, prefix) => {\n if (!ret.includes(prefix.replace(/_$/g, \"\"))) {\n ret.push(prefix.replace(/_$/g, \"\"));\n }\n return ret;\n }, [] as string[]);\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 this.env = defu(\n {\n parsed: await loadEnv(this, this.config.env)\n },\n this.env ?? {},\n {\n types: {\n env: {}\n },\n used: {\n env: {},\n secrets: {}\n },\n parsed: {},\n injected: {}\n }\n ) as EnvPluginContext[\"env\"];\n\n if (\n this.config.command !== \"prepare\" &&\n !this.config.skipCache &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n existsSync(getEnvTypeReflectionsPath(this, \"env\"))\n ) {\n this.debug(\n `Skipping reflection initialization as the meta checksum has not changed.`\n );\n\n this.env.types.env = await readEnvTypeReflection(this, \"env\");\n\n if (existsSync(getEnvReflectionsPath(this, \"env\"))) {\n this.env.used.env = await readEnvReflection(this);\n }\n\n if (existsSync(getEnvTypeReflectionsPath(this, \"secrets\"))) {\n this.env.types.secrets = await readEnvTypeReflection(\n this,\n \"secrets\"\n );\n }\n\n if (existsSync(getEnvReflectionsPath(this, \"secrets\"))) {\n this.env.used.secrets = await readSecretsReflection(this);\n }\n } else {\n this.debug(\n `Starting environment configuration reflection initialization.`\n );\n\n this.env.types.env = await reflectEnv(\n this,\n this.config.env.types?.file\n ? isParentPath(\n this.config.env.types?.file,\n this.workspaceConfig.workspaceRoot\n )\n ? this.config.env.types?.file\n : joinPaths(\n this.config.projectRoot,\n this.config.env.types?.file\n )\n : undefined,\n this.config.env.types?.name\n );\n if (!this.env.types.env) {\n throw new Error(\n \"Failed to find the environment configuration type reflection in the context.\"\n );\n }\n\n await writeEnvTypeReflection(this, this.env.types.env, \"env\");\n\n this.env.types.secrets = await reflectSecrets(\n this,\n this.config.env.secrets?.file\n ? isParentPath(\n this.config.env.secrets?.file,\n this.workspaceConfig.workspaceRoot\n )\n ? this.config.env.secrets?.file\n : joinPaths(\n this.config.projectRoot,\n this.config.env.secrets?.file\n )\n : undefined,\n this.config.env.secrets?.name\n );\n if (!this.env.types.secrets) {\n throw new Error(\n \"Failed to find the secrets configuration type reflection in the context.\"\n );\n }\n\n await writeEnvTypeReflection(this, this.env.types.secrets, \"secrets\");\n\n this.debug(\n `Resolved ${\n this.env.types.env.getProperties().length ?? 0\n } environment configuration parameters and ${\n this.env.types.secrets?.getProperties().length ?? 0\n } secret configuration parameters`\n );\n\n const envWithAlias = this.env.types.env\n .getProperties()\n .filter(prop => prop.getAlias().length > 0);\n\n Object.entries(await loadEnv(this, this.config.env)).forEach(\n ([key, value]) => {\n const unprefixedKey = this.config.env.prefix.reduce(\n (ret, prefix) => {\n if (key.replace(/_$/g, \"\").startsWith(prefix)) {\n return key.replace(/_$/g, \"\").slice(prefix.length);\n }\n return ret;\n },\n key\n );\n\n const aliasKey = envWithAlias.find(prop =>\n prop?.getAlias().reverse().includes(unprefixedKey)\n );\n if (this.env.types.env?.hasProperty(unprefixedKey) || aliasKey) {\n this.env.types.env\n .getProperty(unprefixedKey)\n .setDefaultValue(value);\n }\n }\n );\n\n this.env.used.env = new ReflectionClass(\n {\n kind: ReflectionKind.objectLiteral,\n typeName: \"Env\",\n description: `An object containing the environment configuration parameters used by the ${\n this.config.name\n ? `${this.config.name} application`\n : \"application\"\n }.`,\n types: []\n },\n this.env.types.env\n );\n\n await writeEnvReflection(this, this.env.used.env, \"env\");\n\n if (this.env.types.secrets) {\n await writeEnvTypeReflection(\n this,\n this.env.types.secrets,\n \"secrets\"\n );\n\n this.env.used.secrets = new ReflectionClass(\n {\n kind: ReflectionKind.objectLiteral,\n typeName: \"Secrets\",\n description: `An object containing the secret configuration parameters used by the ${\n this.config.name\n ? `${this.config.name} application`\n : \"application\"\n }.`,\n types: []\n },\n this.env.types.secrets\n );\n await writeEnvReflection(this, this.env.used.secrets, \"secrets\");\n }\n }\n },\n async prepare() {\n this.debug(\n `Preparing the Environment runtime artifacts for the Powerlines project.`\n );\n\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <EnvBuiltin\n defaultConfig={this.config.env.defaultConfig}\n reflection={result}\n />\n );\n },\n transform: {\n order: \"post\",\n async handler() {\n if (this.env.used.env.getProperties().length > 0) {\n this.trace(\n `Persisting used environment configuration reflections to ${getEnvReflectionsPath(\n this,\n \"env\"\n )}.`\n );\n await writeEnvReflection(this, this.env.used.env, \"env\");\n }\n\n if (this.env.used.secrets.getProperties().length > 0) {\n this.trace(\n `Persisting used secret configuration reflections to ${getEnvReflectionsPath(\n this,\n \"secrets\"\n )}.`\n );\n await writeEnvReflection(this, this.env.used.secrets, \"secrets\");\n }\n }\n },\n async docs() {\n this.debug(\n `Documenting environment variables configuration values in \"${joinPaths(\n getDocsOutputPath(this),\n \"env.md\"\n )}\"`\n );\n\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <EnvDocsFile levelOffset={0} reflection={result} />\n );\n },\n async buildEnd() {\n const reflectionPath = getEnvReflectionsPath(this, \"env\");\n\n this.debug(`Writing env reflection types to ${reflectionPath}.`);\n\n await writeEnvReflection(this, this.env.used.env, \"env\");\n }\n },\n {\n name: \"env:automd-generator\",\n config() {\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAa+B,UACXC,UAA4B,EAAE,KAC3B;AACH,QAAO;EACL9B,MAAM8B,QAAQ9B,MAAM;EACpBG,MAAM2B,QAAQ3B,MAAM;EACpB;GACE4B,MAAM;GACN,MAAMC,SAAS;AACb,SAAKC,MACH,yEACD;IAED,MAAMD,SAAS;KACbjB,KAAKJ,KAAKmB,SAAS;MACjBI,OAAO,EAA6B;MACpCC,QAAQ,EAAA;MACT,CAAC;KACFC,WAAW,EACTjC,OAAO,EACLkC,SAAS,CAACzB,eAAc,EAC1B,EACF;KACD;AAED,QAAIoB,OAAOjB,IAAImB,MACbF,QAAOjB,IAAImB,QAAQ9B,oBACjB4B,OAAOjB,IAAImB,MACM;SACd;AACL,UAAKI,KACH,4FACD;KAED,MAAMC,2BACJ,MAAMrB,4BAA4B,KAAK;AACzCc,YAAOjB,IAAImB,QAAQ9B,oBACjB,GAAGmC,yBAAyBC,KAAI,GAAID,yBAAyBR,OAC5C;;AAGrB,QAAIC,OAAOjB,IAAI0B,QACbT,QAAOjB,IAAI0B,UAAUrC,oBACnB4B,OAAOjB,IAAI0B,QACM;SACd;KACL,MAAMC,+BACJ,MAAMrB,gCAAgC,KAAK;AAC7CW,YAAOjB,IAA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F,aAAa;KAAGL,YAAYH;KAAM,CACjD,CAAC;;GAEH,MAAMS,WAAW;IACf,MAAMC,iBAAiBlF,sBAAsB,MAAM,MAAM;AAEzD,SAAKc,MAAM,mCAAmCoE,eAAc,GAAI;AAEhE,UAAM5E,mBAAmB,MAAM,KAAKV,IAAIuC,KAAKvC,KAAK,MAAM;;GAE3D;EACD;GACEgB,MAAM;GACNC,SAAS;AACP,WAAO,EACL9B,QAAQS,KAAKmB,QAAQ5B,UAAU,EAAE,EAAE,EACjCoG,YAAY,EACVvF,KAAKA,IAAI,KAAI,EACf,EACD,CAAA,EACF;;GAEJ;EACD;GACEgB,MAAM;GACNwE,MAAM,EACJnD,iBAA+B;AAC7B,WAAO,EACLoD,WAAW,KAAKxE,QAAQjB,KAAKoB,QAC9B;MAEL;GACD;EACDjC,OAAO4B,QAAQ5B,OAAO;EACvB;;AAGH,kBAAe2B"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["ReflectionClass","ReflectionKind","alloy","render","automd","babel","parseTypeDefinition","toArray","ENV_PREFIXES","existsSync","joinPaths","constantCase","defu","envBabelPlugin","EnvDocsFile","EnvBuiltin","env","getDocsOutputPath","loadEnv","getEnvDefaultTypeDefinition","getEnvReflectionsPath","getEnvTypeReflectionsPath","getSecretsDefaultTypeDefinition","readEnvReflection","readEnvTypeReflection","readSecretsReflection","writeEnvReflection","writeEnvTypeReflection","reflectEnv","reflectSecrets","plugin","options","name","config","debug","types","validate","inject","prefix","transform","plugins","warn","envDefaultTypeDefinition","file","fs","resolve","secrets","secretsDefaultTypeDefinition","reduce","ret","formattedPrefix","includes","push","framework","filter","Boolean","replace","configResolved","parsed","used","injected","command","skipCache","persistedMeta","checksum","meta","Error","getProperties","length","envWithAlias","prop","getAlias","Object","entries","forEach","key","value","unprefixedKey","startsWith","slice","aliasKey","find","reverse","hasProperty","getProperty","setDefaultValue","kind","objectLiteral","typeName","description","prepare","_self$","result","_$createComponent","defaultConfig","reflection","order","handler","trace","docs","levelOffset","buildEnd","reflectionPath","generators","vite","envPrefix"],"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 {\n ReflectionClass,\n ReflectionKind\n} from \"@powerlines/deepkit/vendor/type\";\nimport alloy from \"@powerlines/plugin-alloy\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport babel from \"@powerlines/plugin-babel\";\nimport { parseTypeDefinition } from \"@stryke/convert/parse-type-definition\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { ENV_PREFIXES } from \"@stryke/env/types\";\nimport { existsSync } from \"@stryke/fs/exists\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport {\n TypeDefinition,\n TypeDefinitionParameter\n} from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines/types/plugin\";\nimport type { UserConfig as ViteUserConfig } from \"vite\";\nimport { envBabelPlugin } from \"./babel/plugin\";\nimport { EnvDocsFile } from \"./components/docs\";\nimport { EnvBuiltin } from \"./components/env\";\nimport { env } from \"./helpers/automd-generator\";\nimport { getDocsOutputPath } from \"./helpers/docs-helper\";\nimport { loadEnv } from \"./helpers/load\";\nimport {\n getEnvDefaultTypeDefinition,\n getEnvReflectionsPath,\n getEnvTypeReflectionsPath,\n getSecretsDefaultTypeDefinition,\n readEnvReflection,\n readEnvTypeReflection,\n readSecretsReflection,\n writeEnvReflection,\n writeEnvTypeReflection\n} from \"./helpers/persistence\";\nimport { reflectEnv, reflectSecrets } from \"./helpers/reflect\";\nimport { EnvPluginContext, EnvPluginOptions } from \"./types/plugin\";\n\nexport * from \"./babel\";\nexport * from \"./components\";\nexport * from \"./helpers\";\nexport * from \"./types\";\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 alloy(options.alloy),\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 types: {} as TypeDefinitionParameter,\n validate: false,\n inject: false,\n prefix: []\n }),\n transform: {\n babel: {\n plugins: [envBabelPlugin]\n }\n }\n };\n\n if (config.env.types) {\n config.env.types = parseTypeDefinition(\n config.env.types\n ) as TypeDefinition;\n } else {\n this.warn(\n \"The `env.types` configuration parameter was not provided. Please ensure this is expected.\"\n );\n\n const envDefaultTypeDefinition =\n await getEnvDefaultTypeDefinition(this);\n\n const file = await this.fs.resolve(envDefaultTypeDefinition.file);\n if (file) {\n config.env.types = parseTypeDefinition(\n `${file}#${envDefaultTypeDefinition.name}`\n ) as TypeDefinition;\n }\n }\n\n if (config.env.secrets) {\n config.env.secrets = parseTypeDefinition(\n config.env.secrets\n ) as TypeDefinition;\n } else {\n const secretsDefaultTypeDefinition =\n await getSecretsDefaultTypeDefinition(this);\n\n const file = await this.fs.resolve(secretsDefaultTypeDefinition.file);\n if (file) {\n config.env.secrets = parseTypeDefinition(\n `${file}#${secretsDefaultTypeDefinition.name}`\n ) as TypeDefinition;\n }\n }\n\n config.env.prefix = toArray(\n (config.env.prefix ?? []) as string[]\n ).reduce(\n (ret: string[], prefix: string) => {\n const formattedPrefix = constantCase(prefix);\n if (!ret.includes(formattedPrefix)) {\n ret.push(formattedPrefix);\n }\n\n return ret;\n },\n [\n ...ENV_PREFIXES,\n \"POWERLINES_\",\n this.config.framework &&\n this.config.framework !== \"powerlines\" &&\n `${constantCase(this.config.framework)}_`\n ].filter(Boolean) as string[]\n );\n\n config.env.prefix = toArray(config.env.prefix).reduce((ret, prefix) => {\n if (!ret.includes(prefix.replace(/_$/g, \"\"))) {\n ret.push(prefix.replace(/_$/g, \"\"));\n }\n return ret;\n }, [] as string[]);\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 this.env = defu(\n {\n parsed: await loadEnv(this, this.config.env),\n validate: !!this.config.env.validate,\n inject: !!this.config.env.inject\n },\n this.env ?? {},\n {\n types: {\n env: {}\n },\n used: {\n env: {},\n secrets: {}\n },\n parsed: {},\n injected: {}\n }\n ) as EnvPluginContext[\"env\"];\n\n if (\n this.config.command !== \"prepare\" &&\n !this.config.skipCache &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n existsSync(getEnvTypeReflectionsPath(this, \"env\"))\n ) {\n this.debug(\n `Skipping reflection initialization as the meta checksum has not changed.`\n );\n\n this.env.types.env = await readEnvTypeReflection(this, \"env\");\n\n if (existsSync(getEnvReflectionsPath(this, \"env\"))) {\n this.env.used.env = await readEnvReflection(this);\n }\n\n if (existsSync(getEnvTypeReflectionsPath(this, \"secrets\"))) {\n this.env.types.secrets = await readEnvTypeReflection(\n this,\n \"secrets\"\n );\n }\n\n if (existsSync(getEnvReflectionsPath(this, \"secrets\"))) {\n this.env.used.secrets = await readSecretsReflection(this);\n }\n } else {\n this.debug(\n `Starting environment configuration reflection initialization.`\n );\n\n this.env.types.env = await reflectEnv(\n this,\n this.config.env.types?.file,\n this.config.env.types?.name\n );\n if (!this.env.types.env) {\n throw new Error(\n \"Failed to find the environment configuration type reflection in the context.\"\n );\n }\n\n await writeEnvTypeReflection(this, this.env.types.env, \"env\");\n\n this.env.types.secrets = await reflectSecrets(\n this,\n this.config.env.secrets?.file,\n this.config.env.secrets?.name\n );\n if (!this.env.types.secrets) {\n throw new Error(\n \"Failed to find the secrets configuration type reflection in the context.\"\n );\n }\n\n await writeEnvTypeReflection(this, this.env.types.secrets, \"secrets\");\n\n this.debug(\n `Resolved ${\n this.env.types.env.getProperties().length ?? 0\n } environment configuration parameters and ${\n this.env.types.secrets?.getProperties().length ?? 0\n } secret configuration parameters`\n );\n\n const envWithAlias = this.env.types.env\n .getProperties()\n .filter(prop => prop.getAlias().length > 0);\n\n Object.entries(await loadEnv(this, this.config.env)).forEach(\n ([key, value]) => {\n const unprefixedKey = this.config.env.prefix.reduce(\n (ret, prefix) => {\n if (key.replace(/_$/g, \"\").startsWith(prefix)) {\n return key.replace(/_$/g, \"\").slice(prefix.length);\n }\n return ret;\n },\n key\n );\n\n const aliasKey = envWithAlias.find(prop =>\n prop?.getAlias().reverse().includes(unprefixedKey)\n );\n if (this.env.types.env?.hasProperty(unprefixedKey) || aliasKey) {\n this.env.types.env\n .getProperty(unprefixedKey)\n .setDefaultValue(value);\n }\n }\n );\n\n this.env.used.env = new ReflectionClass(\n {\n kind: ReflectionKind.objectLiteral,\n typeName: \"Env\",\n description: `An object containing the environment configuration parameters used by the ${\n this.config.name\n ? `${this.config.name} application`\n : \"application\"\n }.`,\n types: []\n },\n this.env.types.env\n );\n\n await writeEnvReflection(this, this.env.used.env, \"env\");\n\n if (this.env.types.secrets) {\n await writeEnvTypeReflection(\n this,\n this.env.types.secrets,\n \"secrets\"\n );\n\n this.env.used.secrets = new ReflectionClass(\n {\n kind: ReflectionKind.objectLiteral,\n typeName: \"Secrets\",\n description: `An object containing the secret configuration parameters used by the ${\n this.config.name\n ? `${this.config.name} application`\n : \"application\"\n }.`,\n types: []\n },\n this.env.types.secrets\n );\n await writeEnvReflection(this, this.env.used.secrets, \"secrets\");\n }\n }\n },\n async prepare() {\n this.debug(\n `Preparing the Environment runtime artifacts for the Powerlines project.`\n );\n\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <EnvBuiltin\n defaultConfig={this.config.env.defaultConfig}\n reflection={result}\n />\n );\n },\n transform: {\n order: \"post\",\n async handler() {\n if (this.env.used.env.getProperties().length > 0) {\n this.trace(\n `Persisting used environment configuration reflections to ${getEnvReflectionsPath(\n this,\n \"env\"\n )}.`\n );\n await writeEnvReflection(this, this.env.used.env, \"env\");\n }\n\n if (this.env.used.secrets.getProperties().length > 0) {\n this.trace(\n `Persisting used secret configuration reflections to ${getEnvReflectionsPath(\n this,\n \"secrets\"\n )}.`\n );\n await writeEnvReflection(this, this.env.used.secrets, \"secrets\");\n }\n }\n },\n async docs() {\n this.debug(\n `Documenting environment variables configuration values in \"${joinPaths(\n getDocsOutputPath(this),\n \"env.md\"\n )}\"`\n );\n\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <EnvDocsFile levelOffset={0} reflection={result} />\n );\n },\n async buildEnd() {\n const reflectionPath = getEnvReflectionsPath(this, \"env\");\n\n this.debug(`Writing env reflection types to ${reflectionPath}.`);\n\n await writeEnvReflection(this, this.env.used.env, \"env\");\n }\n },\n {\n name: \"env:automd-generator\",\n config() {\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa8B,UACXC,UAA4B,EAAE,KAC3B;AACH,QAAO;EACL7B,MAAM6B,QAAQ7B,MAAM;EACpBG,MAAM0B,QAAQ1B,MAAM;EACpB;GACE2B,MAAM;GACN,MAAMC,SAAS;AACb,SAAKC,MACH,yEACD;IAED,MAAMD,SAAS;KACbjB,KAAKJ,KAAKmB,SAAS;MACjBI,OAAO,EAA6B;MACpCC,UAAU;MACVC,QAAQ;MACRC,QAAQ,EAAA;MACT,CAAC;KACFC,WAAW,EACTlC,OAAO,EACLmC,SAAS,CAAC3B,eAAc,EAC1B,EACF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AACD,YAAMM,mBAAmB,MAAM,KAAKV,IAAI2C,KAAKb,SAAS,UAAU;;;IAGrE;GACD,MAAMqD,OAAO;AACX,SAAKjE,MACH,8DAA8DxB,UAC5DO,kBAAkB,KAAK,EACvB,SACD,CAAA,GACF;IAED,MAAM2E,SAAS,MAAMpE,sBAAsB,MAAM,MAAM;AAEvD,WAAOrB,OACL,MAAI0F,gBACH/E,aAAW;KAACsF,aAAa;KAAGL,YAAYH;KAAM,CACjD,CAAC;;GAEH,MAAMS,WAAW;IACf,MAAMC,iBAAiBlF,sBAAsB,MAAM,MAAM;AAEzD,SAAKc,MAAM,mCAAmCoE,eAAc,GAAI;AAEhE,UAAM5E,mBAAmB,MAAM,KAAKV,IAAI2C,KAAK3C,KAAK,MAAM;;GAE3D;EACD;GACEgB,MAAM;GACNC,SAAS;AACP,WAAO,EACL7B,QAAQQ,KAAKmB,QAAQ3B,UAAU,EAAE,EAAE,EACjCmG,YAAY,EACVvF,KAAKA,IAAI,KAAI,EACf,EACD,CAAA,EACF;;GAEJ;EACD;GACEgB,MAAM;GACNwE,MAAM,EACJ/C,iBAA+B;AAC7B,WAAO,EACLgD,WAAW,KAAKxE,QAAQjB,KAAKsB,QAC9B;MAEL;GACD;EACDlC,OAAO2B,QAAQ3B,OAAO;EACvB;;AAGH,kBAAe0B"}
|
package/dist/types/plugin.cjs
CHANGED
|
@@ -49,6 +49,8 @@ const __ΩEnvPluginOptions = [
|
|
|
49
49
|
"inject",
|
|
50
50
|
true,
|
|
51
51
|
"Should the plugin inject the env variables in the source code with their values?",
|
|
52
|
+
"validate",
|
|
53
|
+
"Should the plugin validate the loaded environment variables against the provided type definitions?",
|
|
52
54
|
"Children",
|
|
53
55
|
"defaultConfig",
|
|
54
56
|
"The default configuration to use when loading environment variables.",
|
|
@@ -62,7 +64,7 @@ const __ΩEnvPluginOptions = [
|
|
|
62
64
|
"alloy",
|
|
63
65
|
"Alloy configuration options to use when injecting environment variables into the source code.",
|
|
64
66
|
"EnvPluginOptions",
|
|
65
|
-
"P!.\"o!#P!4#8?$!4%8?&P&&FJ4'8?()4)8
|
|
67
|
+
"P!.\"o!#P!4#8?$!4%8?&P&&FJ4'8?()4)8>*?+)4,8>*?-\"w.4/8?0n1428?3n4458?6n7488?9MKw:y"
|
|
66
68
|
];
|
|
67
69
|
const __ΩEnvPluginUserConfig = [
|
|
68
70
|
() => __powerlines_plugin_babel_types.__ΩBabelPluginUserConfig,
|
|
@@ -90,11 +92,15 @@ const __ΩEnvPluginResolvedConfig = [
|
|
|
90
92
|
"inject",
|
|
91
93
|
"inject",
|
|
92
94
|
"Should the plugin inject the env variables in the source code with their values?",
|
|
95
|
+
() => __ΩEnvPluginOptions,
|
|
96
|
+
"validate",
|
|
97
|
+
"validate",
|
|
98
|
+
"Should the plugin validate the loaded environment variables against the provided type definitions?",
|
|
93
99
|
"prefix",
|
|
94
100
|
"The prefix used for environment variables",
|
|
95
101
|
"env",
|
|
96
102
|
"EnvPluginResolvedConfig",
|
|
97
|
-
"Pn!n\"PP!.%o$#o#\"n(.)o'#o&\"P!4*?+!4,?-n../f40?
|
|
103
|
+
"Pn!n\"PP!.%o$#o#\"n(.)o'#o&\"P!4*?+!4,?-n../f40?1n2.3f44?5&F46?7MK48MKw9y"
|
|
98
104
|
];
|
|
99
105
|
const __ΩEnvPluginContext = [
|
|
100
106
|
() => __ΩEnvPluginResolvedConfig,
|
package/dist/types/plugin.d.cts
CHANGED
|
@@ -31,6 +31,12 @@ type EnvPluginOptions = Omit<DotenvConfiguration, "types"> & {
|
|
|
31
31
|
* @defaultValue false
|
|
32
32
|
*/
|
|
33
33
|
inject?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Should the plugin validate the loaded environment variables against the provided type definitions?
|
|
36
|
+
*
|
|
37
|
+
* @defaultValue false
|
|
38
|
+
*/
|
|
39
|
+
validate?: boolean;
|
|
34
40
|
/**
|
|
35
41
|
* The default configuration to use when loading environment variables.
|
|
36
42
|
*
|
|
@@ -86,6 +92,13 @@ type EnvPluginResolvedConfig = BabelPluginResolvedConfig & AlloyPluginResolvedCo
|
|
|
86
92
|
* This value is the result of reflecting the {@link EnvPluginOptions.inject} option.
|
|
87
93
|
*/
|
|
88
94
|
inject: EnvPluginOptions["inject"];
|
|
95
|
+
/**
|
|
96
|
+
* Should the plugin validate the loaded environment variables against the provided type definitions?
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* This value is the result of reflecting the {@link EnvPluginOptions.validate} option.
|
|
100
|
+
*/
|
|
101
|
+
validate: EnvPluginOptions["validate"];
|
|
89
102
|
/**
|
|
90
103
|
* The prefix used for environment variables
|
|
91
104
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../../src/types/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAyCY,OAAA;KAEA,gBAAA,GAAmB,KAAK;EAFxB;AAEZ;;EAA+B,KAAA,CAAA,EAIrB,uBAJqB;EAIrB;;;
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../../src/types/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAyCY,OAAA;KAEA,gBAAA,GAAmB,KAAK;EAFxB;AAEZ;;EAA+B,KAAA,CAAA,EAIrB,uBAJqB;EAIrB;;;EA2CA,OAAA,CAAA,EAtCE,uBAsCF;EAQC;;;AAWX;;;EAES,MAAA,CAAA,EAAA,MAAA,GAAA,MAAA,EAAA;EAAgB;AAGzB;;;;EAEkB,MAAA,CAAA,EAAA,OAAA;EAAT;;;;;EAgBQ,QAAA,CAAA,EAAA,OAAA;EAQD;;;AAoBhB;;;EAIuB,aAAA,CAAA,EAlFL,QAkFK;EACA;;;;;;EAmCR,KAAA,CAAA,EA9GL,kBA8GK;EASH;;;;;;WA/GD;;;;;;;UAQD;;KAGE,mBAAA,GAAsB,wBAChC;OACO;;KAGG,uBAAA,GAA0B,4BACpC;OACO,SAAS,KAAK,2CACjB,SAAS,KAAK;;;;;;;WAOL;;;;;;;aAQE;;;;;;;YAQD;;;;;;;cAQE;;;;;;;;;;UAYD,yCACS,0BAA0B,iCAGhD,mBAAmB,kBACnB,mBAAmB;;;;;;;;;;;;WAYZ;;;;eAKI;;;;;;;;;;;;WAaJ,WAAW;;;;eAKP,WAAW;;;;;;;;YASd;;;;;;;cAQE"}
|
package/dist/types/plugin.d.mts
CHANGED
|
@@ -31,6 +31,12 @@ type EnvPluginOptions = Omit<DotenvConfiguration, "types"> & {
|
|
|
31
31
|
* @defaultValue false
|
|
32
32
|
*/
|
|
33
33
|
inject?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Should the plugin validate the loaded environment variables against the provided type definitions?
|
|
36
|
+
*
|
|
37
|
+
* @defaultValue false
|
|
38
|
+
*/
|
|
39
|
+
validate?: boolean;
|
|
34
40
|
/**
|
|
35
41
|
* The default configuration to use when loading environment variables.
|
|
36
42
|
*
|
|
@@ -86,6 +92,13 @@ type EnvPluginResolvedConfig = BabelPluginResolvedConfig & AlloyPluginResolvedCo
|
|
|
86
92
|
* This value is the result of reflecting the {@link EnvPluginOptions.inject} option.
|
|
87
93
|
*/
|
|
88
94
|
inject: EnvPluginOptions["inject"];
|
|
95
|
+
/**
|
|
96
|
+
* Should the plugin validate the loaded environment variables against the provided type definitions?
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* This value is the result of reflecting the {@link EnvPluginOptions.validate} option.
|
|
100
|
+
*/
|
|
101
|
+
validate: EnvPluginOptions["validate"];
|
|
89
102
|
/**
|
|
90
103
|
* The prefix used for environment variables
|
|
91
104
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../../src/types/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAyCY,OAAA;KAEA,gBAAA,GAAmB,KAAK;EAFxB;AAEZ;;EAA+B,KAAA,CAAA,EAIrB,uBAJqB;EAIrB;;;
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../../src/types/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAyCY,OAAA;KAEA,gBAAA,GAAmB,KAAK;EAFxB;AAEZ;;EAA+B,KAAA,CAAA,EAIrB,uBAJqB;EAIrB;;;EA2CA,OAAA,CAAA,EAtCE,uBAsCF;EAQC;;;AAWX;;;EAES,MAAA,CAAA,EAAA,MAAA,GAAA,MAAA,EAAA;EAAgB;AAGzB;;;;EAEkB,MAAA,CAAA,EAAA,OAAA;EAAT;;;;;EAgBQ,QAAA,CAAA,EAAA,OAAA;EAQD;;;AAoBhB;;;EAIuB,aAAA,CAAA,EAlFL,QAkFK;EACA;;;;;;EAmCR,KAAA,CAAA,EA9GL,kBA8GK;EASH;;;;;;WA/GD;;;;;;;UAQD;;KAGE,mBAAA,GAAsB,wBAChC;OACO;;KAGG,uBAAA,GAA0B,4BACpC;OACO,SAAS,KAAK,2CACjB,SAAS,KAAK;;;;;;;WAOL;;;;;;;aAQE;;;;;;;YAQD;;;;;;;cAQE;;;;;;;;;;UAYD,yCACS,0BAA0B,iCAGhD,mBAAmB,kBACnB,mBAAmB;;;;;;;;;;;;WAYZ;;;;eAKI;;;;;;;;;;;;WAaJ,WAAW;;;;eAKP,WAAW;;;;;;;;YASd;;;;;;;cAQE"}
|
package/dist/types/plugin.mjs
CHANGED
|
@@ -48,6 +48,8 @@ const __ΩEnvPluginOptions = [
|
|
|
48
48
|
"inject",
|
|
49
49
|
true,
|
|
50
50
|
"Should the plugin inject the env variables in the source code with their values?",
|
|
51
|
+
"validate",
|
|
52
|
+
"Should the plugin validate the loaded environment variables against the provided type definitions?",
|
|
51
53
|
"Children",
|
|
52
54
|
"defaultConfig",
|
|
53
55
|
"The default configuration to use when loading environment variables.",
|
|
@@ -61,7 +63,7 @@ const __ΩEnvPluginOptions = [
|
|
|
61
63
|
"alloy",
|
|
62
64
|
"Alloy configuration options to use when injecting environment variables into the source code.",
|
|
63
65
|
"EnvPluginOptions",
|
|
64
|
-
"P!.\"o!#P!4#8?$!4%8?&P&&FJ4'8?()4)8
|
|
66
|
+
"P!.\"o!#P!4#8?$!4%8?&P&&FJ4'8?()4)8>*?+)4,8>*?-\"w.4/8?0n1428?3n4458?6n7488?9MKw:y"
|
|
65
67
|
];
|
|
66
68
|
const __ΩEnvPluginUserConfig = [
|
|
67
69
|
() => __ΩBabelPluginUserConfig,
|
|
@@ -89,11 +91,15 @@ const __ΩEnvPluginResolvedConfig = [
|
|
|
89
91
|
"inject",
|
|
90
92
|
"inject",
|
|
91
93
|
"Should the plugin inject the env variables in the source code with their values?",
|
|
94
|
+
() => __ΩEnvPluginOptions,
|
|
95
|
+
"validate",
|
|
96
|
+
"validate",
|
|
97
|
+
"Should the plugin validate the loaded environment variables against the provided type definitions?",
|
|
92
98
|
"prefix",
|
|
93
99
|
"The prefix used for environment variables",
|
|
94
100
|
"env",
|
|
95
101
|
"EnvPluginResolvedConfig",
|
|
96
|
-
"Pn!n\"PP!.%o$#o#\"n(.)o'#o&\"P!4*?+!4,?-n../f40?
|
|
102
|
+
"Pn!n\"PP!.%o$#o#\"n(.)o'#o&\"P!4*?+!4,?-n../f40?1n2.3f44?5&F46?7MK48MKw9y"
|
|
97
103
|
];
|
|
98
104
|
const __ΩEnvPluginContext = [
|
|
99
105
|
() => __ΩEnvPluginResolvedConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../../src/types/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 { Children } from \"@alloy-js/core\";\nimport { Reflection } from \"@powerlines/deepkit/types\";\nimport {\n AlloyPluginContext,\n AlloyPluginOptions,\n AlloyPluginResolvedConfig,\n AlloyPluginUserConfig\n} from \"@powerlines/plugin-alloy/types\";\nimport { AutoMDPluginOptions } from \"@powerlines/plugin-automd/types/plugin\";\nimport {\n BabelPluginContext,\n BabelPluginOptions,\n BabelPluginResolvedConfig,\n BabelPluginUserConfig\n} from \"@powerlines/plugin-babel/types\";\nimport type { DotenvParseOutput } from \"@stryke/env/types\";\nimport {\n DotenvConfiguration,\n TypeDefinition,\n TypeDefinitionParameter\n} from \"@stryke/types/configuration\";\nimport { EnvInterface, SecretsInterface } from \"./runtime\";\n\nexport type EnvType = \"env\" | \"secrets\";\n\nexport type EnvPluginOptions = Omit<DotenvConfiguration, \"types\"> & {\n /**\n * A path to the type definition for the expected env configuration parameters. This value can include both a path to the typescript file and the name of the type definition to use separated by a `\":\"` or `\"#\"` character. For example: `\"./src/types/env.ts#ConfigConfiguration\"`.\n */\n types?: TypeDefinitionParameter;\n\n /**\n * A path to the type definition for the expected env secret parameters. This value can include both a path to the typescript file and the name of the type definition to use separated by a `\":\"` or `\"#\"` character. For example: `\"./src/types/env.ts#ConfigSecrets\"`.\n */\n secrets?: TypeDefinitionParameter;\n\n /**\n * An additional prefix (or list of additional prefixes) to apply to the environment variables\n *\n * @remarks\n * By default, the plugin will use the `POWERLINES_` prefix. This option is useful for avoiding conflicts with other environment variables.\n */\n prefix?: string | string[];\n\n /**\n * Should the plugin inject the env variables in the source code with their values?\n *\n * @defaultValue false\n */\n inject?: boolean;\n\n /**\n * The default configuration to use when loading environment variables.\n *\n * @remarks\n * This configuration is used as the base configuration when loading environment variables, and will be overridden by any values found in the `.env` file or the process environment.\n */\n defaultConfig?: Children;\n\n /**\n * Babel configuration options to use when injecting environment variables into the source code.\n *\n * @remarks\n * This option allows you to customize the Babel transformation process used to inject environment variables into the source code. If not provided, the plugin will use default Babel settings.\n */\n babel?: BabelPluginOptions;\n\n /**\n * AutoMD configuration options to allow injecting environment variables documentation into a markdown file such as a README.md.\n *\n * @remarks\n * The README.md file should contain the `<!-- automd:env --><!-- /automd -->` comment block where the documentation will be injected.\n */\n automd?: AutoMDPluginOptions;\n\n /**\n * Alloy configuration options to use when injecting environment variables into the source code.\n *\n * @remarks\n * This option allows you to customize the Alloy transformation process used to inject environment variables into the source code. If not provided, the plugin will use default Alloy settings.\n */\n alloy?: AlloyPluginOptions;\n};\n\nexport type EnvPluginUserConfig = BabelPluginUserConfig &\n AlloyPluginUserConfig & {\n env: EnvPluginOptions;\n };\n\nexport type EnvPluginResolvedConfig = BabelPluginResolvedConfig &\n AlloyPluginResolvedConfig & {\n env: Required<Pick<DotenvConfiguration, \"additionalFiles\">> &\n Required<Pick<EnvPluginOptions, \"defaultConfig\">> & {\n /**\n * The type definition for the expected env variable parameters\n *\n * @remarks\n * This value is parsed from the {@link EnvPluginOptions.types} option.\n */\n types: TypeDefinition;\n\n /**\n * The type definition for the expected env secret parameters\n *\n * @remarks\n * This value is parsed from the {@link EnvPluginOptions.secrets} option.\n */\n secrets: TypeDefinition;\n\n /**\n * Should the plugin inject the env variables in the source code with their values?\n *\n * @remarks\n * This value is the result of reflecting the {@link EnvPluginOptions.inject} option.\n */\n inject: EnvPluginOptions[\"inject\"];\n\n /**\n * The prefix used for environment variables\n *\n * @remarks\n * This value is used to filter environment variables that are loaded from the .env file and the process environment.\n */\n prefix: string[];\n };\n };\n\nexport interface EnvPluginContext<\n TResolvedConfig extends EnvPluginResolvedConfig = EnvPluginResolvedConfig\n>\n extends\n BabelPluginContext<TResolvedConfig>,\n AlloyPluginContext<TResolvedConfig> {\n env: {\n /**\n * The type definitions reflection for the env variables and secrets\n *\n * @remarks\n * These reflections contains the structure of the expected environment variables and secrets as defined by the type definitions provided in the plugin configuration.\n */\n types: {\n /**\n * The type definitions for the expected env variables\n */\n env: Reflection;\n\n /**\n * The type definitions for the expected env secrets\n */\n secrets: Reflection;\n };\n\n /**\n * The current **used** environment variables and secrets reflection\n *\n * @remarks\n * This reflection contains the structure of the current environment variables and secrets as defined during the plugin initialization by extracting the values from the source code.\n */\n used: {\n /**\n * The current env variables reflection\n */\n env: Reflection<EnvInterface>;\n\n /**\n * The current env secrets reflection\n */\n secrets: Reflection<SecretsInterface>;\n };\n\n /**\n * The parsed .env configuration object\n *\n * @remarks\n * This value is the result of loading the .env configuration file found in the project root directory and merging it with the values provided at {@link EnvPluginOptions.values}\n */\n parsed: DotenvParseOutput;\n\n /**\n * The injected environment variables and secrets reflection\n *\n * @remarks\n * This reflection contains the structure of the injected environment variables and secrets that were injected into the source code during the build process.\n */\n injected: Reflection;\n };\n}\n"],"mappings":";;;;;;;AAAA,MAAM,UAAU;CAAC;CAAK;OAAW;OAAe;CAAY;CAAQ;CAAC;;;;;;AAErE,MAAM,UAAU;CAAC;CAAK;CAAK;CAAQ;CAAY;;;;;;;AA0B/C,MAAM,aAAa;CAAC;CAAA;CAAA;CAAA;CAAA;AAEpB,MAAM,sBAAqB;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;OAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAE3B,MAAM,yBAAyB;OAAO;OAAC;OAAA;CAAA;CAAA;CAAA;CAAA;AAEvC,MAAM,6BAAC;OAAA;OAAA;OAAA;OAAA;CAAA;OAAA;OAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAEP,MAAM,sBAAU;OAAA;CAAA;OAAA;OAAA;OAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;OAAA;OAAA;CAAA;OAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../../src/types/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 { Children } from \"@alloy-js/core\";\nimport { Reflection } from \"@powerlines/deepkit/types\";\nimport {\n AlloyPluginContext,\n AlloyPluginOptions,\n AlloyPluginResolvedConfig,\n AlloyPluginUserConfig\n} from \"@powerlines/plugin-alloy/types\";\nimport { AutoMDPluginOptions } from \"@powerlines/plugin-automd/types/plugin\";\nimport {\n BabelPluginContext,\n BabelPluginOptions,\n BabelPluginResolvedConfig,\n BabelPluginUserConfig\n} from \"@powerlines/plugin-babel/types\";\nimport type { DotenvParseOutput } from \"@stryke/env/types\";\nimport {\n DotenvConfiguration,\n TypeDefinition,\n TypeDefinitionParameter\n} from \"@stryke/types/configuration\";\nimport { EnvInterface, SecretsInterface } from \"./runtime\";\n\nexport type EnvType = \"env\" | \"secrets\";\n\nexport type EnvPluginOptions = Omit<DotenvConfiguration, \"types\"> & {\n /**\n * A path to the type definition for the expected env configuration parameters. This value can include both a path to the typescript file and the name of the type definition to use separated by a `\":\"` or `\"#\"` character. For example: `\"./src/types/env.ts#ConfigConfiguration\"`.\n */\n types?: TypeDefinitionParameter;\n\n /**\n * A path to the type definition for the expected env secret parameters. This value can include both a path to the typescript file and the name of the type definition to use separated by a `\":\"` or `\"#\"` character. For example: `\"./src/types/env.ts#ConfigSecrets\"`.\n */\n secrets?: TypeDefinitionParameter;\n\n /**\n * An additional prefix (or list of additional prefixes) to apply to the environment variables\n *\n * @remarks\n * By default, the plugin will use the `POWERLINES_` prefix. This option is useful for avoiding conflicts with other environment variables.\n */\n prefix?: string | string[];\n\n /**\n * Should the plugin inject the env variables in the source code with their values?\n *\n * @defaultValue false\n */\n inject?: boolean;\n\n /**\n * Should the plugin validate the loaded environment variables against the provided type definitions?\n *\n * @defaultValue false\n */\n validate?: boolean;\n\n /**\n * The default configuration to use when loading environment variables.\n *\n * @remarks\n * This configuration is used as the base configuration when loading environment variables, and will be overridden by any values found in the `.env` file or the process environment.\n */\n defaultConfig?: Children;\n\n /**\n * Babel configuration options to use when injecting environment variables into the source code.\n *\n * @remarks\n * This option allows you to customize the Babel transformation process used to inject environment variables into the source code. If not provided, the plugin will use default Babel settings.\n */\n babel?: BabelPluginOptions;\n\n /**\n * AutoMD configuration options to allow injecting environment variables documentation into a markdown file such as a README.md.\n *\n * @remarks\n * The README.md file should contain the `<!-- automd:env --><!-- /automd -->` comment block where the documentation will be injected.\n */\n automd?: AutoMDPluginOptions;\n\n /**\n * Alloy configuration options to use when injecting environment variables into the source code.\n *\n * @remarks\n * This option allows you to customize the Alloy transformation process used to inject environment variables into the source code. If not provided, the plugin will use default Alloy settings.\n */\n alloy?: AlloyPluginOptions;\n};\n\nexport type EnvPluginUserConfig = BabelPluginUserConfig &\n AlloyPluginUserConfig & {\n env: EnvPluginOptions;\n };\n\nexport type EnvPluginResolvedConfig = BabelPluginResolvedConfig &\n AlloyPluginResolvedConfig & {\n env: Required<Pick<DotenvConfiguration, \"additionalFiles\">> &\n Required<Pick<EnvPluginOptions, \"defaultConfig\">> & {\n /**\n * The type definition for the expected env variable parameters\n *\n * @remarks\n * This value is parsed from the {@link EnvPluginOptions.types} option.\n */\n types: TypeDefinition;\n\n /**\n * The type definition for the expected env secret parameters\n *\n * @remarks\n * This value is parsed from the {@link EnvPluginOptions.secrets} option.\n */\n secrets: TypeDefinition;\n\n /**\n * Should the plugin inject the env variables in the source code with their values?\n *\n * @remarks\n * This value is the result of reflecting the {@link EnvPluginOptions.inject} option.\n */\n inject: EnvPluginOptions[\"inject\"];\n\n /**\n * Should the plugin validate the loaded environment variables against the provided type definitions?\n *\n * @remarks\n * This value is the result of reflecting the {@link EnvPluginOptions.validate} option.\n */\n validate: EnvPluginOptions[\"validate\"];\n\n /**\n * The prefix used for environment variables\n *\n * @remarks\n * This value is used to filter environment variables that are loaded from the .env file and the process environment.\n */\n prefix: string[];\n };\n };\n\nexport interface EnvPluginContext<\n TResolvedConfig extends EnvPluginResolvedConfig = EnvPluginResolvedConfig\n>\n extends\n BabelPluginContext<TResolvedConfig>,\n AlloyPluginContext<TResolvedConfig> {\n env: {\n /**\n * The type definitions reflection for the env variables and secrets\n *\n * @remarks\n * These reflections contains the structure of the expected environment variables and secrets as defined by the type definitions provided in the plugin configuration.\n */\n types: {\n /**\n * The type definitions for the expected env variables\n */\n env: Reflection;\n\n /**\n * The type definitions for the expected env secrets\n */\n secrets: Reflection;\n };\n\n /**\n * The current **used** environment variables and secrets reflection\n *\n * @remarks\n * This reflection contains the structure of the current environment variables and secrets as defined during the plugin initialization by extracting the values from the source code.\n */\n used: {\n /**\n * The current env variables reflection\n */\n env: Reflection<EnvInterface>;\n\n /**\n * The current env secrets reflection\n */\n secrets: Reflection<SecretsInterface>;\n };\n\n /**\n * The parsed .env configuration object\n *\n * @remarks\n * This value is the result of loading the .env configuration file found in the project root directory and merging it with the values provided at {@link EnvPluginOptions.values}\n */\n parsed: DotenvParseOutput;\n\n /**\n * The injected environment variables and secrets reflection\n *\n * @remarks\n * This reflection contains the structure of the injected environment variables and secrets that were injected into the source code during the build process.\n */\n injected: Reflection;\n };\n}\n"],"mappings":";;;;;;;AAAA,MAAM,UAAU;CAAC;CAAK;OAAW;OAAe;CAAY;CAAQ;CAAC;;;;;;AAErE,MAAM,UAAU;CAAC;CAAK;CAAK;CAAQ;CAAY;;;;;;;AA0B/C,MAAM,aAAa;CAAC;CAAA;CAAA;CAAA;CAAA;AAEpB,MAAM,sBAAqB;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;OAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAE3B,MAAM,yBAAyB;OAAO;OAAC;OAAA;CAAA;CAAA;CAAA;CAAA;AAEvC,MAAM,6BAAC;OAAA;OAAA;OAAA;OAAA;CAAA;OAAA;OAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAEP,MAAM,sBAAU;OAAA;CAAA;OAAA;OAAA;OAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;OAAA;OAAA;CAAA;OAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"type": "module",
|
|
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
|
"repository": {
|
|
@@ -309,7 +309,7 @@
|
|
|
309
309
|
"@powerlines/plugin-automd": "^0.1.286",
|
|
310
310
|
"@powerlines/plugin-babel": "^0.12.295",
|
|
311
311
|
"@powerlines/plugin-plugin": "^0.12.237",
|
|
312
|
-
"@storm-software/config-tools": "^1.189.
|
|
312
|
+
"@storm-software/config-tools": "^1.189.6",
|
|
313
313
|
"@stryke/capnp": "^0.12.68",
|
|
314
314
|
"@stryke/env": "^0.20.60",
|
|
315
315
|
"@stryke/fs": "^0.33.43",
|
|
@@ -328,5 +328,5 @@
|
|
|
328
328
|
},
|
|
329
329
|
"publishConfig": { "access": "public" },
|
|
330
330
|
"types": "./dist/index.d.cts",
|
|
331
|
-
"gitHead": "
|
|
331
|
+
"gitHead": "554a70aaf64cca56e3d8c077d50fa6944b3b96d3"
|
|
332
332
|
}
|