@donotdev/core 0.0.38 → 0.0.40
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/empty.cjs +21 -0
- package/empty.js +4 -5
- package/functions/index.js +12 -12
- package/i18n/locales/lazy/crud_ar.json +3 -0
- package/i18n/locales/lazy/crud_da.json +3 -0
- package/i18n/locales/lazy/crud_de.json +3 -0
- package/i18n/locales/lazy/crud_en.json +3 -0
- package/i18n/locales/lazy/crud_es.json +3 -0
- package/i18n/locales/lazy/crud_fr.json +3 -0
- package/i18n/locales/lazy/crud_it.json +3 -0
- package/i18n/locales/lazy/crud_ja.json +3 -0
- package/i18n/locales/lazy/crud_ko.json +3 -0
- package/i18n/locales/lazy/crud_nl.json +3 -0
- package/index.d.ts +253 -268
- package/index.js +214 -58
- package/next/index.js +16 -16
- package/package.json +4 -3
- package/server.d.ts +44 -37
- package/server.js +1 -1
- package/vite/index.js +74 -81
package/empty.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview CJS empty module for optional dep aliasing
|
|
3
|
+
* @description Bundlers (esbuild, Turbopack, Rollup) statically analyze ESM exports.
|
|
4
|
+
* Named imports like `import { CrudCard } from '@donotdev/crud'` fail against an ESM
|
|
5
|
+
* empty module because the export doesn't exist. CJS has dynamic exports — bundlers
|
|
6
|
+
* allow any named import to resolve. Used as alias target by all bundlers.
|
|
7
|
+
* No framework code imports this directly.
|
|
8
|
+
*/
|
|
9
|
+
const handler = {
|
|
10
|
+
get(_, prop) {
|
|
11
|
+
if (prop === 'then') return undefined;
|
|
12
|
+
return noop;
|
|
13
|
+
},
|
|
14
|
+
apply() {
|
|
15
|
+
return noop;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const noop = new Proxy(function () {}, handler);
|
|
19
|
+
module.exports = noop;
|
|
20
|
+
module.exports.default = noop;
|
|
21
|
+
module.exports.__esModule = true;
|
package/empty.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview
|
|
3
|
-
* @description
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* @fileoverview ESM empty module for optional dep aliasing (Vite resolveId → browser)
|
|
3
|
+
* @description Proxy-based noop that silently absorbs any property access or function call.
|
|
4
|
+
* Used by Vite's resolveId hook — served directly to the browser in dev mode.
|
|
5
|
+
* For esbuild pre-bundling (which needs CJS for dynamic named exports), see empty.cjs.
|
|
6
6
|
*/
|
|
7
7
|
const handler = {
|
|
8
8
|
get(_, prop) {
|
|
9
|
-
// Support Promise-like: import('shiki').then(m => m.highlight(...)) — no-op
|
|
10
9
|
if (prop === 'then') return undefined;
|
|
11
10
|
return noop;
|
|
12
11
|
},
|
package/functions/index.js
CHANGED
|
@@ -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 j(){let a=process.cwd(),e=10;for(let t=0;t<e;t++){let s=P.join(a,"package.json");if(A.existsSync(s))try{let o=JSON.parse(A.readFileSync(s,"utf8")),r=o.workspaces&&Array.isArray(o.workspaces);if(r&&o.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&&o.workspaces.some(i=>i.includes("dndev/packages"))){let u=o.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 T,join as w,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 D={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"},S={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:[`${D.SOURCE_EAGER}/*_*.json`],lazy:[`${D.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:S.globalIgnore},css:{absolute:!0,onlyFiles:!0,ignore:[...S.globalIgnore,"**/*.test.css"]},routes:{absolute:!0,onlyFiles:!0,ignore:[...S.globalIgnore,"**/*.test.tsx","**/*.stories.tsx"]},i18n:{absolute:!0,onlyFiles:!0,ignore:S.globalIgnore},assets:{absolute:!0,onlyFiles:!0,ignore:S.globalIgnore}};function V(a,e=null){let t=S[a];if(!t)throw new Error(`Unknown pattern type: ${a}`);return e&&t.framework?{...t,framework:t.framework.map(s=>`${e}/${s}`)}:t}function J(a){return Y[a]||Y.base}var _={getGlobOptionsFor:J||void 0,SCAN_PATTERNS:S||void 0,getPatternsFor:V||void 0,I18N_PATHS:D||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"},O=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(),s=K(t,e);return this.normalizePath(s)}getBasename(e){if(!e)return"";let s=this.normalizePath(e).split("/");return s[s.length-1]||""}getDirname(e){return e?this.normalizePath(x(e)):""}resolvePackage(e,t=null){try{let s=t||this.getAppRoot(),o=ce(w(s,"package.json")).resolve(e);return this.normalizePath(o)}catch{return null}}resolveFrameworkPackage(e,t=null){let s=this.resolvePackage(`${e}/package.json`,t);if(s)return this.getDirname(s);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 o=this.resolveRepoPath(`node_modules/${e}`);return this.pathExists(o)?o:null}resolvePackageAsset(e,t=null){return this.resolvePackage(e,t)}resolveAppPath(e){let t=this.getAppRoot(),s=T(t,e);return this.normalizePath(s)}resolveRepoPath(e){let t=this.getRepoRoot(),s=this.normalizePath(e),n=T(t,s);return this.normalizePath(n)}resolvePath(e,t){let s=this.normalizePath(t),n=this.normalizePath(e),o=T(s,n);return this.normalizePath(o)}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:s="auto",encoding:n="utf8"}=t,o=this._detectFormat(e,s);try{if(o==="buffer")return await h.promises.readFile(e);let r=await h.promises.readFile(e,n),c=this.stripBom(r);return o==="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:s="auto",encoding:n="utf8"}=t,o=this._detectFormat(e,s);try{if(o==="buffer")return h.readFileSync(e);let r=h.readFileSync(e,n),c=this.stripBom(r);return o==="json"?JSON.parse(c):c}catch(r){return this.options.debug&&y.warn(`Failed to read file: ${e}`,r),null}}async write(e,t,s={}){let{format:n="auto",overwrite:o=!1,dryRun:r=!1,verbose:c=!1}=s,l=this.normalizePath(e),f=this.normalizePath(x(l)),i=this.pathExists(l);if(i&&!o)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,s={}){let{format:n="auto",overwrite:o=!1,dryRun:r=!1,verbose:c=!1}=s,l=this.normalizePath(e),f=this.normalizePath(x(l)),i=this.pathExists(l);if(i&&!o)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,s={}){let{overwrite:n=!1,dryRun:o=!1,verbose:r=!1}=s,c=this.normalizePath(t),l=this.pathExists(c);if(l&&!n)return r&&y.info(`Skipping existing file: ${c}`),!1;if(o)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,s={}){let{overwrite:n=!1,dryRun:o=!1,verbose:r=!1}=s,c=this.normalizePath(t),l=this.pathExists(c);if(l&&!n)return r&&y.info(`Skipping existing file: ${c}`),!1;if(o)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(s){return t||y.error(`Error checking path existence: ${e}`,s),!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(s){return this.options.debug&&y.warn(`Failed to read directory: ${e}`,s),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,s){return h.watch(e,t,s)}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=w(this._repoRoot,"packages");return this.pathExists(e)}isWithinApp(e){let t=this.normalizePath(T(e)),s=this.getAppRoot(),n=K(s,t),o=this.normalizePath(n);return!o.startsWith("../")&&!o.startsWith("/")}async findFiles(e,t,s={}){let n=this.normalizePath(w(e,t)),o=this.getAppRoot(),r=this.normalizePath(o),c=n.startsWith(r)?n.slice(r.length+1):n,l={absolute:!0,onlyFiles:!0,braceExpansion:!0,extglob:!0,globstar:!0,cwd:o,ignore:_.SCAN_PATTERNS?.globalIgnore||["**/node_modules/**","**/dist/**","**/build/**","**/.git/**"]};return await this._globWithNormalization([c],{...l,...s})}clearCache(){}async _resolveFrameworkI18nPattern(e){let t=_.I18N_PATHS;if(!t)return null;let s=e.replace(t.SOURCE_ROOT+"/",""),n=this.resolveFrameworkPackage("@donotdev/core");if(!n)return null;let o=this.normalizePath(w(n,t.PUBLISHED_ROOT,s)),r=o.replace(/\/[^/]*\*.*$/,"");return this.pathExists(r),o}async _globWithNormalization(e,t){return(await fe(e,t)).map(n=>{let o=typeof n=="string"?n:n.path;return this.normalizePath(o)})}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 s=[...e.framework,...e.consumer];for(let i of s)if(typeof i!="string"||i.trim()==="")return{frameworkFiles:[],consumerFiles:[]};let n=this.getAppRoot(),o=_.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={...o,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(),s=this.getRepoRoot();if(e==="i18n"&&(!t||t===s))throw new Error(`Cannot resolve i18n patterns: appRoot not set (appRoot: ${t}, repoRoot: ${s}). Ensure configResolved hook has run before discovery.`);let n=_.getPatternsFor(e),o=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:o?(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:o?(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:o?(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(e=!1){if(e)return"@donotdev/core/empty";let t=this.resolvePackage("@donotdev/core/empty");if(t)return t;let s=x(pe(import.meta.url));return this.normalizePath(w(s,"../empty.js"))}_findRepoRoot(e){let t=this.normalizePath(e),s=0,n=this.options.maxLevels;for(;s<n;){let o=this.normalizePath(w(t,Z.TOOLING)),r=this.normalizePath(w(t,Z.CORE));if(this.pathExists(o)&&this.pathExists(r))return t;let c=w(t,"apps");if(this.pathExists(c)&&this.statSync(c)?.isDirectory())return this.normalizePath(t);let l=this.normalizePath(w(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,s++}return this.normalizePath(e)}};function N(a={}){let{entry:e="src/index.ts",outDir:t="lib",minify:s=!1,sourcemap:n=!0,platform:o="firebase",workspace:r,bundleWorkspaceDeps:c=!1,importFramework:l=!1,external:f=!1,...i}=a,u=O.getInstance(),d=H(r),m={entryPoints:[e],bundle:!0,platform:"node",target:"node20",format:"esm",outdir:t,outExtension:{".js":".js"},minify:s,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 $=["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=[...$,"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(o==="framework"){let v=O.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),s="";for(let[n,o]of Object.entries(a))if(o!=null)if(typeof o=="object"&&!Array.isArray(o))Object.keys(o).length===0?s+=`${t}${n}: {}
|
|
2
|
-
`:
|
|
3
|
-
${Q(
|
|
4
|
-
`;else{
|
|
5
|
-
`;for(let r of
|
|
6
|
-
`;for(let i=1;i<c.length;i++){let[u,d]=c[i];
|
|
7
|
-
`}}else
|
|
8
|
-
`}else
|
|
9
|
-
`;return
|
|
1
|
+
import A from"node:fs";import P from"node:path";import{fileURLToPath as oe}from"node:url";var ne=oe(import.meta.url),Pe=P.dirname(ne);function j(){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 C,join as S,dirname as F,relative as K,normalize as le,sep as q,extname as ue}from"node:path";import"node:url";import pe from"fast-glob";var D={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:[`${D.SOURCE_EAGER}/*_*.json`],lazy:[`${D.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:D||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"},O=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(F(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=C(t,e);return this.normalizePath(o)}resolveRepoPath(e){let t=this.getRepoRoot(),o=this.normalizePath(e),n=C(t,o);return this.normalizePath(n)}resolvePath(e,t){let o=this.normalizePath(t),n=this.normalizePath(e),s=C(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(F(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(F(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(F(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(F(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(C(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 pe(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")}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(F(t))===t)return t;let f=this.normalizePath(F(t));if(f===t)break;t=f,o++}return this.normalizePath(e)}};function T(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=O.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 $=["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 x=u.normalizePath(`${p}/package.json`);if(u.pathExists(x)){let b=u.readSync(x,{format:"json"});if(b&&Array.isArray(b.workspaces)){v=u.normalizePath(p);for(let R of b.workspaces)R==="apps/*"||R==="functions"||!R.includes("*")&&!R.includes("/")&&I.push(R);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=[...$,"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=O.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[,E]of Object.entries(k.exports)){let b=E?.import||E?.default||(typeof E=="string"?E:null);if(!b||!b.endsWith(".ts"))continue;let R=b.replace(/^\.\/src\//,"").replace(/\.ts$/,"");x[R]=b}Object.keys(x).length>0&&(m.entryPoints=x)}}return m}import{readFileSync as N,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}: {}
|
|
2
|
+
`:o+=`${t}${n}:
|
|
3
|
+
${Q(s,e+1)}`;else if(Array.isArray(s))if(s.length===0)o+=`${t}${n}: []
|
|
4
|
+
`;else{o+=`${t}${n}:
|
|
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
|
+
`;for(let i=1;i<c.length;i++){let[u,d]=c[i];o+=`${t} ${u}: ${d}
|
|
7
|
+
`}}else o+=`${t} - ${r}
|
|
8
|
+
`}else o+=`${t}${n}: ${s}
|
|
9
|
+
`;return o}var fe=["X_GOOGLE_","FIREBASE_","EXT_","GCLOUD_"],de=["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=N(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 z(a=".env"){if(!L(a))return[];let e=N(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();de.includes(r)||fe.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?z(e.envPath):z(),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($=>({key:$})):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
|
|
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||{}),
|
|
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?z(e.envPath):z();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=z();for(let f of t)e.add(f);if(e.size===0||!L(".env"))return{stripped:[],kept:0};let n=N(".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(`
|
|
14
14
|
`));let c=`# Secrets managed by sync-secrets (auto-filtered by build)
|
|
15
|
-
`;if(L(".env.local")){let f=
|
|
15
|
+
`;if(L(".env.local")){let f=N(".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()+`
|
|
16
16
|
`+c+u.join(`
|
|
17
17
|
`)+`
|
|
18
18
|
`)}else B(".env.local",c+r.join(`
|
|
19
19
|
`)+`
|
|
20
|
-
`);return{stripped:r.map(f=>f.split("=")[0].trim()),kept:
|
|
20
|
+
`);return{stripped:r.map(f=>f.split("=")[0].trim()),kept:s.length}}import{writeFileSync as he}from"fs";function me(a={}){let e=j();return T({...a,platform:"firebase",bundleWorkspaceDeps:!0,importFramework:!0,workspace:e})}async function ge(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=me({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:$,crudFunctions:I,autoDetected:W,autoSecrets:v}=M(a,{entryFile:c,envPath:l});he("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=j();return T({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{ge as buildFunctions,Ye as createAppFunctionsConfig,se as createFunctionsEsbuildConfig,He as createRootFunctionsConfig,G as filterEnvSecrets,re as generateFunctionsYaml,M as generateFunctionsYamlWithInfo};
|