@powerlines/plugin-env 0.16.1 → 0.16.2

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.
@@ -13,7 +13,7 @@ function __assignType(fn, args) {
13
13
  return fn;
14
14
  }
15
15
  const envBabelPlugin = (__powerlines_plugin_babel_helpers_create_plugin.createBabelPlugin.Ω = [[() => require_types_plugin.__ΩEnvPluginContext, "n!"]], (0, __powerlines_plugin_babel_helpers_create_plugin.createBabelPlugin)("env", __assignType(({ log, context }) => {
16
- function extractEnv(node, pass, isInjectable = false) {
16
+ function extractEnv(node, pass, isInjectable = false, isUsingBuiltin = false) {
17
17
  const envTypesAliasProperties = context.env.types.env?.getProperties().filter(__assignType((prop) => prop.getAlias().length > 0, [
18
18
  "prop",
19
19
  "",
@@ -87,6 +87,7 @@ const envBabelPlugin = (__powerlines_plugin_babel_helpers_create_plugin.createBa
87
87
  "",
88
88
  "P\"2!\"/\""
89
89
  ])).join("\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`);
90
+ else if (pass.filename && isUsingBuiltin) context.warn(`The "${name}" environment variable is used in the source code file ${pass.filename}, but is not defined in the \`env\` type definition. If this is intentional, you can ignore this warning. Otherwise, please 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.`);
90
91
  }
91
92
  }
92
93
  extractEnv.__type = [
@@ -94,14 +95,15 @@ const envBabelPlugin = (__powerlines_plugin_babel_helpers_create_plugin.createBa
94
95
  () => powerlines_types_babel.__ΩBabelPluginPass,
95
96
  "pass",
96
97
  "isInjectable",
98
+ "isUsingBuiltin",
97
99
  "extractEnv",
98
- "P!2!n\"2#\"2$\"/%"
100
+ "P!2!n\"2#\"2$\"2%\"/&"
99
101
  ];
100
102
  return { visitor: { MemberExpression: __assignType(function MemberExpression(path, pass) {
101
103
  if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "process" }) && path.get("property")?.isIdentifier()) {
102
104
  const identifier = path.get("property")?.node;
103
105
  if (!identifier.name) return;
104
- extractEnv(identifier, pass, false);
106
+ extractEnv(identifier, pass, false, false);
105
107
  path.replaceWithSourceString(`env.${identifier.name}`);
106
108
  (0, __powerlines_plugin_babel_helpers_module_helpers.addImport)(path, {
107
109
  module: `${context.config.framework || "powerlines"}:env`,
@@ -111,7 +113,7 @@ const envBabelPlugin = (__powerlines_plugin_babel_helpers_create_plugin.createBa
111
113
  } else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isMetaProperty() && path.get("property")?.isIdentifier()) {
112
114
  const identifier = path.get("property")?.node;
113
115
  if (!identifier.name) return;
114
- extractEnv(identifier, pass, false);
116
+ extractEnv(identifier, pass, false, false);
115
117
  path.replaceWithSourceString(`env.${identifier.name}`);
116
118
  (0, __powerlines_plugin_babel_helpers_module_helpers.addImport)(path, {
117
119
  module: `${context.config.framework || "powerlines"}:env`,
@@ -121,7 +123,7 @@ const envBabelPlugin = (__powerlines_plugin_babel_helpers_create_plugin.createBa
121
123
  } else if (path.get("object")?.isIdentifier({ name: "env" }) && path.get("property")?.isIdentifier()) {
122
124
  const identifier = path.get("property")?.node;
123
125
  if (!identifier.name) return;
124
- extractEnv(identifier, pass, false);
126
+ extractEnv(identifier, pass, false, true);
125
127
  }
126
128
  }, [
127
129
  () => __babel_core.NodePath,
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.cts","names":[],"sources":["../../src/babel/plugin.ts"],"sourcesContent":[],"mappings":";;;;;cAkCa,gBAAc,iBAAA,CAAA,kCAAA,iBAmM1B,uBAAA,GAnM0B"}
1
+ {"version":3,"file":"plugin.d.cts","names":[],"sources":["../../src/babel/plugin.ts"],"sourcesContent":[],"mappings":";;;;;cAkCa,gBAAc,iBAAA,CAAA,kCAAA,iBA4M1B,uBAAA,GA5M0B"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.mts","names":[],"sources":["../../src/babel/plugin.ts"],"sourcesContent":[],"mappings":";;;;;cAkCa,gBAAc,iBAAA,CAAA,kCAAA,iBAmM1B,uBAAA,GAnM0B"}
1
+ {"version":3,"file":"plugin.d.mts","names":[],"sources":["../../src/babel/plugin.ts"],"sourcesContent":[],"mappings":";;;;;cAkCa,gBAAc,iBAAA,CAAA,kCAAA,iBA4M1B,uBAAA,GA5M0B"}
@@ -12,7 +12,7 @@ function __assignType(fn, args) {
12
12
  return fn;
13
13
  }
14
14
  const envBabelPlugin = (createBabelPlugin.Ω = [[() => __ΩEnvPluginContext, "n!"]], createBabelPlugin("env", __assignType(({ log, context }) => {
15
- function extractEnv(node, pass, isInjectable = false) {
15
+ function extractEnv(node, pass, isInjectable = false, isUsingBuiltin = false) {
16
16
  const envTypesAliasProperties = context.env.types.env?.getProperties().filter(__assignType((prop) => prop.getAlias().length > 0, [
17
17
  "prop",
18
18
  "",
@@ -86,6 +86,7 @@ const envBabelPlugin = (createBabelPlugin.Ω = [[() => __ΩEnvPluginContext, "n!
86
86
  "",
87
87
  "P\"2!\"/\""
88
88
  ])).join("\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`);
89
+ else if (pass.filename && isUsingBuiltin) context.warn(`The "${name}" environment variable is used in the source code file ${pass.filename}, but is not defined in the \`env\` type definition. If this is intentional, you can ignore this warning. Otherwise, please 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.`);
89
90
  }
90
91
  }
91
92
  extractEnv.__type = [
@@ -93,14 +94,15 @@ const envBabelPlugin = (createBabelPlugin.Ω = [[() => __ΩEnvPluginContext, "n!
93
94
  () => __ΩBabelPluginPass,
94
95
  "pass",
95
96
  "isInjectable",
97
+ "isUsingBuiltin",
96
98
  "extractEnv",
97
- "P!2!n\"2#\"2$\"/%"
99
+ "P!2!n\"2#\"2$\"2%\"/&"
98
100
  ];
99
101
  return { visitor: { MemberExpression: __assignType(function MemberExpression(path, pass) {
100
102
  if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "process" }) && path.get("property")?.isIdentifier()) {
101
103
  const identifier = path.get("property")?.node;
102
104
  if (!identifier.name) return;
103
- extractEnv(identifier, pass, false);
105
+ extractEnv(identifier, pass, false, false);
104
106
  path.replaceWithSourceString(`env.${identifier.name}`);
105
107
  addImport(path, {
106
108
  module: `${context.config.framework || "powerlines"}:env`,
@@ -110,7 +112,7 @@ const envBabelPlugin = (createBabelPlugin.Ω = [[() => __ΩEnvPluginContext, "n!
110
112
  } else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isMetaProperty() && path.get("property")?.isIdentifier()) {
111
113
  const identifier = path.get("property")?.node;
112
114
  if (!identifier.name) return;
113
- extractEnv(identifier, pass, false);
115
+ extractEnv(identifier, pass, false, false);
114
116
  path.replaceWithSourceString(`env.${identifier.name}`);
115
117
  addImport(path, {
116
118
  module: `${context.config.framework || "powerlines"}:env`,
@@ -120,7 +122,7 @@ const envBabelPlugin = (createBabelPlugin.Ω = [[() => __ΩEnvPluginContext, "n!
120
122
  } else if (path.get("object")?.isIdentifier({ name: "env" }) && path.get("property")?.isIdentifier()) {
121
123
  const identifier = path.get("property")?.node;
122
124
  if (!identifier.name) return;
123
- extractEnv(identifier, pass, false);
125
+ extractEnv(identifier, pass, false, true);
124
126
  }
125
127
  }, [
126
128
  () => NodePath,
@@ -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 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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K,wBAAwB,OAAK,WAAA,OAAA;AACzC,aAAA,MAAA;;IAEW,MAAM;IACN,UAAO;IACV,CAAC;aAEC,KACF,IAAI,SAAS,EACZ,IAAI,WAAW,EACf,aAAI,EAAA,MAAA,OAAA,CAAA,IACN,KAAK,IAAI,SAAS,EAAE,IAAI,SAAS,EAAE,gBAAW,IAC9C,KAAK,IAAI,WAAW,EAAE,cAAK,EAAA;GAE3B,MAAM,aAAa,KAAK,IAAI,WAAO,EAAA;AACnC,OAAI,CAAC,WAAK,KACN;AAEJ,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 isUsingBuiltin = 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 } else if (pass.filename && isUsingBuiltin) {\n context.warn(\n `The \"${\n name\n }\" environment variable is used in the source code file ${\n pass.filename\n }, but is not defined in the \\`env\\` type definition. If this is intentional, you can ignore this warning. Otherwise, please 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 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, 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, 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, true);\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,iBAAA,OAAA;EACf,MAAM,0BAAU,QAAA,IAAA,MAAA,KACV,eAAa,CACd,OAAO,cAAM,SAAA,KAAA,UAAA,CAAA,SAAA,GAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;AAClB,MAAI,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a,KAAK,IAAI,WAAA,EAAA;AAC5B,OAAI,CAAC,WAAA,KACD;AAEX,cAAA,YAAA,MAAA,OAAA,MAAA;;AAEO,aAAU,MAAM;IACZ,QAAO,GAAA,QAAA,OAAA,aAAA,aAAA;IACP,MAAM;IACd,UAAA;IACK,CAAC;aAEG,KACJ,IAAI,SAAC,EACJ,IAAI,WAAW,EACf,aAAa,EAAE,MAAM,OAAI,CAAA,IAC7B,KAAA,IAAA,SAAA,EAAA,IAAA,SAAA,EAAA,gBAAA,IACE,KAAK,IAAI,WAAW,EAAE,cAAa,EAAA;GAEnC,MAAM,aAAa,KAAK,IAAI,WAAW,EAAE;AACzC,OAAI,CAAA,WAAA,KACA;AAEJ,cAAG,YAAA,MAAA,OAAA,MAAA;AACN,QAAA,wBAAA,OAAA,WAAA,OAAA;AACL,aAAA,MAAA;IACK,QAAA,GAAA,QAAA,OAAA,aAAA,aAAA;IACA,MAAA;IACO,UAAU;IACb,CAAC;aAEL,KAAA,IAAA,SAAA,EAAA,aAAA,EAAA,MAAA,OAAA,CAAA,IACG,KAAK,IAAI,WAAW,EAAE,cAAc,EAAE;GAEtC,MAAM,aAAa,KAAK,IAAI,WAAI,EAAA;AAChC,OAAE,CAAA,WAAA,KACH;AAEC,cAAW,YAAY,MAAM,OAAO,KAAK;;IAE9C;QAAO;EAAU;QAAc;EAAoB;EAAQ;EAAoB;EAAiB,CAAA,EACvG,EACH;GACF;CAAC;CAAE;CAAA;CAAA,CAAA,CAAA"}
package/dist/index.cjs CHANGED
@@ -85,11 +85,7 @@ const plugin = (options = {}) => {
85
85
  },
86
86
  async configResolved() {
87
87
  this.debug(`Environment plugin configuration has been resolved for the Powerlines project.`);
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 ?? {}, {
88
+ this.env = require_defu.defu({ parsed: await require_helpers_load.loadEnv(this, this.config.env) }, this.env ?? {}, {
93
89
  types: { env: {} },
94
90
  used: {
95
91
  env: {},
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;cAmEa,0BAA2B,mBAAmB,4BAChD,qBA6UJ,OAAO"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;cAmEa,0BAA2B,mBAAmB,4BAChD,qBA2UJ,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;cAmEa,0BAA2B,mBAAmB,4BAChD,qBA6UJ,OAAO"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;cAmEa,0BAA2B,mBAAmB,4BAChD,qBA2UJ,OAAO"}
package/dist/index.mjs CHANGED
@@ -80,11 +80,7 @@ const plugin = (options = {}) => {
80
80
  },
81
81
  async configResolved() {
82
82
  this.debug(`Environment plugin configuration has been resolved for the Powerlines project.`);
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 ?? {}, {
83
+ this.env = defu({ parsed: await loadEnv(this, this.config.env) }, this.env ?? {}, {
88
84
  types: { env: {} },
89
85
  used: {
90
86
  env: {},
@@ -1 +1 @@
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":";;;;;;;;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"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 },\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;KACD;AAED,QAAIoB,OAAOjB,IAAImB,MACbF,QAAOjB,IAAImB,QAAQ7B,oBACjB2B,OAAOjB,IAAImB,MACM;SACd;AACL,UAAKM,KACH,4FACD;KAED,MAAMC,2BACJ,MAAMvB,4BAA4B,KAAK;KAEzC,MAAMwB,OAAO,MAAM,KAAKC,GAAGC,QAAQH,yBAAyBC,KAAK;AACjE,SAAIA,KACFV,QAAOjB,IAAImB,QAAQ7B,oBACjB,GAAGqC,KAAI,GAAID,yBAAyBV,OACnB;;AAIvB,QAAIC,OAAOjB,IAAI8B,QACbb,QAAOjB,IAAI8B,UAAUxC,oBACnB2B,OAAOjB,IAAI8B,QACM;SACd;KACL,MAAMC,+BACJ,MAAMzB,gCAAgC,KAAK;KAE7C,MAAMqB,OAAO,MAAM,KAAKC,GAAGC,QAAQE,6BAA6BJ,KAAK;AACrE,SAAIA,KACFV,QAAOjB,IAAI8B,UAAUxC,oBACnB,GAAGqC,KAAI,GAAII,6BAA6Bf,OACvB;;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KxE,QAAQjB,KAAKsB,QAC9B;MAEL;GACD;EACDlC,OAAO2B,QAAQ3B,OAAO;EACvB;;AAGH,kBAAe0B"}
@@ -88,19 +88,15 @@ const __ΩEnvPluginResolvedConfig = [
88
88
  "The type definition for the expected env variable parameters",
89
89
  "secrets",
90
90
  "The type definition for the expected env secret parameters",
91
- () => __ΩEnvPluginOptions,
92
- "inject",
93
91
  "inject",
94
92
  "Should the plugin inject the env variables in the source code with their values?",
95
- () => __ΩEnvPluginOptions,
96
- "validate",
97
93
  "validate",
98
94
  "Should the plugin validate the loaded environment variables against the provided type definitions?",
99
95
  "prefix",
100
96
  "The prefix used for environment variables",
101
97
  "env",
102
98
  "EnvPluginResolvedConfig",
103
- "Pn!n\"PP!.%o$#o#\"n(.)o'#o&\"P!4*?+!4,?-n../f40?1n2.3f44?5&F46?7MK48MKw9y"
99
+ "Pn!n\"PP!.%o$#o#\"n(.)o'#o&\"P!4*?+!4,?-)4.?/)40?1&F42?3MK44MKw5y"
104
100
  ];
105
101
  const __ΩEnvPluginContext = [
106
102
  () => __ΩEnvPluginResolvedConfig,
@@ -91,14 +91,14 @@ type EnvPluginResolvedConfig = BabelPluginResolvedConfig & AlloyPluginResolvedCo
91
91
  * @remarks
92
92
  * This value is the result of reflecting the {@link EnvPluginOptions.inject} option.
93
93
  */
94
- inject: EnvPluginOptions["inject"];
94
+ inject: boolean;
95
95
  /**
96
96
  * Should the plugin validate the loaded environment variables against the provided type definitions?
97
97
  *
98
98
  * @remarks
99
99
  * This value is the result of reflecting the {@link EnvPluginOptions.validate} option.
100
100
  */
101
- validate: EnvPluginOptions["validate"];
101
+ validate: boolean;
102
102
  /**
103
103
  * The prefix used for environment variables
104
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,E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C;OACO,SAAS,KAAK,2CACjB,SAAS,KAAK;;;;;;;WAOL;;;;;;;aAQE;;;;;;;;;;;;;;;;;;;;;;;;UA4BA,yCACS,0BAA0B,iCAGhD,mBAAmB,kBACnB,mBAAmB;;;;;;;;;;;;WAYZ;;;;eAKI;;;;;;;;;;;;WAaJ,WAAW;;;;eAKP,WAAW;;;;;;;;YASd;;;;;;;cAQE"}
@@ -91,14 +91,14 @@ type EnvPluginResolvedConfig = BabelPluginResolvedConfig & AlloyPluginResolvedCo
91
91
  * @remarks
92
92
  * This value is the result of reflecting the {@link EnvPluginOptions.inject} option.
93
93
  */
94
- inject: EnvPluginOptions["inject"];
94
+ inject: boolean;
95
95
  /**
96
96
  * Should the plugin validate the loaded environment variables against the provided type definitions?
97
97
  *
98
98
  * @remarks
99
99
  * This value is the result of reflecting the {@link EnvPluginOptions.validate} option.
100
100
  */
101
- validate: EnvPluginOptions["validate"];
101
+ validate: boolean;
102
102
  /**
103
103
  * The prefix used for environment variables
104
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;;;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"}
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;EAAc;AA4B/B;;;;;EAiBW,aAAA,CAAA,EA/FO,QA+FP;EAKI;;;;;;EAmCD,KAAA,CAAA,EA/HJ,kBA+HI;EArDV;;;;;;WAlEO;;;;;;;UAQD;;KAGE,mBAAA,GAAsB,wBAChC;OACO;;KAGG,uBAAA,GAA0B,4BACpC;OACO,SAAS,KAAK,2CACjB,SAAS,KAAK;;;;;;;WAOL;;;;;;;aAQE;;;;;;;;;;;;;;;;;;;;;;;;UA4BA,yCACS,0BAA0B,iCAGhD,mBAAmB,kBACnB,mBAAmB;;;;;;;;;;;;WAYZ;;;;eAKI;;;;;;;;;;;;WAaJ,WAAW;;;;eAKP,WAAW;;;;;;;;YASd;;;;;;;cAQE"}
@@ -87,19 +87,15 @@ const __ΩEnvPluginResolvedConfig = [
87
87
  "The type definition for the expected env variable parameters",
88
88
  "secrets",
89
89
  "The type definition for the expected env secret parameters",
90
- () => __ΩEnvPluginOptions,
91
- "inject",
92
90
  "inject",
93
91
  "Should the plugin inject the env variables in the source code with their values?",
94
- () => __ΩEnvPluginOptions,
95
- "validate",
96
92
  "validate",
97
93
  "Should the plugin validate the loaded environment variables against the provided type definitions?",
98
94
  "prefix",
99
95
  "The prefix used for environment variables",
100
96
  "env",
101
97
  "EnvPluginResolvedConfig",
102
- "Pn!n\"PP!.%o$#o#\"n(.)o'#o&\"P!4*?+!4,?-n../f40?1n2.3f44?5&F46?7MK48MKw9y"
98
+ "Pn!n\"PP!.%o$#o#\"n(.)o'#o&\"P!4*?+!4,?-)4.?/)40?1&F42?3MK44MKw5y"
103
99
  ];
104
100
  const __ΩEnvPluginContext = [
105
101
  () => __Ω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 * 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"}
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: boolean;\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: boolean;\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;CAAA;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.16.1",
3
+ "version": "0.16.2",
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": {
@@ -328,5 +328,5 @@
328
328
  },
329
329
  "publishConfig": { "access": "public" },
330
330
  "types": "./dist/index.d.cts",
331
- "gitHead": "554a70aaf64cca56e3d8c077d50fa6944b3b96d3"
331
+ "gitHead": "9f1424c86b1e1e3429776ec2afd1e4b15b390047"
332
332
  }