@donotdev/core 0.0.46 → 0.1.0

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/LICENSE.md CHANGED
@@ -8,7 +8,7 @@ Copyright © 2025 Ambroise Park Consulting. All rights reserved.
8
8
 
9
9
  ## 1. DEFINITIONS
10
10
 
11
- **1.1 "Framework"** means the DoNotDev commercial software packages (excluding @donotdev/cli and @donotdev/components, which are free), including all compiled JavaScript files, TypeScript definition files, and associated documentation.
11
+ **1.1 "Framework"** means the DoNotDev commercial software packages (excluding @donotdev/cli, @donotdev/components, @donotdev/expo, and @donotdev/templates, which are licensed under MIT), including all compiled JavaScript files, TypeScript definition files, and associated documentation.
12
12
 
13
13
  **1.2 "License Key"** means the unique alphanumeric key provided to you upon purchase, required to suppress watermarks and unlock full Framework functionality.
14
14
 
@@ -231,12 +231,12 @@ Ambroise Park Consulting has no obligation to provide support, updates, or maint
231
231
 
232
232
  Questions about licensing or compliance:
233
233
 
234
- **Email:** mooti.web.app@gmail.com
234
+ **Email:** contact@donotdev.com
235
235
  **Website:** donotdev.com
236
236
 
237
237
  ---
238
238
 
239
239
  **END OF LICENSE AGREEMENT**
240
240
 
241
- **DoNotDev Framework License v2.0**
241
+ **DoNotDev Framework License v1.0**
242
242
  Ambroise Park Consulting – 2025
@@ -12,7 +12,7 @@ import * as React from 'react';
12
12
  /**
13
13
  * Memory allocation options for Cloud Functions
14
14
  *
15
- * @version 0.0.1
15
+ * @version 0.1.0
16
16
  * @since 0.0.1
17
17
  * @author AMBROISE PARK Consulting
18
18
  */
@@ -28,7 +28,7 @@ type FunctionMemory =
28
28
  /**
29
29
  * Function trigger types
30
30
  *
31
- * @version 0.0.1
31
+ * @version 0.1.0
32
32
  * @since 0.0.1
33
33
  * @author AMBROISE PARK Consulting
34
34
  */
@@ -45,7 +45,7 @@ type FunctionTrigger =
45
45
  * Function-level deployment metadata
46
46
  * @description Per-function configuration for Firebase deployment (like PageMeta for pages)
47
47
  *
48
- * @version 0.0.1
48
+ * @version 0.1.0
49
49
  * @since 0.0.1
50
50
  * @author AMBROISE PARK Consulting
51
51
  */
@@ -79,7 +79,7 @@ interface FunctionMeta {
79
79
  /**
80
80
  * CRUD entity configuration for auto-generation
81
81
  *
82
- * @version 0.0.1
82
+ * @version 0.1.0
83
83
  * @since 0.0.1
84
84
  * @author AMBROISE PARK Consulting
85
85
  */
@@ -93,7 +93,7 @@ interface CrudConfig {
93
93
  /**
94
94
  * App-level defaults for all functions
95
95
  *
96
- * @version 0.0.1
96
+ * @version 0.1.0
97
97
  * @since 0.0.1
98
98
  * @author AMBROISE PARK Consulting
99
99
  */
@@ -132,7 +132,7 @@ interface FunctionDefaults {
132
132
  * };
133
133
  * ```
134
134
  *
135
- * @version 0.0.1
135
+ * @version 0.1.0
136
136
  * @since 0.0.1
137
137
  * @author AMBROISE PARK Consulting
138
138
  */
@@ -304,7 +304,7 @@ declare module 'react' {
304
304
  * @fileoverview Type Definitions for esbuild Configuration
305
305
  * @description TypeScript type definitions for esbuild configuration used in Firebase and Vercel function builds.
306
306
  *
307
- * @version 0.0.1
307
+ * @version 0.1.0
308
308
  * @since 0.0.1
309
309
  * @author AMBROISE PARK Consulting
310
310
  */
@@ -314,7 +314,7 @@ declare module 'react' {
314
314
  /**
315
315
  * Esbuild configuration options
316
316
  *
317
- * @version 0.0.1
317
+ * @version 0.1.0
318
318
  * @since 0.0.1
319
319
  * @author AMBROISE PARK Consulting
320
320
  */
@@ -332,7 +332,7 @@ interface EsbuildOptions {
332
332
  /**
333
333
  * Create esbuild configuration for functions
334
334
  *
335
- * @version 0.0.1
335
+ * @version 0.1.0
336
336
  * @since 0.0.1
337
337
  * @author AMBROISE PARK Consulting
338
338
  */
@@ -342,7 +342,7 @@ declare function createFunctionsEsbuildConfig(
342
342
  /**
343
343
  * Create root functions esbuild configuration
344
344
  *
345
- * @version 0.0.1
345
+ * @version 0.1.0
346
346
  * @since 0.0.1
347
347
  * @author AMBROISE PARK Consulting
348
348
  */
@@ -352,7 +352,7 @@ declare function createRootFunctionsConfig(
352
352
  /**
353
353
  * Create app functions esbuild configuration
354
354
  *
355
- * @version 0.0.1
355
+ * @version 0.1.0
356
356
  * @since 0.0.1
357
357
  * @author AMBROISE PARK Consulting
358
358
  */
@@ -1,20 +1,20 @@
1
- import A from"node:fs";import P from"node:path";import{fileURLToPath as oe}from"node:url";var ne=oe(import.meta.url),be=P.dirname(ne);function D(){let a=process.cwd(),e=10;for(let t=0;t<e;t++){let o=P.join(a,"package.json");if(A.existsSync(o))try{let s=JSON.parse(A.readFileSync(o,"utf8")),r=s.workspaces&&Array.isArray(s.workspaces);if(r&&s.workspaces.some(i=>i==="packages/**"||i.startsWith("packages/"))&&(A.existsSync(P.join(a,"packages","core"))||A.existsSync(P.join(a,"packages","functions"))))return{type:"dndev",root:a};if(r&&s.workspaces.some(i=>i.includes("dndev/packages"))){let u=s.workspaces.find(m=>m.includes("dndev/packages")).replace(/\/packages.*$/,""),d=P.resolve(a,u);if(A.existsSync(P.join(d,"packages","core")))return{type:"dndev",root:d}}}catch{}let n=P.dirname(a);if(n===a)break;a=n}return{type:"npm",root:process.cwd()}}function ie(a){return a.type==="dndev"?a.root:null}function H(a){let e={};if(a.type==="dndev"){let t=ie(a);t&&(e["@donotdev/types"]=P.join(t,"packages","core","types","src"),e["@donotdev/functions"]=P.join(t,"packages","functions","src"),e["@donotdev/utils"]=P.join(t,"packages","core","utils","src"),e["@donotdev/schemas"]=P.join(t,"packages","core","schemas","src"),e["@donotdev/core"]=P.join(t,"packages","core"))}return e}import*as h from"node:fs";import"node:fs";import{createRequire as ce}from"node:module";import{resolve as O,join as S,dirname as x,relative as K,normalize as le,sep as q,extname as ue}from"node:path";import{fileURLToPath as pe}from"node:url";import fe from"fast-glob";var T={SOURCE_ROOT:"packages/core/i18n",SOURCE_LOCALES:"packages/core/i18n/locales",SOURCE_EAGER:"packages/core/i18n/locales/eager",SOURCE_LAZY:"packages/core/i18n/locales/lazy",PUBLISHED_ROOT:"i18n",PUBLISHED_LOCALES:"i18n/locales",PUBLISHED_EAGER:"i18n/locales/eager",PUBLISHED_LAZY:"i18n/locales/lazy"},w={routes:{consumer:["src/**/*Page.tsx","src/pages/**/*Page.tsx"],exclude:["**/node_modules/**","**/dist/**","**/build/**","**/*.test.tsx","**/*.stories.tsx"],extensions:[".tsx"]},css:{consumer:["src/**/*.css"],themes:["src/**/*.css"],extensions:[".css",".scss",".sass"],framework:["packages/ui/src/**/*.css","packages/core/components/src/**/*.css","packages/core/templates/src/**/*.css"]},i18n:{eager:["src/locales/*_*.json"],lazy:["src/**/locales/*_*.json","!src/locales/*_*.json","../../entities/locales/*_*.json"],additional:[],framework:{eager:[`${T.SOURCE_EAGER}/*_*.json`],lazy:[`${T.SOURCE_LAZY}/*_*.json`]},extensions:[".json"]},assets:{consumer:["public/**/*"],fallback:["manifest.json"],modern:["logo.svg","favicon.svg","apple-touch-icon.png","android-chrome-192x192.png","android-chrome-512x512.png"],patterns:["favicon.svg","favicon.ico","favicon-*.png","logo.svg","logo.png","logo.webp","logo.avif","apple-touch-icon*.png","android-chrome-*.png","manifest.json"],fonts:["fonts/**/*.woff2","fonts/**/*.woff","fonts/**/*.ttf"],framework:["packages/ui/assets/**/*"]},pwa:{consumer:["public/manifest.json","public/service-worker.js","public/sw.js","public/icon-192x192.png","public/icon-512x512.png","public/favicon.ico","public/favicon.svg","public/apple-touch-icon.png","public/logo.svg"],exclude:["**/node_modules/**","**/dist/**","**/build/**"],extensions:[".json",".js",".png",".svg",".ico"],framework:["packages/ui/assets/**/*"]},globalIgnore:["**/node_modules/**","**/dist/**","**/build/**","**/.git/**","**/coverage/**","**/test/**"]};var Y={base:{absolute:!0,onlyFiles:!0,ignore:w.globalIgnore},css:{absolute:!0,onlyFiles:!0,ignore:[...w.globalIgnore,"**/*.test.css"]},routes:{absolute:!0,onlyFiles:!0,ignore:[...w.globalIgnore,"**/*.test.tsx","**/*.stories.tsx"]},i18n:{absolute:!0,onlyFiles:!0,ignore:w.globalIgnore},assets:{absolute:!0,onlyFiles:!0,ignore:w.globalIgnore}};function V(a,e=null){let t=w[a];if(!t)throw new Error(`Unknown pattern type: ${a}`);return e&&t.framework?{...t,framework:t.framework.map(o=>`${e}/${o}`)}:t}function J(a){return Y[a]||Y.base}var _={getGlobOptionsFor:J||void 0,SCAN_PATTERNS:w||void 0,getPatternsFor:V||void 0,I18N_PATHS:T||void 0},y={error:(a,e)=>{},warn:(a,e)=>{},info:a=>{}};function X(a,e){return a().catch(t=>{throw new Error(`${e}: ${t instanceof Error?t.message:String(t)}`)})}var Z={CLI:"packages/cli",COMPONENTS:"packages/core/components",CONFIG:"packages/core/config",CORE:"packages/core",CRUD:"packages/core/crud",FEATURES:"packages/features",HOOKS:"packages/core/hooks",I18N:"packages/core/i18n",SCHEMAS:"packages/core/schemas",STORES:"packages/core/stores",TEMPLATES:"packages/templates",TOOLING:"packages/tooling",TYPES:"packages/core/types",UI:"packages/ui",UTILS:"packages/core/utils",AUTH:"packages/features/auth",BILLING:"packages/features/billing",OAUTH:"packages/features/oauth",FIREBASE:"packages/providers/firebase",FUNCTIONS:"packages/functions"},z=class a{static _instance=null;options;_repoRoot;_appRoot=null;static getInstance(e={}){return a._instance||(a._instance=new a(e)),a._instance}static _reset(){a._instance=null}constructor(e={}){if(a._instance)return a._instance;this.options={maxLevels:e.maxLevels??10,customMarkers:e.customMarkers||[],cache:e.cache??!1,debug:e.debug??!1};try{let t=process.cwd();if(!t)throw new Error("PathResolver: process.cwd() returned undefined. This should never happen.");this._repoRoot=this._findRepoRoot(t)}catch(t){throw new Error(`PathResolver constructor failed: ${t instanceof Error?t.message:String(t)}. cwd: ${process.cwd()}`)}this._appRoot=null,a._instance=this}normalizePath(e){if(!e)return"";try{return le(e).split(q).join("/")}catch{return String(e).split(q).join("/")}}getRelativePath(e){let t=this.getAppRoot(),o=K(t,e);return this.normalizePath(o)}getBasename(e){if(!e)return"";let o=this.normalizePath(e).split("/");return o[o.length-1]||""}getDirname(e){return e?this.normalizePath(x(e)):""}resolvePackage(e,t=null){try{let o=t||this.getAppRoot(),s=ce(S(o,"package.json")).resolve(e);return this.normalizePath(s)}catch{return null}}resolveFrameworkPackage(e,t=null){let o=this.resolvePackage(`${e}/package.json`,t);if(o)return this.getDirname(o);if(this.isMonorepo()&&e.startsWith("@donotdev/")){let r=e.replace("@donotdev/",""),c=this.resolveRepoPath(`packages/${r}`);if(this.pathExists(c))return c;if(["auth","billing","crud","oauth"].includes(r)){let l=this.resolveRepoPath(`packages/features/${r}`);if(this.pathExists(l))return l}if(r==="firebase"){let l=this.resolveRepoPath(`packages/providers/${r}`);if(this.pathExists(l))return l}}let n=this.resolveAppPath(`node_modules/${e}`);if(this.pathExists(n))return n;let s=this.resolveRepoPath(`node_modules/${e}`);return this.pathExists(s)?s:null}resolvePackageAsset(e,t=null){return this.resolvePackage(e,t)}resolveAppPath(e){let t=this.getAppRoot(),o=O(t,e);return this.normalizePath(o)}resolveRepoPath(e){let t=this.getRepoRoot(),o=this.normalizePath(e),n=O(t,o);return this.normalizePath(n)}resolvePath(e,t){let o=this.normalizePath(t),n=this.normalizePath(e),s=O(o,n);return this.normalizePath(s)}createImportPath(e){return"./"+this.getRelativePath(e)}getFileInfo(e){try{let t=h.statSync(e);return{absolutePath:this.normalizePath(e),relativePath:this.getRelativePath(e),importPath:this.createImportPath(e),size:t.size,isFile:t.isFile(),isDirectory:t.isDirectory()}}catch{return null}}_detectFormat(e,t){return t&&t!=="auto"?t:ue(e).toLowerCase()===".json"?"json":"text"}async read(e,t={}){let{format:o="auto",encoding:n="utf8"}=t,s=this._detectFormat(e,o);try{if(s==="buffer")return await h.promises.readFile(e);let r=await h.promises.readFile(e,n),c=this.stripBom(r);return s==="json"?JSON.parse(c):c}catch(r){return this.options.debug&&y.warn(`Failed to read file: ${e}`,r),null}}readSync(e,t={}){let{format:o="auto",encoding:n="utf8"}=t,s=this._detectFormat(e,o);try{if(s==="buffer")return h.readFileSync(e);let r=h.readFileSync(e,n),c=this.stripBom(r);return s==="json"?JSON.parse(c):c}catch(r){return this.options.debug&&y.warn(`Failed to read file: ${e}`,r),null}}async write(e,t,o={}){let{format:n="auto",overwrite:s=!1,dryRun:r=!1,verbose:c=!1}=o,l=this.normalizePath(e),f=this.normalizePath(x(l)),i=this.pathExists(l);if(i&&!s)return c&&y.info(`Skipping existing file: ${l}`),!1;if(r)return y.info(`[DRY RUN] Would write file: ${l}`),!0;try{await h.promises.mkdir(f,{recursive:!0})}catch(m){if(m?.code!=="EEXIST")throw m}let u=this._detectFormat(e,n),d;Buffer.isBuffer(t)?d=t:u==="json"&&typeof t=="object"?d=JSON.stringify(t,null,2):d=String(t);try{return await X(async()=>(Buffer.isBuffer(d)?await h.promises.writeFile(l,d):await h.promises.writeFile(l,d,"utf8"),c&&y.info(`${i?"Updated":"Created"} file: ${l}`),!0),`Failed to write file: ${l}`)}catch{return!1}}writeSync(e,t,o={}){let{format:n="auto",overwrite:s=!1,dryRun:r=!1,verbose:c=!1}=o,l=this.normalizePath(e),f=this.normalizePath(x(l)),i=this.pathExists(l);if(i&&!s)return c&&y.info(`Skipping existing file: ${l}`),!1;if(r)return y.info(`[DRY RUN] Would write file: ${l}`),!0;try{h.mkdirSync(f,{recursive:!0})}catch(m){if(m?.code!=="EEXIST")throw m}let u=this._detectFormat(e,n),d;Buffer.isBuffer(t)?d=t:u==="json"&&typeof t=="object"?d=JSON.stringify(t,null,2):d=String(t);try{return Buffer.isBuffer(d)?h.writeFileSync(l,d):h.writeFileSync(l,d,"utf8"),c&&y.info(`${i?"Updated":"Created"} file: ${l}`),!0}catch(m){throw new Error(`Failed to write file: ${l}: ${m instanceof Error?m.message:String(m)}`)}}async copy(e,t,o={}){let{overwrite:n=!1,dryRun:s=!1,verbose:r=!1}=o,c=this.normalizePath(t),l=this.pathExists(c);if(l&&!n)return r&&y.info(`Skipping existing file: ${c}`),!1;if(s)return y.info(`[DRY RUN] Would copy file: ${c}`),!0;let f=this.normalizePath(x(c));try{await h.promises.mkdir(f,{recursive:!0})}catch(i){if(i?.code!=="EEXIST")throw i}try{return await X(async()=>(await h.promises.copyFile(e,c),r&&y.info(`${l?"Updated":"Created"} file: ${c}`),!0),`Failed to copy file from ${e} to ${c}`)}catch{return!1}}copySync(e,t,o={}){let{overwrite:n=!1,dryRun:s=!1,verbose:r=!1}=o,c=this.normalizePath(t),l=this.pathExists(c);if(l&&!n)return r&&y.info(`Skipping existing file: ${c}`),!1;if(s)return y.info(`[DRY RUN] Would copy file: ${c}`),!0;let f=this.normalizePath(x(c));try{h.mkdirSync(f,{recursive:!0})}catch(i){if(i?.code!=="EEXIST")throw i}try{return h.copyFileSync(e,c),r&&y.info(`${l?"Updated":"Created"} file: ${c}`),!0}catch{return!1}}pathExists(e,t=!1){try{return h.existsSync(e)}catch(o){return t||y.error(`Error checking path existence: ${e}`,o),!1}}mkdir(e){try{let t=e.startsWith("/")||e.match(/^[A-Z]:/)?this.normalizePath(e):this.resolveAppPath(e);return h.existsSync(t)||h.mkdirSync(t,{recursive:!0}),!0}catch{return!1}}readdirSync(e,t){try{return h.readdirSync(e,t)}catch(o){return this.options.debug&&y.warn(`Failed to read directory: ${e}`,o),t&&typeof t=="object"&&"withFileTypes"in t&&t.withFileTypes?[]:[]}}statSync(e){try{return h.statSync(e)}catch(t){return this.options.debug&&y.warn(`Failed to stat file: ${e}`,t),null}}realpathSync(e){return h.realpathSync(e)}watch(e,t,o){return h.watch(e,t,o)}lstatSync(e){try{return h.lstatSync(e)}catch(t){return this.options.debug&&y.warn(`Failed to lstat file: ${e}`,t),null}}async ensureDir(e){try{await h.promises.mkdir(e,{recursive:!0})}catch(t){if(t?.code!=="EEXIST")throw t}}ensureDirSync(e){try{h.mkdirSync(e,{recursive:!0})}catch(t){if(t?.code!=="EEXIST")throw t}}async remove(e){await h.promises.rm(e,{recursive:!0,force:!0})}removeSync(e){h.rmSync(e,{recursive:!0,force:!0})}async readdir(e,t){return h.promises.readdir(e,t)}stripBom(e){return e.charCodeAt(0)===65279?e.slice(1):e}getRepoRoot(){return this._repoRoot||process.cwd()}getAppRoot(){return this._appRoot?this._appRoot:this._repoRoot}setAppRoot(e){if(!e)throw new Error("PathResolver.setAppRoot: root cannot be undefined or null");this._appRoot=this.normalizePath(e)}isMonorepo(){let e=S(this._repoRoot,"packages");return this.pathExists(e)}isWithinApp(e){let t=this.normalizePath(O(e)),o=this.getAppRoot(),n=K(o,t),s=this.normalizePath(n);return!s.startsWith("../")&&!s.startsWith("/")}async findFiles(e,t,o={}){let n=this.normalizePath(S(e,t)),s=this.getAppRoot(),r=this.normalizePath(s),c=n.startsWith(r)?n.slice(r.length+1):n,l={absolute:!0,onlyFiles:!0,braceExpansion:!0,extglob:!0,globstar:!0,cwd:s,ignore:_.SCAN_PATTERNS?.globalIgnore||["**/node_modules/**","**/dist/**","**/build/**","**/.git/**"]};return await this._globWithNormalization([c],{...l,...o})}clearCache(){}async _resolveFrameworkI18nPattern(e){let t=_.I18N_PATHS;if(!t)return null;let o=e.replace(t.SOURCE_ROOT+"/",""),n=this.resolveFrameworkPackage("@donotdev/core");if(!n)return null;let s=this.normalizePath(S(n,t.PUBLISHED_ROOT,o)),r=s.replace(/\/[^/]*\*.*$/,"");return this.pathExists(r),s}async _globWithNormalization(e,t){return(await fe(e,t)).map(n=>{let s=typeof n=="string"?n:n.path;return this.normalizePath(s)})}async resolveFiles(e,t="css"){if(!e||typeof e!="object")return{frameworkFiles:[],consumerFiles:[]};if(t==="i18n")return{frameworkFiles:[],consumerFiles:[]};if(Array.isArray(e.framework)||(e.framework=[]),!Array.isArray(e.consumer))return{frameworkFiles:[],consumerFiles:[]};let o=[...e.framework,...e.consumer];for(let i of o)if(typeof i!="string"||i.trim()==="")return{frameworkFiles:[],consumerFiles:[]};let n=this.getAppRoot(),s=_.getGlobOptionsFor?_.getGlobOptionsFor(t):{ignore:["**/node_modules/**","**/dist/**","**/build/**"]},r=this.normalizePath(n),c=e.framework.map(i=>{let u=this.normalizePath(i);return u.startsWith(r)?u.slice(r.length+1):u}),l=e.consumer.map(i=>{let u=this.normalizePath(i);return u.startsWith(r)?u.slice(r.length+1):u}),f={...s,onlyFiles:!0,absolute:!0,braceExpansion:!0,extglob:!0,globstar:!0,cwd:n};try{let i=c.length>0?await this._globWithNormalization(c,f):[],u=await this._globWithNormalization(l,f);return{frameworkFiles:i,consumerFiles:u}}catch{return this.options.debug,{frameworkFiles:[],consumerFiles:[]}}}async resolvePatterns(e){if(!_.getPatternsFor)return{framework:[],consumer:[],all:[]};let t=this.getAppRoot(),o=this.getRepoRoot();if(e==="i18n"&&(!t||t===o))throw new Error(`Cannot resolve i18n patterns: appRoot not set (appRoot: ${t}, repoRoot: ${o}). Ensure configResolved hook has run before discovery.`);let n=_.getPatternsFor(e),s=this.isMonorepo();if(e==="i18n"){let l=n,f={eager:l.eager.map(i=>i.startsWith("!")?"!"+this.resolveAppPath(i.slice(1)):this.resolveAppPath(i)),lazy:l.lazy.map(i=>i.startsWith("!")?"!"+this.resolveAppPath(i.slice(1)):this.resolveAppPath(i)),framework:{eager:s?(l.framework?.eager||[]).map(i=>this.resolveRepoPath(i)).filter(Boolean):await Promise.all((l.framework?.eager||[]).map(i=>this._resolveFrameworkI18nPattern(i))).then(i=>i.filter(Boolean)),lazy:s?(l.framework?.lazy||[]).map(i=>this.resolveRepoPath(i)).filter(Boolean):await Promise.all((l.framework?.lazy||[]).map(i=>this._resolveFrameworkI18nPattern(i))).then(i=>i.filter(Boolean))},all:[]};return f.all=[...f.eager,...f.lazy,...f.framework.eager,...f.framework.lazy],f}let r=n,c={framework:s?(r.framework||[]).map(l=>this.resolveRepoPath(l)).filter(Boolean):[],consumer:(r.consumer||[]).map(l=>this.resolveAppPath(l)),all:[]};return c.all=[...c.consumer,...c.framework],c}getEmptyModulePath(){return this.getEmptyCjsModulePath().replace(/\.cjs$/,".js")}getEmptyFlagModulePath(){let e=x(pe(import.meta.url));return this.normalizePath(O(e,"emptyFlag.js"))}getEmptyCjsModulePath(){let e=this.resolvePackage("@donotdev/core/empty");if(!e)throw new Error("Cannot resolve @donotdev/core/empty \u2014 package setup is broken");return e}_findRepoRoot(e){let t=this.normalizePath(e),o=0,n=this.options.maxLevels;for(;o<n;){let s=this.normalizePath(S(t,Z.TOOLING)),r=this.normalizePath(S(t,Z.CORE));if(this.pathExists(s)&&this.pathExists(r))return t;let c=S(t,"apps");if(this.pathExists(c)&&this.statSync(c)?.isDirectory())return this.normalizePath(t);let l=this.normalizePath(S(t,"package.json"));if(this.pathExists(l)&&this.normalizePath(x(t))===t)return t;let f=this.normalizePath(x(t));if(f===t)break;t=f,o++}return this.normalizePath(e)}};function N(a={}){let{entry:e="src/index.ts",outDir:t="lib",minify:o=!1,sourcemap:n=!0,platform:s="firebase",workspace:r,bundleWorkspaceDeps:c=!1,importFramework:l=!1,external:f=!1,...i}=a,u=z.getInstance(),d=H(r),m={entryPoints:[e],bundle:!0,platform:"node",target:"node20",format:"esm",outdir:t,outExtension:{".js":".js"},minify:o,sourcemap:n,metafile:!0,logLevel:"info",loader:{".ts":"ts",".tsx":"tsx",".css":"empty"},keepNames:!0,treeShaking:!0,...i};c&&Object.keys(d).length>0&&(m.alias=Object.fromEntries(Object.entries(d).map(([v,p])=>[v,u.normalizePath(p)]))),m.mainFields=["module","main"],m.conditions=["import","module","node"];let j=["fs","path","crypto","util","stream","events","buffer","url","querystring","http","https","zlib","os","child_process","assert","constants","domain","punycode","string_decoder","timers","tty","vm","worker_threads","perf_hooks","async_hooks"],I=[];if(c)try{let v=r?.root||process.cwd(),p=process.cwd(),g=10;for(let k=0;k<g;k++){let R=u.normalizePath(`${p}/package.json`);if(u.pathExists(R)){let b=u.readSync(R,{format:"json"});if(b&&Array.isArray(b.workspaces)){v=u.normalizePath(p);for(let F of b.workspaces)F==="apps/*"||F==="functions"||!F.includes("*")&&!F.includes("/")&&I.push(F);break}}let E=u.getDirname(p);if(E===p)break;p=E}}catch{}let W={name:"external-node-modules",setup(v){v.onResolve({filter:/^firebase($|\/)/},p=>{if(p.path==="firebase-admin"||p.path.startsWith("firebase-admin/")||p.path==="firebase-functions"||p.path.startsWith("firebase-functions/"))return null;let g;if(r?.type==="dndev"&&r.root)g=u.normalizePath(`${r.root}/packages/core/config/functions/firebase-stub.js`);else{let k=import.meta.url,E=new URL(k).pathname.replace(/^\/([A-Z]:)/i,"$1"),b=u.getDirname(E);g=u.normalizePath(`${b}/firebase-stub.js`)}return{path:g}}),v.onResolve({filter:/.*/},p=>{if(p.kind==="entry-point")return null;if(p.path.match(/@donotdev\/functions\/.+/)&&c&&r?.type==="dndev"){let g=p.path.replace("@donotdev/functions/","");return{path:u.normalizePath(`${r.root}/packages/functions/src/${g}/index.ts`)}}if(p.path==="@donotdev/utils")return r?.type==="dndev"?{path:u.normalizePath(`${r.root}/packages/core/utils/src/server/index.ts`)}:v.resolve("@donotdev/utils/server",{kind:p.kind,resolveDir:p.resolveDir});if(p.path.match(/@donotdev\/utils\/.+/)&&r?.type==="dndev"){let g=p.path.replace("@donotdev/utils/","");return{path:u.normalizePath(`${r.root}/packages/core/utils/src/${g}/index.ts`)}}if(p.path==="@donotdev/supabase")return r?.type==="dndev"?{path:u.normalizePath(`${r.root}/packages/providers/supabase/src/server/index.ts`)}:v.resolve("@donotdev/supabase/server",{kind:p.kind,resolveDir:p.resolveDir});if(p.path==="@donotdev/core")return r?.type==="dndev"?{path:u.normalizePath(`${r.root}/packages/core/server.ts`)}:v.resolve("@donotdev/core/server",{kind:p.kind,resolveDir:p.resolveDir});if(p.path.match(/@donotdev\/core\/.+/)&&c&&r?.type==="dndev"){let g=p.path.replace("@donotdev/core/","");return{path:u.normalizePath(`${r.root}/packages/core/${g}.ts`)}}if(p.path==="firebase-admin"||p.path.startsWith("firebase-admin/")||p.path==="firebase-functions"||p.path.startsWith("firebase-functions/"))return{path:p.path,external:!0};if(p.path.match(/@donotdev\/core\/.+/)&&c&&r?.type==="dndev"){let g=p.path.replace("@donotdev/core/","");return{path:u.normalizePath(`${r.root}/packages/core/${g}.ts`)}}if(p.path.startsWith("@donotdev/")||p.path==="valibot"||p.path.startsWith("valibot/"))return null;if(I.length>0){let g=p.path.split("/")[0];if(I.includes(g))return null}return p.path.startsWith(".")||p.path.startsWith("/")?null:{path:p.path,external:!0}})}};if(m.external=[...j,"firebase-admin","firebase-functions"],m.plugins=[W,...m.plugins||[]],m.define={"process.env.NODE_ENV":JSON.stringify(process.env.NODE_ENV||"production"),...m.define||{}},l&&r.type==="dndev"){let v=r.root,p=u.normalizePath(`${v}/functions/lib`);m.alias={...m.alias,"@donotdev/functions":p}}if(s==="framework"){let v=z.getInstance(),p=r?.root?v.normalizePath(`${r.root}/packages/functions`):process.cwd(),g=v.normalizePath(`${p}/package.json`),k=v.readSync(g,{format:"json"});if(k?.exports){let R={};for(let[,E]of Object.entries(k.exports)){let b=E?.import||E?.default||(typeof E=="string"?E:null);if(!b||!b.endsWith(".ts"))continue;let F=b.replace(/^\.\/src\//,"").replace(/\.ts$/,"");R[F]=b}Object.keys(R).length>0&&(m.entryPoints=R)}}return m}import{readFileSync as C,writeFileSync as B,existsSync as L}from"fs";import"path";var U=["create","get","list","listCard","update","delete"];function Q(a,e=0){let t=" ".repeat(e),o="";for(let[n,s]of Object.entries(a))if(s!=null)if(typeof s=="object"&&!Array.isArray(s))Object.keys(s).length===0?o+=`${t}${n}: {}
1
+ import z from"node:fs";import P from"node:path";import{fileURLToPath as re}from"node:url";var se=re(import.meta.url),ye=P.dirname(se);function T(){let a=process.cwd(),e=10;for(let t=0;t<e;t++){let o=P.join(a,"package.json");if(z.existsSync(o))try{let s=JSON.parse(z.readFileSync(o,"utf8")),r=s.workspaces&&Array.isArray(s.workspaces);if(r&&s.workspaces.some(i=>i==="packages/**"||i.startsWith("packages/"))&&(z.existsSync(P.join(a,"packages","core"))||z.existsSync(P.join(a,"packages","functions"))))return{type:"dndev",root:a};if(r&&s.workspaces.some(i=>i.includes("dndev/packages"))){let u=s.workspaces.find(m=>m.includes("dndev/packages")).replace(/\/packages.*$/,""),d=P.resolve(a,u);if(z.existsSync(P.join(d,"packages","core")))return{type:"dndev",root:d}}}catch{}let n=P.dirname(a);if(n===a)break;a=n}return{type:"npm",root:process.cwd()}}function oe(a){return a.type==="dndev"?a.root:null}function M(a){let e={};if(a.type==="dndev"){let t=oe(a);t&&(e["@donotdev/types"]=P.join(t,"packages","core","types","src"),e["@donotdev/functions"]=P.join(t,"packages","functions","src"),e["@donotdev/utils"]=P.join(t,"packages","core","utils","src"),e["@donotdev/schemas"]=P.join(t,"packages","core","schemas","src"),e["@donotdev/core"]=P.join(t,"packages","core"))}return e}import*as h from"node:fs";import"node:fs";import{createRequire as ie}from"node:module";import{resolve as $,join as F,dirname as _,relative as V,normalize as ae,sep as J,extname as ce}from"node:path";import{fileURLToPath as le}from"node:url";import ue from"fast-glob";var N={SOURCE_ROOT:"packages/core/i18n",SOURCE_LOCALES:"packages/core/i18n/locales",SOURCE_EAGER:"packages/core/i18n/locales/eager",SOURCE_LAZY:"packages/core/i18n/locales/lazy",PUBLISHED_ROOT:"i18n",PUBLISHED_LOCALES:"i18n/locales",PUBLISHED_EAGER:"i18n/locales/eager",PUBLISHED_LAZY:"i18n/locales/lazy"},R={routes:{consumer:["src/**/*Page.tsx","src/pages/**/*Page.tsx"],exclude:["**/node_modules/**","**/dist/**","**/build/**","**/*.test.tsx","**/*.stories.tsx"],extensions:[".tsx"]},css:{consumer:["src/**/*.css"],themes:["src/**/*.css"],extensions:[".css",".scss",".sass"],framework:["packages/ui/src/**/*.css","packages/core/components/src/**/*.css","packages/core/templates/src/**/*.css"]},i18n:{eager:["src/locales/*_*.json"],lazy:["src/**/locales/*_*.json","!src/locales/*_*.json","../../entities/locales/*_*.json"],additional:[],framework:{eager:[`${N.SOURCE_EAGER}/*_*.json`],lazy:[`${N.SOURCE_LAZY}/*_*.json`]},extensions:[".json"]},assets:{consumer:["public/**/*"],fallback:["manifest.json"],modern:["logo.svg","favicon.svg","apple-touch-icon.png","android-chrome-192x192.png","android-chrome-512x512.png"],patterns:["favicon.svg","favicon.ico","favicon-*.png","logo.svg","logo.png","logo.webp","logo.avif","apple-touch-icon*.png","android-chrome-*.png","manifest.json"],fonts:["fonts/**/*.woff2","fonts/**/*.woff","fonts/**/*.ttf"],framework:["packages/ui/assets/**/*"]},pwa:{consumer:["public/manifest.json","public/service-worker.js","public/sw.js","public/icon-192x192.png","public/icon-512x512.png","public/favicon.ico","public/favicon.svg","public/apple-touch-icon.png","public/logo.svg"],exclude:["**/node_modules/**","**/dist/**","**/build/**"],extensions:[".json",".js",".png",".svg",".ico"],framework:["packages/ui/assets/**/*"]},globalIgnore:["**/node_modules/**","**/dist/**","**/build/**","**/.git/**","**/coverage/**","**/test/**"]};var G={base:{absolute:!0,onlyFiles:!0,ignore:R.globalIgnore},css:{absolute:!0,onlyFiles:!0,ignore:[...R.globalIgnore,"**/*.test.css"]},routes:{absolute:!0,onlyFiles:!0,ignore:[...R.globalIgnore,"**/*.test.tsx","**/*.stories.tsx"]},i18n:{absolute:!0,onlyFiles:!0,ignore:R.globalIgnore},assets:{absolute:!0,onlyFiles:!0,ignore:R.globalIgnore}};function H(a,e=null){let t=R[a];if(!t)throw new Error(`Unknown pattern type: ${a}`);return e&&t.framework?{...t,framework:t.framework.map(o=>`${e}/${o}`)}:t}function Y(a){return G[a]||G.base}var O={getGlobOptionsFor:Y||void 0,SCAN_PATTERNS:R||void 0,getPatternsFor:H||void 0,I18N_PATHS:N||void 0},y={error:(a,e)=>{},warn:(a,e)=>{},info:a=>{}};function K(a,e){return a().catch(t=>{throw new Error(`${e}: ${t instanceof Error?t.message:String(t)}`)})}var q={CLI:"packages/cli",COMPONENTS:"packages/core/components",CONFIG:"packages/core/config",CORE:"packages/core",CRUD:"packages/core/crud",FEATURES:"packages/features",HOOKS:"packages/core/hooks",I18N:"packages/core/i18n",SCHEMAS:"packages/core/schemas",STORES:"packages/core/stores",TEMPLATES:"packages/templates",TOOLING:"packages/tooling",TYPES:"packages/core/types",UI:"packages/ui",UTILS:"packages/core/utils",AUTH:"packages/features/auth",BILLING:"packages/features/billing",OAUTH:"packages/features/oauth",FIREBASE:"packages/providers/firebase",FUNCTIONS:"packages/functions"},S=class a{static _instance=null;options;_repoRoot;_appRoot=null;static getInstance(e={}){return a._instance||(a._instance=new a(e)),a._instance}static _reset(){a._instance=null}constructor(e={}){if(a._instance)return a._instance;this.options={maxLevels:e.maxLevels??10,customMarkers:e.customMarkers||[],cache:e.cache??!1,debug:e.debug??!1};try{let t=process.cwd();if(!t)throw new Error("PathResolver: process.cwd() returned undefined. This should never happen.");this._repoRoot=this._findRepoRoot(t)}catch(t){throw new Error(`PathResolver constructor failed: ${t instanceof Error?t.message:String(t)}. cwd: ${process.cwd()}`)}this._appRoot=null,a._instance=this}normalizePath(e){if(!e)return"";try{return ae(e).split(J).join("/")}catch{return String(e).split(J).join("/")}}getRelativePath(e){let t=this.getAppRoot(),o=V(t,e);return this.normalizePath(o)}getBasename(e){if(!e)return"";let o=this.normalizePath(e).split("/");return o[o.length-1]||""}getDirname(e){return e?this.normalizePath(_(e)):""}resolvePackage(e,t=null){try{let o=t||this.getAppRoot(),s=ie(F(o,"package.json")).resolve(e);return this.normalizePath(s)}catch{return null}}resolveFrameworkPackage(e,t=null){let o=this.resolvePackage(`${e}/package.json`,t);if(o)return this.getDirname(o);if(this.isMonorepo()&&e.startsWith("@donotdev/")){let r=e.replace("@donotdev/",""),c=this.resolveRepoPath(`packages/${r}`);if(this.pathExists(c))return c;if(["auth","billing","crud","oauth"].includes(r)){let l=this.resolveRepoPath(`packages/features/${r}`);if(this.pathExists(l))return l}if(r==="firebase"){let l=this.resolveRepoPath(`packages/providers/${r}`);if(this.pathExists(l))return l}}let n=this.resolveAppPath(`node_modules/${e}`);if(this.pathExists(n))return n;let s=this.resolveRepoPath(`node_modules/${e}`);return this.pathExists(s)?s:null}resolvePackageAsset(e,t=null){return this.resolvePackage(e,t)}resolveAppPath(e){let t=this.getAppRoot(),o=$(t,e);return this.normalizePath(o)}resolveRepoPath(e){let t=this.getRepoRoot(),o=this.normalizePath(e),n=$(t,o);return this.normalizePath(n)}resolvePath(e,t){let o=this.normalizePath(t),n=this.normalizePath(e),s=$(o,n);return this.normalizePath(s)}createImportPath(e){return"./"+this.getRelativePath(e)}getFileInfo(e){try{let t=h.statSync(e);return{absolutePath:this.normalizePath(e),relativePath:this.getRelativePath(e),importPath:this.createImportPath(e),size:t.size,isFile:t.isFile(),isDirectory:t.isDirectory()}}catch{return null}}_detectFormat(e,t){return t&&t!=="auto"?t:ce(e).toLowerCase()===".json"?"json":"text"}async read(e,t={}){let{format:o="auto",encoding:n="utf8"}=t,s=this._detectFormat(e,o);try{if(s==="buffer")return await h.promises.readFile(e);let r=await h.promises.readFile(e,n),c=this.stripBom(r);return s==="json"?JSON.parse(c):c}catch(r){return this.options.debug&&y.warn(`Failed to read file: ${e}`,r),null}}readSync(e,t={}){let{format:o="auto",encoding:n="utf8"}=t,s=this._detectFormat(e,o);try{if(s==="buffer")return h.readFileSync(e);let r=h.readFileSync(e,n),c=this.stripBom(r);return s==="json"?JSON.parse(c):c}catch(r){return this.options.debug&&y.warn(`Failed to read file: ${e}`,r),null}}async write(e,t,o={}){let{format:n="auto",overwrite:s=!1,dryRun:r=!1,verbose:c=!1}=o,l=this.normalizePath(e),f=this.normalizePath(_(l)),i=this.pathExists(l);if(i&&!s)return c&&y.info(`Skipping existing file: ${l}`),!1;if(r)return y.info(`[DRY RUN] Would write file: ${l}`),!0;try{await h.promises.mkdir(f,{recursive:!0})}catch(m){if(m?.code!=="EEXIST")throw m}let u=this._detectFormat(e,n),d;Buffer.isBuffer(t)?d=t:u==="json"&&typeof t=="object"?d=JSON.stringify(t,null,2):d=String(t);try{return await K(async()=>(Buffer.isBuffer(d)?await h.promises.writeFile(l,d):await h.promises.writeFile(l,d,"utf8"),c&&y.info(`${i?"Updated":"Created"} file: ${l}`),!0),`Failed to write file: ${l}`)}catch{return!1}}writeSync(e,t,o={}){let{format:n="auto",overwrite:s=!1,dryRun:r=!1,verbose:c=!1}=o,l=this.normalizePath(e),f=this.normalizePath(_(l)),i=this.pathExists(l);if(i&&!s)return c&&y.info(`Skipping existing file: ${l}`),!1;if(r)return y.info(`[DRY RUN] Would write file: ${l}`),!0;try{h.mkdirSync(f,{recursive:!0})}catch(m){if(m?.code!=="EEXIST")throw m}let u=this._detectFormat(e,n),d;Buffer.isBuffer(t)?d=t:u==="json"&&typeof t=="object"?d=JSON.stringify(t,null,2):d=String(t);try{return Buffer.isBuffer(d)?h.writeFileSync(l,d):h.writeFileSync(l,d,"utf8"),c&&y.info(`${i?"Updated":"Created"} file: ${l}`),!0}catch(m){throw new Error(`Failed to write file: ${l}: ${m instanceof Error?m.message:String(m)}`)}}async copy(e,t,o={}){let{overwrite:n=!1,dryRun:s=!1,verbose:r=!1}=o,c=this.normalizePath(t),l=this.pathExists(c);if(l&&!n)return r&&y.info(`Skipping existing file: ${c}`),!1;if(s)return y.info(`[DRY RUN] Would copy file: ${c}`),!0;let f=this.normalizePath(_(c));try{await h.promises.mkdir(f,{recursive:!0})}catch(i){if(i?.code!=="EEXIST")throw i}try{return await K(async()=>(await h.promises.copyFile(e,c),r&&y.info(`${l?"Updated":"Created"} file: ${c}`),!0),`Failed to copy file from ${e} to ${c}`)}catch{return!1}}copySync(e,t,o={}){let{overwrite:n=!1,dryRun:s=!1,verbose:r=!1}=o,c=this.normalizePath(t),l=this.pathExists(c);if(l&&!n)return r&&y.info(`Skipping existing file: ${c}`),!1;if(s)return y.info(`[DRY RUN] Would copy file: ${c}`),!0;let f=this.normalizePath(_(c));try{h.mkdirSync(f,{recursive:!0})}catch(i){if(i?.code!=="EEXIST")throw i}try{return h.copyFileSync(e,c),r&&y.info(`${l?"Updated":"Created"} file: ${c}`),!0}catch{return!1}}pathExists(e,t=!1){try{return h.existsSync(e)}catch(o){return t||y.error(`Error checking path existence: ${e}`,o),!1}}mkdir(e){try{let t=e.startsWith("/")||e.match(/^[A-Z]:/)?this.normalizePath(e):this.resolveAppPath(e);return h.existsSync(t)||h.mkdirSync(t,{recursive:!0}),!0}catch{return!1}}readdirSync(e,t){try{return h.readdirSync(e,t)}catch(o){return this.options.debug&&y.warn(`Failed to read directory: ${e}`,o),t&&typeof t=="object"&&"withFileTypes"in t&&t.withFileTypes?[]:[]}}statSync(e){try{return h.statSync(e)}catch(t){return this.options.debug&&y.warn(`Failed to stat file: ${e}`,t),null}}realpathSync(e){return h.realpathSync(e)}watch(e,t,o){return h.watch(e,t,o)}lstatSync(e){try{return h.lstatSync(e)}catch(t){return this.options.debug&&y.warn(`Failed to lstat file: ${e}`,t),null}}async ensureDir(e){try{await h.promises.mkdir(e,{recursive:!0})}catch(t){if(t?.code!=="EEXIST")throw t}}ensureDirSync(e){try{h.mkdirSync(e,{recursive:!0})}catch(t){if(t?.code!=="EEXIST")throw t}}async remove(e){await h.promises.rm(e,{recursive:!0,force:!0})}removeSync(e){h.rmSync(e,{recursive:!0,force:!0})}async readdir(e,t){return h.promises.readdir(e,t)}stripBom(e){return e.charCodeAt(0)===65279?e.slice(1):e}getRepoRoot(){return this._repoRoot||process.cwd()}getAppRoot(){return this._appRoot?this._appRoot:this._repoRoot}setAppRoot(e){if(!e)throw new Error("PathResolver.setAppRoot: root cannot be undefined or null");this._appRoot=this.normalizePath(e)}isMonorepo(){let e=F(this._repoRoot,"packages");return this.pathExists(e)}isWithinApp(e){let t=this.normalizePath($(e)),o=this.getAppRoot(),n=V(o,t),s=this.normalizePath(n);return!s.startsWith("../")&&!s.startsWith("/")}async findFiles(e,t,o={}){let n=this.normalizePath(F(e,t)),s=this.getAppRoot(),r=this.normalizePath(s),c=n.startsWith(r)?n.slice(r.length+1):n,l={absolute:!0,onlyFiles:!0,braceExpansion:!0,extglob:!0,globstar:!0,cwd:s,ignore:O.SCAN_PATTERNS?.globalIgnore||["**/node_modules/**","**/dist/**","**/build/**","**/.git/**"]};return await this._globWithNormalization([c],{...l,...o})}clearCache(){}async _resolveFrameworkI18nPattern(e){let t=O.I18N_PATHS;if(!t)return null;let o=e.replace(t.SOURCE_ROOT+"/",""),n=this.resolveFrameworkPackage("@donotdev/core");if(!n)return null;let s=this.normalizePath(F(n,t.PUBLISHED_ROOT,o)),r=s.replace(/\/[^/]*\*.*$/,"");return this.pathExists(r),s}async _globWithNormalization(e,t){return(await ue(e,t)).map(n=>{let s=typeof n=="string"?n:n.path;return this.normalizePath(s)})}async resolveFiles(e,t="css"){if(!e||typeof e!="object")return{frameworkFiles:[],consumerFiles:[]};if(t==="i18n")return{frameworkFiles:[],consumerFiles:[]};if(Array.isArray(e.framework)||(e.framework=[]),!Array.isArray(e.consumer))return{frameworkFiles:[],consumerFiles:[]};let o=[...e.framework,...e.consumer];for(let i of o)if(typeof i!="string"||i.trim()==="")return{frameworkFiles:[],consumerFiles:[]};let n=this.getAppRoot(),s=O.getGlobOptionsFor?O.getGlobOptionsFor(t):{ignore:["**/node_modules/**","**/dist/**","**/build/**"]},r=this.normalizePath(n),c=e.framework.map(i=>{let u=this.normalizePath(i);return u.startsWith(r)?u.slice(r.length+1):u}),l=e.consumer.map(i=>{let u=this.normalizePath(i);return u.startsWith(r)?u.slice(r.length+1):u}),f={...s,onlyFiles:!0,absolute:!0,braceExpansion:!0,extglob:!0,globstar:!0,cwd:n};try{let i=c.length>0?await this._globWithNormalization(c,f):[],u=await this._globWithNormalization(l,f);return{frameworkFiles:i,consumerFiles:u}}catch{return this.options.debug,{frameworkFiles:[],consumerFiles:[]}}}async resolvePatterns(e){if(!O.getPatternsFor)return{framework:[],consumer:[],all:[]};let t=this.getAppRoot(),o=this.getRepoRoot();if(e==="i18n"&&(!t||t===o))throw new Error(`Cannot resolve i18n patterns: appRoot not set (appRoot: ${t}, repoRoot: ${o}). Ensure configResolved hook has run before discovery.`);let n=O.getPatternsFor(e),s=this.isMonorepo();if(e==="i18n"){let l=n,f={eager:l.eager.map(i=>i.startsWith("!")?"!"+this.resolveAppPath(i.slice(1)):this.resolveAppPath(i)),lazy:l.lazy.map(i=>i.startsWith("!")?"!"+this.resolveAppPath(i.slice(1)):this.resolveAppPath(i)),framework:{eager:s?(l.framework?.eager||[]).map(i=>this.resolveRepoPath(i)).filter(Boolean):await Promise.all((l.framework?.eager||[]).map(i=>this._resolveFrameworkI18nPattern(i))).then(i=>i.filter(Boolean)),lazy:s?(l.framework?.lazy||[]).map(i=>this.resolveRepoPath(i)).filter(Boolean):await Promise.all((l.framework?.lazy||[]).map(i=>this._resolveFrameworkI18nPattern(i))).then(i=>i.filter(Boolean))},all:[]};return f.all=[...f.eager,...f.lazy,...f.framework.eager,...f.framework.lazy],f}let r=n,c={framework:s?(r.framework||[]).map(l=>this.resolveRepoPath(l)).filter(Boolean):[],consumer:(r.consumer||[]).map(l=>this.resolveAppPath(l)),all:[]};return c.all=[...c.consumer,...c.framework],c}getEmptyModulePath(){return this.getEmptyCjsModulePath().replace(/\.cjs$/,".js")}getEmptyFlagModulePath(){let e=_(le(import.meta.url));return this.normalizePath($(e,"emptyFlag.js"))}getEmptyCjsModulePath(){let e=this.resolvePackage("@donotdev/core/empty");if(!e)throw new Error("Cannot resolve @donotdev/core/empty \u2014 package setup is broken");return e}_findRepoRoot(e){let t=this.normalizePath(e),o=0,n=this.options.maxLevels;for(;o<n;){let s=this.normalizePath(F(t,q.TOOLING)),r=this.normalizePath(F(t,q.CORE));if(this.pathExists(s)&&this.pathExists(r))return t;let c=F(t,"apps");if(this.pathExists(c)&&this.statSync(c)?.isDirectory())return this.normalizePath(t);let l=this.normalizePath(F(t,"package.json"));if(this.pathExists(l)&&this.normalizePath(_(t))===t)return t;let f=this.normalizePath(_(t));if(f===t)break;t=f,o++}return this.normalizePath(e)}};function C(a={}){let{entry:e="src/index.ts",outDir:t="lib",minify:o=!1,sourcemap:n=!0,platform:s="firebase",workspace:r,bundleWorkspaceDeps:c=!1,importFramework:l=!1,external:f=!1,...i}=a,u=S.getInstance(),d=M(r),m={entryPoints:[e],bundle:!0,platform:"node",target:"node20",format:"esm",outdir:t,outExtension:{".js":".js"},minify:o,sourcemap:n,metafile:!0,logLevel:"info",loader:{".ts":"ts",".tsx":"tsx",".css":"empty"},keepNames:!0,treeShaking:!0,...i};c&&Object.keys(d).length>0&&(m.alias=Object.fromEntries(Object.entries(d).map(([v,p])=>[v,u.normalizePath(p)]))),m.mainFields=["module","main"],m.conditions=["import","module","node"];let I=["fs","path","crypto","util","stream","events","buffer","url","querystring","http","https","zlib","os","child_process","assert","constants","domain","punycode","string_decoder","timers","tty","vm","worker_threads","perf_hooks","async_hooks"],D=[];if(c)try{let v=r?.root||process.cwd(),p=process.cwd(),g=10;for(let k=0;k<g;k++){let x=u.normalizePath(`${p}/package.json`);if(u.pathExists(x)){let E=u.readSync(x,{format:"json"});if(E&&Array.isArray(E.workspaces)){v=u.normalizePath(p);for(let A of E.workspaces)A==="apps/*"||A==="functions"||!A.includes("*")&&!A.includes("/")&&D.push(A);break}}let w=u.getDirname(p);if(w===p)break;p=w}}catch{}let L={name:"external-node-modules",setup(v){v.onResolve({filter:/^firebase($|\/)/},p=>{if(p.path==="firebase-admin"||p.path.startsWith("firebase-admin/")||p.path==="firebase-functions"||p.path.startsWith("firebase-functions/"))return null;let g;if(r?.type==="dndev"&&r.root)g=u.normalizePath(`${r.root}/packages/core/config/functions/firebase-stub.js`);else{let k=import.meta.url,w=new URL(k).pathname.replace(/^\/([A-Z]:)/i,"$1"),E=u.getDirname(w);g=u.normalizePath(`${E}/firebase-stub.js`)}return{path:g}}),v.onResolve({filter:/.*/},p=>{if(p.kind==="entry-point")return null;if(p.path.match(/@donotdev\/functions\/.+/)&&c&&r?.type==="dndev"){let g=p.path.replace("@donotdev/functions/","");return{path:u.normalizePath(`${r.root}/packages/functions/src/${g}/index.ts`)}}if(p.path==="@donotdev/utils")return r?.type==="dndev"?{path:u.normalizePath(`${r.root}/packages/core/utils/src/server/index.ts`)}:v.resolve("@donotdev/utils/server",{kind:p.kind,resolveDir:p.resolveDir});if(p.path.match(/@donotdev\/utils\/.+/)&&r?.type==="dndev"){let g=p.path.replace("@donotdev/utils/","");return{path:u.normalizePath(`${r.root}/packages/core/utils/src/${g}/index.ts`)}}if(p.path==="@donotdev/supabase")return r?.type==="dndev"?{path:u.normalizePath(`${r.root}/packages/providers/supabase/src/server/index.ts`)}:v.resolve("@donotdev/supabase/server",{kind:p.kind,resolveDir:p.resolveDir});if(p.path==="@donotdev/core")return r?.type==="dndev"?{path:u.normalizePath(`${r.root}/packages/core/server.ts`)}:v.resolve("@donotdev/core/server",{kind:p.kind,resolveDir:p.resolveDir});if(p.path.match(/@donotdev\/core\/.+/)&&c&&r?.type==="dndev"){let g=p.path.replace("@donotdev/core/","");return{path:u.normalizePath(`${r.root}/packages/core/${g}.ts`)}}if(p.path==="firebase-admin"||p.path.startsWith("firebase-admin/")||p.path==="firebase-functions"||p.path.startsWith("firebase-functions/"))return{path:p.path,external:!0};if(p.path.match(/@donotdev\/core\/.+/)&&c&&r?.type==="dndev"){let g=p.path.replace("@donotdev/core/","");return{path:u.normalizePath(`${r.root}/packages/core/${g}.ts`)}}if(p.path.startsWith("@donotdev/")||p.path==="valibot"||p.path.startsWith("valibot/"))return null;if(D.length>0){let g=p.path.split("/")[0];if(D.includes(g))return null}return p.path.startsWith(".")||p.path.startsWith("/")?null:{path:p.path,external:!0}})}};if(m.external=[...I,"firebase-admin","firebase-functions"],m.plugins=[L,...m.plugins||[]],m.define={"process.env.NODE_ENV":JSON.stringify(process.env.NODE_ENV||"production"),...m.define||{}},l&&r.type==="dndev"){let v=r.root,p=u.normalizePath(`${v}/functions/lib`);m.alias={...m.alias,"@donotdev/functions":p}}if(s==="framework"){let v=S.getInstance(),p=r?.root?v.normalizePath(`${r.root}/packages/functions`):process.cwd(),g=v.normalizePath(`${p}/package.json`),k=v.readSync(g,{format:"json"});if(k?.exports){let x={};for(let[,w]of Object.entries(k.exports)){let E=w?.import||w?.default||(typeof w=="string"?w:null);if(!E||!E.endsWith(".ts"))continue;let A=E.replace(/^\.\/src\//,"").replace(/\.ts$/,"");x[A]=E}Object.keys(x).length>0&&(m.entryPoints=x)}}return m}var b=S.getInstance(),W=["create","get","list","listCard","update","delete"];function X(a,e=0){let t=" ".repeat(e),o="";for(let[n,s]of Object.entries(a))if(s!=null)if(typeof s=="object"&&!Array.isArray(s))Object.keys(s).length===0?o+=`${t}${n}: {}
2
2
  `:o+=`${t}${n}:
3
- ${Q(s,e+1)}`;else if(Array.isArray(s))if(s.length===0)o+=`${t}${n}: []
3
+ ${X(s,e+1)}`;else if(Array.isArray(s))if(s.length===0)o+=`${t}${n}: []
4
4
  `;else{o+=`${t}${n}:
5
5
  `;for(let r of s)if(typeof r=="object"&&r!==null){let c=Object.entries(r),[l,f]=c[0];o+=`${t} - ${l}: ${f}
6
6
  `;for(let i=1;i<c.length;i++){let[u,d]=c[i];o+=`${t} ${u}: ${d}
7
7
  `}}else o+=`${t} - ${r}
8
8
  `}else o+=`${t}${n}: ${s}
9
- `;return o}var de=["X_GOOGLE_","FIREBASE_","EXT_","GCLOUD_"],he=["FIREBASE_REGION","FIREBASE_PROJECT_ID","FIREBASE_AUTH_DOMAIN","ENABLE_RATE_LIMITING","DISABLE_RATE_LIMITING","ENABLE_METRICS","DISABLE_METRICS","ENFORCE_APP_CHECK"];function ee(a){if(!L(a))return[];let e=C(a,"utf-8"),t=[],o=e.matchAll(/export\s*\{([^}]+)\}/g);for(let s of o)if(s[1]){let r=s[1].split(",").map(c=>{let l=c.trim().split(/\s+as\s+/);return(l[1]||l[0]||"").trim()}).filter(Boolean);t.push(...r)}let n=e.matchAll(/export\s+const\s+(\w+)/g);for(let s of n)s[1]&&t.push(s[1]);return[...new Set(t)]}function $(a=".env"){if(!L(a))return[];let e=C(a,"utf-8"),t=[];for(let o of e.split(/\r?\n/)){let n=o.trim();if(!n||n.startsWith("#"))continue;let s=n.indexOf("=");if(s<=0)continue;let r=n.substring(0,s).trim();he.includes(r)||de.some(c=>r.startsWith(c))||t.push(r)}return t}function te(a){return U.some(e=>a.startsWith(`${e}_`))}function re(a,e={}){let t=a.defaults||{},o=t.labels||{},n={},s=e.envPath?$(e.envPath):$(),r=s.length>0?s.map(u=>({key:u})):void 0,c=e.entryFile?ee(e.entryFile):[],l=a.functions||{},f=new Set(Object.keys(l));for(let u of c)!te(u)&&!f.has(u)&&f.add(u);for(let u of f){let d=l[u]||{},m={...o,...d.labels};d.category&&(m.category=d.category),n[u]={region:d.region||t.region||["europe-west1"],platform:d.platform||t.platform||"gcfv2",entryPoint:d.entryPoint||u,labels:m},d.trigger==="http"?n[u].httpsTrigger={}:n[u].callableTrigger={},d.secrets?.length?n[u].secretEnvironmentVariables=d.secrets.map(j=>({key:j})):r&&(n[u].secretEnvironmentVariables=r)}if(a.crud?.entities)for(let u of a.crud.entities)for(let d of U){let m=`${d}_${u}`;n[m]={region:t.region||["europe-west1"],platform:t.platform||"gcfv2",callableTrigger:{},entryPoint:m,labels:{...o,category:"crud"}},r&&(n[m].secretEnvironmentVariables=r)}return`# Firebase Functions Configuration
9
+ `;return o}var pe=["X_GOOGLE_","FIREBASE_","EXT_","GCLOUD_"],fe=["FIREBASE_REGION","FIREBASE_PROJECT_ID","FIREBASE_AUTH_DOMAIN","ENABLE_RATE_LIMITING","DISABLE_RATE_LIMITING","ENABLE_METRICS","DISABLE_METRICS","ENFORCE_APP_CHECK"];function Z(a){if(!b.pathExists(a))return[];let e=b.readSync(a,{format:"text"}),t=[],o=e.matchAll(/export\s*\{([^}]+)\}/g);for(let s of o)if(s[1]){let r=s[1].split(",").map(c=>{let l=c.trim().split(/\s+as\s+/);return(l[1]||l[0]||"").trim()}).filter(Boolean);t.push(...r)}let n=e.matchAll(/export\s+const\s+(\w+)/g);for(let s of n)s[1]&&t.push(s[1]);return[...new Set(t)]}function j(a=".env"){if(!b.pathExists(a))return[];let e=b.readSync(a),t=[];for(let o of e.split(/\r?\n/)){let n=o.trim();if(!n||n.startsWith("#"))continue;let s=n.indexOf("=");if(s<=0)continue;let r=n.substring(0,s).trim();fe.includes(r)||pe.some(c=>r.startsWith(c))||t.push(r)}return t}function Q(a){return W.some(e=>a.startsWith(`${e}_`))}function ee(a,e={}){let t=a.defaults||{},o=t.labels||{},n={},s=e.envPath?j(e.envPath):j(),r=s.length>0?s.map(u=>({key:u})):void 0,c=e.entryFile?Z(e.entryFile):[],l=a.functions||{},f=new Set(Object.keys(l));for(let u of c)!Q(u)&&!f.has(u)&&f.add(u);for(let u of f){let d=l[u]||{},m={...o,...d.labels};d.category&&(m.category=d.category),n[u]={region:d.region||t.region||["europe-west1"],platform:d.platform||t.platform||"gcfv2",entryPoint:d.entryPoint||u,labels:m},d.trigger==="http"?n[u].httpsTrigger={}:n[u].callableTrigger={},d.secrets?.length?n[u].secretEnvironmentVariables=d.secrets.map(I=>({key:I})):r&&(n[u].secretEnvironmentVariables=r)}if(a.crud?.entities)for(let u of a.crud.entities)for(let d of W){let m=`${d}_${u}`;n[m]={region:t.region||["europe-west1"],platform:t.platform||"gcfv2",callableTrigger:{},entryPoint:m,labels:{...o,category:"crud"}},r&&(n[m].secretEnvironmentVariables=r)}return`# Firebase Functions Configuration
10
10
  # Generated by @donotdev/core/functions - DO NOT EDIT MANUALLY
11
11
  # Generated at: ${new Date().toISOString()}
12
12
 
13
- `+Q({endpoints:n,specVersion:"v1alpha1",requiredAPIs:[]})}function M(a,e={}){let t=Object.keys(a.functions||{}),o=[];if(a.crud?.entities)for(let l of a.crud.entities)for(let f of U)o.push(`${f}_${l}`);let s=(e.entryFile?ee(e.entryFile):[]).filter(l=>!te(l)&&!t.includes(l)),r=[...t,...s],c=e.envPath?$(e.envPath):$();return{yaml:re(a,e),functions:[...r,...o],staticFunctions:r,crudFunctions:o,autoDetected:s,autoSecrets:c}}function G(a){let e=new Set;for(let f of Object.values(a.functions||{}))if(f.secrets)for(let i of f.secrets)e.add(i);let t=$();for(let f of t)e.add(f);if(e.size===0||!L(".env"))return{stripped:[],kept:0};let n=C(".env","utf-8").split(/\r?\n/),s=[],r=[];for(let f of n){let i=f.trim();if(!i||i.startsWith("#")){s.push(f);continue}let u=i.indexOf("="),d=u>0?i.substring(0,u).trim():"";e.has(d)?r.push(f):s.push(f)}if(r.length===0)return{stripped:[],kept:s.length};B(".env",s.join(`
13
+ `+X({endpoints:n,specVersion:"v1alpha1",requiredAPIs:[]})}function B(a,e={}){let t=Object.keys(a.functions||{}),o=[];if(a.crud?.entities)for(let l of a.crud.entities)for(let f of W)o.push(`${f}_${l}`);let s=(e.entryFile?Z(e.entryFile):[]).filter(l=>!Q(l)&&!t.includes(l)),r=[...t,...s],c=e.envPath?j(e.envPath):j();return{yaml:ee(a,e),functions:[...r,...o],staticFunctions:r,crudFunctions:o,autoDetected:s,autoSecrets:c}}function U(a){let e=new Set;for(let f of Object.values(a.functions||{}))if(f.secrets)for(let i of f.secrets)e.add(i);let t=j();for(let f of t)e.add(f);if(e.size===0||!b.pathExists(".env"))return{stripped:[],kept:0};let n=b.readSync(".env").split(/\r?\n/),s=[],r=[];for(let f of n){let i=f.trim();if(!i||i.startsWith("#")){s.push(f);continue}let u=i.indexOf("="),d=u>0?i.substring(0,u).trim():"";e.has(d)?r.push(f):s.push(f)}if(r.length===0)return{stripped:[],kept:s.length};b.writeSync(".env",s.join(`
14
14
  `));let c=`# Secrets managed by sync-secrets (auto-filtered by build)
15
- `;if(L(".env.local")){let f=C(".env.local","utf-8"),i=new Set(f.split(/\r?\n/).filter(d=>d.trim()&&!d.trim().startsWith("#")).map(d=>d.split("=")[0].trim())),u=r.filter(d=>!i.has(d.split("=")[0].trim()));u.length>0&&B(".env.local",f.trimEnd()+`
15
+ `;if(b.pathExists(".env.local")){let f=b.readSync(".env.local"),i=new Set(f.split(/\r?\n/).filter(d=>d.trim()&&!d.trim().startsWith("#")).map(d=>d.split("=")[0].trim())),u=r.filter(d=>!i.has(d.split("=")[0].trim()));u.length>0&&b.writeSync(".env.local",f.trimEnd()+`
16
16
  `+c+u.join(`
17
17
  `)+`
18
- `)}else B(".env.local",c+r.join(`
18
+ `)}else b.writeSync(".env.local",c+r.join(`
19
19
  `)+`
20
- `);return{stripped:r.map(f=>f.split("=")[0].trim()),kept:s.length}}import{writeFileSync as me}from"fs";function ge(a={}){let e=D();return N({...a,platform:"firebase",bundleWorkspaceDeps:!0,importFramework:!0,workspace:e})}async function ve(a,e={}){let{entry:t="src/index.ts",outDir:o="lib",minify:n=process.env.NODE_ENV==="production",sourcemap:s=!0,analyze:r=!1,entryFile:c="src/index.ts",envPath:l=".env",...f}=e;try{let{build:i}=await import("esbuild"),u=ge({entry:t,outDir:o,minify:n,sourcemap:s,...f}),d=await i(u);d.errors.length>0&&process.exit(1),d.warnings.length>0;let{yaml:m,staticFunctions:j,crudFunctions:I,autoDetected:W,autoSecrets:v}=M(a,{entryFile:c,envPath:l});me("functions.yaml",m),W.length>0,v.length>0;let{stripped:p}=G(a);if(p.length>0,r&&d.metafile){let{analyzeMetafile:g}=await import("esbuild"),k=await g(d.metafile)}}catch{process.exit(1)}}function se(a={}){let{entry:e="src/index.ts",outDir:t="lib",minify:o=!1,sourcemap:n=!0,platform:s="firebase",...r}=a,c=D();return N({entry:e,outDir:t,minify:o,sourcemap:n,platform:s,workspace:c,...r})}function He(a={}){return se({...a,platform:"framework",bundleWorkspaceDeps:!0})}function Ye(a={}){return se({...a,platform:"firebase",bundleWorkspaceDeps:!0,importFramework:!0})}export{ve as buildFunctions,Ye as createAppFunctionsConfig,se as createFunctionsEsbuildConfig,He as createRootFunctionsConfig,G as filterEnvSecrets,re as generateFunctionsYaml,M as generateFunctionsYamlWithInfo};
20
+ `);return{stripped:r.map(f=>f.split("=")[0].trim()),kept:s.length}}function de(a={}){let e=T();return C({...a,platform:"firebase",bundleWorkspaceDeps:!0,importFramework:!0,workspace:e})}async function he(a,e={}){let{entry:t="src/index.ts",outDir:o="lib",minify:n=process.env.NODE_ENV==="production",sourcemap:s=!0,analyze:r=!1,entryFile:c="src/index.ts",envPath:l=".env",...f}=e;try{let{build:i}=await import("esbuild"),u=de({entry:t,outDir:o,minify:n,sourcemap:s,...f}),d=await i(u);d.errors.length>0&&process.exit(1),d.warnings.length>0;let{yaml:m,staticFunctions:I,crudFunctions:D,autoDetected:L,autoSecrets:v}=B(a,{entryFile:c,envPath:l});S.getInstance().writeSync("functions.yaml",m),L.length>0,v.length>0;let{stripped:g}=U(a);if(g.length>0,r&&d.metafile){let{analyzeMetafile:k}=await import("esbuild"),x=await k(d.metafile)}}catch{process.exit(1)}}function te(a={}){let{entry:e="src/index.ts",outDir:t="lib",minify:o=!1,sourcemap:n=!0,platform:s="firebase",...r}=a,c=T();return C({entry:e,outDir:t,minify:o,sourcemap:n,platform:s,workspace:c,...r})}function We(a={}){return te({...a,platform:"framework",bundleWorkspaceDeps:!0})}function Be(a={}){return te({...a,platform:"firebase",bundleWorkspaceDeps:!0,importFramework:!0})}export{he as buildFunctions,Be as createAppFunctionsConfig,te as createFunctionsEsbuildConfig,We as createRootFunctionsConfig,U as filterEnvSecrets,ee as generateFunctionsYaml,B as generateFunctionsYamlWithInfo};