@powerlines/plugin-vite 0.14.78 → 0.14.80
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/internal/helpers/environment.cjs +1 -1
- package/dist/powerlines/src/internal/helpers/environment.mjs +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/types/config.d.cts +1 -1
- package/dist/powerlines/src/types/config.d.mts +1 -1
- package/dist/powerlines/src/types/context.d.cts +15 -3
- package/dist/powerlines/src/types/context.d.mts +15 -3
- package/dist/powerlines/src/types/fs.d.cts +2 -2
- package/dist/powerlines/src/types/fs.d.mts +2 -2
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`defu`);t=e.__toESM(t);let n=require(`@stryke/string-format/title-case`);const r=`
|
|
1
|
+
const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`defu`);t=e.__toESM(t);let n=require(`@stryke/string-format/title-case`);const r=`default`,i=`__GLOBAL__`;function a(e,r){return(0,t.default)(r.environments?.[e]??{},{name:e,title:r.title||(0,n.titleCase)(r.name),ssr:!1,mainFields:r.build?.platform===`browser`?[`browser`,`module`,`jsnext:main`,`jsnext`]:[`module`,`jsnext:main`,`jsnext`],extensions:[`.mjs`,`.js`,`.mts`,`.ts`,`.jsx`,`.tsx`,`.json`],consumer:r.build?.platform===`browser`?`client`:`server`,preview:r.build?.platform===`browser`?{port:5173,open:!0,strictPort:!1,host:`localhost`,allowedHosts:[`.`],cors:!0,headers:{}}:void 0},r)}function o(e){return a(`default`,e)}exports.GLOBAL_ENVIRONMENT=`__GLOBAL__`,exports.createDefaultEnvironment=o,exports.createEnvironment=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"defu";import{titleCase as t}from"@stryke/string-format/title-case";const n=`__GLOBAL__`;function r(n,r){return e(r.environments?.[n]??{},{name:n,title:r.title||t(r.name),ssr:!1,mainFields:r.build?.platform===`browser`?[`browser`,`module`,`jsnext:main`,`jsnext`]:[`module`,`jsnext:main`,`jsnext`],extensions:[`.mjs`,`.js`,`.mts`,`.ts`,`.jsx`,`.tsx`,`.json`],consumer:r.build?.platform===`browser`?`client`:`server`,preview:r.build?.platform===`browser`?{port:5173,open:!0,strictPort:!1,host:`localhost`,allowedHosts:[`.`],cors:!0,headers:{}}:void 0},r)}function i(e){return r(`
|
|
1
|
+
import e from"defu";import{titleCase as t}from"@stryke/string-format/title-case";const n=`__GLOBAL__`;function r(n,r){return e(r.environments?.[n]??{},{name:n,title:r.title||t(r.name),ssr:!1,mainFields:r.build?.platform===`browser`?[`browser`,`module`,`jsnext:main`,`jsnext`]:[`module`,`jsnext:main`,`jsnext`],extensions:[`.mjs`,`.js`,`.mts`,`.ts`,`.jsx`,`.tsx`,`.json`],consumer:r.build?.platform===`browser`?`client`:`server`,preview:r.build?.platform===`browser`?{port:5173,open:!0,strictPort:!1,host:`localhost`,allowedHosts:[`.`],cors:!0,headers:{}}:void 0},r)}function i(e){return r(`default`,e)}export{n as GLOBAL_ENVIRONMENT,i as createDefaultEnvironment,r as createEnvironment};
|
|
@@ -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(`@storm-software/config-tools/types`),f=require(`defu`);f=e.__toESM(f);let p=require(`@stryke/helpers/omit`),m=require(`@stryke/path/replace`),h=require(`@stryke/type-checks/is-string`),g=require(`@stryke/convert/to-array`),_=require(`@stryke/hash/murmurhash`),v=require(`@stryke/helpers/get-unique`),y=require(`@stryke/path/append`),b=require(`@stryke/type-checks/is-set-string`),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;#c;#l;#u;#d;#f(e={}){return{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}}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,(0,g.toArray)(this.config.entry))}get tsconfig(){return this.#c||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#c}set tsconfig(e){this.#c=e,this.resolvePatterns=(0,I.tsconfigPathsToRegExp)(e?.options?.paths??{})}get fs(){return this.#s||=l.VirtualFileSystem.createSync(this),this.#s}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:(0,_.murmurhash)({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:u.PROJECT_ROOT_HASH_LENGTH}),configHash:(0,_.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,_.murmurhash)({checksum:this.#n,config:this.meta.configHash},{maxLength:u.CACHE_HASH_LENGTH}))}get dtsPath(){return this.config.output.dts?(0,y.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.#l||=r.createProgram(this,{skipAddingFilesFromTsConfig:!0}),this.#l}get parserCache(){return this.#u||=(0,L.create)({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#u}get requestCache(){return this.#d||=(0,L.create)({cacheId:`http`,cacheDir:this.cachePath,ttl:300*1e3,lruSize:5e3,persistInterval:250}),this.#d}async fetch(e,t={}){let n=(0,_.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,_.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,y.appendPath)(t,this.entryPath),e,(0,f.default)(n,{type:`entry`}))}async emitBuiltin(e,t,n,r={}){return this.fs.write(n?(0,M.isAbsolute)(n)?n:(0,N.joinPaths)(this.builtinsPath,n):(0,y.appendPath)(t,this.builtinsPath),e,(0,f.default)(r,{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,b.isSetString)(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(d.LogLevelLabel.FATAL,(0,h.isString)(e)?e:T.StormJSON.stringify(e))}error(e){this.log(d.LogLevelLabel.ERROR,(0,h.isString)(e)?e:T.StormJSON.stringify(e))}warn(e){this.log(d.LogLevelLabel.WARN,(0,h.isString)(e)?e:T.StormJSON.stringify(e))}info(e){this.log(d.LogLevelLabel.INFO,(0,h.isString)(e)?e:T.StormJSON.stringify(e))}debug(e){this.log(d.LogLevelLabel.DEBUG,(0,h.isString)(e)?e:T.StormJSON.stringify(e))}trace(e){this.log(d.LogLevelLabel.TRACE,(0,h.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,f.default)({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},r.isHighPriority?this.#f(e):{},{command:this.config.inlineConfig?.command,...this.#f(this.config.inlineConfig)},this.#f(this.config.userConfig),{mode:this.workspaceConfig?.mode,logLevel:this.workspaceConfig?.logLevel,skipCache:this.workspaceConfig?.skipCache},{name:this.projectJson?.name||this.packageJson?.name,version:this.packageJson?.version,description:this.packageJson?.description,sourceRoot:this.projectJson?.sourceRoot||(0,y.appendPath)(`src`,c.projectRoot),output:(0,f.default)(e.output??{},{outputPath:c.projectRoot?(0,N.joinPaths)(this.workspaceConfig?.directories?.build||`dist`,c.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:(0,N.joinPaths)(c.projectRoot,`.${e.framework??`powerlines`}`),dts:(0,N.joinPaths)(c.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:c.projectRoot,glob:`*.md`},{input:c.projectRoot,glob:`package.json`}]})},r.isHighPriority?{}:this.#f(e),{inlineConfig:{},userConfig:{},framework:`powerlines`,platform:`neutral`,mode:`production`,projectType:`application`,logLevel:`info`,preview:!1,environments:{},transform:{babel:{plugins:[],presets:[]}},lint:{eslint:{}},build:{target:`esnext`,override:{}}})),this.config.entry=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,v.getUnique)(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=(0,v.getUnique)(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=(0,v.getUnique)(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=(0,v.getUnique)(this.config.build.noExternal)),this.config.output.format=(0,v.getUnique)((0,g.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,v.getUnique)(this.config.output.assets.map(e=>({glob:(0,C.isSetObject)(e)?e.glob:e,input:(0,h.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,y.appendPath)(e.input,this.workspaceConfig.workspaceRoot),output:(0,C.isSetObject)(e)&&e.output?(0,j.isParentPath)(e.output,this.workspaceConfig.workspaceRoot)?e.output:(0,y.appendPath)((0,N.joinPaths)(this.config.output.outputPath,(0,m.replacePath)((0,m.replacePath)(e.output,(0,m.replacePath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):(0,y.appendPath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:(0,C.isSetObject)(e)&&e.ignore?(0,g.toArray)(e.ignore):void 0}))),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.#s??=await l.VirtualFileSystem.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=(0,f.default)({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},(0,p.omit)(e??{},[`entry`]),(0,p.omit)(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=(0,v.getUnique)((0,g.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(`@storm-software/config-tools/types`),f=require(`defu`);f=e.__toESM(f);let p=require(`@stryke/helpers/omit`),m=require(`@stryke/path/replace`),h=require(`@stryke/type-checks/is-string`),g=require(`@stryke/convert/to-array`),_=require(`@stryke/hash/murmurhash`),v=require(`@stryke/helpers/get-unique`),y=require(`@stryke/path/append`),b=require(`@stryke/type-checks/is-set-string`),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;#c;#l;#u;#d;#f(e={}){return{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}}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(){let e=Object.entries(this.fs.metadata).filter(([,e])=>e&&e.type===`entry`).map(([e,t])=>({file:e,name:t?.properties?.name||`default`}));return n.resolveEntriesSync(this,e.length===0&&this.config.entry?(0,g.toArray)(this.config.entry):e)}get tsconfig(){return this.#c||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#c}set tsconfig(e){this.#c=e,this.resolvePatterns=(0,I.tsconfigPathsToRegExp)(e?.options?.paths??{})}get fs(){return this.#s||=l.VirtualFileSystem.createSync(this),this.#s}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:(0,_.murmurhash)({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:u.PROJECT_ROOT_HASH_LENGTH}),configHash:(0,_.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,_.murmurhash)({checksum:this.#n,config:this.meta.configHash},{maxLength:u.CACHE_HASH_LENGTH}))}get dtsPath(){return this.config.output.dts?(0,y.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.#l||=r.createProgram(this,{skipAddingFilesFromTsConfig:!0}),this.#l}get parserCache(){return this.#u||=(0,L.create)({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#u}get requestCache(){return this.#d||=(0,L.create)({cacheId:`http`,cacheDir:this.cachePath,ttl:300*1e3,lruSize:5e3,persistInterval:250}),this.#d}async fetch(e,t={}){let n=(0,_.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,_.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,y.appendPath)(t,this.entryPath),e,(0,f.default)((0,p.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,y.appendPath)(t,this.builtinsPath),e,(0,f.default)(r,{meta:{type:`builtin`}}))}async withUserConfig(e,t={isHighPriority:!0}){this.mergeUserConfig(e),await this.init(this.config.userConfig,t)}async withInlineConfig(e,t={isHighPriority:!0}){if(this.config.inlineConfig=e,e.command===`new`){let e=(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,`package.json`);if(!(0,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,b.isSetString)(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(d.LogLevelLabel.FATAL,(0,h.isString)(e)?e:T.StormJSON.stringify(e))}error(e){this.log(d.LogLevelLabel.ERROR,(0,h.isString)(e)?e:T.StormJSON.stringify(e))}warn(e){this.log(d.LogLevelLabel.WARN,(0,h.isString)(e)?e:T.StormJSON.stringify(e))}info(e){this.log(d.LogLevelLabel.INFO,(0,h.isString)(e)?e:T.StormJSON.stringify(e))}debug(e){this.log(d.LogLevelLabel.DEBUG,(0,h.isString)(e)?e:T.StormJSON.stringify(e))}trace(e){this.log(d.LogLevelLabel.TRACE,(0,h.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,f.default)({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},r.isHighPriority?this.#f(e):{},{command:this.config.inlineConfig?.command,...this.#f(this.config.inlineConfig)},this.#f(this.config.userConfig),{mode:this.workspaceConfig?.mode,logLevel:this.workspaceConfig?.logLevel,skipCache:this.workspaceConfig?.skipCache},{name:this.projectJson?.name||this.packageJson?.name,version:this.packageJson?.version,description:this.packageJson?.description,sourceRoot:this.projectJson?.sourceRoot||(0,y.appendPath)(`src`,c.projectRoot),output:(0,f.default)(e.output??{},{outputPath:c.projectRoot?(0,N.joinPaths)(this.workspaceConfig?.directories?.build||`dist`,c.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:(0,N.joinPaths)(c.projectRoot,`.${e.framework??`powerlines`}`),dts:(0,N.joinPaths)(c.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:c.projectRoot,glob:`*.md`},{input:c.projectRoot,glob:`package.json`}]})},r.isHighPriority?{}:this.#f(e),{inlineConfig:{},userConfig:{},framework:`powerlines`,platform:`neutral`,mode:`production`,projectType:`application`,logLevel:`info`,preview:!1,environments:{},transform:{babel:{plugins:[],presets:[]}},lint:{eslint:{}},build:{target:`esnext`,override:{}}})),this.config.entry=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,v.getUnique)(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=(0,v.getUnique)(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=(0,v.getUnique)(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=(0,v.getUnique)(this.config.build.noExternal)),this.config.output.format=(0,v.getUnique)((0,g.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,v.getUniqueBy)(this.config.output.assets.map(e=>({glob:(0,C.isSetObject)(e)?e.glob:e,input:(0,h.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,y.appendPath)(e.input,this.workspaceConfig.workspaceRoot),output:(0,C.isSetObject)(e)&&e.output?(0,j.isParentPath)(e.output,this.workspaceConfig.workspaceRoot)?e.output:(0,y.appendPath)((0,N.joinPaths)(this.config.output.outputPath,(0,m.replacePath)((0,m.replacePath)(e.output,(0,m.replacePath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):(0,y.appendPath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:(0,C.isSetObject)(e)&&e.ignore?(0,g.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.#s??=await l.VirtualFileSystem.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=(0,f.default)({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},(0,p.omit)(e??{},[`entry`]),(0,p.omit)(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=(0,v.getUnique)((0,g.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{LogLevelLabel as g}from"@storm-software/config-tools/types";import _ from"defu";import{omit as v}from"@stryke/helpers/omit";import{replacePath as y}from"@stryke/path/replace";import{isString as b}from"@stryke/type-checks/is-string";import{toArray as x}from"@stryke/convert/to-array";import{murmurhash as S}from"@stryke/hash/murmurhash";import{getUnique 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{relativeToWorkspaceRoot as E}from"@stryke/fs/get-workspace-root";import{resolvePackage as D}from"@stryke/fs/resolve";import{isSetObject as O}from"@stryke/type-checks/is-set-object";import{readJsonFile as k}from"@stryke/fs/json";import{StormJSON as A}from"@stryke/json/storm-json";import{titleCase as j}from"@stryke/string-format/title-case";import{existsSync as M}from"@stryke/fs/exists";import{getEnvPaths as N}from"@stryke/env/get-env-paths";import{hashDirectory as P}from"@stryke/hash/hash-files";import{fetchRequest as F}from"@stryke/http/fetch";import{isParentPath as I}from"@stryke/path/is-parent-path";import{isAbsolute as L}from"@stryke/path/is-type";import{joinPaths as R}from"@stryke/path/join";import{isNull as z}from"@stryke/type-checks/is-null";import{uuid as B}from"@stryke/unique-id/uuid";import{match as V,tsconfigPathsToRegExp as H}from"bundle-require";import{create as U}from"flat-cache";import{parse as W}from"oxc-parser";import{Agent as G,Response as K,interceptors as q,setGlobalDispatcher as J}from"undici";const Y=new WeakMap;J(new G({keepAliveTimeout:1e4}).compose(q.retry({maxRetries:3,minTimeout:1e3,maxTimeout:1e4,timeoutFactor:2,retryAfter:!0})));var X=class G{#e={};#t;#n=null;#r=B();#i=B();#a=Date.now();#o;#s;#c;#l;#u;#d;#f(e={}){return{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}}static async from(e,t){let n=new G(await o(e,t.root));await n.withUserConfig(t);let r=await D(`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,x(this.config.entry))}get tsconfig(){return this.#c||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#c}set tsconfig(e){this.#c=e,this.resolvePatterns=H(e?.options?.paths??{})}get fs(){return this.#s||=f.createSync(this),this.#s}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:S({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:m}),configHash:S(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||=N({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:this.workspaceConfig.workspaceRoot}),this.#o}get artifactsPath(){return R(this.workspaceConfig.workspaceRoot,this.config.projectRoot,this.config.output.artifactsPath)}get builtinsPath(){return R(this.artifactsPath,`builtins`)}get entryPath(){return R(this.artifactsPath,`entry`)}get dataPath(){return R(this.envPaths.data,`projects`,h(this.config.name,this.meta.projectRootHash))}get cachePath(){return R(this.envPaths.cache,`projects`,S({checksum:this.#n,config:this.meta.configHash},{maxLength:p}))}get dtsPath(){return this.config.output.dts?w(this.config.output.dts,this.workspaceConfig.workspaceRoot):R(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return E(this.config.projectRoot)}get builtins(){return Object.values(this.fs.metadata).filter(e=>e&&e.type===`builtin`).map(e=>e?.id).filter(Boolean)}get program(){return this.#l||=r(this,{skipAddingFilesFromTsConfig:!0}),this.#l}get parserCache(){return this.#u||=U({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#u}get requestCache(){return this.#d||=U({cacheId:`http`,cacheDir:this.cachePath,ttl:300*1e3,lruSize:5e3,persistInterval:250}),this.#d}async fetch(e,t={}){let n=S({input:e.toString(),options:JSON.stringify(t)});if(!this.config.skipCache&&!t.skipCache){let e=this.requestCache.get(n);if(e)return new K(e.body,{status:e.status,statusText:e.statusText,headers:e.headers})}let r=await F(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 K(i.body,{status:i.status,statusText:i.statusText,headers:i.headers})}async parse(e,t={}){let n=S({code:e,options:t}),r;return!this.config.skipCache&&(r=this.parserCache.get(n),r)?r:(r=await W(`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=>V(r,[e.find]));e&&(r=e.replacement)}else O(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(V(r,this.resolvePatterns)||V(r,this.config.build.noExternal))return;if(V(r,this.config.build.external)||r.startsWith(`node:`)||!/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(r))return{id:r,external:!0}}else{if(V(r,this.config.build.noExternal))return;if(V(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(L(t)?t:w(t,this.entryPath),e,_(n,{type:`entry`}))}async emitBuiltin(e,t,n,r={}){return this.fs.write(n?L(n)?n:R(this.builtinsPath,n):w(t,this.builtinsPath),e,_(r,{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=R(this.workspaceConfig.workspaceRoot,`package.json`);if(!M(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await k(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(g.FATAL,b(e)?e:A.stringify(e))}error(e){this.log(g.ERROR,b(e)?e:A.stringify(e))}warn(e){this.log(g.WARN,b(e)?e:A.stringify(e))}info(e){this.log(g.INFO,b(e)?e:A.stringify(e))}debug(e){this.log(g.DEBUG,b(e)?e:A.stringify(e))}trace(e){this.log(g.TRACE,b(e)?e:A.stringify(e))}createLog(e=null){return u(e,{...this.config,logLevel:z(this.config.logLevel)?`silent`:this.config.logLevel})}extendLog(e){return d(this.log,e)}async generateChecksum(e=this.config.projectRoot){return this.#n=await P(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,this.#o=N({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(Y.has(o)){let e=Y.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=R(o.projectRoot,`project.json`);M(e)&&(this.projectJson=await k(e));let t=R(o.projectRoot,`package.json`);M(t)&&(this.packageJson=await k(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),Y.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),O(n)&&(this.resolvedConfig=_({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},r.isHighPriority?this.#f(n):{},{command:this.config.inlineConfig?.command,...this.#f(this.config.inlineConfig)},this.#f(this.config.userConfig),{mode:this.workspaceConfig?.mode,logLevel:this.workspaceConfig?.logLevel,skipCache:this.workspaceConfig?.skipCache},{name:this.projectJson?.name||this.packageJson?.name,version:this.packageJson?.version,description:this.packageJson?.description,sourceRoot:this.projectJson?.sourceRoot||w(`src`,o.projectRoot),output:_(n.output??{},{outputPath:o.projectRoot?R(this.workspaceConfig?.directories?.build||`dist`,o.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:R(o.projectRoot,`.${n.framework??`powerlines`}`),dts:R(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.#f(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??=j(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=C(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=C(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=C(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=C(this.config.build.noExternal)),this.config.output.format=C(x(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??=R(`dist`,this.config.projectRoot),this.config.output.buildPath??=R(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:O(e)?e.glob:e,input:b(e)||!e.input||e.input===`.`||e.input===`/`||e.input===`./`?this.workspaceConfig.workspaceRoot:I(e.input,this.workspaceConfig.workspaceRoot)||e.input===this.workspaceConfig.workspaceRoot?e.input:w(e.input,this.workspaceConfig.workspaceRoot),output:O(e)&&e.output?I(e.output,this.workspaceConfig.workspaceRoot)?e.output:w(R(this.config.output.outputPath,y(y(e.output,y(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):w(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:O(e)&&e.ignore?x(e.ignore):void 0}))),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.#s??=await f.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=_({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},v(e??{},[`entry`]),v(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=C(x(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{X 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{LogLevelLabel as g}from"@storm-software/config-tools/types";import _ from"defu";import{omit as v}from"@stryke/helpers/omit";import{replacePath as y}from"@stryke/path/replace";import{isString as b}from"@stryke/type-checks/is-string";import{toArray as x}from"@stryke/convert/to-array";import{murmurhash as S}from"@stryke/hash/murmurhash";import{getUnique as C,getUniqueBy as w}from"@stryke/helpers/get-unique";import{appendPath as T}from"@stryke/path/append";import{isSetString as E}from"@stryke/type-checks/is-set-string";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;#c;#l;#u;#d;#f(e={}){return{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}}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(){let e=Object.entries(this.fs.metadata).filter(([,e])=>e&&e.type===`entry`).map(([e,t])=>({file:e,name:t?.properties?.name||`default`}));return n(this,e.length===0&&this.config.entry?x(this.config.entry):e)}get tsconfig(){return this.#c||(this.tsconfig={tsconfigFilePath:this.config.tsconfig}),this.#c}set tsconfig(e){this.#c=e,this.resolvePatterns=U(e?.options?.paths??{})}get fs(){return this.#s||=f.createSync(this),this.#s}get checksum(){return this.#n}get meta(){return{buildId:this.#r,releaseId:this.#i,checksum:this.#n,timestamp:this.#a,projectRootHash:S({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:m}),configHash:S(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`,S({checksum:this.#n,config:this.meta.configHash},{maxLength:p}))}get dtsPath(){return this.config.output.dts?T(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.#l||=r(this,{skipAddingFilesFromTsConfig:!0}),this.#l}get parserCache(){return this.#u||=W({cacheId:`parser`,cacheDir:this.cachePath,ttl:7200*1e3,lruSize:5e3,persistInterval:250}),this.#u}get requestCache(){return this.#d||=W({cacheId:`http`,cacheDir:this.cachePath,ttl:300*1e3,lruSize:5e3,persistInterval:250}),this.#d}async fetch(e,t={}){let n=S({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=S({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:T(t,this.entryPath),e,_(v(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):T(t,this.builtinsPath),e,_(r,{meta:{type:`builtin`}}))}async withUserConfig(e,t={isHighPriority:!0}){this.mergeUserConfig(e),await this.init(this.config.userConfig,t)}async withInlineConfig(e,t={isHighPriority:!0}){if(this.config.inlineConfig=e,e.command===`new`){let e=z(this.workspaceConfig.workspaceRoot,`package.json`);if(!N(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await A(e),this.workspaceConfig.repository??=E(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(g.FATAL,b(e)?e:j.stringify(e))}error(e){this.log(g.ERROR,b(e)?e:j.stringify(e))}warn(e){this.log(g.WARN,b(e)?e:j.stringify(e))}info(e){this.log(g.INFO,b(e)?e:j.stringify(e))}debug(e){this.log(g.DEBUG,b(e)?e:j.stringify(e))}trace(e){this.log(g.TRACE,b(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=_({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},r.isHighPriority?this.#f(n):{},{command:this.config.inlineConfig?.command,...this.#f(this.config.inlineConfig)},this.#f(this.config.userConfig),{mode:this.workspaceConfig?.mode,logLevel:this.workspaceConfig?.logLevel,skipCache:this.workspaceConfig?.skipCache},{name:this.projectJson?.name||this.packageJson?.name,version:this.packageJson?.version,description:this.packageJson?.description,sourceRoot:this.projectJson?.sourceRoot||T(`src`,o.projectRoot),output:_(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.#f(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=C(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=C(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=C(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=C(this.config.build.noExternal)),this.config.output.format=C(x(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=w(this.config.output.assets.map(e=>({glob:k(e)?e.glob:e,input:b(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:T(e.input,this.workspaceConfig.workspaceRoot),output:k(e)&&e.output?L(e.output,this.workspaceConfig.workspaceRoot)?e.output:T(z(this.config.output.outputPath,y(y(e.output,y(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):T(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:k(e)&&e.ignore?x(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.#s??=await f.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=_({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},v(e??{},[`entry`]),v(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=C(x(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};
|
|
@@ -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";
|
|
8
9
|
import { Format } from "@storm-software/build-tools/types";
|
|
9
10
|
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
10
11
|
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
|
|
@@ -8,9 +8,9 @@ import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
|
8
8
|
import { PreviewOptions } from "vite";
|
|
9
9
|
import { transformAsync } from "@babel/core";
|
|
10
10
|
import { MaybePromise } from "@stryke/types/base";
|
|
11
|
+
import { TypeDefinitionParameter } from "@stryke/types/configuration";
|
|
11
12
|
import { Format } from "@storm-software/build-tools/types";
|
|
12
13
|
import { StormWorkspaceConfig } from "@storm-software/config/types";
|
|
13
|
-
import { TypeDefinitionParameter } from "@stryke/types/configuration";
|
|
14
14
|
import { AssetGlob } from "@stryke/types/file";
|
|
15
15
|
|
|
16
16
|
//#region ../powerlines/src/types/config.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolveOptions, VirtualFile, VirtualFileSystemInterface } from "./fs.cjs";
|
|
1
|
+
import { ResolveOptions, VirtualFile, VirtualFileSystemInterface, WriteOptions } from "./fs.cjs";
|
|
2
2
|
import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.cjs";
|
|
3
3
|
import { Plugin } from "./plugin.cjs";
|
|
4
4
|
import { ParsedTypeScriptConfig } from "./tsconfig.cjs";
|
|
@@ -7,6 +7,7 @@ import { HookKeys, Hooks, HooksList } from "./hooks.cjs";
|
|
|
7
7
|
import { EnvPaths } from "@stryke/env/get-env-paths";
|
|
8
8
|
import { FetchRequestOptions } from "@stryke/http/fetch";
|
|
9
9
|
import { NonUndefined } from "@stryke/types/base";
|
|
10
|
+
import { TypeDefinition } from "@stryke/types/configuration";
|
|
10
11
|
import { PackageJson } from "@stryke/types/package-json";
|
|
11
12
|
import { Jiti } from "jiti";
|
|
12
13
|
import { SourceMap } from "magic-string";
|
|
@@ -74,6 +75,15 @@ interface ParseOptions extends ParserOptions {
|
|
|
74
75
|
*/
|
|
75
76
|
allowReturnOutsideFunction?: boolean;
|
|
76
77
|
}
|
|
78
|
+
interface EmitEntryOptions extends WriteOptions {
|
|
79
|
+
/**
|
|
80
|
+
* The export name of the type definition in the file being emitted
|
|
81
|
+
*
|
|
82
|
+
* @remarks
|
|
83
|
+
* If no value is provided, we will attempt to infer the type definition from the module's `default` export.
|
|
84
|
+
*/
|
|
85
|
+
name?: TypeDefinition["name"];
|
|
86
|
+
}
|
|
77
87
|
/**
|
|
78
88
|
* The unresolved Powerlines context.
|
|
79
89
|
*
|
|
@@ -290,15 +300,17 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
|
|
|
290
300
|
* @param code - The source code of the builtin file
|
|
291
301
|
* @param id - The unique identifier of the builtin file
|
|
292
302
|
* @param path - An optional path to write the builtin file to
|
|
303
|
+
* @param options - Additional options for writing the builtin file
|
|
293
304
|
*/
|
|
294
|
-
emitBuiltin: (code: string, id: string, path?: string) => Promise<void>;
|
|
305
|
+
emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
|
|
295
306
|
/**
|
|
296
307
|
* Resolves a entry virtual file and writes it to the VFS if it does not already exist
|
|
297
308
|
*
|
|
298
309
|
* @param code - The source code of the entry file
|
|
299
310
|
* @param path - An optional path to write the entry file to
|
|
311
|
+
* @param options - Additional options for writing the entry file
|
|
300
312
|
*/
|
|
301
|
-
emitEntry: (code: string, path: string) => Promise<void>;
|
|
313
|
+
emitEntry: (code: string, path: string, options?: EmitEntryOptions) => Promise<void>;
|
|
302
314
|
/**
|
|
303
315
|
* A function to update the context fields using a new user configuration options
|
|
304
316
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolveOptions, VirtualFile, VirtualFileSystemInterface } from "./fs.mjs";
|
|
1
|
+
import { ResolveOptions, VirtualFile, VirtualFileSystemInterface, WriteOptions } from "./fs.mjs";
|
|
2
2
|
import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.mjs";
|
|
3
3
|
import { Plugin } from "./plugin.mjs";
|
|
4
4
|
import { ParsedTypeScriptConfig } from "./tsconfig.mjs";
|
|
@@ -13,6 +13,7 @@ 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";
|
|
16
17
|
import { PackageJson } from "@stryke/types/package-json";
|
|
17
18
|
import { Range } from "semver";
|
|
18
19
|
|
|
@@ -74,6 +75,15 @@ interface ParseOptions extends ParserOptions {
|
|
|
74
75
|
*/
|
|
75
76
|
allowReturnOutsideFunction?: boolean;
|
|
76
77
|
}
|
|
78
|
+
interface EmitEntryOptions extends WriteOptions {
|
|
79
|
+
/**
|
|
80
|
+
* The export name of the type definition in the file being emitted
|
|
81
|
+
*
|
|
82
|
+
* @remarks
|
|
83
|
+
* If no value is provided, we will attempt to infer the type definition from the module's `default` export.
|
|
84
|
+
*/
|
|
85
|
+
name?: TypeDefinition["name"];
|
|
86
|
+
}
|
|
77
87
|
/**
|
|
78
88
|
* The unresolved Powerlines context.
|
|
79
89
|
*
|
|
@@ -290,15 +300,17 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
|
|
|
290
300
|
* @param code - The source code of the builtin file
|
|
291
301
|
* @param id - The unique identifier of the builtin file
|
|
292
302
|
* @param path - An optional path to write the builtin file to
|
|
303
|
+
* @param options - Additional options for writing the builtin file
|
|
293
304
|
*/
|
|
294
|
-
emitBuiltin: (code: string, id: string, path?: string) => Promise<void>;
|
|
305
|
+
emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
|
|
295
306
|
/**
|
|
296
307
|
* Resolves a entry virtual file and writes it to the VFS if it does not already exist
|
|
297
308
|
*
|
|
298
309
|
* @param code - The source code of the entry file
|
|
299
310
|
* @param path - An optional path to write the entry file to
|
|
311
|
+
* @param options - Additional options for writing the entry file
|
|
300
312
|
*/
|
|
301
|
-
emitEntry: (code: string, path: string) => Promise<void>;
|
|
313
|
+
emitEntry: (code: string, path: string, options?: EmitEntryOptions) => Promise<void>;
|
|
302
314
|
/**
|
|
303
315
|
* A function to update the context fields using a new user configuration options
|
|
304
316
|
*/
|
|
@@ -210,7 +210,7 @@ interface WriteOptions {
|
|
|
210
210
|
/**
|
|
211
211
|
* Additional metadata for the file.
|
|
212
212
|
*/
|
|
213
|
-
meta?: VirtualFileMetadata
|
|
213
|
+
meta?: Partial<VirtualFileMetadata>;
|
|
214
214
|
}
|
|
215
215
|
interface ResolveOptions$1 extends ResolveOptions {
|
|
216
216
|
/**
|
|
@@ -455,4 +455,4 @@ interface VirtualFileSystemInterface {
|
|
|
455
455
|
dispose: () => Promise<void>;
|
|
456
456
|
}
|
|
457
457
|
//#endregion
|
|
458
|
-
export { ResolveOptions$1 as ResolveOptions, StoragePort, StoragePreset, VirtualFile, VirtualFileSystemInterface };
|
|
458
|
+
export { ResolveOptions$1 as ResolveOptions, StoragePort, StoragePreset, VirtualFile, VirtualFileSystemInterface, WriteOptions };
|
|
@@ -210,7 +210,7 @@ interface WriteOptions {
|
|
|
210
210
|
/**
|
|
211
211
|
* Additional metadata for the file.
|
|
212
212
|
*/
|
|
213
|
-
meta?: VirtualFileMetadata
|
|
213
|
+
meta?: Partial<VirtualFileMetadata>;
|
|
214
214
|
}
|
|
215
215
|
interface ResolveOptions$1 extends ResolveOptions {
|
|
216
216
|
/**
|
|
@@ -455,4 +455,4 @@ interface VirtualFileSystemInterface {
|
|
|
455
455
|
dispose: () => Promise<void>;
|
|
456
456
|
}
|
|
457
457
|
//#endregion
|
|
458
|
-
export { ResolveOptions$1 as ResolveOptions, StoragePort, StoragePreset, VirtualFile, VirtualFileSystemInterface };
|
|
458
|
+
export { ResolveOptions$1 as ResolveOptions, StoragePort, StoragePreset, VirtualFile, VirtualFileSystemInterface, WriteOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-vite",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.80",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
|
|
6
6
|
"repository": {
|
|
@@ -152,14 +152,14 @@
|
|
|
152
152
|
"defu": "^6.1.4",
|
|
153
153
|
"jiti": "^2.6.1",
|
|
154
154
|
"vite": "8.0.0-beta.2",
|
|
155
|
-
"powerlines": "^0.
|
|
155
|
+
"powerlines": "^0.33.1"
|
|
156
156
|
},
|
|
157
157
|
"devDependencies": {
|
|
158
158
|
"vite": "8.0.0-beta.2",
|
|
159
|
-
"@powerlines/nx": "^0.11.
|
|
160
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
159
|
+
"@powerlines/nx": "^0.11.11",
|
|
160
|
+
"@powerlines/plugin-plugin": "^0.12.32",
|
|
161
161
|
"@types/node": "^24.10.4"
|
|
162
162
|
},
|
|
163
163
|
"publishConfig": { "access": "public" },
|
|
164
|
-
"gitHead": "
|
|
164
|
+
"gitHead": "62d69003529024ae533a5885904fa16dce400a57"
|
|
165
165
|
}
|