@powerlines/plugin-env 0.16.235 → 0.16.237
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/components/docs.cjs +1 -1
- package/dist/components/docs.mjs +1 -1
- package/dist/helpers/index.cjs +1 -3
- package/dist/helpers/index.d.cts +2 -2
- package/dist/helpers/index.d.mts +2 -2
- package/dist/helpers/index.mjs +2 -2
- package/dist/helpers/schema.cjs +1 -45
- package/dist/helpers/schema.d.cts +1 -15
- package/dist/helpers/schema.d.cts.map +1 -1
- package/dist/helpers/schema.d.mts +1 -15
- package/dist/helpers/schema.d.mts.map +1 -1
- package/dist/helpers/schema.mjs +1 -43
- package/dist/helpers/schema.mjs.map +1 -1
- package/dist/index.cjs +3 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/components/docs.cjs
CHANGED
|
@@ -2,7 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_types_plugin = require('../types/plugin.cjs');
|
|
4
4
|
let _powerlines_schema_helpers = require("@powerlines/schema/helpers");
|
|
5
|
-
let _stryke_path_join = require("@stryke/path/join");
|
|
6
5
|
let powerlines_plugin_utils = require("powerlines/plugin-utils");
|
|
7
6
|
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
8
7
|
let _alloy_js_core = require("@alloy-js/core");
|
|
@@ -13,6 +12,7 @@ let _powerlines_plugin_alloy_markdown_components_heading = require("@powerlines/
|
|
|
13
12
|
let _powerlines_plugin_alloy_markdown_components_markdown_file = require("@powerlines/plugin-alloy/markdown/components/markdown-file");
|
|
14
13
|
let _powerlines_plugin_alloy_markdown_components_markdown_table = require("@powerlines/plugin-alloy/markdown/components/markdown-table");
|
|
15
14
|
let _powerlines_schema_codegen = require("@powerlines/schema/codegen");
|
|
15
|
+
let _stryke_path_join = require("@stryke/path/join");
|
|
16
16
|
|
|
17
17
|
//#region src/components/docs.tsx
|
|
18
18
|
const __ΩPartial = [
|
package/dist/components/docs.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { __ΩEnvPluginContext } from "../types/plugin.mjs";
|
|
2
2
|
import { getProperties } from "@powerlines/schema/helpers";
|
|
3
|
-
import { joinPaths } from "@stryke/path/join";
|
|
4
3
|
import { getDocsOutputPath } from "powerlines/plugin-utils";
|
|
5
4
|
import { createComponent, mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
6
5
|
import { Show, code } from "@alloy-js/core";
|
|
@@ -11,6 +10,7 @@ import { Heading } from "@powerlines/plugin-alloy/markdown/components/heading";
|
|
|
11
10
|
import { MarkdownFile } from "@powerlines/plugin-alloy/markdown/components/markdown-file";
|
|
12
11
|
import { MarkdownTable } from "@powerlines/plugin-alloy/markdown/components/markdown-table";
|
|
13
12
|
import { stringifyType } from "@powerlines/schema/codegen";
|
|
13
|
+
import { joinPaths } from "@stryke/path/join";
|
|
14
14
|
|
|
15
15
|
//#region src/components/docs.tsx
|
|
16
16
|
const __ΩPartial = [
|
package/dist/helpers/index.cjs
CHANGED
|
@@ -11,7 +11,5 @@ exports.getDefaultSecretsTypeDefinition = require_helpers_schema.getDefaultSecre
|
|
|
11
11
|
exports.getDefaultVarsTypeDefinition = require_helpers_schema.getDefaultVarsTypeDefinition;
|
|
12
12
|
exports.loadEnv = require_helpers_load.loadEnv;
|
|
13
13
|
exports.loadEnvFromContext = require_helpers_load.loadEnvFromContext;
|
|
14
|
-
exports.readActiveEnv = require_helpers_schema.readActiveEnv;
|
|
15
14
|
exports.removeEnvPrefix = require_helpers_source_file_env.removeEnvPrefix;
|
|
16
|
-
exports.resolveRuntimeTypeFile = require_helpers_schema.resolveRuntimeTypeFile;
|
|
17
|
-
exports.writeActiveEnv = require_helpers_schema.writeActiveEnv;
|
|
15
|
+
exports.resolveRuntimeTypeFile = require_helpers_schema.resolveRuntimeTypeFile;
|
package/dist/helpers/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { env } from "./automd-generator.cjs";
|
|
2
2
|
import { loadEnv, loadEnvFromContext } from "./load.cjs";
|
|
3
|
-
import { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition,
|
|
3
|
+
import { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, resolveRuntimeTypeFile } from "./schema.cjs";
|
|
4
4
|
import { formatEnvField, removeEnvPrefix } from "./source-file-env.cjs";
|
|
5
|
-
export { env, extractEnvSchema, formatEnvField, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, loadEnv, loadEnvFromContext,
|
|
5
|
+
export { env, extractEnvSchema, formatEnvField, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, loadEnv, loadEnvFromContext, removeEnvPrefix, resolveRuntimeTypeFile };
|
package/dist/helpers/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { env } from "./automd-generator.mjs";
|
|
2
2
|
import { loadEnv, loadEnvFromContext } from "./load.mjs";
|
|
3
|
-
import { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition,
|
|
3
|
+
import { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, resolveRuntimeTypeFile } from "./schema.mjs";
|
|
4
4
|
import { formatEnvField, removeEnvPrefix } from "./source-file-env.mjs";
|
|
5
|
-
export { env, extractEnvSchema, formatEnvField, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, loadEnv, loadEnvFromContext,
|
|
5
|
+
export { env, extractEnvSchema, formatEnvField, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, loadEnv, loadEnvFromContext, removeEnvPrefix, resolveRuntimeTypeFile };
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { formatEnvField, removeEnvPrefix } from "./source-file-env.mjs";
|
|
2
2
|
import { loadEnv, loadEnvFromContext } from "./load.mjs";
|
|
3
|
-
import { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition,
|
|
3
|
+
import { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, resolveRuntimeTypeFile } from "./schema.mjs";
|
|
4
4
|
import { env } from "./automd-generator.mjs";
|
|
5
5
|
|
|
6
|
-
export { env, extractEnvSchema, formatEnvField, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, loadEnv, loadEnvFromContext,
|
|
6
|
+
export { env, extractEnvSchema, formatEnvField, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, loadEnv, loadEnvFromContext, removeEnvPrefix, resolveRuntimeTypeFile };
|
package/dist/helpers/schema.cjs
CHANGED
|
@@ -5,7 +5,6 @@ const require_helpers_load = require('./load.cjs');
|
|
|
5
5
|
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
6
6
|
let _powerlines_schema_extract = require("@powerlines/schema/extract");
|
|
7
7
|
let _powerlines_schema_helpers = require("@powerlines/schema/helpers");
|
|
8
|
-
let _stryke_path_join = require("@stryke/path/join");
|
|
9
8
|
let _stryke_type_checks_is_set_array = require("@stryke/type-checks/is-set-array");
|
|
10
9
|
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
11
10
|
let defu = require("defu");
|
|
@@ -155,52 +154,9 @@ extractEnvSchema.__type = [
|
|
|
155
154
|
"Extracts the environment variables and secrets schema from the provided type definitions in the plugin options, merges them with the default environment variables and secrets schema, and stores the resulting schema in the plugin context for later use during the build process.",
|
|
156
155
|
"P\"2!n\"2#>$$`/%?&"
|
|
157
156
|
];
|
|
158
|
-
/**
|
|
159
|
-
* Reads the active environment variables and secrets from the plugin context's cache and stores them in the plugin context for use during the build process. This function should be called during the plugin's `buildStart` hook to ensure that the active environment variables and secrets are available before the build process begins.
|
|
160
|
-
*
|
|
161
|
-
* @param context - The plugin context
|
|
162
|
-
* @returns A promise that resolves when the active environment variables and secrets have been read and stored in the plugin context.
|
|
163
|
-
*/
|
|
164
|
-
async function readActiveEnv(context) {
|
|
165
|
-
context.env.vars.schema.metadata ??= {};
|
|
166
|
-
context.env.vars.schema.metadata.active ??= [];
|
|
167
|
-
if (context.fs.existsSync((0, _stryke_path_join.joinPaths)(context.cachePath, "env", "vars.json"))) {
|
|
168
|
-
const content = await context.fs.read((0, _stryke_path_join.joinPaths)(context.cachePath, "env", "vars.json"));
|
|
169
|
-
if (content) context.env.vars.schema.metadata.active = JSON.parse(content)?.elements ?? [];
|
|
170
|
-
}
|
|
171
|
-
context.env.secrets.schema.metadata ??= {};
|
|
172
|
-
context.env.secrets.schema.metadata.active ??= [];
|
|
173
|
-
if (context.fs.existsSync((0, _stryke_path_join.joinPaths)(context.cachePath, "env", "secrets.json"))) {
|
|
174
|
-
const content = await context.fs.read((0, _stryke_path_join.joinPaths)(context.cachePath, "env", "secrets.json"));
|
|
175
|
-
if (content) context.env.secrets.schema.metadata.active = JSON.parse(content)?.elements ?? [];
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
readActiveEnv.__type = [
|
|
179
|
-
"context",
|
|
180
|
-
"readActiveEnv",
|
|
181
|
-
"Reads the active environment variables and secrets from the plugin context's cache and stores them in the plugin context for use during the build process. This function should be called during the plugin's `buildStart` hook to ensure that the active environment variables and secrets are available before the build process begins.",
|
|
182
|
-
"P\"2!\"/\"?#"
|
|
183
|
-
];
|
|
184
|
-
/**
|
|
185
|
-
* Writes the active environment variables and secrets from the plugin context to the plugin context's cache for use during the build process. This function should be called whenever the active environment variables and secrets are updated in the plugin context to ensure that the latest values are available during the build process.
|
|
186
|
-
*
|
|
187
|
-
* @param context - The plugin context
|
|
188
|
-
* @returns A promise that resolves when the active environment variables and secrets have been written to the plugin context's cache.
|
|
189
|
-
*/
|
|
190
|
-
async function writeActiveEnv(context) {
|
|
191
|
-
return Promise.all([(0, _stryke_type_checks_is_set_array.isSetArray)(context.env.vars.schema.metadata?.active) ? context.fs.write((0, _stryke_path_join.joinPaths)(context.cachePath, "env", "vars.json"), JSON.stringify({ elements: context.env.vars.schema.metadata.active })) : void 0, (0, _stryke_type_checks_is_set_array.isSetArray)(context.env.secrets.schema.metadata?.active) ? context.fs.write((0, _stryke_path_join.joinPaths)(context.cachePath, "env", "secrets.json"), JSON.stringify({ elements: context.env.secrets.schema.metadata.active })) : void 0].filter(Boolean));
|
|
192
|
-
}
|
|
193
|
-
writeActiveEnv.__type = [
|
|
194
|
-
"context",
|
|
195
|
-
"writeActiveEnv",
|
|
196
|
-
"Writes the active environment variables and secrets from the plugin context to the plugin context's cache for use during the build process. This function should be called whenever the active environment variables and secrets are updated in the plugin context to ensure that the latest values are available during the build process.",
|
|
197
|
-
"P\"2!\"/\"?#"
|
|
198
|
-
];
|
|
199
157
|
|
|
200
158
|
//#endregion
|
|
201
159
|
exports.extractEnvSchema = extractEnvSchema;
|
|
202
160
|
exports.getDefaultSecretsTypeDefinition = getDefaultSecretsTypeDefinition;
|
|
203
161
|
exports.getDefaultVarsTypeDefinition = getDefaultVarsTypeDefinition;
|
|
204
|
-
exports.
|
|
205
|
-
exports.resolveRuntimeTypeFile = resolveRuntimeTypeFile;
|
|
206
|
-
exports.writeActiveEnv = writeActiveEnv;
|
|
162
|
+
exports.resolveRuntimeTypeFile = resolveRuntimeTypeFile;
|
|
@@ -34,20 +34,6 @@ declare function getDefaultSecretsTypeDefinition<TContext extends UnresolvedCont
|
|
|
34
34
|
* @returns A promise that resolves when the schema has been extracted and stored in the plugin context.
|
|
35
35
|
*/
|
|
36
36
|
declare function extractEnvSchema<TContext extends EnvPluginContext>(context: TContext, options?: EnvPluginOptions): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Reads the active environment variables and secrets from the plugin context's cache and stores them in the plugin context for use during the build process. This function should be called during the plugin's `buildStart` hook to ensure that the active environment variables and secrets are available before the build process begins.
|
|
39
|
-
*
|
|
40
|
-
* @param context - The plugin context
|
|
41
|
-
* @returns A promise that resolves when the active environment variables and secrets have been read and stored in the plugin context.
|
|
42
|
-
*/
|
|
43
|
-
declare function readActiveEnv<TContext extends EnvPluginContext>(context: TContext): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Writes the active environment variables and secrets from the plugin context to the plugin context's cache for use during the build process. This function should be called whenever the active environment variables and secrets are updated in the plugin context to ensure that the latest values are available during the build process.
|
|
46
|
-
*
|
|
47
|
-
* @param context - The plugin context
|
|
48
|
-
* @returns A promise that resolves when the active environment variables and secrets have been written to the plugin context's cache.
|
|
49
|
-
*/
|
|
50
|
-
declare function writeActiveEnv<TContext extends EnvPluginContext>(context: TContext): Promise<void[]>;
|
|
51
37
|
//#endregion
|
|
52
|
-
export { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition,
|
|
38
|
+
export { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, resolveRuntimeTypeFile };
|
|
53
39
|
//# sourceMappingURL=schema.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.cts","names":[],"sources":["../../src/helpers/schema.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"schema.d.cts","names":[],"sources":["../../src/helpers/schema.ts"],"mappings":";;;;;;;AAwCA;;;;iBAAsB,sBAAA,kBACH,iBAAA,CAAA,CACjB,OAAA,EAAS,QAAA,GAAW,OAAA;;;;;;;iBAiBA,4BAAA,kBACH,iBAAA,CAAA,CACjB,OAAA,EAAS,QAAA,GAAW,OAAA,CAAQ,cAAA;;;AAnBD;AAiB7B;;iBAcsB,+BAAA,kBACH,iBAAA,CAAA,CACjB,OAAA,EAAS,QAAA,GAAW,OAAA,CAAQ,cAAA;;;;;;;;;;;iBAiBR,gBAAA,kBAAkC,gBAAA,CAAA,CACtD,OAAA,EAAS,QAAA,EACT,OAAA,GAAS,gBAAA,GACR,OAAA"}
|
|
@@ -34,20 +34,6 @@ declare function getDefaultSecretsTypeDefinition<TContext extends UnresolvedCont
|
|
|
34
34
|
* @returns A promise that resolves when the schema has been extracted and stored in the plugin context.
|
|
35
35
|
*/
|
|
36
36
|
declare function extractEnvSchema<TContext extends EnvPluginContext>(context: TContext, options?: EnvPluginOptions): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Reads the active environment variables and secrets from the plugin context's cache and stores them in the plugin context for use during the build process. This function should be called during the plugin's `buildStart` hook to ensure that the active environment variables and secrets are available before the build process begins.
|
|
39
|
-
*
|
|
40
|
-
* @param context - The plugin context
|
|
41
|
-
* @returns A promise that resolves when the active environment variables and secrets have been read and stored in the plugin context.
|
|
42
|
-
*/
|
|
43
|
-
declare function readActiveEnv<TContext extends EnvPluginContext>(context: TContext): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Writes the active environment variables and secrets from the plugin context to the plugin context's cache for use during the build process. This function should be called whenever the active environment variables and secrets are updated in the plugin context to ensure that the latest values are available during the build process.
|
|
46
|
-
*
|
|
47
|
-
* @param context - The plugin context
|
|
48
|
-
* @returns A promise that resolves when the active environment variables and secrets have been written to the plugin context's cache.
|
|
49
|
-
*/
|
|
50
|
-
declare function writeActiveEnv<TContext extends EnvPluginContext>(context: TContext): Promise<void[]>;
|
|
51
37
|
//#endregion
|
|
52
|
-
export { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition,
|
|
38
|
+
export { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, resolveRuntimeTypeFile };
|
|
53
39
|
//# sourceMappingURL=schema.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.mts","names":[],"sources":["../../src/helpers/schema.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"schema.d.mts","names":[],"sources":["../../src/helpers/schema.ts"],"mappings":";;;;;;;AAwCA;;;;iBAAsB,sBAAA,kBACH,iBAAA,CAAA,CACjB,OAAA,EAAS,QAAA,GAAW,OAAA;;;;;;;iBAiBA,4BAAA,kBACH,iBAAA,CAAA,CACjB,OAAA,EAAS,QAAA,GAAW,OAAA,CAAQ,cAAA;;;AAnBD;AAiB7B;;iBAcsB,+BAAA,kBACH,iBAAA,CAAA,CACjB,OAAA,EAAS,QAAA,GAAW,OAAA,CAAQ,cAAA;;;;;;;;;;;iBAiBR,gBAAA,kBAAkC,gBAAA,CAAA,CACtD,OAAA,EAAS,QAAA,EACT,OAAA,GAAS,gBAAA,GACR,OAAA"}
|
package/dist/helpers/schema.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import { loadEnv } from "./load.mjs";
|
|
|
3
3
|
import { isString } from "@stryke/type-checks/is-string";
|
|
4
4
|
import { extract } from "@powerlines/schema/extract";
|
|
5
5
|
import { getProperties, mergeSchemas } from "@powerlines/schema/helpers";
|
|
6
|
-
import { joinPaths } from "@stryke/path/join";
|
|
7
6
|
import { isSetArray } from "@stryke/type-checks/is-set-array";
|
|
8
7
|
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
9
8
|
import defu from "defu";
|
|
@@ -152,48 +151,7 @@ extractEnvSchema.__type = [
|
|
|
152
151
|
"Extracts the environment variables and secrets schema from the provided type definitions in the plugin options, merges them with the default environment variables and secrets schema, and stores the resulting schema in the plugin context for later use during the build process.",
|
|
153
152
|
"P\"2!n\"2#>$$`/%?&"
|
|
154
153
|
];
|
|
155
|
-
/**
|
|
156
|
-
* Reads the active environment variables and secrets from the plugin context's cache and stores them in the plugin context for use during the build process. This function should be called during the plugin's `buildStart` hook to ensure that the active environment variables and secrets are available before the build process begins.
|
|
157
|
-
*
|
|
158
|
-
* @param context - The plugin context
|
|
159
|
-
* @returns A promise that resolves when the active environment variables and secrets have been read and stored in the plugin context.
|
|
160
|
-
*/
|
|
161
|
-
async function readActiveEnv(context) {
|
|
162
|
-
context.env.vars.schema.metadata ??= {};
|
|
163
|
-
context.env.vars.schema.metadata.active ??= [];
|
|
164
|
-
if (context.fs.existsSync(joinPaths(context.cachePath, "env", "vars.json"))) {
|
|
165
|
-
const content = await context.fs.read(joinPaths(context.cachePath, "env", "vars.json"));
|
|
166
|
-
if (content) context.env.vars.schema.metadata.active = JSON.parse(content)?.elements ?? [];
|
|
167
|
-
}
|
|
168
|
-
context.env.secrets.schema.metadata ??= {};
|
|
169
|
-
context.env.secrets.schema.metadata.active ??= [];
|
|
170
|
-
if (context.fs.existsSync(joinPaths(context.cachePath, "env", "secrets.json"))) {
|
|
171
|
-
const content = await context.fs.read(joinPaths(context.cachePath, "env", "secrets.json"));
|
|
172
|
-
if (content) context.env.secrets.schema.metadata.active = JSON.parse(content)?.elements ?? [];
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
readActiveEnv.__type = [
|
|
176
|
-
"context",
|
|
177
|
-
"readActiveEnv",
|
|
178
|
-
"Reads the active environment variables and secrets from the plugin context's cache and stores them in the plugin context for use during the build process. This function should be called during the plugin's `buildStart` hook to ensure that the active environment variables and secrets are available before the build process begins.",
|
|
179
|
-
"P\"2!\"/\"?#"
|
|
180
|
-
];
|
|
181
|
-
/**
|
|
182
|
-
* Writes the active environment variables and secrets from the plugin context to the plugin context's cache for use during the build process. This function should be called whenever the active environment variables and secrets are updated in the plugin context to ensure that the latest values are available during the build process.
|
|
183
|
-
*
|
|
184
|
-
* @param context - The plugin context
|
|
185
|
-
* @returns A promise that resolves when the active environment variables and secrets have been written to the plugin context's cache.
|
|
186
|
-
*/
|
|
187
|
-
async function writeActiveEnv(context) {
|
|
188
|
-
return Promise.all([isSetArray(context.env.vars.schema.metadata?.active) ? context.fs.write(joinPaths(context.cachePath, "env", "vars.json"), JSON.stringify({ elements: context.env.vars.schema.metadata.active })) : void 0, isSetArray(context.env.secrets.schema.metadata?.active) ? context.fs.write(joinPaths(context.cachePath, "env", "secrets.json"), JSON.stringify({ elements: context.env.secrets.schema.metadata.active })) : void 0].filter(Boolean));
|
|
189
|
-
}
|
|
190
|
-
writeActiveEnv.__type = [
|
|
191
|
-
"context",
|
|
192
|
-
"writeActiveEnv",
|
|
193
|
-
"Writes the active environment variables and secrets from the plugin context to the plugin context's cache for use during the build process. This function should be called whenever the active environment variables and secrets are updated in the plugin context to ensure that the latest values are available during the build process.",
|
|
194
|
-
"P\"2!\"/\"?#"
|
|
195
|
-
];
|
|
196
154
|
|
|
197
155
|
//#endregion
|
|
198
|
-
export { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition,
|
|
156
|
+
export { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition, resolveRuntimeTypeFile };
|
|
199
157
|
//# sourceMappingURL=schema.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","names":[],"sources":["../../src/helpers/schema.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { ObjectSchema } from \"@powerlines/schema\";\nimport { extract } from \"@powerlines/schema/extract\";\nimport { getProperties, mergeSchemas } from \"@powerlines/schema/helpers\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport type { TypeDefinition } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { UnresolvedContext } from \"powerlines\";\nimport {\n EnvPluginContext,\n EnvPluginOptions,\n EnvSchemaMetadata\n} from \"../types/plugin\";\nimport { loadEnv } from \"./load\";\n\n/**\n * Resolves the runtime type definition file for the environment variables.\n *\n * @param context - The plugin context.\n * @returns The runtime type definition file for the environment variables.\n */\nexport async function resolveRuntimeTypeFile<\n TContext extends UnresolvedContext\n>(context: TContext): Promise<string> {\n const resolved = await context.fs.resolve(\"@powerlines/plugin-env/types/env\");\n if (!resolved) {\n throw new Error(\n `Failed to resolve the runtime type definition file for the environment variables. Please ensure that the \"@powerlines/plugin-env\" package is installed.`\n );\n }\n\n return resolved;\n}\n\n/**\n * Gets the default type definition for the environment variables.\n *\n * @param context - The plugin context.\n * @returns The default type definition for the environment variables.\n */\nexport async function getDefaultVarsTypeDefinition<\n TContext extends UnresolvedContext\n>(context: TContext): Promise<TypeDefinition> {\n return {\n file: await resolveRuntimeTypeFile(context),\n name: \"EnvInterface\"\n };\n}\n\n/** Gets the default type definition for the environment secrets.\n *\n * @param context - The plugin context.\n * @returns The default type definition for the environment secrets.\n */\nexport async function getDefaultSecretsTypeDefinition<\n TContext extends UnresolvedContext\n>(context: TContext): Promise<TypeDefinition> {\n return {\n file: await resolveRuntimeTypeFile(context),\n name: \"SecretsInterface\"\n };\n}\n\n/**\n * Extracts the environment variables and secrets schema from the provided type definitions in the plugin options, merges them with the default environment variables and secrets schema, and stores the resulting schema in the plugin context for later use during the build process.\n *\n * @remarks\n * This function should be called during the plugin's `config` hook to ensure that the environment variables and secrets schema is available in the plugin context before the build process begins. The resulting schema will be used to validate the loaded environment variables and secrets, as well as to provide type information for the injected environment variables and secrets during the build process.\n *\n * @param context - The plugin context\n * @param options - The plugin options containing the environment variables and secrets type definitions to extract the schema from. If not provided, the default type definitions will be used.\n * @returns A promise that resolves when the schema has been extracted and stored in the plugin context.\n */\nexport async function extractEnvSchema<TContext extends EnvPluginContext>(\n context: TContext,\n options: EnvPluginOptions = {}\n): Promise<void> {\n const defaultVarsTypeDefinition = await getDefaultVarsTypeDefinition(context);\n const defaultSecretsTypeDefinition =\n await getDefaultSecretsTypeDefinition(context);\n\n const vars = (await extract(\n context,\n context.config.env.vars\n )) as ObjectSchema<EnvSchemaMetadata>;\n if (\n (isString(context.config.env.vars) &&\n context.config.env.vars !==\n `${defaultVarsTypeDefinition.file}#${defaultVarsTypeDefinition.name}`) ||\n (isSetObject(context.config.env.vars) &&\n ((context.config.env.vars as TypeDefinition).file !==\n defaultVarsTypeDefinition.file ||\n (context.config.env.vars as TypeDefinition).name !==\n defaultVarsTypeDefinition.name))\n ) {\n vars.schema = mergeSchemas(\n vars,\n (await extract(\n context,\n defaultVarsTypeDefinition\n )) as ObjectSchema<EnvSchemaMetadata>\n );\n }\n\n const secrets = (await extract(\n context,\n context.config.env.secrets\n )) as ObjectSchema<EnvSchemaMetadata>;\n if (\n (isString(context.config.env.secrets) &&\n context.config.env.secrets !==\n `${defaultSecretsTypeDefinition.file}#${defaultSecretsTypeDefinition.name}`) ||\n (isSetObject(context.config.env.secrets) &&\n ((context.config.env.secrets as TypeDefinition).file !==\n defaultSecretsTypeDefinition.file ||\n (context.config.env.secrets as TypeDefinition).name !==\n defaultSecretsTypeDefinition.name))\n ) {\n secrets.schema = mergeSchemas(\n secrets,\n (await extract(\n context,\n defaultSecretsTypeDefinition\n )) as ObjectSchema<EnvSchemaMetadata>\n );\n }\n\n context.env = defu(\n {\n vars,\n secrets,\n parsed: await loadEnv(context, context.config.env)\n },\n context.env ?? {},\n {\n parsed: {},\n injected: []\n }\n );\n\n const properties = getProperties(context.env.vars);\n context.info({\n meta: {\n category: \"env\"\n },\n message: `Environment Variables configuration: ${\n options.vars ? \"\" : \"Defaulted \"\n }${\n context.env.vars.variant === \"reflection\"\n ? \"Deepkit type definition\"\n : context.env.vars.variant === \"json-schema\"\n ? \"JSON Schema\"\n : context.env.vars.variant === \"standard-schema\"\n ? \"Standard Schema\"\n : context.env.vars.variant === \"zod3\"\n ? \"Zod v3 schema\"\n : \"Typescript exported type\"\n }${options.vars ? \" from plugin options\" : \"\"} provided ${\n Object.keys(properties).length\n } parameters\\nEnvironment Secret configuration: ${\n options.secrets ? \"\" : \"Defaulted \"\n }${\n context.env.secrets.variant === \"reflection\"\n ? \"Deepkit type definition\"\n : context.env.secrets.variant === \"json-schema\"\n ? \"JSON Schema\"\n : context.env.secrets.variant === \"standard-schema\"\n ? \"Standard Schema\"\n : context.env.secrets.variant === \"zod3\"\n ? \"Zod v3 schema\"\n : \"Typescript exported type\"\n }${options.secrets ? \" from plugin options\" : \"\"} provided ${\n context.env.secrets?.schema\n ? Object.keys(getProperties(context.env.secrets)).length\n : \"0\"\n } parameters\\nEnvironment variable Prefixes: ${context.config.env.prefix.join(\n \", \"\n )}\\nShould inject values: ${\n context.config.env.inject ? \"Yes\" : \"No\"\n }\\nShould validate configuration: ${\n context.config.env.validate ? \"Yes\" : \"No\"\n }`\n });\n\n const aliases = Object.fromEntries(\n Object.entries(properties).flatMap(\n ([key, prop]) =>\n (isSetArray(prop.metadata?.alias)\n ? prop.metadata?.alias?.map(alias => [\n alias,\n { ...prop, metadata: { ...prop.metadata, alias: [key] } }\n ])\n : []) as [string, typeof prop][]\n )\n );\n\n for (const [key, value] of Object.entries(\n await loadEnv(context, context.config.env)\n )) {\n const unprefixedKey = context.config.env.prefix.reduce((ret, prefix) => {\n if (key.replace(/_$/g, \"\").startsWith(prefix)) {\n return key.replace(/_$/g, \"\").slice(prefix.length);\n }\n return ret;\n }, key);\n if (properties[unprefixedKey]) {\n if (!properties[unprefixedKey].metadata?.isRuntime) {\n if (\n properties[unprefixedKey].optional &&\n context.env.vars.schema.optionalProperties?.[unprefixedKey]\n ) {\n context.env.vars.schema.optionalProperties[unprefixedKey].metadata ??=\n {} as EnvSchemaMetadata;\n context.env.vars.schema.optionalProperties[\n unprefixedKey\n ].metadata.default = value;\n } else if (context.env.vars.schema.properties?.[unprefixedKey]) {\n context.env.vars.schema.properties[unprefixedKey].metadata ??=\n {} as EnvSchemaMetadata;\n context.env.vars.schema.properties[unprefixedKey].metadata.default =\n value;\n }\n }\n } else if (aliases[unprefixedKey]) {\n if (!aliases[unprefixedKey].metadata?.isRuntime) {\n const alias =\n aliases[unprefixedKey].metadata?.alias?.[0] ?? unprefixedKey;\n if (\n aliases[unprefixedKey].optional &&\n context.env.vars.schema.optionalProperties?.[alias]\n ) {\n context.env.vars.schema.optionalProperties[alias].metadata ??=\n {} as EnvSchemaMetadata;\n context.env.vars.schema.optionalProperties[alias].metadata.default =\n value;\n } else if (context.env.vars.schema.properties?.[alias]) {\n context.env.vars.schema.properties[alias].metadata ??=\n {} as EnvSchemaMetadata;\n context.env.vars.schema.properties[alias].metadata.default = value;\n }\n }\n }\n }\n}\n\n/**\n * Reads the active environment variables and secrets from the plugin context's cache and stores them in the plugin context for use during the build process. This function should be called during the plugin's `buildStart` hook to ensure that the active environment variables and secrets are available before the build process begins.\n *\n * @param context - The plugin context\n * @returns A promise that resolves when the active environment variables and secrets have been read and stored in the plugin context.\n */\nexport async function readActiveEnv<TContext extends EnvPluginContext>(\n context: TContext\n) {\n context.env.vars.schema.metadata ??= {} as EnvSchemaMetadata;\n context.env.vars.schema.metadata.active ??= [];\n if (context.fs.existsSync(joinPaths(context.cachePath, \"env\", \"vars.json\"))) {\n const content = await context.fs.read(\n joinPaths(context.cachePath, \"env\", \"vars.json\")\n );\n if (content) {\n context.env.vars.schema.metadata.active =\n JSON.parse(content)?.elements ?? [];\n }\n }\n\n context.env.secrets.schema.metadata ??= {} as EnvSchemaMetadata;\n context.env.secrets.schema.metadata.active ??= [];\n if (\n context.fs.existsSync(joinPaths(context.cachePath, \"env\", \"secrets.json\"))\n ) {\n const content = await context.fs.read(\n joinPaths(context.cachePath, \"env\", \"secrets.json\")\n );\n if (content) {\n context.env.secrets.schema.metadata.active =\n JSON.parse(content)?.elements ?? [];\n }\n }\n}\n\n/**\n * Writes the active environment variables and secrets from the plugin context to the plugin context's cache for use during the build process. This function should be called whenever the active environment variables and secrets are updated in the plugin context to ensure that the latest values are available during the build process.\n *\n * @param context - The plugin context\n * @returns A promise that resolves when the active environment variables and secrets have been written to the plugin context's cache.\n */\nexport async function writeActiveEnv<TContext extends EnvPluginContext>(\n context: TContext\n) {\n return Promise.all(\n [\n isSetArray(context.env.vars.schema.metadata?.active)\n ? context.fs.write(\n joinPaths(context.cachePath, \"env\", \"vars.json\"),\n JSON.stringify({\n elements: context.env.vars.schema.metadata!.active\n })\n )\n : undefined,\n isSetArray(context.env.secrets.schema.metadata?.active)\n ? context.fs.write(\n joinPaths(context.cachePath, \"env\", \"secrets.json\"),\n JSON.stringify({\n elements: context.env.secrets.schema.metadata!.active\n })\n )\n : undefined\n ].filter(Boolean) as Promise<void>[]\n );\n}\n"],"mappings":";;;;;;;;;;;AAEA,SAAS,aAAY,IAAK,MAAC;;CAE1B,OAAK;AACN;;;;;;;AAeA,eAAsB,uBAAuB,SAAC;CAC9C,MAAQ,WAAW,MAAM,QAAG,GAAO,QAAS,kCAAC;CAC7C,IAAM,CAAC,UACP,MAAS,IAAA,MAAW,yJAA2C;CAE/D,OAAO;AACP;AACA,uBAAS,SAAoB;CAAI;CAAE;CAAW;CAAA;AAAA;;;;;;;;CAQ5C,OAAA;EACC,MAAA,MAAa,uBAAuB,OAAM;EAC5C,MAAA;CACC;AACF;AACA,6BAAE,SAAA;CAAA;CAAA;CAAA;CAAA;AAAA;;;;;;AAMF,eAAmB,gCAAA,SAAA;CACjB,OAAK;EACH,MAAC,MAAA,uBAAA,OAAA;EACH,MAAA;;AAEF;AACA,gCAAA,SAAA;CAAA;CAAA;CAAA;AAAA;;;;;;;;;;;AAWA,eAAS,iBAAA,SAAA,UAAA,CAAA,GAAA;CACP,MAAM,4BAAQ,MAAuB,6BAAQ,OAAA;CAC7C,MAAM,+BAAe,MAAA,gCAAA,OAAA;CACrB,MAAC,OAAA,MAAA,QAAA,SAAA,QAAA,OAAA,IAAA,IAAA;CACH,IAAA,SAAA,QAAA,OAAA,IAAA,IAAA,KAAA,QAAA,OAAA,IAAA,SAAA,GAAA,0BAAA,KAAA,GAAA,0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AAA;CAEF;AACF;AACA,cAAK,SAAA;CAAA;CAAA;CAAA;CAAA;AAAA;;;;;;;;CAQH,OAAM,QAAA,IAAa,CAAA,WAAA,QAAc,IAAQ,KAAI,OAAK,UAAA,MAAA,IAAA,QAAA,GAAA,MAAA,UAAA,QAAA,WAAA,OAAA,WAAA,GAAA,KAAA,UAAA,EAClD,UAAY,QAAC,IAAA,KAAA,OAAA,SAAA,OACb,CAAC,CAAC,IAAI,QAAE,WAAA,QAAA,IAAA,QAAA,OAAA,UAAA,MAAA,IAAA,QAAA,GAAA,MAAA,UAAA,QAAA,WAAA,OAAA,cAAA,GAAA,KAAA,UAAA,EACN,UAAU,QAAM,IAAA,QAAA,OAAA,SAAA,OAClB,CAAC,CAAC,IAAC,MAAA,EAAA,OAAA,OAAA,CAAA;AACL;AACA,eAAc,SAAU;CAAC;CAAW;CAAC;CAAA;AAAA"}
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":[],"sources":["../../src/helpers/schema.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { ObjectSchema } from \"@powerlines/schema\";\nimport { extract } from \"@powerlines/schema/extract\";\nimport { getProperties, mergeSchemas } from \"@powerlines/schema/helpers\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport type { TypeDefinition } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { UnresolvedContext } from \"powerlines\";\nimport {\n EnvPluginContext,\n EnvPluginOptions,\n EnvSchemaMetadata\n} from \"../types/plugin\";\nimport { loadEnv } from \"./load\";\n\n/**\n * Resolves the runtime type definition file for the environment variables.\n *\n * @param context - The plugin context.\n * @returns The runtime type definition file for the environment variables.\n */\nexport async function resolveRuntimeTypeFile<\n TContext extends UnresolvedContext\n>(context: TContext): Promise<string> {\n const resolved = await context.fs.resolve(\"@powerlines/plugin-env/types/env\");\n if (!resolved) {\n throw new Error(\n `Failed to resolve the runtime type definition file for the environment variables. Please ensure that the \"@powerlines/plugin-env\" package is installed.`\n );\n }\n\n return resolved;\n}\n\n/**\n * Gets the default type definition for the environment variables.\n *\n * @param context - The plugin context.\n * @returns The default type definition for the environment variables.\n */\nexport async function getDefaultVarsTypeDefinition<\n TContext extends UnresolvedContext\n>(context: TContext): Promise<TypeDefinition> {\n return {\n file: await resolveRuntimeTypeFile(context),\n name: \"EnvInterface\"\n };\n}\n\n/** Gets the default type definition for the environment secrets.\n *\n * @param context - The plugin context.\n * @returns The default type definition for the environment secrets.\n */\nexport async function getDefaultSecretsTypeDefinition<\n TContext extends UnresolvedContext\n>(context: TContext): Promise<TypeDefinition> {\n return {\n file: await resolveRuntimeTypeFile(context),\n name: \"SecretsInterface\"\n };\n}\n\n/**\n * Extracts the environment variables and secrets schema from the provided type definitions in the plugin options, merges them with the default environment variables and secrets schema, and stores the resulting schema in the plugin context for later use during the build process.\n *\n * @remarks\n * This function should be called during the plugin's `config` hook to ensure that the environment variables and secrets schema is available in the plugin context before the build process begins. The resulting schema will be used to validate the loaded environment variables and secrets, as well as to provide type information for the injected environment variables and secrets during the build process.\n *\n * @param context - The plugin context\n * @param options - The plugin options containing the environment variables and secrets type definitions to extract the schema from. If not provided, the default type definitions will be used.\n * @returns A promise that resolves when the schema has been extracted and stored in the plugin context.\n */\nexport async function extractEnvSchema<TContext extends EnvPluginContext>(\n context: TContext,\n options: EnvPluginOptions = {}\n): Promise<void> {\n const defaultVarsTypeDefinition = await getDefaultVarsTypeDefinition(context);\n const defaultSecretsTypeDefinition =\n await getDefaultSecretsTypeDefinition(context);\n\n const vars = (await extract(\n context,\n context.config.env.vars\n )) as ObjectSchema<EnvSchemaMetadata>;\n if (\n (isString(context.config.env.vars) &&\n context.config.env.vars !==\n `${defaultVarsTypeDefinition.file}#${\n defaultVarsTypeDefinition.name\n }`) ||\n (isSetObject(context.config.env.vars) &&\n ((context.config.env.vars as TypeDefinition).file !==\n defaultVarsTypeDefinition.file ||\n (context.config.env.vars as TypeDefinition).name !==\n defaultVarsTypeDefinition.name))\n ) {\n vars.schema = mergeSchemas(\n vars,\n (await extract(\n context,\n defaultVarsTypeDefinition\n )) as ObjectSchema<EnvSchemaMetadata>\n );\n }\n\n const secrets = (await extract(\n context,\n context.config.env.secrets\n )) as ObjectSchema<EnvSchemaMetadata>;\n if (\n (isString(context.config.env.secrets) &&\n context.config.env.secrets !==\n `${defaultSecretsTypeDefinition.file}#${\n defaultSecretsTypeDefinition.name\n }`) ||\n (isSetObject(context.config.env.secrets) &&\n ((context.config.env.secrets as TypeDefinition).file !==\n defaultSecretsTypeDefinition.file ||\n (context.config.env.secrets as TypeDefinition).name !==\n defaultSecretsTypeDefinition.name))\n ) {\n secrets.schema = mergeSchemas(\n secrets,\n (await extract(\n context,\n defaultSecretsTypeDefinition\n )) as ObjectSchema<EnvSchemaMetadata>\n );\n }\n\n context.env = defu(\n {\n vars,\n secrets,\n parsed: await loadEnv(context, context.config.env)\n },\n context.env ?? {},\n {\n parsed: {},\n injected: []\n }\n );\n\n const properties = getProperties(context.env.vars);\n context.info({\n meta: {\n category: \"env\"\n },\n message: `Environment Variables configuration: ${\n options.vars ? \"\" : \"Defaulted \"\n }${\n context.env.vars.variant === \"reflection\"\n ? \"Deepkit type definition\"\n : context.env.vars.variant === \"json-schema\"\n ? \"JSON Schema\"\n : context.env.vars.variant === \"standard-schema\"\n ? \"Standard Schema\"\n : context.env.vars.variant === \"zod3\"\n ? \"Zod v3 schema\"\n : \"Typescript exported type\"\n }${options.vars ? \" from plugin options\" : \"\"} provided ${\n Object.keys(properties).length\n } parameters\\nEnvironment Secret configuration: ${\n options.secrets ? \"\" : \"Defaulted \"\n }${\n context.env.secrets.variant === \"reflection\"\n ? \"Deepkit type definition\"\n : context.env.secrets.variant === \"json-schema\"\n ? \"JSON Schema\"\n : context.env.secrets.variant === \"standard-schema\"\n ? \"Standard Schema\"\n : context.env.secrets.variant === \"zod3\"\n ? \"Zod v3 schema\"\n : \"Typescript exported type\"\n }${options.secrets ? \" from plugin options\" : \"\"} provided ${\n context.env.secrets?.schema\n ? Object.keys(getProperties(context.env.secrets)).length\n : \"0\"\n } parameters\\nEnvironment variable Prefixes: ${context.config.env.prefix.join(\n \", \"\n )}\\nShould inject values: ${\n context.config.env.inject ? \"Yes\" : \"No\"\n }\\nShould validate configuration: ${\n context.config.env.validate ? \"Yes\" : \"No\"\n }`\n });\n\n const aliases = Object.fromEntries(\n Object.entries(properties).flatMap(\n ([key, prop]) =>\n (isSetArray(prop.metadata?.alias)\n ? prop.metadata?.alias?.map(alias => [\n alias,\n { ...prop, metadata: { ...prop.metadata, alias: [key] } }\n ])\n : []) as [string, typeof prop][]\n )\n );\n\n for (const [key, value] of Object.entries(\n await loadEnv(context, context.config.env)\n )) {\n const unprefixedKey = context.config.env.prefix.reduce((ret, prefix) => {\n if (key.replace(/_$/g, \"\").startsWith(prefix)) {\n return key.replace(/_$/g, \"\").slice(prefix.length);\n }\n return ret;\n }, key);\n if (properties[unprefixedKey]) {\n if (!properties[unprefixedKey].metadata?.isRuntime) {\n if (\n properties[unprefixedKey].optional &&\n context.env.vars.schema.optionalProperties?.[unprefixedKey]\n ) {\n context.env.vars.schema.optionalProperties[unprefixedKey].metadata ??=\n {} as EnvSchemaMetadata;\n context.env.vars.schema.optionalProperties[\n unprefixedKey\n ].metadata.default = value;\n } else if (context.env.vars.schema.properties?.[unprefixedKey]) {\n context.env.vars.schema.properties[unprefixedKey].metadata ??=\n {} as EnvSchemaMetadata;\n context.env.vars.schema.properties[unprefixedKey].metadata.default =\n value;\n }\n }\n } else if (aliases[unprefixedKey]) {\n if (!aliases[unprefixedKey].metadata?.isRuntime) {\n const alias =\n aliases[unprefixedKey].metadata?.alias?.[0] ?? unprefixedKey;\n if (\n aliases[unprefixedKey].optional &&\n context.env.vars.schema.optionalProperties?.[alias]\n ) {\n context.env.vars.schema.optionalProperties[alias].metadata ??=\n {} as EnvSchemaMetadata;\n context.env.vars.schema.optionalProperties[alias].metadata.default =\n value;\n } else if (context.env.vars.schema.properties?.[alias]) {\n context.env.vars.schema.properties[alias].metadata ??=\n {} as EnvSchemaMetadata;\n context.env.vars.schema.properties[alias].metadata.default = value;\n }\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAEA,SAAS,aAAY,IAAK,MAAC;;CAE1B,OAAK;AACN;;;;;;;AAcA,eAAmB,uBAAyB,SAAQ;CACpD,MAAQ,WAAC,MAAe,QAAA,GAAY,QAAQ,kCAA4B;CACxE,IAAM,CAAC,UACP,MAAS,IAAA,MAAW,yJAA2C;CAE/D,OAAO;AACP;AACA,uBAAS,SAAoB;CAAI;CAAE;CAAW;CAAA;AAAA;;;;;;;;CAQ5C,OAAA;EACC,MAAA,MAAa,uBAAuB,OAAM;EAC5C,MAAA;CACC;AACF;AACA,6BAAE,SAAA;CAAA;CAAA;CAAA;CAAA;AAAA;;;;;;AAMF,eAAmB,gCAAA,SAAA;CACjB,OAAK;EACH,MAAC,MAAA,uBAAA,OAAA;EACH,MAAA;;AAEF;AACA,gCAAA,SAAA;CAAA;CAAA;CAAA;AAAA;;;;;;;;;;;AAWA,eAAS,iBAAA,SAAA,UAAA,CAAA,GAAA;CACP,MAAM,4BAAQ,MAAuB,6BAAQ,OAAA;CAC7C,MAAM,+BAAe,MAAA,gCAAA,OAAA;CACrB,MAAC,OAAA,MAAA,QAAA,SAAA,QAAA,OAAA,IAAA,IAAA;CACH,IAAA,SAAA,QAAA,OAAA,IAAA,IAAA,KAAA,QAAA,OAAA,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AA,KAAA,OAAA,WAA0B,eAAA,aAAA,CAAA;KAC1B,QAAG,IAAA,KAAA,OAAA,WAAA,eAAA,SAAA,UAAA;IACR;;EACC,OACE,IAAA,QAAA,gBACF;OAAG,CAAA,QAAQ,eAAgB,UAAG,WAAgB;IAC5C,MAAE,QAAA,QAAA,eAA+B,UAAA,QAAA,MAAA;IACrC,IAAA,QAAA,eAAA,YAAA,QAAA,IAAA,KAAA,OAAA,qBAAA,QAAA;KACK,QAAS,IAAA,KAAA,OAAY,mBAAA,OAAA,aAAA,CAAA;KACpB,QAAA,IAAA,KAAA,OAAA,mBAAA,OAAA,SAAA,UAAA;IACH,OAAM,IAAA,QAAO,IAAA,KAAA,OAAA,aAAA,QAAA;KACZ,QAAO,IAAA,KAAA,OAAA,WAAA,OAAA,aAAA,CAAA;KACP,QAAA,IAAA,KAAA,OAAA,WAAA,OAAA,SAAA,UAAA;IACA;GACH;;;AAGL;AACA,iBAAW,SAAA;CAAA;OAAA;CAAA;QAAA,CAAA;CAAA;CAAA;CAAA;AAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -7,17 +7,18 @@ const require_helpers_automd_generator = require('./helpers/automd-generator.cjs
|
|
|
7
7
|
const require_components_docs = require('./components/docs.cjs');
|
|
8
8
|
const require_components_env_builtin = require('./components/env-builtin.cjs');
|
|
9
9
|
const require_babel_plugin = require('./babel/plugin.cjs');
|
|
10
|
-
let _stryke_path_join = require("@stryke/path/join");
|
|
11
10
|
let defu = require("defu");
|
|
12
11
|
defu = require_runtime.__toESM(defu);
|
|
13
12
|
let powerlines_plugin_utils = require("powerlines/plugin-utils");
|
|
14
13
|
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
14
|
+
let _stryke_path_join = require("@stryke/path/join");
|
|
15
15
|
let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
16
16
|
let _powerlines_plugin_alloy_render = require("@powerlines/plugin-alloy/render");
|
|
17
17
|
let _powerlines_plugin_automd = require("@powerlines/plugin-automd");
|
|
18
18
|
_powerlines_plugin_automd = require_runtime.__toESM(_powerlines_plugin_automd);
|
|
19
19
|
let _powerlines_plugin_babel = require("@powerlines/plugin-babel");
|
|
20
20
|
_powerlines_plugin_babel = require_runtime.__toESM(_powerlines_plugin_babel);
|
|
21
|
+
let _powerlines_schema_persistence = require("@powerlines/schema/persistence");
|
|
21
22
|
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
22
23
|
let _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
|
|
23
24
|
|
|
@@ -81,19 +82,17 @@ const plugin = __assignType((options = {}) => {
|
|
|
81
82
|
prepare: __assignType(async function prepare() {
|
|
82
83
|
const _self$ = this;
|
|
83
84
|
this.debug(`Preparing the Environment runtime artifacts for the Powerlines project.`);
|
|
84
|
-
await require_helpers_schema.readActiveEnv(this);
|
|
85
85
|
return (0, _powerlines_plugin_alloy_render.render)(this, (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_env_builtin.EnvBuiltin, { get defaultConfig() {
|
|
86
86
|
return _self$.config.env.defaultConfig;
|
|
87
87
|
} }));
|
|
88
88
|
}, ["prepare", "P\"/!"]),
|
|
89
89
|
docs: __assignType(async function docs() {
|
|
90
90
|
this.debug(`Documenting environment variables configuration values in "${(0, _stryke_path_join.joinPaths)((0, powerlines_plugin_utils.getDocsOutputPath)(this.config.root), "env.md")}"`);
|
|
91
|
-
await require_helpers_schema.readActiveEnv(this);
|
|
92
91
|
return (0, _powerlines_plugin_alloy_render.render)(this, (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_docs.EnvDocsFile, { levelOffset: 0 }));
|
|
93
92
|
}, ["docs", "P\"/!"]),
|
|
94
93
|
buildEnd: __assignType(async function buildEnd() {
|
|
95
94
|
this.debug("Writing active environment variables to disk.");
|
|
96
|
-
await
|
|
95
|
+
await (0, _powerlines_schema_persistence.writeSchema)(this, this.env.vars);
|
|
97
96
|
}, ["buildEnd", "P\"/!"])
|
|
98
97
|
},
|
|
99
98
|
{
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;YA4CY,MAAA;IACR,GAAA,GAAM,gBAAgB;EAAA;AAAA;;;;cAOb,MAAA,oBAA2B,gBAAA,GAAmB,gBAAA,EACzD,OAAA,GAAS,gBAAA,KA8HJ,MAAA,CAAO,QAAA"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;YA4CY,MAAA;IACR,GAAA,GAAM,gBAAgB;EAAA;AAAA;;;;cAOb,MAAA,oBAA2B,gBAAA,GAAmB,gBAAA,EACzD,OAAA,GAAS,gBAAA,KA8HJ,MAAA,CAAO,QAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { __ΩEnvPluginContext, __ΩEnvPluginOptions, __ΩEnvPluginResolvedConfig, __ΩEnvPluginUserConfig, __ΩEnvSchemaMetadata, __ΩEnvType } from "./types/plugin.mjs";
|
|
2
2
|
import { __ΩEnvInterface, __ΩSecretsInterface } from "./types/env.mjs";
|
|
3
|
-
import { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition
|
|
3
|
+
import { extractEnvSchema, getDefaultSecretsTypeDefinition, getDefaultVarsTypeDefinition } from "./helpers/schema.mjs";
|
|
4
4
|
import { env } from "./helpers/automd-generator.mjs";
|
|
5
5
|
import { EnvDocsFile } from "./components/docs.mjs";
|
|
6
6
|
import { EnvBuiltin } from "./components/env-builtin.mjs";
|
|
7
7
|
import { envBabelPlugin } from "./babel/plugin.mjs";
|
|
8
|
-
import { joinPaths } from "@stryke/path/join";
|
|
9
8
|
import defu from "defu";
|
|
10
9
|
import { getDocsOutputPath } from "powerlines/plugin-utils";
|
|
11
10
|
import { createComponent } from "@alloy-js/core/jsx-runtime";
|
|
11
|
+
import { joinPaths } from "@stryke/path/join";
|
|
12
12
|
import { getUnique } from "@stryke/helpers/get-unique";
|
|
13
13
|
import { render } from "@powerlines/plugin-alloy/render";
|
|
14
14
|
import automd from "@powerlines/plugin-automd";
|
|
15
15
|
import babel from "@powerlines/plugin-babel";
|
|
16
|
+
import { writeSchema } from "@powerlines/schema/persistence";
|
|
16
17
|
import { toArray } from "@stryke/convert/to-array";
|
|
17
18
|
import { constantCase } from "@stryke/string-format/constant-case";
|
|
18
19
|
|
|
@@ -76,19 +77,17 @@ const plugin = __assignType((options = {}) => {
|
|
|
76
77
|
prepare: __assignType(async function prepare() {
|
|
77
78
|
const _self$ = this;
|
|
78
79
|
this.debug(`Preparing the Environment runtime artifacts for the Powerlines project.`);
|
|
79
|
-
await readActiveEnv(this);
|
|
80
80
|
return render(this, createComponent(EnvBuiltin, { get defaultConfig() {
|
|
81
81
|
return _self$.config.env.defaultConfig;
|
|
82
82
|
} }));
|
|
83
83
|
}, ["prepare", "P\"/!"]),
|
|
84
84
|
docs: __assignType(async function docs() {
|
|
85
85
|
this.debug(`Documenting environment variables configuration values in "${joinPaths(getDocsOutputPath(this.config.root), "env.md")}"`);
|
|
86
|
-
await readActiveEnv(this);
|
|
87
86
|
return render(this, createComponent(EnvDocsFile, { levelOffset: 0 }));
|
|
88
87
|
}, ["docs", "P\"/!"]),
|
|
89
88
|
buildEnd: __assignType(async function buildEnd() {
|
|
90
89
|
this.debug("Writing active environment variables to disk.");
|
|
91
|
-
await
|
|
90
|
+
await writeSchema(this, this.env.vars);
|
|
92
91
|
}, ["buildEnd", "P\"/!"])
|
|
93
92
|
},
|
|
94
93
|
{
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport babel from \"@powerlines/plugin-babel\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport defu from \"defu\";\nimport type { Plugin, UnresolvedContext } from \"powerlines\";\nimport { getDocsOutputPath } from \"powerlines/plugin-utils\";\nimport type { UserConfig as ViteUserConfig } from \"vite\";\nimport { envBabelPlugin } from \"./babel/plugin\";\nimport { EnvDocsFile } from \"./components/docs\";\nimport { EnvBuiltin } from \"./components/env-builtin\";\nimport { env } from \"./helpers/automd-generator\";\nimport {\n extractEnvSchema,\n getDefaultSecretsTypeDefinition,\n getDefaultVarsTypeDefinition
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport babel from \"@powerlines/plugin-babel\";\nimport { writeSchema } from \"@powerlines/schema/persistence\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport defu from \"defu\";\nimport type { Plugin, UnresolvedContext } from \"powerlines\";\nimport { getDocsOutputPath } from \"powerlines/plugin-utils\";\nimport type { UserConfig as ViteUserConfig } from \"vite\";\nimport { envBabelPlugin } from \"./babel/plugin\";\nimport { EnvDocsFile } from \"./components/docs\";\nimport { EnvBuiltin } from \"./components/env-builtin\";\nimport { env } from \"./helpers/automd-generator\";\nimport {\n extractEnvSchema,\n getDefaultSecretsTypeDefinition,\n getDefaultVarsTypeDefinition\n} from \"./helpers/schema\";\nimport type { EnvPluginContext, EnvPluginOptions } from \"./types/plugin\";\n\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n env?: EnvPluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to inject environment variables into the source code.\n */\nexport const plugin = <TContext extends EnvPluginContext = EnvPluginContext>(\n options: EnvPluginOptions = {}\n) => {\n return [\n babel(options.babel),\n {\n name: \"env\",\n async config() {\n this.debug(\n \"Providing default configuration for the Powerlines `env` build plugin.\"\n );\n\n const config = {\n env: defu(options, {\n validate: false,\n inject: false,\n prefix: []\n }),\n babel: {\n ...options.babel,\n skipTransform: !options.inject,\n plugins: [envBabelPlugin]\n }\n };\n\n if (!config.env.vars) {\n this.warn(\n \"The `env.vars` configuration parameter was not provided. Please ensure this is expected.\"\n );\n\n config.env.vars = await getDefaultVarsTypeDefinition(\n this as UnresolvedContext\n );\n }\n\n if (!config.env.secrets) {\n config.env.secrets = await getDefaultSecretsTypeDefinition(\n this as UnresolvedContext\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 \"POWERLINES_\",\n this.config.framework?.name &&\n this.config.framework?.name !== \"powerlines\" &&\n `${constantCase(this.config.framework?.name)}_`\n ].filter(Boolean) as string[]\n );\n\n config.env.prefix = getUnique(\n 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\n return config;\n },\n async configResolved() {\n this.debug(\n `Environment plugin configuration has been resolved for the Powerlines project.`\n );\n\n await extractEnvSchema(this, options);\n },\n async prepare() {\n this.debug(\n `Preparing the Environment runtime artifacts for the Powerlines project.`\n );\n\n return render(\n this,\n <EnvBuiltin defaultConfig={this.config.env.defaultConfig} />\n );\n },\n async docs() {\n this.debug(\n `Documenting environment variables configuration values in \"${joinPaths(\n getDocsOutputPath(this.config.root),\n \"env.md\"\n )}\"`\n );\n\n return render(this, <EnvDocsFile levelOffset={0} />);\n },\n async buildEnd() {\n this.debug(\"Writing active environment variables to disk.\");\n\n await writeSchema(this, this.env.vars);\n }\n },\n {\n name: \"env:automd-generator\",\n configResolved() {\n return {\n automd: defu(options.automd ?? {}, {\n generators: {\n env: env(this)\n }\n })\n };\n }\n },\n {\n name: \"env:vite\",\n vite: {\n configResolved(this: TContext) {\n return {\n envPrefix: this.config?.env?.prefix\n } as ViteUserConfig;\n }\n }\n },\n automd(options.automd)\n ] as Plugin<TContext>[];\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;CAEE,GAAG,SAAS;;AAEd;;;;AAqCA,MAAa,SAAS,cAAC,UAAA,CAAA,MAAA;;;;GAEvB,MAAQ;GACN,MAAA,SAAiB;IACf,KAAM,MAAA,wEAAgB;IACxB,MAAA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MAAI,aAAW,eAAgB,OAAA;IAC7B,KAAK,MAAM,8DAA6B,UAAA,kBAAA,KAAA,OAAA,IAAA,GAAA,QAAA,EAAA,EAAA;IACxC,OAAI,OAAM,MAAA,gBAAA,aAAA,EACR,aAAQ,EACV,CAAC,CAAC;GACJ,GAAG,CAAC,QAAQ,OAAK,CAAA;GACjB,UAAU,aAAS,eAAgB,WAAA;IACjC,KAAK,MAAC,+CAAA;;GAER,GAAG,CAAC,YAAW,OAAG,CAAA;EACpB;EAAG;GACD,MAAM;GACN,gBAAS,aAAY,SAAA,iBAAA;IACnB,OAAM,EACJ,QAAM,KAAK,QAAO,UAAW,CAAA,GAAM,EACjC,YAAO,EACL,KAAA,IAAO,IAAA,EACV,KAEH;GACF,GAAG,CAAC,kBAAiB,OAAI,CAAA;EAC3B;EAAG;GACD,MAAM;GACN,MAAM,EACJ,gBAAgB,aAAA,SAAA,iBAAA;IACd,OAAO,EACN,WAAA,KAAA,QAAA,KAAA;GAEH,GAAE;IAAA;IAAa;IAAA;IAAA;GAAA,CAAA,EACjB;EACF;EAAG,OAAO,QAAA,MAAc;CAAC;AAC3B,GAAG;CAAC;CAAc;QAAA,CAAA;CAAA;CAAA;AAAA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-env",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.237",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package containing a Powerlines plugin for injecting static .env configuration values to the code so that they're accessible at runtime.",
|
|
6
6
|
"keywords": ["dotenv", "powerlines", "storm-software", "powerlines-plugin"],
|
|
@@ -107,12 +107,12 @@
|
|
|
107
107
|
"@alloy-js/typescript": "^0.23.0",
|
|
108
108
|
"@babel/core": "8.0.0-rc.5",
|
|
109
109
|
"@babel/types": "8.0.0-rc.5",
|
|
110
|
-
"@powerlines/core": "^0.15.
|
|
111
|
-
"@powerlines/plugin-alloy": "^0.26.
|
|
112
|
-
"@powerlines/plugin-automd": "^0.1.
|
|
113
|
-
"@powerlines/plugin-babel": "^0.13.
|
|
114
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
115
|
-
"@powerlines/schema": "^0.11.
|
|
110
|
+
"@powerlines/core": "^0.15.22",
|
|
111
|
+
"@powerlines/plugin-alloy": "^0.26.129",
|
|
112
|
+
"@powerlines/plugin-automd": "^0.1.506",
|
|
113
|
+
"@powerlines/plugin-babel": "^0.13.41",
|
|
114
|
+
"@powerlines/plugin-plugin": "^0.12.457",
|
|
115
|
+
"@powerlines/schema": "^0.11.24",
|
|
116
116
|
"@storm-software/config-tools": "^1.190.20",
|
|
117
117
|
"@stryke/capnp": "^0.12.102",
|
|
118
118
|
"@stryke/convert": "^0.7.7",
|
|
@@ -127,9 +127,9 @@
|
|
|
127
127
|
"automd": "^0.4.3",
|
|
128
128
|
"c12": "^3.3.4",
|
|
129
129
|
"defu": "^6.1.7",
|
|
130
|
-
"powerlines": "^0.47.
|
|
130
|
+
"powerlines": "^0.47.45"
|
|
131
131
|
},
|
|
132
132
|
"devDependencies": { "@types/node": "^25.9.0", "vite": "^8.0.13" },
|
|
133
133
|
"publishConfig": { "access": "public" },
|
|
134
|
-
"gitHead": "
|
|
134
|
+
"gitHead": "7fb37a42aa27f6cbc6b7412e259d0f7a79bac8ed"
|
|
135
135
|
}
|