@powerlines/plugin-tsdown 0.1.35 โ 0.1.36
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 +3 -3
- package/dist/powerlines/src/api.mjs +1 -1
- package/dist/powerlines/src/internal/helpers/resolve-tsconfig.cjs +1 -1
- package/dist/powerlines/src/internal/helpers/resolve-tsconfig.mjs +1 -1
- package/dist/powerlines/src/lib/build/tsdown.cjs +1 -1
- package/dist/powerlines/src/lib/build/tsdown.mjs +1 -1
- package/dist/powerlines/src/lib/entry.cjs +1 -1
- package/dist/powerlines/src/lib/entry.mjs +1 -1
- package/dist/powerlines/src/lib/fs/vfs.cjs +1 -1
- package/dist/powerlines/src/lib/fs/vfs.mjs +1 -1
- package/dist/powerlines/src/lib/utilities/meta.cjs +1 -1
- package/dist/powerlines/src/lib/utilities/meta.mjs +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/convert/to-array`),p=require(`@stryke/path/append`),m=require(`@stryke/type-checks/is-set-string`),
|
|
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,
|
|
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/convert/to-array`),p=require(`@stryke/path/append`),m=require(`@stryke/path/join-paths`),h=require(`@stryke/type-checks/is-set-string`),g=require(`@babel/core`),_=require(`@storm-software/config-tools/logger/console`),v=require(`@stryke/fs/helpers`),y=require(`@stryke/fs/install`),b=require(`@stryke/fs/list-files`),x=require(`@stryke/fs/package-fns`),S=require(`@stryke/fs/resolve`),C=require(`@stryke/path/replace`),w=require(`@stryke/type-checks/is-error`),T=require(`@stryke/type-checks/is-function`),E=require(`@stryke/type-checks/is-number`),D=require(`@stryke/type-checks/is-object`),O=require(`@stryke/type-checks/is-promise`),k=require(`@stryke/type-checks/is-set`),A=require(`@stryke/type-checks/is-set-object`),j=require(`chalk`);j=e.__toESM(j);let M=require(`handlebars`);M=e.__toESM(M);var N=class e{#e;get context(){return this.#e}constructor(e){this.#e=e}static async from(t,n){let r=new e(await l.PowerlinesAPIContext.from(t,n));r.#e.$$internal={api:r,addPlugin:r.#i.bind(r)};for(let e of r.context.config.plugins??[])await r.#i(e);r.context.plugins.length===0&&r.context.log(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,f.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.input.file||e.file}${e.output?` -> ${e.output}`:``}`).join(`
|
|
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,_.formatLogMessage)(e.config)}`),e.fs.existsSync(e.cachePath)||await(0,v.createDirectory)(e.cachePath),e.fs.existsSync(e.dataPath)||await(0,v.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,g.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,S.resolvePackage)(`typescript`))throw Error(`Could not resolve TypeScript package location. Please ensure TypeScript is installed.`);let i=r.reduce((t,n)=>{let r=(0,C.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,D.isObject)(e)?e.code:e,f=await this.callHook(`types`,{environment:e,sequential:!0,order:`pre`,result:`merge`,asNextParam:l},s);if(f&&((0,A.isSetObject)(f)?(s=f.code,Array.isArray(f.directives)&&f.directives.length>0&&c.push(...f.directives)):(0,h.isSetString)(f)&&(s=f)),f=await this.callHook(`types`,{environment:e,sequential:!0,order:`normal`,result:`merge`,asNextParam:l},s),f&&((0,A.isSetObject)(f)?(s=f.code,Array.isArray(f.directives)&&f.directives.length>0&&c.push(...f.directives)):(0,h.isSetString)(f)&&(s=f)),f=await this.callHook(`types`,{environment:e,sequential:!0,order:`post`,result:`merge`,asNextParam:l},s),f&&((0,A.isSetObject)(f)?(s=f.code,Array.isArray(f.directives)&&f.directives.length>0&&c.push(...f.directives)):(0,h.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,
|
|
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,b.listFiles)((0,m.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,m.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,b.listFiles)((0,m.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,m.joinPaths)(e.config.projectRoot,n.replace(`.hbs`,``)),t(e))}}else{let t=await(0,b.listFiles)((0,m.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,m.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,m.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.output.buildPath)),await e.fs.remove((0,m.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,A.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,p.appendPath)(e.config.output.buildPath,e.workspaceConfig.workspaceRoot),n=(0,m.joinPaths)((0,p.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,m.joinPaths)((0,C.replacePath)(t.input,e.workspaceConfig.workspaceRoot),t.glob))} -> ${j.default.greenBright((0,m.joinPaths)((0,C.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,k.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(t.dependsOn)for(let e of t.dependsOn)await this.#i(e);this.context.log(d.LogLevelLabel.DEBUG,`Successfully initialized the ${j.default.bold.cyanBright(t.name)} plugin`),await this.context.addPlugin(t)}}async#a(e){let t=e;if((0,O.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(s.isPlugin(t))n=t;else if((0,T.isFunction)(t))n=await Promise.resolve(t());else if((0,h.isSetString)(t)){let e=await this.#o(t);n=(0,T.isFunction)(e)?await Promise.resolve(e()):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,h.isSetString)(e)){let t=await this.#o(e);n=(0,T.isFunction)(t)?await Promise.resolve(r?t(r):t()):t}else (0,T.isFunction)(e)?n=await Promise.resolve(e(r)):s.isPlugin(e)&&(n=e)}if(!n)throw Error(`The plugin configuration ${JSON.stringify(t)} is invalid. This configuration must point to a valid Powerlines plugin module.`);if(!s.isPlugin(n))throw Error(`The plugin option ${JSON.stringify(n)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);return s.checkDedupe(n,this.context.plugins)?(this.context.log(d.LogLevelLabel.TRACE,`Duplicate ${j.default.bold.cyanBright(n.name)} plugin dependency detected - Skipping initialization.`),null):(this.context.log(d.LogLevelLabel.TRACE,`Initializing the ${j.default.bold.cyanBright(n.name)} plugin...`),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,x.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,y.install)(e,{cwd:this.context.config.projectRoot});if((0,E.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,m.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,w.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
|
-
import{moduleResolverBabelPlugin as e}from"./internal/babel/module-resolver-plugin.mjs";import{emitTypes as t,formatTypes as n}from"./internal/helpers/generate-types.mjs";import{callHook as r}from"./internal/helpers/hooks.mjs";import{installDependencies as i}from"./internal/helpers/install-dependencies.mjs";import{getParsedTypeScriptConfig as a,isIncludeMatchFound as o}from"./lib/typescript/tsconfig.mjs";import{getTsconfigDtsPath as s,initializeTsconfig as c,resolveTsconfig as l}from"./internal/helpers/resolve-tsconfig.mjs";import{checkDedupe as u,isPlugin as d,isPluginConfig as f,isPluginConfigObject as p,isPluginConfigTuple as m}from"./plugin-utils/helpers.mjs";import{writeMetaFile as h}from"./lib/utilities/meta.mjs";import{PowerlinesAPIContext as g}from"./lib/contexts/api-context.mjs";import{getFileHeader as _}from"./lib/utilities/file-header.mjs";import{LogLevelLabel as v}from"@storm-software/config-tools/types";import{toArray as y}from"@stryke/convert/to-array";import{appendPath as b}from"@stryke/path/append";import{
|
|
1
|
+
import{moduleResolverBabelPlugin as e}from"./internal/babel/module-resolver-plugin.mjs";import{emitTypes as t,formatTypes as n}from"./internal/helpers/generate-types.mjs";import{callHook as r}from"./internal/helpers/hooks.mjs";import{installDependencies as i}from"./internal/helpers/install-dependencies.mjs";import{getParsedTypeScriptConfig as a,isIncludeMatchFound as o}from"./lib/typescript/tsconfig.mjs";import{getTsconfigDtsPath as s,initializeTsconfig as c,resolveTsconfig as l}from"./internal/helpers/resolve-tsconfig.mjs";import{checkDedupe as u,isPlugin as d,isPluginConfig as f,isPluginConfigObject as p,isPluginConfigTuple as m}from"./plugin-utils/helpers.mjs";import{writeMetaFile as h}from"./lib/utilities/meta.mjs";import{PowerlinesAPIContext as g}from"./lib/contexts/api-context.mjs";import{getFileHeader as _}from"./lib/utilities/file-header.mjs";import{LogLevelLabel as v}from"@storm-software/config-tools/types";import{toArray as y}from"@stryke/convert/to-array";import{appendPath as b}from"@stryke/path/append";import{joinPaths as x}from"@stryke/path/join-paths";import{isSetString as S}from"@stryke/type-checks/is-set-string";import{transformAsync as C}from"@babel/core";import{formatLogMessage as w}from"@storm-software/config-tools/logger/console";import{createDirectory as T}from"@stryke/fs/helpers";import{install as E}from"@stryke/fs/install";import{listFiles as D}from"@stryke/fs/list-files";import{isPackageExists as O}from"@stryke/fs/package-fns";import{resolvePackage as k}from"@stryke/fs/resolve";import{replacePath as A}from"@stryke/path/replace";import{isError as j}from"@stryke/type-checks/is-error";import{isFunction as M}from"@stryke/type-checks/is-function";import{isNumber as N}from"@stryke/type-checks/is-number";import{isObject as P}from"@stryke/type-checks/is-object";import{isPromiseLike as F}from"@stryke/type-checks/is-promise";import{isSet as I}from"@stryke/type-checks/is-set";import{isSetObject as L}from"@stryke/type-checks/is-set-object";import R from"chalk";import z from"handlebars";Symbol.asyncDispose;export{};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../../lib/typescript/tsconfig.cjs`);let n=require(`@storm-software/config-tools/types`),r=require(`@stryke/
|
|
1
|
+
const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../../lib/typescript/tsconfig.cjs`);let n=require(`@storm-software/config-tools/types`),r=require(`@stryke/path/join-paths`),i=require(`@stryke/fs/package-fns`),a=require(`chalk`);a=e.__toESM(a);let o=require(`@donedeal0/superdiff`),s=require(`@stryke/fs/json`),c=require(`@stryke/json/storm-json`),l=require(`@stryke/path/file-path-fns`),u=require(`@stryke/string-format/title-case`);function d(e){return(0,r.joinPaths)((0,l.relativePath)((0,r.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.projectRoot),(0,l.findFilePath)(e.dtsPath)),(0,l.findFileName)(e.dtsPath))}async function f(e){let n=t.getParsedTypeScriptConfig(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig,e.config.tsconfigRaw),r=await(0,s.readJsonFile)(t.getTsconfigFilePath(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig));if(r.compilerOptions??={},e.config.output.dts!==!1){let n=d(e);r.include?.some(r=>t.isIncludeMatchFound(r,[e.dtsPath,n]))||(r.include??=[],r.include.push(n.startsWith(`./`)?n.slice(2):n))}return n.options.lib?.some(e=>[`lib.esnext.d.ts`,`lib.es2021.d.ts`,`lib.es2022.d.ts`,`lib.es2023.d.ts`].includes(e.toLowerCase()))||(r.compilerOptions.lib??=[],r.compilerOptions.lib.push(`esnext`)),n.options.esModuleInterop!==!0&&(r.compilerOptions.esModuleInterop=!0),n.options.isolatedModules!==!0&&(r.compilerOptions.isolatedModules=!0),e.config.build.platform===`node`&&(n.options.types?.some(e=>e.toLowerCase()===`node`||e.toLowerCase()===`@types/node`)||(r.compilerOptions.types??=[],r.compilerOptions.types.push(`node`))),r}async function p(e){if(e.log(n.LogLevelLabel.TRACE,`Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.`),!(0,i.isPackageExists)(`typescript`))throw Error(`The TypeScript package is not installed. Please install the package using the command: "npm install typescript --save-dev"`);let r=t.getTsconfigFilePath(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig);e.tsconfig.originalTsconfigJson=await(0,s.readJsonFile)(r),e.tsconfig.tsconfigJson=await f(e),e.log(n.LogLevelLabel.TRACE,`Writing updated TypeScript configuration (tsconfig.json) file to disk.`),await e.fs.write(r,c.StormJSON.stringify(e.tsconfig.tsconfigJson)),e.tsconfig=t.getParsedTypeScriptConfig(e.workspaceConfig.workspaceRoot,e.config.projectRoot,e.config.tsconfig,e.config.tsconfigRaw,e.tsconfig.originalTsconfigJson)}async function m(e){let r=await(0,s.readJsonFile)(e.tsconfig.tsconfigFilePath);r?.compilerOptions?.types&&Array.isArray(r.compilerOptions.types)&&!r.compilerOptions.types.length&&delete r.compilerOptions.types;let i=(0,o.getObjectDiff)(e.tsconfig.originalTsconfigJson,r,{ignoreArrayOrder:!0,showOnly:{statuses:[`added`,`deleted`,`updated`],granularity:`deep`}}),l=[],d=(e,t)=>{if(e.status===`added`||e.status===`deleted`||e.status===`updated`)if(e.diff)for(let n of e.diff)d(n,t?`${t}.${e.property}`:e.property);else l.push({field:t?`${t}.${e.property}`:e.property,status:e.status,previous:e.status===`added`?`---`:c.StormJSON.stringify(e.previousValue),current:e.status===`deleted`?`---`:c.StormJSON.stringify(e.currentValue)})};for(let e of i.diff)d(e);if(l.length>0&&e.log(n.LogLevelLabel.WARN,`Updating the following configuration values in "${e.tsconfig.tsconfigFilePath}" file:
|
|
2
2
|
|
|
3
3
|
${l.map((e,t)=>`${a.default.bold.whiteBright(`${t+1}. ${(0,u.titleCase)(e.status)} the ${e.field} field: `)}
|
|
4
4
|
${a.default.red(` - Previous: ${e.previous} `)}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{getParsedTypeScriptConfig as e,getTsconfigFilePath as t,isIncludeMatchFound as n}from"../../lib/typescript/tsconfig.mjs";import{LogLevelLabel as r}from"@storm-software/config-tools/types";import{
|
|
1
|
+
import{getParsedTypeScriptConfig as e,getTsconfigFilePath as t,isIncludeMatchFound as n}from"../../lib/typescript/tsconfig.mjs";import{LogLevelLabel as r}from"@storm-software/config-tools/types";import{joinPaths as i}from"@stryke/path/join-paths";import{isPackageExists as a}from"@stryke/fs/package-fns";import o from"chalk";import{getObjectDiff as s}from"@donedeal0/superdiff";import{readJsonFile as c}from"@stryke/fs/json";import{StormJSON as l}from"@stryke/json/storm-json";import{findFileName as u,findFilePath as d,relativePath as f}from"@stryke/path/file-path-fns";import{titleCase as p}from"@stryke/string-format/title-case";function m(e){return i(f(i(e.workspaceConfig.workspaceRoot,e.config.projectRoot),d(e.dtsPath)),u(e.dtsPath))}async function h(r){let i=e(r.workspaceConfig.workspaceRoot,r.config.projectRoot,r.config.tsconfig,r.config.tsconfigRaw),a=await c(t(r.workspaceConfig.workspaceRoot,r.config.projectRoot,r.config.tsconfig));if(a.compilerOptions??={},r.config.output.dts!==!1){let e=m(r);a.include?.some(t=>n(t,[r.dtsPath,e]))||(a.include??=[],a.include.push(e.startsWith(`./`)?e.slice(2):e))}return i.options.lib?.some(e=>[`lib.esnext.d.ts`,`lib.es2021.d.ts`,`lib.es2022.d.ts`,`lib.es2023.d.ts`].includes(e.toLowerCase()))||(a.compilerOptions.lib??=[],a.compilerOptions.lib.push(`esnext`)),i.options.esModuleInterop!==!0&&(a.compilerOptions.esModuleInterop=!0),i.options.isolatedModules!==!0&&(a.compilerOptions.isolatedModules=!0),r.config.build.platform===`node`&&(i.options.types?.some(e=>e.toLowerCase()===`node`||e.toLowerCase()===`@types/node`)||(a.compilerOptions.types??=[],a.compilerOptions.types.push(`node`))),a}async function g(n){if(n.log(r.TRACE,`Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.`),!a(`typescript`))throw Error(`The TypeScript package is not installed. Please install the package using the command: "npm install typescript --save-dev"`);let i=t(n.workspaceConfig.workspaceRoot,n.config.projectRoot,n.config.tsconfig);n.tsconfig.originalTsconfigJson=await c(i),n.tsconfig.tsconfigJson=await h(n),n.log(r.TRACE,`Writing updated TypeScript configuration (tsconfig.json) file to disk.`),await n.fs.write(i,l.stringify(n.tsconfig.tsconfigJson)),n.tsconfig=e(n.workspaceConfig.workspaceRoot,n.config.projectRoot,n.config.tsconfig,n.config.tsconfigRaw,n.tsconfig.originalTsconfigJson)}async function _(t){let n=await c(t.tsconfig.tsconfigFilePath);n?.compilerOptions?.types&&Array.isArray(n.compilerOptions.types)&&!n.compilerOptions.types.length&&delete n.compilerOptions.types;let i=s(t.tsconfig.originalTsconfigJson,n,{ignoreArrayOrder:!0,showOnly:{statuses:[`added`,`deleted`,`updated`],granularity:`deep`}}),a=[],u=(e,t)=>{if(e.status===`added`||e.status===`deleted`||e.status===`updated`)if(e.diff)for(let n of e.diff)u(n,t?`${t}.${e.property}`:e.property);else a.push({field:t?`${t}.${e.property}`:e.property,status:e.status,previous:e.status===`added`?`---`:l.stringify(e.previousValue),current:e.status===`deleted`?`---`:l.stringify(e.currentValue)})};for(let e of i.diff)u(e);if(a.length>0&&t.log(r.WARN,`Updating the following configuration values in "${t.tsconfig.tsconfigFilePath}" file:
|
|
2
2
|
|
|
3
3
|
${a.map((e,t)=>`${o.bold.whiteBright(`${t+1}. ${p(e.status)} the ${e.field} field: `)}
|
|
4
4
|
${o.red(` - Previous: ${e.previous} `)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`defu`);t=e.__toESM(t);let n=require(`@stryke/convert/
|
|
1
|
+
const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`defu`);t=e.__toESM(t);let n=require(`@stryke/convert/to-array`),r=require(`@stryke/helpers/omit`),i=require(`@stryke/path/append`),a=require(`@stryke/path/join-paths`),o=require(`@stryke/type-checks/is-set-string`);const s={platform:`neutral`,target:`esnext`,cjsDefault:!0,unbundle:!0,shims:!0,fixedExtension:!0,nodeProtocol:!0,clean:!1};function c(e){return(0,n.toArray)(e).map(e=>{switch(e){case`cjs`:return`cjs`;case`iife`:return`iife`;case`esm`:default:return`esm`}})}const l=(e,...t)=>t.filter(Boolean).join(` `).replace(RegExp(`\\[${e.config.name}\\]`,`g`),``).trim();function u(e){return(0,t.default)({entry:e.entry.length>0?e.entry.filter(Boolean).map(t=>(0,i.appendPath)((0,i.appendPath)(t.file,e.config.projectRoot),e.workspaceConfig.workspaceRoot)):[(0,a.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.sourceRoot,`**/*.ts`),(0,a.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.sourceRoot,`**/*.tsx`)],alias:e.builtins.reduce((t,n)=>{let r=e.fs.ids[n];return r&&(t[n]=r),t},{}),noExternal:e.builtins},e.config.build.variant===`tsdown`?e.config.build.override:{},e.config.build.variant===`tsdown`?(0,r.omit)(e.config.build,[`override`,`variant`]):{},{name:e.config.name,cwd:(0,i.appendPath)(e.config.projectRoot,e.workspaceConfig.workspaceRoot),dts:{parallel:!0,newContext:!0,cwd:(0,i.appendPath)(e.config.projectRoot,e.workspaceConfig.workspaceRoot),tsconfig:(0,i.appendPath)(e.tsconfig.tsconfigFilePath,e.workspaceConfig.workspaceRoot),sourcemap:e.config.mode===`development`},outDir:(0,i.appendPath)(e.config.output.buildPath,e.workspaceConfig.workspaceRoot),tsconfig:(0,i.appendPath)(e.tsconfig.tsconfigFilePath,e.workspaceConfig.workspaceRoot),format:c(e.config.output.format).filter(Boolean),mode:e.config.mode,treeshake:e.config.build.variant===`tsdown`||e.config.build.variant===`tsup`?e.config.build?.treeshake:e.config.build.variant===`esbuild`?e.config.build?.treeShaking:void 0,minify:e.config.mode===`production`,metafile:e.config.mode===`development`,sourcemap:e.config.mode===`development`,debug:e.config.mode===`development`,silent:e.config.logLevel===null||e.config.mode===`production`,logLevel:e.config.logLevel===`trace`?`debug`:e.config.logLevel,customLogger:{level:e.config.logLevel===`trace`?`debug`:e.config.logLevel,info:(...t)=>(0,o.isSetString)(l(e,...t).replace(/\s+/g,``))&&e.info(l(e,...t)),warn:(...t)=>(0,o.isSetString)(l(e,...t).replace(/\s+/g,``))&&e.warn(l(e,...t)),warnOnce:(...t)=>(0,o.isSetString)(l(e,...t).replace(/\s+/g,``))&&e.warn(l(e,...t)),error:(...t)=>(0,o.isSetString)(l(e,...t).replace(/\s+/g,``))&&e.error(l(e,...t)),success:(...t)=>(0,o.isSetString)(l(e,...t).replace(/\s+/g,``))&&e.info(l(e,...t))}},s)}exports.extractTsdownConfig=u;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"defu";import{
|
|
1
|
+
import e from"defu";import{toArray as t}from"@stryke/convert/to-array";import{omit as n}from"@stryke/helpers/omit";import{appendPath as r}from"@stryke/path/append";import{joinPaths as i}from"@stryke/path/join-paths";import{isSetString as a}from"@stryke/type-checks/is-set-string";const o={platform:`neutral`,target:`esnext`,cjsDefault:!0,unbundle:!0,shims:!0,fixedExtension:!0,nodeProtocol:!0,clean:!1};function s(e){return t(e).map(e=>{switch(e){case`cjs`:return`cjs`;case`iife`:return`iife`;case`esm`:default:return`esm`}})}const c=(e,...t)=>t.filter(Boolean).join(` `).replace(RegExp(`\\[${e.config.name}\\]`,`g`),``).trim();function l(t){return e({entry:t.entry.length>0?t.entry.filter(Boolean).map(e=>r(r(e.file,t.config.projectRoot),t.workspaceConfig.workspaceRoot)):[i(t.workspaceConfig.workspaceRoot,t.config.sourceRoot,`**/*.ts`),i(t.workspaceConfig.workspaceRoot,t.config.sourceRoot,`**/*.tsx`)],alias:t.builtins.reduce((e,n)=>{let r=t.fs.ids[n];return r&&(e[n]=r),e},{}),noExternal:t.builtins},t.config.build.variant===`tsdown`?t.config.build.override:{},t.config.build.variant===`tsdown`?n(t.config.build,[`override`,`variant`]):{},{name:t.config.name,cwd:r(t.config.projectRoot,t.workspaceConfig.workspaceRoot),dts:{parallel:!0,newContext:!0,cwd:r(t.config.projectRoot,t.workspaceConfig.workspaceRoot),tsconfig:r(t.tsconfig.tsconfigFilePath,t.workspaceConfig.workspaceRoot),sourcemap:t.config.mode===`development`},outDir:r(t.config.output.buildPath,t.workspaceConfig.workspaceRoot),tsconfig:r(t.tsconfig.tsconfigFilePath,t.workspaceConfig.workspaceRoot),format:s(t.config.output.format).filter(Boolean),mode:t.config.mode,treeshake:t.config.build.variant===`tsdown`||t.config.build.variant===`tsup`?t.config.build?.treeshake:t.config.build.variant===`esbuild`?t.config.build?.treeShaking:void 0,minify:t.config.mode===`production`,metafile:t.config.mode===`development`,sourcemap:t.config.mode===`development`,debug:t.config.mode===`development`,silent:t.config.logLevel===null||t.config.mode===`production`,logLevel:t.config.logLevel===`trace`?`debug`:t.config.logLevel,customLogger:{level:t.config.logLevel===`trace`?`debug`:t.config.logLevel,info:(...e)=>a(c(t,...e).replace(/\s+/g,``))&&t.info(c(t,...e)),warn:(...e)=>a(c(t,...e).replace(/\s+/g,``))&&t.warn(c(t,...e)),warnOnce:(...e)=>a(c(t,...e).replace(/\s+/g,``))&&t.warn(c(t,...e)),error:(...e)=>a(c(t,...e).replace(/\s+/g,``))&&t.error(c(t,...e)),success:(...e)=>a(c(t,...e).replace(/\s+/g,``))&&t.info(c(t,...e))}},o)}export{l as extractTsdownConfig};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../plugin-utils/paths.cjs`);let n=require(`@stryke/convert/
|
|
1
|
+
const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../plugin-utils/paths.cjs`);let n=require(`@stryke/convert/to-array`),r=require(`@stryke/path/append`),i=require(`@stryke/path/join-paths`),a=require(`@stryke/type-checks/is-set-string`),o=require(`@stryke/fs/list-files`),s=require(`@stryke/path/replace`),c=require(`@stryke/type-checks/is-string`),l=require(`@stryke/hash/murmurhash`),u=require(`@stryke/helpers/get-unique`),d=require(`@stryke/convert/parse-type-definition`),f=require(`@stryke/fs/is-file`);function p(e,t){return(0,s.replacePath)(t.file,(0,i.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.projectRoot))}function m(e,t){return{file:p(e,t),name:t.name}}function h(e,t){return(0,s.replaceExtension)((0,s.replacePath)((0,s.replacePath)((0,s.replacePath)((0,s.replacePath)((0,s.replacePath)(t.file,(0,i.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.sourceRoot)),(0,i.joinPaths)(e.workspaceConfig.workspaceRoot,e.config.projectRoot)),e.config.sourceRoot),e.config.projectRoot),(0,s.replacePath)(e.config.sourceRoot,e.config.projectRoot)))}function g(e,t){let n=m(e,t);return{...n,input:n,output:h(e,t)}}function _(e,n){return n.map(n=>(0,c.isString)(n)?t.replacePathTokens(e,n):t.replacePathTokens(e,n.file)).map(t=>{let n=(0,d.parseTypeDefinition)(t),i=(0,r.appendPath)(n.file,e.config.projectRoot);return(0,f.isFile)(i)?g(e,{file:(0,s.replacePath)(i,e.config.projectRoot),name:n.name}):(0,o.listFilesSync)(i).map(t=>g(e,{file:t,name:n.name}))}).flat().filter(Boolean)}function v(e=[]){return(0,u.getUniqueBy)((0,n.toArray)(e),e=>(0,a.isSetString)(e)?e:(0,l.murmurhash)(e??{},{maxLength:24}))}exports.getUniqueEntries=v,exports.resolveEntriesSync=_;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{replacePathTokens as e}from"../plugin-utils/paths.mjs";import{
|
|
1
|
+
import{replacePathTokens as e}from"../plugin-utils/paths.mjs";import{toArray as t}from"@stryke/convert/to-array";import{appendPath as n}from"@stryke/path/append";import{joinPaths as r}from"@stryke/path/join-paths";import{isSetString as i}from"@stryke/type-checks/is-set-string";import{listFiles as a,listFilesSync as o}from"@stryke/fs/list-files";import{replaceExtension as s,replacePath as c}from"@stryke/path/replace";import{isString as l}from"@stryke/type-checks/is-string";import{murmurhash as u}from"@stryke/hash/murmurhash";import{getUniqueBy as d}from"@stryke/helpers/get-unique";import{parseTypeDefinition as f}from"@stryke/convert/parse-type-definition";import{isFile as p}from"@stryke/fs/is-file";function m(e,t){return c(t.file,r(e.workspaceConfig.workspaceRoot,e.config.projectRoot))}function h(e,t){return{file:m(e,t),name:t.name}}function g(e,t){return s(c(c(c(c(c(t.file,r(e.workspaceConfig.workspaceRoot,e.config.sourceRoot)),r(e.workspaceConfig.workspaceRoot,e.config.projectRoot)),e.config.sourceRoot),e.config.projectRoot),c(e.config.sourceRoot,e.config.projectRoot)))}function _(e,t){let n=h(e,t);return{...n,input:n,output:g(e,t)}}function v(t,r){return r.map(n=>l(n)?e(t,n):e(t,n.file)).map(e=>{let r=f(e),i=n(r.file,t.config.projectRoot);return p(i)?_(t,{file:c(i,t.config.projectRoot),name:r.name}):o(i).map(e=>_(t,{file:e,name:r.name}))}).flat().filter(Boolean)}function y(e=[]){return d(t(e),e=>i(e)?e:u(e??{},{maxLength:24}))}export{y as getUniqueEntries,v as resolveEntriesSync};
|
|
@@ -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/convert/to-array`),l=require(`@stryke/path/append`),u=require(`@stryke/type-checks/is-set-string`),d=require(`@stryke/fs/resolve`),f=require(`@stryke/path/join-paths`),p=require(`@stryke/path/replace`),m=require(`@stryke/type-checks/is-set-object`),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,p.replacePath)(t,this.#o.builtinsPath)),i.normalizeId(t,this.#o.config.output.builtinPrefix)}#l(e){return i.normalizePath(e.includes(`{`)||e.includes(`}`)?t.replacePathTokens(this.#o,e):e,this.#o.builtinsPath,this.#o.config.output.builtinPrefix)}#u(e){let t=`::GLOBSTAR::`;return RegExp(`^${this.#l(e).replace(/\*\*/g,t).replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/]*`).replace(/\?/g,`[^/]`).replace(new RegExp(t,`g`),`.*`)}$`)}#d(e){let t=this.resolveSync(this.#l(e))||e;for(let e of Object.keys(this.#r).filter(Boolean).sort().reverse())if((0,b.isParentPath)(t,e))return{base:e,relativeKey:(0,p.replacePath)(t,e),adapter:this.#r[e]};return{base:``,relativeKey:t,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>(0,b.isParentPath)(n,e)||t&&(0,b.isParentPath)(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(t){if(!t.config.skipCache&&(0,_.existsSync)((0,f.joinPaths)(t.dataPath,`fs.bin`))){let r=await(0,w.readFileBuffer)((0,f.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,f.joinPaths)(t.dataPath,`fs.bin`))){let r=(0,w.readFileBufferSync)((0,f.joinPaths)(t.dataPath,`fs.bin`)),i=new C.Message(r,!1).getRoot(n.FileSystem),a=new e(t,i);i._hasStorage()&&i.storage.length>0&&i.storage.values().map(e=>{a.writeSync(e.path,e.code)})}return new e(t,new C.Message().initRoot(n.FileSystem))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=(0,S.create)({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,(0,m.isSetObject)(this.#o.config.output.storage)&&(this.#r={...this.#r,...this.#o.config.output.storage}),this.#r.virtual??=new o.VirtualStorageAdapter({base:`/_virtual`}),this.#o.config.output.storage!==`fs`&&(this.#r[this.#o.artifactsPath]??=new o.VirtualStorageAdapter({base:this.#o.artifactsPath}),this.#r[this.#o.builtinsPath]??=new o.VirtualStorageAdapter({base:this.#o.builtinsPath}),this.#r[this.#o.entryPath]??=new o.VirtualStorageAdapter({base:this.#o.entryPath})),this.#e={},t._hasMetadata()&&(this.#e=t.metadata.values().reduce((e,t)=>(e[t.id]={id:t.id,type:t.type,timestamp:t.timestamp||Date.now(),properties:t._hasProperties()?t.properties.values().reduce((e,t)=>(e[t.key]=t.value,e),{}):{}},e),{})),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,l.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,l.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,f.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,f.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,u.isSetString)(n)&&(!(0,m.isSetObject)(n)||!(0,u.isSetString)(n.input))||!(0,u.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,u.isSetString)(n)&&n.includes(`*`)||(0,m.isSetObject)(n)&&(0,u.isSetString)(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,(0,l.appendPath)((0,p.replacePath)(e,i),r))));else{let e=await this.read(a);e!==void 0&&await this.write(this.#l(r),e,{skipFormat:!0})}}copySync(e,t){let n=e instanceof URL?(0,D.fileURLToPath)(e):e,r=t instanceof URL?(0,D.fileURLToPath)(t):t;if(!(0,u.isSetString)(n)&&(!(0,m.isSetObject)(n)||!(0,u.isSetString)(n.input))||!(0,u.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,u.isSetString)(n)&&n.includes(`*`)||(0,m.isSetObject)(n)&&(0,u.isSetString)(n.glob))this.globSync(n).map(e=>this.copySync(e,(0,l.appendPath)((0,g.findFilePath)((0,p.replacePath)(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l((0,g.hasFileExtension)(r)?r:(0,l.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,c.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,c.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,l.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,l.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,l.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,d.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await(0,d.resolve)(i,{...r,paths:e})}catch{}}return o&&!this.#o.config.skipCache&&this.resolverCache.set(a,o),o}resolveSync(e,n,r={}){let i=e;if((i.includes(`{`)||i.includes(`}`))&&(i=t.replacePathTokens(this.#o,i)),(0,x.isAbsolutePath)(i))return i;let a;if(!this.#o.config.skipCache&&(a=this.resolverCache.get(this.#c(i)),a))return a;if(a=this.paths[this.#c(i)],!a){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push((0,l.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,l.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,l.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,d.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=(0,d.resolveSync)(i,{...r,paths:e})}catch{}}return a&&!this.#o.config.skipCache&&this.resolverCache.set(this.#c(i),a),a}async dispose(){if(!this.#a){this.#a=!0,this.#s(s.LogLevelLabel.DEBUG,`Disposing virtual file system...`),await this.remove((0,f.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,f.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/convert/to-array`),l=require(`@stryke/path/append`),u=require(`@stryke/path/join-paths`),d=require(`@stryke/type-checks/is-set-string`),f=require(`@stryke/fs/resolve`),p=require(`@stryke/path/replace`),m=require(`@stryke/type-checks/is-set-object`),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,p.replacePath)(t,this.#o.builtinsPath)),i.normalizeId(t,this.#o.config.output.builtinPrefix)}#l(e){return i.normalizePath(e.includes(`{`)||e.includes(`}`)?t.replacePathTokens(this.#o,e):e,this.#o.builtinsPath,this.#o.config.output.builtinPrefix)}#u(e){let t=`::GLOBSTAR::`;return RegExp(`^${this.#l(e).replace(/\*\*/g,t).replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/]*`).replace(/\?/g,`[^/]`).replace(new RegExp(t,`g`),`.*`)}$`)}#d(e){let t=this.resolveSync(this.#l(e))||e;for(let e of Object.keys(this.#r).filter(Boolean).sort().reverse())if((0,b.isParentPath)(t,e))return{base:e,relativeKey:(0,p.replacePath)(t,e),adapter:this.#r[e]};return{base:``,relativeKey:t,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>(0,b.isParentPath)(n,e)||t&&(0,b.isParentPath)(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(t){if(!t.config.skipCache&&(0,_.existsSync)((0,u.joinPaths)(t.dataPath,`fs.bin`))){let r=await(0,w.readFileBuffer)((0,u.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,u.joinPaths)(t.dataPath,`fs.bin`))){let r=(0,w.readFileBufferSync)((0,u.joinPaths)(t.dataPath,`fs.bin`)),i=new C.Message(r,!1).getRoot(n.FileSystem),a=new e(t,i);i._hasStorage()&&i.storage.length>0&&i.storage.values().map(e=>{a.writeSync(e.path,e.code)})}return new e(t,new C.Message().initRoot(n.FileSystem))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=(0,S.create)({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,(0,m.isSetObject)(this.#o.config.output.storage)&&(this.#r={...this.#r,...this.#o.config.output.storage}),this.#r.virtual??=new o.VirtualStorageAdapter({base:`/_virtual`}),this.#o.config.output.storage!==`fs`&&(this.#r[this.#o.artifactsPath]??=new o.VirtualStorageAdapter({base:this.#o.artifactsPath}),this.#r[this.#o.builtinsPath]??=new o.VirtualStorageAdapter({base:this.#o.builtinsPath}),this.#r[this.#o.entryPath]??=new o.VirtualStorageAdapter({base:this.#o.entryPath})),this.#e={},t._hasMetadata()&&(this.#e=t.metadata.values().reduce((e,t)=>(e[t.id]={id:t.id,type:t.type,timestamp:t.timestamp||Date.now(),properties:t._hasProperties()?t.properties.values().reduce((e,t)=>(e[t.key]=t.value,e),{}):{}},e),{})),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,l.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,l.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,u.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,u.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,d.isSetString)(n)&&(!(0,m.isSetObject)(n)||!(0,d.isSetString)(n.input))||!(0,d.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,d.isSetString)(n)&&n.includes(`*`)||(0,m.isSetObject)(n)&&(0,d.isSetString)(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,(0,l.appendPath)((0,p.replacePath)(e,i),r))));else{let e=await this.read(a);e!==void 0&&await this.write(this.#l(r),e,{skipFormat:!0})}}copySync(e,t){let n=e instanceof URL?(0,D.fileURLToPath)(e):e,r=t instanceof URL?(0,D.fileURLToPath)(t):t;if(!(0,d.isSetString)(n)&&(!(0,m.isSetObject)(n)||!(0,d.isSetString)(n.input))||!(0,d.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,d.isSetString)(n)&&n.includes(`*`)||(0,m.isSetObject)(n)&&(0,d.isSetString)(n.glob))this.globSync(n).map(e=>this.copySync(e,(0,l.appendPath)((0,g.findFilePath)((0,p.replacePath)(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l((0,g.hasFileExtension)(r)?r:(0,l.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,c.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,c.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,l.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,l.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,l.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,f.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,f.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,l.appendPath)(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push((0,l.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,l.appendPath)(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of(0,f.getResolutionCombinations)(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=(0,f.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,u.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,u.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{toArray as l}from"@stryke/convert/to-array";import{appendPath as u}from"@stryke/path/append";import{isSetString as d}from"@stryke/type-checks/is-set-string";import{getResolutionCombinations as f,resolve as p,resolveSync as m}from"@stryke/fs/resolve";import{joinPaths as h}from"@stryke/path/join-paths";import{replacePath as g}from"@stryke/path/replace";import{isSetObject as _}from"@stryke/type-checks/is-set-object";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=g(t,this.#o.builtinsPath)),i(t,this.#o.config.output.builtinPrefix)}#l(t){return a(t.includes(`{`)||t.includes(`}`)?e(this.#o,t):t,this.#o.builtinsPath,this.#o.config.output.builtinPrefix)}#u(e){let t=`::GLOBSTAR::`;return RegExp(`^${this.#l(e).replace(/\*\*/g,t).replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/]*`).replace(/\?/g,`[^/]`).replace(new RegExp(t,`g`),`.*`)}$`)}#d(e){let t=this.resolveSync(this.#l(e))||e;for(let e of Object.keys(this.#r).filter(Boolean).sort().reverse())if(T(t,e))return{base:e,relativeKey:g(t,e),adapter:this.#r[e]};return{base:``,relativeKey:t,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>T(n,e)||t&&T(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(e){if(!e.config.skipCache&&S(h(e.dataPath,`fs.bin`))){let n=await k(h(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(h(e.dataPath,`fs.bin`))){let n=A(h(e.dataPath,`fs.bin`)),r=new O.Message(n,!1).getRoot(t),i=new L(e,r);r._hasStorage()&&r.storage.length>0&&r.storage.values().map(e=>{i.writeSync(e.path,e.code)})}return new L(e,new O.Message().initRoot(t))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=D({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,_(this.#o.config.output.storage)&&(this.#r={...this.#r,...this.#o.config.output.storage}),this.#r.virtual??=new s({base:`/_virtual`}),this.#o.config.output.storage!==`fs`&&(this.#r[this.#o.artifactsPath]??=new s({base:this.#o.artifactsPath}),this.#r[this.#o.builtinsPath]??=new s({base:this.#o.builtinsPath}),this.#r[this.#o.entryPath]??=new s({base:this.#o.entryPath})),this.#e={},t._hasMetadata()&&(this.#e=t.metadata.values().reduce((e,t)=>(e[t.id]={id:t.id,type:t.type,timestamp:t.timestamp||Date.now(),properties:t._hasProperties()?t.properties.values().reduce((e,t)=>(e[t.key]=t.value,e),{}):{}},e),{})),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?u(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?u(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(h(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(h(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(!d(n)&&(!_(n)||!d(n.input))||!d(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)||d(n)&&n.includes(`*`)||_(n)&&d(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,u(g(e,i),r))));else{let e=await this.read(a);e!==void 0&&await this.write(this.#l(r),e,{skipFormat:!0})}}copySync(e,t){let n=e instanceof URL?P(e):e,r=t instanceof URL?P(t):t;if(!d(n)&&(!_(n)||!d(n.input))||!d(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)||d(n)&&n.includes(`*`)||_(n)&&d(n.glob))this.globSync(n).map(e=>this.copySync(e,u(b(g(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l(x(r)?r:u(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(l(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(l(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(u(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(u(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=>u(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of f(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await p(i,{...r,paths:e})}catch{}}return o&&!this.#o.config.skipCache&&this.resolverCache.set(a,o),o}resolveSync(t,n,r={}){let i=t;if((i.includes(`{`)||i.includes(`}`))&&(i=e(this.#o,i)),E(i))return i;let a;if(!this.#o.config.skipCache&&(a=this.resolverCache.get(this.#c(i)),a))return a;if(a=this.paths[this.#c(i)],!a){let e=r.paths??[];n&&!e.includes(n)&&e.push(n),e.push(this.#o.workspaceConfig.workspaceRoot),e.push(u(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(u(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=>u(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of f(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=m(i,{...r,paths:e})}catch{}}return a&&!this.#o.config.skipCache&&this.resolverCache.set(this.#c(i),a),a}async dispose(){if(!this.#a){this.#a=!0,this.#s(c.DEBUG,`Disposing virtual file system...`),await this.remove(h(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(h(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{toArray as l}from"@stryke/convert/to-array";import{appendPath as u}from"@stryke/path/append";import{joinPaths as d}from"@stryke/path/join-paths";import{isSetString as f}from"@stryke/type-checks/is-set-string";import{getResolutionCombinations as p,resolve as m,resolveSync as h}from"@stryke/fs/resolve";import{replacePath as g}from"@stryke/path/replace";import{isSetObject as _}from"@stryke/type-checks/is-set-object";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=g(t,this.#o.builtinsPath)),i(t,this.#o.config.output.builtinPrefix)}#l(t){return a(t.includes(`{`)||t.includes(`}`)?e(this.#o,t):t,this.#o.builtinsPath,this.#o.config.output.builtinPrefix)}#u(e){let t=`::GLOBSTAR::`;return RegExp(`^${this.#l(e).replace(/\*\*/g,t).replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/]*`).replace(/\?/g,`[^/]`).replace(new RegExp(t,`g`),`.*`)}$`)}#d(e){let t=this.resolveSync(this.#l(e))||e;for(let e of Object.keys(this.#r).filter(Boolean).sort().reverse())if(T(t,e))return{base:e,relativeKey:g(t,e),adapter:this.#r[e]};return{base:``,relativeKey:t,adapter:this.#r[``]}}#f(e=``,t=!1){return Object.keys(this.#r).sort().reverse().filter(n=>T(n,e)||t&&T(e,n)).map(t=>({relativeBase:e.length>t.length?e.slice(t.length):void 0,base:t,adapter:this.#r[t]}))}static async create(e){if(!e.config.skipCache&&S(d(e.dataPath,`fs.bin`))){let n=await k(d(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(d(e.dataPath,`fs.bin`))){let n=A(d(e.dataPath,`fs.bin`)),r=new O.Message(n,!1).getRoot(t),i=new L(e,r);r._hasStorage()&&r.storage.length>0&&r.storage.values().map(e=>{i.writeSync(e.path,e.code)})}return new L(e,new O.Message().initRoot(t))}get metadata(){return new Proxy(this.#e,{get:(e,t)=>e[this.#c(t)]})}get ids(){return new Proxy(this.#n,{get:(e,t)=>e[this.#l(t)]})}get paths(){return new Proxy(this.#n,{get:(e,t)=>e[this.#c(t)]})}get resolverCache(){return this.#i||=D({cacheId:`module-resolution`,cacheDir:this.#o.cachePath,ttl:3600*1e3,lruSize:5e3,persistInterval:100}),this.#i}constructor(e,t){this.#o=e,_(this.#o.config.output.storage)&&(this.#r={...this.#r,...this.#o.config.output.storage}),this.#r.virtual??=new s({base:`/_virtual`}),this.#o.config.output.storage!==`fs`&&(this.#r[this.#o.artifactsPath]??=new s({base:this.#o.artifactsPath}),this.#r[this.#o.builtinsPath]??=new s({base:this.#o.builtinsPath}),this.#r[this.#o.entryPath]??=new s({base:this.#o.entryPath})),this.#e={},t._hasMetadata()&&(this.#e=t.metadata.values().reduce((e,t)=>(e[t.id]={id:t.id,type:t.type,timestamp:t.timestamp||Date.now(),properties:t._hasProperties()?t.properties.values().reduce((e,t)=>(e[t.key]=t.value,e),{}):{}},e),{})),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?u(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?u(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(d(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(d(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(!f(n)&&(!_(n)||!f(n.input))||!f(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)||f(n)&&n.includes(`*`)||_(n)&&f(n.glob))await Promise.all((await this.glob(n)).map(async e=>this.copy(e,u(g(e,i),r))));else{let e=await this.read(a);e!==void 0&&await this.write(this.#l(r),e,{skipFormat:!0})}}copySync(e,t){let n=e instanceof URL?P(e):e,r=t instanceof URL?P(t):t;if(!f(n)&&(!_(n)||!f(n.input))||!f(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)||f(n)&&n.includes(`*`)||_(n)&&f(n.glob))this.globSync(n).map(e=>this.copySync(e,u(b(g(e,i)),r)));else{let e=this.readSync(a);e!==void 0&&this.writeSync(this.#l(x(r)?r:u(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(l(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(l(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(u(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(u(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=>u(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of p(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(await n.exists(e)){o=t;break}}if(!o)try{o=await m(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(u(this.#o.config.projectRoot,this.#o.workspaceConfig.workspaceRoot)),e.push(u(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=>u(e,this.#o.workspaceConfig.workspaceRoot)));for(let t of p(i,{paths:e})){let{relativeKey:e,adapter:n}=this.#d(t);if(n.existsSync(e)){a=t;break}}if(!a)try{a=h(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(d(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(d(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`);let t=require(`@storm-software/config-tools/types`),n=require(`@stryke/
|
|
1
|
+
const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`@storm-software/config-tools/types`),n=require(`@stryke/path/join-paths`),r=require(`@stryke/fs/list-files`),i=require(`@stryke/fs/json`),a=require(`@stryke/path/file-path-fns`),o=require(`@stryke/fs/exists`),s=require(`@stryke/helpers/get-unique`);require(`@stryke/fs/remove-file`);let c=require(`@stryke/string-format/kebab-case`);const l=45,u=62;function d(e,t){let n=`${(0,c.kebabCase)(e)}_${t}`;return n.length>45?n.slice(0,45):n}async function f(e){let r=(0,n.joinPaths)(e.dataPath,`meta.json`);e.log(t.LogLevelLabel.DEBUG,`Writing runtime metadata to ${r}`),await e.fs.write(r,JSON.stringify(e.meta,null,2))}exports.CACHE_HASH_LENGTH=62,exports.PROJECT_ROOT_HASH_LENGTH=45,exports.getPrefixedProjectRootHash=d,exports.writeMetaFile=f;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LogLevelLabel as e}from"@storm-software/config-tools/types";import{
|
|
1
|
+
import{LogLevelLabel as e}from"@storm-software/config-tools/types";import{joinPaths as t}from"@stryke/path/join-paths";import{listFiles as n}from"@stryke/fs/list-files";import{readJsonFile as r}from"@stryke/fs/json";import{hasFileExtension as i}from"@stryke/path/file-path-fns";import{existsSync as a}from"@stryke/fs/exists";import{getUnique as o}from"@stryke/helpers/get-unique";import"@stryke/fs/remove-file";import{kebabCase as s}from"@stryke/string-format/kebab-case";const c=45,l=62;function u(e,t){let n=`${s(e)}_${t}`;return n.length>45?n.slice(0,45):n}async function d(n){let r=t(n.dataPath,`meta.json`);n.log(e.DEBUG,`Writing runtime metadata to ${r}`),await n.fs.write(r,JSON.stringify(n.meta,null,2))}export{l as CACHE_HASH_LENGTH,c as PROJECT_ROOT_HASH_LENGTH,u as getPrefixedProjectRootHash,d as writeMetaFile};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-tsdown",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
|
|
6
6
|
"repository": {
|
|
@@ -150,13 +150,13 @@
|
|
|
150
150
|
"@stryke/type-checks": "^0.5.14",
|
|
151
151
|
"@stryke/types": "^0.10.28",
|
|
152
152
|
"defu": "^6.1.4",
|
|
153
|
-
"powerlines": "^0.34.
|
|
153
|
+
"powerlines": "^0.34.2"
|
|
154
154
|
},
|
|
155
155
|
"devDependencies": {
|
|
156
|
-
"@powerlines/nx": "^0.11.
|
|
157
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
156
|
+
"@powerlines/nx": "^0.11.15",
|
|
157
|
+
"@powerlines/plugin-plugin": "^0.12.36",
|
|
158
158
|
"@types/node": "^24.10.4"
|
|
159
159
|
},
|
|
160
160
|
"publishConfig": { "access": "public" },
|
|
161
|
-
"gitHead": "
|
|
161
|
+
"gitHead": "6407c0f7097c50efaf2096a8ea0b53f403f3ac0a"
|
|
162
162
|
}
|