@stacksjs/config 0.75.685 → 0.75.687

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/index.d.ts CHANGED
@@ -10,6 +10,7 @@
10
10
  // `overridesReady` are silently ignored.
11
11
  export * from './config';
12
12
  export { FRAMEWORK_DEFAULTS } from './defaults';
13
+ export { configSource, describeConfigSource, registerBundledConfig, settledConfigSource, userConfigFileNames, type BundledConfig, type ConfigSource } from './sources';
13
14
  export { validateConfig, reportConfigIssues, type ConfigValidationIssue } from './validators';
14
15
  export { feature, enableFeature, disableFeature, resetFeature, listFeatures, type AppFeatureFlags, type FeatureFlag, type StacksFeature } from './features';
15
16
  export { packageComponentRoots, packageJobRoots, packageMigrationRoots, packageModelRoots, packageViewRoots, type PackageResourceOptions, type PackageResourceRoot } from './discovered-resources';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./config";export{FRAMEWORK_DEFAULTS}from"./defaults";export{validateConfig,reportConfigIssues}from"./validators";export{feature,enableFeature,disableFeature,resetFeature,listFeatures}from"./features";export{packageComponentRoots,packageJobRoots,packageMigrationRoots,packageModelRoots,packageViewRoots}from"./discovered-resources";export{DEFAULT_VIEW_ROUTE_BUNDLES,DEFAULT_VIEW_TEMPLATES,DEFAULT_VIEWS_ALWAYS,resolveViewPatterns,withheldDefaultViews}from"./views";export{createRequestContext,enterRequestScope,installRequestContext,installRequestScope,parseCookieHeader,scopedRequestSnapshot,scopeStxServeContext,useRequestEvent}from"./request-context";export{clearShownFormFlash,expiredFormFlashCookie,flashableField,flashableInput,FORM_FLASH_COOKIE,FORM_FLASH_MAX_BYTES,FORM_FLASH_SECONDS,formFlashCookie,openFormFlash,sealFormFlash}from"./form-flash";export*from"./capabilities";
1
+ export*from"./config";export{FRAMEWORK_DEFAULTS}from"./defaults";export{configSource,describeConfigSource,registerBundledConfig,settledConfigSource,userConfigFileNames}from"./sources";export{validateConfig,reportConfigIssues}from"./validators";export{feature,enableFeature,disableFeature,resetFeature,listFeatures}from"./features";export{packageComponentRoots,packageJobRoots,packageMigrationRoots,packageModelRoots,packageViewRoots}from"./discovered-resources";export{DEFAULT_VIEW_ROUTE_BUNDLES,DEFAULT_VIEW_TEMPLATES,DEFAULT_VIEWS_ALWAYS,resolveViewPatterns,withheldDefaultViews}from"./views";export{createRequestContext,enterRequestScope,installRequestContext,installRequestScope,parseCookieHeader,scopedRequestSnapshot,scopeStxServeContext,useRequestEvent}from"./request-context";export{clearShownFormFlash,expiredFormFlashCookie,flashableField,flashableInput,FORM_FLASH_COOKIE,FORM_FLASH_MAX_BYTES,FORM_FLASH_SECONDS,formFlashCookie,openFormFlash,sealFormFlash}from"./form-flash";export*from"./capabilities";
package/dist/overrides.js CHANGED
@@ -1,4 +1,4 @@
1
- import{existsSync}from"node:fs";import{resolve}from"node:path";import{pathToFileURL}from"node:url";import{projectPath}from"@stacksjs/path";import{defaults}from"./defaults";import{plainEnv}from"./plain-env";import{validateConfig}from"./validators";const skipConfigLoading=process.env.SKIP_CONFIG_LOADING==="true";const skipConfigValidation=process.env.SKIP_CONFIG_VALIDATION==="true";const OVERRIDES_KEY=Symbol.for("@stacksjs/config:overrides");const READY_KEY=Symbol.for("@stacksjs/config:overridesReady");export function defaultsForOverrides(){return{ai:{},analytics:{},app:{...defaults.app,name:plainEnv("APP_NAME")||defaults.app?.name||"Stacks",env:plainEnv("APP_ENV")||"production"},auth:{},cache:{},cli:{},cloud:{},cms:{},commerce:{},dashboard:{},database:{},dns:{},realtime:{},email:{},errors:{},featureFlags:{},git:{},hashing:{},images:{},library:{},logging:{},marketing:{},monitoring:{},notification:{},queue:{},payment:{},ports:{},saas:{},searchEngine:{},security:{},server:{},sites:{},forms:{},services:{},sms:{},socials:{},filesystems:{},team:{},ui:{}}}const globalScope=globalThis;const sharedOverrides=globalScope[OVERRIDES_KEY];export const overrides=sharedOverrides??(()=>{const created=defaultsForOverrides();globalScope[OVERRIDES_KEY]=created;return created})();const userConfigs=[["ai","ai"],["analytics","analytics"],["app","app"],["auth","auth"],["cache","cache"],["cli","cli"],["cloud","cloud"],["cms","cms"],["commerce","commerce"],["cors","cors"],["dashboard","dashboard"],["database","database"],["dns","dns"],["docs","docs"],["email","email"],["errors","errors"],["featureFlags","feature-flags"],["git","git"],["hashing","hashing"],["images","images"],["library","library"],["logging","logging"],["marketing","marketing"],["monitoring","monitoring"],["notification","notification"],["payment","payment"],["ports","ports"],["queue","queue"],["realtime","realtime"],["saas","saas"],["searchEngine","search-engine"],["security","security"],["sites","sites"],["forms","forms"],["server","server"],["services","services"],["sms","sms"],["socials","socials"],["filesystems","filesystems"],["team","team"],["ui","ui","stx"]];export function resolveUserConfigName(names,root=projectPath()){const present=names.filter((candidate)=>existsSync(resolve(root,"config",`${candidate}.ts`)));if(present.length>1){console.warn(`[config] config/${present.join(".ts and config/")}.ts both exist and configure the same thing. `+`Using config/${present[0]}.ts; delete the other so every consumer agrees on one.`)}return present[0]??names[0]}export function userConfigUrl(name,root=projectPath()){return pathToFileURL(resolve(root,"config",`${name}.ts`)).href}const sharedReady=globalScope[READY_KEY];export const overridesReady=sharedReady??(()=>{const promise=skipConfigLoading?Promise.resolve(overrides):Promise.all(userConfigs.map(async([key,...names])=>{const name=resolveUserConfigName(names);const modulePath=userConfigUrl(name);try{const mod=await import(modulePath);if(mod?.default!==undefined){overrides[key]=mod.default}}catch(err){const code=err?.code;const msg=err?.message??String(err);const isMissing=code==="ERR_MODULE_NOT_FOUND"||code==="MODULE_NOT_FOUND"||/Cannot find module/i.test(msg);if(!isMissing){console.warn(`[config] Failed to load ${String(key)} config from ${modulePath}: ${msg}`)}}})).then(()=>{if(!skipConfigValidation){const issues=validateConfig(overrides);if(issues.length>0){console.error("[config] Configuration issues detected:");for(const issue of issues){console.error(` • ${issue.path}: ${issue.message}`)}const summary=issues.map((i)=>` • ${i.path}: ${i.message}`).join(`
1
+ import{existsSync}from"node:fs";import{resolve}from"node:path";import{pathToFileURL}from"node:url";import{projectPath}from"@stacksjs/path";import{defaults}from"./defaults";import{plainEnv}from"./plain-env";import{bundledConfig,OVERRIDES_READY_KEY,recordConfigSource,USER_CONFIG_FILES}from"./sources";import{validateConfig}from"./validators";const skipConfigLoading=process.env.SKIP_CONFIG_LOADING==="true";const skipConfigValidation=process.env.SKIP_CONFIG_VALIDATION==="true";const OVERRIDES_KEY=Symbol.for("@stacksjs/config:overrides");const READY_KEY=OVERRIDES_READY_KEY;export function defaultsForOverrides(){return{ai:{},analytics:{},app:{...defaults.app,name:plainEnv("APP_NAME")||defaults.app?.name||"Stacks",env:plainEnv("APP_ENV")||"production"},auth:{},cache:{},cli:{},cloud:{},cms:{},commerce:{},dashboard:{},database:{},dns:{},realtime:{},email:{},errors:{},featureFlags:{},git:{},hashing:{},images:{},library:{},logging:{},marketing:{},monitoring:{},notification:{},queue:{},payment:{},ports:{},saas:{},searchEngine:{},security:{},server:{},sites:{},forms:{},services:{},sms:{},socials:{},filesystems:{},team:{},ui:{}}}const globalScope=globalThis;const sharedOverrides=globalScope[OVERRIDES_KEY];export const overrides=sharedOverrides??(()=>{const created=defaultsForOverrides();globalScope[OVERRIDES_KEY]=created;return created})();export function resolveUserConfigName(names,root=projectPath()){const present=names.filter((candidate)=>existsSync(resolve(root,"config",`${candidate}.ts`)));if(present.length>1){console.warn(`[config] config/${present.join(".ts and config/")}.ts both exist and configure the same thing. `+`Using config/${present[0]}.ts; delete the other so every consumer agrees on one.`)}return present[0]??names[0]}export function userConfigUrl(name,root=projectPath()){return pathToFileURL(resolve(root,"config",`${name}.ts`)).href}const sharedReady=globalScope[READY_KEY];export const overridesReady=sharedReady??(()=>{const bundled=bundledConfig();const root=bundled?undefined:projectPath();const source=skipConfigLoading?{from:"skipped",loaded:[],failed:[]}:bundled?{from:"bundled",loaded:[],failed:[]}:{from:"files",root,loaded:[],failed:[]};const promise=skipConfigLoading?Promise.resolve(overrides).then((loaded)=>{recordConfigSource(source);return loaded}):Promise.all(USER_CONFIG_FILES.map(async([key,...names])=>{const name=bundled?bundledConfigName(bundled,names):resolveUserConfigName(names,root);if(name===undefined)return;const modulePath=bundled?`config/${name}.ts (compiled in)`:userConfigUrl(name,root);try{const mod=bundled?await bundled[name]():await import(modulePath);if(mod?.default!==undefined){overrides[key]=mod.default;source.loaded.push(name)}}catch(err){const code=err?.code;const msg=err?.message??String(err);const isMissing=!bundled&&(code==="ERR_MODULE_NOT_FOUND"||code==="MODULE_NOT_FOUND"||/Cannot find module/i.test(msg));if(!isMissing){source.failed.push({name,error:msg});console.warn(`[config] Failed to load ${String(key)} config from ${modulePath}: ${msg}`)}}})).then(()=>{if(!skipConfigValidation){const issues=validateConfig(overrides);if(issues.length>0){console.error("[config] Configuration issues detected:");for(const issue of issues){console.error(` • ${issue.path}: ${issue.message}`)}const summary=issues.map((i)=>` • ${i.path}: ${i.message}`).join(`
2
2
  `);throw new Error(`[config] ${issues.length} configuration issue(s) detected at boot:
3
3
  ${summary}
4
- `+`Set SKIP_CONFIG_VALIDATION=true to bypass (e.g. when running migrations against partial config).`)}}return overrides});globalScope[READY_KEY]=promise;return promise})();export default overrides;
4
+ `+`Set SKIP_CONFIG_VALIDATION=true to bypass (e.g. when running migrations against partial config).`)}}return overrides}).finally(()=>{source.loaded.sort();recordConfigSource(source)});globalScope[READY_KEY]=promise;return promise})();function bundledConfigName(bundled,names){return names.find((candidate)=>Object.hasOwn(bundled,candidate))}export default overrides;
@@ -0,0 +1,61 @@
1
+ /** Every file name the loader reads from `config/`, without `.ts`. */
2
+ export declare function userConfigFileNames(): string[];
3
+ /**
4
+ * Hand the loader the app's compiled-in config, to use instead of `config/`
5
+ * on disk. Must run before anything imports `@stacksjs/config`: the loader
6
+ * reads `config/` once, when it is first evaluated, and a registration after
7
+ * that would be ignored, so it throws instead.
8
+ */
9
+ export declare function registerBundledConfig(config: BundledConfig): void;
10
+ /** The registered compiled-in config, if any. */
11
+ export declare function bundledConfig(): BundledConfig | undefined;
12
+ /** Which config this process booted with; undefined until the loader has finished. */
13
+ export declare function configSource(): ConfigSource | undefined;
14
+ /**
15
+ * Which config this process booted with, once the loader has finished:
16
+ * waits for it when config has started loading, and is undefined when nothing
17
+ * has imported config at all. A failed load still says what it read.
18
+ */
19
+ export declare function settledConfigSource(): Promise<ConfigSource | undefined>;
20
+ /** For the loader: record what it loaded. */
21
+ export declare function recordConfigSource(source: ConfigSource): void;
22
+ /** One line saying which config the process booted with, for a log. */
23
+ export declare function describeConfigSource(source: ConfigSource): string;
24
+ /*.ts` reach the config proxy one of two ways. A
25
+ * process started from the project imports them from `config/` on disk. A
26
+ * compiled app has no `config/` beside it, and the loader's `import()` of a
27
+ * computed path is one the bundler cannot follow, so the app fell back to the
28
+ * framework defaults with no word said (stacksjs/stacks#3368). The build now
29
+ * names each file in a static `import()` and registers those loaders here
30
+ * before config loads.
31
+ *
32
+ * This module imports nothing, so registering costs nothing and cannot pull
33
+ * the config graph in early. The loader records what it loaded here as well,
34
+ * so whatever boots the app can say which config it booted with.
35
+ */
36
+ /**
37
+ * `[configKey, filename, ...alternativeFilenames]` for every file the loader
38
+ * reads from `config/`.
39
+ *
40
+ * The alternatives exist because stx accepts either name for its own config:
41
+ * `loadStxConfig` resolves `{ name: 'stx', alias: 'ui' }`, so an app can write
42
+ * `config/stx.ts` and stx reads it happily - while the loader looked only for
43
+ * `config/ui.ts` and left `config.ui` undefined. `resolveViewPatterns` treats
44
+ * undefined exactly like `true`, so such an app kept mounting the framework's
45
+ * demo views through a green build and a green deploy (stacksjs/stacks#2446).
46
+ *
47
+ * The first name that exists wins, and the primary stays first, so no app that
48
+ * resolves today resolves differently.
49
+ */
50
+ export declare const USER_CONFIG_FILES: ReadonlyArray<readonly [string, string, ...string[]]>;
51
+ /** The loader's readiness Promise, anchored by `overrides.ts`; present once config has started loading. */
52
+ export declare const OVERRIDES_READY_KEY: symbol;
53
+ /** Which config the process booted with, recorded by the loader once it has run. */
54
+ export declare interface ConfigSource {
55
+ from: 'bundled' | 'files' | 'skipped'
56
+ root?: string
57
+ loaded: string[]
58
+ failed: Array<{ name: string, error: string }>
59
+ }
60
+ /** A config file the build compiled in: its `config/<name>.ts`, by name, as a static `import()`. */
61
+ export type BundledConfig = Record<string, () => unknown>;
@@ -0,0 +1 @@
1
+ export const USER_CONFIG_FILES=[["ai","ai"],["analytics","analytics"],["app","app"],["auth","auth"],["cache","cache"],["cli","cli"],["cloud","cloud"],["cms","cms"],["commerce","commerce"],["cors","cors"],["dashboard","dashboard"],["database","database"],["dns","dns"],["docs","docs"],["email","email"],["errors","errors"],["featureFlags","feature-flags"],["git","git"],["hashing","hashing"],["images","images"],["library","library"],["logging","logging"],["marketing","marketing"],["monitoring","monitoring"],["notification","notification"],["payment","payment"],["ports","ports"],["queue","queue"],["realtime","realtime"],["saas","saas"],["searchEngine","search-engine"],["security","security"],["sites","sites"],["forms","forms"],["server","server"],["services","services"],["sms","sms"],["socials","socials"],["filesystems","filesystems"],["team","team"],["ui","ui","stx"]];export function userConfigFileNames(){return USER_CONFIG_FILES.flatMap(([,...names])=>names)}const BUNDLED_KEY=Symbol.for("@stacksjs/config:bundled");const SOURCE_KEY=Symbol.for("@stacksjs/config:source");export const OVERRIDES_READY_KEY=Symbol.for("@stacksjs/config:overridesReady");const scope=globalThis;export function registerBundledConfig(config){if(scope[OVERRIDES_READY_KEY]){throw new Error("Config has already loaded from config/ on disk, so the bundled config would be ignored. Register it before anything imports @stacksjs/config.")}scope[BUNDLED_KEY]=config}export function bundledConfig(){return scope[BUNDLED_KEY]}export function configSource(){return scope[SOURCE_KEY]}export async function settledConfigSource(){const ready=scope[OVERRIDES_READY_KEY];if(ready)await ready.catch(()=>{});return configSource()}export function recordConfigSource(source){scope[SOURCE_KEY]=source}export function describeConfigSource(source){const where=source.from==="bundled"?"compiled into the app":`from ${source.root??"."}/config`;if(source.from==="skipped")return"config: not loaded (SKIP_CONFIG_LOADING), framework defaults throughout";const failed=source.failed.length?`; failed: ${source.failed.map((file)=>`${file.name}.ts (${file.error})`).join(", ")}`:"";if(!source.loaded.length)return`config: no config/*.ts ${source.from==="bundled"?"compiled into the app":`under ${source.root??"."}`}, framework defaults throughout${failed}`;return`config: ${source.loaded.map((name)=>`${name}.ts`).join(", ")} ${where}; framework defaults for the rest${failed}`}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/config",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.685",
5
+ "version": "0.75.687",
6
6
  "description": "The Stacks config helper methods.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -55,16 +55,16 @@
55
55
  "prepublishOnly": "bun run build"
56
56
  },
57
57
  "dependencies": {
58
- "@stacksjs/events": "0.75.685",
59
- "@stacksjs/features": "0.75.685",
60
- "@stacksjs/path": "0.75.685",
61
- "@stacksjs/tunnel": "0.75.685",
58
+ "@stacksjs/events": "0.75.687",
59
+ "@stacksjs/features": "0.75.687",
60
+ "@stacksjs/path": "0.75.687",
61
+ "@stacksjs/tunnel": "0.75.687",
62
62
  "ts-pantry": "^0.11.198"
63
63
  },
64
64
  "devDependencies": {
65
- "@stacksjs/alias": "0.75.685",
66
- "@stacksjs/env": "0.75.685",
67
- "@stacksjs/types": "0.75.685",
65
+ "@stacksjs/alias": "0.75.687",
66
+ "@stacksjs/env": "0.75.687",
67
+ "@stacksjs/types": "0.75.687",
68
68
  "better-dx": "^0.2.39"
69
69
  }
70
70
  }