@powerlines/plugin-env 0.15.103 → 0.15.105

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.
@@ -1,13 +1,5 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  const require_types_plugin = require('../types/plugin.cjs');
3
- const require_helpers_persistence = require('../helpers/persistence.cjs');
4
- let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
5
- let __powerlines_deepkit_capnp = require("@powerlines/deepkit/capnp");
6
- let __powerlines_deepkit_schemas_reflection = require("@powerlines/deepkit/schemas/reflection");
7
- let __stryke_capnp = require("@stryke/capnp");
8
- __stryke_capnp = require_rolldown_runtime.__toESM(__stryke_capnp);
9
- let __stryke_fs_buffer = require("@stryke/fs/buffer");
10
- let node_fs = require("node:fs");
11
3
  let powerlines_types_babel = require("powerlines/types/babel");
12
4
  let __babel_core = require("@babel/core");
13
5
  let __powerlines_deepkit_utilities = require("@powerlines/deepkit/utilities");
@@ -51,7 +43,10 @@ const envBabelPlugin = (__powerlines_plugin_babel_helpers_create_plugin.createBa
51
43
  "P\"2!\"/\""
52
44
  ]));
53
45
  if (!envProperty || envProperty.isIgnored()) return;
54
- if (!context.env.used.env.hasProperty(name)) context.env.used.env.addProperty(envProperty.property);
46
+ if (!context.env.used.env.hasProperty(name)) {
47
+ log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, `Adding "${name}" environment variables found in "${pass.filename || "unknown file"}" to used environment configuration reflection object.`);
48
+ context.env.used.env.addProperty(envProperty.property);
49
+ }
55
50
  if (context.config.env.inject && isInjectable) {
56
51
  let value = context.env.parsed?.[name];
57
52
  if (value === void 0) {
@@ -102,77 +97,40 @@ const envBabelPlugin = (__powerlines_plugin_babel_helpers_create_plugin.createBa
102
97
  "extractEnv",
103
98
  "P!2!n\"2#\"2$\"/%"
104
99
  ];
105
- return {
106
- visitor: { MemberExpression: __assignType(function MemberExpression(path, pass) {
107
- if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "process" }) && path.get("property")?.isIdentifier()) {
108
- const identifier = path.get("property")?.node;
109
- if (!identifier.name) return;
110
- extractEnv(identifier, pass, false);
111
- path.replaceWithSourceString(`env.${identifier.name}`);
112
- (0, __powerlines_plugin_babel_helpers_module_helpers.addImport)(path, {
113
- module: `${context.config.framework || "powerlines"}:env`,
114
- name: "env",
115
- imported: "env"
116
- });
117
- } else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isMetaProperty() && path.get("property")?.isIdentifier()) {
118
- const identifier = path.get("property")?.node;
119
- if (!identifier.name) return;
120
- extractEnv(identifier, pass, false);
121
- path.replaceWithSourceString(`env.${identifier.name}`);
122
- (0, __powerlines_plugin_babel_helpers_module_helpers.addImport)(path, {
123
- module: `${context.config.framework || "powerlines"}:env`,
124
- name: "env",
125
- imported: "env"
126
- });
127
- } else if (path.get("object")?.isIdentifier({ name: "env" }) && path.get("property")?.isIdentifier()) {
128
- const identifier = path.get("property")?.node;
129
- if (!identifier.name) return;
130
- extractEnv(identifier, pass, false);
131
- }
132
- }, [
133
- () => __babel_core.NodePath,
134
- "path",
135
- () => powerlines_types_babel.__ΩBabelPluginPass,
136
- "pass",
137
- "MemberExpression",
138
- "PP!7!2\"n#2$\"/%"
139
- ]) },
140
- post() {
141
- log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Adding environment variables from ${this.filename || "unknown file"} to env.json.`);
142
- let persistedEnv = __powerlines_deepkit_vendor_type.ReflectionClass.from({
143
- kind: __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral,
144
- description: `An object containing the environment variables used by the application.`,
145
- types: []
100
+ return { visitor: { MemberExpression: __assignType(function MemberExpression(path, pass) {
101
+ if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "process" }) && path.get("property")?.isIdentifier()) {
102
+ const identifier = path.get("property")?.node;
103
+ if (!identifier.name) return;
104
+ extractEnv(identifier, pass, false);
105
+ path.replaceWithSourceString(`env.${identifier.name}`);
106
+ (0, __powerlines_plugin_babel_helpers_module_helpers.addImport)(path, {
107
+ module: `${context.config.framework || "powerlines"}:env`,
108
+ name: "env",
109
+ imported: "env"
146
110
  });
147
- const reflectionPath = require_helpers_persistence.getEnvReflectionsPath(context, "env");
148
- if (reflectionPath && (0, node_fs.existsSync)(reflectionPath)) {
149
- log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Environment reflection file found at ${reflectionPath}, reading existing reflection.`);
150
- persistedEnv = (0, __powerlines_deepkit_vendor_type.resolveClassType)((0, __powerlines_deepkit_vendor_type.deserializeType)((0, __powerlines_deepkit_capnp.convertFromCapnp)(new __stryke_capnp.Message((0, __stryke_fs_buffer.readFileBufferSync)(reflectionPath), false).getRoot(__powerlines_deepkit_schemas_reflection.SerializedTypes).types)));
151
- }
152
- log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Adding new variables to env reflection at ${reflectionPath}.`);
153
- persistedEnv.getProperties().filter(__assignType((property) => property.getNameAsString() && !context.env.used.env.hasProperty(property.getNameAsString()), [
154
- "property",
155
- "",
156
- "P\"2!\"/\""
157
- ])).forEach(__assignType((property) => {
158
- context.env.used.env.addProperty({
159
- ...property,
160
- name: property.getNameAsString(),
161
- description: property.getDescription() ?? `The ${property.getNameAsString()} variable.`,
162
- default: property.getDefaultValue(),
163
- optional: property.isOptional() ? true : void 0,
164
- readonly: property.isReadonly() ? true : void 0,
165
- visibility: property.getVisibility(),
166
- type: property.getType(),
167
- tags: property.getTags()
168
- });
169
- }, [
170
- "property",
171
- "",
172
- "P\"2!\"/\""
173
- ]));
111
+ } else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isMetaProperty() && path.get("property")?.isIdentifier()) {
112
+ const identifier = path.get("property")?.node;
113
+ if (!identifier.name) return;
114
+ extractEnv(identifier, pass, false);
115
+ path.replaceWithSourceString(`env.${identifier.name}`);
116
+ (0, __powerlines_plugin_babel_helpers_module_helpers.addImport)(path, {
117
+ module: `${context.config.framework || "powerlines"}:env`,
118
+ name: "env",
119
+ imported: "env"
120
+ });
121
+ } else if (path.get("object")?.isIdentifier({ name: "env" }) && path.get("property")?.isIdentifier()) {
122
+ const identifier = path.get("property")?.node;
123
+ if (!identifier.name) return;
124
+ extractEnv(identifier, pass, false);
174
125
  }
175
- };
126
+ }, [
127
+ () => __babel_core.NodePath,
128
+ "path",
129
+ () => powerlines_types_babel.__ΩBabelPluginPass,
130
+ "pass",
131
+ "MemberExpression",
132
+ "PP!7!2\"n#2$\"/%"
133
+ ]) } };
176
134
  }, [
177
135
  "param0",
178
136
  "",
@@ -1,11 +1,4 @@
1
1
  import { __ΩEnvPluginContext } from "../types/plugin.mjs";
2
- import { getEnvReflectionsPath } from "../helpers/persistence.mjs";
3
- import { ReflectionClass, ReflectionKind, deserializeType, resolveClassType } from "@powerlines/deepkit/vendor/type";
4
- import { convertFromCapnp } from "@powerlines/deepkit/capnp";
5
- import { SerializedTypes } from "@powerlines/deepkit/schemas/reflection";
6
- import * as capnp from "@stryke/capnp";
7
- import { readFileBufferSync } from "@stryke/fs/buffer";
8
- import { existsSync } from "node:fs";
9
2
  import { __ΩBabelPluginPass } from "powerlines/types/babel";
10
3
  import { NodePath } from "@babel/core";
11
4
  import { stringifyDefaultValue } from "@powerlines/deepkit/utilities";
@@ -49,7 +42,10 @@ const envBabelPlugin = (createBabelPlugin.Ω = [[() => __ΩEnvPluginContext, "n!
49
42
  "P\"2!\"/\""
50
43
  ]));
51
44
  if (!envProperty || envProperty.isIgnored()) return;
52
- if (!context.env.used.env.hasProperty(name)) context.env.used.env.addProperty(envProperty.property);
45
+ if (!context.env.used.env.hasProperty(name)) {
46
+ log(LogLevelLabel.DEBUG, `Adding "${name}" environment variables found in "${pass.filename || "unknown file"}" to used environment configuration reflection object.`);
47
+ context.env.used.env.addProperty(envProperty.property);
48
+ }
53
49
  if (context.config.env.inject && isInjectable) {
54
50
  let value = context.env.parsed?.[name];
55
51
  if (value === void 0) {
@@ -100,77 +96,40 @@ const envBabelPlugin = (createBabelPlugin.Ω = [[() => __ΩEnvPluginContext, "n!
100
96
  "extractEnv",
101
97
  "P!2!n\"2#\"2$\"/%"
102
98
  ];
103
- return {
104
- visitor: { MemberExpression: __assignType(function MemberExpression(path, pass) {
105
- if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "process" }) && path.get("property")?.isIdentifier()) {
106
- const identifier = path.get("property")?.node;
107
- if (!identifier.name) return;
108
- extractEnv(identifier, pass, false);
109
- path.replaceWithSourceString(`env.${identifier.name}`);
110
- addImport(path, {
111
- module: `${context.config.framework || "powerlines"}:env`,
112
- name: "env",
113
- imported: "env"
114
- });
115
- } else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isMetaProperty() && path.get("property")?.isIdentifier()) {
116
- const identifier = path.get("property")?.node;
117
- if (!identifier.name) return;
118
- extractEnv(identifier, pass, false);
119
- path.replaceWithSourceString(`env.${identifier.name}`);
120
- addImport(path, {
121
- module: `${context.config.framework || "powerlines"}:env`,
122
- name: "env",
123
- imported: "env"
124
- });
125
- } else if (path.get("object")?.isIdentifier({ name: "env" }) && path.get("property")?.isIdentifier()) {
126
- const identifier = path.get("property")?.node;
127
- if (!identifier.name) return;
128
- extractEnv(identifier, pass, false);
129
- }
130
- }, [
131
- () => NodePath,
132
- "path",
133
- () => __ΩBabelPluginPass,
134
- "pass",
135
- "MemberExpression",
136
- "PP!7!2\"n#2$\"/%"
137
- ]) },
138
- post() {
139
- log(LogLevelLabel.TRACE, `Adding environment variables from ${this.filename || "unknown file"} to env.json.`);
140
- let persistedEnv = ReflectionClass.from({
141
- kind: ReflectionKind.objectLiteral,
142
- description: `An object containing the environment variables used by the application.`,
143
- types: []
99
+ return { visitor: { MemberExpression: __assignType(function MemberExpression(path, pass) {
100
+ if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "process" }) && path.get("property")?.isIdentifier()) {
101
+ const identifier = path.get("property")?.node;
102
+ if (!identifier.name) return;
103
+ extractEnv(identifier, pass, false);
104
+ path.replaceWithSourceString(`env.${identifier.name}`);
105
+ addImport(path, {
106
+ module: `${context.config.framework || "powerlines"}:env`,
107
+ name: "env",
108
+ imported: "env"
144
109
  });
145
- const reflectionPath = getEnvReflectionsPath(context, "env");
146
- if (reflectionPath && existsSync(reflectionPath)) {
147
- log(LogLevelLabel.TRACE, `Environment reflection file found at ${reflectionPath}, reading existing reflection.`);
148
- persistedEnv = resolveClassType(deserializeType(convertFromCapnp(new capnp.Message(readFileBufferSync(reflectionPath), false).getRoot(SerializedTypes).types)));
149
- }
150
- log(LogLevelLabel.TRACE, `Adding new variables to env reflection at ${reflectionPath}.`);
151
- persistedEnv.getProperties().filter(__assignType((property) => property.getNameAsString() && !context.env.used.env.hasProperty(property.getNameAsString()), [
152
- "property",
153
- "",
154
- "P\"2!\"/\""
155
- ])).forEach(__assignType((property) => {
156
- context.env.used.env.addProperty({
157
- ...property,
158
- name: property.getNameAsString(),
159
- description: property.getDescription() ?? `The ${property.getNameAsString()} variable.`,
160
- default: property.getDefaultValue(),
161
- optional: property.isOptional() ? true : void 0,
162
- readonly: property.isReadonly() ? true : void 0,
163
- visibility: property.getVisibility(),
164
- type: property.getType(),
165
- tags: property.getTags()
166
- });
167
- }, [
168
- "property",
169
- "",
170
- "P\"2!\"/\""
171
- ]));
110
+ } else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isMetaProperty() && path.get("property")?.isIdentifier()) {
111
+ const identifier = path.get("property")?.node;
112
+ if (!identifier.name) return;
113
+ extractEnv(identifier, pass, false);
114
+ path.replaceWithSourceString(`env.${identifier.name}`);
115
+ addImport(path, {
116
+ module: `${context.config.framework || "powerlines"}:env`,
117
+ name: "env",
118
+ imported: "env"
119
+ });
120
+ } else if (path.get("object")?.isIdentifier({ name: "env" }) && path.get("property")?.isIdentifier()) {
121
+ const identifier = path.get("property")?.node;
122
+ if (!identifier.name) return;
123
+ extractEnv(identifier, pass, false);
172
124
  }
173
- };
125
+ }, [
126
+ () => NodePath,
127
+ "path",
128
+ () => __ΩBabelPluginPass,
129
+ "pass",
130
+ "MemberExpression",
131
+ "PP!7!2\"n#2$\"/%"
132
+ ]) } };
174
133
  }, [
175
134
  "param0",
176
135
  "",
package/dist/index.cjs CHANGED
@@ -141,6 +141,19 @@ const plugin = (options = {}) => {
141
141
  return _self$.config.env.defaultConfig;
142
142
  } }));
143
143
  },
144
+ transform: {
145
+ order: "post",
146
+ async handler() {
147
+ if (this.env.used.env.getProperties().length > 0) {
148
+ this.debug(`Persisting used environment configuration reflections to ${require_helpers_persistence.getEnvReflectionsPath(this, "env")}.`);
149
+ await require_helpers_persistence.writeEnvReflection(this, this.env.used.env, "env");
150
+ }
151
+ if (this.env.used.secrets.getProperties().length > 0) {
152
+ this.debug(`Persisting used secret configuration reflections to ${require_helpers_persistence.getEnvReflectionsPath(this, "secrets")}.`);
153
+ await require_helpers_persistence.writeEnvReflection(this, this.env.used.secrets, "secrets");
154
+ }
155
+ }
156
+ },
144
157
  async docs() {
145
158
  this.debug("Writing Environment documentation for the Powerlines project artifacts.");
146
159
  const outputPath = require_join_paths.joinPaths(this.config.projectRoot, "docs", "generated");
package/dist/index.mjs CHANGED
@@ -136,6 +136,19 @@ const plugin = (options = {}) => {
136
136
  return _self$.config.env.defaultConfig;
137
137
  } }));
138
138
  },
139
+ transform: {
140
+ order: "post",
141
+ async handler() {
142
+ if (this.env.used.env.getProperties().length > 0) {
143
+ this.debug(`Persisting used environment configuration reflections to ${getEnvReflectionsPath(this, "env")}.`);
144
+ await writeEnvReflection(this, this.env.used.env, "env");
145
+ }
146
+ if (this.env.used.secrets.getProperties().length > 0) {
147
+ this.debug(`Persisting used secret configuration reflections to ${getEnvReflectionsPath(this, "secrets")}.`);
148
+ await writeEnvReflection(this, this.env.used.secrets, "secrets");
149
+ }
150
+ }
151
+ },
139
152
  async docs() {
140
153
  this.debug("Writing Environment documentation for the Powerlines project artifacts.");
141
154
  const outputPath = joinPaths(this.config.projectRoot, "docs", "generated");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-env",
3
- "version": "0.15.103",
3
+ "version": "0.15.105",
4
4
  "type": "module",
5
5
  "description": "A package containing a Powerlines plugin for injecting static .env configuration values to the code so that they're accessible at runtime.",
6
6
  "repository": {
@@ -193,10 +193,10 @@
193
193
  "@alloy-js/typescript": "^0.22.0",
194
194
  "@babel/core": "^7.28.6",
195
195
  "@babel/types": "^7.28.6",
196
- "@powerlines/plugin-alloy": "^0.18.97",
197
- "@powerlines/plugin-automd": "^0.1.207",
198
- "@powerlines/plugin-babel": "^0.12.216",
199
- "@powerlines/plugin-plugin": "^0.12.158",
196
+ "@powerlines/plugin-alloy": "^0.18.98",
197
+ "@powerlines/plugin-automd": "^0.1.208",
198
+ "@powerlines/plugin-babel": "^0.12.217",
199
+ "@powerlines/plugin-plugin": "^0.12.159",
200
200
  "@storm-software/config-tools": "^1.189.0",
201
201
  "@stryke/capnp": "^0.12.61",
202
202
  "@stryke/env": "^0.20.53",
@@ -206,14 +206,14 @@
206
206
  "@stryke/type-checks": "^0.5.20",
207
207
  "@stryke/types": "^0.10.34",
208
208
  "automd": "^0.4.2",
209
- "powerlines": "^0.37.80"
209
+ "powerlines": "^0.37.81"
210
210
  },
211
211
  "devDependencies": {
212
- "@powerlines/deepkit": "^0.5.124",
213
- "@powerlines/plugin-deepkit": "^0.11.86",
212
+ "@powerlines/deepkit": "^0.5.125",
213
+ "@powerlines/plugin-deepkit": "^0.11.87",
214
214
  "@types/node": "^24.10.9",
215
215
  "vite": "8.0.0-beta.2"
216
216
  },
217
217
  "publishConfig": { "access": "public" },
218
- "gitHead": "9efecc8e1430d61981c1375aeffdb63d72bc0028"
218
+ "gitHead": "ef6060b6d1538862d195a97bfbca9e5e9eedafaf"
219
219
  }