@frontfriend/sdk 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD_PARTY_NOTICES +2 -0
- package/dist/cli.js +175 -180
- package/dist/lib/core/adoption.js +1 -1
- package/dist/lib/core/api-client.js +8 -8
- package/dist/lib/core/application-adoption.js +17 -17
- package/dist/lib/core/cache-manager.js +1 -1
- package/dist/lib/core/cached-components-config.js +11 -11
- package/dist/lib/core/credentials.js +7 -7
- package/dist/lib/core/nativeSource.js +2 -2
- package/dist/lib/core/token-artifact-client.js +10 -10
- package/dist/lib/core/token-processor.js +6 -6
- package/dist/mcp.cjs +672 -120
- package/dist/next.js +11 -11
- package/dist/package.json +1 -1
- package/dist/vite.js +14 -14
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
const path=require("path"),{CACHE_DIR_NAME,CACHE_TTL_MS,CACHE_FILES}=require("./constants"),{CacheError}=require("./errors"),{readJsonFileSafe,readFileSafe,writeJsonFile,writeTextFile,writeModuleExportsFile,fileExists,ensureDirectoryExists,removeDirectory,removeFile}=require("./file-utils"),{CLASSES_SOURCE_FILE,CSS_CLASSES_SOURCE_FILE}=require("./classes-source");class CacheManager{constructor(e=process.cwd()){this.appRoot=e,this.cacheDir=path.join(e,"node_modules",CACHE_DIR_NAME),this.metadataFile=path.join(this.cacheDir,"metadata.json"),this.maxAge=CACHE_TTL_MS}getCacheDir(){return this.cacheDir}isLocalOnly(){return readJsonFileSafe(this.metadataFile)?.version==="local-components"}getIconLibrary(){const e=path.join(this.cacheDir,"iconLibrary.json");return fileExists(e)?readJsonFileSafe(e):null}exists(){return fileExists(this.cacheDir)}isValid(){if(!this.exists())return!1;try{const e=readJsonFileSafe(this.metadataFile);if(!e)return!1;const s=new Date(e.timestamp).getTime();return Date.now()-s<this.maxAge}catch{return!1}}load(){if(!this.exists())return null;try{const e={};for(const s of CACHE_FILES.JS){const t=path.join(this.cacheDir,s);if(fileExists(t)){const
|
|
1
|
+
const path=require("path"),{CACHE_DIR_NAME,CACHE_TTL_MS,CACHE_FILES}=require("./constants"),{CacheError}=require("./errors"),{readJsonFileSafe,readFileSafe,writeJsonFile,writeTextFile,writeModuleExportsFile,fileExists,ensureDirectoryExists,removeDirectory,removeFile}=require("./file-utils"),{CLASSES_SOURCE_FILE,CSS_CLASSES_SOURCE_FILE}=require("./classes-source");class CacheManager{constructor(e=process.cwd()){this.appRoot=e,this.cacheDir=path.join(e,"node_modules",CACHE_DIR_NAME),this.metadataFile=path.join(this.cacheDir,"metadata.json"),this.maxAge=CACHE_TTL_MS}getCacheDir(){return this.cacheDir}isLocalOnly(){return readJsonFileSafe(this.metadataFile)?.version==="local-components"}getIconLibrary(){const e=path.join(this.cacheDir,"iconLibrary.json");return fileExists(e)?readJsonFileSafe(e):null}exists(){return fileExists(this.cacheDir)}isValid(){if(!this.exists())return!1;try{const e=readJsonFileSafe(this.metadataFile);if(!e)return!1;const s=new Date(e.timestamp).getTime();return Date.now()-s<this.maxAge}catch{return!1}}load(){if(!this.exists())return null;try{const e={};for(const s of CACHE_FILES.JS){const t=path.join(this.cacheDir,s);if(fileExists(t)){const o=s.replace(".js","");try{const i=readFileSafe(t);if(i!==null){const n={},r={exports:n};new Function("module","exports",i)(r,n),e[o]=r.exports}}catch(i){console.warn(`[Frontfriend] Failed to load ${s}: ${i.message}`),(i.message.includes("Unexpected token")||i.message.includes("Invalid character"))&&console.warn("[Frontfriend] This might be a BOM or encoding issue. Try deleting node_modules/.cache/frontfriend and running `npx frontfriend init` again.")}}}for(const s of CACHE_FILES.JSON){const t=path.join(this.cacheDir,s),o=s.replace(".json",""),i=readJsonFileSafe(t);i!==null&&(e[o]=i)}return e["components-config"]&&(e.componentsConfig=e["components-config"],delete e["components-config"]),e.cls&&!e.safelist&&(e.safelist=e.cls,delete e.cls),e}catch(e){throw new CacheError(`Failed to load cache: ${e.message}`,"read")}}save(e){try{ensureDirectoryExists(this.cacheDir);const s={timestamp:new Date().toISOString(),version:e.metadata?.version||"2.0.0",ffId:e.metadata?.ffId},t=["tokens","variables","semanticVariables","semanticDarkVariables","keyframes","animations","safelist","custom"];for(const i of t)if(e[i]!==void 0){const n=path.join(this.cacheDir,`${i}.js`);writeModuleExportsFile(n,e[i])}if(e.safelist&&Array.isArray(e.safelist)){const i=path.join(this.cacheDir,"safelist.js");writeModuleExportsFile(i,e.safelist)}const o={fonts:e.fonts,icons:e.icons||e.iconSet,"components-config":e.componentsConfig,iconLibrary:e.iconLibrary,version:e.version,versionMetadata:e.versionMetadata,base:e.base,nativeTokens:e.nativeTokens};for(const[i,n]of Object.entries(o))if(n!==void 0){const r=path.join(this.cacheDir,`${i}.json`);writeJsonFile(r,n)}e.themeCSS!==void 0&&writeTextFile(path.join(this.cacheDir,"theme.css"),e.themeCSS),e.classesContent!==void 0&&(writeTextFile(path.join(this.cacheDir,CLASSES_SOURCE_FILE),e.classesContent),removeFile(path.join(this.cacheDir,CSS_CLASSES_SOURCE_FILE))),writeJsonFile(this.metadataFile,s)}catch(s){throw new CacheError(`Failed to save cache: ${s.message}`,"write")}}saveAtomic(e,s=()=>{}){const t=require("node:fs"),{randomUUID:o}=require("node:crypto");t.mkdirSync(path.dirname(this.cacheDir),{recursive:!0});const i=`${this.cacheDir}.write-lock`;let n;try{n=t.openSync(i,"wx")}catch(c){if(c.code!=="EEXIST")throw c;const a=Number(t.readFileSync(i,"utf8"));let l=!0;if(a>0)try{process.kill(a,0)}catch(f){l=f.code!=="ESRCH"}if(l)throw new CacheError("Another process is installing tokens. Retry after it completes.","write");t.unlinkSync(i),n=t.openSync(i,"wx")}const r=`${this.cacheDir}.previous`,h=`${this.cacheDir}.${o()}.pending`;try{t.writeFileSync(n,String(process.pid)),!t.existsSync(this.cacheDir)&&t.existsSync(r)&&t.renameSync(r,this.cacheDir);const c=new CacheManager(this.appRoot);c.cacheDir=h,c.metadataFile=path.join(h,"metadata.json"),c.save(e),t.existsSync(r)&&t.rmSync(r,{recursive:!0}),t.existsSync(this.cacheDir)&&t.renameSync(this.cacheDir,r);try{t.renameSync(h,this.cacheDir),s()}catch(a){throw t.rmSync(this.cacheDir,{recursive:!0,force:!0}),t.existsSync(r)&&t.renameSync(r,this.cacheDir),a}t.rmSync(r,{recursive:!0,force:!0})}catch(c){if(["EACCES","EPERM","EBUSY","EXDEV"].includes(c.code)){const a=new CacheError(`Atomic cache replacement failed (${c.code}). Check ownership and whether node_modules/.cache/frontfriend is a mount point. Mount the parent node_modules/.cache directory instead; the cache directory must be replaceable. No permission changes were made.`,"write");throw a.cause=c,a}throw c}finally{t.rmSync(h,{recursive:!0,force:!0}),t.closeSync(n),t.rmSync(i,{force:!0})}}clear(){this.exists()&&removeDirectory(this.cacheDir)}}module.exports=CacheManager;
|