@powerlines/plugin-rspack 0.5.100 โ 0.5.102
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 +2 -2
- 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/plugin-utils/helpers.cjs +1 -1
- package/dist/powerlines/src/plugin-utils/helpers.mjs +1 -1
- package/dist/powerlines/src/types/config.d.cts +3 -3
- package/dist/powerlines/src/types/config.d.mts +3 -4
- 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,11 +1,11 @@
|
|
|
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(`@storm-software/config-tools/types`),f=require(`@stryke/path/join-paths`),p=require(`@babel/core`),m=require(`@storm-software/config-tools/logger/console`),h=require(`@stryke/convert/to-array`),g=require(`@stryke/fs/helpers`),_=require(`@stryke/fs/install`),v=require(`@stryke/fs/list-files`),y=require(`@stryke/fs/package-fns`),b=require(`@stryke/fs/resolve`),x=require(`@stryke/path/append`),S=require(`@stryke/path/replace`),C=require(`@stryke/type-checks/is-error`),w=require(`@stryke/type-checks/is-function`),T=require(`@stryke/type-checks/is-number`),E=require(`@stryke/type-checks/is-object`),D=require(`@stryke/type-checks/is-promise`),O=require(`@stryke/type-checks/is-set`),k=require(`@stryke/type-checks/is-set-object`),A=require(`@stryke/type-checks/is-set-string`),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(d.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(d.LogLevelLabel.TRACE,` ๐๏ธ Preparing the Powerlines project`),this.context.log(d.LogLevelLabel.TRACE,` โ๏ธ Aggregating configuration options for the Powerlines project`),await this.context.withInlineConfig(e),await this.#r(async e=>{if(e.log(d.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(d.LogLevelLabel.DEBUG,`The configuration provided ${(0,h.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(`@storm-software/config-tools/types`),f=require(`@stryke/path/join-paths`),p=require(`@babel/core`),m=require(`@storm-software/config-tools/logger/console`),h=require(`@stryke/convert/to-array`),g=require(`@stryke/fs/helpers`),_=require(`@stryke/fs/install`),v=require(`@stryke/fs/list-files`),y=require(`@stryke/fs/package-fns`),b=require(`@stryke/fs/resolve`),x=require(`@stryke/path/append`),S=require(`@stryke/path/replace`),C=require(`@stryke/type-checks/is-error`),w=require(`@stryke/type-checks/is-function`),T=require(`@stryke/type-checks/is-number`),E=require(`@stryke/type-checks/is-object`),D=require(`@stryke/type-checks/is-promise`),O=require(`@stryke/type-checks/is-set`),k=require(`@stryke/type-checks/is-set-object`),A=require(`@stryke/type-checks/is-set-string`),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(d.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(d.LogLevelLabel.TRACE,` ๐๏ธ Preparing the Powerlines project`),this.context.log(d.LogLevelLabel.TRACE,` โ๏ธ Aggregating configuration options for the Powerlines project`),await this.context.withInlineConfig(e),await this.#r(async e=>{if(e.log(d.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(d.LogLevelLabel.DEBUG,`The configuration provided ${(0,h.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(d.LogLevelLabel.TRACE,`Powerlines configuration has been resolved: \n\n${(0,m.formatLogMessage)(e.config)}`),e.fs.existsSync(e.cachePath)||await(0,g.createDirectory)(e.cachePath),e.fs.existsSync(e.dataPath)||await(0,g.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(d.LogLevelLabel.TRACE,`Preparing the TypeScript definitions for the Powerlines project.`),e.fs.existsSync(e.dtsPath)&&await e.fs.remove(e.dtsPath),e.log(d.LogLevelLabel.TRACE,`Transforming built-ins runtime modules files.`);let r=await Promise.all((await e.getBuiltins()).map(async n=>{let r=await(0,p.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(d.LogLevelLabel.TRACE,`Writing transformed built-in runtime file ${n.id}.`),await e.emitBuiltin(r.code,n.id,n.path),n.path}));if(!await(0,b.resolvePackage)(`typescript`))throw Error(`Could not resolve TypeScript package location. Please ensure TypeScript is installed.`);let i=r.reduce((t,n)=>{let r=(0,S.replacePath)(n,e.workspaceConfig.workspaceRoot);return t.includes(r)||t.push(r),t},[]);e.log(d.LogLevelLabel.TRACE,`Parsing TypeScript configuration for the Powerlines project.`);let s=await n.emitTypes(e,i);e.log(d.LogLevelLabel.TRACE,`Generating TypeScript declaration file ${e.dtsPath}.`);let c=[],l=e=>(0,E.isObject)(e)?e.code:e,f=await this.callHook(`types`,{environment:e,sequential:!0,order:`pre`,result:`merge`,asNextParam:l},s);if(f&&((0,k.isSetObject)(f)?(s=f.code,Array.isArray(f.directives)&&f.directives.length>0&&c.push(...f.directives)):(0,A.isSetString)(f)&&(s=f)),f=await this.callHook(`types`,{environment:e,sequential:!0,order:`normal`,result:`merge`,asNextParam:l},s),f&&((0,k.isSetObject)(f)?(s=f.code,Array.isArray(f.directives)&&f.directives.length>0&&c.push(...f.directives)):(0,A.isSetString)(f)&&(s=f)),f=await this.callHook(`types`,{environment:e,sequential:!0,order:`post`,result:`merge`,asNextParam:l},s),f&&((0,k.isSetObject)(f)?(s=f.code,Array.isArray(f.directives)&&f.directives.length>0&&c.push(...f.directives)):(0,A.isSetString)(f)&&(s=f)),s?.trim()||c.length>0)await e.fs.write(e.dtsPath,`${c?`${c.map(e=>`/// <reference types="${e}" />`).join(`
|
|
3
3
|
`)}
|
|
4
4
|
|
|
5
5
|
`:``}${u.getFileHeader(e,{directive:null,prettierIgnore:!1})}
|
|
6
6
|
|
|
7
7
|
${n.formatTypes(s)}
|
|
8
|
-
`);else{let t=o.getTsconfigDtsPath(e);if(e.tsconfig.tsconfigJson.include&&a.isIncludeMatchFound(t,e.tsconfig.tsconfigJson.include)){let n=t.startsWith(`./`)?t.slice(2):t;e.tsconfig.tsconfigJson.include=e.tsconfig.tsconfigJson.include.filter(e=>e?.toString()!==n),await e.fs.write(e.tsconfig.tsconfigFilePath,JSON.stringify(e.tsconfig.tsconfigJson,null,2))}}}if(e.tsconfig=a.getParsedTypeScriptConfig(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig),!e.tsconfig)throw Error(`Failed to parse the TypeScript configuration file.`);await this.callHook(`prepare`,{environment:e,order:`post`}),await c.writeMetaFile(e),e.persistedMeta=e.meta}),this.context.log(d.LogLevelLabel.INFO,`Powerlines API has been prepared successfully`)}async new(e){this.context.log(d.LogLevelLabel.INFO,`๐ Creating a new Powerlines project`),await this.prepare(e),await this.#r(async e=>{e.log(d.LogLevelLabel.TRACE,`Initializing the processing options for the Powerlines project.`),await this.callHook(`new`,{environment:e,order:`pre`});let t=await(0,v.listFiles)((0,f.joinPaths)(e.powerlinesPath,`files/common/**/*.hbs`));for(let n of t){e.log(d.LogLevelLabel.TRACE,`Adding template file: ${n}`);let t=M.default.compile(n);await e.fs.write((0,f.joinPaths)(e.config.projectRoot,n.replace(`.hbs`,``)),t(e))}if(await this.callHook(`new`,{environment:e,order:`normal`}),e.config.projectType===`application`){let t=await(0,v.listFiles)((0,f.joinPaths)(e.powerlinesPath,`files/application/**/*.hbs`));for(let n of t){e.log(d.LogLevelLabel.TRACE,`Adding application template file: ${n}`);let t=M.default.compile(n);await e.fs.write((0,f.joinPaths)(e.config.projectRoot,n.replace(`.hbs`,``)),t(e))}}else{let t=await(0,v.listFiles)((0,f.joinPaths)(e.powerlinesPath,`files/library/**/*.hbs`));for(let n of t){e.log(d.LogLevelLabel.TRACE,`Adding library template file: ${n}`);let t=M.default.compile(n);await e.fs.write((0,f.joinPaths)(e.config.projectRoot,n.replace(`.hbs`,``)),t(e))}}await this.callHook(`new`,{environment:e,order:`post`})}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines - New command completed`)}async clean(e={command:`clean`}){this.context.log(d.LogLevelLabel.INFO,`๐งน Cleaning the previous Powerlines artifacts`),await this.prepare(e),await this.#r(async e=>{this.context.log(d.LogLevelLabel.TRACE,`Cleaning the project's dist and artifacts directories.`),await e.fs.remove((0,f.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.output.buildPath)),await e.fs.remove((0,f.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.output.artifactsPath)),await this.callHook(`clean`,{environment:e,sequential:!1})}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines - Clean command completed`)}async lint(e={command:`lint`}){this.context.log(d.LogLevelLabel.INFO,`๐ Linting the Powerlines project`),await this.prepare(e),await this.#r(async e=>{e.config.lint!==!1&&await this.callHook(`lint`,{environment:e,sequential:!1})}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines linting completed`)}async build(e={command:`build`}){this.context.log(d.LogLevelLabel.INFO,`๐ฆ Building the Powerlines project`),await this.prepare(e),this.context.config.singleBuild?await this.#t(await this.#e.toEnvironment()):await this.#r(async e=>{await this.#t(e)}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines build completed`)}async docs(e={command:`docs`}){this.context.log(d.LogLevelLabel.INFO,`๐ Generating documentation for the Powerlines project`),await this.prepare(e),await this.#r(async t=>{t.log(d.LogLevelLabel.TRACE,`Writing documentation for the Powerlines project artifacts.`),await this.prepare(e),await this.#r(async e=>{await this.callHook(`docs`,{environment:e})})}),this.#e.log(d.LogLevelLabel.TRACE,`Powerlines documentation generation completed`)}async deploy(e={command:`deploy`}){this.context.log(d.LogLevelLabel.INFO,`๐ฆ Deploying the Powerlines project`),await this.prepare(e),await this.#r(async e=>{await this.callHook(`deploy`,{environment:e})}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines deploy completed`)}async finalize(){this.context.log(d.LogLevelLabel.TRACE,`Powerlines finalize execution started`),await this.#r(async e=>{await this.callHook(`finalize`,{environment:e}),await e.fs.dispose()}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines finalize execution completed`)}async callHook(e,t,...n){return r.callHook((0,k.isSetObject)(t?.environment)?t.environment:await this.#e.getEnvironment(t?.environment),e,{sequential:!0,...t},...n)}async[Symbol.asyncDispose](){await this.finalize()}async#t(e){if(await this.callHook(`build`,{environment:e,order:`pre`}),await this.callHook(`build`,{environment:e,order:`normal`}),e.config.output.buildPath!==e.config.output.outputPath){let t=(0,x.appendPath)(e.config.output.buildPath,e.workspaceConfig.workspaceRoot),n=(0,f.joinPaths)((0,x.appendPath)(e.config.output.outputPath,e.workspaceConfig.workspaceRoot),`dist`);e.fs.existsSync(t)&&t!==n&&(e.log(d.LogLevelLabel.INFO,`Copying build output files from project's build directory (${e.config.output.buildPath}) to the workspace's output directory (${e.config.output.outputPath}).`),await e.fs.copy(t,n))}await Promise.all(e.config.output.assets.map(async t=>{e.log(d.LogLevelLabel.DEBUG,`Copying asset(s): ${j.default.redBright(e.workspaceConfig.workspaceRoot===t.input?t.glob:(0,f.joinPaths)((0,S.replacePath)(t.input,e.workspaceConfig.workspaceRoot),t.glob))} -> ${j.default.greenBright((0,f.joinPaths)((0,S.replacePath)(t.output,e.workspaceConfig.workspaceRoot),t.glob))} ${Array.isArray(t.ignore)&&t.ignore.length>0?` (ignoring: ${t.ignore.map(e=>j.default.yellowBright(e)).join(`, `)})`:``}`),await e.fs.copy(t,t.output)})),await this.callHook(`build`,{environment:e,order:`post`})}async#n(){return!this.context.config.environments||Object.keys(this.context.config.environments).length<=1?(this.context.log(d.LogLevelLabel.DEBUG,`No environments are configured for this Powerlines project. Using the default environment.`),[await this.context.getEnvironment()]):(this.context.log(d.LogLevelLabel.DEBUG,`Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`),(await Promise.all(Object.entries(this.context.config.environments).map(async([e,t])=>{if(!await this.context.getEnvironmentSafe(e)){let n=await this.callHook(`configEnvironment`,{environment:e},e,t);n&&(this.context.environments[e]=await this.context.in(n))}return this.context.environments[e]}))).filter(e=>(0,O.isSet)(e)))}async#r(e){await Promise.all((await this.#n()).map(async t=>Promise.resolve(e(t))))}async#i(e){if(e){let t=await this.#a(e);if(!t)return;if(
|
|
8
|
+
`);else{let t=o.getTsconfigDtsPath(e);if(e.tsconfig.tsconfigJson.include&&a.isIncludeMatchFound(t,e.tsconfig.tsconfigJson.include)){let n=t.startsWith(`./`)?t.slice(2):t;e.tsconfig.tsconfigJson.include=e.tsconfig.tsconfigJson.include.filter(e=>e?.toString()!==n),await e.fs.write(e.tsconfig.tsconfigFilePath,JSON.stringify(e.tsconfig.tsconfigJson,null,2))}}}if(e.tsconfig=a.getParsedTypeScriptConfig(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig),!e.tsconfig)throw Error(`Failed to parse the TypeScript configuration file.`);await this.callHook(`prepare`,{environment:e,order:`post`}),await c.writeMetaFile(e),e.persistedMeta=e.meta}),this.context.log(d.LogLevelLabel.INFO,`Powerlines API has been prepared successfully`)}async new(e){this.context.log(d.LogLevelLabel.INFO,`๐ Creating a new Powerlines project`),await this.prepare(e),await this.#r(async e=>{e.log(d.LogLevelLabel.TRACE,`Initializing the processing options for the Powerlines project.`),await this.callHook(`new`,{environment:e,order:`pre`});let t=await(0,v.listFiles)((0,f.joinPaths)(e.powerlinesPath,`files/common/**/*.hbs`));for(let n of t){e.log(d.LogLevelLabel.TRACE,`Adding template file: ${n}`);let t=M.default.compile(n);await e.fs.write((0,f.joinPaths)(e.config.projectRoot,n.replace(`.hbs`,``)),t(e))}if(await this.callHook(`new`,{environment:e,order:`normal`}),e.config.projectType===`application`){let t=await(0,v.listFiles)((0,f.joinPaths)(e.powerlinesPath,`files/application/**/*.hbs`));for(let n of t){e.log(d.LogLevelLabel.TRACE,`Adding application template file: ${n}`);let t=M.default.compile(n);await e.fs.write((0,f.joinPaths)(e.config.projectRoot,n.replace(`.hbs`,``)),t(e))}}else{let t=await(0,v.listFiles)((0,f.joinPaths)(e.powerlinesPath,`files/library/**/*.hbs`));for(let n of t){e.log(d.LogLevelLabel.TRACE,`Adding library template file: ${n}`);let t=M.default.compile(n);await e.fs.write((0,f.joinPaths)(e.config.projectRoot,n.replace(`.hbs`,``)),t(e))}}await this.callHook(`new`,{environment:e,order:`post`})}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines - New command completed`)}async clean(e={command:`clean`}){this.context.log(d.LogLevelLabel.INFO,`๐งน Cleaning the previous Powerlines artifacts`),await this.prepare(e),await this.#r(async e=>{this.context.log(d.LogLevelLabel.TRACE,`Cleaning the project's dist and artifacts directories.`),await e.fs.remove((0,f.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.output.buildPath)),await e.fs.remove((0,f.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.output.artifactsPath)),await this.callHook(`clean`,{environment:e,sequential:!1})}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines - Clean command completed`)}async lint(e={command:`lint`}){this.context.log(d.LogLevelLabel.INFO,`๐ Linting the Powerlines project`),await this.prepare(e),await this.#r(async e=>{e.config.lint!==!1&&await this.callHook(`lint`,{environment:e,sequential:!1})}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines linting completed`)}async build(e={command:`build`}){this.context.log(d.LogLevelLabel.INFO,`๐ฆ Building the Powerlines project`),await this.prepare(e),this.context.config.singleBuild?await this.#t(await this.#e.toEnvironment()):await this.#r(async e=>{await this.#t(e)}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines build completed`)}async docs(e={command:`docs`}){this.context.log(d.LogLevelLabel.INFO,`๐ Generating documentation for the Powerlines project`),await this.prepare(e),await this.#r(async t=>{t.log(d.LogLevelLabel.TRACE,`Writing documentation for the Powerlines project artifacts.`),await this.prepare(e),await this.#r(async e=>{await this.callHook(`docs`,{environment:e})})}),this.#e.log(d.LogLevelLabel.TRACE,`Powerlines documentation generation completed`)}async deploy(e={command:`deploy`}){this.context.log(d.LogLevelLabel.INFO,`๐ฆ Deploying the Powerlines project`),await this.prepare(e),await this.#r(async e=>{await this.callHook(`deploy`,{environment:e})}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines deploy completed`)}async finalize(){this.context.log(d.LogLevelLabel.TRACE,`Powerlines finalize execution started`),await this.#r(async e=>{await this.callHook(`finalize`,{environment:e}),await e.fs.dispose()}),this.context.log(d.LogLevelLabel.TRACE,`Powerlines finalize execution completed`)}async callHook(e,t,...n){return r.callHook((0,k.isSetObject)(t?.environment)?t.environment:await this.#e.getEnvironment(t?.environment),e,{sequential:!0,...t},...n)}async[Symbol.asyncDispose](){await this.finalize()}async#t(e){if(await this.callHook(`build`,{environment:e,order:`pre`}),await this.callHook(`build`,{environment:e,order:`normal`}),e.config.output.buildPath!==e.config.output.outputPath){let t=(0,x.appendPath)(e.config.output.buildPath,e.workspaceConfig.workspaceRoot),n=(0,f.joinPaths)((0,x.appendPath)(e.config.output.outputPath,e.workspaceConfig.workspaceRoot),`dist`);e.fs.existsSync(t)&&t!==n&&(e.log(d.LogLevelLabel.INFO,`Copying build output files from project's build directory (${e.config.output.buildPath}) to the workspace's output directory (${e.config.output.outputPath}).`),await e.fs.copy(t,n))}await Promise.all(e.config.output.assets.map(async t=>{e.log(d.LogLevelLabel.DEBUG,`Copying asset(s): ${j.default.redBright(e.workspaceConfig.workspaceRoot===t.input?t.glob:(0,f.joinPaths)((0,S.replacePath)(t.input,e.workspaceConfig.workspaceRoot),t.glob))} -> ${j.default.greenBright((0,f.joinPaths)((0,S.replacePath)(t.output,e.workspaceConfig.workspaceRoot),t.glob))} ${Array.isArray(t.ignore)&&t.ignore.length>0?` (ignoring: ${t.ignore.map(e=>j.default.yellowBright(e)).join(`, `)})`:``}`),await e.fs.copy(t,t.output)})),await this.callHook(`build`,{environment:e,order:`post`})}async#n(){return!this.context.config.environments||Object.keys(this.context.config.environments).length<=1?(this.context.log(d.LogLevelLabel.DEBUG,`No environments are configured for this Powerlines project. Using the default environment.`),[await this.context.getEnvironment()]):(this.context.log(d.LogLevelLabel.DEBUG,`Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`),(await Promise.all(Object.entries(this.context.config.environments).map(async([e,t])=>{if(!await this.context.getEnvironmentSafe(e)){let n=await this.callHook(`configEnvironment`,{environment:e},e,t);n&&(this.context.environments[e]=await this.context.in(n))}return this.context.environments[e]}))).filter(e=>(0,O.isSet)(e)))}async#r(e){await Promise.all((await this.#n()).map(async t=>Promise.resolve(e(t))))}async#i(e){if(e){let t=await this.#a(e);if(!t)return;for(let e of t){if(e.dependsOn)for(let t of e.dependsOn)await this.#i(t);this.context.log(d.LogLevelLabel.DEBUG,`Successfully initialized the ${j.default.bold.cyanBright(e.name)} plugin`),await this.context.addPlugin(e)}}}async#a(e){let t=e;if((0,D.isPromiseLike)(e)&&(t=await Promise.resolve(e)),!s.isPluginConfig(t))throw Error(`Invalid plugin specified in the configuration - ${JSON.stringify(t)}. Please ensure the value is a plugin name, an object with the \`plugin\` and \`props\` properties, or an instance of \`Plugin\`.`);let n;if(Array.isArray(t)&&t.every(s.isPlugin))n=t;else if(s.isPlugin(t))n=[t];else if((0,w.isFunction)(t))n=(0,h.toArray)(await Promise.resolve(t()));else if((0,A.isSetString)(t)){let e=await this.#o(t);n=(0,w.isFunction)(e)?(0,h.toArray)(await Promise.resolve(e())):(0,h.toArray)(e)}else if(s.isPluginConfigTuple(t)||s.isPluginConfigObject(t)){let e,r;if(s.isPluginConfigTuple(t)?(e=t[0],r=t?.length===2?t[1]:void 0):(e=t.plugin,r=t.options),(0,A.isSetString)(e)){let t=await this.#o(e);n=(0,w.isFunction)(t)?(0,h.toArray)(await Promise.resolve(r?t(r):t())):(0,h.toArray)(t)}else (0,w.isFunction)(e)?n=(0,h.toArray)(await Promise.resolve(e(r))):Array.isArray(e)&&e.every(s.isPlugin)?n=e:s.isPlugin(e)&&(n=(0,h.toArray)(e))}if(!n)throw Error(`The plugin configuration ${JSON.stringify(t)} is invalid. This configuration must point to a valid Powerlines plugin module.`);if(n.length>0&&!n.every(s.isPlugin))throw Error(`The plugin option ${JSON.stringify(n)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);for(let e of n){if(s.checkDedupe(e,this.context.plugins))return this.context.log(d.LogLevelLabel.TRACE,`Duplicate ${j.default.bold.cyanBright(e.name)} plugin dependency detected - Skipping initialization.`),null;this.context.log(d.LogLevelLabel.TRACE,`Initializing the ${j.default.bold.cyanBright(e.name)} plugin...`)}return n}async#o(e){if(e.startsWith(`@`)&&e.split(`/`).filter(Boolean).length>2){let t=e.split(`/`).filter(Boolean);e=`${t[0]}/${t[1]}`}let t=(0,y.isPackageExists)(e,{paths:[this.context.workspaceConfig.workspaceRoot,this.context.config.projectRoot]});if(!t&&this.context.config.skipInstalls!==!0){this.#e.log(d.LogLevelLabel.WARN,`The plugin package "${e}" is not installed. It will be installed automatically.`);let t=await(0,_.install)(e,{cwd:this.context.config.projectRoot});if((0,T.isNumber)(t.exitCode)&&t.exitCode>0)throw this.#e.log(d.LogLevelLabel.ERROR,t.stderr),Error(`An error occurred while installing the build plugin package "${e}" `)}try{let t=await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve((0,f.joinPaths)(e,`plugin`))),n=t.plugin??t.default;if(!n)throw Error(`The plugin package "${e}" does not export a valid module.`);return n}catch(n){try{let t=await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(e)),n=t.plugin??t.default;if(!n)throw Error(`The plugin package "${e}" does not export a valid module.`);return n}catch{throw t?Error(`An error occurred while importing the build plugin package "${e}":
|
|
9
9
|
${(0,C.isError)(n)?n.message:String(n)}
|
|
10
10
|
|
|
11
11
|
Note: Please ensure the plugin package's default export is a class that extends \`Plugin\` with a constructor that excepts a single arguments of type \`PluginOptions\`.`):Error(`The plugin package "${e}" is not installed. Please install the package using the command: "npm install ${e} --save-dev"`)}}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../typescript/ts-morph.cjs`),n=require(`../typescript/tsconfig.cjs`),r=require(`../config-file.cjs`),i=require(`../../internal/helpers/resolver.cjs`),a=require(`../../plugin-utils/helpers.cjs`),o=require(`../../plugin-utils/paths.cjs`),s=require(`../entry.cjs`),c=require(`../logger.cjs`),l=require(`../fs/vfs.cjs`),u=require(`../utilities/meta.cjs`);let d=require(`@storm-software/config-tools/types`),f=require(`defu`);f=e.__toESM(f);let p=require(`@stryke/helpers/omit`),m=require(`@stryke/fs/get-workspace-root`),h=require(`@stryke/convert/to-array`),g=require(`@stryke/fs/resolve`),_=require(`@stryke/path/append`),v=require(`@stryke/path/replace`),y=require(`@stryke/type-checks/is-set-object`),b=require(`@stryke/type-checks/is-set-string`),x=require(`@stryke/type-checks/is-string`),S=require(`@stryke/fs/json`),C=require(`@stryke/json/storm-json`),w=require(`@stryke/string-format/title-case`),T=require(`@stryke/fs/exists`),E=require(`@stryke/env/get-env-paths`),D=require(`@stryke/hash/hash-files`),O=require(`@stryke/hash/murmurhash`),k=require(`@stryke/helpers/get-unique`),A=require(`@stryke/http/fetch`),j=require(`@stryke/path/is-parent-path`),M=require(`@stryke/path/is-type`),N=require(`@stryke/path/join`),P=require(`@stryke/type-checks/is-null`),F=require(`@stryke/unique-id/uuid`),I=require(`bundle-require`),L=require(`flat-cache`),R=require(`oxc-parser`),z=require(`undici`);const B=new WeakMap;(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,f.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 i=new e(await r.loadWorkspaceConfig(t,n.root));await i.withUserConfig(n);let a=await(0,g.resolvePackage)(`powerlines`);if(!a)throw Error("Could not resolve `powerlines` package location.");return i.powerlinesPath=a,i}dependencies={};devDependencies={};persistedMeta=void 0;powerlinesPath;packageJson;projectJson=void 0;resolver;resolvePatterns=[];get $$internal(){return this.#e}set $$internal(e){this.#e=e}get entry(){return s.resolveEntriesSync(this,this.#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,O.murmurhash)({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:u.PROJECT_ROOT_HASH_LENGTH}),configHash:(0,O.murmurhash)(this.config,{maxLength:u.CACHE_HASH_LENGTH})}}get config(){return this.resolvedConfig??{}}get log(){return this.logFn||=this.createLog(),this.logFn}get workspaceConfig(){return this.#t}get envPaths(){return this.#o||=(0,E.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,O.murmurhash)({checksum:this.#n,config:this.meta.configHash},{maxLength:u.CACHE_HASH_LENGTH}))}get dtsPath(){return this.config.output.dts?(0,_.appendPath)(this.config.output.dts,this.workspaceConfig.workspaceRoot):(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return(0,m.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||=t.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,O.murmurhash)({input:e.toString(),options:JSON.stringify(t)});if(!this.config.skipCache&&!t.skipCache){let e=this.requestCache.get(n);if(e)return new z.Response(e.body,{status:e.status,statusText:e.statusText,headers:e.headers})}let r=await(0,A.fetchRequest)(e,{timeout:12e3,...t}),i={body:await r.text(),status:r.status,statusText:r.statusText,headers:Object.fromEntries(r.headers.entries())};if(!this.config.skipCache&&!t.skipCache)try{this.requestCache.set(n,i)}catch{}return new z.Response(i.body,{status:i.status,statusText:i.statusText,headers:i.headers})}async parse(e,t={}){let n=(0,O.murmurhash)({code:e,options:t}),r;return!this.config.skipCache&&(r=this.parserCache.get(n),r)?r:(r=await(0,R.parse)(`source.${t.lang||`ts`}`,e,{...t,sourceType:`module`,showSemanticErrors:this.config.mode===`development`}),this.config.skipCache||this.parserCache.set(n,r),r)}async resolve(e,t,n={}){let r=e;if(this.config.build.alias)if(Array.isArray(this.config.build.alias)){let e=this.config.build.alias.find(e=>(0,I.match)(r,[e.find]));e&&(r=e.replacement)}else (0,y.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,_.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,_.appendPath)(t,this.builtinsPath),e,(0,f.default)(r,{meta:{type:`builtin`}}))}async withUserConfig(e,t={isHighPriority:!0}){this.mergeUserConfig(e),await this.init(this.config.userConfig,t)}async withInlineConfig(e,t={isHighPriority:!0}){if(this.config.inlineConfig=e,e.command===`new`){let e=(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,`package.json`);if(!(0,T.existsSync)(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await(0,S.readJsonFile)(e),this.workspaceConfig.repository??=(0,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,x.isString)(e)?e:C.StormJSON.stringify(e))}error(e){this.log(d.LogLevelLabel.ERROR,(0,x.isString)(e)?e:C.StormJSON.stringify(e))}warn(e){this.log(d.LogLevelLabel.WARN,(0,x.isString)(e)?e:C.StormJSON.stringify(e))}info(e){this.log(d.LogLevelLabel.INFO,(0,x.isString)(e)?e:C.StormJSON.stringify(e))}debug(e){this.log(d.LogLevelLabel.DEBUG,(0,x.isString)(e)?e:C.StormJSON.stringify(e))}trace(e){this.log(d.LogLevelLabel.TRACE,(0,x.isString)(e)?e:C.StormJSON.stringify(e))}createLog(e=null){return c.createLog(e,{...this.config,logLevel:(0,P.isNull)(this.config.logLevel)?`silent`:this.config.logLevel})}extendLog(e){return c.extendLog(this.log,e)}async generateChecksum(e=this.config.projectRoot){return this.#n=await(0,D.hashDirectory)(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,this.#o=(0,E.getEnvPaths)({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot})}resolvedConfig={};logFn;async init(e={},t={isHighPriority:!0}){let c={projectRoot:e.root??this.config.projectRoot??this.config.userConfig?.root??this.config.inlineConfig?.root,mode:(e.mode??this.config.mode)||this.workspaceConfig.mode,skipCache:e.skipCache??this.config.skipCache??!1,configFile:e.configFile??this.config.configFile,framework:e.framework??this.config.framework??`powerlines`,command:this.config.inlineConfig?.command};if(B.has(c)){let e=B.get(c);this.projectJson=e.projectJson,this.packageJson=e.packageJson,this.#n=e.checksum,this.resolver=e.resolver,this.mergeUserConfig(e.userConfig.config,this.config.userConfig)}else{let t=(0,N.joinPaths)(c.projectRoot,`project.json`);(0,T.existsSync)(t)&&(this.projectJson=await(0,S.readJsonFile)(t));let n=(0,N.joinPaths)(c.projectRoot,`package.json`);(0,T.existsSync)(n)&&(this.packageJson=await(0,S.readJsonFile)(n)),this.#n=await this.generateChecksum(c.projectRoot),this.resolver=i.createResolver({workspaceRoot:this.workspaceConfig.workspaceRoot,projectRoot:c.projectRoot,cacheDir:this.cachePath,mode:c.mode,logLevel:e.logLevel||this.config?.logLevel||this.workspaceConfig.logLevel||`info`,skipCache:c.skipCache});let a=await r.loadUserConfigFile(c.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,c.command,c.mode,c.configFile,c.framework);this.mergeUserConfig(a.config),B.set(c,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:a})}e.tsconfig??=n.getTsconfigFilePath(this.workspaceConfig.workspaceRoot,c.projectRoot,e.tsconfig),(0,y.isSetObject)(e)&&(this.resolvedConfig=(0,f.default)({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},t.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,_.appendPath)(`src`,c.projectRoot),output:(0,f.default)(e.output??{},{outputPath:c.projectRoot?(0,N.joinPaths)(this.workspaceConfig?.directories?.build||`dist`,c.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:(0,N.joinPaths)(c.projectRoot,`.${e.framework??`powerlines`}`),dts:(0,N.joinPaths)(c.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:c.projectRoot,glob:`*.md`},{input:c.projectRoot,glob:`package.json`}]})},t.isHighPriority?{}:this.#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=s.getUniqueEntries(this.config.entry),this.config.name?.startsWith(`@`)&&this.config.name.split(`/`).filter(Boolean).length>1&&(this.config.name=this.config.name.split(`/`).filter(Boolean)[1]),this.config.title??=(0,w.titleCase)(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=(0,k.getUnique)(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=(0,k.getUnique)(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=(0,k.getUnique)(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=(0,k.getUnique)(this.config.build.noExternal)),this.config.output.format=(0,k.getUnique)((0,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,k.getUniqueBy)(this.config.output.assets.map(e=>({glob:(0,y.isSetObject)(e)?e.glob:e,input:(0,x.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,_.appendPath)(e.input,this.workspaceConfig.workspaceRoot),output:(0,y.isSetObject)(e)&&e.output?(0,j.isParentPath)(e.output,this.workspaceConfig.workspaceRoot)?e.output:(0,_.appendPath)((0,N.joinPaths)(this.config.output.outputPath,(0,v.replacePath)((0,v.replacePath)(e.output,(0,v.replacePath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):(0,_.appendPath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:(0,y.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)=>(a.isPlugin(t)&&a.checkDedupe(t,e.filter(e=>a.isPlugin(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=o.replacePathTokens(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=o.replacePathTokens(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(e=>o.replacePathTokens(this,e))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(e=>({...e,glob:o.replacePathTokens(this,e.glob),ignore:e.ignore?e.ignore.map(e=>o.replacePathTokens(this,e)):void 0,input:o.replacePathTokens(this,e.input),output:o.replacePathTokens(this,e.output)}))),this.#c??=await l.VirtualFileSystem.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=(0,f.default)({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},(0,p.omit)(e??{},[`entry`]),(0,p.omit)(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=(0,k.getUnique)((0,h.toArray)(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(a.isPlugin(t)&&a.checkDedupe(t,e.filter(e=>a.isPlugin(e)))||e.push(t),e),[])}};exports.PowerlinesContext=V;
|
|
1
|
+
const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../typescript/ts-morph.cjs`),n=require(`../typescript/tsconfig.cjs`),r=require(`../config-file.cjs`),i=require(`../../internal/helpers/resolver.cjs`),a=require(`../../plugin-utils/helpers.cjs`),o=require(`../../plugin-utils/paths.cjs`),s=require(`../entry.cjs`),c=require(`../logger.cjs`),l=require(`../fs/vfs.cjs`),u=require(`../utilities/meta.cjs`);let d=require(`@storm-software/config-tools/types`),f=require(`defu`);f=e.__toESM(f);let p=require(`@stryke/helpers/omit`),m=require(`@stryke/fs/get-workspace-root`),h=require(`@stryke/convert/to-array`),g=require(`@stryke/fs/resolve`),_=require(`@stryke/path/append`),v=require(`@stryke/path/replace`),y=require(`@stryke/type-checks/is-set-object`),b=require(`@stryke/type-checks/is-set-string`),x=require(`@stryke/type-checks/is-string`),S=require(`@stryke/fs/json`),C=require(`@stryke/json/storm-json`),w=require(`@stryke/string-format/title-case`),T=require(`@stryke/fs/exists`),E=require(`@stryke/env/get-env-paths`),D=require(`@stryke/hash/hash-files`),O=require(`@stryke/hash/murmurhash`),k=require(`@stryke/helpers/get-unique`),A=require(`@stryke/http/fetch`),j=require(`@stryke/path/is-parent-path`),M=require(`@stryke/path/is-type`),N=require(`@stryke/path/join`),P=require(`@stryke/type-checks/is-null`),F=require(`@stryke/unique-id/uuid`),I=require(`bundle-require`),L=require(`flat-cache`),R=require(`oxc-parser`),z=require(`undici`);const B=new WeakMap;(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,f.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 i=new e(await r.loadWorkspaceConfig(t,n.root));await i.withUserConfig(n);let a=await(0,g.resolvePackage)(`powerlines`);if(!a)throw Error("Could not resolve `powerlines` package location.");return i.powerlinesPath=a,i}dependencies={};devDependencies={};persistedMeta=void 0;powerlinesPath;packageJson;projectJson=void 0;resolver;resolvePatterns=[];get $$internal(){return this.#e}set $$internal(e){this.#e=e}get entry(){return s.resolveEntriesSync(this,this.#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,O.murmurhash)({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:u.PROJECT_ROOT_HASH_LENGTH}),configHash:(0,O.murmurhash)(this.config,{maxLength:u.CACHE_HASH_LENGTH})}}get config(){return this.resolvedConfig??{}}get log(){return this.logFn||=this.createLog(),this.logFn}get workspaceConfig(){return this.#t}get envPaths(){return this.#o||=(0,E.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,O.murmurhash)({checksum:this.#n,config:this.meta.configHash},{maxLength:u.CACHE_HASH_LENGTH}))}get dtsPath(){return this.config.output.dts?(0,_.appendPath)(this.config.output.dts,this.workspaceConfig.workspaceRoot):(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return(0,m.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||=t.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,O.murmurhash)({input:e.toString(),options:JSON.stringify(t)});if(!this.config.skipCache&&!t.skipCache){let e=this.requestCache.get(n);if(e)return new z.Response(e.body,{status:e.status,statusText:e.statusText,headers:e.headers})}let r=await(0,A.fetchRequest)(e,{timeout:12e3,...t}),i={body:await r.text(),status:r.status,statusText:r.statusText,headers:Object.fromEntries(r.headers.entries())};if(!this.config.skipCache&&!t.skipCache)try{this.requestCache.set(n,i)}catch{}return new z.Response(i.body,{status:i.status,statusText:i.statusText,headers:i.headers})}async parse(e,t={}){let n=(0,O.murmurhash)({code:e,options:t}),r;return!this.config.skipCache&&(r=this.parserCache.get(n),r)?r:(r=await(0,R.parse)(`source.${t.lang||`ts`}`,e,{...t,sourceType:`module`,showSemanticErrors:this.config.mode===`development`}),this.config.skipCache||this.parserCache.set(n,r),r)}async resolve(e,t,n={}){let r=e;if(this.config.build.alias)if(Array.isArray(this.config.build.alias)){let e=this.config.build.alias.find(e=>(0,I.match)(r,[e.find]));e&&(r=e.replacement)}else (0,y.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,_.appendPath)(t,this.entryPath);return this.entry??=[],this.entry.push({name:n.name,file:r,input:n.input,output:n.output}),this.fs.write(r,e,(0,f.default)((0,p.omit)(n,[`name`]),{meta:{type:`entry`,properties:{name:n.name,output:n.output,"input.file":n.input?.file,"input.name":n.input?.name}}}))}async emitBuiltin(e,t,n,r={}){return this.fs.write(n?(0,M.isAbsolute)(n)?n:(0,N.joinPaths)(this.builtinsPath,n):(0,_.appendPath)(t,this.builtinsPath),e,(0,f.default)(r,{meta:{type:`builtin`}}))}async withUserConfig(e,t={isHighPriority:!0}){this.mergeUserConfig(e),await this.init(this.config.userConfig,t)}async withInlineConfig(e,t={isHighPriority:!0}){if(this.config.inlineConfig=e,e.command===`new`){let e=(0,N.joinPaths)(this.workspaceConfig.workspaceRoot,`package.json`);if(!(0,T.existsSync)(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await(0,S.readJsonFile)(e),this.workspaceConfig.repository??=(0,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,x.isString)(e)?e:C.StormJSON.stringify(e))}error(e){this.log(d.LogLevelLabel.ERROR,(0,x.isString)(e)?e:C.StormJSON.stringify(e))}warn(e){this.log(d.LogLevelLabel.WARN,(0,x.isString)(e)?e:C.StormJSON.stringify(e))}info(e){this.log(d.LogLevelLabel.INFO,(0,x.isString)(e)?e:C.StormJSON.stringify(e))}debug(e){this.log(d.LogLevelLabel.DEBUG,(0,x.isString)(e)?e:C.StormJSON.stringify(e))}trace(e){this.log(d.LogLevelLabel.TRACE,(0,x.isString)(e)?e:C.StormJSON.stringify(e))}createLog(e=null){return c.createLog(e,{...this.config,logLevel:(0,P.isNull)(this.config.logLevel)?`silent`:this.config.logLevel})}extendLog(e){return c.extendLog(this.log,e)}async generateChecksum(e=this.config.projectRoot){return this.#n=await(0,D.hashDirectory)(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,this.#o=(0,E.getEnvPaths)({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot})}resolvedConfig={};logFn;async init(e={},t={isHighPriority:!0}){let c={projectRoot:e.root??this.config.projectRoot??this.config.userConfig?.root??this.config.inlineConfig?.root,mode:(e.mode??this.config.mode)||this.workspaceConfig.mode,skipCache:e.skipCache??this.config.skipCache??!1,configFile:e.configFile??this.config.configFile,framework:e.framework??this.config.framework??`powerlines`,command:this.config.inlineConfig?.command};if(B.has(c)){let e=B.get(c);this.projectJson=e.projectJson,this.packageJson=e.packageJson,this.#n=e.checksum,this.resolver=e.resolver,this.mergeUserConfig(e.userConfig.config,this.config.userConfig)}else{let t=(0,N.joinPaths)(c.projectRoot,`project.json`);(0,T.existsSync)(t)&&(this.projectJson=await(0,S.readJsonFile)(t));let n=(0,N.joinPaths)(c.projectRoot,`package.json`);(0,T.existsSync)(n)&&(this.packageJson=await(0,S.readJsonFile)(n)),this.#n=await this.generateChecksum(c.projectRoot),this.resolver=i.createResolver({workspaceRoot:this.workspaceConfig.workspaceRoot,projectRoot:c.projectRoot,cacheDir:this.cachePath,mode:c.mode,logLevel:e.logLevel||this.config?.logLevel||this.workspaceConfig.logLevel||`info`,skipCache:c.skipCache});let a=await r.loadUserConfigFile(c.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,c.command,c.mode,c.configFile,c.framework);this.mergeUserConfig(a.config),B.set(c,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:a})}e.tsconfig??=n.getTsconfigFilePath(this.workspaceConfig.workspaceRoot,c.projectRoot,e.tsconfig),(0,y.isSetObject)(e)&&(this.resolvedConfig=(0,f.default)({inlineConfig:this.config.inlineConfig,userConfig:this.config.userConfig},t.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,_.appendPath)(`src`,c.projectRoot),output:(0,f.default)(e.output??{},{outputPath:c.projectRoot?(0,N.joinPaths)(this.workspaceConfig?.directories?.build||`dist`,c.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:(0,N.joinPaths)(c.projectRoot,`.${e.framework??`powerlines`}`),dts:(0,N.joinPaths)(c.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:c.projectRoot,glob:`*.md`},{input:c.projectRoot,glob:`package.json`}]})},t.isHighPriority?{}:this.#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=s.getUniqueEntries(this.config.entry),this.config.name?.startsWith(`@`)&&this.config.name.split(`/`).filter(Boolean).length>1&&(this.config.name=this.config.name.split(`/`).filter(Boolean)[1]),this.config.title??=(0,w.titleCase)(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=(0,k.getUnique)(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=(0,k.getUnique)(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=(0,k.getUnique)(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=(0,k.getUnique)(this.config.build.noExternal)),this.config.output.format=(0,k.getUnique)((0,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,k.getUniqueBy)(this.config.output.assets.map(e=>({glob:(0,y.isSetObject)(e)?e.glob:e,input:(0,x.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,_.appendPath)(e.input,this.workspaceConfig.workspaceRoot),output:(0,y.isSetObject)(e)&&e.output?(0,j.isParentPath)(e.output,this.workspaceConfig.workspaceRoot)?e.output:(0,_.appendPath)((0,N.joinPaths)(this.config.output.outputPath,(0,v.replacePath)((0,v.replacePath)(e.output,(0,v.replacePath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):(0,_.appendPath)(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:(0,y.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)=>(a.isPlugin(t)&&a.checkDedupe(t,e.filter(e=>a.isPlugin(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=o.replacePathTokens(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=o.replacePathTokens(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(e=>o.replacePathTokens(this,e))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(e=>({...e,glob:o.replacePathTokens(this,e.glob),ignore:e.ignore?e.ignore.map(e=>o.replacePathTokens(this,e)):void 0,input:o.replacePathTokens(this,e.input),output:o.replacePathTokens(this,e.output)}))),this.#c??=await l.VirtualFileSystem.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=(0,f.default)({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},(0,p.omit)(e??{},[`entry`]),(0,p.omit)(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=(0,k.getUnique)((0,h.toArray)(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(a.isPlugin(t)&&a.checkDedupe(t,e.filter(e=>a.isPlugin(e)))||e.push(t),e),[])}};exports.PowerlinesContext=V;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createProgram as e}from"../typescript/ts-morph.mjs";import{getTsconfigFilePath as t}from"../typescript/tsconfig.mjs";import{loadUserConfigFile as n,loadWorkspaceConfig as r}from"../config-file.mjs";import{createResolver as i}from"../../internal/helpers/resolver.mjs";import{checkDedupe as a,isPlugin as o}from"../../plugin-utils/helpers.mjs";import{replacePathTokens as s}from"../../plugin-utils/paths.mjs";import{getUniqueEntries as c,resolveEntriesSync as l}from"../entry.mjs";import{createLog as u,extendLog as d}from"../logger.mjs";import{VirtualFileSystem as f}from"../fs/vfs.mjs";import{CACHE_HASH_LENGTH as p,PROJECT_ROOT_HASH_LENGTH as m,getPrefixedProjectRootHash as h}from"../utilities/meta.mjs";import{LogLevelLabel as g}from"@storm-software/config-tools/types";import _ from"defu";import{omit as v}from"@stryke/helpers/omit";import{relativeToWorkspaceRoot as y}from"@stryke/fs/get-workspace-root";import{toArray as b}from"@stryke/convert/to-array";import{resolvePackage as x}from"@stryke/fs/resolve";import{appendPath as S}from"@stryke/path/append";import{replacePath as C}from"@stryke/path/replace";import{isSetObject as w}from"@stryke/type-checks/is-set-object";import{isSetString as T}from"@stryke/type-checks/is-set-string";import{isString as E}from"@stryke/type-checks/is-string";import{readJsonFile as D}from"@stryke/fs/json";import{StormJSON as O}from"@stryke/json/storm-json";import{titleCase as k}from"@stryke/string-format/title-case";import{existsSync as A}from"@stryke/fs/exists";import{getEnvPaths as j}from"@stryke/env/get-env-paths";import{hashDirectory as M}from"@stryke/hash/hash-files";import{murmurhash as N}from"@stryke/hash/murmurhash";import{getUnique as P,getUniqueBy as F}from"@stryke/helpers/get-unique";import{fetchRequest as I}from"@stryke/http/fetch";import{isParentPath as L}from"@stryke/path/is-parent-path";import{isAbsolute as R}from"@stryke/path/is-type";import{joinPaths as z}from"@stryke/path/join";import{isNull as B}from"@stryke/type-checks/is-null";import{uuid as V}from"@stryke/unique-id/uuid";import{match as H,tsconfigPathsToRegExp as U}from"bundle-require";import{create as W}from"flat-cache";import{parse as G}from"oxc-parser";import{Agent as K,Response as q,interceptors as J,setGlobalDispatcher as Y}from"undici";const X=new WeakMap;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 _({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 r(e,t.root));await n.withUserConfig(t);let i=await x(`powerlines`);if(!i)throw Error("Could not resolve `powerlines` package location.");return n.powerlinesPath=i,n}dependencies={};devDependencies={};persistedMeta=void 0;powerlinesPath;packageJson;projectJson=void 0;resolver;resolvePatterns=[];get $$internal(){return this.#e}set $$internal(e){this.#e=e}get entry(){return l(this,this.#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:N({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:m}),configHash:N(this.config,{maxLength:p})}}get config(){return this.resolvedConfig??{}}get log(){return this.logFn||=this.createLog(),this.logFn}get workspaceConfig(){return this.#t}get envPaths(){return this.#o||=j({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`,N({checksum:this.#n,config:this.meta.configHash},{maxLength:p}))}get dtsPath(){return this.config.output.dts?S(this.config.output.dts,this.workspaceConfig.workspaceRoot):z(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return y(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||=e(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=N({input:e.toString(),options:JSON.stringify(t)});if(!this.config.skipCache&&!t.skipCache){let e=this.requestCache.get(n);if(e)return new q(e.body,{status:e.status,statusText:e.statusText,headers:e.headers})}let r=await I(e,{timeout:12e3,...t}),i={body:await r.text(),status:r.status,statusText:r.statusText,headers:Object.fromEntries(r.headers.entries())};if(!this.config.skipCache&&!t.skipCache)try{this.requestCache.set(n,i)}catch{}return new q(i.body,{status:i.status,statusText:i.statusText,headers:i.headers})}async parse(e,t={}){let n=N({code:e,options:t}),r;return!this.config.skipCache&&(r=this.parserCache.get(n),r)?r:(r=await G(`source.${t.lang||`ts`}`,e,{...t,sourceType:`module`,showSemanticErrors:this.config.mode===`development`}),this.config.skipCache||this.parserCache.set(n,r),r)}async resolve(e,t,n={}){let r=e;if(this.config.build.alias)if(Array.isArray(this.config.build.alias)){let e=this.config.build.alias.find(e=>H(r,[e.find]));e&&(r=e.replacement)}else w(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:S(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):S(t,this.builtinsPath),e,_(r,{meta:{type:`builtin`}}))}async withUserConfig(e,t={isHighPriority:!0}){this.mergeUserConfig(e),await this.init(this.config.userConfig,t)}async withInlineConfig(e,t={isHighPriority:!0}){if(this.config.inlineConfig=e,e.command===`new`){let e=z(this.workspaceConfig.workspaceRoot,`package.json`);if(!A(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await D(e),this.workspaceConfig.repository??=T(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(g.FATAL,E(e)?e:O.stringify(e))}error(e){this.log(g.ERROR,E(e)?e:O.stringify(e))}warn(e){this.log(g.WARN,E(e)?e:O.stringify(e))}info(e){this.log(g.INFO,E(e)?e:O.stringify(e))}debug(e){this.log(g.DEBUG,E(e)?e:O.stringify(e))}trace(e){this.log(g.TRACE,E(e)?e:O.stringify(e))}createLog(e=null){return u(e,{...this.config,logLevel:B(this.config.logLevel)?`silent`:this.config.logLevel})}extendLog(e){return d(this.log,e)}async generateChecksum(e=this.config.projectRoot){return this.#n=await M(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,this.#o=j({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot})}resolvedConfig={};logFn;async init(e={},r={isHighPriority:!0}){let l={projectRoot:e.root??this.config.projectRoot??this.config.userConfig?.root??this.config.inlineConfig?.root,mode:(e.mode??this.config.mode)||this.workspaceConfig.mode,skipCache:e.skipCache??this.config.skipCache??!1,configFile:e.configFile??this.config.configFile,framework:e.framework??this.config.framework??`powerlines`,command:this.config.inlineConfig?.command};if(X.has(l)){let e=X.get(l);this.projectJson=e.projectJson,this.packageJson=e.packageJson,this.#n=e.checksum,this.resolver=e.resolver,this.mergeUserConfig(e.userConfig.config,this.config.userConfig)}else{let t=z(l.projectRoot,`project.json`);A(t)&&(this.projectJson=await D(t));let r=z(l.projectRoot,`package.json`);A(r)&&(this.packageJson=await D(r)),this.#n=await this.generateChecksum(l.projectRoot),this.resolver=i({workspaceRoot:this.workspaceConfig.workspaceRoot,projectRoot:l.projectRoot,cacheDir:this.cachePath,mode:l.mode,logLevel:e.logLevel||this.config?.logLevel||this.workspaceConfig.logLevel||`info`,skipCache:l.skipCache});let a=await n(l.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,l.command,l.mode,l.configFile,l.framework);this.mergeUserConfig(a.config),X.set(l,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:a})}e.tsconfig??=t(this.workspaceConfig.workspaceRoot,l.projectRoot,e.tsconfig),w(e)&&(this.resolvedConfig=_({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||S(`src`,l.projectRoot),output:_(e.output??{},{outputPath:l.projectRoot?z(this.workspaceConfig?.directories?.build||`dist`,l.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:z(l.projectRoot,`.${e.framework??`powerlines`}`),dts:z(l.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:l.projectRoot,glob:`*.md`},{input:l.projectRoot,glob:`package.json`}]})},r.isHighPriority?{}:this.#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=c(this.config.entry),this.config.name?.startsWith(`@`)&&this.config.name.split(`/`).filter(Boolean).length>1&&(this.config.name=this.config.name.split(`/`).filter(Boolean)[1]),this.config.title??=k(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=P(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=P(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=P(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=P(this.config.build.noExternal)),this.config.output.format=P(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=F(this.config.output.assets.map(e=>({glob:w(e)?e.glob:e,input:E(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:S(e.input,this.workspaceConfig.workspaceRoot),output:w(e)&&e.output?L(e.output,this.workspaceConfig.workspaceRoot)?e.output:S(z(this.config.output.outputPath,C(C(e.output,C(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):S(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:w(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)=>(o(t)&&a(t,e.filter(e=>o(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=s(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=s(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(e=>s(this,e))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(e=>({...e,glob:s(this,e.glob),ignore:e.ignore?e.ignore.map(e=>s(this,e)):void 0,input:s(this,e.input),output:s(this,e.output)}))),this.#c??=await f.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=_({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},v(e??{},[`entry`]),v(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=P(b(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(o(t)&&a(t,e.filter(e=>o(e)))||e.push(t),e),[])}};export{Z as PowerlinesContext};
|
|
1
|
+
import{createProgram as e}from"../typescript/ts-morph.mjs";import{getTsconfigFilePath as t}from"../typescript/tsconfig.mjs";import{loadUserConfigFile as n,loadWorkspaceConfig as r}from"../config-file.mjs";import{createResolver as i}from"../../internal/helpers/resolver.mjs";import{checkDedupe as a,isPlugin as o}from"../../plugin-utils/helpers.mjs";import{replacePathTokens as s}from"../../plugin-utils/paths.mjs";import{getUniqueEntries as c,resolveEntriesSync as l}from"../entry.mjs";import{createLog as u,extendLog as d}from"../logger.mjs";import{VirtualFileSystem as f}from"../fs/vfs.mjs";import{CACHE_HASH_LENGTH as p,PROJECT_ROOT_HASH_LENGTH as m,getPrefixedProjectRootHash as h}from"../utilities/meta.mjs";import{LogLevelLabel as g}from"@storm-software/config-tools/types";import _ from"defu";import{omit as v}from"@stryke/helpers/omit";import{relativeToWorkspaceRoot as y}from"@stryke/fs/get-workspace-root";import{toArray as b}from"@stryke/convert/to-array";import{resolvePackage as x}from"@stryke/fs/resolve";import{appendPath as S}from"@stryke/path/append";import{replacePath as C}from"@stryke/path/replace";import{isSetObject as w}from"@stryke/type-checks/is-set-object";import{isSetString as T}from"@stryke/type-checks/is-set-string";import{isString as E}from"@stryke/type-checks/is-string";import{readJsonFile as D}from"@stryke/fs/json";import{StormJSON as O}from"@stryke/json/storm-json";import{titleCase as k}from"@stryke/string-format/title-case";import{existsSync as A}from"@stryke/fs/exists";import{getEnvPaths as j}from"@stryke/env/get-env-paths";import{hashDirectory as M}from"@stryke/hash/hash-files";import{murmurhash as N}from"@stryke/hash/murmurhash";import{getUnique as P,getUniqueBy as F}from"@stryke/helpers/get-unique";import{fetchRequest as I}from"@stryke/http/fetch";import{isParentPath as L}from"@stryke/path/is-parent-path";import{isAbsolute as R}from"@stryke/path/is-type";import{joinPaths as z}from"@stryke/path/join";import{isNull as B}from"@stryke/type-checks/is-null";import{uuid as V}from"@stryke/unique-id/uuid";import{match as H,tsconfigPathsToRegExp as U}from"bundle-require";import{create as W}from"flat-cache";import{parse as G}from"oxc-parser";import{Agent as K,Response as q,interceptors as J,setGlobalDispatcher as Y}from"undici";const X=new WeakMap;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 _({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 r(e,t.root));await n.withUserConfig(t);let i=await x(`powerlines`);if(!i)throw Error("Could not resolve `powerlines` package location.");return n.powerlinesPath=i,n}dependencies={};devDependencies={};persistedMeta=void 0;powerlinesPath;packageJson;projectJson=void 0;resolver;resolvePatterns=[];get $$internal(){return this.#e}set $$internal(e){this.#e=e}get entry(){return l(this,this.#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:N({workspaceRoot:this.workspaceConfig?.workspaceRoot,projectRoot:this.config?.projectRoot},{maxLength:m}),configHash:N(this.config,{maxLength:p})}}get config(){return this.resolvedConfig??{}}get log(){return this.logFn||=this.createLog(),this.logFn}get workspaceConfig(){return this.#t}get envPaths(){return this.#o||=j({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`,N({checksum:this.#n,config:this.meta.configHash},{maxLength:p}))}get dtsPath(){return this.config.output.dts?S(this.config.output.dts,this.workspaceConfig.workspaceRoot):z(this.workspaceConfig.workspaceRoot,this.config.projectRoot,`powerlines.d.ts`)}get relativeToWorkspaceRoot(){return y(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||=e(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=N({input:e.toString(),options:JSON.stringify(t)});if(!this.config.skipCache&&!t.skipCache){let e=this.requestCache.get(n);if(e)return new q(e.body,{status:e.status,statusText:e.statusText,headers:e.headers})}let r=await I(e,{timeout:12e3,...t}),i={body:await r.text(),status:r.status,statusText:r.statusText,headers:Object.fromEntries(r.headers.entries())};if(!this.config.skipCache&&!t.skipCache)try{this.requestCache.set(n,i)}catch{}return new q(i.body,{status:i.status,statusText:i.statusText,headers:i.headers})}async parse(e,t={}){let n=N({code:e,options:t}),r;return!this.config.skipCache&&(r=this.parserCache.get(n),r)?r:(r=await G(`source.${t.lang||`ts`}`,e,{...t,sourceType:`module`,showSemanticErrors:this.config.mode===`development`}),this.config.skipCache||this.parserCache.set(n,r),r)}async resolve(e,t,n={}){let r=e;if(this.config.build.alias)if(Array.isArray(this.config.build.alias)){let e=this.config.build.alias.find(e=>H(r,[e.find]));e&&(r=e.replacement)}else w(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:S(t,this.entryPath);return this.entry??=[],this.entry.push({name:n.name,file:r,input:n.input,output:n.output}),this.fs.write(r,e,_(v(n,[`name`]),{meta:{type:`entry`,properties:{name:n.name,output:n.output,"input.file":n.input?.file,"input.name":n.input?.name}}}))}async emitBuiltin(e,t,n,r={}){return this.fs.write(n?R(n)?n:z(this.builtinsPath,n):S(t,this.builtinsPath),e,_(r,{meta:{type:`builtin`}}))}async withUserConfig(e,t={isHighPriority:!0}){this.mergeUserConfig(e),await this.init(this.config.userConfig,t)}async withInlineConfig(e,t={isHighPriority:!0}){if(this.config.inlineConfig=e,e.command===`new`){let e=z(this.workspaceConfig.workspaceRoot,`package.json`);if(!A(e))throw Error(`The workspace package.json file could not be found at ${e}`);this.packageJson=await D(e),this.workspaceConfig.repository??=T(this.packageJson?.repository)?this.packageJson.repository:this.packageJson?.repository?.url}await this.init(this.config.inlineConfig,t)}fatal(e){this.log(g.FATAL,E(e)?e:O.stringify(e))}error(e){this.log(g.ERROR,E(e)?e:O.stringify(e))}warn(e){this.log(g.WARN,E(e)?e:O.stringify(e))}info(e){this.log(g.INFO,E(e)?e:O.stringify(e))}debug(e){this.log(g.DEBUG,E(e)?e:O.stringify(e))}trace(e){this.log(g.TRACE,E(e)?e:O.stringify(e))}createLog(e=null){return u(e,{...this.config,logLevel:B(this.config.logLevel)?`silent`:this.config.logLevel})}extendLog(e){return d(this.log,e)}async generateChecksum(e=this.config.projectRoot){return this.#n=await M(e,{ignore:[`node_modules`,`.git`,`.nx`,`.cache`,`.storm`,`tmp`,`dist`]}),this.#n}constructor(e){this.#t=e,this.#o=j({orgId:`storm-software`,appId:`powerlines`,workspaceRoot:e.workspaceRoot})}resolvedConfig={};logFn;async init(e={},r={isHighPriority:!0}){let l={projectRoot:e.root??this.config.projectRoot??this.config.userConfig?.root??this.config.inlineConfig?.root,mode:(e.mode??this.config.mode)||this.workspaceConfig.mode,skipCache:e.skipCache??this.config.skipCache??!1,configFile:e.configFile??this.config.configFile,framework:e.framework??this.config.framework??`powerlines`,command:this.config.inlineConfig?.command};if(X.has(l)){let e=X.get(l);this.projectJson=e.projectJson,this.packageJson=e.packageJson,this.#n=e.checksum,this.resolver=e.resolver,this.mergeUserConfig(e.userConfig.config,this.config.userConfig)}else{let t=z(l.projectRoot,`project.json`);A(t)&&(this.projectJson=await D(t));let r=z(l.projectRoot,`package.json`);A(r)&&(this.packageJson=await D(r)),this.#n=await this.generateChecksum(l.projectRoot),this.resolver=i({workspaceRoot:this.workspaceConfig.workspaceRoot,projectRoot:l.projectRoot,cacheDir:this.cachePath,mode:l.mode,logLevel:e.logLevel||this.config?.logLevel||this.workspaceConfig.logLevel||`info`,skipCache:l.skipCache});let a=await n(l.projectRoot,this.workspaceConfig.workspaceRoot,this.resolver,l.command,l.mode,l.configFile,l.framework);this.mergeUserConfig(a.config),X.set(l,{projectJson:this.projectJson,packageJson:this.packageJson,checksum:this.#n,resolver:this.resolver,userConfig:a})}e.tsconfig??=t(this.workspaceConfig.workspaceRoot,l.projectRoot,e.tsconfig),w(e)&&(this.resolvedConfig=_({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||S(`src`,l.projectRoot),output:_(e.output??{},{outputPath:l.projectRoot?z(this.workspaceConfig?.directories?.build||`dist`,l.projectRoot):this.workspaceConfig?.directories?.build||`dist`,artifactsPath:z(l.projectRoot,`.${e.framework??`powerlines`}`),dts:z(l.projectRoot,`${e.framework??`powerlines`}.d.ts`),builtinPrefix:e.framework??`powerlines`,assets:[{glob:`LICENSE`},{input:l.projectRoot,glob:`*.md`},{input:l.projectRoot,glob:`package.json`}]})},r.isHighPriority?{}:this.#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=c(this.config.entry),this.config.name?.startsWith(`@`)&&this.config.name.split(`/`).filter(Boolean).length>1&&(this.config.name=this.config.name.split(`/`).filter(Boolean)[1]),this.config.title??=k(this.config.name),this.config.userConfig.build?.external&&(this.config.userConfig.build.external=P(this.config.userConfig.build.external)),this.config.userConfig.build?.noExternal&&(this.config.userConfig.build.noExternal=P(this.config.userConfig.build.noExternal)),this.config.build.external&&(this.config.build.external=P(this.config.build.external)),this.config.build.noExternal&&(this.config.build.noExternal=P(this.config.build.noExternal)),this.config.output.format=P(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=F(this.config.output.assets.map(e=>({glob:w(e)?e.glob:e,input:E(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:S(e.input,this.workspaceConfig.workspaceRoot),output:w(e)&&e.output?L(e.output,this.workspaceConfig.workspaceRoot)?e.output:S(z(this.config.output.outputPath,C(C(e.output,C(this.config.output.outputPath,this.workspaceConfig.workspaceRoot)),this.config.output.outputPath)),this.workspaceConfig.workspaceRoot):S(this.config.output.outputPath,this.workspaceConfig.workspaceRoot),ignore:w(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)=>(o(t)&&a(t,e.filter(e=>o(e)))||e.push(t),e),[]),this.config.tsconfig&&(this.config.tsconfig=s(this,this.config.tsconfig)),this.config.output.dts&&(this.config.output.dts=s(this,this.config.output.dts)),this.config.build.polyfill&&(this.config.build.polyfill=this.config.build.polyfill.map(e=>s(this,e))),this.config.output.assets&&(this.config.output.assets=this.config.output.assets.map(e=>({...e,glob:s(this,e.glob),ignore:e.ignore?e.ignore.map(e=>s(this,e)):void 0,input:s(this,e.input),output:s(this,e.output)}))),this.#c??=await f.create(this)}mergeUserConfig(e={},t=this.config.userConfig??{}){this.config.userConfig=_({entry:Array.isArray(e.entry)&&e.entry.length>0?e.entry:Array.isArray(t?.entry)&&t.entry.length>0?t.entry:[]},v(e??{},[`entry`]),v(t??{},[`entry`])),this.config.userConfig.output?.format&&(this.config.userConfig.output.format=P(b(this.config.userConfig.output?.format))),this.config.userConfig.plugins=(this.config.userConfig.plugins??[]).filter(Boolean).reduce((e,t)=>(o(t)&&a(t,e.filter(e=>o(e)))||e.push(t),e),[])}};export{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(`@storm-software/config-tools/types`),c=require(`@stryke/path/join-paths`),l=require(`@stryke/convert/to-array`),u=require(`@stryke/fs/resolve`),d=require(`@stryke/path/append`),f=require(`@stryke/path/replace`),p=require(`@stryke/type-checks/is-set-object`),m=require(`@stryke/type-checks/is-set-string`),h=require(`@stryke/type-checks/is-string`),g=require(`@stryke/path/file-path-fns`),_=require(`@stryke/fs/exists`),v=require(`@stryke/hash/murmurhash`),y=require(`@stryke/helpers/get-unique`),b=require(`@stryke/path/is-parent-path`),x=require(`@stryke/path/is-type`),S=require(`flat-cache`),C=require(`@stryke/capnp`);C=e.__toESM(C);let w=require(`@stryke/fs/buffer`),T=require(`@stryke/string-format/pretty-bytes`),E=require(`node:buffer`),D=require(`node:url`),O=require(`prettier`);var k=class e{#e;#t;#n;#r={"":new a.FileSystemStorageAdapter};#i;#a=!1;#o;#s;#c(e){let t=e;return(0,b.isParentPath)(t,this.#o.builtinsPath)&&(t=(0,f.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,f.replacePath)(t,e),adapter:this.#r[e]};return{base:``,relativeKey:t,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>(0,b.isParentPath)(n,e)||t&&(0,b.isParentPath)(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(t){if(!t.config.skipCache&&(0,_.existsSync)((0,c.joinPaths)(t.dataPath,`fs.bin`))){let r=await(0,w.readFileBuffer)((0,c.joinPaths)(t.dataPath,`fs.bin`)),i=new C.Message(r,!1).getRoot(n.FileSystem),a=new e(t,i);i._hasStorage()&&i.storage.length>0&&await Promise.all(i.storage.values().map(async e=>{await a.write(e.path,e.code)}))}return new e(t,new C.Message().initRoot(n.FileSystem))}static createSync(t){if(!t.config.skipCache&&(0,_.existsSync)((0,c.joinPaths)(t.dataPath,`fs.bin`))){let r=(0,w.readFileBufferSync)((0,c.joinPaths)(t.dataPath,`fs.bin`)),i=new C.Message(r,!1).getRoot(n.FileSystem),a=new e(t,i);i._hasStorage()&&i.storage.length>0&&i.storage.values().map(e=>{a.writeSync(e.path,e.code)})}return new e(t,new C.Message().initRoot(n.FileSystem))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=(0,S.create)({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,(0,p.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,y.getUnique)(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?(0,d.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return(0,y.getUnique)((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?(0,d.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(s.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,g.hasFileExtension)(t)?await r.remove(n):await r.clear(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}removeSync(e){let t=this.#l(e);this.#s(s.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,g.hasFileExtension)(t)?r.removeSync(n):r.clearSync(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}async glob(e){let t=[];for(let n of i.normalizeGlobPatterns(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...await this.list(e));else{let n=await this.resolve(e);n&&!t.includes(n)&&t.push(n)}continue}let r=(0,x.isAbsolutePath)(e)?e:this.#l((0,c.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,g.findFilePath)(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i)));await Promise.all((await this.list(a&&(0,x.isAbsolutePath)(a)?a:this.#o.workspaceConfig.workspaceRoot)).map(async e=>{if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}))}return t}globSync(e){let t=[];for(let n of i.normalizeGlobPatterns(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...this.listSync(e));else{let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}continue}let r=(0,x.isAbsolutePath)(e)?e:this.#l((0,c.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,g.findFilePath)(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i))),o=this.listSync(a&&(0,x.isAbsolutePath)(a)?a:this.#o.workspaceConfig.workspaceRoot);for(let e of o)if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}return t}async copy(e,t){let n=e instanceof URL?(0,D.fileURLToPath)(e):e,r=t instanceof URL?(0,D.fileURLToPath)(t):t;if(!(0,m.isSetString)(n)&&(!(0,p.isSetObject)(n)||!(0,m.isSetString)(n.input))||!(0,m.isSetString)(r))return;let i=(0,h.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,p.isSetObject)(n)&&(0,m.isSetString)(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,(0,d.appendPath)((0,f.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,p.isSetObject)(n)||!(0,m.isSetString)(n.input))||!(0,m.isSetString)(r))return;let i=(0,h.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,p.isSetObject)(n)&&(0,m.isSetString)(n.glob))this.globSync(n).map(e=>this.copySync(e,(0,d.appendPath)((0,g.findFilePath)((0,f.replacePath)(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l((0,g.hasFileExtension)(r)?r:(0,d.appendPath)((0,g.findFileName)(a),r)),e,{skipFormat:!0})}}async move(e,t){(0,g.hasFileExtension)(e)?(await this.copy(e,t),await this.remove(e)):await Promise.all((await this.list(e)).map(async e=>{await this.copy(e,t),await this.remove(e)}))}moveSync(e,t){(0,g.hasFileExtension)(e)?(this.copySync(e,t),this.removeSync(e)):this.listSync(e).forEach(e=>{this.copySync(e,t),this.removeSync(e)})}async read(e){let t=await this.resolve(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(s.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(s.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(s.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,l.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(s.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,l.toArray)(t)).size)})`);let a=n?.meta?.id||this.#c(r);return this.#e[a]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[a]=this.#l(r),this.#t[this.#l(r)]=a,i.setSync(r,t)}mkdirSync(e){return this.#d(e)?.adapter?.mkdirSync(e)}async mkdir(e){return this.#d(e)?.adapter?.mkdir(e)}getMetadata(e){let t=this.resolveSync(e);if(t&&this.metadata[t])return this.metadata[t]}async resolve(e,n,r={}){let i=e;if((i.includes(`{`)||i.includes(`}`))&&(i=t.replacePathTokens(this.#o,i)),(0,x.isAbsolutePath)(i))return i;let a=(0,v.murmurhash)({path:this.#c(i),importer:n,options:r}),o;if(!this.#o.config.skipCache&&(o=this.resolverCache.get(a),o))return o;if(o=this.paths[this.#c(i)],!o){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push((0,d.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,d.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,d.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,u.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,u.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,d.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,d.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,d.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,u.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=(0,u.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(s.LogLevelLabel.DEBUG,`Disposing virtual file system...`),await this.remove((0,c.joinPaths)(this.#o.dataPath,`fs.bin`));let e=new C.Message,t=e.initRoot(n.FileSystem),r=await this.list(),i=t._initStorage(r.length);await Promise.all(r.map(async(e,t)=>{let n=await this.read(e),r=i.get(t);r.path=e,r.code=n||``}));let a=t._initIds(Object.keys(this.ids).length);Object.entries(this.ids).filter(([,e])=>e).forEach(([e,t],n)=>{let r=a.get(n);r.id=e,r.path=t});let o=t._initMetadata(Object.keys(this.metadata).length);Object.entries(this.metadata).filter(([,e])=>e).forEach(([e,t],n)=>{let r=o.get(n);if(r.id=e,r.type=t.type,r.timestamp=t.timestamp??BigInt(Date.now()),t.properties){let e=r._initProperties(Object.keys(t.properties).length);Object.entries(t.properties).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await(0,w.writeFileBuffer)((0,c.joinPaths)(this.#o.dataPath,`fs.bin`),e.toArrayBuffer()),this.#o.config.skipCache||this.#i.save(!0),await Promise.all(this.#f().map(async e=>e.adapter.dispose())),this.#s(s.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(`@storm-software/config-tools/types`),c=require(`@stryke/path/join-paths`),l=require(`@stryke/convert/to-array`),u=require(`@stryke/fs/resolve`),d=require(`@stryke/path/append`),f=require(`@stryke/path/replace`),p=require(`@stryke/type-checks/is-set-object`),m=require(`@stryke/type-checks/is-set-string`),h=require(`@stryke/type-checks/is-string`),g=require(`@stryke/path/file-path-fns`),_=require(`@stryke/fs/exists`),v=require(`@stryke/hash/murmurhash`),y=require(`@stryke/helpers/get-unique`),b=require(`@stryke/path/is-parent-path`),x=require(`@stryke/path/is-type`),S=require(`flat-cache`),C=require(`@stryke/capnp`);C=e.__toESM(C);let w=require(`@stryke/fs/buffer`),T=require(`@stryke/string-format/pretty-bytes`),E=require(`node:buffer`),D=require(`node:url`),O=require(`prettier`);var k=class e{#e;#t;#n;#r={"":new a.FileSystemStorageAdapter};#i;#a=!1;#o;#s;#c(e){let t=e;return(0,b.isParentPath)(t,this.#o.builtinsPath)&&(t=(0,f.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,f.replacePath)(t,e),adapter:this.#r[e]};return{base:``,relativeKey:t,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>(0,b.isParentPath)(n,e)||t&&(0,b.isParentPath)(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(t){if(!t.config.skipCache&&(0,_.existsSync)((0,c.joinPaths)(t.dataPath,`fs.bin`))){let r=await(0,w.readFileBuffer)((0,c.joinPaths)(t.dataPath,`fs.bin`)),i=new C.Message(r,!1).getRoot(n.FileSystem),a=new e(t,i);i._hasStorage()&&i.storage.length>0&&await Promise.all(i.storage.values().map(async e=>{await a.write(e.path,e.code)}))}return new e(t,new C.Message().initRoot(n.FileSystem))}static createSync(t){if(!t.config.skipCache&&(0,_.existsSync)((0,c.joinPaths)(t.dataPath,`fs.bin`))){let r=(0,w.readFileBufferSync)((0,c.joinPaths)(t.dataPath,`fs.bin`)),i=new C.Message(r,!1).getRoot(n.FileSystem),a=new e(t,i);i._hasStorage()&&i.storage.length>0&&i.storage.values().map(e=>{a.writeSync(e.path,e.code)})}return new e(t,new C.Message().initRoot(n.FileSystem))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=(0,S.create)({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,(0,p.isSetObject)(this.#o.config.output.storage)&&(this.#r={...this.#r,...this.#o.config.output.storage}),this.#r.virtual??=new o.VirtualStorageAdapter({base:`/_virtual`}),this.#o.config.output.storage!==`fs`&&(this.#r[this.#o.artifactsPath]??=new o.VirtualStorageAdapter({base:this.#o.artifactsPath}),this.#r[this.#o.builtinsPath]??=new o.VirtualStorageAdapter({base:this.#o.builtinsPath}),this.#r[this.#o.entryPath]??=new o.VirtualStorageAdapter({base:this.#o.entryPath})),this.#e={},t._hasMetadata()&&(this.#e=t.metadata.values().reduce((e,t)=>(e[t.id]={id:t.id,type:t.type,timestamp:t.timestamp||Date.now(),properties:t._hasProperties()?t.properties.values().reduce((e,t)=>(e[t.key]=t.value,e),{}):{}},e),{}),e.config.skipCache!==!0&&Object.entries(this.#e).filter(([,e])=>e.type===`entry`).forEach(([e,t])=>{this.#o.entry??=[],this.#o.entry.push({file:e,name:t.properties.name,output:t.properties.output,input:t.properties[`input.file`]?{file:t.properties[`input.file`],name:t.properties[`input.name`]}:void 0})})),this.#t={},this.#n={},t._hasIds()&&(this.#t=t.ids.values().reduce((e,t)=>(e[t.path]??=t.id,e),{}),this.#n=t.ids.values().reduce((e,t)=>(e[t.id]??=t.path,e),{})),this.#s=r.extendLog(this.#o.log,`file-system`)}async exists(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.exists(t)}existsSync(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.existsSync(t)}isVirtual(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.name===`virtual`:!1}isDirectorySync(e){let t=this.resolveSync(e);return t?!!(this.existsSync(t)&&this.#d(t)?.adapter?.isDirectorySync(t)):!1}async isDirectory(e){let t=await this.resolve(e);return t?!!(await this.exists(t)&&await this.#d(t)?.adapter?.isDirectory(t)):!1}isFileSync(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.isFileSync(t)??!1:!1}async isFile(e){let t=await this.resolve(e);return t?await this.#d(t)?.adapter?.isFile(t)??!1:!1}listSync(e){return(0,y.getUnique)(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?(0,d.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return(0,y.getUnique)((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?(0,d.appendPath)(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(s.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,g.hasFileExtension)(t)?await r.remove(n):await r.clear(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}removeSync(e){let t=this.#l(e);this.#s(s.LogLevelLabel.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);(0,g.hasFileExtension)(t)?r.removeSync(n):r.clearSync(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}async glob(e){let t=[];for(let n of i.normalizeGlobPatterns(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...await this.list(e));else{let n=await this.resolve(e);n&&!t.includes(n)&&t.push(n)}continue}let r=(0,x.isAbsolutePath)(e)?e:this.#l((0,c.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,g.findFilePath)(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i)));await Promise.all((await this.list(a&&(0,x.isAbsolutePath)(a)?a:this.#o.workspaceConfig.workspaceRoot)).map(async e=>{if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}))}return t}globSync(e){let t=[];for(let n of i.normalizeGlobPatterns(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...this.listSync(e));else{let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}continue}let r=(0,x.isAbsolutePath)(e)?e:this.#l((0,c.joinPaths)(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?(0,g.findFilePath)(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i))),o=this.listSync(a&&(0,x.isAbsolutePath)(a)?a:this.#o.workspaceConfig.workspaceRoot);for(let e of o)if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}return t}async copy(e,t){let n=e instanceof URL?(0,D.fileURLToPath)(e):e,r=t instanceof URL?(0,D.fileURLToPath)(t):t;if(!(0,m.isSetString)(n)&&(!(0,p.isSetObject)(n)||!(0,m.isSetString)(n.input))||!(0,m.isSetString)(r))return;let i=(0,h.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,p.isSetObject)(n)&&(0,m.isSetString)(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,(0,d.appendPath)((0,f.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,p.isSetObject)(n)||!(0,m.isSetString)(n.input))||!(0,m.isSetString)(r))return;let i=(0,h.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,p.isSetObject)(n)&&(0,m.isSetString)(n.glob))this.globSync(n).map(e=>this.copySync(e,(0,d.appendPath)((0,g.findFilePath)((0,f.replacePath)(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l((0,g.hasFileExtension)(r)?r:(0,d.appendPath)((0,g.findFileName)(a),r)),e,{skipFormat:!0})}}async move(e,t){(0,g.hasFileExtension)(e)?(await this.copy(e,t),await this.remove(e)):await Promise.all((await this.list(e)).map(async e=>{await this.copy(e,t),await this.remove(e)}))}moveSync(e,t){(0,g.hasFileExtension)(e)?(this.copySync(e,t),this.removeSync(e)):this.listSync(e).forEach(e=>{this.copySync(e,t),this.removeSync(e)})}async read(e){let t=await this.resolve(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(s.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(s.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(s.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,l.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(s.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,l.toArray)(t)).size)})`);let a=n?.meta?.id||this.#c(r);return this.#e[a]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[a]=this.#l(r),this.#t[this.#l(r)]=a,i.setSync(r,t)}mkdirSync(e){return this.#d(e)?.adapter?.mkdirSync(e)}async mkdir(e){return this.#d(e)?.adapter?.mkdir(e)}getMetadata(e){let t=this.resolveSync(e);if(t&&this.metadata[t])return this.metadata[t]}async resolve(e,n,r={}){let i=e;if((i.includes(`{`)||i.includes(`}`))&&(i=t.replacePathTokens(this.#o,i)),(0,x.isAbsolutePath)(i))return i;let a=(0,v.murmurhash)({path:this.#c(i),importer:n,options:r}),o;if(!this.#o.config.skipCache&&(o=this.resolverCache.get(a),o))return o;if(o=this.paths[this.#c(i)],!o){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push((0,d.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,d.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,d.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,u.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,u.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,d.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,d.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,d.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,u.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=(0,u.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(s.LogLevelLabel.DEBUG,`Disposing virtual file system...`),await this.remove((0,c.joinPaths)(this.#o.dataPath,`fs.bin`));let e=new C.Message,t=e.initRoot(n.FileSystem),r=await this.list(),i=t._initStorage(r.length);await Promise.all(r.map(async(e,t)=>{let n=await this.read(e),r=i.get(t);r.path=e,r.code=n||``}));let a=t._initIds(Object.keys(this.ids).length);Object.entries(this.ids).filter(([,e])=>e).forEach(([e,t],n)=>{let r=a.get(n);r.id=e,r.path=t});let o=t._initMetadata(Object.keys(this.metadata).length);Object.entries(this.metadata).filter(([,e])=>e).forEach(([e,t],n)=>{let r=o.get(n);if(r.id=e,r.type=t.type,r.timestamp=t.timestamp??BigInt(Date.now()),t.properties){let e=r._initProperties(Object.keys(t.properties).length);Object.entries(t.properties).filter(([,e])=>(0,m.isSetString)(e)).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await(0,w.writeFileBuffer)((0,c.joinPaths)(this.#o.dataPath,`fs.bin`),e.toArrayBuffer()),this.#o.config.skipCache||this.#i.save(!0),await Promise.all(this.#f().map(async e=>e.adapter.dispose())),this.#s(s.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{LogLevelLabel as c}from"@storm-software/config-tools/types";import{joinPaths as l}from"@stryke/path/join-paths";import{toArray as u}from"@stryke/convert/to-array";import{getResolutionCombinations as d,resolve as f,resolveSync as p}from"@stryke/fs/resolve";import{appendPath as m}from"@stryke/path/append";import{replacePath as h}from"@stryke/path/replace";import{isSetObject as g}from"@stryke/type-checks/is-set-object";import{isSetString as _}from"@stryke/type-checks/is-set-string";import{isString as v}from"@stryke/type-checks/is-string";import{findFileName as y,findFilePath as b,hasFileExtension as x}from"@stryke/path/file-path-fns";import{existsSync as S}from"@stryke/fs/exists";import{murmurhash as C}from"@stryke/hash/murmurhash";import{getUnique as w}from"@stryke/helpers/get-unique";import{isParentPath as T}from"@stryke/path/is-parent-path";import{isAbsolutePath as E}from"@stryke/path/is-type";import{create as D}from"flat-cache";import*as O from"@stryke/capnp";import{readFileBuffer as k,readFileBufferSync as A,writeFileBuffer as j}from"@stryke/fs/buffer";import{prettyBytes as M}from"@stryke/string-format/pretty-bytes";import{Blob as N}from"node:buffer";import{fileURLToPath as P}from"node:url";import{format as F,resolveConfig as I}from"prettier";var L=class L{#e;#t;#n;#r={"":new o};#i;#a=!1;#o;#s;#c(e){let t=e;return T(t,this.#o.builtinsPath)&&(t=h(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:h(t,e),adapter:this.#r[e]};return{base:``,relativeKey:t,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>T(n,e)||t&&T(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(e){if(!e.config.skipCache&&S(l(e.dataPath,`fs.bin`))){let n=await k(l(e.dataPath,`fs.bin`)),r=new O.Message(n,!1).getRoot(t),i=new L(e,r);r._hasStorage()&&r.storage.length>0&&await Promise.all(r.storage.values().map(async e=>{await i.write(e.path,e.code)}))}return new L(e,new O.Message().initRoot(t))}static createSync(e){if(!e.config.skipCache&&S(l(e.dataPath,`fs.bin`))){let n=A(l(e.dataPath,`fs.bin`)),r=new O.Message(n,!1).getRoot(t),i=new L(e,r);r._hasStorage()&&r.storage.length>0&&r.storage.values().map(e=>{i.writeSync(e.path,e.code)})}return new L(e,new O.Message().initRoot(t))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=D({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,g(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 w(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 w((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(c.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);x(t)?await r.remove(n):await r.clear(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}removeSync(e){let t=this.#l(e);this.#s(c.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);x(t)?r.removeSync(n):r.clearSync(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}async glob(e){let t=[];for(let n of r(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...await this.list(e));else{let n=await this.resolve(e);n&&!t.includes(n)&&t.push(n)}continue}let r=E(e)?e:this.#l(l(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?b(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i)));await Promise.all((await this.list(a&&E(a)?a:this.#o.workspaceConfig.workspaceRoot)).map(async e=>{if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}))}return t}globSync(e){let t=[];for(let n of r(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...this.listSync(e));else{let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}continue}let r=E(e)?e:this.#l(l(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?b(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i))),o=this.listSync(a&&E(a)?a:this.#o.workspaceConfig.workspaceRoot);for(let e of o)if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}return t}async copy(e,t){let n=e instanceof URL?P(e):e,r=t instanceof URL?P(t):t;if(!_(n)&&(!g(n)||!_(n.input))||!_(r))return;let i=v(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=await this.resolve(i);if(a)if(this.isDirectorySync(a)||_(n)&&n.includes(`*`)||g(n)&&_(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,m(h(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(!_(n)&&(!g(n)||!_(n.input))||!_(r))return;let i=v(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=this.resolveSync(i);if(a)if(this.isDirectorySync(a)||_(n)&&n.includes(`*`)||g(n)&&_(n.glob))this.globSync(n).map(e=>this.copySync(e,m(b(h(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l(x(r)?r:m(y(a),r)),e,{skipFormat:!0})}}async move(e,t){x(e)?(await this.copy(e,t),await this.remove(e)):await Promise.all((await this.list(e)).map(async e=>{await this.copy(e,t),await this.remove(e)}))}moveSync(e,t){x(e)?(this.copySync(e,t),this.removeSync(e)):this.listSync(e).forEach(e=>{this.copySync(e,t),this.removeSync(e)})}async read(e){let t=await this.resolve(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(c.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(c.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(c.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(u(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(c.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(u(t)).size)})`);let a=n?.meta?.id||this.#c(r);return this.#e[a]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[a]=this.#l(r),this.#t[this.#l(r)]=a,i.setSync(r,t)}mkdirSync(e){return this.#d(e)?.adapter?.mkdirSync(e)}async mkdir(e){return this.#d(e)?.adapter?.mkdir(e)}getMetadata(e){let t=this.resolveSync(e);if(t&&this.metadata[t])return this.metadata[t]}async resolve(t,n,r={}){let i=t;if((i.includes(`{`)||i.includes(`}`))&&(i=e(this.#o,i)),E(i))return i;let a=C({path:this.#c(i),importer:n,options:r}),o;if(!this.#o.config.skipCache&&(o=this.resolverCache.get(a),o))return o;if(o=this.paths[this.#c(i)],!o){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push(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 d(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await f(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 d(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=p(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(c.DEBUG,`Disposing virtual file system...`),await this.remove(l(this.#o.dataPath,`fs.bin`));let e=new O.Message,n=e.initRoot(t),r=await this.list(),i=n._initStorage(r.length);await Promise.all(r.map(async(e,t)=>{let n=await this.read(e),r=i.get(t);r.path=e,r.code=n||``}));let a=n._initIds(Object.keys(this.ids).length);Object.entries(this.ids).filter(([,e])=>e).forEach(([e,t],n)=>{let r=a.get(n);r.id=e,r.path=t});let o=n._initMetadata(Object.keys(this.metadata).length);Object.entries(this.metadata).filter(([,e])=>e).forEach(([e,t],n)=>{let r=o.get(n);if(r.id=e,r.type=t.type,r.timestamp=t.timestamp??BigInt(Date.now()),t.properties){let e=r._initProperties(Object.keys(t.properties).length);Object.entries(t.properties).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await j(l(this.#o.dataPath,`fs.bin`),e.toArrayBuffer()),this.#o.config.skipCache||this.#i.save(!0),await Promise.all(this.#f().map(async e=>e.adapter.dispose())),this.#s(c.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{LogLevelLabel as c}from"@storm-software/config-tools/types";import{joinPaths as l}from"@stryke/path/join-paths";import{toArray as u}from"@stryke/convert/to-array";import{getResolutionCombinations as d,resolve as f,resolveSync as p}from"@stryke/fs/resolve";import{appendPath as m}from"@stryke/path/append";import{replacePath as h}from"@stryke/path/replace";import{isSetObject as g}from"@stryke/type-checks/is-set-object";import{isSetString as _}from"@stryke/type-checks/is-set-string";import{isString as v}from"@stryke/type-checks/is-string";import{findFileName as y,findFilePath as b,hasFileExtension as x}from"@stryke/path/file-path-fns";import{existsSync as S}from"@stryke/fs/exists";import{murmurhash as C}from"@stryke/hash/murmurhash";import{getUnique as w}from"@stryke/helpers/get-unique";import{isParentPath as T}from"@stryke/path/is-parent-path";import{isAbsolutePath as E}from"@stryke/path/is-type";import{create as D}from"flat-cache";import*as O from"@stryke/capnp";import{readFileBuffer as k,readFileBufferSync as A,writeFileBuffer as j}from"@stryke/fs/buffer";import{prettyBytes as M}from"@stryke/string-format/pretty-bytes";import{Blob as N}from"node:buffer";import{fileURLToPath as P}from"node:url";import{format as F,resolveConfig as I}from"prettier";var L=class L{#e;#t;#n;#r={"":new o};#i;#a=!1;#o;#s;#c(e){let t=e;return T(t,this.#o.builtinsPath)&&(t=h(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:h(t,e),adapter:this.#r[e]};return{base:``,relativeKey:t,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>T(n,e)||t&&T(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(e){if(!e.config.skipCache&&S(l(e.dataPath,`fs.bin`))){let n=await k(l(e.dataPath,`fs.bin`)),r=new O.Message(n,!1).getRoot(t),i=new L(e,r);r._hasStorage()&&r.storage.length>0&&await Promise.all(r.storage.values().map(async e=>{await i.write(e.path,e.code)}))}return new L(e,new O.Message().initRoot(t))}static createSync(e){if(!e.config.skipCache&&S(l(e.dataPath,`fs.bin`))){let n=A(l(e.dataPath,`fs.bin`)),r=new O.Message(n,!1).getRoot(t),i=new L(e,r);r._hasStorage()&&r.storage.length>0&&r.storage.values().map(e=>{i.writeSync(e.path,e.code)})}return new L(e,new O.Message().initRoot(t))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=D({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,g(this.#o.config.output.storage)&&(this.#r={...this.#r,...this.#o.config.output.storage}),this.#r.virtual??=new s({base:`/_virtual`}),this.#o.config.output.storage!==`fs`&&(this.#r[this.#o.artifactsPath]??=new s({base:this.#o.artifactsPath}),this.#r[this.#o.builtinsPath]??=new s({base:this.#o.builtinsPath}),this.#r[this.#o.entryPath]??=new s({base:this.#o.entryPath})),this.#e={},t._hasMetadata()&&(this.#e=t.metadata.values().reduce((e,t)=>(e[t.id]={id:t.id,type:t.type,timestamp:t.timestamp||Date.now(),properties:t._hasProperties()?t.properties.values().reduce((e,t)=>(e[t.key]=t.value,e),{}):{}},e),{}),e.config.skipCache!==!0&&Object.entries(this.#e).filter(([,e])=>e.type===`entry`).forEach(([e,t])=>{this.#o.entry??=[],this.#o.entry.push({file:e,name:t.properties.name,output:t.properties.output,input:t.properties[`input.file`]?{file:t.properties[`input.file`],name:t.properties[`input.name`]}:void 0})})),this.#t={},this.#n={},t._hasIds()&&(this.#t=t.ids.values().reduce((e,t)=>(e[t.path]??=t.id,e),{}),this.#n=t.ids.values().reduce((e,t)=>(e[t.id]??=t.path,e),{})),this.#s=n(this.#o.log,`file-system`)}async exists(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.exists(t)}existsSync(e){let{relativeKey:t,adapter:n}=this.#d(e);return n.existsSync(t)}isVirtual(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.name===`virtual`:!1}isDirectorySync(e){let t=this.resolveSync(e);return t?!!(this.existsSync(t)&&this.#d(t)?.adapter?.isDirectorySync(t)):!1}async isDirectory(e){let t=await this.resolve(e);return t?!!(await this.exists(t)&&await this.#d(t)?.adapter?.isDirectory(t)):!1}isFileSync(e){let t=this.resolveSync(e);return t?this.#d(t)?.adapter?.isFileSync(t)??!1:!1}async isFile(e){let t=await this.resolve(e);return t?await this.#d(t)?.adapter?.isFile(t)??!1:!1}listSync(e){return w(this.#f(e,!0).map(e=>e.adapter.listSync(e.relativeBase?e.base?m(e.relativeBase,e.base):e.relativeBase:e.base)).flat())}async list(e){return w((await Promise.all(this.#f(e,!0).map(async e=>e.adapter.list(e.relativeBase?e.base?m(e.relativeBase,e.base):e.relativeBase:e.base)))).flat())}async remove(e){let t=this.#l(e);this.#s(c.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);x(t)?await r.remove(n):await r.clear(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}removeSync(e){let t=this.#l(e);this.#s(c.TRACE,`Removing file: ${t}`);let{relativeKey:n,adapter:r}=this.#d(t);x(t)?r.removeSync(n):r.clearSync(n);let i=this.#t[t];i&&this.#e[i]&&(delete this.#e[i],delete this.#t[t],delete this.#n[i])}async glob(e){let t=[];for(let n of r(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...await this.list(e));else{let n=await this.resolve(e);n&&!t.includes(n)&&t.push(n)}continue}let r=E(e)?e:this.#l(l(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?b(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i)));await Promise.all((await this.list(a&&E(a)?a:this.#o.workspaceConfig.workspaceRoot)).map(async e=>{if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}))}return t}globSync(e){let t=[];for(let n of r(this.#o.workspaceConfig.workspaceRoot,e)){let e=this.#l(n);if(!/[*?[\]{}]/.test(e)&&!e.includes(`**`)){if(this.isDirectorySync(e))t.push(...this.listSync(e));else{let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}continue}let r=E(e)?e:this.#l(l(this.#o.workspaceConfig.workspaceRoot,e)),i=r.search(/[*?[\]{}]/),a=i===-1?b(r):r.slice(0,Math.max(0,r.lastIndexOf(`/`,i))),o=this.listSync(a&&E(a)?a:this.#o.workspaceConfig.workspaceRoot);for(let e of o)if(this.#u(r).test(e)){let n=this.resolveSync(e);n&&!t.includes(n)&&t.push(n)}}return t}async copy(e,t){let n=e instanceof URL?P(e):e,r=t instanceof URL?P(t):t;if(!_(n)&&(!g(n)||!_(n.input))||!_(r))return;let i=v(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=await this.resolve(i);if(a)if(this.isDirectorySync(a)||_(n)&&n.includes(`*`)||g(n)&&_(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,m(h(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(!_(n)&&(!g(n)||!_(n.input))||!_(r))return;let i=v(n)?n:n.input?n.input:this.#o.workspaceConfig.workspaceRoot,a=this.resolveSync(i);if(a)if(this.isDirectorySync(a)||_(n)&&n.includes(`*`)||g(n)&&_(n.glob))this.globSync(n).map(e=>this.copySync(e,m(b(h(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l(x(r)?r:m(y(a),r)),e,{skipFormat:!0})}}async move(e,t){x(e)?(await this.copy(e,t),await this.remove(e)):await Promise.all((await this.list(e)).map(async e=>{await this.copy(e,t),await this.remove(e)}))}moveSync(e,t){x(e)?(this.copySync(e,t),this.removeSync(e)):this.listSync(e).forEach(e=>{this.copySync(e,t),this.removeSync(e)})}async read(e){let t=await this.resolve(e);if(!t)return;let{relativeKey:n,adapter:r}=this.#d(t);return this.#s(c.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(c.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(c.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(u(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(c.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(u(t)).size)})`);let a=n?.meta?.id||this.#c(r);return this.#e[a]={variant:`normal`,timestamp:Date.now(),...n.meta??{}},this.#n[a]=this.#l(r),this.#t[this.#l(r)]=a,i.setSync(r,t)}mkdirSync(e){return this.#d(e)?.adapter?.mkdirSync(e)}async mkdir(e){return this.#d(e)?.adapter?.mkdir(e)}getMetadata(e){let t=this.resolveSync(e);if(t&&this.metadata[t])return this.metadata[t]}async resolve(t,n,r={}){let i=t;if((i.includes(`{`)||i.includes(`}`))&&(i=e(this.#o,i)),E(i))return i;let a=C({path:this.#c(i),importer:n,options:r}),o;if(!this.#o.config.skipCache&&(o=this.resolverCache.get(a),o))return o;if(o=this.paths[this.#c(i)],!o){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push(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 d(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await f(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 d(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=p(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(c.DEBUG,`Disposing virtual file system...`),await this.remove(l(this.#o.dataPath,`fs.bin`));let e=new O.Message,n=e.initRoot(t),r=await this.list(),i=n._initStorage(r.length);await Promise.all(r.map(async(e,t)=>{let n=await this.read(e),r=i.get(t);r.path=e,r.code=n||``}));let a=n._initIds(Object.keys(this.ids).length);Object.entries(this.ids).filter(([,e])=>e).forEach(([e,t],n)=>{let r=a.get(n);r.id=e,r.path=t});let o=n._initMetadata(Object.keys(this.metadata).length);Object.entries(this.metadata).filter(([,e])=>e).forEach(([e,t],n)=>{let r=o.get(n);if(r.id=e,r.type=t.type,r.timestamp=t.timestamp??BigInt(Date.now()),t.properties){let e=r._initProperties(Object.keys(t.properties).length);Object.entries(t.properties).filter(([,e])=>_(e)).forEach(([t,n],r)=>{let i=e.get(r);i.key=t,i.value=n})}}),await j(l(this.#o.dataPath,`fs.bin`),e.toArrayBuffer()),this.#o.config.skipCache||this.#i.save(!0),await Promise.all(this.#f().map(async e=>e.adapter.dispose())),this.#s(c.TRACE,`Virtual file system has been disposed.`)}}async[Symbol.asyncDispose](){return this.dispose()}};export{L as VirtualFileSystem};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../types/commands.cjs`);let n=require(`@stryke/type-checks/is-function`),r=require(`@stryke/type-checks/is-set-object`),i=require(`@stryke/type-checks/is-set-string`),a=require(`@stryke/type-checks/is-undefined`);function o(e){return(0,r.isSetObject)(e)&&`name`in e&&(0,i.isSetString)(e.name)&&((0,a.isUndefined)(e.applyToEnvironment)||`applyToEnvironment`in e&&(0,n.isFunction)(e.applyToEnvironment))&&((0,a.isUndefined)(e.dedupe)||`dedupe`in e&&(0,n.isFunction)(e.dedupe))&&((0,a.isUndefined)(e.dependsOn)||`dependsOn`in e&&Array.isArray(e.dependsOn)&&e.dependsOn.every(l))&&t.SUPPORTED_COMMANDS.every(t=>(0,a.isUndefined)(e[t])||t in e&&((0,n.isFunction)(e[t])||(0,r.isSetObject)(e[t])&&`handler`in e[t]&&(0,n.isFunction)(e[t].handler)))}function s(e){return(0,r.isSetObject)(e)&&`plugin`in e&&(((0,i.isSetString)(e.plugin)||(0,n.isFunction)(e.plugin))&&`options`in e&&(0,r.isSetObject)(e.options)||o(e.plugin))}function c(e){return Array.isArray(e)&&(e.length===1||e.length===2)&&(((0,i.isSetString)(e[0])||(0,n.isFunction)(e[0]))&&e.length>1&&(0,r.isSetObject)(e[1])||o(e[0]))}function l(e){return(0,i.isSetString)(e)||(0,n.isFunction)(e)||o(e)||s(e)||c(e)}function u(e){return(0,n.isFunction)(e)||(0,r.isSetObject)(e)&&`handler`in e&&(0,n.isFunction)(e.handler)}function d(e){return(0,r.isSetObject)(e)&&`handler`in e&&(0,n.isFunction)(e.handler)}function f(e){return u(e)||d(e)}function p(e){return(0,n.isFunction)(e)?e:e.handler}function m(e){return e.startsWith(`vite:`)||e.startsWith(`esbuild:`)||e.startsWith(`rolldown:`)||e.startsWith(`rollup:`)||e.startsWith(`webpack:`)||e.startsWith(`rspack:`)||e.startsWith(`farm:`)}function h(e,t){return e.dedupe===!1||t.some(t=>t.dedupe!==!1&&((0,n.isFunction)(t.dedupe)&&t.dedupe(e)||t.name===e.name))}function g(e,t,r,i){h(t,i.map(e=>e.plugin))||i.push((0,n.isFunction)(r)?{plugin:t,handler:p(r).bind(e)}:{plugin:t,...r,handler:p(r).bind(e)})}exports.addPluginHook=g,exports.checkDedupe=h,exports.getHookHandler=p,exports.isHookExternal=m,exports.isPlugin=o,exports.isPluginConfig=l,exports.isPluginConfigObject=s,exports.isPluginConfigTuple=c,exports.isPluginHook=f;
|
|
1
|
+
const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../types/commands.cjs`);let n=require(`@stryke/type-checks/is-function`),r=require(`@stryke/type-checks/is-set-object`),i=require(`@stryke/type-checks/is-set-string`),a=require(`@stryke/type-checks/is-undefined`);function o(e){return(0,r.isSetObject)(e)&&`name`in e&&(0,i.isSetString)(e.name)&&((0,a.isUndefined)(e.applyToEnvironment)||`applyToEnvironment`in e&&(0,n.isFunction)(e.applyToEnvironment))&&((0,a.isUndefined)(e.dedupe)||`dedupe`in e&&(0,n.isFunction)(e.dedupe))&&((0,a.isUndefined)(e.dependsOn)||`dependsOn`in e&&Array.isArray(e.dependsOn)&&e.dependsOn.every(l))&&t.SUPPORTED_COMMANDS.every(t=>(0,a.isUndefined)(e[t])||t in e&&((0,n.isFunction)(e[t])||(0,r.isSetObject)(e[t])&&`handler`in e[t]&&(0,n.isFunction)(e[t].handler)))}function s(e){return(0,r.isSetObject)(e)&&`plugin`in e&&(((0,i.isSetString)(e.plugin)||(0,n.isFunction)(e.plugin))&&`options`in e&&(0,r.isSetObject)(e.options)||o(e.plugin))}function c(e){return Array.isArray(e)&&(e.length===1||e.length===2)&&(((0,i.isSetString)(e[0])||(0,n.isFunction)(e[0]))&&e.length>1&&(0,r.isSetObject)(e[1])||o(e[0]))}function l(e){return(0,i.isSetString)(e)||(0,n.isFunction)(e)||o(e)||Array.isArray(e)&&e.every(e=>o(e))||s(e)||c(e)}function u(e){return(0,n.isFunction)(e)||(0,r.isSetObject)(e)&&`handler`in e&&(0,n.isFunction)(e.handler)}function d(e){return(0,r.isSetObject)(e)&&`handler`in e&&(0,n.isFunction)(e.handler)}function f(e){return u(e)||d(e)}function p(e){return(0,n.isFunction)(e)?e:e.handler}function m(e){return e.startsWith(`vite:`)||e.startsWith(`esbuild:`)||e.startsWith(`rolldown:`)||e.startsWith(`rollup:`)||e.startsWith(`webpack:`)||e.startsWith(`rspack:`)||e.startsWith(`farm:`)}function h(e,t){return e.dedupe===!1||t.some(t=>t.dedupe!==!1&&((0,n.isFunction)(t.dedupe)&&t.dedupe(e)||t.name===e.name))}function g(e,t,r,i){h(t,i.map(e=>e.plugin))||i.push((0,n.isFunction)(r)?{plugin:t,handler:p(r).bind(e)}:{plugin:t,...r,handler:p(r).bind(e)})}exports.addPluginHook=g,exports.checkDedupe=h,exports.getHookHandler=p,exports.isHookExternal=m,exports.isPlugin=o,exports.isPluginConfig=l,exports.isPluginConfigObject=s,exports.isPluginConfigTuple=c,exports.isPluginHook=f;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SUPPORTED_COMMANDS as e}from"../types/commands.mjs";import{isFunction as t}from"@stryke/type-checks/is-function";import{isSetObject as n}from"@stryke/type-checks/is-set-object";import{isSetString as r}from"@stryke/type-checks/is-set-string";import{isUndefined as i}from"@stryke/type-checks/is-undefined";function a(a){return n(a)&&`name`in a&&r(a.name)&&(i(a.applyToEnvironment)||`applyToEnvironment`in a&&t(a.applyToEnvironment))&&(i(a.dedupe)||`dedupe`in a&&t(a.dedupe))&&(i(a.dependsOn)||`dependsOn`in a&&Array.isArray(a.dependsOn)&&a.dependsOn.every(c))&&e.every(e=>i(a[e])||e in a&&(t(a[e])||n(a[e])&&`handler`in a[e]&&t(a[e].handler)))}function o(e){return n(e)&&`plugin`in e&&((r(e.plugin)||t(e.plugin))&&`options`in e&&n(e.options)||a(e.plugin))}function s(e){return Array.isArray(e)&&(e.length===1||e.length===2)&&((r(e[0])||t(e[0]))&&e.length>1&&n(e[1])||a(e[0]))}function c(e){return r(e)||t(e)||a(e)||o(e)||s(e)}function l(e){return t(e)||n(e)&&`handler`in e&&t(e.handler)}function u(e){return n(e)&&`handler`in e&&t(e.handler)}function d(e){return l(e)||u(e)}function f(e){return t(e)?e:e.handler}function p(e){return e.startsWith(`vite:`)||e.startsWith(`esbuild:`)||e.startsWith(`rolldown:`)||e.startsWith(`rollup:`)||e.startsWith(`webpack:`)||e.startsWith(`rspack:`)||e.startsWith(`farm:`)}function m(e,n){return e.dedupe===!1||n.some(n=>n.dedupe!==!1&&(t(n.dedupe)&&n.dedupe(e)||n.name===e.name))}function h(e,n,r,i){m(n,i.map(e=>e.plugin))||i.push(t(r)?{plugin:n,handler:f(r).bind(e)}:{plugin:n,...r,handler:f(r).bind(e)})}export{h as addPluginHook,m as checkDedupe,f as getHookHandler,p as isHookExternal,a as isPlugin,c as isPluginConfig,o as isPluginConfigObject,s as isPluginConfigTuple,d as isPluginHook};
|
|
1
|
+
import{SUPPORTED_COMMANDS as e}from"../types/commands.mjs";import{isFunction as t}from"@stryke/type-checks/is-function";import{isSetObject as n}from"@stryke/type-checks/is-set-object";import{isSetString as r}from"@stryke/type-checks/is-set-string";import{isUndefined as i}from"@stryke/type-checks/is-undefined";function a(a){return n(a)&&`name`in a&&r(a.name)&&(i(a.applyToEnvironment)||`applyToEnvironment`in a&&t(a.applyToEnvironment))&&(i(a.dedupe)||`dedupe`in a&&t(a.dedupe))&&(i(a.dependsOn)||`dependsOn`in a&&Array.isArray(a.dependsOn)&&a.dependsOn.every(c))&&e.every(e=>i(a[e])||e in a&&(t(a[e])||n(a[e])&&`handler`in a[e]&&t(a[e].handler)))}function o(e){return n(e)&&`plugin`in e&&((r(e.plugin)||t(e.plugin))&&`options`in e&&n(e.options)||a(e.plugin))}function s(e){return Array.isArray(e)&&(e.length===1||e.length===2)&&((r(e[0])||t(e[0]))&&e.length>1&&n(e[1])||a(e[0]))}function c(e){return r(e)||t(e)||a(e)||Array.isArray(e)&&e.every(e=>a(e))||o(e)||s(e)}function l(e){return t(e)||n(e)&&`handler`in e&&t(e.handler)}function u(e){return n(e)&&`handler`in e&&t(e.handler)}function d(e){return l(e)||u(e)}function f(e){return t(e)?e:e.handler}function p(e){return e.startsWith(`vite:`)||e.startsWith(`esbuild:`)||e.startsWith(`rolldown:`)||e.startsWith(`rollup:`)||e.startsWith(`webpack:`)||e.startsWith(`rspack:`)||e.startsWith(`farm:`)}function m(e,n){return e.dedupe===!1||n.some(n=>n.dedupe!==!1&&(t(n.dedupe)&&n.dedupe(e)||n.name===e.name))}function h(e,n,r,i){m(n,i.map(e=>e.plugin))||i.push(t(r)?{plugin:n,handler:f(r).bind(e)}:{plugin:n,...r,handler:f(r).bind(e)})}export{h as addPluginHook,m as checkDedupe,f as getHookHandler,p as isHookExternal,a as isPlugin,c as isPluginConfig,o as isPluginConfigObject,s as isPluginConfigTuple,d as isPluginHook};
|
|
@@ -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
|
|
@@ -18,7 +18,7 @@ type LogFn = (type: LogLevelLabel, ...args: string[]) => void;
|
|
|
18
18
|
* The {@link StormWorkspaceConfig | configuration} object for an entire Powerlines workspace
|
|
19
19
|
*/
|
|
20
20
|
type WorkspaceConfig = Partial<StormWorkspaceConfig> & Required<Pick<StormWorkspaceConfig, "workspaceRoot">>;
|
|
21
|
-
type PluginFactory<in out TContext extends PluginContext = PluginContext, TOptions = any> = (options: TOptions) => MaybePromise<Plugin<TContext
|
|
21
|
+
type PluginFactory<in out TContext extends PluginContext = PluginContext, TOptions = any> = (options: TOptions) => MaybePromise<Plugin<TContext> | Plugin<TContext>[]>;
|
|
22
22
|
/**
|
|
23
23
|
* A configuration tuple for a Powerlines plugin.
|
|
24
24
|
*/
|
|
@@ -36,7 +36,7 @@ type PluginConfigObject<TContext extends PluginContext = PluginContext, TOptions
|
|
|
36
36
|
/**
|
|
37
37
|
* A configuration tuple for a Powerlines plugin.
|
|
38
38
|
*/
|
|
39
|
-
type PluginConfig<TContext extends PluginContext = PluginContext> = string | PluginFactory<TContext, void> | Plugin<TContext> | Promise<Plugin<TContext
|
|
39
|
+
type PluginConfig<TContext extends PluginContext = PluginContext> = string | PluginFactory<TContext, void> | Plugin<TContext> | Plugin<TContext>[] | Promise<Plugin<TContext> | Plugin<TContext>[]> | PluginConfigTuple<TContext> | PluginConfigObject<TContext>;
|
|
40
40
|
type ProjectType = "application" | "library";
|
|
41
41
|
interface DeployConfig {
|
|
42
42
|
/**
|
|
@@ -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
|
|
@@ -20,7 +19,7 @@ type LogFn = (type: LogLevelLabel, ...args: string[]) => void;
|
|
|
20
19
|
* The {@link StormWorkspaceConfig | configuration} object for an entire Powerlines workspace
|
|
21
20
|
*/
|
|
22
21
|
type WorkspaceConfig = Partial<StormWorkspaceConfig> & Required<Pick<StormWorkspaceConfig, "workspaceRoot">>;
|
|
23
|
-
type PluginFactory<in out TContext extends PluginContext = PluginContext, TOptions = any> = (options: TOptions) => MaybePromise<Plugin<TContext
|
|
22
|
+
type PluginFactory<in out TContext extends PluginContext = PluginContext, TOptions = any> = (options: TOptions) => MaybePromise<Plugin<TContext> | Plugin<TContext>[]>;
|
|
24
23
|
/**
|
|
25
24
|
* A configuration tuple for a Powerlines plugin.
|
|
26
25
|
*/
|
|
@@ -38,7 +37,7 @@ type PluginConfigObject<TContext extends PluginContext = PluginContext, TOptions
|
|
|
38
37
|
/**
|
|
39
38
|
* A configuration tuple for a Powerlines plugin.
|
|
40
39
|
*/
|
|
41
|
-
type PluginConfig<TContext extends PluginContext = PluginContext> = string | PluginFactory<TContext, void> | Plugin<TContext> | Promise<Plugin<TContext
|
|
40
|
+
type PluginConfig<TContext extends PluginContext = PluginContext> = string | PluginFactory<TContext, void> | Plugin<TContext> | Plugin<TContext>[] | Promise<Plugin<TContext> | Plugin<TContext>[]> | PluginConfigTuple<TContext> | PluginConfigObject<TContext>;
|
|
42
41
|
type ProjectType = "application" | "library";
|
|
43
42
|
interface DeployConfig {
|
|
44
43
|
/**
|
|
@@ -6,7 +6,6 @@ import { ExternalIdResult, UnpluginBuildContext, UnpluginContext, UnpluginMessag
|
|
|
6
6
|
import { EnvPaths } from "@stryke/env/get-env-paths";
|
|
7
7
|
import { FetchRequestOptions } from "@stryke/http/fetch";
|
|
8
8
|
import { NonUndefined } from "@stryke/types/base";
|
|
9
|
-
import { TypeDefinition } from "@stryke/types/configuration";
|
|
10
9
|
import { PackageJson } from "@stryke/types/package-json";
|
|
11
10
|
import { Jiti } from "jiti";
|
|
12
11
|
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-rspack",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.102",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing a Powerlines plugin to build projects using Webpack.",
|
|
6
6
|
"repository": {
|
|
@@ -152,13 +152,13 @@
|
|
|
152
152
|
"@stryke/types": "^0.10.28",
|
|
153
153
|
"defu": "^6.1.4",
|
|
154
154
|
"jiti": "^2.6.1",
|
|
155
|
-
"powerlines": "^0.
|
|
155
|
+
"powerlines": "^0.35.1"
|
|
156
156
|
},
|
|
157
157
|
"devDependencies": {
|
|
158
|
-
"@powerlines/nx": "^0.11.
|
|
159
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
158
|
+
"@powerlines/nx": "^0.11.24",
|
|
159
|
+
"@powerlines/plugin-plugin": "^0.12.45",
|
|
160
160
|
"@types/node": "^24.10.4"
|
|
161
161
|
},
|
|
162
162
|
"publishConfig": { "access": "public" },
|
|
163
|
-
"gitHead": "
|
|
163
|
+
"gitHead": "02f049f03f9e12a6fd5263ea8cbee3cdb6f896a3"
|
|
164
164
|
}
|