@powerlines/plugin-rolldown 0.7.125 → 0.7.127

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`@babel/helper-plugin-utils`),n=require(`@babel/types`);n=e.__toESM(n);function r(e,t){if(!n.isStringLiteral(e.node))return;let r=e.node.value,i=t.context?.fs.resolveSync(r);i&&e.replaceWith(n.stringLiteral(i.replace(/\.(?:ts|mts|cts)x?$/,``)))}const i=[`require`,`require.resolve`,`System.import`,`jest.genMockFromModule`,`jest.mock`,`jest.unmock`,`jest.doMock`,`jest.dontMock`,`jest.setMock`,`jest.requireActual`,`jest.requireMock`,`require.requireActual`,`require.requireMock`];function a(e,t,r){let{node:i}=t;if(n.isMemberExpression(i))return t.matchesPattern(r);if(!n.isIdentifier(i)||r.includes(`.`))return!1;let a=r.split(`.`)[0];return i.name===a}const o={CallExpression:(e,t)=>{if(t.moduleResolverVisited.has(e))return;let o=e.get(`callee`);(o&&i.some(e=>a(t,o,e))||n.isImport(e.node.callee))&&(t.moduleResolverVisited.add(e),r(e.get(`arguments.0`),t))},"ImportDeclaration|ExportDeclaration|ExportAllDeclaration":(e,t)=>{!e||!e.get(`source`)||t.moduleResolverVisited.has(e)||(t.moduleResolverVisited.add(e),r(e.get(`source`),t))}},s=e=>(0,t.declare)(function(t){let n=new Set;return{name:`powerlines:module-resolver`,manipulateOptions(e){e.filename??=`unknown`},pre(){n=new Set},visitor:{Program:{enter(r,i){r.traverse(o,{...i,context:e,moduleResolverVisited:n,api:t})},exit(r,i){r.traverse(o,{...i,context:e,moduleResolverVisited:n,api:t})}}},post(){n.clear()}}});exports.moduleResolverBabelPlugin=s;
1
+ const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`@babel/helper-plugin-utils`),n=require(`@babel/types`);n=e.__toESM(n);function r(e,t){if(!n.isStringLiteral(e.node))return;let r=t.context?.fs.resolveSync(e.node.value);r&&e.replaceWith(n.stringLiteral(r.replace(/\.(?:ts|mts|cts)x?$/,``)))}const i=[`require`,`require.resolve`,`System.import`,`jest.genMockFromModule`,`jest.mock`,`jest.unmock`,`jest.doMock`,`jest.dontMock`,`jest.setMock`,`jest.requireActual`,`jest.requireMock`,`require.requireActual`,`require.requireMock`];function a(e,t,r){let{node:i}=t;if(n.isMemberExpression(i))return t.matchesPattern(r);if(!n.isIdentifier(i)||r.includes(`.`))return!1;let a=r.split(`.`)[0];return i.name===a}const o={CallExpression:(e,t)=>{if(t.moduleResolverVisited.has(e))return;let o=e.get(`callee`);(o&&i.some(e=>a(t,o,e))||n.isImport(e.node.callee))&&(t.moduleResolverVisited.add(e),r(e.get(`arguments.0`),t))},"ImportDeclaration|ExportDeclaration|ExportAllDeclaration":(e,t)=>{!e||!e.get(`source`)||t.moduleResolverVisited.has(e)||(t.moduleResolverVisited.add(e),r(e.get(`source`),t))}},s=e=>(0,t.declare)(function(t){let n=new Set;return{name:`powerlines:module-resolver`,manipulateOptions(e){e.filename??=`unknown`},pre(){n=new Set},visitor:{Program:{enter(r,i){r.traverse(o,{...i,context:e,moduleResolverVisited:n,api:t})},exit(r,i){r.traverse(o,{...i,context:e,moduleResolverVisited:n,api:t})}}},post(){n.clear()}}});exports.moduleResolverBabelPlugin=s;
@@ -1 +1 @@
1
- import{declare as e}from"@babel/helper-plugin-utils";import*as t from"@babel/types";function n(e,n){if(!t.isStringLiteral(e.node))return;let r=e.node.value,i=n.context?.fs.resolveSync(r);i&&e.replaceWith(t.stringLiteral(i.replace(/\.(?:ts|mts|cts)x?$/,``)))}const r=[`require`,`require.resolve`,`System.import`,`jest.genMockFromModule`,`jest.mock`,`jest.unmock`,`jest.doMock`,`jest.dontMock`,`jest.setMock`,`jest.requireActual`,`jest.requireMock`,`require.requireActual`,`require.requireMock`];function i(e,n,r){let{node:i}=n;if(t.isMemberExpression(i))return n.matchesPattern(r);if(!t.isIdentifier(i)||r.includes(`.`))return!1;let a=r.split(`.`)[0];return i.name===a}const a={CallExpression:(e,a)=>{if(a.moduleResolverVisited.has(e))return;let o=e.get(`callee`);(o&&r.some(e=>i(a,o,e))||t.isImport(e.node.callee))&&(a.moduleResolverVisited.add(e),n(e.get(`arguments.0`),a))},"ImportDeclaration|ExportDeclaration|ExportAllDeclaration":(e,t)=>{!e||!e.get(`source`)||t.moduleResolverVisited.has(e)||(t.moduleResolverVisited.add(e),n(e.get(`source`),t))}},o=t=>e(function(e){let n=new Set;return{name:`powerlines:module-resolver`,manipulateOptions(e){e.filename??=`unknown`},pre(){n=new Set},visitor:{Program:{enter(r,i){r.traverse(a,{...i,context:t,moduleResolverVisited:n,api:e})},exit(r,i){r.traverse(a,{...i,context:t,moduleResolverVisited:n,api:e})}}},post(){n.clear()}}});export{o as moduleResolverBabelPlugin};
1
+ import{declare as e}from"@babel/helper-plugin-utils";import*as t from"@babel/types";function n(e,n){if(!t.isStringLiteral(e.node))return;let r=n.context?.fs.resolveSync(e.node.value);r&&e.replaceWith(t.stringLiteral(r.replace(/\.(?:ts|mts|cts)x?$/,``)))}const r=[`require`,`require.resolve`,`System.import`,`jest.genMockFromModule`,`jest.mock`,`jest.unmock`,`jest.doMock`,`jest.dontMock`,`jest.setMock`,`jest.requireActual`,`jest.requireMock`,`require.requireActual`,`require.requireMock`];function i(e,n,r){let{node:i}=n;if(t.isMemberExpression(i))return n.matchesPattern(r);if(!t.isIdentifier(i)||r.includes(`.`))return!1;let a=r.split(`.`)[0];return i.name===a}const a={CallExpression:(e,a)=>{if(a.moduleResolverVisited.has(e))return;let o=e.get(`callee`);(o&&r.some(e=>i(a,o,e))||t.isImport(e.node.callee))&&(a.moduleResolverVisited.add(e),n(e.get(`arguments.0`),a))},"ImportDeclaration|ExportDeclaration|ExportAllDeclaration":(e,t)=>{!e||!e.get(`source`)||t.moduleResolverVisited.has(e)||(t.moduleResolverVisited.add(e),n(e.get(`source`),t))}},o=t=>e(function(e){let n=new Set;return{name:`powerlines:module-resolver`,manipulateOptions(e){e.filename??=`unknown`},pre(){n=new Set},visitor:{Program:{enter(r,i){r.traverse(a,{...i,context:t,moduleResolverVisited:n,api:e})},exit(r,i){r.traverse(a,{...i,context:t,moduleResolverVisited:n,api:e})}}},post(){n.clear()}}});export{o as moduleResolverBabelPlugin};
@@ -1 +1 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../typescript/ts-morph.cjs`),n=require(`../typescript/tsconfig.cjs`),r=require(`../config-file.cjs`),i=require(`../../internal/helpers/resolver.cjs`),a=require(`../../plugin-utils/helpers.cjs`),o=require(`../../plugin-utils/paths.cjs`),s=require(`../entry.cjs`),c=require(`../logger.cjs`),l=require(`../fs/vfs.cjs`),u=require(`../utilities/meta.cjs`);let d=require(`@stryke/convert/to-array`),f=require(`defu`);f=e.__toESM(f);let p=require(`@stryke/helpers/omit`),m=require(`@stryke/type-checks/is-string`),h=require(`@storm-software/config-tools/types`),g=require(`@stryke/fs/get-workspace-root`),_=require(`@stryke/fs/resolve`),v=require(`@stryke/path/append`),y=require(`@stryke/path/replace`),b=require(`@stryke/type-checks/is-set-object`),x=require(`@stryke/type-checks/is-set-string`),S=require(`@stryke/fs/json`),C=require(`@stryke/json/storm-json`),w=require(`@stryke/string-format/title-case`),T=require(`@stryke/fs/exists`),E=require(`@stryke/env/get-env-paths`),D=require(`@stryke/hash/hash-files`),O=require(`@stryke/hash/murmurhash`),k=require(`@stryke/helpers/get-unique`),A=require(`@stryke/http/fetch`),j=require(`@stryke/path/is-parent-path`),M=require(`@stryke/path/is-type`),N=require(`@stryke/path/join`),P=require(`@stryke/type-checks/is-null`),F=require(`@stryke/unique-id/uuid`),I=require(`bundle-require`),L=require(`flat-cache`),R=require(`oxc-parser`),z=require(`undici`);const B=new WeakMap,V=new WeakMap;(0,z.setGlobalDispatcher)(new z.Agent({keepAliveTimeout:1e4}).compose(z.interceptors.retry({maxRetries:3,minTimeout:1e3,maxTimeout:1e4,timeoutFactor:2,retryAfter:!0})));var H=class e{#e={};#t;#n=null;#r=(0,F.uuid)();#i=(0,F.uuid)();#a=Date.now();#o=null;#s;#c;#l;#u;#d;#f(e={}){return(0,f.default)({variant:e.build?.variant,projectType:e.type,projectRoot:e.root,name:e.name,title:e.title,compatibilityDate:e.compatibilityDate,description:e.description,sourceRoot:e.sourceRoot,configFile:e.configFile,customLogger:e.customLogger,logLevel:e.logLevel,tsconfig:e.tsconfig,tsconfigRaw:e.tsconfigRaw,skipCache:e.skipCache,skipInstalls:e.skipInstalls,entry:e.entry,output:e.output,plugins:e.plugins,mode:e.mode,lint:e.lint,transform:e.transform,build:e.build,framework:e.framework,...e},{output:e.framework?{artifactsPath:(0,N.joinPaths)(e.root??this.config.projectRoot,`.${e.framework??`powerlines`}`),dts:(0,N.joinPaths)(e.root??this.config.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`}:{}})}static async from(t,n){let i=new e(await r.loadWorkspaceConfig(t,n.root));await i.withUserConfig(n);let a=await(0,_.resolvePackage)(`powerlines`);if(!a)throw Error("Could not resolve `powerlines` package location.");return i.powerlinesPath=a,i}dependencies={};devDependencies={};persistedMeta=void 0;powerlinesPath;packageJson;projectJson=void 0;resolver;resolvePatterns=[];get $$internal(){return this.#e}set $$internal(e){this.#e=e}get entry(){return s.resolveEntriesSync(this,this.#o?this.#o:(0,d.toArray)(this.config.entry))}set entry(e){this.#o=e}get tsconfig(){return this.#c||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#c}set tsconfig(e){this.#c=e,this.resolvePatterns=(0,I.tsconfigPathsToRegExp)(e?.options?.paths??{})}get fs(){return this.#s||=l.VirtualFileSystem.createSync(this),this.#s}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:(0,O.murmurhash)({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:u.PROJECT_ROOT_HASH_LENGTH}),configHash:(0,O.murmurhash)(this.config,{maxLength:u.CACHE_HASH_LENGTH})}}get config(){return this.resolvedConfig??{}}get log(){return this.logFn||=this.createLog(),this.logFn}get workspaceConfig(){return this.#t}get envPaths(){if(V.has({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`}))return V.get({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`});let e=(0,E.getEnvPaths)({orgId:`storm-software`,appId:this.config?.framework||`powerlines`,workspaceRoot:this.workspaceConfig.workspaceRoot});return V.set({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`},e),e}get artifactsPath(){return(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,this.config.projectRoot,this.config.output.artifactsPath)}get builtinsPath(){return(0,N.joinPaths)(this.artifactsPath,`builtins`)}get entryPath(){return(0,N.joinPaths)(this.artifactsPath,`entry`)}get dataPath(){return(0,N.joinPaths)(this.envPaths.data,`projects`,u.getPrefixedProjectRootHash(this.config.name,this.meta.projectRootHash))}get cachePath(){return(0,N.joinPaths)(this.envPaths.cache,`projects`,(0,O.murmurhash)({checksum:this.#n,config:this.meta.configHash},{maxLength:u.CACHE_HASH_LENGTH}))}get dtsPath(){return this.config.output.dts?(0,v.appendPath)(this.config.output.dts,this.workspaceConfig.workspaceRoot):(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return(0,g.relativeToWorkspaceRoot)(this.config.projectRoot)}get builtins(){return Object.values(this.fs.metadata).filter(e=>e&&e.type===`builtin`).map(e=>e?.id).filter(Boolean)}get program(){return this.#l||=t.createProgram(this,{skipAddingFilesFromTsConfig:!0}),this.#l}get parserCache(){return this.#u||=(0,L.create)({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#u}get requestCache(){return this.#d||=(0,L.create)({cacheId:`http`,cacheDir:this.cachePath,ttl:360*60*1e3,lruSize:5e3,persistInterval:250}),this.#d}async fetch(e,t={}){let n=(0,O.murmurhash)({input:e.toString(),options:JSON.stringify(t)});if(!this.config.skipCache&&!t.skipCache){let e=this.requestCache.get(n);if(e)return new z.Response(e.body,{status:e.status,statusText:e.statusText,headers:e.headers})}let r=await(0,A.fetchRequest)(e,{timeout:12e3,...t}),i={body:await r.text(),status:r.status,statusText:r.statusText,headers:Object.fromEntries(r.headers.entries())};if(!this.config.skipCache&&!t.skipCache)try{this.requestCache.set(n,i)}catch{}return new z.Response(i.body,{status:i.status,statusText:i.statusText,headers:i.headers})}async parse(e,t={}){let n=(0,O.murmurhash)({code:e,options:t}),r;return!this.config.skipCache&&(r=this.parserCache.get(n),r)?r:(r=await(0,R.parse)(`source.${t.lang||`ts`}`,e,{...t,sourceType:`module`,showSemanticErrors:this.config.mode===`development`}),this.config.skipCache||this.parserCache.set(n,r),r)}async resolve(e,t,n={}){let r=e;if(this.config.build.alias)if(Array.isArray(this.config.build.alias)){let e=this.config.build.alias.find(e=>(0,I.match)(r,[e.find]));e&&(r=e.replacement)}else (0,b.isSetObject)(this.config.build.alias)&&this.config.build.alias[e]&&(r=this.config.build.alias[e]);if(this.fs.isVirtual(r)){let e=await this.fs.resolve(r,t,{conditions:this.config.build.conditions,extensions:this.config.build.extensions,...n});return e?{id:`\0${e}`,external:this.config.projectType!==`application`}:void 0}if(this.config.build.skipNodeModulesBundle){if((0,I.match)(r,this.resolvePatterns)||(0,I.match)(r,this.config.build.noExternal))return;if((0,I.match)(r,this.config.build.external)||r.startsWith(`node:`)||!/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(r))return{id:r,external:!0}}else{if((0,I.match)(r,this.config.build.noExternal))return;if((0,I.match)(r,this.config.build.external)||r.startsWith(`node:`))return{id:r,external:!0}}}async load(e){let t=await this.fs.resolve(e);if(!t)return;let n=await this.fs.read(t);if(n)return{code:n,map:null}}async getBuiltins(){return Promise.all(Object.entries(this.fs.metadata).filter(([,e])=>e&&e.type===`builtin`).map(async([e,t])=>{let n=await this.fs.read(e);return{...t,path:e,code:n}}))}async emitEntry(e,t,n={}){let r=(0,M.isAbsolute)(t)?t:(0,v.appendPath)(t,this.entryPath);return this.entry??=[],this.entry.push({name:n.name,file:r,input:n.input,output:n.output}),this.fs.write(r,e,(0,f.default)((0,p.omit)(n,[`name`]),{meta:{type:`entry`,properties:{name:n.name,output:n.output,"input.file":n.input?.file,"input.name":n.input?.name}}}))}async emitBuiltin(e,t,n,r={}){return this.fs.write(n?(0,M.isAbsolute)(n)?n:(0,N.joinPaths)(this.builtinsPath,n):(0,v.appendPath)(t,this.builtinsPath),e,(0,f.default)(r,{meta:{type:`builtin`}}))}async withUserConfig(e,t={isHighPriority:!0}){this.mergeUserConfig(e),await this.init(this.config.userConfig,t)}async withInlineConfig(e,t={isHighPriority:!0}){if(this.config.inlineConfig=e,e.command===`new`){let e=(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,`package.json`);if(!(0,T.existsSync)(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await(0,S.readJsonFile)(e),this.workspaceConfig.repository??=(0,x.isSetString)(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(h.LogLevelLabel.FATAL,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}error(e){this.log(h.LogLevelLabel.ERROR,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}warn(e){this.log(h.LogLevelLabel.WARN,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}info(e){this.log(h.LogLevelLabel.INFO,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}debug(e){this.log(h.LogLevelLabel.DEBUG,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}trace(e){this.log(h.LogLevelLabel.TRACE,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}createLog(e=null){return c.createLog(e,{...this.config,logLevel:(0,P.isNull)(this.config.logLevel)?`silent`:this.config.logLevel})}extendLog(e){return c.extendLog(this.log,e)}async generateChecksum(e=this.config.projectRoot){return this.#n=await(0,D.hashDirectory)(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,V.set({workspaceRoot:e.workspaceRoot,framework:`powerlines`},(0,E.getEnvPaths)({orgId:((0,b.isSetObject)(e.organization)?e.organization.name:e.organization)||`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot}))}resolvedConfig={};logFn;async init(e={},t={isHighPriority:!0}){let c={projectRoot:e.root??this.config.projectRoot??this.config.userConfig?.root??this.config.inlineConfig?.root,mode:(e.mode??this.config.mode)||this.workspaceConfig.mode,skipCache:e.skipCache??this.config.skipCache??!1,configFile:e.configFile??this.config.configFile,framework:e.framework??this.config.framework??`powerlines`,command:this.config.inlineConfig?.command};if(B.has(c)){let e=B.get(c);this.projectJson=e.projectJson,this.packageJson=e.packageJson,this.#n=e.checksum,this.resolver=e.resolver,this.mergeUserConfig(e.userConfig.config,this.config.userConfig)}else{let t=(0,N.joinPaths)(c.projectRoot,`project.json`);(0,T.existsSync)(t)&&(this.projectJson=await(0,S.readJsonFile)(t));let n=(0,N.joinPaths)(c.projectRoot,`package.json`);(0,T.existsSync)(n)&&(this.packageJson=await(0,S.readJsonFile)(n)),this.#n=await this.generateChecksum(c.projectRoot),this.resolver=i.createResolver({workspaceRoot:this.workspaceConfig.workspaceRoot,projectRoot:c.projectRoot,cacheDir:this.cachePath,mode:c.mode,logLevel:e.logLevel||this.config?.logLevel||this.workspaceConfig.logLevel||`info`,skipCache:c.skipCache});let a=await r.loadUserConfigFile(c.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,c.command,c.mode,c.configFile,c.framework);this.mergeUserConfig(a.config),B.set(c,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:a})}e.tsconfig??=n.getTsconfigFilePath(this.workspaceConfig.workspaceRoot,c.projectRoot,e.tsconfig),(0,b.isSetObject)(e)&&(this.resolvedConfig=(0,f.default)({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},t.isHighPriority?this.#f(e):{},{command:this.config.inlineConfig?.command,...this.#f(this.config.inlineConfig)},this.#f(this.config.userConfig),{mode:this.workspaceConfig?.mode,logLevel:this.workspaceConfig?.logLevel,skipCache:this.workspaceConfig?.skipCache},{name:this.projectJson?.name||this.packageJson?.name,version:this.packageJson?.version,description:this.packageJson?.description,sourceRoot:this.projectJson?.sourceRoot||(0,v.appendPath)(`src`,c.projectRoot),output:(0,f.default)(e.output??{},{outputPath:c.projectRoot?(0,N.joinPaths)(this.workspaceConfig?.directories?.build||`dist`,c.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:(0,N.joinPaths)(c.projectRoot,`.${e.framework??`powerlines`}`),dts:(0,N.joinPaths)(c.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:c.projectRoot,glob:`*.md`},{input:c.projectRoot,glob:`package.json`}]})},t.isHighPriority?{}:this.#f(e),{inlineConfig:{},userConfig:{},framework:`powerlines`,platform:`neutral`,mode:`production`,projectType:`application`,logLevel:`info`,preview:!1,environments:{},transform:{babel:{plugins:[],presets:[]}},lint:{eslint:{}},build:{target:`esnext`,override:{}}})),this.config.entry=s.getUniqueEntries(this.config.entry),this.config.name?.startsWith(`@`)&&this.config.name.split(`/`).filter(Boolean).length>1&&(this.config.name=this.config.name.split(`/`).filter(Boolean)[1]),this.config.title??=(0,w.titleCase)(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=(0,k.getUnique)(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=(0,k.getUnique)(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=(0,k.getUnique)(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=(0,k.getUnique)(this.config.build.noExternal)),this.config.output.format=(0,k.getUnique)((0,d.toArray)(this.config.output?.format??(this.config.projectType===`library`?[`cjs`,`esm`]:[`esm`]))),this.config.projectRoot&&this.config.projectRoot!==`.`&&this.config.projectRoot!==`./`&&this.config.projectRoot!==this.workspaceConfig.workspaceRoot?(this.config.output.outputPath??=(0,N.joinPaths)(`dist`,this.config.projectRoot),this.config.output.buildPath??=(0,N.joinPaths)(this.config.projectRoot,`dist`)):(this.config.output.outputPath??=`dist`,this.config.output.buildPath??=`dist`),this.config.output.assets=(0,k.getUniqueBy)(this.config.output.assets.map(e=>({glob:(0,b.isSetObject)(e)?e.glob:e,input:(0,m.isString)(e)||!e.input||e.input===`.`||e.input===`/`||e.input===`./`?this.workspaceConfig.workspaceRoot:(0,j.isParentPath)(e.input,this.workspaceConfig.workspaceRoot)||e.input===this.workspaceConfig.workspaceRoot?e.input:(0,v.appendPath)(e.input,this.workspaceConfig.workspaceRoot),output:(0,b.isSetObject)(e)&&e.output?(0,j.isParentPath)(e.output,this.workspaceConfig.workspaceRoot)?e.output:(0,v.appendPath)((0,N.joinPaths)(this.config.output.outputPath,(0,y.replacePath)((0,y.replacePath)(e.output,(0,y.replacePath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):(0,v.appendPath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:(0,b.isSetObject)(e)&&e.ignore?(0,d.toArray)(e.ignore):void 0})),e=>`${e.input}-${e.glob}-${e.output}`),this.config.plugins=(this.config.plugins??[]).filter(Boolean).reduce((e,t)=>(a.isPlugin(t)&&a.checkDedupe(t,e.filter(e=>a.isPlugin(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=o.replacePathTokens(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=o.replacePathTokens(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(e=>o.replacePathTokens(this,e))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(e=>({...e,glob:o.replacePathTokens(this,e.glob),ignore:e.ignore?e.ignore.map(e=>o.replacePathTokens(this,e)):void 0,input:o.replacePathTokens(this,e.input),output:o.replacePathTokens(this,e.output)}))),this.#s??=await l.VirtualFileSystem.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=(0,f.default)({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},(0,p.omit)(e??{},[`entry`]),(0,p.omit)(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=(0,k.getUnique)((0,d.toArray)(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(a.isPlugin(t)&&a.checkDedupe(t,e.filter(e=>a.isPlugin(e)))||e.push(t),e),[])}};exports.PowerlinesContext=H;
1
+ const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../typescript/ts-morph.cjs`),n=require(`../typescript/tsconfig.cjs`),r=require(`../config-file.cjs`),i=require(`../../internal/helpers/resolver.cjs`),a=require(`../../plugin-utils/helpers.cjs`),o=require(`../../plugin-utils/paths.cjs`),s=require(`../entry.cjs`),c=require(`../logger.cjs`),l=require(`../fs/vfs.cjs`),u=require(`../utilities/meta.cjs`);let d=require(`@stryke/convert/to-array`),f=require(`defu`);f=e.__toESM(f);let p=require(`@stryke/helpers/omit`),m=require(`@stryke/type-checks/is-string`),h=require(`@storm-software/config-tools/types`),g=require(`@stryke/fs/get-workspace-root`),_=require(`@stryke/fs/resolve`),v=require(`@stryke/path/append`),y=require(`@stryke/path/replace`),b=require(`@stryke/type-checks/is-set-object`),x=require(`@stryke/type-checks/is-set-string`),S=require(`@stryke/fs/json`),C=require(`@stryke/json/storm-json`),w=require(`@stryke/string-format/title-case`),T=require(`@stryke/fs/exists`),E=require(`@stryke/env/get-env-paths`),D=require(`@stryke/hash/hash-files`),O=require(`@stryke/hash/murmurhash`),k=require(`@stryke/helpers/get-unique`),A=require(`@stryke/http/fetch`),j=require(`@stryke/path/is-parent-path`),M=require(`@stryke/path/is-type`),N=require(`@stryke/path/join`),P=require(`@stryke/type-checks/is-null`),F=require(`@stryke/unique-id/uuid`),I=require(`bundle-require`),L=require(`flat-cache`),R=require(`oxc-parser`),z=require(`undici`);const B=new WeakMap,V=new WeakMap;(0,z.setGlobalDispatcher)(new z.Agent({keepAliveTimeout:1e4}).compose(z.interceptors.retry({maxRetries:3,minTimeout:1e3,maxTimeout:1e4,timeoutFactor:2,retryAfter:!0})));var H=class e{#e={};#t;#n=null;#r=(0,F.uuid)();#i=(0,F.uuid)();#a=Date.now();#o=null;#s;#c;#l;#u;#d;#f(e={}){return(0,f.default)({variant:e.build?.variant,projectType:e.type,projectRoot:e.root,name:e.name,title:e.title,compatibilityDate:e.compatibilityDate,description:e.description,sourceRoot:e.sourceRoot,configFile:e.configFile,customLogger:e.customLogger,logLevel:e.logLevel,tsconfig:e.tsconfig,tsconfigRaw:e.tsconfigRaw,skipCache:e.skipCache,skipInstalls:e.skipInstalls,entry:e.entry,output:e.output,plugins:e.plugins,mode:e.mode,lint:e.lint,transform:e.transform,build:e.build,framework:e.framework,...e},{output:e.framework?{artifactsPath:(0,N.joinPaths)(e.root??this.config.projectRoot,`.${e.framework??`powerlines`}`),dts:(0,N.joinPaths)(e.root??this.config.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`}:{}})}static async from(t,n){let i=new e(await r.loadWorkspaceConfig(t,n.root));await i.withUserConfig(n);let a=await(0,_.resolvePackage)(`powerlines`);if(!a)throw Error("Could not resolve `powerlines` package location.");return i.powerlinesPath=a,i}dependencies={};devDependencies={};persistedMeta=void 0;powerlinesPath;packageJson;projectJson=void 0;resolver;resolvePatterns=[];get $$internal(){return this.#e}set $$internal(e){this.#e=e}get entry(){return s.resolveEntriesSync(this,this.#o?this.#o:(0,d.toArray)(this.config.entry))}set entry(e){this.#o=e}get tsconfig(){return this.#c||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#c}set tsconfig(e){this.#c=e,this.resolvePatterns=(0,I.tsconfigPathsToRegExp)(e?.options?.paths??{})}get fs(){return this.#s||=l.VirtualFileSystem.createSync(this),this.#s}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:(0,O.murmurhash)({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:u.PROJECT_ROOT_HASH_LENGTH}),configHash:(0,O.murmurhash)(this.config,{maxLength:u.CACHE_HASH_LENGTH})}}get config(){return this.resolvedConfig??{}}get log(){return this.logFn||=this.createLog(),this.logFn}get workspaceConfig(){return this.#t}get envPaths(){if(V.has({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`}))return V.get({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`});let e=(0,E.getEnvPaths)({orgId:`storm-software`,appId:this.config?.framework||`powerlines`,workspaceRoot:this.workspaceConfig.workspaceRoot});return V.set({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`},e),e}get artifactsPath(){return(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,this.config.projectRoot,this.config.output.artifactsPath)}get builtinsPath(){return(0,N.joinPaths)(this.artifactsPath,`builtins`)}get entryPath(){return(0,N.joinPaths)(this.artifactsPath,`entry`)}get dataPath(){return(0,N.joinPaths)(this.envPaths.data,`projects`,u.getPrefixedProjectRootHash(this.config.name,this.meta.projectRootHash))}get cachePath(){return(0,N.joinPaths)(this.envPaths.cache,`projects`,(0,O.murmurhash)({checksum:this.#n,config:this.meta.configHash},{maxLength:u.CACHE_HASH_LENGTH}))}get dtsPath(){return this.config.output.dts?(0,v.appendPath)(this.config.output.dts,this.workspaceConfig.workspaceRoot):(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return(0,g.relativeToWorkspaceRoot)(this.config.projectRoot)}get builtins(){return Object.values(this.fs.metadata).filter(e=>e&&e.type===`builtin`).map(e=>e?.id).filter(Boolean)}get program(){return this.#l||=t.createProgram(this,{skipAddingFilesFromTsConfig:!0}),this.#l}get parserCache(){return this.#u||=(0,L.create)({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#u}get requestCache(){return this.#d||=(0,L.create)({cacheId:`http`,cacheDir:this.cachePath,ttl:360*60*1e3,lruSize:5e3,persistInterval:250}),this.#d}async fetch(e,t={}){let n=(0,O.murmurhash)({input:e.toString(),options:JSON.stringify(t)});if(!this.config.skipCache&&!t.skipCache){let e=this.requestCache.get(n);if(e)return new z.Response(e.body,{status:e.status,statusText:e.statusText,headers:e.headers})}let r=await(0,A.fetchRequest)(e,{timeout:12e3,...t}),i={body:await r.text(),status:r.status,statusText:r.statusText,headers:Object.fromEntries(r.headers.entries())};if(!this.config.skipCache&&!t.skipCache)try{this.requestCache.set(n,i)}catch{}return new z.Response(i.body,{status:i.status,statusText:i.statusText,headers:i.headers})}async parse(e,t={}){let n=(0,O.murmurhash)({code:e,options:t}),r;return!this.config.skipCache&&(r=this.parserCache.get(n),r)?r:(r=await(0,R.parse)(`source.${t.lang||`ts`}`,e,{...t,sourceType:`module`,showSemanticErrors:this.config.mode===`development`}),this.config.skipCache||this.parserCache.set(n,r),r)}async resolve(e,t,n={}){let r=e;if(this.config.build.alias)if(Array.isArray(this.config.build.alias)){let e=this.config.build.alias.find(e=>(0,I.match)(r,[e.find]));e&&(r=e.replacement)}else (0,b.isSetObject)(this.config.build.alias)&&this.config.build.alias[e]&&(r=this.config.build.alias[e]);if(this.fs.isVirtual(r)){let e=await this.fs.resolve(r,t,{conditions:this.config.build.conditions,extensions:this.config.build.extensions,...n});return e?{id:`\0${e}`,external:this.config.projectType!==`application`}:void 0}if(this.config.build.skipNodeModulesBundle){if((0,I.match)(r,this.resolvePatterns)||(0,I.match)(r,this.config.build.noExternal))return;if((0,I.match)(r,this.config.build.external)||r.startsWith(`node:`)||!/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(r))return{id:r,external:!0}}else{if((0,I.match)(r,this.config.build.noExternal))return;if((0,I.match)(r,this.config.build.external)||r.startsWith(`node:`))return{id:r,external:!0}}}async load(e){let t=await this.fs.resolve(e);if(!t)return;let n=await this.fs.read(t);if(n)return{code:n,map:null}}async getBuiltins(){return Promise.all(Object.entries(this.fs.metadata).filter(([,e])=>e&&e.type===`builtin`).map(async([e,t])=>{let n=await this.fs.read(e);return{...t,path:e,code:n}}))}async emitEntry(e,t,n={}){let r=(0,M.isAbsolute)(t)?t:(0,v.appendPath)(t,this.entryPath);return this.entry??=[],this.entry.push({name:n.name,file:r,input:n.input,output:n.output}),this.fs.write(r,e,(0,f.default)((0,p.omit)(n,[`name`]),{meta:{type:`entry`,properties:{name:n.name,output:n.output,"input.file":n.input?.file,"input.name":n.input?.name}}}))}emitEntrySync(e,t,n={}){let r=(0,M.isAbsolute)(t)?t:(0,v.appendPath)(t,this.entryPath);return this.entry??=[],this.entry.push({name:n?.name,file:r,input:n?.input,output:n?.output}),this.fs.writeSync(r,e,(0,f.default)((0,p.omit)(n,[`name`]),{meta:{type:`entry`,properties:{name:n?.name,output:n?.output,"input.file":n?.input?.file,"input.name":n?.input?.name}}}))}async emitBuiltin(e,t,n,r={}){return this.fs.write(n?(0,M.isAbsolute)(n)?n:(0,N.joinPaths)(this.builtinsPath,n):(0,v.appendPath)(t,this.builtinsPath),e,(0,f.default)(r,{meta:{type:`builtin`}}))}emitBuiltinSync(e,t,n,r){return this.fs.writeSync(n?(0,M.isAbsolute)(n)?n:(0,N.joinPaths)(this.builtinsPath,n):(0,v.appendPath)(t,this.builtinsPath),e,(0,f.default)(r,{meta:{type:`builtin`}}))}async withUserConfig(e,t={isHighPriority:!0}){this.mergeUserConfig(e),await this.init(this.config.userConfig,t)}async withInlineConfig(e,t={isHighPriority:!0}){if(this.config.inlineConfig=e,e.command===`new`){let e=(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,`package.json`);if(!(0,T.existsSync)(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await(0,S.readJsonFile)(e),this.workspaceConfig.repository??=(0,x.isSetString)(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(h.LogLevelLabel.FATAL,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}error(e){this.log(h.LogLevelLabel.ERROR,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}warn(e){this.log(h.LogLevelLabel.WARN,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}info(e){this.log(h.LogLevelLabel.INFO,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}debug(e){this.log(h.LogLevelLabel.DEBUG,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}trace(e){this.log(h.LogLevelLabel.TRACE,(0,m.isString)(e)?e:C.StormJSON.stringify(e))}createLog(e=null){return c.createLog(e,{...this.config,logLevel:(0,P.isNull)(this.config.logLevel)?`silent`:this.config.logLevel})}extendLog(e){return c.extendLog(this.log,e)}async generateChecksum(e=this.config.projectRoot){return this.#n=await(0,D.hashDirectory)(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,V.set({workspaceRoot:e.workspaceRoot,framework:`powerlines`},(0,E.getEnvPaths)({orgId:((0,b.isSetObject)(e.organization)?e.organization.name:e.organization)||`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot}))}resolvedConfig={};logFn;async init(e={},t={isHighPriority:!0}){let c={projectRoot:e.root??this.config.projectRoot??this.config.userConfig?.root??this.config.inlineConfig?.root,mode:(e.mode??this.config.mode)||this.workspaceConfig.mode,skipCache:e.skipCache??this.config.skipCache??!1,configFile:e.configFile??this.config.configFile,framework:e.framework??this.config.framework??`powerlines`,command:this.config.inlineConfig?.command};if(B.has(c)){let e=B.get(c);this.projectJson=e.projectJson,this.packageJson=e.packageJson,this.#n=e.checksum,this.resolver=e.resolver,this.mergeUserConfig(e.userConfig.config,this.config.userConfig)}else{let t=(0,N.joinPaths)(c.projectRoot,`project.json`);(0,T.existsSync)(t)&&(this.projectJson=await(0,S.readJsonFile)(t));let n=(0,N.joinPaths)(c.projectRoot,`package.json`);(0,T.existsSync)(n)&&(this.packageJson=await(0,S.readJsonFile)(n)),this.#n=await this.generateChecksum(c.projectRoot),this.resolver=i.createResolver({workspaceRoot:this.workspaceConfig.workspaceRoot,projectRoot:c.projectRoot,cacheDir:this.cachePath,mode:c.mode,logLevel:e.logLevel||this.config?.logLevel||this.workspaceConfig.logLevel||`info`,skipCache:c.skipCache});let a=await r.loadUserConfigFile(c.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,c.command,c.mode,c.configFile,c.framework);this.mergeUserConfig(a.config),B.set(c,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:a})}e.tsconfig??=n.getTsconfigFilePath(this.workspaceConfig.workspaceRoot,c.projectRoot,e.tsconfig),(0,b.isSetObject)(e)&&(this.resolvedConfig=(0,f.default)({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},t.isHighPriority?this.#f(e):{},{command:this.config.inlineConfig?.command,...this.#f(this.config.inlineConfig)},this.#f(this.config.userConfig),{mode:this.workspaceConfig?.mode,logLevel:this.workspaceConfig?.logLevel,skipCache:this.workspaceConfig?.skipCache},{name:this.projectJson?.name||this.packageJson?.name,version:this.packageJson?.version,description:this.packageJson?.description,sourceRoot:this.projectJson?.sourceRoot||(0,v.appendPath)(`src`,c.projectRoot),output:(0,f.default)(e.output??{},{outputPath:c.projectRoot?(0,N.joinPaths)(this.workspaceConfig?.directories?.build||`dist`,c.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:(0,N.joinPaths)(c.projectRoot,`.${e.framework??`powerlines`}`),dts:(0,N.joinPaths)(c.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:c.projectRoot,glob:`*.md`},{input:c.projectRoot,glob:`package.json`}]})},t.isHighPriority?{}:this.#f(e),{inlineConfig:{},userConfig:{},framework:`powerlines`,platform:`neutral`,mode:`production`,projectType:`application`,logLevel:`info`,preview:!1,environments:{},transform:{babel:{plugins:[],presets:[]}},lint:{eslint:{}},build:{target:`esnext`,override:{}}})),this.config.entry=s.getUniqueEntries(this.config.entry),this.config.name?.startsWith(`@`)&&this.config.name.split(`/`).filter(Boolean).length>1&&(this.config.name=this.config.name.split(`/`).filter(Boolean)[1]),this.config.title??=(0,w.titleCase)(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=(0,k.getUnique)(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=(0,k.getUnique)(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=(0,k.getUnique)(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=(0,k.getUnique)(this.config.build.noExternal)),this.config.output.format=(0,k.getUnique)((0,d.toArray)(this.config.output?.format??(this.config.projectType===`library`?[`cjs`,`esm`]:[`esm`]))),this.config.projectRoot&&this.config.projectRoot!==`.`&&this.config.projectRoot!==`./`&&this.config.projectRoot!==this.workspaceConfig.workspaceRoot?(this.config.output.outputPath??=(0,N.joinPaths)(`dist`,this.config.projectRoot),this.config.output.buildPath??=(0,N.joinPaths)(this.config.projectRoot,`dist`)):(this.config.output.outputPath??=`dist`,this.config.output.buildPath??=`dist`),this.config.output.assets=(0,k.getUniqueBy)(this.config.output.assets.map(e=>({glob:(0,b.isSetObject)(e)?e.glob:e,input:(0,m.isString)(e)||!e.input||e.input===`.`||e.input===`/`||e.input===`./`?this.workspaceConfig.workspaceRoot:(0,j.isParentPath)(e.input,this.workspaceConfig.workspaceRoot)||e.input===this.workspaceConfig.workspaceRoot?e.input:(0,v.appendPath)(e.input,this.workspaceConfig.workspaceRoot),output:(0,b.isSetObject)(e)&&e.output?(0,j.isParentPath)(e.output,this.workspaceConfig.workspaceRoot)?e.output:(0,v.appendPath)((0,N.joinPaths)(this.config.output.outputPath,(0,y.replacePath)((0,y.replacePath)(e.output,(0,y.replacePath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):(0,v.appendPath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:(0,b.isSetObject)(e)&&e.ignore?(0,d.toArray)(e.ignore):void 0})),e=>`${e.input}-${e.glob}-${e.output}`),this.config.plugins=(this.config.plugins??[]).filter(Boolean).reduce((e,t)=>(a.isPlugin(t)&&a.checkDedupe(t,e.filter(e=>a.isPlugin(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=o.replacePathTokens(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=o.replacePathTokens(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(e=>o.replacePathTokens(this,e))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(e=>({...e,glob:o.replacePathTokens(this,e.glob),ignore:e.ignore?e.ignore.map(e=>o.replacePathTokens(this,e)):void 0,input:o.replacePathTokens(this,e.input),output:o.replacePathTokens(this,e.output)}))),this.#s??=await l.VirtualFileSystem.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=(0,f.default)({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},(0,p.omit)(e??{},[`entry`]),(0,p.omit)(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=(0,k.getUnique)((0,d.toArray)(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(a.isPlugin(t)&&a.checkDedupe(t,e.filter(e=>a.isPlugin(e)))||e.push(t),e),[])}};exports.PowerlinesContext=H;
@@ -1 +1 @@
1
- import{createProgram as e}from"../typescript/ts-morph.mjs";import{getTsconfigFilePath as t}from"../typescript/tsconfig.mjs";import{loadUserConfigFile as n,loadWorkspaceConfig as r}from"../config-file.mjs";import{createResolver as i}from"../../internal/helpers/resolver.mjs";import{checkDedupe as a,isPlugin as o}from"../../plugin-utils/helpers.mjs";import{replacePathTokens as s}from"../../plugin-utils/paths.mjs";import{getUniqueEntries as c,resolveEntriesSync as l}from"../entry.mjs";import{createLog as u,extendLog as d}from"../logger.mjs";import{VirtualFileSystem as f}from"../fs/vfs.mjs";import{CACHE_HASH_LENGTH as p,PROJECT_ROOT_HASH_LENGTH as m,getPrefixedProjectRootHash as h}from"../utilities/meta.mjs";import{toArray as g}from"@stryke/convert/to-array";import _ from"defu";import{omit as v}from"@stryke/helpers/omit";import{isString as y}from"@stryke/type-checks/is-string";import{LogLevelLabel as b}from"@storm-software/config-tools/types";import{relativeToWorkspaceRoot as x}from"@stryke/fs/get-workspace-root";import{resolvePackage as S}from"@stryke/fs/resolve";import{appendPath as C}from"@stryke/path/append";import{replacePath as w}from"@stryke/path/replace";import{isSetObject as T}from"@stryke/type-checks/is-set-object";import{isSetString as E}from"@stryke/type-checks/is-set-string";import{readJsonFile as D}from"@stryke/fs/json";import{StormJSON as O}from"@stryke/json/storm-json";import{titleCase as k}from"@stryke/string-format/title-case";import{existsSync as A}from"@stryke/fs/exists";import{getEnvPaths as j}from"@stryke/env/get-env-paths";import{hashDirectory as M}from"@stryke/hash/hash-files";import{murmurhash as N}from"@stryke/hash/murmurhash";import{getUnique as P,getUniqueBy as F}from"@stryke/helpers/get-unique";import{fetchRequest as I}from"@stryke/http/fetch";import{isParentPath as L}from"@stryke/path/is-parent-path";import{isAbsolute as R}from"@stryke/path/is-type";import{joinPaths as z}from"@stryke/path/join";import{isNull as B}from"@stryke/type-checks/is-null";import{uuid as V}from"@stryke/unique-id/uuid";import{match as H,tsconfigPathsToRegExp as U}from"bundle-require";import{create as W}from"flat-cache";import{parse as G}from"oxc-parser";import{Agent as K,Response as q,interceptors as J,setGlobalDispatcher as Y}from"undici";const X=new WeakMap,Z=new WeakMap;Y(new K({keepAliveTimeout:1e4}).compose(J.retry({maxRetries:3,minTimeout:1e3,maxTimeout:1e4,timeoutFactor:2,retryAfter:!0})));var Q=class K{#e={};#t;#n=null;#r=V();#i=V();#a=Date.now();#o=null;#s;#c;#l;#u;#d;#f(e={}){return _({variant:e.build?.variant,projectType:e.type,projectRoot:e.root,name:e.name,title:e.title,compatibilityDate:e.compatibilityDate,description:e.description,sourceRoot:e.sourceRoot,configFile:e.configFile,customLogger:e.customLogger,logLevel:e.logLevel,tsconfig:e.tsconfig,tsconfigRaw:e.tsconfigRaw,skipCache:e.skipCache,skipInstalls:e.skipInstalls,entry:e.entry,output:e.output,plugins:e.plugins,mode:e.mode,lint:e.lint,transform:e.transform,build:e.build,framework:e.framework,...e},{output:e.framework?{artifactsPath:z(e.root??this.config.projectRoot,`.${e.framework??`powerlines`}`),dts:z(e.root??this.config.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`}:{}})}static async from(e,t){let n=new K(await r(e,t.root));await n.withUserConfig(t);let i=await S(`powerlines`);if(!i)throw Error("Could not resolve `powerlines` package location.");return n.powerlinesPath=i,n}dependencies={};devDependencies={};persistedMeta=void 0;powerlinesPath;packageJson;projectJson=void 0;resolver;resolvePatterns=[];get $$internal(){return this.#e}set $$internal(e){this.#e=e}get entry(){return l(this,this.#o?this.#o:g(this.config.entry))}set entry(e){this.#o=e}get tsconfig(){return this.#c||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#c}set tsconfig(e){this.#c=e,this.resolvePatterns=U(e?.options?.paths??{})}get fs(){return this.#s||=f.createSync(this),this.#s}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:N({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:m}),configHash:N(this.config,{maxLength:p})}}get config(){return this.resolvedConfig??{}}get log(){return this.logFn||=this.createLog(),this.logFn}get workspaceConfig(){return this.#t}get envPaths(){if(Z.has({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`}))return Z.get({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`});let e=j({orgId:`storm-software`,appId:this.config?.framework||`powerlines`,workspaceRoot:this.workspaceConfig.workspaceRoot});return Z.set({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`},e),e}get artifactsPath(){return z(this.workspaceConfig.workspaceRoot,this.config.projectRoot,this.config.output.artifactsPath)}get builtinsPath(){return z(this.artifactsPath,`builtins`)}get entryPath(){return z(this.artifactsPath,`entry`)}get dataPath(){return z(this.envPaths.data,`projects`,h(this.config.name,this.meta.projectRootHash))}get cachePath(){return z(this.envPaths.cache,`projects`,N({checksum:this.#n,config:this.meta.configHash},{maxLength:p}))}get dtsPath(){return this.config.output.dts?C(this.config.output.dts,this.workspaceConfig.workspaceRoot):z(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return x(this.config.projectRoot)}get builtins(){return Object.values(this.fs.metadata).filter(e=>e&&e.type===`builtin`).map(e=>e?.id).filter(Boolean)}get program(){return this.#l||=e(this,{skipAddingFilesFromTsConfig:!0}),this.#l}get parserCache(){return this.#u||=W({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#u}get requestCache(){return this.#d||=W({cacheId:`http`,cacheDir:this.cachePath,ttl:360*60*1e3,lruSize:5e3,persistInterval:250}),this.#d}async fetch(e,t={}){let n=N({input:e.toString(),options:JSON.stringify(t)});if(!this.config.skipCache&&!t.skipCache){let e=this.requestCache.get(n);if(e)return new q(e.body,{status:e.status,statusText:e.statusText,headers:e.headers})}let r=await I(e,{timeout:12e3,...t}),i={body:await r.text(),status:r.status,statusText:r.statusText,headers:Object.fromEntries(r.headers.entries())};if(!this.config.skipCache&&!t.skipCache)try{this.requestCache.set(n,i)}catch{}return new q(i.body,{status:i.status,statusText:i.statusText,headers:i.headers})}async parse(e,t={}){let n=N({code:e,options:t}),r;return!this.config.skipCache&&(r=this.parserCache.get(n),r)?r:(r=await G(`source.${t.lang||`ts`}`,e,{...t,sourceType:`module`,showSemanticErrors:this.config.mode===`development`}),this.config.skipCache||this.parserCache.set(n,r),r)}async resolve(e,t,n={}){let r=e;if(this.config.build.alias)if(Array.isArray(this.config.build.alias)){let e=this.config.build.alias.find(e=>H(r,[e.find]));e&&(r=e.replacement)}else T(this.config.build.alias)&&this.config.build.alias[e]&&(r=this.config.build.alias[e]);if(this.fs.isVirtual(r)){let e=await this.fs.resolve(r,t,{conditions:this.config.build.conditions,extensions:this.config.build.extensions,...n});return e?{id:`\0${e}`,external:this.config.projectType!==`application`}:void 0}if(this.config.build.skipNodeModulesBundle){if(H(r,this.resolvePatterns)||H(r,this.config.build.noExternal))return;if(H(r,this.config.build.external)||r.startsWith(`node:`)||!/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(r))return{id:r,external:!0}}else{if(H(r,this.config.build.noExternal))return;if(H(r,this.config.build.external)||r.startsWith(`node:`))return{id:r,external:!0}}}async load(e){let t=await this.fs.resolve(e);if(!t)return;let n=await this.fs.read(t);if(n)return{code:n,map:null}}async getBuiltins(){return Promise.all(Object.entries(this.fs.metadata).filter(([,e])=>e&&e.type===`builtin`).map(async([e,t])=>{let n=await this.fs.read(e);return{...t,path:e,code:n}}))}async emitEntry(e,t,n={}){let r=R(t)?t:C(t,this.entryPath);return this.entry??=[],this.entry.push({name:n.name,file:r,input:n.input,output:n.output}),this.fs.write(r,e,_(v(n,[`name`]),{meta:{type:`entry`,properties:{name:n.name,output:n.output,"input.file":n.input?.file,"input.name":n.input?.name}}}))}async emitBuiltin(e,t,n,r={}){return this.fs.write(n?R(n)?n:z(this.builtinsPath,n):C(t,this.builtinsPath),e,_(r,{meta:{type:`builtin`}}))}async withUserConfig(e,t={isHighPriority:!0}){this.mergeUserConfig(e),await this.init(this.config.userConfig,t)}async withInlineConfig(e,t={isHighPriority:!0}){if(this.config.inlineConfig=e,e.command===`new`){let e=z(this.workspaceConfig.workspaceRoot,`package.json`);if(!A(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await D(e),this.workspaceConfig.repository??=E(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(b.FATAL,y(e)?e:O.stringify(e))}error(e){this.log(b.ERROR,y(e)?e:O.stringify(e))}warn(e){this.log(b.WARN,y(e)?e:O.stringify(e))}info(e){this.log(b.INFO,y(e)?e:O.stringify(e))}debug(e){this.log(b.DEBUG,y(e)?e:O.stringify(e))}trace(e){this.log(b.TRACE,y(e)?e:O.stringify(e))}createLog(e=null){return u(e,{...this.config,logLevel:B(this.config.logLevel)?`silent`:this.config.logLevel})}extendLog(e){return d(this.log,e)}async generateChecksum(e=this.config.projectRoot){return this.#n=await M(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,Z.set({workspaceRoot:e.workspaceRoot,framework:`powerlines`},j({orgId:(T(e.organization)?e.organization.name:e.organization)||`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot}))}resolvedConfig={};logFn;async init(e={},r={isHighPriority:!0}){let l={projectRoot:e.root??this.config.projectRoot??this.config.userConfig?.root??this.config.inlineConfig?.root,mode:(e.mode??this.config.mode)||this.workspaceConfig.mode,skipCache:e.skipCache??this.config.skipCache??!1,configFile:e.configFile??this.config.configFile,framework:e.framework??this.config.framework??`powerlines`,command:this.config.inlineConfig?.command};if(X.has(l)){let e=X.get(l);this.projectJson=e.projectJson,this.packageJson=e.packageJson,this.#n=e.checksum,this.resolver=e.resolver,this.mergeUserConfig(e.userConfig.config,this.config.userConfig)}else{let t=z(l.projectRoot,`project.json`);A(t)&&(this.projectJson=await D(t));let r=z(l.projectRoot,`package.json`);A(r)&&(this.packageJson=await D(r)),this.#n=await this.generateChecksum(l.projectRoot),this.resolver=i({workspaceRoot:this.workspaceConfig.workspaceRoot,projectRoot:l.projectRoot,cacheDir:this.cachePath,mode:l.mode,logLevel:e.logLevel||this.config?.logLevel||this.workspaceConfig.logLevel||`info`,skipCache:l.skipCache});let a=await n(l.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,l.command,l.mode,l.configFile,l.framework);this.mergeUserConfig(a.config),X.set(l,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:a})}e.tsconfig??=t(this.workspaceConfig.workspaceRoot,l.projectRoot,e.tsconfig),T(e)&&(this.resolvedConfig=_({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},r.isHighPriority?this.#f(e):{},{command:this.config.inlineConfig?.command,...this.#f(this.config.inlineConfig)},this.#f(this.config.userConfig),{mode:this.workspaceConfig?.mode,logLevel:this.workspaceConfig?.logLevel,skipCache:this.workspaceConfig?.skipCache},{name:this.projectJson?.name||this.packageJson?.name,version:this.packageJson?.version,description:this.packageJson?.description,sourceRoot:this.projectJson?.sourceRoot||C(`src`,l.projectRoot),output:_(e.output??{},{outputPath:l.projectRoot?z(this.workspaceConfig?.directories?.build||`dist`,l.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:z(l.projectRoot,`.${e.framework??`powerlines`}`),dts:z(l.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:l.projectRoot,glob:`*.md`},{input:l.projectRoot,glob:`package.json`}]})},r.isHighPriority?{}:this.#f(e),{inlineConfig:{},userConfig:{},framework:`powerlines`,platform:`neutral`,mode:`production`,projectType:`application`,logLevel:`info`,preview:!1,environments:{},transform:{babel:{plugins:[],presets:[]}},lint:{eslint:{}},build:{target:`esnext`,override:{}}})),this.config.entry=c(this.config.entry),this.config.name?.startsWith(`@`)&&this.config.name.split(`/`).filter(Boolean).length>1&&(this.config.name=this.config.name.split(`/`).filter(Boolean)[1]),this.config.title??=k(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=P(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=P(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=P(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=P(this.config.build.noExternal)),this.config.output.format=P(g(this.config.output?.format??(this.config.projectType===`library`?[`cjs`,`esm`]:[`esm`]))),this.config.projectRoot&&this.config.projectRoot!==`.`&&this.config.projectRoot!==`./`&&this.config.projectRoot!==this.workspaceConfig.workspaceRoot?(this.config.output.outputPath??=z(`dist`,this.config.projectRoot),this.config.output.buildPath??=z(this.config.projectRoot,`dist`)):(this.config.output.outputPath??=`dist`,this.config.output.buildPath??=`dist`),this.config.output.assets=F(this.config.output.assets.map(e=>({glob:T(e)?e.glob:e,input:y(e)||!e.input||e.input===`.`||e.input===`/`||e.input===`./`?this.workspaceConfig.workspaceRoot:L(e.input,this.workspaceConfig.workspaceRoot)||e.input===this.workspaceConfig.workspaceRoot?e.input:C(e.input,this.workspaceConfig.workspaceRoot),output:T(e)&&e.output?L(e.output,this.workspaceConfig.workspaceRoot)?e.output:C(z(this.config.output.outputPath,w(w(e.output,w(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):C(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:T(e)&&e.ignore?g(e.ignore):void 0})),e=>`${e.input}-${e.glob}-${e.output}`),this.config.plugins=(this.config.plugins??[]).filter(Boolean).reduce((e,t)=>(o(t)&&a(t,e.filter(e=>o(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=s(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=s(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(e=>s(this,e))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(e=>({...e,glob:s(this,e.glob),ignore:e.ignore?e.ignore.map(e=>s(this,e)):void 0,input:s(this,e.input),output:s(this,e.output)}))),this.#s??=await f.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=_({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},v(e??{},[`entry`]),v(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=P(g(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(o(t)&&a(t,e.filter(e=>o(e)))||e.push(t),e),[])}};export{Q as PowerlinesContext};
1
+ import{createProgram as e}from"../typescript/ts-morph.mjs";import{getTsconfigFilePath as t}from"../typescript/tsconfig.mjs";import{loadUserConfigFile as n,loadWorkspaceConfig as r}from"../config-file.mjs";import{createResolver as i}from"../../internal/helpers/resolver.mjs";import{checkDedupe as a,isPlugin as o}from"../../plugin-utils/helpers.mjs";import{replacePathTokens as s}from"../../plugin-utils/paths.mjs";import{getUniqueEntries as c,resolveEntriesSync as l}from"../entry.mjs";import{createLog as u,extendLog as d}from"../logger.mjs";import{VirtualFileSystem as f}from"../fs/vfs.mjs";import{CACHE_HASH_LENGTH as p,PROJECT_ROOT_HASH_LENGTH as m,getPrefixedProjectRootHash as h}from"../utilities/meta.mjs";import{toArray as g}from"@stryke/convert/to-array";import _ from"defu";import{omit as v}from"@stryke/helpers/omit";import{isString as y}from"@stryke/type-checks/is-string";import{LogLevelLabel as b}from"@storm-software/config-tools/types";import{relativeToWorkspaceRoot as x}from"@stryke/fs/get-workspace-root";import{resolvePackage as S}from"@stryke/fs/resolve";import{appendPath as C}from"@stryke/path/append";import{replacePath as w}from"@stryke/path/replace";import{isSetObject as T}from"@stryke/type-checks/is-set-object";import{isSetString as E}from"@stryke/type-checks/is-set-string";import{readJsonFile as D}from"@stryke/fs/json";import{StormJSON as O}from"@stryke/json/storm-json";import{titleCase as k}from"@stryke/string-format/title-case";import{existsSync as A}from"@stryke/fs/exists";import{getEnvPaths as j}from"@stryke/env/get-env-paths";import{hashDirectory as M}from"@stryke/hash/hash-files";import{murmurhash as N}from"@stryke/hash/murmurhash";import{getUnique as P,getUniqueBy as F}from"@stryke/helpers/get-unique";import{fetchRequest as I}from"@stryke/http/fetch";import{isParentPath as L}from"@stryke/path/is-parent-path";import{isAbsolute as R}from"@stryke/path/is-type";import{joinPaths as z}from"@stryke/path/join";import{isNull as B}from"@stryke/type-checks/is-null";import{uuid as V}from"@stryke/unique-id/uuid";import{match as H,tsconfigPathsToRegExp as U}from"bundle-require";import{create as W}from"flat-cache";import{parse as G}from"oxc-parser";import{Agent as K,Response as q,interceptors as J,setGlobalDispatcher as Y}from"undici";const X=new WeakMap,Z=new WeakMap;Y(new K({keepAliveTimeout:1e4}).compose(J.retry({maxRetries:3,minTimeout:1e3,maxTimeout:1e4,timeoutFactor:2,retryAfter:!0})));var Q=class K{#e={};#t;#n=null;#r=V();#i=V();#a=Date.now();#o=null;#s;#c;#l;#u;#d;#f(e={}){return _({variant:e.build?.variant,projectType:e.type,projectRoot:e.root,name:e.name,title:e.title,compatibilityDate:e.compatibilityDate,description:e.description,sourceRoot:e.sourceRoot,configFile:e.configFile,customLogger:e.customLogger,logLevel:e.logLevel,tsconfig:e.tsconfig,tsconfigRaw:e.tsconfigRaw,skipCache:e.skipCache,skipInstalls:e.skipInstalls,entry:e.entry,output:e.output,plugins:e.plugins,mode:e.mode,lint:e.lint,transform:e.transform,build:e.build,framework:e.framework,...e},{output:e.framework?{artifactsPath:z(e.root??this.config.projectRoot,`.${e.framework??`powerlines`}`),dts:z(e.root??this.config.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`}:{}})}static async from(e,t){let n=new K(await r(e,t.root));await n.withUserConfig(t);let i=await S(`powerlines`);if(!i)throw Error("Could not resolve `powerlines` package location.");return n.powerlinesPath=i,n}dependencies={};devDependencies={};persistedMeta=void 0;powerlinesPath;packageJson;projectJson=void 0;resolver;resolvePatterns=[];get $$internal(){return this.#e}set $$internal(e){this.#e=e}get entry(){return l(this,this.#o?this.#o:g(this.config.entry))}set entry(e){this.#o=e}get tsconfig(){return this.#c||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#c}set tsconfig(e){this.#c=e,this.resolvePatterns=U(e?.options?.paths??{})}get fs(){return this.#s||=f.createSync(this),this.#s}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:N({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:m}),configHash:N(this.config,{maxLength:p})}}get config(){return this.resolvedConfig??{}}get log(){return this.logFn||=this.createLog(),this.logFn}get workspaceConfig(){return this.#t}get envPaths(){if(Z.has({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`}))return Z.get({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`});let e=j({orgId:`storm-software`,appId:this.config?.framework||`powerlines`,workspaceRoot:this.workspaceConfig.workspaceRoot});return Z.set({workspaceRoot:this.workspaceConfig.workspaceRoot,framework:this.config?.framework||`powerlines`},e),e}get artifactsPath(){return z(this.workspaceConfig.workspaceRoot,this.config.projectRoot,this.config.output.artifactsPath)}get builtinsPath(){return z(this.artifactsPath,`builtins`)}get entryPath(){return z(this.artifactsPath,`entry`)}get dataPath(){return z(this.envPaths.data,`projects`,h(this.config.name,this.meta.projectRootHash))}get cachePath(){return z(this.envPaths.cache,`projects`,N({checksum:this.#n,config:this.meta.configHash},{maxLength:p}))}get dtsPath(){return this.config.output.dts?C(this.config.output.dts,this.workspaceConfig.workspaceRoot):z(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return x(this.config.projectRoot)}get builtins(){return Object.values(this.fs.metadata).filter(e=>e&&e.type===`builtin`).map(e=>e?.id).filter(Boolean)}get program(){return this.#l||=e(this,{skipAddingFilesFromTsConfig:!0}),this.#l}get parserCache(){return this.#u||=W({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#u}get requestCache(){return this.#d||=W({cacheId:`http`,cacheDir:this.cachePath,ttl:360*60*1e3,lruSize:5e3,persistInterval:250}),this.#d}async fetch(e,t={}){let n=N({input:e.toString(),options:JSON.stringify(t)});if(!this.config.skipCache&&!t.skipCache){let e=this.requestCache.get(n);if(e)return new q(e.body,{status:e.status,statusText:e.statusText,headers:e.headers})}let r=await I(e,{timeout:12e3,...t}),i={body:await r.text(),status:r.status,statusText:r.statusText,headers:Object.fromEntries(r.headers.entries())};if(!this.config.skipCache&&!t.skipCache)try{this.requestCache.set(n,i)}catch{}return new q(i.body,{status:i.status,statusText:i.statusText,headers:i.headers})}async parse(e,t={}){let n=N({code:e,options:t}),r;return!this.config.skipCache&&(r=this.parserCache.get(n),r)?r:(r=await G(`source.${t.lang||`ts`}`,e,{...t,sourceType:`module`,showSemanticErrors:this.config.mode===`development`}),this.config.skipCache||this.parserCache.set(n,r),r)}async resolve(e,t,n={}){let r=e;if(this.config.build.alias)if(Array.isArray(this.config.build.alias)){let e=this.config.build.alias.find(e=>H(r,[e.find]));e&&(r=e.replacement)}else T(this.config.build.alias)&&this.config.build.alias[e]&&(r=this.config.build.alias[e]);if(this.fs.isVirtual(r)){let e=await this.fs.resolve(r,t,{conditions:this.config.build.conditions,extensions:this.config.build.extensions,...n});return e?{id:`\0${e}`,external:this.config.projectType!==`application`}:void 0}if(this.config.build.skipNodeModulesBundle){if(H(r,this.resolvePatterns)||H(r,this.config.build.noExternal))return;if(H(r,this.config.build.external)||r.startsWith(`node:`)||!/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(r))return{id:r,external:!0}}else{if(H(r,this.config.build.noExternal))return;if(H(r,this.config.build.external)||r.startsWith(`node:`))return{id:r,external:!0}}}async load(e){let t=await this.fs.resolve(e);if(!t)return;let n=await this.fs.read(t);if(n)return{code:n,map:null}}async getBuiltins(){return Promise.all(Object.entries(this.fs.metadata).filter(([,e])=>e&&e.type===`builtin`).map(async([e,t])=>{let n=await this.fs.read(e);return{...t,path:e,code:n}}))}async emitEntry(e,t,n={}){let r=R(t)?t:C(t,this.entryPath);return this.entry??=[],this.entry.push({name:n.name,file:r,input:n.input,output:n.output}),this.fs.write(r,e,_(v(n,[`name`]),{meta:{type:`entry`,properties:{name:n.name,output:n.output,"input.file":n.input?.file,"input.name":n.input?.name}}}))}emitEntrySync(e,t,n={}){let r=R(t)?t:C(t,this.entryPath);return this.entry??=[],this.entry.push({name:n?.name,file:r,input:n?.input,output:n?.output}),this.fs.writeSync(r,e,_(v(n,[`name`]),{meta:{type:`entry`,properties:{name:n?.name,output:n?.output,"input.file":n?.input?.file,"input.name":n?.input?.name}}}))}async emitBuiltin(e,t,n,r={}){return this.fs.write(n?R(n)?n:z(this.builtinsPath,n):C(t,this.builtinsPath),e,_(r,{meta:{type:`builtin`}}))}emitBuiltinSync(e,t,n,r){return this.fs.writeSync(n?R(n)?n:z(this.builtinsPath,n):C(t,this.builtinsPath),e,_(r,{meta:{type:`builtin`}}))}async withUserConfig(e,t={isHighPriority:!0}){this.mergeUserConfig(e),await this.init(this.config.userConfig,t)}async withInlineConfig(e,t={isHighPriority:!0}){if(this.config.inlineConfig=e,e.command===`new`){let e=z(this.workspaceConfig.workspaceRoot,`package.json`);if(!A(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await D(e),this.workspaceConfig.repository??=E(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(b.FATAL,y(e)?e:O.stringify(e))}error(e){this.log(b.ERROR,y(e)?e:O.stringify(e))}warn(e){this.log(b.WARN,y(e)?e:O.stringify(e))}info(e){this.log(b.INFO,y(e)?e:O.stringify(e))}debug(e){this.log(b.DEBUG,y(e)?e:O.stringify(e))}trace(e){this.log(b.TRACE,y(e)?e:O.stringify(e))}createLog(e=null){return u(e,{...this.config,logLevel:B(this.config.logLevel)?`silent`:this.config.logLevel})}extendLog(e){return d(this.log,e)}async generateChecksum(e=this.config.projectRoot){return this.#n=await M(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,Z.set({workspaceRoot:e.workspaceRoot,framework:`powerlines`},j({orgId:(T(e.organization)?e.organization.name:e.organization)||`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot}))}resolvedConfig={};logFn;async init(e={},r={isHighPriority:!0}){let l={projectRoot:e.root??this.config.projectRoot??this.config.userConfig?.root??this.config.inlineConfig?.root,mode:(e.mode??this.config.mode)||this.workspaceConfig.mode,skipCache:e.skipCache??this.config.skipCache??!1,configFile:e.configFile??this.config.configFile,framework:e.framework??this.config.framework??`powerlines`,command:this.config.inlineConfig?.command};if(X.has(l)){let e=X.get(l);this.projectJson=e.projectJson,this.packageJson=e.packageJson,this.#n=e.checksum,this.resolver=e.resolver,this.mergeUserConfig(e.userConfig.config,this.config.userConfig)}else{let t=z(l.projectRoot,`project.json`);A(t)&&(this.projectJson=await D(t));let r=z(l.projectRoot,`package.json`);A(r)&&(this.packageJson=await D(r)),this.#n=await this.generateChecksum(l.projectRoot),this.resolver=i({workspaceRoot:this.workspaceConfig.workspaceRoot,projectRoot:l.projectRoot,cacheDir:this.cachePath,mode:l.mode,logLevel:e.logLevel||this.config?.logLevel||this.workspaceConfig.logLevel||`info`,skipCache:l.skipCache});let a=await n(l.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,l.command,l.mode,l.configFile,l.framework);this.mergeUserConfig(a.config),X.set(l,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:a})}e.tsconfig??=t(this.workspaceConfig.workspaceRoot,l.projectRoot,e.tsconfig),T(e)&&(this.resolvedConfig=_({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},r.isHighPriority?this.#f(e):{},{command:this.config.inlineConfig?.command,...this.#f(this.config.inlineConfig)},this.#f(this.config.userConfig),{mode:this.workspaceConfig?.mode,logLevel:this.workspaceConfig?.logLevel,skipCache:this.workspaceConfig?.skipCache},{name:this.projectJson?.name||this.packageJson?.name,version:this.packageJson?.version,description:this.packageJson?.description,sourceRoot:this.projectJson?.sourceRoot||C(`src`,l.projectRoot),output:_(e.output??{},{outputPath:l.projectRoot?z(this.workspaceConfig?.directories?.build||`dist`,l.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:z(l.projectRoot,`.${e.framework??`powerlines`}`),dts:z(l.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:l.projectRoot,glob:`*.md`},{input:l.projectRoot,glob:`package.json`}]})},r.isHighPriority?{}:this.#f(e),{inlineConfig:{},userConfig:{},framework:`powerlines`,platform:`neutral`,mode:`production`,projectType:`application`,logLevel:`info`,preview:!1,environments:{},transform:{babel:{plugins:[],presets:[]}},lint:{eslint:{}},build:{target:`esnext`,override:{}}})),this.config.entry=c(this.config.entry),this.config.name?.startsWith(`@`)&&this.config.name.split(`/`).filter(Boolean).length>1&&(this.config.name=this.config.name.split(`/`).filter(Boolean)[1]),this.config.title??=k(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=P(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=P(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=P(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=P(this.config.build.noExternal)),this.config.output.format=P(g(this.config.output?.format??(this.config.projectType===`library`?[`cjs`,`esm`]:[`esm`]))),this.config.projectRoot&&this.config.projectRoot!==`.`&&this.config.projectRoot!==`./`&&this.config.projectRoot!==this.workspaceConfig.workspaceRoot?(this.config.output.outputPath??=z(`dist`,this.config.projectRoot),this.config.output.buildPath??=z(this.config.projectRoot,`dist`)):(this.config.output.outputPath??=`dist`,this.config.output.buildPath??=`dist`),this.config.output.assets=F(this.config.output.assets.map(e=>({glob:T(e)?e.glob:e,input:y(e)||!e.input||e.input===`.`||e.input===`/`||e.input===`./`?this.workspaceConfig.workspaceRoot:L(e.input,this.workspaceConfig.workspaceRoot)||e.input===this.workspaceConfig.workspaceRoot?e.input:C(e.input,this.workspaceConfig.workspaceRoot),output:T(e)&&e.output?L(e.output,this.workspaceConfig.workspaceRoot)?e.output:C(z(this.config.output.outputPath,w(w(e.output,w(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):C(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:T(e)&&e.ignore?g(e.ignore):void 0})),e=>`${e.input}-${e.glob}-${e.output}`),this.config.plugins=(this.config.plugins??[]).filter(Boolean).reduce((e,t)=>(o(t)&&a(t,e.filter(e=>o(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=s(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=s(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(e=>s(this,e))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(e=>({...e,glob:s(this,e.glob),ignore:e.ignore?e.ignore.map(e=>s(this,e)):void 0,input:s(this,e.input),output:s(this,e.output)}))),this.#s??=await f.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=_({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},v(e??{},[`entry`]),v(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=P(g(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(o(t)&&a(t,e.filter(e=>o(e)))||e.push(t),e),[])}};export{Q as PowerlinesContext};
@@ -1 +1 @@
1
- const e=require(`../../../../../_virtual/rolldown_runtime.cjs`);let t=require(`@stryke/path/append`),n=require(`@stryke/path/join`),r=require(`@stryke/path/correct-path`),i=require(`node:path`);var a=class{#e=!1;options;constructor(e={base:`/`}){this.options=e,this.options.base=(0,i.resolve)(e.base),this.options.isReadOnly=!!e.isReadOnly}async exists(e){return this.existsSync(e)}async get(e){return this.getSync(e)}async set(e,t){this.options.isReadOnly||this.setSync(e,t)}mkdirSync(e){}async mkdir(e){return Promise.resolve(this.mkdirSync(e))}async remove(e){this.options.isReadOnly||this.removeSync(e)}clearSync(e){if(!this.options.isReadOnly){let t=this.listSync(e||this.options.base);if(!t.length)return;t.map(t=>this.removeSync(e&&!t.startsWith(e)?(0,n.joinPaths)(e,t):t))}}async clear(e){if(!this.options.isReadOnly){let t=await this.list(e||this.options.base);if(!t.length)return;await Promise.all(t.map(async t=>this.remove(e&&!t.startsWith(e)?(0,n.joinPaths)(e,t):t)))}}async list(e){return this.listSync(e)}isDirectorySync(e){return!1}async isDirectory(e){return Promise.resolve(this.isDirectorySync(e))}isFileSync(e){return this.existsSync(e)&&!this.isDirectorySync(e)}async isFile(e){return Promise.resolve(this.isFileSync(e))}dispose(){return Promise.resolve()}async[Symbol.asyncDispose](){return this._dispose()}resolve(e=this.options.base){if(/\.\.:|\.\.$/.test(e))throw Error(`[${this.name}]: Invalid key: ${JSON.stringify(e)} provided to storage adapter.`);return(0,t.appendPath)((0,r.correctPath)(e).replace(/:/g,`/`),this.options.base)}async _dispose(){this.#e||=(await Promise.resolve(this.dispose()),!0)}};exports.BaseStorageAdapter=a;
1
+ const e=require(`../../../../../_virtual/rolldown_runtime.cjs`);let t=require(`@stryke/path/append`),n=require(`@stryke/path/join`),r=require(`@stryke/path/correct-path`),i=require(`node:path`);var a=class{#e=!1;options;preset=null;constructor(e={base:`/`}){this.options=e,this.options.base=(0,i.resolve)(e.base),this.options.isReadOnly=!!e.isReadOnly}async exists(e){return this.existsSync(e)}async get(e){return this.getSync(e)}async set(e,t){this.options.isReadOnly||this.setSync(e,t)}mkdirSync(e){}async mkdir(e){return Promise.resolve(this.mkdirSync(e))}async remove(e){this.options.isReadOnly||this.removeSync(e)}clearSync(e){if(!this.options.isReadOnly){let t=this.listSync(e||this.options.base);if(!t.length)return;t.map(t=>this.removeSync(e&&!t.startsWith(e)?(0,n.joinPaths)(e,t):t))}}async clear(e){if(!this.options.isReadOnly){let t=await this.list(e||this.options.base);if(!t.length)return;await Promise.all(t.map(async t=>this.remove(e&&!t.startsWith(e)?(0,n.joinPaths)(e,t):t)))}}async list(e){return this.listSync(e)}isDirectorySync(e){return!1}async isDirectory(e){return Promise.resolve(this.isDirectorySync(e))}isFileSync(e){return this.existsSync(e)&&!this.isDirectorySync(e)}async isFile(e){return Promise.resolve(this.isFileSync(e))}dispose(){return Promise.resolve()}async[Symbol.asyncDispose](){return this._dispose()}resolve(e=this.options.base){if(/\.\.:|\.\.$/.test(e))throw Error(`[${this.name}]: Invalid key: ${JSON.stringify(e)} provided to storage adapter.`);return(0,t.appendPath)((0,r.correctPath)(e).replace(/:/g,`/`),this.options.base)}async _dispose(){this.#e||=(await Promise.resolve(this.dispose()),!0)}};exports.BaseStorageAdapter=a;
@@ -1 +1 @@
1
- import{appendPath as e}from"@stryke/path/append";import{joinPaths as t}from"@stryke/path/join";import{correctPath as n}from"@stryke/path/correct-path";import{resolve as r}from"node:path";var i=class{#e=!1;options;constructor(e={base:`/`}){this.options=e,this.options.base=r(e.base),this.options.isReadOnly=!!e.isReadOnly}async exists(e){return this.existsSync(e)}async get(e){return this.getSync(e)}async set(e,t){this.options.isReadOnly||this.setSync(e,t)}mkdirSync(e){}async mkdir(e){return Promise.resolve(this.mkdirSync(e))}async remove(e){this.options.isReadOnly||this.removeSync(e)}clearSync(e){if(!this.options.isReadOnly){let n=this.listSync(e||this.options.base);if(!n.length)return;n.map(n=>this.removeSync(e&&!n.startsWith(e)?t(e,n):n))}}async clear(e){if(!this.options.isReadOnly){let n=await this.list(e||this.options.base);if(!n.length)return;await Promise.all(n.map(async n=>this.remove(e&&!n.startsWith(e)?t(e,n):n)))}}async list(e){return this.listSync(e)}isDirectorySync(e){return!1}async isDirectory(e){return Promise.resolve(this.isDirectorySync(e))}isFileSync(e){return this.existsSync(e)&&!this.isDirectorySync(e)}async isFile(e){return Promise.resolve(this.isFileSync(e))}dispose(){return Promise.resolve()}async[Symbol.asyncDispose](){return this._dispose()}resolve(t=this.options.base){if(/\.\.:|\.\.$/.test(t))throw Error(`[${this.name}]: Invalid key: ${JSON.stringify(t)} provided to storage adapter.`);return e(n(t).replace(/:/g,`/`),this.options.base)}async _dispose(){this.#e||=(await Promise.resolve(this.dispose()),!0)}};export{i as BaseStorageAdapter};
1
+ import{appendPath as e}from"@stryke/path/append";import{joinPaths as t}from"@stryke/path/join";import{correctPath as n}from"@stryke/path/correct-path";import{resolve as r}from"node:path";var i=class{#e=!1;options;preset=null;constructor(e={base:`/`}){this.options=e,this.options.base=r(e.base),this.options.isReadOnly=!!e.isReadOnly}async exists(e){return this.existsSync(e)}async get(e){return this.getSync(e)}async set(e,t){this.options.isReadOnly||this.setSync(e,t)}mkdirSync(e){}async mkdir(e){return Promise.resolve(this.mkdirSync(e))}async remove(e){this.options.isReadOnly||this.removeSync(e)}clearSync(e){if(!this.options.isReadOnly){let n=this.listSync(e||this.options.base);if(!n.length)return;n.map(n=>this.removeSync(e&&!n.startsWith(e)?t(e,n):n))}}async clear(e){if(!this.options.isReadOnly){let n=await this.list(e||this.options.base);if(!n.length)return;await Promise.all(n.map(async n=>this.remove(e&&!n.startsWith(e)?t(e,n):n)))}}async list(e){return this.listSync(e)}isDirectorySync(e){return!1}async isDirectory(e){return Promise.resolve(this.isDirectorySync(e))}isFileSync(e){return this.existsSync(e)&&!this.isDirectorySync(e)}async isFile(e){return Promise.resolve(this.isFileSync(e))}dispose(){return Promise.resolve()}async[Symbol.asyncDispose](){return this._dispose()}resolve(t=this.options.base){if(/\.\.:|\.\.$/.test(t))throw Error(`[${this.name}]: Invalid key: ${JSON.stringify(t)} provided to storage adapter.`);return e(n(t).replace(/:/g,`/`),this.options.base)}async _dispose(){this.#e||=(await Promise.resolve(this.dispose()),!0)}};export{i as BaseStorageAdapter};
@@ -1 +1 @@
1
- const e=require(`../../../../../_virtual/rolldown_runtime.cjs`),t=require(`../helpers.cjs`),n=require(`./base.cjs`);let r=require(`node:fs`),i=require(`@stryke/fs/helpers`),a=require(`@stryke/fs/list-files`),o=require(`@stryke/fs/exists`),s=require(`@stryke/fs/is-file`),c=require(`@stryke/fs/read-file`),l=require(`@stryke/fs/write-file`),u=require(`node:fs/promises`);var d=class extends n.BaseStorageAdapter{name=`file-system`;constructor(e){super(e)}existsSync(e){return(0,o.existsSync)(this.resolve(e))}async exists(e){return(0,o.exists)(this.resolve(e))}getSync(e){return(0,c.readFileSync)(this.resolve(e))}async get(e){return(0,c.readFile)(this.resolve(e))}setSync(e,t){if(!this.options.isReadOnly)return(0,l.writeFileSync)(this.resolve(e),t)}async set(e,t){if(!this.options.isReadOnly)return(0,l.writeFile)(this.resolve(e),t)}removeSync(e){if(!this.options.isReadOnly)try{return(0,r.unlinkSync)(this.resolve(e))}catch(e){return t.ignoreNotfound(e)}}async remove(e){if(!this.options.isReadOnly)return(0,u.unlink)(this.resolve(e)).catch(t.ignoreNotfound)}mkdirSync(e){(0,i.createDirectorySync)(this.resolve(e))}async mkdir(e){await(0,i.createDirectory)(this.resolve(e))}listSync(e){try{return(0,a.listFilesSync)(this.resolve(e),{ignore:this.options.ignore})}catch(e){return t.ignoreNotfound(e)??[]}}async list(e){return(0,a.listFiles)(this.resolve(e),{ignore:this.options.ignore}).catch(t.ignoreNotfound).then(e=>e||[])}isDirectorySync(e){return(0,s.isDirectory)(this.resolve(e))}isFileSync(e){return!(0,s.isFile)(this.resolve(e))}};exports.FileSystemStorageAdapter=d;
1
+ const e=require(`../../../../../_virtual/rolldown_runtime.cjs`),t=require(`../helpers.cjs`),n=require(`./base.cjs`);let r=require(`node:fs`),i=require(`@stryke/fs/helpers`),a=require(`@stryke/fs/list-files`),o=require(`@stryke/fs/exists`),s=require(`@stryke/fs/is-file`),c=require(`@stryke/fs/read-file`),l=require(`@stryke/fs/write-file`),u=require(`node:fs/promises`);var d=class extends n.BaseStorageAdapter{name=`file-system`;preset=`fs`;constructor(e){super(e)}existsSync(e){return(0,o.existsSync)(this.resolve(e))}async exists(e){return(0,o.exists)(this.resolve(e))}getSync(e){return(0,c.readFileSync)(this.resolve(e))}async get(e){return(0,c.readFile)(this.resolve(e))}setSync(e,t){if(!this.options.isReadOnly)return(0,l.writeFileSync)(this.resolve(e),t)}async set(e,t){if(!this.options.isReadOnly)return(0,l.writeFile)(this.resolve(e),t)}removeSync(e){if(!this.options.isReadOnly)try{return(0,r.unlinkSync)(this.resolve(e))}catch(e){return t.ignoreNotfound(e)}}async remove(e){if(!this.options.isReadOnly)return(0,u.unlink)(this.resolve(e)).catch(t.ignoreNotfound)}mkdirSync(e){(0,i.createDirectorySync)(this.resolve(e))}async mkdir(e){await(0,i.createDirectory)(this.resolve(e))}listSync(e){try{return(0,a.listFilesSync)(this.resolve(e),{ignore:this.options.ignore})}catch(e){return t.ignoreNotfound(e)??[]}}async list(e){return(0,a.listFiles)(this.resolve(e),{ignore:this.options.ignore}).catch(t.ignoreNotfound).then(e=>e||[])}isDirectorySync(e){return(0,s.isDirectory)(this.resolve(e))}isFileSync(e){return!(0,s.isFile)(this.resolve(e))}};exports.FileSystemStorageAdapter=d;
@@ -1 +1 @@
1
- import{ignoreNotfound as e}from"../helpers.mjs";import{BaseStorageAdapter as t}from"./base.mjs";import{unlinkSync as n}from"node:fs";import{createDirectory as r,createDirectorySync as i}from"@stryke/fs/helpers";import{listFiles as a,listFilesSync as o}from"@stryke/fs/list-files";import{exists as s,existsSync as c}from"@stryke/fs/exists";import{isDirectory as l,isFile as u}from"@stryke/fs/is-file";import{readFile as d,readFileSync as f}from"@stryke/fs/read-file";import{writeFile as p,writeFileSync as m}from"@stryke/fs/write-file";import{unlink as h}from"node:fs/promises";var g=class extends t{name=`file-system`;constructor(e){super(e)}existsSync(e){return c(this.resolve(e))}async exists(e){return s(this.resolve(e))}getSync(e){return f(this.resolve(e))}async get(e){return d(this.resolve(e))}setSync(e,t){if(!this.options.isReadOnly)return m(this.resolve(e),t)}async set(e,t){if(!this.options.isReadOnly)return p(this.resolve(e),t)}removeSync(t){if(!this.options.isReadOnly)try{return n(this.resolve(t))}catch(t){return e(t)}}async remove(t){if(!this.options.isReadOnly)return h(this.resolve(t)).catch(e)}mkdirSync(e){i(this.resolve(e))}async mkdir(e){await r(this.resolve(e))}listSync(t){try{return o(this.resolve(t),{ignore:this.options.ignore})}catch(t){return e(t)??[]}}async list(t){return a(this.resolve(t),{ignore:this.options.ignore}).catch(e).then(e=>e||[])}isDirectorySync(e){return l(this.resolve(e))}isFileSync(e){return!u(this.resolve(e))}};export{g as FileSystemStorageAdapter};
1
+ import{ignoreNotfound as e}from"../helpers.mjs";import{BaseStorageAdapter as t}from"./base.mjs";import{unlinkSync as n}from"node:fs";import{createDirectory as r,createDirectorySync as i}from"@stryke/fs/helpers";import{listFiles as a,listFilesSync as o}from"@stryke/fs/list-files";import{exists as s,existsSync as c}from"@stryke/fs/exists";import{isDirectory as l,isFile as u}from"@stryke/fs/is-file";import{readFile as d,readFileSync as f}from"@stryke/fs/read-file";import{writeFile as p,writeFileSync as m}from"@stryke/fs/write-file";import{unlink as h}from"node:fs/promises";var g=class extends t{name=`file-system`;preset=`fs`;constructor(e){super(e)}existsSync(e){return c(this.resolve(e))}async exists(e){return s(this.resolve(e))}getSync(e){return f(this.resolve(e))}async get(e){return d(this.resolve(e))}setSync(e,t){if(!this.options.isReadOnly)return m(this.resolve(e),t)}async set(e,t){if(!this.options.isReadOnly)return p(this.resolve(e),t)}removeSync(t){if(!this.options.isReadOnly)try{return n(this.resolve(t))}catch(t){return e(t)}}async remove(t){if(!this.options.isReadOnly)return h(this.resolve(t)).catch(e)}mkdirSync(e){i(this.resolve(e))}async mkdir(e){await r(this.resolve(e))}listSync(t){try{return o(this.resolve(t),{ignore:this.options.ignore})}catch(t){return e(t)??[]}}async list(t){return a(this.resolve(t),{ignore:this.options.ignore}).catch(e).then(e=>e||[])}isDirectorySync(e){return l(this.resolve(e))}isFileSync(e){return!u(this.resolve(e))}};export{g as FileSystemStorageAdapter};
@@ -1 +1 @@
1
- const e=require(`../../../../../_virtual/rolldown_runtime.cjs`),t=require(`./base.cjs`);let n=require(`@stryke/path/is-parent-path`);var r=class extends t.BaseStorageAdapter{name=`virtual`;data=new Map;constructor(e){super(e)}existsSync(e){return this.data.has(this.resolve(e))}getSync(e){return this.data.get(this.resolve(e))??null}setSync(e,t){this.options.isReadOnly||this.data.set(this.resolve(e),t)}removeSync(e){this.options.isReadOnly||this.data.delete(this.resolve(e))}listSync(e){return[...this.data.keys().filter(t=>e?(0,n.isParentPath)(t,this.resolve(e)):!0)]}async dispose(){return this.clear()}};exports.VirtualStorageAdapter=r;
1
+ const e=require(`../../../../../_virtual/rolldown_runtime.cjs`),t=require(`./base.cjs`);let n=require(`@stryke/path/is-parent-path`);var r=class extends t.BaseStorageAdapter{name=`virtual`;preset=`virtual`;data=new Map;constructor(e){super(e)}existsSync(e){return this.data.has(this.resolve(e))}getSync(e){return this.data.get(this.resolve(e))??null}setSync(e,t){this.options.isReadOnly||this.data.set(this.resolve(e),t)}removeSync(e){this.options.isReadOnly||this.data.delete(this.resolve(e))}listSync(e){return[...this.data.keys().filter(t=>e?(0,n.isParentPath)(t,this.resolve(e)):!0)]}async dispose(){return this.clear()}};exports.VirtualStorageAdapter=r;
@@ -1 +1 @@
1
- import{BaseStorageAdapter as e}from"./base.mjs";import{isParentPath as t}from"@stryke/path/is-parent-path";var n=class extends e{name=`virtual`;data=new Map;constructor(e){super(e)}existsSync(e){return this.data.has(this.resolve(e))}getSync(e){return this.data.get(this.resolve(e))??null}setSync(e,t){this.options.isReadOnly||this.data.set(this.resolve(e),t)}removeSync(e){this.options.isReadOnly||this.data.delete(this.resolve(e))}listSync(e){return[...this.data.keys().filter(n=>e?t(n,this.resolve(e)):!0)]}async dispose(){return this.clear()}};export{n as VirtualStorageAdapter};
1
+ import{BaseStorageAdapter as e}from"./base.mjs";import{isParentPath as t}from"@stryke/path/is-parent-path";var n=class extends e{name=`virtual`;preset=`virtual`;data=new Map;constructor(e){super(e)}existsSync(e){return this.data.has(this.resolve(e))}getSync(e){return this.data.get(this.resolve(e))??null}setSync(e,t){this.options.isReadOnly||this.data.set(this.resolve(e),t)}removeSync(e){this.options.isReadOnly||this.data.delete(this.resolve(e))}listSync(e){return[...this.data.keys().filter(n=>e?t(n,this.resolve(e)):!0)]}async dispose(){return this.clear()}};export{n as VirtualStorageAdapter};
@@ -1 +1 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../../plugin-utils/paths.cjs`),n=require(`../../../schemas/fs.cjs`),r=require(`../logger.cjs`),i=require(`./helpers.cjs`),a=require(`./storage/file-system.cjs`),o=require(`./storage/virtual.cjs`);let s=require(`@stryke/convert/to-array`),c=require(`@stryke/path/join-paths`),l=require(`@stryke/type-checks/is-string`),u=require(`@storm-software/config-tools/types`),d=require(`@stryke/fs/resolve`),f=require(`@stryke/path/append`),p=require(`@stryke/path/replace`),m=require(`@stryke/type-checks/is-set-object`),h=require(`@stryke/type-checks/is-set-string`),g=require(`@stryke/path/file-path-fns`),_=require(`@stryke/fs/exists`),v=require(`@stryke/hash/murmurhash`),y=require(`@stryke/helpers/get-unique`),b=require(`@stryke/path/is-parent-path`),x=require(`@stryke/path/is-type`),S=require(`flat-cache`),C=require(`@stryke/capnp`);C=e.__toESM(C);let w=require(`@stryke/fs/buffer`),T=require(`@stryke/string-format/pretty-bytes`),E=require(`node:buffer`),D=require(`node:url`),O=require(`prettier`);var k=class e{#e;#t;#n;#r={"":new a.FileSystemStorageAdapter};#i;#a=!1;#o;#s;#c(e){let t=e;return(0,b.isParentPath)(t,this.#o.builtinsPath)&&(t=(0,p.replacePath)(t,this.#o.builtinsPath)),i.normalizeId(t,this.#o.config.output.builtinPrefix)}#l(e){return i.normalizePath(e.includes(`{`)||e.includes(`}`)?t.replacePathTokens(this.#o,e):e,this.#o.builtinsPath,this.#o.config.output.builtinPrefix)}#u(e){let t=`::GLOBSTAR::`;return RegExp(`^${this.#l(e).replace(/\*\*/g,t).replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/]*`).replace(/\?/g,`[^/]`).replace(new RegExp(t,`g`),`.*`)}$`)}#d(e){let t=this.resolveSync(this.#l(e))||e;for(let e of Object.keys(this.#r).filter(Boolean).sort().reverse())if((0,b.isParentPath)(t,e))return{base:e,relativeKey:(0,p.replacePath)(t,e),adapter:this.#r[e]};return{base:``,relativeKey:t,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>(0,b.isParentPath)(n,e)||t&&(0,b.isParentPath)(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(t){if(!t.config.skipCache&&(0,_.existsSync)((0,c.joinPaths)(t.dataPath,`fs.bin`))){let r=await(0,w.readFileBuffer)((0,c.joinPaths)(t.dataPath,`fs.bin`)),i=new C.Message(r,!1).getRoot(n.FileSystem),a=new e(t,i);i._hasStorage()&&i.storage.length>0&&await Promise.all(i.storage.values().map(async e=>{await a.write(e.path,e.code)}))}return new e(t,new C.Message().initRoot(n.FileSystem))}static createSync(t){if(!t.config.skipCache&&(0,_.existsSync)((0,c.joinPaths)(t.dataPath,`fs.bin`))){let r=(0,w.readFileBufferSync)((0,c.joinPaths)(t.dataPath,`fs.bin`)),i=new C.Message(r,!1).getRoot(n.FileSystem),a=new e(t,i);i._hasStorage()&&i.storage.length>0&&i.storage.values().map(e=>{a.writeSync(e.path,e.code)})}return new e(t,new C.Message().initRoot(n.FileSystem))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=(0,S.create)({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,(0,m.isSetObject)(this.#o.config.output.storage)&&(this.#r={...this.#r,...this.#o.config.output.storage}),this.#r.virtual??=new o.VirtualStorageAdapter({base:`/_virtual`}),this.#o.config.output.storage!==`fs`&&(this.#r[this.#o.artifactsPath]??=new o.VirtualStorageAdapter({base:this.#o.artifactsPath}),this.#r[this.#o.builtinsPath]??=new o.VirtualStorageAdapter({base:this.#o.builtinsPath}),this.#r[this.#o.entryPath]??=new o.VirtualStorageAdapter({base:this.#o.entryPath})),this.#e={},t._hasMetadata()&&(this.#e=t.metadata.values().reduce((e,t)=>(e[t.id]={id:t.id,type:t.type,timestamp:t.timestamp||Date.now(),properties:t._hasProperties()?t.properties.values().reduce((e,t)=>(e[t.key]=t.value,e),{}):{}},e),{}),e.config.skipCache!==!0&&Object.entries(this.#e).filter(([,e])=>e.type===`entry`).forEach(([e,t])=>{this.#o.entry??=[],this.#o.entry.push({file:e,name:t.properties.name,output:t.properties.output,input:t.properties[`input.file`]?{file:t.properties[`input.file`],name:t.properties[`input.name`]}:void 0})})),this.#t={},this.#n={},t._hasIds()&&(this.#t=t.ids.values().reduce((e,t)=>(e[t.path]??=t.id,e),{}),this.#n=t.ids.values().reduce((e,t)=>(e[t.id]??=t.path,e),{})),this.#s=r.extendLog(this.#o.log,`file-system`)}async exists(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.exists(t)}existsSync(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.existsSync(t)}isVirtual(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.name===`virtual`:!1}isDirectorySync(e){let t=this.resolveSync(e);return t?!!(this.existsSync(t)&&this.#d(t)?.adapter?.isDirectorySync(t)):!1}async isDirectory(e){let t=await this.resolve(e);return t?!!(await this.exists(t)&&await this.#d(t)?.adapter?.isDirectory(t)):!1}isFileSync(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.isFileSync(t)??!1:!1}async isFile(e){let t=await this.resolve(e);return t?await this.#d(t)?.adapter?.isFile(t)??!1:!1}listSync(e){return(0,y.getUnique)(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?(0,f.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return(0,y.getUnique)((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?(0,f.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(u.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,g.hasFileExtension)(t)?await r.remove(n):await r.clear(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}removeSync(e){let t=this.#l(e);this.#s(u.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,g.hasFileExtension)(t)?r.removeSync(n):r.clearSync(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}async glob(e){let t=[];for(let n of i.normalizeGlobPatterns(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...await this.list(e));else{let n=await this.resolve(e);n&&!t.includes(n)&&t.push(n)}continue}let r=(0,x.isAbsolutePath)(e)?e:this.#l((0,c.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,g.findFilePath)(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i)));await Promise.all((await this.list(a&&(0,x.isAbsolutePath)(a)?a:this.#o.workspaceConfig.workspaceRoot)).map(async e=>{if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}))}return t}globSync(e){let t=[];for(let n of i.normalizeGlobPatterns(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...this.listSync(e));else{let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}continue}let r=(0,x.isAbsolutePath)(e)?e:this.#l((0,c.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,g.findFilePath)(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i))),o=this.listSync(a&&(0,x.isAbsolutePath)(a)?a:this.#o.workspaceConfig.workspaceRoot);for(let e of o)if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}return t}async copy(e,t){let n=e instanceof URL?(0,D.fileURLToPath)(e):e,r=t instanceof URL?(0,D.fileURLToPath)(t):t;if(!(0,h.isSetString)(n)&&(!(0,m.isSetObject)(n)||!(0,h.isSetString)(n.input))||!(0,h.isSetString)(r))return;let i=(0,l.isString)(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=await this.resolve(i);if(a)if(this.isDirectorySync(a)||(0,h.isSetString)(n)&&n.includes(`*`)||(0,m.isSetObject)(n)&&(0,h.isSetString)(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,(0,f.appendPath)((0,p.replacePath)(e,i),r))));else{let e=await this.read(a);e!==void 0&&await this.write(this.#l(r),e,{skipFormat:!0})}}copySync(e,t){let n=e instanceof URL?(0,D.fileURLToPath)(e):e,r=t instanceof URL?(0,D.fileURLToPath)(t):t;if(!(0,h.isSetString)(n)&&(!(0,m.isSetObject)(n)||!(0,h.isSetString)(n.input))||!(0,h.isSetString)(r))return;let i=(0,l.isString)(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=this.resolveSync(i);if(a)if(this.isDirectorySync(a)||(0,h.isSetString)(n)&&n.includes(`*`)||(0,m.isSetObject)(n)&&(0,h.isSetString)(n.glob))this.globSync(n).map(e=>this.copySync(e,(0,f.appendPath)((0,g.findFilePath)((0,p.replacePath)(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l((0,g.hasFileExtension)(r)?r:(0,f.appendPath)((0,g.findFileName)(a),r)),e,{skipFormat:!0})}}async move(e,t){(0,g.hasFileExtension)(e)?(await this.copy(e,t),await this.remove(e)):await Promise.all((await this.list(e)).map(async e=>{await this.copy(e,t),await this.remove(e)}))}moveSync(e,t){(0,g.hasFileExtension)(e)?(this.copySync(e,t),this.removeSync(e)):this.listSync(e).forEach(e=>{this.copySync(e,t),this.removeSync(e)})}async read(e){let t=await this.resolve(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(u.LogLevelLabel.TRACE,`Reading ${r.name} file: ${t}`),await r.get(n)??void 0}readSync(e){let t=this.resolveSync(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(u.LogLevelLabel.TRACE,`Reading ${r.name} file: ${t}`),r.getSync(n)??void 0}async write(e,t=``,n={}){let r=t;if(!n.skipFormat){let n=await(0,O.resolveConfig)(this.#l(e));n&&(r=await(0,O.format)(t,{absolutePath:this.#l(e),...n}))}let{relativeKey:i,adapter:a}=this.#d(e);this.#s(u.LogLevelLabel.TRACE,`Writing ${this.#l(i)} to ${a.name===`virtual`?`the virtual file system`:a.name===`file-system`?`the local file system`:a.name} (size: ${(0,T.prettyBytes)(new E.Blob((0,s.toArray)(r)).size)})`);let o=n?.meta?.id||this.#c(i);return this.#e[o]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[o]=this.#l(i),this.#t[this.#l(i)]=o,a.set(i,r)}writeSync(e,t=``,n={}){let{relativeKey:r,adapter:i}=this.#d(e);this.#s(u.LogLevelLabel.TRACE,`Writing ${this.#l(r)} file to ${i.name===`virtual`?`the virtual file system`:i.name===`file-system`?`the local file system`:i.name} (size: ${(0,T.prettyBytes)(new E.Blob((0,s.toArray)(t)).size)})`);let a=n?.meta?.id||this.#c(r);return this.#e[a]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[a]=this.#l(r),this.#t[this.#l(r)]=a,i.setSync(r,t)}mkdirSync(e){return this.#d(e)?.adapter?.mkdirSync(e)}async mkdir(e){return this.#d(e)?.adapter?.mkdir(e)}getMetadata(e){let t=this.resolveSync(e);if(t&&this.metadata[t])return this.metadata[t]}async resolve(e,n,r={}){let i=e;if((i.includes(`{`)||i.includes(`}`))&&(i=t.replacePathTokens(this.#o,i)),(0,x.isAbsolutePath)(i))return i;let a=(0,v.murmurhash)({path:this.#c(i),importer:n,options:r}),o;if(!this.#o.config.skipCache&&(o=this.resolverCache.get(a),o))return o;if(o=this.paths[this.#c(i)],!o){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push((0,f.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,f.appendPath)(this.#o.config.sourceRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(...Object.keys(this.#o.tsconfig?.options?.paths??{}).filter(e=>i.startsWith(e.replace(/\*$/,``))).map(e=>this.#o.tsconfig?.options?.paths?.[e]).flat().filter(Boolean).map(e=>(0,f.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,d.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await(0,d.resolve)(i,{...r,paths:e})}catch{}}return o&&!this.#o.config.skipCache&&this.resolverCache.set(a,o),o}resolveSync(e,n,r={}){let i=e;if((i.includes(`{`)||i.includes(`}`))&&(i=t.replacePathTokens(this.#o,i)),(0,x.isAbsolutePath)(i))return i;let a;if(!this.#o.config.skipCache&&(a=this.resolverCache.get(this.#c(i)),a))return a;if(a=this.paths[this.#c(i)],!a){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push((0,f.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,f.appendPath)(this.#o.config.sourceRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(...Object.keys(this.#o.tsconfig?.options?.paths??{}).filter(e=>i.startsWith(e.replace(/\*$/,``))).map(e=>this.#o.tsconfig?.options?.paths?.[e]).flat().filter(Boolean).map(e=>(0,f.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,d.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=(0,d.resolveSync)(i,{...r,paths:e})}catch{}}return a&&!this.#o.config.skipCache&&this.resolverCache.set(this.#c(i),a),a}async dispose(){if(!this.#a){this.#a=!0,this.#s(u.LogLevelLabel.DEBUG,`Disposing virtual file system...`),await this.remove((0,c.joinPaths)(this.#o.dataPath,`fs.bin`));let e=new C.Message,t=e.initRoot(n.FileSystem),r=await this.list(),i=t._initStorage(r.length);await Promise.all(r.map(async(e,t)=>{let n=await this.read(e),r=i.get(t);r.path=e,r.code=n||``}));let a=t._initIds(Object.keys(this.ids).length);Object.entries(this.ids).filter(([,e])=>e).forEach(([e,t],n)=>{let r=a.get(n);r.id=e,r.path=t});let o=t._initMetadata(Object.keys(this.metadata).length);Object.entries(this.metadata).filter(([,e])=>e).forEach(([e,t],n)=>{let r=o.get(n);if(r.id=e,r.type=t.type,r.timestamp=t.timestamp??BigInt(Date.now()),t.properties){let e=r._initProperties(Object.keys(t.properties).length);Object.entries(t.properties).filter(([,e])=>(0,h.isSetString)(e)).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await(0,w.writeFileBuffer)((0,c.joinPaths)(this.#o.dataPath,`fs.bin`),e.toArrayBuffer()),this.#o.config.skipCache||this.#i.save(!0),await Promise.all(this.#f().map(async e=>e.adapter.dispose())),this.#s(u.LogLevelLabel.TRACE,`Virtual file system has been disposed.`)}}async[Symbol.asyncDispose](){return this.dispose()}};exports.VirtualFileSystem=k;
1
+ const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../../plugin-utils/paths.cjs`),n=require(`../../../schemas/fs.cjs`),r=require(`../logger.cjs`),i=require(`./helpers.cjs`),a=require(`./storage/file-system.cjs`),o=require(`./storage/virtual.cjs`);let s=require(`@stryke/convert/to-array`),c=require(`@stryke/path/join-paths`),l=require(`@stryke/type-checks/is-string`),u=require(`@storm-software/config-tools/types`),d=require(`@stryke/fs/resolve`),f=require(`@stryke/path/append`),p=require(`@stryke/path/replace`),m=require(`@stryke/type-checks/is-set-object`),h=require(`@stryke/type-checks/is-set-string`),g=require(`@stryke/path/file-path-fns`),_=require(`@stryke/fs/exists`),v=require(`@stryke/hash/murmurhash`),y=require(`@stryke/helpers/get-unique`),b=require(`@stryke/path/is-parent-path`),x=require(`@stryke/path/is-type`),S=require(`flat-cache`),C=require(`@stryke/capnp`);C=e.__toESM(C);let w=require(`@stryke/fs/buffer`),T=require(`@stryke/string-format/pretty-bytes`),E=require(`@stryke/type-checks/is-regexp`),D=require(`node:buffer`),O=require(`node:url`),k=require(`prettier`);var A=class e{#e;#t;#n;#r={"":new a.FileSystemStorageAdapter};#i;#a=!1;#o;#s;#c(e){let t=e;return(0,b.isParentPath)(t,this.#o.builtinsPath)&&(t=(0,p.replacePath)(t,this.#o.builtinsPath)),i.normalizeId(t,this.#o.config.output.builtinPrefix)}#l(e){return i.normalizePath(e.includes(`{`)||e.includes(`}`)?t.replacePathTokens(this.#o,e):e,this.#o.builtinsPath,this.#o.config.output.builtinPrefix)}#u(e){let t=`::GLOBSTAR::`;return RegExp(`^${this.#l(e).replace(/\*\*/g,t).replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/]*`).replace(/\?/g,`[^/]`).replace(new RegExp(t,`g`),`.*`)}$`)}#d(e){let t=Object.entries(this.#r).find(([,t])=>t.name===e||t.preset&&t.preset.toLowerCase()===e?.toLowerCase());if(t)return{base:t[0],relativeKey:``,adapter:t[1]};let n=this.resolveSync(this.#l(e))||e;for(let e of Object.keys(this.#r).filter(Boolean).sort().reverse())if((0,b.isParentPath)(n,e))return{base:e,relativeKey:(0,p.replacePath)(n,e),adapter:this.#r[e]};return{base:``,relativeKey:n,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>(0,b.isParentPath)(n,e)||t&&(0,b.isParentPath)(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(t){if(!t.config.skipCache&&(0,_.existsSync)((0,c.joinPaths)(t.dataPath,`fs.bin`))){let r=await(0,w.readFileBuffer)((0,c.joinPaths)(t.dataPath,`fs.bin`)),i=new C.Message(r,!1).getRoot(n.FileSystem),a=new e(t,i);i._hasStorage()&&i.storage.length>0&&await Promise.all(i.storage.values().map(async e=>{await a.write(e.path,e.code)}))}return new e(t,new C.Message().initRoot(n.FileSystem))}static createSync(t){if(!t.config.skipCache&&(0,_.existsSync)((0,c.joinPaths)(t.dataPath,`fs.bin`))){let r=(0,w.readFileBufferSync)((0,c.joinPaths)(t.dataPath,`fs.bin`)),i=new C.Message(r,!1).getRoot(n.FileSystem),a=new e(t,i);i._hasStorage()&&i.storage.length>0&&i.storage.values().map(e=>{a.writeSync(e.path,e.code)})}return new e(t,new C.Message().initRoot(n.FileSystem))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=(0,S.create)({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,(0,m.isSetObject)(this.#o.config.output.storage)&&(this.#r={...this.#r,...this.#o.config.output.storage}),this.#r.virtual??=new o.VirtualStorageAdapter({base:`/_virtual`}),this.#o.config.output.storage!==`fs`&&(this.#r[this.#o.artifactsPath]??=new o.VirtualStorageAdapter({base:this.#o.artifactsPath}),this.#r[this.#o.builtinsPath]??=new o.VirtualStorageAdapter({base:this.#o.builtinsPath}),this.#r[this.#o.entryPath]??=new o.VirtualStorageAdapter({base:this.#o.entryPath})),this.#e={},t._hasMetadata()&&(this.#e=t.metadata.values().reduce((e,t)=>(e[t.id]={id:t.id,type:t.type,timestamp:t.timestamp||Date.now(),properties:t._hasProperties()?t.properties.values().reduce((e,t)=>(e[t.key]=t.value,e),{}):{}},e),{}),e.config.skipCache!==!0&&Object.entries(this.#e).filter(([,e])=>e.type===`entry`).forEach(([e,t])=>{this.#o.entry??=[],this.#o.entry.push({file:e,name:t.properties.name,output:t.properties.output,input:t.properties[`input.file`]?{file:t.properties[`input.file`],name:t.properties[`input.name`]}:void 0})})),this.#t={},this.#n={},t._hasIds()&&(this.#t=t.ids.values().reduce((e,t)=>(e[t.path]??=t.id,e),{}),this.#n=t.ids.values().reduce((e,t)=>(e[t.id]??=t.path,e),{})),this.#s=r.extendLog(this.#o.log,`file-system`)}async exists(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.exists(t)}existsSync(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.existsSync(t)}isVirtual(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.name===`virtual`:!1}isDirectorySync(e){let t=this.resolveSync(e);return t?!!(this.existsSync(t)&&this.#d(t)?.adapter?.isDirectorySync(t)):!1}async isDirectory(e){let t=await this.resolve(e);return t?!!(await this.exists(t)&&await this.#d(t)?.adapter?.isDirectory(t)):!1}isFileSync(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.isFileSync(t)??!1:!1}async isFile(e){let t=await this.resolve(e);return t?await this.#d(t)?.adapter?.isFile(t)??!1:!1}listSync(e){return(0,y.getUnique)(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?(0,f.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return(0,y.getUnique)((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?(0,f.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(u.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,g.hasFileExtension)(t)?await r.remove(n):await r.clear(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}removeSync(e){let t=this.#l(e);this.#s(u.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,g.hasFileExtension)(t)?r.removeSync(n):r.clearSync(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}async glob(e){let t=[];for(let n of i.normalizeGlobPatterns(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...await this.list(e));else{let n=await this.resolve(e);n&&!t.includes(n)&&t.push(n)}continue}let r=(0,x.isAbsolutePath)(e)?e:this.#l((0,c.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,g.findFilePath)(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i)));await Promise.all((await this.list(a&&(0,x.isAbsolutePath)(a)?a:this.#o.workspaceConfig.workspaceRoot)).map(async e=>{if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}))}return t}globSync(e){let t=[];for(let n of i.normalizeGlobPatterns(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...this.listSync(e));else{let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}continue}let r=(0,x.isAbsolutePath)(e)?e:this.#l((0,c.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,g.findFilePath)(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i))),o=this.listSync(a&&(0,x.isAbsolutePath)(a)?a:this.#o.workspaceConfig.workspaceRoot);for(let e of o)if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}return t}async copy(e,t){let n=e instanceof URL?(0,O.fileURLToPath)(e):e,r=t instanceof URL?(0,O.fileURLToPath)(t):t;if(!(0,h.isSetString)(n)&&(!(0,m.isSetObject)(n)||!(0,h.isSetString)(n.input))||!(0,h.isSetString)(r))return;let i=(0,l.isString)(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=await this.resolve(i);if(a)if(this.isDirectorySync(a)||(0,h.isSetString)(n)&&n.includes(`*`)||(0,m.isSetObject)(n)&&(0,h.isSetString)(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,(0,f.appendPath)((0,p.replacePath)(e,i),r))));else{let e=await this.read(a);e!==void 0&&await this.write(this.#l(r),e,{skipFormat:!0})}}copySync(e,t){let n=e instanceof URL?(0,O.fileURLToPath)(e):e,r=t instanceof URL?(0,O.fileURLToPath)(t):t;if(!(0,h.isSetString)(n)&&(!(0,m.isSetObject)(n)||!(0,h.isSetString)(n.input))||!(0,h.isSetString)(r))return;let i=(0,l.isString)(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=this.resolveSync(i);if(a)if(this.isDirectorySync(a)||(0,h.isSetString)(n)&&n.includes(`*`)||(0,m.isSetObject)(n)&&(0,h.isSetString)(n.glob))this.globSync(n).map(e=>this.copySync(e,(0,f.appendPath)((0,g.findFilePath)((0,p.replacePath)(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l((0,g.hasFileExtension)(r)?r:(0,f.appendPath)((0,g.findFileName)(a),r)),e,{skipFormat:!0})}}async move(e,t){(0,g.hasFileExtension)(e)?(await this.copy(e,t),await this.remove(e)):await Promise.all((await this.list(e)).map(async e=>{await this.copy(e,t),await this.remove(e)}))}moveSync(e,t){(0,g.hasFileExtension)(e)?(this.copySync(e,t),this.removeSync(e)):this.listSync(e).forEach(e=>{this.copySync(e,t),this.removeSync(e)})}async read(e){let t=await this.resolve(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(u.LogLevelLabel.TRACE,`Reading ${r.name} file: ${t}`),await r.get(n)??void 0}readSync(e){let t=this.resolveSync(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(u.LogLevelLabel.TRACE,`Reading ${r.name} file: ${t}`),r.getSync(n)??void 0}async write(e,t=``,n={}){let r=t;if(!n.skipFormat){let n=await(0,k.resolveConfig)(this.#l(e));n&&(r=await(0,k.format)(t,{absolutePath:this.#l(e),...n}))}let{relativeKey:i,adapter:a}=this.#d(n.storage||e);this.#s(u.LogLevelLabel.TRACE,`Writing ${this.#l(i)} to ${a.name===`virtual`?`the virtual file system`:a.name===`file-system`?`the local file system`:a.name} (size: ${(0,T.prettyBytes)(new D.Blob((0,s.toArray)(r)).size)})`);let o=n?.meta?.id||this.#c(i);return this.#e[o]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[o]=this.#l(i),this.#t[this.#l(i)]=o,a.set(i,r)}writeSync(e,t=``,n={}){let{relativeKey:r,adapter:i}=this.#d(n.storage||e);this.#s(u.LogLevelLabel.TRACE,`Writing ${this.#l(r)} file to ${i.name===`virtual`?`the virtual file system`:i.name===`file-system`?`the local file system`:i.name} (size: ${(0,T.prettyBytes)(new D.Blob((0,s.toArray)(t)).size)})`);let a=n?.meta?.id||this.#c(r);return this.#e[a]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[a]=this.#l(r),this.#t[this.#l(r)]=a,i.setSync(r,t)}mkdirSync(e){return this.#d(e)?.adapter?.mkdirSync(e)}async mkdir(e){return this.#d(e)?.adapter?.mkdir(e)}getMetadata(e){let t=this.resolveSync(e);if(t&&this.metadata[t])return this.metadata[t]}resolveAlias(e){let t=e;if(this.#o.config.build.alias){if(Array.isArray(this.#o.config.build.alias)&&this.#o.config.build.alias.length>0){let e=this.#o.config.build.alias.filter(e=>(0,h.isSetString)(e.find)&&(e.find===t||t.startsWith(`${e.find}/`))||(0,E.isRegExp)(e.find)&&e.find.test(t));if(e.length>0){let n=e.reduce((e,t)=>((0,h.isSetString)(e.find)?e.find.length:(0,E.isRegExp)(e.find)?e.find.source.length:0)>((0,h.isSetString)(t.find)?t.find.length:(0,E.isRegExp)(t.find)?t.find.source.length:0)?e:t);(0,h.isSetString)(n.find)?t=t.replace(RegExp(`^${n.find}`),n.replacement):(0,E.isRegExp)(n.find)&&(t=t.replace(n.find,n.replacement))}}else if((0,m.isSetObject)(this.#o.config.build.alias)){let e=Object.keys(this.#o.config.build.alias).filter(e=>e===t||t.startsWith(`${e}/`));if(e.length>0){let n=e.reduce((e,t)=>e.length>t.length?e:t);t=t.replace(RegExp(`^${n}`),this.#o.config.build.alias[n])}}}return t}async resolve(e,n,r={}){let i=e;if((i.includes(`{`)||i.includes(`}`))&&(i=t.replacePathTokens(this.#o,i)),r.skipAlias!==!0&&(i=this.resolveAlias(i)),(0,x.isAbsolutePath)(i))return i;let a=(0,v.murmurhash)({path:this.#c(i),importer:n,options:r}),o;if(!this.#o.config.skipCache&&(o=this.resolverCache.get(a),o))return o;if(o=this.paths[this.#c(i)],!o){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push((0,f.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,f.appendPath)(this.#o.config.sourceRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(...Object.keys(this.#o.tsconfig?.options?.paths??{}).filter(e=>i.startsWith(e.replace(/\*$/,``))).map(e=>this.#o.tsconfig?.options?.paths?.[e]).flat().filter(Boolean).map(e=>(0,f.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,d.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await(0,d.resolve)(i,{...r,paths:e})}catch{}}return o&&!this.#o.config.skipCache&&this.resolverCache.set(a,o),o}resolveSync(e,n,r={}){let i=e;if((i.includes(`{`)||i.includes(`}`))&&(i=t.replacePathTokens(this.#o,i)),r.skipAlias!==!0&&(i=this.resolveAlias(i)),(0,x.isAbsolutePath)(i))return i;let a;if(!this.#o.config.skipCache&&(a=this.resolverCache.get(this.#c(i)),a))return a;if(a=this.paths[this.#c(i)],!a){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push((0,f.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,f.appendPath)(this.#o.config.sourceRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(...Object.keys(this.#o.tsconfig?.options?.paths??{}).filter(e=>i.startsWith(e.replace(/\*$/,``))).map(e=>this.#o.tsconfig?.options?.paths?.[e]).flat().filter(Boolean).map(e=>(0,f.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,d.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=(0,d.resolveSync)(i,{...r,paths:e})}catch{}}return a&&!this.#o.config.skipCache&&this.resolverCache.set(this.#c(i),a),a}async dispose(){if(!this.#a){this.#a=!0,this.#s(u.LogLevelLabel.DEBUG,`Disposing virtual file system...`),await this.remove((0,c.joinPaths)(this.#o.dataPath,`fs.bin`));let e=new C.Message,t=e.initRoot(n.FileSystem),r=await this.list(),i=t._initStorage(r.length);await Promise.all(r.map(async(e,t)=>{let n=await this.read(e),r=i.get(t);r.path=e,r.code=n||``}));let a=t._initIds(Object.keys(this.ids).length);Object.entries(this.ids).filter(([,e])=>e).forEach(([e,t],n)=>{let r=a.get(n);r.id=e,r.path=t});let o=t._initMetadata(Object.keys(this.metadata).length);Object.entries(this.metadata).filter(([,e])=>e).forEach(([e,t],n)=>{let r=o.get(n);if(r.id=e,r.type=t.type,r.timestamp=t.timestamp??BigInt(Date.now()),t.properties){let e=r._initProperties(Object.keys(t.properties).length);Object.entries(t.properties).filter(([,e])=>(0,h.isSetString)(e)).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await(0,w.writeFileBuffer)((0,c.joinPaths)(this.#o.dataPath,`fs.bin`),e.toArrayBuffer()),this.#o.config.skipCache||this.#i.save(!0),await Promise.all(this.#f().map(async e=>e.adapter.dispose())),this.#s(u.LogLevelLabel.TRACE,`Virtual file system has been disposed.`)}}async[Symbol.asyncDispose](){return this.dispose()}};exports.VirtualFileSystem=A;
@@ -1 +1 @@
1
- import{replacePathTokens as e}from"../../plugin-utils/paths.mjs";import{FileSystem as t}from"../../../schemas/fs.mjs";import{extendLog as n}from"../logger.mjs";import{normalizeGlobPatterns as r,normalizeId as i,normalizePath as a}from"./helpers.mjs";import{FileSystemStorageAdapter as o}from"./storage/file-system.mjs";import{VirtualStorageAdapter as s}from"./storage/virtual.mjs";import{toArray as c}from"@stryke/convert/to-array";import{joinPaths as l}from"@stryke/path/join-paths";import{isString as u}from"@stryke/type-checks/is-string";import{LogLevelLabel as d}from"@storm-software/config-tools/types";import{getResolutionCombinations as f,resolve as p,resolveSync as m}from"@stryke/fs/resolve";import{appendPath as h}from"@stryke/path/append";import{replacePath as g}from"@stryke/path/replace";import{isSetObject as _}from"@stryke/type-checks/is-set-object";import{isSetString as v}from"@stryke/type-checks/is-set-string";import{findFileName as y,findFilePath as b,hasFileExtension as x}from"@stryke/path/file-path-fns";import{existsSync as S}from"@stryke/fs/exists";import{murmurhash as C}from"@stryke/hash/murmurhash";import{getUnique as w}from"@stryke/helpers/get-unique";import{isParentPath as T}from"@stryke/path/is-parent-path";import{isAbsolutePath as E}from"@stryke/path/is-type";import{create as D}from"flat-cache";import*as O from"@stryke/capnp";import{readFileBuffer as k,readFileBufferSync as A,writeFileBuffer as j}from"@stryke/fs/buffer";import{prettyBytes as M}from"@stryke/string-format/pretty-bytes";import{Blob as N}from"node:buffer";import{fileURLToPath as P}from"node:url";import{format as F,resolveConfig as I}from"prettier";var L=class L{#e;#t;#n;#r={"":new o};#i;#a=!1;#o;#s;#c(e){let t=e;return T(t,this.#o.builtinsPath)&&(t=g(t,this.#o.builtinsPath)),i(t,this.#o.config.output.builtinPrefix)}#l(t){return a(t.includes(`{`)||t.includes(`}`)?e(this.#o,t):t,this.#o.builtinsPath,this.#o.config.output.builtinPrefix)}#u(e){let t=`::GLOBSTAR::`;return RegExp(`^${this.#l(e).replace(/\*\*/g,t).replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/]*`).replace(/\?/g,`[^/]`).replace(new RegExp(t,`g`),`.*`)}$`)}#d(e){let t=this.resolveSync(this.#l(e))||e;for(let e of Object.keys(this.#r).filter(Boolean).sort().reverse())if(T(t,e))return{base:e,relativeKey:g(t,e),adapter:this.#r[e]};return{base:``,relativeKey:t,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>T(n,e)||t&&T(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(e){if(!e.config.skipCache&&S(l(e.dataPath,`fs.bin`))){let n=await k(l(e.dataPath,`fs.bin`)),r=new O.Message(n,!1).getRoot(t),i=new L(e,r);r._hasStorage()&&r.storage.length>0&&await Promise.all(r.storage.values().map(async e=>{await i.write(e.path,e.code)}))}return new L(e,new O.Message().initRoot(t))}static createSync(e){if(!e.config.skipCache&&S(l(e.dataPath,`fs.bin`))){let n=A(l(e.dataPath,`fs.bin`)),r=new O.Message(n,!1).getRoot(t),i=new L(e,r);r._hasStorage()&&r.storage.length>0&&r.storage.values().map(e=>{i.writeSync(e.path,e.code)})}return new L(e,new O.Message().initRoot(t))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=D({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,_(this.#o.config.output.storage)&&(this.#r={...this.#r,...this.#o.config.output.storage}),this.#r.virtual??=new s({base:`/_virtual`}),this.#o.config.output.storage!==`fs`&&(this.#r[this.#o.artifactsPath]??=new s({base:this.#o.artifactsPath}),this.#r[this.#o.builtinsPath]??=new s({base:this.#o.builtinsPath}),this.#r[this.#o.entryPath]??=new s({base:this.#o.entryPath})),this.#e={},t._hasMetadata()&&(this.#e=t.metadata.values().reduce((e,t)=>(e[t.id]={id:t.id,type:t.type,timestamp:t.timestamp||Date.now(),properties:t._hasProperties()?t.properties.values().reduce((e,t)=>(e[t.key]=t.value,e),{}):{}},e),{}),e.config.skipCache!==!0&&Object.entries(this.#e).filter(([,e])=>e.type===`entry`).forEach(([e,t])=>{this.#o.entry??=[],this.#o.entry.push({file:e,name:t.properties.name,output:t.properties.output,input:t.properties[`input.file`]?{file:t.properties[`input.file`],name:t.properties[`input.name`]}:void 0})})),this.#t={},this.#n={},t._hasIds()&&(this.#t=t.ids.values().reduce((e,t)=>(e[t.path]??=t.id,e),{}),this.#n=t.ids.values().reduce((e,t)=>(e[t.id]??=t.path,e),{})),this.#s=n(this.#o.log,`file-system`)}async exists(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.exists(t)}existsSync(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.existsSync(t)}isVirtual(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.name===`virtual`:!1}isDirectorySync(e){let t=this.resolveSync(e);return t?!!(this.existsSync(t)&&this.#d(t)?.adapter?.isDirectorySync(t)):!1}async isDirectory(e){let t=await this.resolve(e);return t?!!(await this.exists(t)&&await this.#d(t)?.adapter?.isDirectory(t)):!1}isFileSync(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.isFileSync(t)??!1:!1}async isFile(e){let t=await this.resolve(e);return t?await this.#d(t)?.adapter?.isFile(t)??!1:!1}listSync(e){return w(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?h(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return w((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?h(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(d.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);x(t)?await r.remove(n):await r.clear(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}removeSync(e){let t=this.#l(e);this.#s(d.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);x(t)?r.removeSync(n):r.clearSync(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}async glob(e){let t=[];for(let n of r(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...await this.list(e));else{let n=await this.resolve(e);n&&!t.includes(n)&&t.push(n)}continue}let r=E(e)?e:this.#l(l(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?b(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i)));await Promise.all((await this.list(a&&E(a)?a:this.#o.workspaceConfig.workspaceRoot)).map(async e=>{if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}))}return t}globSync(e){let t=[];for(let n of r(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...this.listSync(e));else{let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}continue}let r=E(e)?e:this.#l(l(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?b(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i))),o=this.listSync(a&&E(a)?a:this.#o.workspaceConfig.workspaceRoot);for(let e of o)if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}return t}async copy(e,t){let n=e instanceof URL?P(e):e,r=t instanceof URL?P(t):t;if(!v(n)&&(!_(n)||!v(n.input))||!v(r))return;let i=u(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=await this.resolve(i);if(a)if(this.isDirectorySync(a)||v(n)&&n.includes(`*`)||_(n)&&v(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,h(g(e,i),r))));else{let e=await this.read(a);e!==void 0&&await this.write(this.#l(r),e,{skipFormat:!0})}}copySync(e,t){let n=e instanceof URL?P(e):e,r=t instanceof URL?P(t):t;if(!v(n)&&(!_(n)||!v(n.input))||!v(r))return;let i=u(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=this.resolveSync(i);if(a)if(this.isDirectorySync(a)||v(n)&&n.includes(`*`)||_(n)&&v(n.glob))this.globSync(n).map(e=>this.copySync(e,h(b(g(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l(x(r)?r:h(y(a),r)),e,{skipFormat:!0})}}async move(e,t){x(e)?(await this.copy(e,t),await this.remove(e)):await Promise.all((await this.list(e)).map(async e=>{await this.copy(e,t),await this.remove(e)}))}moveSync(e,t){x(e)?(this.copySync(e,t),this.removeSync(e)):this.listSync(e).forEach(e=>{this.copySync(e,t),this.removeSync(e)})}async read(e){let t=await this.resolve(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(d.TRACE,`Reading ${r.name} file: ${t}`),await r.get(n)??void 0}readSync(e){let t=this.resolveSync(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(d.TRACE,`Reading ${r.name} file: ${t}`),r.getSync(n)??void 0}async write(e,t=``,n={}){let r=t;if(!n.skipFormat){let n=await I(this.#l(e));n&&(r=await F(t,{absolutePath:this.#l(e),...n}))}let{relativeKey:i,adapter:a}=this.#d(e);this.#s(d.TRACE,`Writing ${this.#l(i)} to ${a.name===`virtual`?`the virtual file system`:a.name===`file-system`?`the local file system`:a.name} (size: ${M(new N(c(r)).size)})`);let o=n?.meta?.id||this.#c(i);return this.#e[o]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[o]=this.#l(i),this.#t[this.#l(i)]=o,a.set(i,r)}writeSync(e,t=``,n={}){let{relativeKey:r,adapter:i}=this.#d(e);this.#s(d.TRACE,`Writing ${this.#l(r)} file to ${i.name===`virtual`?`the virtual file system`:i.name===`file-system`?`the local file system`:i.name} (size: ${M(new N(c(t)).size)})`);let a=n?.meta?.id||this.#c(r);return this.#e[a]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[a]=this.#l(r),this.#t[this.#l(r)]=a,i.setSync(r,t)}mkdirSync(e){return this.#d(e)?.adapter?.mkdirSync(e)}async mkdir(e){return this.#d(e)?.adapter?.mkdir(e)}getMetadata(e){let t=this.resolveSync(e);if(t&&this.metadata[t])return this.metadata[t]}async resolve(t,n,r={}){let i=t;if((i.includes(`{`)||i.includes(`}`))&&(i=e(this.#o,i)),E(i))return i;let a=C({path:this.#c(i),importer:n,options:r}),o;if(!this.#o.config.skipCache&&(o=this.resolverCache.get(a),o))return o;if(o=this.paths[this.#c(i)],!o){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push(h(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(h(this.#o.config.sourceRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(...Object.keys(this.#o.tsconfig?.options?.paths??{}).filter(e=>i.startsWith(e.replace(/\*$/,``))).map(e=>this.#o.tsconfig?.options?.paths?.[e]).flat().filter(Boolean).map(e=>h(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of f(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await p(i,{...r,paths:e})}catch{}}return o&&!this.#o.config.skipCache&&this.resolverCache.set(a,o),o}resolveSync(t,n,r={}){let i=t;if((i.includes(`{`)||i.includes(`}`))&&(i=e(this.#o,i)),E(i))return i;let a;if(!this.#o.config.skipCache&&(a=this.resolverCache.get(this.#c(i)),a))return a;if(a=this.paths[this.#c(i)],!a){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push(h(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(h(this.#o.config.sourceRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(...Object.keys(this.#o.tsconfig?.options?.paths??{}).filter(e=>i.startsWith(e.replace(/\*$/,``))).map(e=>this.#o.tsconfig?.options?.paths?.[e]).flat().filter(Boolean).map(e=>h(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of f(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=m(i,{...r,paths:e})}catch{}}return a&&!this.#o.config.skipCache&&this.resolverCache.set(this.#c(i),a),a}async dispose(){if(!this.#a){this.#a=!0,this.#s(d.DEBUG,`Disposing virtual file system...`),await this.remove(l(this.#o.dataPath,`fs.bin`));let e=new O.Message,n=e.initRoot(t),r=await this.list(),i=n._initStorage(r.length);await Promise.all(r.map(async(e,t)=>{let n=await this.read(e),r=i.get(t);r.path=e,r.code=n||``}));let a=n._initIds(Object.keys(this.ids).length);Object.entries(this.ids).filter(([,e])=>e).forEach(([e,t],n)=>{let r=a.get(n);r.id=e,r.path=t});let o=n._initMetadata(Object.keys(this.metadata).length);Object.entries(this.metadata).filter(([,e])=>e).forEach(([e,t],n)=>{let r=o.get(n);if(r.id=e,r.type=t.type,r.timestamp=t.timestamp??BigInt(Date.now()),t.properties){let e=r._initProperties(Object.keys(t.properties).length);Object.entries(t.properties).filter(([,e])=>v(e)).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await j(l(this.#o.dataPath,`fs.bin`),e.toArrayBuffer()),this.#o.config.skipCache||this.#i.save(!0),await Promise.all(this.#f().map(async e=>e.adapter.dispose())),this.#s(d.TRACE,`Virtual file system has been disposed.`)}}async[Symbol.asyncDispose](){return this.dispose()}};export{L as VirtualFileSystem};
1
+ import{replacePathTokens as e}from"../../plugin-utils/paths.mjs";import{FileSystem as t}from"../../../schemas/fs.mjs";import{extendLog as n}from"../logger.mjs";import{normalizeGlobPatterns as r,normalizeId as i,normalizePath as a}from"./helpers.mjs";import{FileSystemStorageAdapter as o}from"./storage/file-system.mjs";import{VirtualStorageAdapter as s}from"./storage/virtual.mjs";import{toArray as c}from"@stryke/convert/to-array";import{joinPaths as l}from"@stryke/path/join-paths";import{isString as u}from"@stryke/type-checks/is-string";import{LogLevelLabel as d}from"@storm-software/config-tools/types";import{getResolutionCombinations as f,resolve as p,resolveSync as m}from"@stryke/fs/resolve";import{appendPath as h}from"@stryke/path/append";import{replacePath as g}from"@stryke/path/replace";import{isSetObject as _}from"@stryke/type-checks/is-set-object";import{isSetString as v}from"@stryke/type-checks/is-set-string";import{findFileName as y,findFilePath as b,hasFileExtension as x}from"@stryke/path/file-path-fns";import{existsSync as S}from"@stryke/fs/exists";import{murmurhash as C}from"@stryke/hash/murmurhash";import{getUnique as w}from"@stryke/helpers/get-unique";import{isParentPath as T}from"@stryke/path/is-parent-path";import{isAbsolutePath as E}from"@stryke/path/is-type";import{create as D}from"flat-cache";import*as O from"@stryke/capnp";import{readFileBuffer as k,readFileBufferSync as A,writeFileBuffer as j}from"@stryke/fs/buffer";import{prettyBytes as M}from"@stryke/string-format/pretty-bytes";import{isRegExp as N}from"@stryke/type-checks/is-regexp";import{Blob as P}from"node:buffer";import{fileURLToPath as F}from"node:url";import{format as I,resolveConfig as L}from"prettier";var R=class R{#e;#t;#n;#r={"":new o};#i;#a=!1;#o;#s;#c(e){let t=e;return T(t,this.#o.builtinsPath)&&(t=g(t,this.#o.builtinsPath)),i(t,this.#o.config.output.builtinPrefix)}#l(t){return a(t.includes(`{`)||t.includes(`}`)?e(this.#o,t):t,this.#o.builtinsPath,this.#o.config.output.builtinPrefix)}#u(e){let t=`::GLOBSTAR::`;return RegExp(`^${this.#l(e).replace(/\*\*/g,t).replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/]*`).replace(/\?/g,`[^/]`).replace(new RegExp(t,`g`),`.*`)}$`)}#d(e){let t=Object.entries(this.#r).find(([,t])=>t.name===e||t.preset&&t.preset.toLowerCase()===e?.toLowerCase());if(t)return{base:t[0],relativeKey:``,adapter:t[1]};let n=this.resolveSync(this.#l(e))||e;for(let e of Object.keys(this.#r).filter(Boolean).sort().reverse())if(T(n,e))return{base:e,relativeKey:g(n,e),adapter:this.#r[e]};return{base:``,relativeKey:n,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>T(n,e)||t&&T(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(e){if(!e.config.skipCache&&S(l(e.dataPath,`fs.bin`))){let n=await k(l(e.dataPath,`fs.bin`)),r=new O.Message(n,!1).getRoot(t),i=new R(e,r);r._hasStorage()&&r.storage.length>0&&await Promise.all(r.storage.values().map(async e=>{await i.write(e.path,e.code)}))}return new R(e,new O.Message().initRoot(t))}static createSync(e){if(!e.config.skipCache&&S(l(e.dataPath,`fs.bin`))){let n=A(l(e.dataPath,`fs.bin`)),r=new O.Message(n,!1).getRoot(t),i=new R(e,r);r._hasStorage()&&r.storage.length>0&&r.storage.values().map(e=>{i.writeSync(e.path,e.code)})}return new R(e,new O.Message().initRoot(t))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=D({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,_(this.#o.config.output.storage)&&(this.#r={...this.#r,...this.#o.config.output.storage}),this.#r.virtual??=new s({base:`/_virtual`}),this.#o.config.output.storage!==`fs`&&(this.#r[this.#o.artifactsPath]??=new s({base:this.#o.artifactsPath}),this.#r[this.#o.builtinsPath]??=new s({base:this.#o.builtinsPath}),this.#r[this.#o.entryPath]??=new s({base:this.#o.entryPath})),this.#e={},t._hasMetadata()&&(this.#e=t.metadata.values().reduce((e,t)=>(e[t.id]={id:t.id,type:t.type,timestamp:t.timestamp||Date.now(),properties:t._hasProperties()?t.properties.values().reduce((e,t)=>(e[t.key]=t.value,e),{}):{}},e),{}),e.config.skipCache!==!0&&Object.entries(this.#e).filter(([,e])=>e.type===`entry`).forEach(([e,t])=>{this.#o.entry??=[],this.#o.entry.push({file:e,name:t.properties.name,output:t.properties.output,input:t.properties[`input.file`]?{file:t.properties[`input.file`],name:t.properties[`input.name`]}:void 0})})),this.#t={},this.#n={},t._hasIds()&&(this.#t=t.ids.values().reduce((e,t)=>(e[t.path]??=t.id,e),{}),this.#n=t.ids.values().reduce((e,t)=>(e[t.id]??=t.path,e),{})),this.#s=n(this.#o.log,`file-system`)}async exists(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.exists(t)}existsSync(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.existsSync(t)}isVirtual(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.name===`virtual`:!1}isDirectorySync(e){let t=this.resolveSync(e);return t?!!(this.existsSync(t)&&this.#d(t)?.adapter?.isDirectorySync(t)):!1}async isDirectory(e){let t=await this.resolve(e);return t?!!(await this.exists(t)&&await this.#d(t)?.adapter?.isDirectory(t)):!1}isFileSync(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.isFileSync(t)??!1:!1}async isFile(e){let t=await this.resolve(e);return t?await this.#d(t)?.adapter?.isFile(t)??!1:!1}listSync(e){return w(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?h(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return w((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?h(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(d.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);x(t)?await r.remove(n):await r.clear(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}removeSync(e){let t=this.#l(e);this.#s(d.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);x(t)?r.removeSync(n):r.clearSync(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}async glob(e){let t=[];for(let n of r(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...await this.list(e));else{let n=await this.resolve(e);n&&!t.includes(n)&&t.push(n)}continue}let r=E(e)?e:this.#l(l(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?b(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i)));await Promise.all((await this.list(a&&E(a)?a:this.#o.workspaceConfig.workspaceRoot)).map(async e=>{if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}))}return t}globSync(e){let t=[];for(let n of r(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...this.listSync(e));else{let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}continue}let r=E(e)?e:this.#l(l(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?b(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i))),o=this.listSync(a&&E(a)?a:this.#o.workspaceConfig.workspaceRoot);for(let e of o)if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}return t}async copy(e,t){let n=e instanceof URL?F(e):e,r=t instanceof URL?F(t):t;if(!v(n)&&(!_(n)||!v(n.input))||!v(r))return;let i=u(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=await this.resolve(i);if(a)if(this.isDirectorySync(a)||v(n)&&n.includes(`*`)||_(n)&&v(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,h(g(e,i),r))));else{let e=await this.read(a);e!==void 0&&await this.write(this.#l(r),e,{skipFormat:!0})}}copySync(e,t){let n=e instanceof URL?F(e):e,r=t instanceof URL?F(t):t;if(!v(n)&&(!_(n)||!v(n.input))||!v(r))return;let i=u(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=this.resolveSync(i);if(a)if(this.isDirectorySync(a)||v(n)&&n.includes(`*`)||_(n)&&v(n.glob))this.globSync(n).map(e=>this.copySync(e,h(b(g(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l(x(r)?r:h(y(a),r)),e,{skipFormat:!0})}}async move(e,t){x(e)?(await this.copy(e,t),await this.remove(e)):await Promise.all((await this.list(e)).map(async e=>{await this.copy(e,t),await this.remove(e)}))}moveSync(e,t){x(e)?(this.copySync(e,t),this.removeSync(e)):this.listSync(e).forEach(e=>{this.copySync(e,t),this.removeSync(e)})}async read(e){let t=await this.resolve(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(d.TRACE,`Reading ${r.name} file: ${t}`),await r.get(n)??void 0}readSync(e){let t=this.resolveSync(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(d.TRACE,`Reading ${r.name} file: ${t}`),r.getSync(n)??void 0}async write(e,t=``,n={}){let r=t;if(!n.skipFormat){let n=await L(this.#l(e));n&&(r=await I(t,{absolutePath:this.#l(e),...n}))}let{relativeKey:i,adapter:a}=this.#d(n.storage||e);this.#s(d.TRACE,`Writing ${this.#l(i)} to ${a.name===`virtual`?`the virtual file system`:a.name===`file-system`?`the local file system`:a.name} (size: ${M(new P(c(r)).size)})`);let o=n?.meta?.id||this.#c(i);return this.#e[o]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[o]=this.#l(i),this.#t[this.#l(i)]=o,a.set(i,r)}writeSync(e,t=``,n={}){let{relativeKey:r,adapter:i}=this.#d(n.storage||e);this.#s(d.TRACE,`Writing ${this.#l(r)} file to ${i.name===`virtual`?`the virtual file system`:i.name===`file-system`?`the local file system`:i.name} (size: ${M(new P(c(t)).size)})`);let a=n?.meta?.id||this.#c(r);return this.#e[a]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[a]=this.#l(r),this.#t[this.#l(r)]=a,i.setSync(r,t)}mkdirSync(e){return this.#d(e)?.adapter?.mkdirSync(e)}async mkdir(e){return this.#d(e)?.adapter?.mkdir(e)}getMetadata(e){let t=this.resolveSync(e);if(t&&this.metadata[t])return this.metadata[t]}resolveAlias(e){let t=e;if(this.#o.config.build.alias){if(Array.isArray(this.#o.config.build.alias)&&this.#o.config.build.alias.length>0){let e=this.#o.config.build.alias.filter(e=>v(e.find)&&(e.find===t||t.startsWith(`${e.find}/`))||N(e.find)&&e.find.test(t));if(e.length>0){let n=e.reduce((e,t)=>(v(e.find)?e.find.length:N(e.find)?e.find.source.length:0)>(v(t.find)?t.find.length:N(t.find)?t.find.source.length:0)?e:t);v(n.find)?t=t.replace(RegExp(`^${n.find}`),n.replacement):N(n.find)&&(t=t.replace(n.find,n.replacement))}}else if(_(this.#o.config.build.alias)){let e=Object.keys(this.#o.config.build.alias).filter(e=>e===t||t.startsWith(`${e}/`));if(e.length>0){let n=e.reduce((e,t)=>e.length>t.length?e:t);t=t.replace(RegExp(`^${n}`),this.#o.config.build.alias[n])}}}return t}async resolve(t,n,r={}){let i=t;if((i.includes(`{`)||i.includes(`}`))&&(i=e(this.#o,i)),r.skipAlias!==!0&&(i=this.resolveAlias(i)),E(i))return i;let a=C({path:this.#c(i),importer:n,options:r}),o;if(!this.#o.config.skipCache&&(o=this.resolverCache.get(a),o))return o;if(o=this.paths[this.#c(i)],!o){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push(h(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(h(this.#o.config.sourceRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(...Object.keys(this.#o.tsconfig?.options?.paths??{}).filter(e=>i.startsWith(e.replace(/\*$/,``))).map(e=>this.#o.tsconfig?.options?.paths?.[e]).flat().filter(Boolean).map(e=>h(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of f(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await p(i,{...r,paths:e})}catch{}}return o&&!this.#o.config.skipCache&&this.resolverCache.set(a,o),o}resolveSync(t,n,r={}){let i=t;if((i.includes(`{`)||i.includes(`}`))&&(i=e(this.#o,i)),r.skipAlias!==!0&&(i=this.resolveAlias(i)),E(i))return i;let a;if(!this.#o.config.skipCache&&(a=this.resolverCache.get(this.#c(i)),a))return a;if(a=this.paths[this.#c(i)],!a){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push(h(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(h(this.#o.config.sourceRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(...Object.keys(this.#o.tsconfig?.options?.paths??{}).filter(e=>i.startsWith(e.replace(/\*$/,``))).map(e=>this.#o.tsconfig?.options?.paths?.[e]).flat().filter(Boolean).map(e=>h(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of f(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=m(i,{...r,paths:e})}catch{}}return a&&!this.#o.config.skipCache&&this.resolverCache.set(this.#c(i),a),a}async dispose(){if(!this.#a){this.#a=!0,this.#s(d.DEBUG,`Disposing virtual file system...`),await this.remove(l(this.#o.dataPath,`fs.bin`));let e=new O.Message,n=e.initRoot(t),r=await this.list(),i=n._initStorage(r.length);await Promise.all(r.map(async(e,t)=>{let n=await this.read(e),r=i.get(t);r.path=e,r.code=n||``}));let a=n._initIds(Object.keys(this.ids).length);Object.entries(this.ids).filter(([,e])=>e).forEach(([e,t],n)=>{let r=a.get(n);r.id=e,r.path=t});let o=n._initMetadata(Object.keys(this.metadata).length);Object.entries(this.metadata).filter(([,e])=>e).forEach(([e,t],n)=>{let r=o.get(n);if(r.id=e,r.type=t.type,r.timestamp=t.timestamp??BigInt(Date.now()),t.properties){let e=r._initProperties(Object.keys(t.properties).length);Object.entries(t.properties).filter(([,e])=>v(e)).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await j(l(this.#o.dataPath,`fs.bin`),e.toArrayBuffer()),this.#o.config.skipCache||this.#i.save(!0),await Promise.all(this.#f().map(async e=>e.adapter.dispose())),this.#s(d.TRACE,`Virtual file system has been disposed.`)}}async[Symbol.asyncDispose](){return this.dispose()}};export{R as VirtualFileSystem};
@@ -301,6 +301,15 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
301
301
  * @param options - Additional options for writing the builtin file
302
302
  */
303
303
  emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
304
+ /**
305
+ * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
306
+ *
307
+ * @param code - The source code of the builtin file
308
+ * @param id - The unique identifier of the builtin file
309
+ * @param path - An optional path to write the builtin file to
310
+ * @param options - Additional options for writing the builtin file
311
+ */
312
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: WriteOptions) => void;
304
313
  /**
305
314
  * Resolves a entry virtual file and writes it to the VFS if it does not already exist
306
315
  *
@@ -309,6 +318,14 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
309
318
  * @param options - Additional options for writing the entry file
310
319
  */
311
320
  emitEntry: (code: string, path: string, options?: EmitEntryOptions) => Promise<void>;
321
+ /**
322
+ * Synchronously resolves a entry virtual file and writes it to the VFS if it does not already exist
323
+ *
324
+ * @param code - The source code of the entry file
325
+ * @param path - An optional path to write the entry file to
326
+ * @param options - Additional options for writing the entry file
327
+ */
328
+ emitEntrySync: (code: string, path: string, options?: EmitEntryOptions) => void;
312
329
  /**
313
330
  * A function to update the context fields using a new user configuration options
314
331
  */
@@ -303,6 +303,15 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
303
303
  * @param options - Additional options for writing the builtin file
304
304
  */
305
305
  emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
306
+ /**
307
+ * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
308
+ *
309
+ * @param code - The source code of the builtin file
310
+ * @param id - The unique identifier of the builtin file
311
+ * @param path - An optional path to write the builtin file to
312
+ * @param options - Additional options for writing the builtin file
313
+ */
314
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: WriteOptions) => void;
306
315
  /**
307
316
  * Resolves a entry virtual file and writes it to the VFS if it does not already exist
308
317
  *
@@ -311,6 +320,14 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
311
320
  * @param options - Additional options for writing the entry file
312
321
  */
313
322
  emitEntry: (code: string, path: string, options?: EmitEntryOptions) => Promise<void>;
323
+ /**
324
+ * Synchronously resolves a entry virtual file and writes it to the VFS if it does not already exist
325
+ *
326
+ * @param code - The source code of the entry file
327
+ * @param path - An optional path to write the entry file to
328
+ * @param options - Additional options for writing the entry file
329
+ */
330
+ emitEntrySync: (code: string, path: string, options?: EmitEntryOptions) => void;
314
331
  /**
315
332
  * A function to update the context fields using a new user configuration options
316
333
  */
@@ -13,6 +13,13 @@ interface StorageAdapter {
13
13
  * A name identifying the storage adapter type.
14
14
  */
15
15
  name: string;
16
+ /**
17
+ * The storage preset for the adapter.
18
+ *
19
+ * @remarks
20
+ * This can be used as an alternate way to identify the type of storage being used.
21
+ */
22
+ preset?: StoragePreset | null;
16
23
  /**
17
24
  * Checks if a key exists in the storage.
18
25
  *
@@ -207,6 +214,13 @@ interface WriteOptions {
207
214
  * @defaultValue false
208
215
  */
209
216
  skipFormat?: boolean;
217
+ /**
218
+ * The storage preset or adapter name for the output file.
219
+ *
220
+ * @remarks
221
+ * If not specified, the output mode will be determined by the provided `output.mode` value.
222
+ */
223
+ storage?: StoragePreset | string;
210
224
  /**
211
225
  * Additional metadata for the file.
212
226
  */
@@ -217,6 +231,10 @@ interface ResolveOptions$1 extends ResolveOptions {
217
231
  * If true, the module is being resolved as an entry point.
218
232
  */
219
233
  isEntry?: boolean;
234
+ /**
235
+ * If true, the resolver will skip alias resolution when resolving modules.
236
+ */
237
+ skipAlias?: boolean;
220
238
  /**
221
239
  * If true, the resolver will skip using the cache when resolving modules.
222
240
  */
@@ -449,6 +467,16 @@ interface VirtualFileSystemInterface {
449
467
  * @returns The resolved module path.
450
468
  */
451
469
  resolveSync: (id: string, importer?: string, options?: ResolveOptions$1) => string | undefined;
470
+ /**
471
+ * Resolves a given module ID using the configured aliases.
472
+ *
473
+ * @remarks
474
+ * This function can be used to map module IDs to different paths based on the alias configuration.
475
+ *
476
+ * @param id - The module ID to resolve.
477
+ * @returns The resolved module ID - after applying any configured aliases (this will be the same as the input ID if no aliases match).
478
+ */
479
+ resolveAlias: (id: string) => string;
452
480
  /**
453
481
  * Disposes of the virtual file system (VFS), writes any virtual file changes to disk, and releases any associated resources.
454
482
  */
@@ -13,6 +13,13 @@ interface StorageAdapter {
13
13
  * A name identifying the storage adapter type.
14
14
  */
15
15
  name: string;
16
+ /**
17
+ * The storage preset for the adapter.
18
+ *
19
+ * @remarks
20
+ * This can be used as an alternate way to identify the type of storage being used.
21
+ */
22
+ preset?: StoragePreset | null;
16
23
  /**
17
24
  * Checks if a key exists in the storage.
18
25
  *
@@ -207,6 +214,13 @@ interface WriteOptions {
207
214
  * @defaultValue false
208
215
  */
209
216
  skipFormat?: boolean;
217
+ /**
218
+ * The storage preset or adapter name for the output file.
219
+ *
220
+ * @remarks
221
+ * If not specified, the output mode will be determined by the provided `output.mode` value.
222
+ */
223
+ storage?: StoragePreset | string;
210
224
  /**
211
225
  * Additional metadata for the file.
212
226
  */
@@ -217,6 +231,10 @@ interface ResolveOptions$1 extends ResolveOptions {
217
231
  * If true, the module is being resolved as an entry point.
218
232
  */
219
233
  isEntry?: boolean;
234
+ /**
235
+ * If true, the resolver will skip alias resolution when resolving modules.
236
+ */
237
+ skipAlias?: boolean;
220
238
  /**
221
239
  * If true, the resolver will skip using the cache when resolving modules.
222
240
  */
@@ -449,6 +467,16 @@ interface VirtualFileSystemInterface {
449
467
  * @returns The resolved module path.
450
468
  */
451
469
  resolveSync: (id: string, importer?: string, options?: ResolveOptions$1) => string | undefined;
470
+ /**
471
+ * Resolves a given module ID using the configured aliases.
472
+ *
473
+ * @remarks
474
+ * This function can be used to map module IDs to different paths based on the alias configuration.
475
+ *
476
+ * @param id - The module ID to resolve.
477
+ * @returns The resolved module ID - after applying any configured aliases (this will be the same as the input ID if no aliases match).
478
+ */
479
+ resolveAlias: (id: string) => string;
452
480
  /**
453
481
  * Disposes of the virtual file system (VFS), writes any virtual file changes to disk, and releases any associated resources.
454
482
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-rolldown",
3
- "version": "0.7.125",
3
+ "version": "0.7.127",
4
4
  "type": "module",
5
5
  "description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
6
6
  "repository": {
@@ -152,15 +152,15 @@
152
152
  "@stryke/types": "^0.10.28",
153
153
  "defu": "^6.1.4",
154
154
  "jiti": "^2.6.1",
155
- "powerlines": "^0.36.20",
155
+ "powerlines": "^0.36.22",
156
156
  "rolldown": "1.0.0-beta.53",
157
157
  "unplugin": "3.0.0-beta.3"
158
158
  },
159
159
  "devDependencies": {
160
- "@powerlines/nx": "^0.11.46",
161
- "@powerlines/plugin-plugin": "^0.12.67",
160
+ "@powerlines/nx": "^0.11.48",
161
+ "@powerlines/plugin-plugin": "^0.12.69",
162
162
  "@types/node": "^24.10.4"
163
163
  },
164
164
  "publishConfig": { "access": "public" },
165
- "gitHead": "bf1440eb5eb29cb9650051e56b0c17e596eb3942"
165
+ "gitHead": "f88fe8eb30f96536b83fc9af884972d48e31e63a"
166
166
  }