@powerlines/plugin-esbuild 0.13.100 → 0.13.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/powerlines/src/api.cjs +1 -1
- package/dist/powerlines/src/lib/contexts/context.cjs +1 -1
- package/dist/powerlines/src/lib/contexts/context.mjs +1 -1
- package/dist/powerlines/src/lib/fs/vfs.cjs +1 -1
- package/dist/powerlines/src/lib/fs/vfs.mjs +1 -1
- package/dist/powerlines/src/lib/utilities/source-file.mjs +1 -1
- package/dist/powerlines/src/types/config.d.cts +1 -1
- package/dist/powerlines/src/types/config.d.mts +1 -2
- package/dist/powerlines/src/types/context.d.cts +13 -10
- package/dist/powerlines/src/types/context.d.mts +13 -10
- package/dist/powerlines/src/types/fs.d.cts +2 -2
- package/dist/powerlines/src/types/fs.d.mts +2 -2
- package/dist/powerlines/src/types/resolved.d.cts +1 -1
- package/dist/powerlines/src/types/resolved.d.mts +1 -1
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`./internal/babel/module-resolver-plugin.cjs`),n=require(`./internal/helpers/generate-types.cjs`),r=require(`./internal/helpers/hooks.cjs`),i=require(`./internal/helpers/install-dependencies.cjs`),a=require(`./lib/typescript/tsconfig.cjs`),o=require(`./internal/helpers/resolve-tsconfig.cjs`),s=require(`./plugin-utils/helpers.cjs`),c=require(`./lib/utilities/meta.cjs`),l=require(`./lib/contexts/api-context.cjs`),u=require(`./lib/utilities/file-header.cjs`);let d=require(`@stryke/path/join-paths`),f=require(`@stryke/path/replace`),p=require(`@stryke/convert/to-array`),m=require(`@stryke/fs/list-files`),h=require(`@stryke/path/append`),g=require(`@stryke/type-checks/is-set-string`),_=require(`@storm-software/config-tools/types`),v=require(`@babel/core`),y=require(`@storm-software/config-tools/logger/console`),b=require(`@stryke/fs/helpers`),x=require(`@stryke/fs/install`),S=require(`@stryke/fs/package-fns`),C=require(`@stryke/fs/resolve`),w=require(`@stryke/type-checks/is-error`),T=require(`@stryke/type-checks/is-function`),E=require(`@stryke/type-checks/is-number`),D=require(`@stryke/type-checks/is-object`),O=require(`@stryke/type-checks/is-promise`),k=require(`@stryke/type-checks/is-set`),A=require(`@stryke/type-checks/is-set-object`),j=require(`chalk`);j=e.__toESM(j);let M=require(`handlebars`);M=e.__toESM(M);var N=class e{#e;get context(){return this.#e}constructor(e){this.#e=e}static async from(t,n){let r=new e(await l.PowerlinesAPIContext.from(t,n));r.#e.$$internal={api:r,addPlugin:r.#i.bind(r)};for(let e of r.context.config.plugins??[])await r.#i(e);r.context.plugins.length===0&&r.context.log(_.LogLevelLabel.WARN,`No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.`);let i=await r.callHook(`config`,{environment:await r.context.getEnvironment(),sequential:!0,result:`merge`});return await r.context.withUserConfig(i,{isHighPriority:!1}),r}async prepare(e={command:`prepare`}){this.context.log(_.LogLevelLabel.TRACE,` 🏗️ Preparing the Powerlines project`),this.context.log(_.LogLevelLabel.TRACE,` ⚙️ Aggregating configuration options for the Powerlines project`),await this.context.withInlineConfig(e),await this.#r(async e=>{if(e.log(_.LogLevelLabel.TRACE,`Initializing the processing options for the Powerlines project.`),await this.callHook(`configResolved`,{environment:e,order:`pre`}),await o.initializeTsconfig(e),await this.callHook(`configResolved`,{environment:e,order:`normal`}),e.log(_.LogLevelLabel.DEBUG,`The configuration provided ${(0,p.toArray)(e.config.entry).length} entry point(s), Powerlines has found ${e.entry.length} entry files(s) for the ${e.config.title} project${e.entry.length>0&&e.entry.length<10?`: \n${e.entry.map(e=>`- ${e.
|
|
1
|
+
const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`./internal/babel/module-resolver-plugin.cjs`),n=require(`./internal/helpers/generate-types.cjs`),r=require(`./internal/helpers/hooks.cjs`),i=require(`./internal/helpers/install-dependencies.cjs`),a=require(`./lib/typescript/tsconfig.cjs`),o=require(`./internal/helpers/resolve-tsconfig.cjs`),s=require(`./plugin-utils/helpers.cjs`),c=require(`./lib/utilities/meta.cjs`),l=require(`./lib/contexts/api-context.cjs`),u=require(`./lib/utilities/file-header.cjs`);let d=require(`@stryke/path/join-paths`),f=require(`@stryke/path/replace`),p=require(`@stryke/convert/to-array`),m=require(`@stryke/fs/list-files`),h=require(`@stryke/path/append`),g=require(`@stryke/type-checks/is-set-string`),_=require(`@storm-software/config-tools/types`),v=require(`@babel/core`),y=require(`@storm-software/config-tools/logger/console`),b=require(`@stryke/fs/helpers`),x=require(`@stryke/fs/install`),S=require(`@stryke/fs/package-fns`),C=require(`@stryke/fs/resolve`),w=require(`@stryke/type-checks/is-error`),T=require(`@stryke/type-checks/is-function`),E=require(`@stryke/type-checks/is-number`),D=require(`@stryke/type-checks/is-object`),O=require(`@stryke/type-checks/is-promise`),k=require(`@stryke/type-checks/is-set`),A=require(`@stryke/type-checks/is-set-object`),j=require(`chalk`);j=e.__toESM(j);let M=require(`handlebars`);M=e.__toESM(M);var N=class e{#e;get context(){return this.#e}constructor(e){this.#e=e}static async from(t,n){let r=new e(await l.PowerlinesAPIContext.from(t,n));r.#e.$$internal={api:r,addPlugin:r.#i.bind(r)};for(let e of r.context.config.plugins??[])await r.#i(e);r.context.plugins.length===0&&r.context.log(_.LogLevelLabel.WARN,`No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.`);let i=await r.callHook(`config`,{environment:await r.context.getEnvironment(),sequential:!0,result:`merge`});return await r.context.withUserConfig(i,{isHighPriority:!1}),r}async prepare(e={command:`prepare`}){this.context.log(_.LogLevelLabel.TRACE,` 🏗️ Preparing the Powerlines project`),this.context.log(_.LogLevelLabel.TRACE,` ⚙️ Aggregating configuration options for the Powerlines project`),await this.context.withInlineConfig(e),await this.#r(async e=>{if(e.log(_.LogLevelLabel.TRACE,`Initializing the processing options for the Powerlines project.`),await this.callHook(`configResolved`,{environment:e,order:`pre`}),await o.initializeTsconfig(e),await this.callHook(`configResolved`,{environment:e,order:`normal`}),e.log(_.LogLevelLabel.DEBUG,`The configuration provided ${(0,p.toArray)(e.config.entry).length} entry point(s), Powerlines has found ${e.entry.length} entry files(s) for the ${e.config.title} project${e.entry.length>0&&e.entry.length<10?`: \n${e.entry.map(e=>`- ${e.file}${e.output?` -> ${e.output}`:``}`).join(`
|
|
2
2
|
`)}`:``}.`),await o.resolveTsconfig(e),await i.installDependencies(e),await this.callHook(`configResolved`,{environment:e,order:`post`}),e.log(_.LogLevelLabel.TRACE,`Powerlines configuration has been resolved: \n\n${(0,y.formatLogMessage)(e.config)}`),e.fs.existsSync(e.cachePath)||await(0,b.createDirectory)(e.cachePath),e.fs.existsSync(e.dataPath)||await(0,b.createDirectory)(e.dataPath),await this.callHook(`prepare`,{environment:e,order:`pre`}),await this.callHook(`prepare`,{environment:e,order:`normal`}),e.config.output.dts!==!1){e.log(_.LogLevelLabel.TRACE,`Preparing the TypeScript definitions for the Powerlines project.`),e.fs.existsSync(e.dtsPath)&&await e.fs.remove(e.dtsPath),e.log(_.LogLevelLabel.TRACE,`Transforming built-ins runtime modules files.`);let r=await Promise.all((await e.getBuiltins()).map(async n=>{let r=await(0,v.transformAsync)(n.code.toString(),{highlightCode:!0,code:!0,ast:!1,cloneInputAst:!1,comments:!0,sourceType:`module`,configFile:!1,babelrc:!1,envName:e.config.mode,caller:{name:`powerlines`},...e.config.transform.babel,filename:n.path,plugins:[[`@babel/plugin-syntax-typescript`],[t.moduleResolverBabelPlugin(e)]]});if(!r?.code)throw Error(`Powerlines - Generate Types failed to compile ${n.id}`);return e.log(_.LogLevelLabel.TRACE,`Writing transformed built-in runtime file ${n.id}.`),await e.emitBuiltin(r.code,n.id,n.path),n.path}));if(!await(0,C.resolvePackage)(`typescript`))throw Error(`Could not resolve TypeScript package location. Please ensure TypeScript is installed.`);let i=r.reduce((t,n)=>{let r=(0,f.replacePath)(n,e.workspaceConfig.workspaceRoot);return t.includes(r)||t.push(r),t},[]);e.log(_.LogLevelLabel.TRACE,`Parsing TypeScript configuration for the Powerlines project.`);let s=await n.emitTypes(e,i);e.log(_.LogLevelLabel.TRACE,`Generating TypeScript declaration file ${e.dtsPath}.`);let c=[],l=e=>(0,D.isObject)(e)?e.code:e,d=await this.callHook(`types`,{environment:e,sequential:!0,order:`pre`,result:`merge`,asNextParam:l},s);if(d&&((0,A.isSetObject)(d)?(s=d.code,Array.isArray(d.directives)&&d.directives.length>0&&c.push(...d.directives)):(0,g.isSetString)(d)&&(s=d)),d=await this.callHook(`types`,{environment:e,sequential:!0,order:`normal`,result:`merge`,asNextParam:l},s),d&&((0,A.isSetObject)(d)?(s=d.code,Array.isArray(d.directives)&&d.directives.length>0&&c.push(...d.directives)):(0,g.isSetString)(d)&&(s=d)),d=await this.callHook(`types`,{environment:e,sequential:!0,order:`post`,result:`merge`,asNextParam:l},s),d&&((0,A.isSetObject)(d)?(s=d.code,Array.isArray(d.directives)&&d.directives.length>0&&c.push(...d.directives)):(0,g.isSetString)(d)&&(s=d)),s?.trim()||c.length>0)await e.fs.write(e.dtsPath,`${c?`${c.map(e=>`/// <reference types="${e}" />`).join(`
|
|
3
3
|
`)}
|
|
4
4
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../../plugin-utils/paths.cjs`),n=require(`../entry.cjs`),r=require(`../typescript/ts-morph.cjs`),i=require(`../typescript/tsconfig.cjs`),a=require(`../config-file.cjs`),o=require(`../../internal/helpers/resolver.cjs`),s=require(`../../plugin-utils/helpers.cjs`),c=require(`../logger.cjs`),l=require(`../fs/vfs.cjs`),u=require(`../utilities/meta.cjs`);let d=require(`defu`);d=e.__toESM(d);let f=require(`@stryke/helpers/omit`),p=require(`@stryke/path/replace`),m=require(`@stryke/type-checks/is-string`),h=require(`@stryke/convert/to-array`),g=require(`@stryke/hash/murmurhash`),_=require(`@stryke/helpers/get-unique`),v=require(`@stryke/path/append`),y=require(`@stryke/type-checks/is-set-string`),b=require(`@storm-software/config-tools/types`),x=require(`@stryke/fs/get-workspace-root`),S=require(`@stryke/fs/resolve`),C=require(`@stryke/type-checks/is-set-object`),w=require(`@stryke/fs/json`),T=require(`@stryke/json/storm-json`),E=require(`@stryke/string-format/title-case`),D=require(`@stryke/fs/exists`),O=require(`@stryke/env/get-env-paths`),k=require(`@stryke/hash/hash-files`),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;(0,z.setGlobalDispatcher)(new z.Agent({keepAliveTimeout:1e4}).compose(z.interceptors.retry({maxRetries:3,minTimeout:1e3,maxTimeout:1e4,timeoutFactor:2,retryAfter:!0})));var V=class e{#e={};#t;#n=null;#r=(0,F.uuid)();#i=(0,F.uuid)();#a=Date.now();#o;#s=null;#c;#l;#u;#d;#f;#p(e={}){return(0,d.default)({variant:e.build?.variant,projectType:e.type,projectRoot:e.root,name:e.name,title:e.title,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 r=new e(await a.loadWorkspaceConfig(t,n.root));await r.withUserConfig(n);let i=await(0,S.resolvePackage)(`powerlines`);if(!i)throw Error("Could not resolve `powerlines` package location.");return r.powerlinesPath=i,r}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 n.resolveEntriesSync(this,this.#s?this.#s:(0,h.toArray)(this.config.entry))}set entry(e){this.#s=e}get tsconfig(){return this.#l||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#l}set tsconfig(e){this.#l=e,this.resolvePatterns=(0,I.tsconfigPathsToRegExp)(e?.options?.paths??{})}get fs(){return this.#c||=l.VirtualFileSystem.createSync(this),this.#c}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:(0,g.murmurhash)({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:u.PROJECT_ROOT_HASH_LENGTH}),configHash:(0,g.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(){return this.#o||=(0,O.getEnvPaths)({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:this.workspaceConfig.workspaceRoot}),this.#o}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,g.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,x.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.#u||=r.createProgram(this,{skipAddingFilesFromTsConfig:!0}),this.#u}get parserCache(){return this.#d||=(0,L.create)({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#d}get requestCache(){return this.#f||=(0,L.create)({cacheId:`http`,cacheDir:this.cachePath,ttl:300*1e3,lruSize:5e3,persistInterval:250}),this.#f}async fetch(e,t={}){let n=(0,g.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,g.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,C.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={}){return this.fs.write((0,M.isAbsolute)(t)?t:(0,v.appendPath)(t,this.entryPath),e,(0,d.default)((0,f.omit)(n,[`name`]),{meta:{type:`entry`,properties:{name:n.name||`default`}}}))}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,d.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,D.existsSync)(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await(0,w.readJsonFile)(e),this.workspaceConfig.repository??=(0,y.isSetString)(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(b.LogLevelLabel.FATAL,(0,m.isString)(e)?e:T.StormJSON.stringify(e))}error(e){this.log(b.LogLevelLabel.ERROR,(0,m.isString)(e)?e:T.StormJSON.stringify(e))}warn(e){this.log(b.LogLevelLabel.WARN,(0,m.isString)(e)?e:T.StormJSON.stringify(e))}info(e){this.log(b.LogLevelLabel.INFO,(0,m.isString)(e)?e:T.StormJSON.stringify(e))}debug(e){this.log(b.LogLevelLabel.DEBUG,(0,m.isString)(e)?e:T.StormJSON.stringify(e))}trace(e){this.log(b.LogLevelLabel.TRACE,(0,m.isString)(e)?e:T.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,k.hashDirectory)(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,this.#o=(0,O.getEnvPaths)({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot})}resolvedConfig={};logFn;async init(e={},r={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,D.existsSync)(t)&&(this.projectJson=await(0,w.readJsonFile)(t));let n=(0,N.joinPaths)(c.projectRoot,`package.json`);(0,D.existsSync)(n)&&(this.packageJson=await(0,w.readJsonFile)(n)),this.#n=await this.generateChecksum(c.projectRoot),this.resolver=o.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 r=await a.loadUserConfigFile(c.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,c.command,c.mode,c.configFile,c.framework);this.mergeUserConfig(r.config),B.set(c,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:r})}e.tsconfig??=i.getTsconfigFilePath(this.workspaceConfig.workspaceRoot,c.projectRoot,e.tsconfig),(0,C.isSetObject)(e)&&(this.resolvedConfig=(0,d.default)({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},r.isHighPriority?this.#p(e):{},{command:this.config.inlineConfig?.command,...this.#p(this.config.inlineConfig)},this.#p(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,d.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`}]})},r.isHighPriority?{}:this.#p(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=n.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,E.titleCase)(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=(0,_.getUnique)(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=(0,_.getUnique)(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=(0,_.getUnique)(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=(0,_.getUnique)(this.config.build.noExternal)),this.config.output.format=(0,_.getUnique)((0,h.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,_.getUniqueBy)(this.config.output.assets.map(e=>({glob:(0,C.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,C.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,p.replacePath)((0,p.replacePath)(e.output,(0,p.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,C.isSetObject)(e)&&e.ignore?(0,h.toArray)(e.ignore):void 0})),e=>`${e.input}-${e.glob}-${e.output}`),this.config.plugins=(this.config.plugins??[]).filter(Boolean).reduce((e,t)=>(s.isPlugin(t)&&s.checkDedupe(t,e.filter(e=>s.isPlugin(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=t.replacePathTokens(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=t.replacePathTokens(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(e=>t.replacePathTokens(this,e))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(e=>({...e,glob:t.replacePathTokens(this,e.glob),ignore:e.ignore?e.ignore.map(e=>t.replacePathTokens(this,e)):void 0,input:t.replacePathTokens(this,e.input),output:t.replacePathTokens(this,e.output)}))),this.#c??=await l.VirtualFileSystem.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=(0,d.default)({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},(0,f.omit)(e??{},[`entry`]),(0,f.omit)(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=(0,_.getUnique)((0,h.toArray)(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(s.isPlugin(t)&&s.checkDedupe(t,e.filter(e=>s.isPlugin(e)))||e.push(t),e),[])}};exports.PowerlinesContext=V;
|
|
1
|
+
const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../../plugin-utils/paths.cjs`),n=require(`../entry.cjs`),r=require(`../typescript/ts-morph.cjs`),i=require(`../typescript/tsconfig.cjs`),a=require(`../config-file.cjs`),o=require(`../../internal/helpers/resolver.cjs`),s=require(`../../plugin-utils/helpers.cjs`),c=require(`../logger.cjs`),l=require(`../fs/vfs.cjs`),u=require(`../utilities/meta.cjs`);let d=require(`defu`);d=e.__toESM(d);let f=require(`@stryke/helpers/omit`),p=require(`@stryke/path/replace`),m=require(`@stryke/type-checks/is-string`),h=require(`@stryke/convert/to-array`),g=require(`@stryke/hash/murmurhash`),_=require(`@stryke/helpers/get-unique`),v=require(`@stryke/path/append`),y=require(`@stryke/type-checks/is-set-string`),b=require(`@storm-software/config-tools/types`),x=require(`@stryke/fs/get-workspace-root`),S=require(`@stryke/fs/resolve`),C=require(`@stryke/type-checks/is-set-object`),w=require(`@stryke/fs/json`),T=require(`@stryke/json/storm-json`),E=require(`@stryke/string-format/title-case`),D=require(`@stryke/fs/exists`),O=require(`@stryke/env/get-env-paths`),k=require(`@stryke/hash/hash-files`),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;(0,z.setGlobalDispatcher)(new z.Agent({keepAliveTimeout:1e4}).compose(z.interceptors.retry({maxRetries:3,minTimeout:1e3,maxTimeout:1e4,timeoutFactor:2,retryAfter:!0})));var V=class e{#e={};#t;#n=null;#r=(0,F.uuid)();#i=(0,F.uuid)();#a=Date.now();#o;#s=null;#c;#l;#u;#d;#f;#p(e={}){return(0,d.default)({variant:e.build?.variant,projectType:e.type,projectRoot:e.root,name:e.name,title:e.title,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 r=new e(await a.loadWorkspaceConfig(t,n.root));await r.withUserConfig(n);let i=await(0,S.resolvePackage)(`powerlines`);if(!i)throw Error("Could not resolve `powerlines` package location.");return r.powerlinesPath=i,r}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 n.resolveEntriesSync(this,this.#s?this.#s:(0,h.toArray)(this.config.entry))}set entry(e){this.#s=e}get tsconfig(){return this.#l||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#l}set tsconfig(e){this.#l=e,this.resolvePatterns=(0,I.tsconfigPathsToRegExp)(e?.options?.paths??{})}get fs(){return this.#c||=l.VirtualFileSystem.createSync(this),this.#c}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:(0,g.murmurhash)({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:u.PROJECT_ROOT_HASH_LENGTH}),configHash:(0,g.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(){return this.#o||=(0,O.getEnvPaths)({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:this.workspaceConfig.workspaceRoot}),this.#o}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,g.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,x.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.#u||=r.createProgram(this,{skipAddingFilesFromTsConfig:!0}),this.#u}get parserCache(){return this.#d||=(0,L.create)({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#d}get requestCache(){return this.#f||=(0,L.create)({cacheId:`http`,cacheDir:this.cachePath,ttl:300*1e3,lruSize:5e3,persistInterval:250}),this.#f}async fetch(e,t={}){let n=(0,g.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,g.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,C.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,d.default)((0,f.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,d.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,D.existsSync)(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await(0,w.readJsonFile)(e),this.workspaceConfig.repository??=(0,y.isSetString)(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(b.LogLevelLabel.FATAL,(0,m.isString)(e)?e:T.StormJSON.stringify(e))}error(e){this.log(b.LogLevelLabel.ERROR,(0,m.isString)(e)?e:T.StormJSON.stringify(e))}warn(e){this.log(b.LogLevelLabel.WARN,(0,m.isString)(e)?e:T.StormJSON.stringify(e))}info(e){this.log(b.LogLevelLabel.INFO,(0,m.isString)(e)?e:T.StormJSON.stringify(e))}debug(e){this.log(b.LogLevelLabel.DEBUG,(0,m.isString)(e)?e:T.StormJSON.stringify(e))}trace(e){this.log(b.LogLevelLabel.TRACE,(0,m.isString)(e)?e:T.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,k.hashDirectory)(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,this.#o=(0,O.getEnvPaths)({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot})}resolvedConfig={};logFn;async init(e={},r={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,D.existsSync)(t)&&(this.projectJson=await(0,w.readJsonFile)(t));let n=(0,N.joinPaths)(c.projectRoot,`package.json`);(0,D.existsSync)(n)&&(this.packageJson=await(0,w.readJsonFile)(n)),this.#n=await this.generateChecksum(c.projectRoot),this.resolver=o.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 r=await a.loadUserConfigFile(c.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,c.command,c.mode,c.configFile,c.framework);this.mergeUserConfig(r.config),B.set(c,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:r})}e.tsconfig??=i.getTsconfigFilePath(this.workspaceConfig.workspaceRoot,c.projectRoot,e.tsconfig),(0,C.isSetObject)(e)&&(this.resolvedConfig=(0,d.default)({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},r.isHighPriority?this.#p(e):{},{command:this.config.inlineConfig?.command,...this.#p(this.config.inlineConfig)},this.#p(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,d.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`}]})},r.isHighPriority?{}:this.#p(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=n.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,E.titleCase)(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=(0,_.getUnique)(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=(0,_.getUnique)(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=(0,_.getUnique)(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=(0,_.getUnique)(this.config.build.noExternal)),this.config.output.format=(0,_.getUnique)((0,h.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,_.getUniqueBy)(this.config.output.assets.map(e=>({glob:(0,C.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,C.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,p.replacePath)((0,p.replacePath)(e.output,(0,p.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,C.isSetObject)(e)&&e.ignore?(0,h.toArray)(e.ignore):void 0})),e=>`${e.input}-${e.glob}-${e.output}`),this.config.plugins=(this.config.plugins??[]).filter(Boolean).reduce((e,t)=>(s.isPlugin(t)&&s.checkDedupe(t,e.filter(e=>s.isPlugin(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=t.replacePathTokens(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=t.replacePathTokens(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(e=>t.replacePathTokens(this,e))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(e=>({...e,glob:t.replacePathTokens(this,e.glob),ignore:e.ignore?e.ignore.map(e=>t.replacePathTokens(this,e)):void 0,input:t.replacePathTokens(this,e.input),output:t.replacePathTokens(this,e.output)}))),this.#c??=await l.VirtualFileSystem.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=(0,d.default)({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},(0,f.omit)(e??{},[`entry`]),(0,f.omit)(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=(0,_.getUnique)((0,h.toArray)(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(s.isPlugin(t)&&s.checkDedupe(t,e.filter(e=>s.isPlugin(e)))||e.push(t),e),[])}};exports.PowerlinesContext=V;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{replacePathTokens as e}from"../../plugin-utils/paths.mjs";import{getUniqueEntries as t,resolveEntriesSync as n}from"../entry.mjs";import{createProgram as r}from"../typescript/ts-morph.mjs";import{getTsconfigFilePath as i}from"../typescript/tsconfig.mjs";import{loadUserConfigFile as a,loadWorkspaceConfig as o}from"../config-file.mjs";import{createResolver as s}from"../../internal/helpers/resolver.mjs";import{checkDedupe as c,isPlugin as l}from"../../plugin-utils/helpers.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 g from"defu";import{omit as _}from"@stryke/helpers/omit";import{replacePath as v}from"@stryke/path/replace";import{isString as y}from"@stryke/type-checks/is-string";import{toArray as b}from"@stryke/convert/to-array";import{murmurhash as x}from"@stryke/hash/murmurhash";import{getUnique as S,getUniqueBy as C}from"@stryke/helpers/get-unique";import{appendPath as w}from"@stryke/path/append";import{isSetString as T}from"@stryke/type-checks/is-set-string";import{LogLevelLabel as E}from"@storm-software/config-tools/types";import{relativeToWorkspaceRoot as D}from"@stryke/fs/get-workspace-root";import{resolvePackage as O}from"@stryke/fs/resolve";import{isSetObject as k}from"@stryke/type-checks/is-set-object";import{readJsonFile as A}from"@stryke/fs/json";import{StormJSON as j}from"@stryke/json/storm-json";import{titleCase as M}from"@stryke/string-format/title-case";import{existsSync as N}from"@stryke/fs/exists";import{getEnvPaths as P}from"@stryke/env/get-env-paths";import{hashDirectory as F}from"@stryke/hash/hash-files";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;Y(new K({keepAliveTimeout:1e4}).compose(J.retry({maxRetries:3,minTimeout:1e3,maxTimeout:1e4,timeoutFactor:2,retryAfter:!0})));var Z=class K{#e={};#t;#n=null;#r=V();#i=V();#a=Date.now();#o;#s=null;#c;#l;#u;#d;#f;#p(e={}){return g({variant:e.build?.variant,projectType:e.type,projectRoot:e.root,name:e.name,title:e.title,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 o(e,t.root));await n.withUserConfig(t);let r=await O(`powerlines`);if(!r)throw Error("Could not resolve `powerlines` package location.");return n.powerlinesPath=r,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 n(this,this.#s?this.#s:b(this.config.entry))}set entry(e){this.#s=e}get tsconfig(){return this.#l||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#l}set tsconfig(e){this.#l=e,this.resolvePatterns=U(e?.options?.paths??{})}get fs(){return this.#c||=f.createSync(this),this.#c}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:x({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:m}),configHash:x(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(){return this.#o||=P({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:this.workspaceConfig.workspaceRoot}),this.#o}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`,x({checksum:this.#n,config:this.meta.configHash},{maxLength:p}))}get dtsPath(){return this.config.output.dts?w(this.config.output.dts,this.workspaceConfig.workspaceRoot):z(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return D(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.#u||=r(this,{skipAddingFilesFromTsConfig:!0}),this.#u}get parserCache(){return this.#d||=W({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#d}get requestCache(){return this.#f||=W({cacheId:`http`,cacheDir:this.cachePath,ttl:300*1e3,lruSize:5e3,persistInterval:250}),this.#f}async fetch(e,t={}){let n=x({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=x({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 k(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={}){return this.fs.write(R(t)?t:w(t,this.entryPath),e,g(_(n,[`name`]),{meta:{type:`entry`,properties:{name:n.name||`default`}}}))}async emitBuiltin(e,t,n,r={}){return this.fs.write(n?R(n)?n:z(this.builtinsPath,n):w(t,this.builtinsPath),e,g(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(!N(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await A(e),this.workspaceConfig.repository??=T(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(E.FATAL,y(e)?e:j.stringify(e))}error(e){this.log(E.ERROR,y(e)?e:j.stringify(e))}warn(e){this.log(E.WARN,y(e)?e:j.stringify(e))}info(e){this.log(E.INFO,y(e)?e:j.stringify(e))}debug(e){this.log(E.DEBUG,y(e)?e:j.stringify(e))}trace(e){this.log(E.TRACE,y(e)?e:j.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 F(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,this.#o=P({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot})}resolvedConfig={};logFn;async init(n={},r={isHighPriority:!0}){let o={projectRoot:n.root??this.config.projectRoot??this.config.userConfig?.root??this.config.inlineConfig?.root,mode:(n.mode??this.config.mode)||this.workspaceConfig.mode,skipCache:n.skipCache??this.config.skipCache??!1,configFile:n.configFile??this.config.configFile,framework:n.framework??this.config.framework??`powerlines`,command:this.config.inlineConfig?.command};if(X.has(o)){let e=X.get(o);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 e=z(o.projectRoot,`project.json`);N(e)&&(this.projectJson=await A(e));let t=z(o.projectRoot,`package.json`);N(t)&&(this.packageJson=await A(t)),this.#n=await this.generateChecksum(o.projectRoot),this.resolver=s({workspaceRoot:this.workspaceConfig.workspaceRoot,projectRoot:o.projectRoot,cacheDir:this.cachePath,mode:o.mode,logLevel:n.logLevel||this.config?.logLevel||this.workspaceConfig.logLevel||`info`,skipCache:o.skipCache});let r=await a(o.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,o.command,o.mode,o.configFile,o.framework);this.mergeUserConfig(r.config),X.set(o,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:r})}n.tsconfig??=i(this.workspaceConfig.workspaceRoot,o.projectRoot,n.tsconfig),k(n)&&(this.resolvedConfig=g({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},r.isHighPriority?this.#p(n):{},{command:this.config.inlineConfig?.command,...this.#p(this.config.inlineConfig)},this.#p(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||w(`src`,o.projectRoot),output:g(n.output??{},{outputPath:o.projectRoot?z(this.workspaceConfig?.directories?.build||`dist`,o.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:z(o.projectRoot,`.${n.framework??`powerlines`}`),dts:z(o.projectRoot,`${n.framework??`powerlines`}.d.ts`),builtinPrefix:n.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:o.projectRoot,glob:`*.md`},{input:o.projectRoot,glob:`package.json`}]})},r.isHighPriority?{}:this.#p(n),{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=t(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??=M(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=S(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=S(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=S(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=S(this.config.build.noExternal)),this.config.output.format=S(b(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=C(this.config.output.assets.map(e=>({glob:k(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:w(e.input,this.workspaceConfig.workspaceRoot),output:k(e)&&e.output?L(e.output,this.workspaceConfig.workspaceRoot)?e.output:w(z(this.config.output.outputPath,v(v(e.output,v(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):w(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:k(e)&&e.ignore?b(e.ignore):void 0})),e=>`${e.input}-${e.glob}-${e.output}`),this.config.plugins=(this.config.plugins??[]).filter(Boolean).reduce((e,t)=>(l(t)&&c(t,e.filter(e=>l(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=e(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=e(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(t=>e(this,t))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(t=>({...t,glob:e(this,t.glob),ignore:t.ignore?t.ignore.map(t=>e(this,t)):void 0,input:e(this,t.input),output:e(this,t.output)}))),this.#c??=await f.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=g({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},_(e??{},[`entry`]),_(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=S(b(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(l(t)&&c(t,e.filter(e=>l(e)))||e.push(t),e),[])}};export{Z as PowerlinesContext};
|
|
1
|
+
import{replacePathTokens as e}from"../../plugin-utils/paths.mjs";import{getUniqueEntries as t,resolveEntriesSync as n}from"../entry.mjs";import{createProgram as r}from"../typescript/ts-morph.mjs";import{getTsconfigFilePath as i}from"../typescript/tsconfig.mjs";import{loadUserConfigFile as a,loadWorkspaceConfig as o}from"../config-file.mjs";import{createResolver as s}from"../../internal/helpers/resolver.mjs";import{checkDedupe as c,isPlugin as l}from"../../plugin-utils/helpers.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 g from"defu";import{omit as _}from"@stryke/helpers/omit";import{replacePath as v}from"@stryke/path/replace";import{isString as y}from"@stryke/type-checks/is-string";import{toArray as b}from"@stryke/convert/to-array";import{murmurhash as x}from"@stryke/hash/murmurhash";import{getUnique as S,getUniqueBy as C}from"@stryke/helpers/get-unique";import{appendPath as w}from"@stryke/path/append";import{isSetString as T}from"@stryke/type-checks/is-set-string";import{LogLevelLabel as E}from"@storm-software/config-tools/types";import{relativeToWorkspaceRoot as D}from"@stryke/fs/get-workspace-root";import{resolvePackage as O}from"@stryke/fs/resolve";import{isSetObject as k}from"@stryke/type-checks/is-set-object";import{readJsonFile as A}from"@stryke/fs/json";import{StormJSON as j}from"@stryke/json/storm-json";import{titleCase as M}from"@stryke/string-format/title-case";import{existsSync as N}from"@stryke/fs/exists";import{getEnvPaths as P}from"@stryke/env/get-env-paths";import{hashDirectory as F}from"@stryke/hash/hash-files";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;Y(new K({keepAliveTimeout:1e4}).compose(J.retry({maxRetries:3,minTimeout:1e3,maxTimeout:1e4,timeoutFactor:2,retryAfter:!0})));var Z=class K{#e={};#t;#n=null;#r=V();#i=V();#a=Date.now();#o;#s=null;#c;#l;#u;#d;#f;#p(e={}){return g({variant:e.build?.variant,projectType:e.type,projectRoot:e.root,name:e.name,title:e.title,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 o(e,t.root));await n.withUserConfig(t);let r=await O(`powerlines`);if(!r)throw Error("Could not resolve `powerlines` package location.");return n.powerlinesPath=r,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 n(this,this.#s?this.#s:b(this.config.entry))}set entry(e){this.#s=e}get tsconfig(){return this.#l||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#l}set tsconfig(e){this.#l=e,this.resolvePatterns=U(e?.options?.paths??{})}get fs(){return this.#c||=f.createSync(this),this.#c}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:x({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:m}),configHash:x(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(){return this.#o||=P({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:this.workspaceConfig.workspaceRoot}),this.#o}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`,x({checksum:this.#n,config:this.meta.configHash},{maxLength:p}))}get dtsPath(){return this.config.output.dts?w(this.config.output.dts,this.workspaceConfig.workspaceRoot):z(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return D(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.#u||=r(this,{skipAddingFilesFromTsConfig:!0}),this.#u}get parserCache(){return this.#d||=W({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#d}get requestCache(){return this.#f||=W({cacheId:`http`,cacheDir:this.cachePath,ttl:300*1e3,lruSize:5e3,persistInterval:250}),this.#f}async fetch(e,t={}){let n=x({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=x({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 k(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:w(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,g(_(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):w(t,this.builtinsPath),e,g(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(!N(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await A(e),this.workspaceConfig.repository??=T(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(E.FATAL,y(e)?e:j.stringify(e))}error(e){this.log(E.ERROR,y(e)?e:j.stringify(e))}warn(e){this.log(E.WARN,y(e)?e:j.stringify(e))}info(e){this.log(E.INFO,y(e)?e:j.stringify(e))}debug(e){this.log(E.DEBUG,y(e)?e:j.stringify(e))}trace(e){this.log(E.TRACE,y(e)?e:j.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 F(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,this.#o=P({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot})}resolvedConfig={};logFn;async init(n={},r={isHighPriority:!0}){let o={projectRoot:n.root??this.config.projectRoot??this.config.userConfig?.root??this.config.inlineConfig?.root,mode:(n.mode??this.config.mode)||this.workspaceConfig.mode,skipCache:n.skipCache??this.config.skipCache??!1,configFile:n.configFile??this.config.configFile,framework:n.framework??this.config.framework??`powerlines`,command:this.config.inlineConfig?.command};if(X.has(o)){let e=X.get(o);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 e=z(o.projectRoot,`project.json`);N(e)&&(this.projectJson=await A(e));let t=z(o.projectRoot,`package.json`);N(t)&&(this.packageJson=await A(t)),this.#n=await this.generateChecksum(o.projectRoot),this.resolver=s({workspaceRoot:this.workspaceConfig.workspaceRoot,projectRoot:o.projectRoot,cacheDir:this.cachePath,mode:o.mode,logLevel:n.logLevel||this.config?.logLevel||this.workspaceConfig.logLevel||`info`,skipCache:o.skipCache});let r=await a(o.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,o.command,o.mode,o.configFile,o.framework);this.mergeUserConfig(r.config),X.set(o,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:r})}n.tsconfig??=i(this.workspaceConfig.workspaceRoot,o.projectRoot,n.tsconfig),k(n)&&(this.resolvedConfig=g({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},r.isHighPriority?this.#p(n):{},{command:this.config.inlineConfig?.command,...this.#p(this.config.inlineConfig)},this.#p(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||w(`src`,o.projectRoot),output:g(n.output??{},{outputPath:o.projectRoot?z(this.workspaceConfig?.directories?.build||`dist`,o.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:z(o.projectRoot,`.${n.framework??`powerlines`}`),dts:z(o.projectRoot,`${n.framework??`powerlines`}.d.ts`),builtinPrefix:n.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:o.projectRoot,glob:`*.md`},{input:o.projectRoot,glob:`package.json`}]})},r.isHighPriority?{}:this.#p(n),{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=t(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??=M(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=S(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=S(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=S(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=S(this.config.build.noExternal)),this.config.output.format=S(b(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=C(this.config.output.assets.map(e=>({glob:k(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:w(e.input,this.workspaceConfig.workspaceRoot),output:k(e)&&e.output?L(e.output,this.workspaceConfig.workspaceRoot)?e.output:w(z(this.config.output.outputPath,v(v(e.output,v(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):w(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:k(e)&&e.ignore?b(e.ignore):void 0})),e=>`${e.input}-${e.glob}-${e.output}`),this.config.plugins=(this.config.plugins??[]).filter(Boolean).reduce((e,t)=>(l(t)&&c(t,e.filter(e=>l(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=e(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=e(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(t=>e(this,t))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(t=>({...t,glob:e(this,t.glob),ignore:t.ignore?t.ignore.map(t=>e(this,t)):void 0,input:e(this,t.input),output:e(this,t.output)}))),this.#c??=await f.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=g({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},_(e??{},[`entry`]),_(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=S(b(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(l(t)&&c(t,e.filter(e=>l(e)))||e.push(t),e),[])}};export{Z as PowerlinesContext};
|
|
@@ -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/path/join-paths`),c=require(`@stryke/path/replace`),l=require(`@stryke/type-checks/is-string`),u=require(`@stryke/convert/to-array`),d=require(`@stryke/hash/murmurhash`),f=require(`@stryke/helpers/get-unique`),p=require(`@stryke/path/append`),m=require(`@stryke/type-checks/is-set-string`),h=require(`@storm-software/config-tools/types`),g=require(`@stryke/fs/resolve`),_=require(`@stryke/type-checks/is-set-object`),v=require(`@stryke/path/file-path-fns`),y=require(`@stryke/fs/exists`),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,c.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,c.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,y.existsSync)((0,s.joinPaths)(t.dataPath,`fs.bin`))){let r=await(0,w.readFileBuffer)((0,s.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,y.existsSync)((0,s.joinPaths)(t.dataPath,`fs.bin`))){let r=(0,w.readFileBufferSync)((0,s.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,_.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),{})),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,f.getUnique)(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?(0,p.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return(0,f.getUnique)((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?(0,p.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(h.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,v.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(h.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,v.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,s.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,v.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,s.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,v.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,m.isSetString)(n)&&(!(0,_.isSetObject)(n)||!(0,m.isSetString)(n.input))||!(0,m.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,m.isSetString)(n)&&n.includes(`*`)||(0,_.isSetObject)(n)&&(0,m.isSetString)(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,(0,p.appendPath)((0,c.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,m.isSetString)(n)&&(!(0,_.isSetObject)(n)||!(0,m.isSetString)(n.input))||!(0,m.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,m.isSetString)(n)&&n.includes(`*`)||(0,_.isSetObject)(n)&&(0,m.isSetString)(n.glob))this.globSync(n).map(e=>this.copySync(e,(0,p.appendPath)((0,v.findFilePath)((0,c.replacePath)(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l((0,v.hasFileExtension)(r)?r:(0,p.appendPath)((0,v.findFileName)(a),r)),e,{skipFormat:!0})}}async move(e,t){(0,v.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,v.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(h.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(h.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(h.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,u.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(h.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,u.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,d.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,p.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,p.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,p.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,g.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,g.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,p.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,p.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,p.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,g.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=(0,g.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(h.LogLevelLabel.DEBUG,`Disposing virtual file system...`),await this.remove((0,s.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).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await(0,w.writeFileBuffer)((0,s.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(h.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/path/join-paths`),c=require(`@stryke/path/replace`),l=require(`@stryke/type-checks/is-string`),u=require(`@stryke/convert/to-array`),d=require(`@stryke/hash/murmurhash`),f=require(`@stryke/helpers/get-unique`),p=require(`@stryke/path/append`),m=require(`@stryke/type-checks/is-set-string`),h=require(`@storm-software/config-tools/types`),g=require(`@stryke/fs/resolve`),_=require(`@stryke/type-checks/is-set-object`),v=require(`@stryke/path/file-path-fns`),y=require(`@stryke/fs/exists`),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,c.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,c.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,y.existsSync)((0,s.joinPaths)(t.dataPath,`fs.bin`))){let r=await(0,w.readFileBuffer)((0,s.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,y.existsSync)((0,s.joinPaths)(t.dataPath,`fs.bin`))){let r=(0,w.readFileBufferSync)((0,s.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,_.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,f.getUnique)(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?(0,p.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return(0,f.getUnique)((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?(0,p.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(h.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,v.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(h.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,v.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,s.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,v.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,s.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,v.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,m.isSetString)(n)&&(!(0,_.isSetObject)(n)||!(0,m.isSetString)(n.input))||!(0,m.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,m.isSetString)(n)&&n.includes(`*`)||(0,_.isSetObject)(n)&&(0,m.isSetString)(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,(0,p.appendPath)((0,c.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,m.isSetString)(n)&&(!(0,_.isSetObject)(n)||!(0,m.isSetString)(n.input))||!(0,m.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,m.isSetString)(n)&&n.includes(`*`)||(0,_.isSetObject)(n)&&(0,m.isSetString)(n.glob))this.globSync(n).map(e=>this.copySync(e,(0,p.appendPath)((0,v.findFilePath)((0,c.replacePath)(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l((0,v.hasFileExtension)(r)?r:(0,p.appendPath)((0,v.findFileName)(a),r)),e,{skipFormat:!0})}}async move(e,t){(0,v.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,v.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(h.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(h.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(h.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,u.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(h.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,u.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,d.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,p.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,p.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,p.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,g.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,g.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,p.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,p.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,p.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,g.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=(0,g.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(h.LogLevelLabel.DEBUG,`Disposing virtual file system...`),await this.remove((0,s.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,m.isSetString)(e)).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await(0,w.writeFileBuffer)((0,s.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(h.LogLevelLabel.TRACE,`Virtual file system has been disposed.`)}}async[Symbol.asyncDispose](){return this.dispose()}};exports.VirtualFileSystem=k;
|
|
@@ -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{joinPaths as c}from"@stryke/path/join-paths";import{replacePath as l}from"@stryke/path/replace";import{isString as u}from"@stryke/type-checks/is-string";import{toArray as d}from"@stryke/convert/to-array";import{murmurhash as f}from"@stryke/hash/murmurhash";import{getUnique as p}from"@stryke/helpers/get-unique";import{appendPath as m}from"@stryke/path/append";import{isSetString as h}from"@stryke/type-checks/is-set-string";import{LogLevelLabel as g}from"@storm-software/config-tools/types";import{getResolutionCombinations as _,resolve as v,resolveSync as y}from"@stryke/fs/resolve";import{isSetObject as b}from"@stryke/type-checks/is-set-object";import{findFileName as x,findFilePath as S,hasFileExtension as C}from"@stryke/path/file-path-fns";import{existsSync as w}from"@stryke/fs/exists";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=l(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:l(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&&w(c(e.dataPath,`fs.bin`))){let n=await k(c(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&&w(c(e.dataPath,`fs.bin`))){let n=A(c(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,b(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),{})),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 p(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?m(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return p((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?m(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(g.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);C(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(g.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);C(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(c(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?S(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(c(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?S(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(!h(n)&&(!b(n)||!h(n.input))||!h(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)||h(n)&&n.includes(`*`)||b(n)&&h(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,m(l(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(!h(n)&&(!b(n)||!h(n.input))||!h(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)||h(n)&&n.includes(`*`)||b(n)&&h(n.glob))this.globSync(n).map(e=>this.copySync(e,m(S(l(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l(C(r)?r:m(x(a),r)),e,{skipFormat:!0})}}async move(e,t){C(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){C(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(g.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(g.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(g.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(d(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(g.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(d(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=f({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(m(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(m(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=>m(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of _(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await v(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(m(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(m(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=>m(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of _(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=y(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(g.DEBUG,`Disposing virtual file system...`),await this.remove(c(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).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await j(c(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(g.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{joinPaths as c}from"@stryke/path/join-paths";import{replacePath as l}from"@stryke/path/replace";import{isString as u}from"@stryke/type-checks/is-string";import{toArray as d}from"@stryke/convert/to-array";import{murmurhash as f}from"@stryke/hash/murmurhash";import{getUnique as p}from"@stryke/helpers/get-unique";import{appendPath as m}from"@stryke/path/append";import{isSetString as h}from"@stryke/type-checks/is-set-string";import{LogLevelLabel as g}from"@storm-software/config-tools/types";import{getResolutionCombinations as _,resolve as v,resolveSync as y}from"@stryke/fs/resolve";import{isSetObject as b}from"@stryke/type-checks/is-set-object";import{findFileName as x,findFilePath as S,hasFileExtension as C}from"@stryke/path/file-path-fns";import{existsSync as w}from"@stryke/fs/exists";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=l(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:l(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&&w(c(e.dataPath,`fs.bin`))){let n=await k(c(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&&w(c(e.dataPath,`fs.bin`))){let n=A(c(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,b(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 p(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?m(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return p((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?m(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(g.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);C(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(g.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);C(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(c(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?S(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(c(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?S(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(!h(n)&&(!b(n)||!h(n.input))||!h(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)||h(n)&&n.includes(`*`)||b(n)&&h(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,m(l(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(!h(n)&&(!b(n)||!h(n.input))||!h(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)||h(n)&&n.includes(`*`)||b(n)&&h(n.glob))this.globSync(n).map(e=>this.copySync(e,m(S(l(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l(C(r)?r:m(x(a),r)),e,{skipFormat:!0})}}async move(e,t){C(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){C(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(g.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(g.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(g.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(d(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(g.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(d(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=f({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(m(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(m(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=>m(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of _(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await v(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(m(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(m(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=>m(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of _(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=y(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(g.DEBUG,`Disposing virtual file system...`),await this.remove(c(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])=>h(e)).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await j(c(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(g.TRACE,`Virtual file system has been disposed.`)}}async[Symbol.asyncDispose](){return this.dispose()}};export{L as VirtualFileSystem};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isString as e}from"@stryke/type-checks/is-string";import{isSetObject as t}from"@stryke/type-checks/is-set-object";import"@stryke/fs/read-file";
|
|
1
|
+
import{isString as e}from"@stryke/type-checks/is-string";import{isSetObject as t}from"@stryke/type-checks/is-set-object";import"@stryke/fs/read-file";function n(n){return n?e(n)?n:t(n)&&`code`in n?n.code:n.toString():``}export{n as getString};
|
|
@@ -5,10 +5,10 @@ import { TSConfig } from "./tsconfig.cjs";
|
|
|
5
5
|
import { PluginContext } from "./context.cjs";
|
|
6
6
|
import { PreviewOptions } from "vite";
|
|
7
7
|
import { MaybePromise } from "@stryke/types/base";
|
|
8
|
-
import { TypeDefinitionParameter } from "@stryke/types/configuration";
|
|
9
8
|
import { Format } from "@storm-software/build-tools/types";
|
|
10
9
|
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
11
10
|
import { StormWorkspaceConfig } from "@storm-software/config/types";
|
|
11
|
+
import { TypeDefinitionParameter } from "@stryke/types/configuration";
|
|
12
12
|
import { AssetGlob } from "@stryke/types/file";
|
|
13
13
|
|
|
14
14
|
//#region ../powerlines/src/types/config.d.ts
|
|
@@ -6,12 +6,11 @@ import { TSConfig } from "./tsconfig.mjs";
|
|
|
6
6
|
import { PluginContext } from "./context.mjs";
|
|
7
7
|
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
8
8
|
import { transformAsync } from "@babel/core";
|
|
9
|
-
import "c12";
|
|
10
9
|
import { PreviewOptions } from "vite";
|
|
11
10
|
import { MaybePromise } from "@stryke/types/base";
|
|
12
|
-
import { TypeDefinitionParameter } from "@stryke/types/configuration";
|
|
13
11
|
import { Format } from "@storm-software/build-tools/types";
|
|
14
12
|
import { StormWorkspaceConfig } from "@storm-software/config/types";
|
|
13
|
+
import { TypeDefinitionParameter } from "@stryke/types/configuration";
|
|
15
14
|
import { AssetGlob } from "@stryke/types/file";
|
|
16
15
|
|
|
17
16
|
//#region ../powerlines/src/types/config.d.ts
|
|
@@ -5,7 +5,6 @@ import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.cjs";
|
|
|
5
5
|
import { EnvPaths } from "@stryke/env/get-env-paths";
|
|
6
6
|
import { FetchRequestOptions } from "@stryke/http/fetch";
|
|
7
7
|
import { NonUndefined } from "@stryke/types/base";
|
|
8
|
-
import { TypeDefinition } from "@stryke/types/configuration";
|
|
9
8
|
import { PackageJson } from "@stryke/types/package-json";
|
|
10
9
|
import { Jiti } from "jiti";
|
|
11
10
|
import { SourceMap } from "magic-string";
|
|
@@ -50,6 +49,9 @@ interface TransformResult$1 {
|
|
|
50
49
|
code: string;
|
|
51
50
|
map: SourceMap | null;
|
|
52
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Options for initializing or updating the context with new configuration values
|
|
54
|
+
*/
|
|
53
55
|
interface InitContextOptions {
|
|
54
56
|
/**
|
|
55
57
|
* If false, the plugin will be loaded after all other plugins.
|
|
@@ -58,27 +60,28 @@ interface InitContextOptions {
|
|
|
58
60
|
*/
|
|
59
61
|
isHighPriority: boolean;
|
|
60
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Options for fetch requests made via the context's {@link Context.fetch} method
|
|
65
|
+
*/
|
|
61
66
|
interface FetchOptions extends FetchRequestOptions {
|
|
62
67
|
/**
|
|
63
68
|
* An indicator specifying that the request should bypass any caching
|
|
64
69
|
*/
|
|
65
70
|
skipCache?: boolean;
|
|
66
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Options for parsing code using [Oxc-Parser](https://github.com/oxc/oxc)
|
|
74
|
+
*/
|
|
67
75
|
interface ParseOptions extends ParserOptions {
|
|
68
76
|
/**
|
|
69
77
|
* When true this allows return statements to be outside functions to e.g. support parsing CommonJS code.
|
|
70
78
|
*/
|
|
71
79
|
allowReturnOutsideFunction?: boolean;
|
|
72
80
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
* @remarks
|
|
78
|
-
* If no value is provided, we will attempt to infer the type definition from the module's `default` export.
|
|
79
|
-
*/
|
|
80
|
-
name?: TypeDefinition["name"];
|
|
81
|
-
}
|
|
81
|
+
/**
|
|
82
|
+
* Options for emitting entry virtual files
|
|
83
|
+
*/
|
|
84
|
+
type EmitEntryOptions = WriteOptions & Omit<ResolvedEntryTypeDefinition, "file">;
|
|
82
85
|
/**
|
|
83
86
|
* The unresolved Powerlines context.
|
|
84
87
|
*
|
|
@@ -13,7 +13,6 @@ import { RequestInfo, Response } from "undici";
|
|
|
13
13
|
import { Jiti } from "jiti";
|
|
14
14
|
import { SourceMap } from "magic-string";
|
|
15
15
|
import { NonUndefined } from "@stryke/types/base";
|
|
16
|
-
import { TypeDefinition } from "@stryke/types/configuration";
|
|
17
16
|
import { PackageJson } from "@stryke/types/package-json";
|
|
18
17
|
import { Range } from "semver";
|
|
19
18
|
|
|
@@ -52,6 +51,9 @@ interface TransformResult$1 {
|
|
|
52
51
|
code: string;
|
|
53
52
|
map: SourceMap | null;
|
|
54
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Options for initializing or updating the context with new configuration values
|
|
56
|
+
*/
|
|
55
57
|
interface InitContextOptions {
|
|
56
58
|
/**
|
|
57
59
|
* If false, the plugin will be loaded after all other plugins.
|
|
@@ -60,27 +62,28 @@ interface InitContextOptions {
|
|
|
60
62
|
*/
|
|
61
63
|
isHighPriority: boolean;
|
|
62
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Options for fetch requests made via the context's {@link Context.fetch} method
|
|
67
|
+
*/
|
|
63
68
|
interface FetchOptions extends FetchRequestOptions {
|
|
64
69
|
/**
|
|
65
70
|
* An indicator specifying that the request should bypass any caching
|
|
66
71
|
*/
|
|
67
72
|
skipCache?: boolean;
|
|
68
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Options for parsing code using [Oxc-Parser](https://github.com/oxc/oxc)
|
|
76
|
+
*/
|
|
69
77
|
interface ParseOptions extends ParserOptions {
|
|
70
78
|
/**
|
|
71
79
|
* When true this allows return statements to be outside functions to e.g. support parsing CommonJS code.
|
|
72
80
|
*/
|
|
73
81
|
allowReturnOutsideFunction?: boolean;
|
|
74
82
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* @remarks
|
|
80
|
-
* If no value is provided, we will attempt to infer the type definition from the module's `default` export.
|
|
81
|
-
*/
|
|
82
|
-
name?: TypeDefinition["name"];
|
|
83
|
-
}
|
|
83
|
+
/**
|
|
84
|
+
* Options for emitting entry virtual files
|
|
85
|
+
*/
|
|
86
|
+
type EmitEntryOptions = WriteOptions & Omit<ResolvedEntryTypeDefinition, "file">;
|
|
84
87
|
/**
|
|
85
88
|
* The unresolved Powerlines context.
|
|
86
89
|
*
|
|
@@ -164,7 +164,7 @@ interface VirtualFileMetadata {
|
|
|
164
164
|
/**
|
|
165
165
|
* Additional metadata associated with the file.
|
|
166
166
|
*/
|
|
167
|
-
properties: Record<string, string>;
|
|
167
|
+
properties: Record<string, string | undefined>;
|
|
168
168
|
}
|
|
169
169
|
interface VirtualFileData {
|
|
170
170
|
/**
|
|
@@ -188,7 +188,7 @@ interface VirtualFileData {
|
|
|
188
188
|
/**
|
|
189
189
|
* Additional metadata associated with the file.
|
|
190
190
|
*/
|
|
191
|
-
properties?: Record<string, string>;
|
|
191
|
+
properties?: Record<string, string | undefined>;
|
|
192
192
|
}
|
|
193
193
|
interface VirtualFile extends Required<VirtualFileData>, VirtualFileMetadata {
|
|
194
194
|
/**
|
|
@@ -164,7 +164,7 @@ interface VirtualFileMetadata {
|
|
|
164
164
|
/**
|
|
165
165
|
* Additional metadata associated with the file.
|
|
166
166
|
*/
|
|
167
|
-
properties: Record<string, string>;
|
|
167
|
+
properties: Record<string, string | undefined>;
|
|
168
168
|
}
|
|
169
169
|
interface VirtualFileData {
|
|
170
170
|
/**
|
|
@@ -188,7 +188,7 @@ interface VirtualFileData {
|
|
|
188
188
|
/**
|
|
189
189
|
* Additional metadata associated with the file.
|
|
190
190
|
*/
|
|
191
|
-
properties?: Record<string, string>;
|
|
191
|
+
properties?: Record<string, string | undefined>;
|
|
192
192
|
}
|
|
193
193
|
interface VirtualFile extends Required<VirtualFileData>, VirtualFileMetadata {
|
|
194
194
|
/**
|
|
@@ -9,7 +9,7 @@ interface ResolvedEntryTypeDefinition extends TypeDefinition {
|
|
|
9
9
|
/**
|
|
10
10
|
* The user provided entry point in the source code
|
|
11
11
|
*/
|
|
12
|
-
input
|
|
12
|
+
input?: TypeDefinition;
|
|
13
13
|
/**
|
|
14
14
|
* An optional name to use in the package export during the build process
|
|
15
15
|
*/
|
|
@@ -10,7 +10,7 @@ interface ResolvedEntryTypeDefinition extends TypeDefinition {
|
|
|
10
10
|
/**
|
|
11
11
|
* The user provided entry point in the source code
|
|
12
12
|
*/
|
|
13
|
-
input
|
|
13
|
+
input?: TypeDefinition;
|
|
14
14
|
/**
|
|
15
15
|
* An optional name to use in the package export during the build process
|
|
16
16
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-esbuild",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.101",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing a Powerlines plugin to build projects using esbuild.",
|
|
6
6
|
"repository": {
|
|
@@ -152,14 +152,14 @@
|
|
|
152
152
|
"defu": "^6.1.4",
|
|
153
153
|
"esbuild": "^0.25.12",
|
|
154
154
|
"jiti": "^2.6.1",
|
|
155
|
-
"powerlines": "^0.
|
|
155
|
+
"powerlines": "^0.35.0",
|
|
156
156
|
"unplugin": "3.0.0-beta.3"
|
|
157
157
|
},
|
|
158
158
|
"devDependencies": {
|
|
159
|
-
"@powerlines/nx": "^0.11.
|
|
160
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
159
|
+
"@powerlines/nx": "^0.11.23",
|
|
160
|
+
"@powerlines/plugin-plugin": "^0.12.44",
|
|
161
161
|
"@types/node": "^24.10.4"
|
|
162
162
|
},
|
|
163
163
|
"publishConfig": { "access": "public" },
|
|
164
|
-
"gitHead": "
|
|
164
|
+
"gitHead": "b2222b4984e94db4850cdeda830206c8f1946395"
|
|
165
165
|
}
|