@powerlines/plugin-env 0.14.21 → 0.14.22
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/_virtual/rolldown_runtime.cjs +37 -1
- package/dist/_virtual/rolldown_runtime.mjs +29 -1
- package/dist/babel/index.cjs +1 -1
- package/dist/babel/index.mjs +3 -1
- package/dist/babel/plugin.cjs +120 -4
- package/dist/babel/plugin.d.cts +2 -3
- package/dist/babel/plugin.d.mts +3 -2
- package/dist/babel/plugin.mjs +118 -4
- package/dist/components/docs.cjs +71 -1
- package/dist/components/docs.mjs +70 -1
- package/dist/components/env.cjs +432 -11
- package/dist/components/env.mjs +430 -9
- package/dist/components/index.cjs +6 -1
- package/dist/components/index.mjs +4 -1
- package/dist/deepkit/schemas/reflection.cjs +3940 -1
- package/dist/deepkit/schemas/reflection.mjs +3938 -1
- package/dist/deepkit/schemas/reflection2.cjs +4112 -1
- package/dist/deepkit/schemas/reflection2.mjs +4110 -1
- package/dist/deepkit/src/capnp.cjs +913 -1
- package/dist/deepkit/src/capnp.mjs +911 -1
- package/dist/deepkit/src/esbuild-plugin.cjs +47 -4
- package/dist/deepkit/src/esbuild-plugin.mjs +46 -4
- package/dist/deepkit/src/reflect-type.cjs +22 -1
- package/dist/deepkit/src/reflect-type.mjs +20 -1
- package/dist/deepkit/src/resolve-reflections.cjs +16 -1
- package/dist/deepkit/src/resolve-reflections.mjs +15 -1
- package/dist/deepkit/src/transformer.cjs +52 -1
- package/dist/deepkit/src/transformer.mjs +49 -1
- package/dist/deepkit/src/transpile.cjs +29 -1
- package/dist/deepkit/src/transpile.mjs +27 -1
- package/dist/deepkit/src/utilities.cjs +66 -1
- package/dist/deepkit/src/utilities.mjs +65 -1
- package/dist/deepkit/src/vendor/type-compiler/index.cjs +38 -1
- package/dist/deepkit/src/vendor/type-compiler/index.mjs +19 -1
- package/dist/deepkit/src/vendor/type.cjs +20 -1
- package/dist/deepkit/src/vendor/type.mjs +11 -1
- package/dist/helpers/automd-generator.cjs +22 -1
- package/dist/helpers/automd-generator.mjs +21 -1
- package/dist/helpers/create-reflection-resource.cjs +55 -1
- package/dist/helpers/create-reflection-resource.mjs +54 -1
- package/dist/helpers/index.cjs +6 -1
- package/dist/helpers/index.mjs +8 -1
- package/dist/helpers/load.cjs +83 -1
- package/dist/helpers/load.d.cts +2 -2
- package/dist/helpers/load.d.mts +3 -2
- package/dist/helpers/load.mjs +80 -1
- package/dist/helpers/persistence.cjs +214 -1
- package/dist/helpers/persistence.d.cts +1 -1
- package/dist/helpers/persistence.d.mts +1 -1
- package/dist/helpers/persistence.mjs +202 -1
- package/dist/helpers/reflect.cjs +111 -1
- package/dist/helpers/reflect.mjs +103 -1
- package/dist/helpers/source-file-env.cjs +28 -1
- package/dist/helpers/source-file-env.mjs +26 -1
- package/dist/helpers/template-helpers.cjs +42 -1
- package/dist/helpers/template-helpers.mjs +41 -1
- package/dist/index.cjs +203 -5
- package/dist/index.d.cts +1 -3
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +170 -5
- package/dist/plugin-alloy/src/core/components/output.cjs +45 -1
- package/dist/plugin-alloy/src/core/components/output.mjs +44 -1
- package/dist/plugin-alloy/src/core/contexts/context.cjs +11 -1
- package/dist/plugin-alloy/src/core/contexts/context.mjs +10 -1
- package/dist/plugin-alloy/src/index.cjs +93 -1
- package/dist/plugin-alloy/src/index.mjs +91 -1
- package/dist/plugin-alloy/src/types/plugin.d.cts +2 -2
- package/dist/plugin-alloy/src/types/plugin.d.mts +2 -2
- package/dist/plugin-automd/src/index.cjs +101 -1
- package/dist/plugin-automd/src/index.mjs +98 -1
- package/dist/plugin-automd/src/types/plugin.d.mts +2 -2
- package/dist/plugin-babel/src/helpers/ast-utils.cjs +10 -1
- package/dist/plugin-babel/src/helpers/ast-utils.mjs +9 -1
- package/dist/plugin-babel/src/helpers/create-plugin.cjs +41 -1
- package/dist/plugin-babel/src/helpers/create-plugin.mjs +39 -1
- package/dist/plugin-babel/src/helpers/filters.cjs +23 -1
- package/dist/plugin-babel/src/helpers/filters.mjs +21 -1
- package/dist/plugin-babel/src/helpers/index.cjs +5 -1
- package/dist/plugin-babel/src/helpers/index.mjs +7 -1
- package/dist/plugin-babel/src/helpers/module-helpers.cjs +38 -1
- package/dist/plugin-babel/src/helpers/module-helpers.mjs +35 -1
- package/dist/plugin-babel/src/helpers/options.cjs +50 -1
- package/dist/plugin-babel/src/helpers/options.mjs +47 -1
- package/dist/plugin-babel/src/index.cjs +91 -1
- package/dist/plugin-babel/src/index.mjs +89 -1
- package/dist/plugin-babel/src/types/plugin.d.cts +2 -2
- package/dist/plugin-babel/src/types/plugin.d.mts +2 -2
- package/dist/powerlines/schemas/fs.d.mts +1 -0
- package/dist/powerlines/src/api.d.mts +7 -0
- package/dist/powerlines/src/index.d.mts +12 -0
- package/dist/powerlines/src/internal/helpers/hooks.d.mts +5 -0
- package/dist/powerlines/src/lib/build/esbuild.cjs +102 -14
- package/dist/powerlines/src/lib/build/esbuild.mjs +100 -14
- package/dist/powerlines/src/lib/entry.cjs +12 -1
- package/dist/powerlines/src/lib/entry.mjs +14 -1
- package/dist/powerlines/src/lib/logger.cjs +41 -1
- package/dist/powerlines/src/lib/logger.mjs +39 -1
- package/dist/powerlines/src/lib/utilities/bundle.cjs +35 -1
- package/dist/powerlines/src/lib/utilities/bundle.mjs +34 -1
- package/dist/powerlines/src/lib/utilities/resolve.cjs +30 -1
- package/dist/powerlines/src/lib/utilities/resolve.mjs +29 -1
- package/dist/powerlines/src/plugin-utils/paths.cjs +1 -1
- package/dist/powerlines/src/plugin-utils/paths.mjs +3 -1
- package/dist/powerlines/src/types/api.d.mts +5 -0
- package/dist/powerlines/src/types/babel.d.cts +3 -2
- package/dist/powerlines/src/types/babel.d.mts +3 -2
- package/dist/powerlines/src/types/commands.d.cts +1 -1
- package/dist/powerlines/src/types/commands.d.mts +2 -2
- package/dist/powerlines/src/types/config.d.cts +5 -5
- package/dist/powerlines/src/types/config.d.mts +6 -6
- package/dist/powerlines/src/types/context.d.cts +28 -4
- package/dist/powerlines/src/types/context.d.mts +30 -6
- package/dist/powerlines/src/types/fs.d.cts +1 -1
- package/dist/powerlines/src/types/fs.d.mts +1 -1
- package/dist/powerlines/src/types/index.d.mts +12 -0
- package/dist/powerlines/src/types/plugin.d.cts +3 -3
- package/dist/powerlines/src/types/plugin.d.mts +4 -4
- package/dist/powerlines/src/types/resolved.d.cts +1 -1
- package/dist/powerlines/src/types/resolved.d.mts +2 -2
- package/dist/powerlines/src/types/tsconfig.d.mts +1 -1
- package/dist/powerlines/src/types/unplugin.d.mts +7 -0
- package/dist/types/index.mjs +1 -1
- package/dist/types/plugin.d.cts +1 -1
- package/dist/types/plugin.mjs +1 -1
- package/dist/types/runtime.mjs +1 -1
- package/package.json +15 -15
- package/dist/babel/index.d.cts +0 -1
- package/dist/helpers/index.d.cts +0 -6
|
@@ -1 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __reExport = (target, mod, secondTarget, symbols) => {
|
|
23
|
+
if (symbols) {
|
|
24
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
25
|
+
secondTarget && __defProp(secondTarget, Symbol.toStringTag, { value: "Module" });
|
|
26
|
+
}
|
|
27
|
+
__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default");
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
|
|
36
|
+
exports.__reExport = __reExport;
|
|
37
|
+
exports.__toESM = __toESM;
|
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
9
|
+
key = keys[i];
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
11
|
+
__defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget, symbols) => {
|
|
21
|
+
if (symbols) {
|
|
22
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
23
|
+
secondTarget && __defProp(secondTarget, Symbol.toStringTag, { value: "Module" });
|
|
24
|
+
}
|
|
25
|
+
__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default");
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { __reExport };
|
package/dist/babel/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_plugin = require('./plugin.cjs');
|
package/dist/babel/index.mjs
CHANGED
package/dist/babel/plugin.cjs
CHANGED
|
@@ -1,5 +1,121 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_type = require('../deepkit/src/vendor/type.cjs');
|
|
3
|
+
const require_create_plugin = require('../plugin-babel/src/helpers/create-plugin.cjs');
|
|
4
|
+
const require_module_helpers = require('../plugin-babel/src/helpers/module-helpers.cjs');
|
|
5
|
+
const require_capnp = require('../deepkit/src/capnp.cjs');
|
|
6
|
+
const require_reflection = require('../deepkit/schemas/reflection2.cjs');
|
|
7
|
+
const require_utilities = require('../deepkit/src/utilities.cjs');
|
|
8
|
+
const require_persistence = require('../helpers/persistence.cjs');
|
|
9
|
+
let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
|
|
10
|
+
let __stryke_capnp = require("@stryke/capnp");
|
|
11
|
+
__stryke_capnp = require_rolldown_runtime.__toESM(__stryke_capnp);
|
|
12
|
+
let __stryke_fs_buffer = require("@stryke/fs/buffer");
|
|
13
|
+
let node_fs = require("node:fs");
|
|
2
14
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
15
|
+
//#region src/babel/plugin.ts
|
|
16
|
+
const envBabelPlugin = require_create_plugin.createBabelPlugin("env", ({ log, context }) => {
|
|
17
|
+
function extractEnv(node, pass, isInjectable = false) {
|
|
18
|
+
const envTypesAliasProperties = context.env.types.env?.getProperties().filter((prop) => prop.getAlias().length > 0);
|
|
19
|
+
if (node.name) {
|
|
20
|
+
const prefix = context.config.env.prefix.find((pre) => node.name && node.name.startsWith(pre) && (context.env.types.env?.hasProperty(node.name.replace(`${pre}_`, "")) || envTypesAliasProperties.some((prop) => prop.getAlias().includes(node.name.replace(`${pre}_`, "")))));
|
|
21
|
+
let name = node.name;
|
|
22
|
+
if (prefix) name = node.name.replace(`${prefix}_`, "");
|
|
23
|
+
log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Environment variable ${name} found in ${pass.filename || "unknown file"}.`);
|
|
24
|
+
if (context.env.types.env?.hasProperty(name) || envTypesAliasProperties.some((prop) => prop.getAlias().includes(name))) {
|
|
25
|
+
const envProperty = context.env.types.env.hasProperty(name) ? context.env.types.env.getProperty(name) : envTypesAliasProperties.find((prop) => prop.getAlias().includes(name));
|
|
26
|
+
if (!envProperty || envProperty.isIgnored()) return;
|
|
27
|
+
if (!context.env.used.env.hasProperty(name)) context.env.used.env.addProperty(envProperty.property);
|
|
28
|
+
if (context.config.env.inject && isInjectable) {
|
|
29
|
+
let value = context.env.parsed?.[name];
|
|
30
|
+
if (value === void 0) {
|
|
31
|
+
const prefix$1 = context.config.env.prefix.find((pre) => {
|
|
32
|
+
return context.env.parsed[`${pre.replace(/_$/g, "")}_${name}`];
|
|
33
|
+
});
|
|
34
|
+
if (prefix$1) value = context.env.parsed[`${prefix$1.replace(/_$/g, "")}_${name}`];
|
|
35
|
+
}
|
|
36
|
+
value ??= envProperty.getDefaultValue();
|
|
37
|
+
if (envProperty.isValueRequired() && value === void 0) throw new Error(`Environment variable \`${name}\` is not defined in the .env configuration files`);
|
|
38
|
+
return require_utilities.stringifyDefaultValue(envProperty, value);
|
|
39
|
+
}
|
|
40
|
+
} 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"}.
|
|
41
|
+
|
|
42
|
+
The following environment configuration names are defined in the \`env\` type definition: \n${context.env.types.env?.getPropertyNames().sort((a, b) => String(a).localeCompare(String(b))).map((typeDef) => ` - ${String(typeDef)} ${envTypesAliasProperties.some((prop) => prop.getNameAsString() === String(typeDef) && prop.getAlias().length > 0) ? `(Alias: ${envTypesAliasProperties?.find((prop) => prop.getNameAsString() === String(typeDef))?.getAlias().join(", ")})` : ""}`).join("\n")} \n\nUsing the following env prefix: \n${context.config.env.prefix.map((prefix$1) => ` - ${prefix$1}`).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`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
visitor: { MemberExpression(path, pass) {
|
|
47
|
+
if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "$storm" }) && path.get("property")?.isIdentifier()) {
|
|
48
|
+
const identifier = path.get("property")?.node;
|
|
49
|
+
extractEnv(identifier, pass, false);
|
|
50
|
+
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
51
|
+
require_module_helpers.addImport(path, {
|
|
52
|
+
module: "storm:env",
|
|
53
|
+
name: "env",
|
|
54
|
+
imported: "env"
|
|
55
|
+
});
|
|
56
|
+
} else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isCallExpression({ callee: {
|
|
57
|
+
name: "useStorm",
|
|
58
|
+
type: "Identifier"
|
|
59
|
+
} }) && path.get("property")?.isIdentifier()) {
|
|
60
|
+
const identifier = path.get("property")?.node;
|
|
61
|
+
extractEnv(identifier, pass, false);
|
|
62
|
+
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
63
|
+
require_module_helpers.addImport(path, {
|
|
64
|
+
module: "storm:env",
|
|
65
|
+
name: "env",
|
|
66
|
+
imported: "env"
|
|
67
|
+
});
|
|
68
|
+
} else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "process" }) && path.get("property")?.isIdentifier()) {
|
|
69
|
+
const identifier = path.get("property")?.node;
|
|
70
|
+
if (!identifier.name) return;
|
|
71
|
+
extractEnv(identifier, pass, false);
|
|
72
|
+
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
73
|
+
require_module_helpers.addImport(path, {
|
|
74
|
+
module: "storm:env",
|
|
75
|
+
name: "env",
|
|
76
|
+
imported: "env"
|
|
77
|
+
});
|
|
78
|
+
} else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isMetaProperty() && path.get("property")?.isIdentifier()) {
|
|
79
|
+
const identifier = path.get("property")?.node;
|
|
80
|
+
if (!identifier.name) return;
|
|
81
|
+
extractEnv(identifier, pass, false);
|
|
82
|
+
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
83
|
+
require_module_helpers.addImport(path, {
|
|
84
|
+
module: "storm:env",
|
|
85
|
+
name: "env",
|
|
86
|
+
imported: "env"
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
} },
|
|
90
|
+
post() {
|
|
91
|
+
log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Adding environment variables from ${this.filename || "unknown file"} to env.json.`);
|
|
92
|
+
let persistedEnv = require_type.type_exports.ReflectionClass.from({
|
|
93
|
+
kind: require_type.type_exports.ReflectionKind.objectLiteral,
|
|
94
|
+
description: `An object containing the environment variables used by the application.`,
|
|
95
|
+
types: []
|
|
96
|
+
});
|
|
97
|
+
const reflectionPath = require_persistence.getEnvReflectionsPath(context, "env");
|
|
98
|
+
if (reflectionPath && (0, node_fs.existsSync)(reflectionPath)) {
|
|
99
|
+
log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Environment reflection file found at ${reflectionPath}, reading existing reflection.`);
|
|
100
|
+
persistedEnv = (0, require_type.type_exports.resolveClassType)((0, require_type.type_exports.deserializeType)(require_capnp.convertFromCapnp(new __stryke_capnp.Message((0, __stryke_fs_buffer.readFileBufferSync)(reflectionPath), false).getRoot(require_reflection.SerializedTypes).types)));
|
|
101
|
+
}
|
|
102
|
+
log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Adding new variables to env reflection at ${reflectionPath}.`);
|
|
103
|
+
persistedEnv.getProperties().filter((property) => property.getNameAsString() && !context.env.used.env.hasProperty(property.getNameAsString())).forEach((property) => {
|
|
104
|
+
context.env.used.env.addProperty({
|
|
105
|
+
...property,
|
|
106
|
+
name: property.getNameAsString(),
|
|
107
|
+
description: property.getDescription() ?? `The ${property.getNameAsString()} variable.`,
|
|
108
|
+
default: property.getDefaultValue(),
|
|
109
|
+
optional: property.isOptional() ? true : void 0,
|
|
110
|
+
readonly: property.isReadonly() ? true : void 0,
|
|
111
|
+
visibility: property.getVisibility(),
|
|
112
|
+
type: property.getType(),
|
|
113
|
+
tags: property.getTags()
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
exports.envBabelPlugin = envBabelPlugin;
|
package/dist/babel/plugin.d.cts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { DeclareBabelTransformPluginReturn } from "../powerlines/src/types/babel.cjs";
|
|
1
2
|
import { EnvPluginContext, EnvPluginResolvedConfig } from "../types/plugin.cjs";
|
|
2
|
-
import "../index.cjs";
|
|
3
|
-
import * as powerlines0 from "powerlines";
|
|
4
3
|
|
|
5
4
|
//#region src/babel/plugin.d.ts
|
|
6
|
-
declare const envBabelPlugin:
|
|
5
|
+
declare const envBabelPlugin: DeclareBabelTransformPluginReturn<EnvPluginContext<EnvPluginResolvedConfig>, Record<string, any>>;
|
|
7
6
|
//#endregion
|
|
8
7
|
export { envBabelPlugin };
|
package/dist/babel/plugin.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { DeclareBabelTransformPluginReturn } from "../powerlines/src/types/babel.mjs";
|
|
2
|
+
import "../powerlines/src/index.mjs";
|
|
1
3
|
import { EnvPluginContext, EnvPluginResolvedConfig } from "../types/plugin.mjs";
|
|
2
4
|
import "../index.mjs";
|
|
3
|
-
import * as powerlines0 from "powerlines";
|
|
4
5
|
|
|
5
6
|
//#region src/babel/plugin.d.ts
|
|
6
|
-
declare const envBabelPlugin:
|
|
7
|
+
declare const envBabelPlugin: DeclareBabelTransformPluginReturn<EnvPluginContext<EnvPluginResolvedConfig>, Record<string, any>>;
|
|
7
8
|
//#endregion
|
|
8
9
|
export { envBabelPlugin };
|
package/dist/babel/plugin.mjs
CHANGED
|
@@ -1,5 +1,119 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type_exports } from "../deepkit/src/vendor/type.mjs";
|
|
2
|
+
import { createBabelPlugin } from "../plugin-babel/src/helpers/create-plugin.mjs";
|
|
3
|
+
import { addImport } from "../plugin-babel/src/helpers/module-helpers.mjs";
|
|
4
|
+
import { convertFromCapnp } from "../deepkit/src/capnp.mjs";
|
|
5
|
+
import { SerializedTypes } from "../deepkit/schemas/reflection2.mjs";
|
|
6
|
+
import { stringifyDefaultValue } from "../deepkit/src/utilities.mjs";
|
|
7
|
+
import { getEnvReflectionsPath } from "../helpers/persistence.mjs";
|
|
8
|
+
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
9
|
+
import * as capnp from "@stryke/capnp";
|
|
10
|
+
import { readFileBufferSync } from "@stryke/fs/buffer";
|
|
11
|
+
import { existsSync } from "node:fs";
|
|
2
12
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
13
|
+
//#region src/babel/plugin.ts
|
|
14
|
+
const envBabelPlugin = createBabelPlugin("env", ({ log, context }) => {
|
|
15
|
+
function extractEnv(node, pass, isInjectable = false) {
|
|
16
|
+
const envTypesAliasProperties = context.env.types.env?.getProperties().filter((prop) => prop.getAlias().length > 0);
|
|
17
|
+
if (node.name) {
|
|
18
|
+
const prefix = context.config.env.prefix.find((pre) => node.name && node.name.startsWith(pre) && (context.env.types.env?.hasProperty(node.name.replace(`${pre}_`, "")) || envTypesAliasProperties.some((prop) => prop.getAlias().includes(node.name.replace(`${pre}_`, "")))));
|
|
19
|
+
let name = node.name;
|
|
20
|
+
if (prefix) name = node.name.replace(`${prefix}_`, "");
|
|
21
|
+
log(LogLevelLabel.TRACE, `Environment variable ${name} found in ${pass.filename || "unknown file"}.`);
|
|
22
|
+
if (context.env.types.env?.hasProperty(name) || envTypesAliasProperties.some((prop) => prop.getAlias().includes(name))) {
|
|
23
|
+
const envProperty = context.env.types.env.hasProperty(name) ? context.env.types.env.getProperty(name) : envTypesAliasProperties.find((prop) => prop.getAlias().includes(name));
|
|
24
|
+
if (!envProperty || envProperty.isIgnored()) return;
|
|
25
|
+
if (!context.env.used.env.hasProperty(name)) context.env.used.env.addProperty(envProperty.property);
|
|
26
|
+
if (context.config.env.inject && isInjectable) {
|
|
27
|
+
let value = context.env.parsed?.[name];
|
|
28
|
+
if (value === void 0) {
|
|
29
|
+
const prefix$1 = context.config.env.prefix.find((pre) => {
|
|
30
|
+
return context.env.parsed[`${pre.replace(/_$/g, "")}_${name}`];
|
|
31
|
+
});
|
|
32
|
+
if (prefix$1) value = context.env.parsed[`${prefix$1.replace(/_$/g, "")}_${name}`];
|
|
33
|
+
}
|
|
34
|
+
value ??= envProperty.getDefaultValue();
|
|
35
|
+
if (envProperty.isValueRequired() && value === void 0) throw new Error(`Environment variable \`${name}\` is not defined in the .env configuration files`);
|
|
36
|
+
return stringifyDefaultValue(envProperty, value);
|
|
37
|
+
}
|
|
38
|
+
} 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"}.
|
|
39
|
+
|
|
40
|
+
The following environment configuration names are defined in the \`env\` type definition: \n${context.env.types.env?.getPropertyNames().sort((a, b) => String(a).localeCompare(String(b))).map((typeDef) => ` - ${String(typeDef)} ${envTypesAliasProperties.some((prop) => prop.getNameAsString() === String(typeDef) && prop.getAlias().length > 0) ? `(Alias: ${envTypesAliasProperties?.find((prop) => prop.getNameAsString() === String(typeDef))?.getAlias().join(", ")})` : ""}`).join("\n")} \n\nUsing the following env prefix: \n${context.config.env.prefix.map((prefix$1) => ` - ${prefix$1}`).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`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
visitor: { MemberExpression(path, pass) {
|
|
45
|
+
if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "$storm" }) && path.get("property")?.isIdentifier()) {
|
|
46
|
+
const identifier = path.get("property")?.node;
|
|
47
|
+
extractEnv(identifier, pass, false);
|
|
48
|
+
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
49
|
+
addImport(path, {
|
|
50
|
+
module: "storm:env",
|
|
51
|
+
name: "env",
|
|
52
|
+
imported: "env"
|
|
53
|
+
});
|
|
54
|
+
} else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isCallExpression({ callee: {
|
|
55
|
+
name: "useStorm",
|
|
56
|
+
type: "Identifier"
|
|
57
|
+
} }) && path.get("property")?.isIdentifier()) {
|
|
58
|
+
const identifier = path.get("property")?.node;
|
|
59
|
+
extractEnv(identifier, pass, false);
|
|
60
|
+
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
61
|
+
addImport(path, {
|
|
62
|
+
module: "storm:env",
|
|
63
|
+
name: "env",
|
|
64
|
+
imported: "env"
|
|
65
|
+
});
|
|
66
|
+
} else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "process" }) && path.get("property")?.isIdentifier()) {
|
|
67
|
+
const identifier = path.get("property")?.node;
|
|
68
|
+
if (!identifier.name) return;
|
|
69
|
+
extractEnv(identifier, pass, false);
|
|
70
|
+
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
71
|
+
addImport(path, {
|
|
72
|
+
module: "storm:env",
|
|
73
|
+
name: "env",
|
|
74
|
+
imported: "env"
|
|
75
|
+
});
|
|
76
|
+
} else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isMetaProperty() && path.get("property")?.isIdentifier()) {
|
|
77
|
+
const identifier = path.get("property")?.node;
|
|
78
|
+
if (!identifier.name) return;
|
|
79
|
+
extractEnv(identifier, pass, false);
|
|
80
|
+
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
81
|
+
addImport(path, {
|
|
82
|
+
module: "storm:env",
|
|
83
|
+
name: "env",
|
|
84
|
+
imported: "env"
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
} },
|
|
88
|
+
post() {
|
|
89
|
+
log(LogLevelLabel.TRACE, `Adding environment variables from ${this.filename || "unknown file"} to env.json.`);
|
|
90
|
+
let persistedEnv = type_exports.ReflectionClass.from({
|
|
91
|
+
kind: type_exports.ReflectionKind.objectLiteral,
|
|
92
|
+
description: `An object containing the environment variables used by the application.`,
|
|
93
|
+
types: []
|
|
94
|
+
});
|
|
95
|
+
const reflectionPath = getEnvReflectionsPath(context, "env");
|
|
96
|
+
if (reflectionPath && existsSync(reflectionPath)) {
|
|
97
|
+
log(LogLevelLabel.TRACE, `Environment reflection file found at ${reflectionPath}, reading existing reflection.`);
|
|
98
|
+
persistedEnv = (0, type_exports.resolveClassType)((0, type_exports.deserializeType)(convertFromCapnp(new capnp.Message(readFileBufferSync(reflectionPath), false).getRoot(SerializedTypes).types)));
|
|
99
|
+
}
|
|
100
|
+
log(LogLevelLabel.TRACE, `Adding new variables to env reflection at ${reflectionPath}.`);
|
|
101
|
+
persistedEnv.getProperties().filter((property) => property.getNameAsString() && !context.env.used.env.hasProperty(property.getNameAsString())).forEach((property) => {
|
|
102
|
+
context.env.used.env.addProperty({
|
|
103
|
+
...property,
|
|
104
|
+
name: property.getNameAsString(),
|
|
105
|
+
description: property.getDescription() ?? `The ${property.getNameAsString()} variable.`,
|
|
106
|
+
default: property.getDefaultValue(),
|
|
107
|
+
optional: property.isOptional() ? true : void 0,
|
|
108
|
+
readonly: property.isReadonly() ? true : void 0,
|
|
109
|
+
visibility: property.getVisibility(),
|
|
110
|
+
type: property.getType(),
|
|
111
|
+
tags: property.getTags()
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
export { envBabelPlugin };
|
package/dist/components/docs.cjs
CHANGED
|
@@ -1 +1,71 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_type = require('../deepkit/src/vendor/type.cjs');
|
|
3
|
+
const require_create_reflection_resource = require('../helpers/create-reflection-resource.cjs');
|
|
4
|
+
let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
5
|
+
let __alloy_js_core = require("@alloy-js/core");
|
|
6
|
+
let __stryke_path_join = require("@stryke/path/join");
|
|
7
|
+
let __powerlines_alloy_core_contexts_context = require("@powerlines/alloy/core/contexts/context");
|
|
8
|
+
let __alloy_js_markdown = require("@alloy-js/markdown");
|
|
9
|
+
let __powerlines_alloy_markdown_components_markdown_file = require("@powerlines/alloy/markdown/components/markdown-file");
|
|
10
|
+
let __powerlines_alloy_markdown_components_markdown_table = require("@powerlines/alloy/markdown/components/markdown-table");
|
|
11
|
+
|
|
12
|
+
//#region src/components/docs.tsx
|
|
13
|
+
/**
|
|
14
|
+
* Generates the environment configuration markdown documentation for the Powerlines project.
|
|
15
|
+
*/
|
|
16
|
+
function EnvDocs() {
|
|
17
|
+
const context = (0, __powerlines_alloy_core_contexts_context.usePowerlines)();
|
|
18
|
+
if (!context) return null;
|
|
19
|
+
const reflection = require_create_reflection_resource.createReflectionResource(context);
|
|
20
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_alloy_markdown_components_markdown_file.MarkdownFile, {
|
|
21
|
+
get path() {
|
|
22
|
+
return (0, __stryke_path_join.joinPaths)(context.config.projectRoot, "docs", "generated", "env.md");
|
|
23
|
+
},
|
|
24
|
+
get children() {
|
|
25
|
+
return [
|
|
26
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_markdown.Heading, {
|
|
27
|
+
level: 1,
|
|
28
|
+
children: "Environment Configuration"
|
|
29
|
+
}),
|
|
30
|
+
__alloy_js_core.code`Below is a list of environment variables used by the`,
|
|
31
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
32
|
+
get when() {
|
|
33
|
+
return !!context?.packageJson.name;
|
|
34
|
+
},
|
|
35
|
+
get children() {
|
|
36
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_markdown.Link, {
|
|
37
|
+
get href() {
|
|
38
|
+
return `https://www.npmjs.com/package/${context?.packageJson.name}`;
|
|
39
|
+
},
|
|
40
|
+
get title() {
|
|
41
|
+
return context.packageJson.name;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}),
|
|
46
|
+
__alloy_js_core.code`package. These values can be updated in the \`.env\` file in the root of the project.`,
|
|
47
|
+
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
48
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_markdown.Heading, {
|
|
49
|
+
level: 2,
|
|
50
|
+
children: "Environment Variables"
|
|
51
|
+
}),
|
|
52
|
+
__alloy_js_core.code`The below list of environment variables are used as configuration parameters to drive the processing of the application. The data contained in these variables are **not** considered sensitive or confidential. Any values provided in these variables will be available in plain text to the public.`,
|
|
53
|
+
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
54
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_alloy_markdown_components_markdown_table.MarkdownTable, { get data() {
|
|
55
|
+
return reflection.data?.getProperties().filter((property) => property.getNameAsString() !== "__STORM_INJECTED__").sort((a, b) => a.getNameAsString().localeCompare(b.getNameAsString())).map((reflectionProperty) => {
|
|
56
|
+
return {
|
|
57
|
+
name: reflectionProperty.getNameAsString().trim(),
|
|
58
|
+
description: (reflectionProperty.getDescription() ?? "").trim(),
|
|
59
|
+
type: (0, require_type.type_exports.stringifyType)(reflectionProperty.getType()).trim().replaceAll(" | ", ", or "),
|
|
60
|
+
defaultValue: reflectionProperty.hasDefault() ? String(reflectionProperty.getDefaultValue())?.includes("\"") ? reflectionProperty.getDefaultValue() : `\`${reflectionProperty.getDefaultValue()}\`` : "",
|
|
61
|
+
required: reflectionProperty.isValueRequired() ? "" : "✔"
|
|
62
|
+
};
|
|
63
|
+
}) ?? [];
|
|
64
|
+
} })
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
exports.EnvDocs = EnvDocs;
|
package/dist/components/docs.mjs
CHANGED
|
@@ -1 +1,70 @@
|
|
|
1
|
-
import{type_exports
|
|
1
|
+
import { type_exports } from "../deepkit/src/vendor/type.mjs";
|
|
2
|
+
import { createReflectionResource } from "../helpers/create-reflection-resource.mjs";
|
|
3
|
+
import { createComponent, createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
4
|
+
import { Show, code } from "@alloy-js/core";
|
|
5
|
+
import { joinPaths } from "@stryke/path/join";
|
|
6
|
+
import { usePowerlines } from "@powerlines/alloy/core/contexts/context";
|
|
7
|
+
import { Heading, Link } from "@alloy-js/markdown";
|
|
8
|
+
import { MarkdownFile } from "@powerlines/alloy/markdown/components/markdown-file";
|
|
9
|
+
import { MarkdownTable } from "@powerlines/alloy/markdown/components/markdown-table";
|
|
10
|
+
|
|
11
|
+
//#region src/components/docs.tsx
|
|
12
|
+
/**
|
|
13
|
+
* Generates the environment configuration markdown documentation for the Powerlines project.
|
|
14
|
+
*/
|
|
15
|
+
function EnvDocs() {
|
|
16
|
+
const context = usePowerlines();
|
|
17
|
+
if (!context) return null;
|
|
18
|
+
const reflection = createReflectionResource(context);
|
|
19
|
+
return createComponent(MarkdownFile, {
|
|
20
|
+
get path() {
|
|
21
|
+
return joinPaths(context.config.projectRoot, "docs", "generated", "env.md");
|
|
22
|
+
},
|
|
23
|
+
get children() {
|
|
24
|
+
return [
|
|
25
|
+
createComponent(Heading, {
|
|
26
|
+
level: 1,
|
|
27
|
+
children: "Environment Configuration"
|
|
28
|
+
}),
|
|
29
|
+
code`Below is a list of environment variables used by the`,
|
|
30
|
+
createComponent(Show, {
|
|
31
|
+
get when() {
|
|
32
|
+
return !!context?.packageJson.name;
|
|
33
|
+
},
|
|
34
|
+
get children() {
|
|
35
|
+
return createComponent(Link, {
|
|
36
|
+
get href() {
|
|
37
|
+
return `https://www.npmjs.com/package/${context?.packageJson.name}`;
|
|
38
|
+
},
|
|
39
|
+
get title() {
|
|
40
|
+
return context.packageJson.name;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}),
|
|
45
|
+
code`package. These values can be updated in the \`.env\` file in the root of the project.`,
|
|
46
|
+
createIntrinsic("hbr", {}),
|
|
47
|
+
createComponent(Heading, {
|
|
48
|
+
level: 2,
|
|
49
|
+
children: "Environment Variables"
|
|
50
|
+
}),
|
|
51
|
+
code`The below list of environment variables are used as configuration parameters to drive the processing of the application. The data contained in these variables are **not** considered sensitive or confidential. Any values provided in these variables will be available in plain text to the public.`,
|
|
52
|
+
createIntrinsic("hbr", {}),
|
|
53
|
+
createComponent(MarkdownTable, { get data() {
|
|
54
|
+
return reflection.data?.getProperties().filter((property) => property.getNameAsString() !== "__STORM_INJECTED__").sort((a, b) => a.getNameAsString().localeCompare(b.getNameAsString())).map((reflectionProperty) => {
|
|
55
|
+
return {
|
|
56
|
+
name: reflectionProperty.getNameAsString().trim(),
|
|
57
|
+
description: (reflectionProperty.getDescription() ?? "").trim(),
|
|
58
|
+
type: (0, type_exports.stringifyType)(reflectionProperty.getType()).trim().replaceAll(" | ", ", or "),
|
|
59
|
+
defaultValue: reflectionProperty.hasDefault() ? String(reflectionProperty.getDefaultValue())?.includes("\"") ? reflectionProperty.getDefaultValue() : `\`${reflectionProperty.getDefaultValue()}\`` : "",
|
|
60
|
+
required: reflectionProperty.isValueRequired() ? "" : "✔"
|
|
61
|
+
};
|
|
62
|
+
}) ?? [];
|
|
63
|
+
} })
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { EnvDocs };
|