@stacksjs/actions 0.72.79 → 0.72.80

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,9 +1,17 @@
1
1
  /**
2
2
  * The text of `storage/framework/types/env.d.ts`.
3
3
  *
4
+ * Bun's `env` namespace only. The `env` exported by '@stacksjs/env' used to be
5
+ * augmented from here too, and that was the wrong source: the key set came
6
+ * from whichever `.env` was on the machine running the generator, so a
7
+ * variable set only in deploy secrets could never be typed, and each type was
8
+ * read off the variable's live value, so the same variable could be `number`
9
+ * here and `string` on a colleague's checkout. `StacksEnv` is now extended
10
+ * from `config/env.ts`, which declares those variables anyway and is committed.
11
+ *
4
12
  * Pure, so the shape can be asserted without writing into the framework.
5
13
  */
6
- export declare function renderEnvTypes(keys: string[], alreadyDeclared: ReadonlySet<string>, typeOf: (key: string) => string): string;
14
+ export declare function renderEnvTypes(keys: string[], typeOf: (key: string) => string): string;
7
15
  /**
8
16
  * Write `storage/framework/types/env.d.ts` and `storage/framework/env.ts`.
9
17
  *
@@ -1,12 +1,25 @@
1
- import{env as e,envEnum,parse}from"@stacksjs/env";import{log}from"@stacksjs/logging";import{path as p}from"@stacksjs/path";import{storage}from"@stacksjs/storage";import{existsSync,readFileSync}from"node:fs";function previouslyDeclaredKeys(){const file=p.frameworkPath("env.ts");if(!existsSync(file))return[];return[...(readFileSync(file,"utf8").match(/export const envKeys = \[([^\]]*)\]/)?.[1]??"").matchAll(/'([A-Z0-9_]+)'/g)].map((match)=>match[1])}function frameworkDeclaredKeys(){const file=[p.frameworkPath("core/env/src/types.ts"),p.projectPath("node_modules/@stacksjs/env/dist/types.d.ts")].find((candidate)=>existsSync(candidate));if(!file)return new Set;const body=readFileSync(file,"utf8"),start=body.indexOf("interface StacksEnv");if(start===-1)return new Set;const block=body.slice(start,body.indexOf(`
2
- }`,start));return new Set([...block.matchAll(/^\s{2}([A-Z][A-Z0-9_]*)\??:/gm)].map((match)=>match[1]))}function resolveEnvKeys(){const keys=new Set(previouslyDeclaredKeys());for(const file of[".env",".env.example"]){const path=p.projectPath(file);if(!existsSync(path))continue;for(const key of Object.keys(parse(readFileSync(path,"utf8")).parsed))keys.add(key)}return[...keys].sort()}export function renderEnvTypes(keys,alreadyDeclared,typeOf){const resolvedKeys=keys;return`
1
+ import{env as e,envEnum,parse}from"@stacksjs/env";import{log}from"@stacksjs/logging";import{path as p}from"@stacksjs/path";import{storage}from"@stacksjs/storage";import{existsSync,readFileSync}from"node:fs";function previouslyDeclaredKeys(){const file=p.frameworkPath("env.ts");if(!existsSync(file))return[];return[...(readFileSync(file,"utf8").match(/export const envKeys = \[([^\]]*)\]/)?.[1]??"").matchAll(/'([A-Z0-9_]+)'/g)].map((match)=>match[1])}function resolveEnvKeys(){const keys=new Set(previouslyDeclaredKeys());for(const file of[".env",".env.example"]){const path=p.projectPath(file);if(!existsSync(path))continue;for(const key of Object.keys(parse(readFileSync(path,"utf8")).parsed))keys.add(key)}return[...keys].sort()}export function renderEnvTypes(keys,typeOf){return`
3
2
  // This file is auto-generated by Stacks. Do not edit this file manually.
4
3
  // If you want to change the environment variables, please edit the .env file.
5
4
  //
5
+ // This types \`Bun.env.SOMETHING\`. The \`env\` exported by '@stacksjs/env' is
6
+ // typed from your \`config/env.ts\` instead - declare a variable there and it
7
+ // is typed everywhere, with no generation step:
8
+ //
9
+ // const envSchema = defineEnv({
10
+ // STRIPE_WEBHOOK_SECRET: { validation: schema.string(), default: '' },
11
+ // })
12
+ //
13
+ // declare module '@stacksjs/env' {
14
+ // interface StacksEnv extends InferEnv<typeof envSchema> {}
15
+ // }
16
+ //
17
+ // export default envSchema
18
+ //
6
19
  // For more information, please visit: https://stacksjs.com/docs
7
20
 
8
- // Marks this file as a module, which is what makes the blocks below
9
- // augmentations. In a global script file \`declare module 'x'\` declares an
21
+ // Marks this file as a module, which is what makes the block below an
22
+ // augmentation. In a global script file \`declare module 'x'\` declares an
10
23
  // ambient module instead, shadowing the real one \u2014 which took '@stacksjs/env'
11
24
  // down to only the members named here and broke every \`import { env }\` in
12
25
  // config/ with "has no exported member 'env'".
@@ -14,24 +27,11 @@ export {}
14
27
 
15
28
  declare module 'bun' {
16
29
  namespace env {
17
- ${resolvedKeys.map((key)=>`const ${key}: ${typeOf(key)}`).join(`
18
- `)}
19
- }
20
- }
21
-
22
- // The \`env\` exported by '@stacksjs/env' is typed by StacksEnv, not by Bun's
23
- // namespace, and its catch-all index signature gives any variable the
24
- // framework does not name the type \`string | number | boolean | undefined\`.
25
- // That is assignable to nothing, so reading a project's own variable in
26
- // \`config/\` failed to typecheck against a plain \`string\` field. Declared
27
- // here, each one gets the type its value implies.
28
- declare module '@stacksjs/env' {
29
- interface StacksEnv {
30
- ${resolvedKeys.filter((key)=>!alreadyDeclared.has(key)).map((key)=>`${key}: ${typeOf(key)} | undefined`).join(`
30
+ ${keys.map((key)=>`const ${key}: ${typeOf(key)}`).join(`
31
31
  `)}
32
32
  }
33
33
  }
34
- `}export async function generateEnvFiles(){log.info("Generating type env files...");const resolvedKeys=resolveEnvKeys(),alreadyDeclared=frameworkDeclaredKeys();function typeOf(key){let type=typeof e[key],value=e[key];if(!value)if(envEnum[key]){type=envEnum[key]?.map((item)=>`'${item}'`).join(" | ");value=envEnum[key]?.[0]}else switch(type){case"number":value="0";break;case"boolean":value=!1;break;default:value=""}type="string";if(typeof value==="string"){if(value.toLowerCase()==="true"||value.toLowerCase()==="false")type="boolean";else if(!Number.isNaN(Number.parseFloat(value))&&Number.isFinite(Number(value)))type="number";else if(envEnum[key])type=envEnum[key].map((item)=>`'${item}'`).join(" | ")}else if(typeof value==="number")type="number";else if(typeof value==="boolean")type="boolean";return type}const envTypes=renderEnvTypes(resolvedKeys,alreadyDeclared,typeOf);await storage.writeFile(p.frameworkPath("types/env.d.ts"),envTypes);log.info(" - ./storage/framework/env.ts");const env=`
34
+ `}export async function generateEnvFiles(){log.info("Generating type env files...");const resolvedKeys=resolveEnvKeys();function typeOf(key){let type=typeof e[key],value=e[key];if(!value)if(envEnum[key]){type=envEnum[key]?.map((item)=>`'${item}'`).join(" | ");value=envEnum[key]?.[0]}else switch(type){case"number":value="0";break;case"boolean":value=!1;break;default:value=""}type="string";if(typeof value==="string"){if(value.toLowerCase()==="true"||value.toLowerCase()==="false")type="boolean";else if(!Number.isNaN(Number.parseFloat(value))&&Number.isFinite(Number(value)))type="number";else if(envEnum[key])type=envEnum[key].map((item)=>`'${item}'`).join(" | ")}else if(typeof value==="number")type="number";else if(typeof value==="boolean")type="boolean";return type}const envTypes=renderEnvTypes(resolvedKeys,typeOf);await storage.writeFile(p.frameworkPath("types/env.d.ts"),envTypes);log.info(" - ./storage/framework/env.ts");const env=`
35
35
  // This file is auto-generated by Stacks. Do not edit this file manually.
36
36
  // If you want to change the environment variables, please edit the .env file.
37
37
  //
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/actions",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.72.79",
5
+ "version": "0.72.80",
6
6
  "description": "The Stacks actions.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -60,35 +60,35 @@
60
60
  "prepublishOnly": "bun run build"
61
61
  },
62
62
  "dependencies": {
63
- "@stacksjs/config": "0.72.79",
63
+ "@stacksjs/config": "0.72.80",
64
64
  "@stacksjs/bumpx": "^0.2.6",
65
65
  "@stacksjs/bunpress": "^0.2.8",
66
66
  "@stacksjs/logsmith": "^0.2.3",
67
- "@stacksjs/registry": "0.72.79",
67
+ "@stacksjs/registry": "0.72.80",
68
68
  "@stacksjs/stx": "^0.2.230",
69
69
  "@stacksjs/ts-cloud": "^0.12.4",
70
70
  "@stacksjs/ts-md": "^0.1.1"
71
71
  },
72
72
  "devDependencies": {
73
- "@stacksjs/api": "0.72.79",
74
- "@stacksjs/cli": "0.72.79",
75
- "@stacksjs/database": "0.72.79",
73
+ "@stacksjs/api": "0.72.80",
74
+ "@stacksjs/cli": "0.72.80",
75
+ "@stacksjs/database": "0.72.80",
76
76
  "@stacksjs/tlsx": "^0.13.2",
77
77
  "better-dx": "^0.2.24",
78
- "@stacksjs/dns": "0.72.79",
79
- "@stacksjs/enums": "0.72.79",
80
- "@stacksjs/env": "0.72.79",
81
- "@stacksjs/error-handling": "0.72.79",
82
- "@stacksjs/image": "0.72.79",
83
- "@stacksjs/logging": "0.72.79",
84
- "@stacksjs/path": "0.72.79",
85
- "@stacksjs/security": "0.72.79",
86
- "@stacksjs/cms": "0.72.79",
87
- "@stacksjs/sites": "0.72.79",
88
- "@stacksjs/storage": "0.72.79",
89
- "@stacksjs/strings": "0.72.79",
90
- "@stacksjs/utils": "0.72.79",
91
- "@stacksjs/validation": "0.72.79"
78
+ "@stacksjs/dns": "0.72.80",
79
+ "@stacksjs/enums": "0.72.80",
80
+ "@stacksjs/env": "0.72.80",
81
+ "@stacksjs/error-handling": "0.72.80",
82
+ "@stacksjs/image": "0.72.80",
83
+ "@stacksjs/logging": "0.72.80",
84
+ "@stacksjs/path": "0.72.80",
85
+ "@stacksjs/security": "0.72.80",
86
+ "@stacksjs/cms": "0.72.80",
87
+ "@stacksjs/sites": "0.72.80",
88
+ "@stacksjs/storage": "0.72.80",
89
+ "@stacksjs/strings": "0.72.80",
90
+ "@stacksjs/utils": "0.72.80",
91
+ "@stacksjs/validation": "0.72.80"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "pickier": "^0.1.58",