archicat 0.0.6 → 0.0.8
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/README.md +19 -8
- package/dist/cli/index.mjs +16 -17
- package/dist/src/index.cjs +1 -1
- package/dist/src/index.d.cts +60 -5
- package/dist/src/index.d.mts +60 -5
- package/dist/src/index.mjs +1 -1
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -12,10 +12,11 @@ npm i -D archicat
|
|
|
12
12
|
|
|
13
13
|
## Why
|
|
14
14
|
|
|
15
|
-
TypeScript asks:
|
|
16
|
-
|
|
15
|
+
TypeScript asks: will this import resolve?
|
|
17
16
|
Archicat asks: should this import exist?
|
|
18
17
|
|
|
18
|
+
One is a compiler. The other is an architect.
|
|
19
|
+
|
|
19
20
|
## Definitions
|
|
20
21
|
|
|
21
22
|
### Module
|
|
@@ -125,7 +126,13 @@ import { MediaRepository } from '../../media/impl/repository';
|
|
|
125
126
|
import { defineArchicatConfig } from 'archicat';
|
|
126
127
|
|
|
127
128
|
export default defineArchicatConfig({
|
|
128
|
-
|
|
129
|
+
typescript: {
|
|
130
|
+
tsConfig: {
|
|
131
|
+
extends: '../../tsconfig.node.json',
|
|
132
|
+
include: ['bootstrap.ts', 'src/app', 'src/libraries', 'src/modules', 'types'],
|
|
133
|
+
exclude: ['node_modules', 'dist'],
|
|
134
|
+
},
|
|
135
|
+
},
|
|
129
136
|
|
|
130
137
|
alias: {
|
|
131
138
|
'@app': './src/app/index.ts',
|
|
@@ -146,16 +153,20 @@ export default defineArchicatConfig({
|
|
|
146
153
|
});
|
|
147
154
|
```
|
|
148
155
|
|
|
149
|
-
|
|
156
|
+
App `tsconfig.json`:
|
|
150
157
|
|
|
151
158
|
```json
|
|
152
159
|
{
|
|
153
|
-
"extends": "./.archicat/tsconfig.json"
|
|
160
|
+
"extends": "./.archicat/tsconfig.json",
|
|
161
|
+
"compilerOptions": {
|
|
162
|
+
"rootDir": ".",
|
|
163
|
+
"outDir": "./dist"
|
|
164
|
+
}
|
|
154
165
|
}
|
|
155
166
|
```
|
|
156
167
|
|
|
157
168
|
> [!IMPORTANT]
|
|
158
|
-
>
|
|
169
|
+
> Generated `.archicat/tsconfig.json` extends `typescript.tsConfig.extends`, therefore put user aliases in `archicat.config.ts`, not in `compilerOptions.paths`.
|
|
159
170
|
|
|
160
171
|
## Output
|
|
161
172
|
|
|
@@ -173,8 +184,8 @@ Root `tsconfig.json`:
|
|
|
173
184
|
## Commands
|
|
174
185
|
|
|
175
186
|
```bash
|
|
176
|
-
archicat
|
|
177
|
-
archicat
|
|
187
|
+
archicat build
|
|
188
|
+
archicat validate
|
|
178
189
|
archicat graph
|
|
179
190
|
archicat doctor
|
|
180
191
|
```
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import e from"node:path";import t from"node:fs";import{createJiti as n}from"jiti";import r from"typescript";const i=Object.freeze({root:`.`,outDir:`.archicat`,alias:Object.freeze({}),prefixes:Object.freeze({module:`@module`,library:`@library`}),modules:Object.freeze({include:Object.freeze([`./src/modules`])}),libraries:Object.freeze({include:Object.freeze([])}),apps:Object.freeze({include:Object.freeze([])})});async function a(n=`archicat.config.ts`){let r=process.cwd(),i=e.resolve(r,n);if(!t.existsSync(i))throw Error(`Archicat config was not found: ${i}`);let a=await o(i,r);l(a,i);let u=s(a),d=e.resolve(r,u.root),f=e.resolve(d,u.outDir),p=e.resolve(f,`reports`),m=c(d,u.tsconfig);return{configFilePath:i,rootDir:d,outDir:f,reportsDir:p,...m?{tsconfigPath:m}:{},config:a,resolvedConfig:u}}async function o(e,t){return await n(t,{interopDefault:!0,extensions:[`.js`,`.cjs`,`.mjs`,`.ts`,`.cts`,`.mts`,`.json`]}).import(e,{default:!0})}function s(e){return{root:e.root??i.root,outDir:e.outDir??i.outDir,alias:{...i.alias,...e.alias??{}},...e.tsconfig===void 0?{}:{tsconfig:e.tsconfig},prefixes:{module:e.prefixes?.module??i.prefixes.module,library:e.prefixes?.library??i.prefixes.library},modules:{include:[...e.modules?.include??i.modules.include]},libraries:{include:[...e.libraries?.include??i.libraries.include]},apps:{include:[...e.apps?.include??i.apps.include]}}}function c(n,r){if(r){let i=e.resolve(n,r);if(!t.existsSync(i))throw Error(`Configured Archicat tsconfig was not found: ${i}`);return i}return[`tsconfig.base.json`,`tsconfig.json`].map(t=>e.join(n,t)).find(e=>t.existsSync(e))}function l(e,t){if(typeof e!=`object`||!e)throw Error(`Invalid Archicat config: ${t}`);let n=e;u(n.root,`root`,t),u(n.outDir,`outDir`,t),u(n.tsconfig,`tsconfig`,t),d(n.modules?.include,`modules.include`,t),d(n.libraries?.include,`libraries.include`,t),d(n.apps?.include,`apps.include`,t),p(n.alias,`alias`,t),f(n.prefixes?.module,`prefixes.module`,t),f(n.prefixes?.library,`prefixes.library`,t)}function u(e,t,n){if(e!==void 0&&(typeof e!=`string`||e.trim()===``))throw Error(`Archicat ${t} must be a non-empty string when defined: ${n}`)}function d(e,t,n){if(e!==void 0&&(!Array.isArray(e)||e.some(e=>typeof e!=`string`||e.trim()===``)))throw Error(`Archicat config ${t} must be an array of non-empty strings: ${n}`)}function f(e,t,n){if(e!==void 0&&(typeof e!=`string`||e.trim()===``||e.includes(`*`)||e.endsWith(`/`)))throw Error(`Archicat config ${t} must be a non-empty prefix without wildcard or trailing slash: ${n}`)}function p(e,t,n){if(e!==void 0){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Archicat config ${t} must be an object of non-empty string aliases: ${n}`);for(let[r,i]of Object.entries(e))if(r.trim()===``||typeof i!=`string`||i.trim()===``)throw Error(`Archicat config ${t} must contain non-empty string aliases: ${n}`)}}function m(e,t,n){let r=t.flatMap(t=>ee(e,t,n));return Array.from(new Set(r)).sort((e,t)=>e.localeCompare(t))}function ee(n,r,i){let a=e.resolve(n,r);if(r.includes(`*`))return te(n,r).filter(t=>e.basename(t)===i);if(!t.existsSync(a))return[];let o=t.statSync(a);return o.isFile()?e.basename(a)===i?[a]:[]:o.isDirectory()?h(a,i):[]}function h(n,r){let i=[],a=t.readdirSync(n,{withFileTypes:!0});for(let t of a){if(re(t.name))continue;let a=e.join(n,t.name);if(t.isDirectory()){i.push(...h(a,r));continue}t.isFile()&&t.name===r&&i.push(a)}return i}function te(n,r){let i=e.resolve(n,r).split(e.sep);if(i.filter(e=>e.includes(`*`)).length!==1)throw Error(`Archicat supports exactly one wildcard segment per include pattern: ${r}`);let a=i.findIndex(e=>e.includes(`*`)),o=i.slice(0,a).join(e.sep)||e.sep,s=i[a]??`*`,c=i.slice(a+1),l=ne(s);return t.existsSync(o)?t.readdirSync(o,{withFileTypes:!0}).filter(e=>e.isDirectory()).filter(e=>l.test(e.name)).map(t=>e.join(o,t.name,...c)).filter(e=>t.existsSync(e)&&t.statSync(e).isFile()):[]}function ne(e){let t=e.replace(/[.+?^${}()|[\]\\]/gu,`\\$&`).replace(/\*/gu,`.*`);return RegExp(`^${t}$`,`u`)}function re(e){return[`node_modules`,`.git`,`.archicat`,`archicat-report`,`dist`,`build`,`coverage`].includes(e)}async function g(e,t){switch(t){case`module`:return ie(e);case`library`:return ae(e);case`app`:return oe(e)}}async function ie(t){let n=await _(t,e.dirname(t));return v(n,t,`module`),{kind:`module`,contractFilePath:t,definitionDir:e.dirname(t),contract:n}}async function ae(t){let n=await _(t,e.dirname(t));return v(n,t,`library`),{kind:`library`,contractFilePath:t,definitionDir:e.dirname(t),contract:n}}async function oe(t){let n=await _(t,e.dirname(t));return v(n,t,`app`),{kind:`app`,contractFilePath:t,definitionDir:e.dirname(t),contract:n}}async function _(e,t){return await n(t,{interopDefault:!0,extensions:[`.js`,`.cjs`,`.mjs`,`.ts`,`.cts`,`.mts`,`.json`]}).import(e,{default:!0})}function v(e,t,n){if(typeof e!=`object`||!e)throw Error(`Invalid Archicat ${n} definition: ${t}`);let r=e;if(r.kind!==n)throw Error(`Archicat ${n} file must export define${se(n)}(...): ${t}`);if(typeof r.name!=`string`||r.name.trim()===``)throw Error(`Archicat ${n} must define a non-empty name: ${t}`);if(n===`app`){x(r.root,`root`,t),b(r.dependencies,t,n);return}let i=r;y(i.api,`api`,t,n),y(i.impl,`impl`,t,n)}function y(e,t,n,r){if(typeof e!=`object`||!e)throw Error(`Archicat ${r}.${t} must be a surface object: ${n}`);x(e.root,`${t}.root`,n),b(e.dependencies,n,`${r}.${t}`)}function b(e,t,n){if(!Array.isArray(e)||e.some(e=>typeof e!=`string`||e.trim()===``))throw Error(`Archicat ${n} dependencies must be an array of non-empty strings: ${t}`)}function x(e,t,n){if(e!==void 0&&(typeof e!=`string`||e.trim()===``))throw Error(`Archicat ${t} must be a non-empty string when defined: ${n}`)}function se(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function ce(e){let t=new Map;for(let n of e){let e=t.get(n.from)??[];e.push(n.to),t.set(n.from,e)}let n=new Set,r=new Set;for(let e of t.keys())S(e,t,n,r,[])}function S(e,t,n,r,i){if(!r.has(e)){if(n.has(e)){let t=i.indexOf(e),n=[...i.slice(t<0?0:t),e];throw Error(`Cyclic Archicat dependency detected: ${n.join(` -> `)}`)}n.add(e);for(let a of t.get(e)??[])S(a,t,n,r,[...i,e]);n.delete(e),r.add(e)}}function le(e){let t=/^(module|library)\.([a-z][a-z0-9-]*)\.(api|impl)$/u.exec(e);if(t)return{kind:t[1],name:t[2],surface:t[3]}}function ue(e){return`${e.kind}.${e.surface}`}function C(e,t,n){let r=le(t);if(!r)throw Error(`${w(e)} declares invalid dependency target "${t}".`);if(!n.has(t))throw Error(`${w(e)} declares unknown dependency "${t}".`);if(e.kind===r.kind&&e.name===r.name)throw Error(`${w(e)} cannot depend on itself: ${t}`);if(!de(e,r))throw Error(`${w(e)} cannot depend on ${ue(r)} target "${t}".`)}function de(e,t){switch(e.surface){case`api`:return e.kind===`module`?t.surface===`api`&&(t.kind===`module`||t.kind===`library`):e.kind===`library`?t.surface===`api`&&t.kind===`library`:!1;case`impl`:return e.kind===`module`?t.surface===`api`&&(t.kind===`module`||t.kind===`library`):e.kind===`library`?t.surface===`api`&&t.kind===`library`:!1;case`app`:return t.kind===`module`||t.kind===`library`}}function w(e){return e.kind===`app`?`App "${e.name}"`:`${fe(e.kind)} "${e.name}" ${e.surface}`}function fe(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function pe(e,t){let n=t.filter(e=>e.kind===`module`).map(t=>me(e,t)),r=t.filter(e=>e.kind===`library`).map(t=>he(e,t)),i=t.filter(e=>e.kind===`app`).map(e=>ge(e)),a=[...n,...r];ve([...a,...i]);let o=_e(a,i);return ye(a,i,o.targets),ce(o.dependencies),{rootDir:e.rootDir,outDir:e.outDir,reportsDir:e.reportsDir,...e.tsconfigPath?{tsconfigPath:e.tsconfigPath}:{},configFilePath:e.configFilePath,config:e.resolvedConfig,modules:n,libraries:r,apps:i,definitions:a,graph:o}}function me(t,n){let{contract:r,contractFilePath:i,definitionDir:a}=n;D(r.name,i,`module`);let o=r.api.root?E(a,r.api.root,`api`,r.name):void 0,s=r.impl.root?E(a,r.impl.root,`impl`,r.name):void 0,c=`${t.resolvedConfig.prefixes.module}/${r.name}`;return{kind:`module`,name:r.name,apiTarget:`module.${r.name}.api`,implTarget:`module.${r.name}.impl`,alias:c,aliasGlob:`${c}/*`,implAlias:`${c}/impl`,implAliasGlob:`${c}/impl/*`,contractFilePath:i,definitionDir:a,api:T(o,r.api.dependencies,e.join(t.outDir,`modules`,r.name,`api`)),impl:T(s,r.impl.dependencies,e.join(t.outDir,`modules`,r.name,`impl`))}}function he(t,n){let{contract:r,contractFilePath:i,definitionDir:a}=n;D(r.name,i,`library`);let o=r.api.root?E(a,r.api.root,`api`,r.name):void 0,s=r.impl.root?E(a,r.impl.root,`impl`,r.name):void 0,c=`${t.resolvedConfig.prefixes.library}/${r.name}`;return{kind:`library`,name:r.name,apiTarget:`library.${r.name}.api`,implTarget:`library.${r.name}.impl`,alias:c,aliasGlob:`${c}/*`,implAlias:`${c}/impl`,implAliasGlob:`${c}/impl/*`,contractFilePath:i,definitionDir:a,api:T(o,r.api.dependencies,e.join(t.outDir,`libraries`,r.name,`api`)),impl:T(s,r.impl.dependencies,e.join(t.outDir,`libraries`,r.name,`impl`))}}function ge(e){let{contract:t,contractFilePath:n,definitionDir:r}=e;return D(t.name,n,`app`),{kind:`app`,name:t.name,target:`app.${t.name}`,contractFilePath:n,definitionDir:r,rootPath:t.root?E(r,t.root,`app`,t.name):r,dependencies:[...t.dependencies]}}function T(e,t,n){return{...e?{rootPath:e}:{},mirrorRootPath:n,dependencies:[...t]}}function E(n,r,i,a){let o=e.resolve(n,r);if(!t.existsSync(o))throw Error(`Definition "${a}" declares ${i} root that does not exist: ${o}`);if(!t.statSync(o).isDirectory())throw Error(`Definition "${a}" declares ${i} root that is not a directory: ${o}`);return o}function _e(e,t){let n=e.flatMap(e=>[{key:e.apiTarget,kind:e.kind,name:e.name,surface:`api`},{key:e.implTarget,kind:e.kind,name:e.name,surface:`impl`}]),r=[...e.flatMap(e=>[...e.api.dependencies.map(t=>({from:e.apiTarget,to:t,origin:`declared`})),...e.impl.dependencies.map(t=>({from:e.implTarget,to:t,origin:`declared`}))]),...t.flatMap(e=>e.dependencies.map(t=>({from:e.target,to:t,origin:`declared`})))];return{targets:n,dependencies:[...e.map(e=>({from:e.implTarget,to:e.apiTarget,origin:`derived`})),...r]}}function D(e,t,n){if(!/^[a-z][a-z0-9-]*$/u.test(e))throw Error(`Invalid Archicat ${n} name "${e}" in ${t}. Use ^[a-z][a-z0-9-]*$`)}function ve(e){let t=new Map;for(let n of e){let e=`${n.kind}.${n.name}`,r=t.get(e);if(r)throw Error(`Duplicate Archicat ${n.kind} name "${n.name}" in ${r} and ${n.contractFilePath}`);t.set(e,n.contractFilePath)}}function ye(e,t,n){let r=new Set(n.map(e=>e.key));for(let t of e){for(let e of t.api.dependencies)C(O(t,`api`),e,r);for(let e of t.impl.dependencies)C(O(t,`impl`),e,r)}for(let e of t)for(let t of e.dependencies)C({kind:`app`,name:e.name,surface:`app`,target:e.target},t,r)}function O(e,t){return{kind:e.kind,name:e.name,surface:t,target:t===`api`?e.apiTarget:e.implTarget}}async function k(e){let t=await a(e),n=m(t.rootDir,t.resolvedConfig.modules.include,`archicat.module.ts`),r=m(t.rootDir,t.resolvedConfig.libraries.include,`archicat.library.ts`),i=m(t.rootDir,t.resolvedConfig.apps.include,`archicat.app.ts`);if(n.length===0&&r.length===0&&i.length===0)throw Error(`No Archicat definition files matched configured include roots.`);return pe(t,[...await Promise.all(n.map(e=>g(e,`module`))),...await Promise.all(r.map(e=>g(e,`library`))),...await Promise.all(i.map(e=>g(e,`app`)))])}function A(t){return t.split(e.sep).join(`/`)}function be(t,n){let r=e.dirname(t),i=e.parse(n),a=e.join(i.dir,i.name),o=A(e.relative(r,a));return o.startsWith(`.`)||(o=`./${o}`),`${o}.js`}function j(t,n){let r=e.relative(n,t);return r===``||!!r&&!r.startsWith(`..`)&&!e.isAbsolute(r)}function M(e){return e.replace(/\.(?:js|mjs|cjs|ts|mts|cts|tsx)$/u,``)}function N(t,n){return A(e.relative(t,n))}function P(e){return t.existsSync(e)?t.statSync(e).isFile()?F(e)?[e]:[]:I(e).filter(F).sort((e,t)=>e.localeCompare(t)):[]}function F(e){return/\.(?:ts|mts|cts|tsx)$/u.test(e)&&!/\.d\.(?:ts|mts|cts)$/u.test(e)}function I(n){let r=[],i=t.readdirSync(n,{withFileTypes:!0});for(let t of i){let i=e.join(n,t.name);if(t.isDirectory()){r.push(...I(i));continue}t.isFile()&&r.push(i)}return r}function xe(e){let n=r.createSourceFile(e,t.readFileSync(e,`utf8`),r.ScriptTarget.Latest,!0),i=[],a=e=>{if(r.isImportDeclaration(e)&&r.isStringLiteral(e.moduleSpecifier)&&i.push({moduleSpecifier:e.moduleSpecifier.text,kind:`import`}),r.isExportDeclaration(e)&&e.moduleSpecifier&&r.isStringLiteral(e.moduleSpecifier)&&i.push({moduleSpecifier:e.moduleSpecifier.text,kind:`export`}),r.isCallExpression(e)&&e.expression.kind===r.SyntaxKind.ImportKeyword){let[t]=e.arguments;t&&r.isStringLiteral(t)&&i.push({moduleSpecifier:t.text,kind:`dynamic-import`})}r.forEachChild(e,a)};return a(n),i}function Se(e){let n=r.createSourceFile(e,t.readFileSync(e,`utf8`),r.ScriptTarget.Latest,!0),i=!1,a=e=>{if(!i){if(r.isExportAssignment(e)&&!e.isExportEquals){i=!0;return}if(Ce(e)){i=!0;return}if(r.isExportDeclaration(e)&&e.exportClause&&r.isNamedExports(e.exportClause))for(let t of e.exportClause.elements){let e=t.name.text,n=t.propertyName?.text;if(e==="default"||n==="default"){i=!0;return}}r.forEachChild(e,a)}};return a(n),i}function Ce(e){let t=r.canHaveModifiers(e)?r.getModifiers(e):void 0;if(!t)return!1;let n=t.some(e=>e.kind===r.SyntaxKind.ExportKeyword),i=t.some(e=>e.kind===r.SyntaxKind.DefaultKeyword);return n&&i}async function we(e){return Te(await k(e))}function Te(e){let t=[],n=[...e.definitions.flatMap(e=>Ee(e)),...e.apps.flatMap(e=>P(e.rootPath))];for(let r of n){let n=L(e,r);if(n)for(let i of xe(r)){let a=De(e,n,r,i.moduleSpecifier);a&&t.push(a)}}return t}function Ee(e){return[...e.api.rootPath?P(e.api.rootPath):[],...e.impl.rootPath?P(e.impl.rootPath):[]]}function De(e,t,n,r){let i=je(e,r);if(i)return Me(t,i)?void 0:i.surface===`impl`&&t.kind!==`app`?R(e,n,r,`${z(t)} cannot import implementation target "${i.target}". Implementation imports are allowed only from app composition roots.`):Ne(e,t.target,i.target)?void 0:R(e,n,r,`${z(t)} imports "${i.target}" but does not declare a dependency that allows it.`);if(r.startsWith(`.`)||r.startsWith(`/`))return Oe(e,t,n,r)}function Oe(e,t,n,r){let i=L(e,ke(n,r));if(!(!i||Ae(t,i)))return R(e,n,r,`${z(t)} imports ${z(i)} through a source path. Use an Archicat alias instead.`)}function L(e,t){let n=M(t);for(let t of e.definitions){if(t.api.rootPath&&j(n,M(t.api.rootPath)))return{kind:t.kind,name:t.name,surface:`api`,target:t.apiTarget,definition:t};if(t.impl.rootPath&&j(n,M(t.impl.rootPath)))return{kind:t.kind,name:t.name,surface:`impl`,target:t.implTarget,definition:t}}for(let t of e.apps)if(j(n,M(t.rootPath)))return{kind:`app`,name:t.name,surface:`app`,target:t.target,app:t}}function ke(t,n){return M(n.startsWith(`/`)?n:e.resolve(e.dirname(t),n))}function Ae(e,t){return e.kind===t.kind&&e.name===t.name}function je(e,t){for(let n of e.definitions){if(n.implAlias&&(t===n.implAlias||t.startsWith(`${n.implAlias}/`)))return{kind:n.kind,name:n.name,surface:`impl`,target:n.implTarget};if(t===n.alias||t.startsWith(`${n.alias}/`))return{kind:n.kind,name:n.name,surface:`api`,target:n.apiTarget}}}function Me(e,t){return e.kind===t.kind&&e.name===t.name&&t.surface===`api`}function Ne(e,t,n){let r=new Set,i=[t];for(;i.length>0;){let t=i.shift();if(t===n)return!0;if(!r.has(t)){r.add(t);for(let n of e.graph.dependencies.filter(e=>e.from===t))i.push(n.to)}}return!1}function R(e,t,n,r){return{filePath:N(e.rootDir,t),importPath:n,message:r}}function z(e){return e.kind===`app`?`App "${e.name}"`:`${Pe(e.kind)} "${e.name}" ${e.surface}`}function Pe(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function B(e){return{exitCode:0,lines:e.map(e=>({kind:`success`,message:e}))}}function Fe(e){return{exitCode:1,lines:e.map(e=>({kind:`error`,message:e}))}}async function Ie(e){let t=await we(e.config);return t.length===0?B([`Architecture check passed.`]):Fe(t.map(e=>`${e.filePath}\n import: ${e.importPath}\n ${e.message}`))}async function Le(e){let t=await k(e);return[...Re(t),...ze(t),...Be(t)]}function Re(n){let r=e.join(n.outDir,`tsconfig.json`);return t.existsSync(r)?[]:[{severity:`warning`,message:`Generated tsconfig does not exist yet: ${r}. Run archicat generate.`}]}function ze(n){let i=e.join(n.rootDir,`tsconfig.json`);if(!t.existsSync(i))return[{severity:`warning`,message:`Root tsconfig.json was not found: ${i}`}];let a=r.parseConfigFileTextToJson(i,t.readFileSync(i,`utf8`));if(a.error)return[{severity:`warning`,message:`Failed to parse root tsconfig.json: ${r.flattenDiagnosticMessageText(a.error.messageText,`
|
|
2
|
-
`)}`}];let o=a.config,s=[];return o.extends!==`./.archicat/tsconfig.json`&&o.extends!==`.archicat/tsconfig.json`&&s.push({severity:`warning`,message:`Root tsconfig.json should extend ./.archicat/tsconfig.json for Archicat aliases to work like Nuxt.`}),(o.compilerOptions?.rootDir===`src`||o.compilerOptions?.rootDir===`./src`)&&s.push({severity:`warning`,message:`compilerOptions.rootDir is set to src. Generated .archicat files live outside src and may break tsc.`}),o.compilerOptions?.paths!==void 0&&s.push({severity:`warning`,message:`compilerOptions.paths should move to archicat.config.ts alias. Root tsconfig paths can override generated Archicat aliases.`}),s}function Be(n){let r=[];for(let i of n.definitions){let n=e.join(i.definitionDir,`api`),a=e.join(i.definitionDir,`impl`);!i.api.rootPath&&t.existsSync(n)&&r.push({severity:`warning`,message:`${V(i.kind)} "${i.name}" has a physical api directory but its contract omits api.root. Archicat treats the public API as empty.`}),!i.impl.rootPath&&t.existsSync(a)&&r.push({severity:`warning`,message:`${V(i.kind)} "${i.name}" has a physical impl directory but its contract omits impl.root. Archicat treats the implementation as no-op.`})}return r}function V(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}async function Ve(e){let t=await Le(e.config);return t.length===0?B([`Doctor found no issues.`]):{exitCode:+!!t.some(e=>e.severity===`error`),lines:t.map(e=>({kind:e.severity===`error`?`error`:`warning`,message:e.message}))}}function He(e){t.existsSync(e)&&t.rmSync(e,{recursive:!0,force:!0}),t.mkdirSync(e,{recursive:!0})}function H(n,r){t.mkdirSync(e.dirname(n),{recursive:!0}),t.writeFileSync(n,r,`utf8`)}function U(e,t){H(e,`${JSON.stringify(t,null,2)}\n`)}function Ue(t){let n=[...t.modules.map(e=>e.apiTarget),...t.libraries.map(e=>e.apiTarget)],r=n,i=t.libraries.map(e=>e.apiTarget),a=i,o=t.graph.targets.map(e=>e.key),s=`import 'archicat';
|
|
1
|
+
import{createRequire as e}from"node:module";import t from"node:fs";import n from"node:path";import{createJiti as r}from"jiti";import i from"typescript";import{consola as a}from"consola";const o=Object.freeze({configFileName:`archicat.config.ts`,root:`.`,outDir:`.archicat`,alias:Object.freeze({}),generated:Object.freeze({reportsDirName:`reports`,buildReportFileName:`build.report.json`,graphReportFileName:`graph.report.json`,tsconfigFileName:`tsconfig.json`,typesInclude:`./types/**/*.d.ts`,ignoredDirectoryNames:Object.freeze([`node_modules`,`.git`,`.archicat`,`archicat-report`,`dist`,`build`,`coverage`])}),typescript:Object.freeze({consumerTsconfigFileName:`tsconfig.json`,tsConfig:Object.freeze({include:Object.freeze([]),exclude:Object.freeze([]),files:Object.freeze([])})}),prefixes:Object.freeze({module:`@module`,library:`@library`}),modules:Object.freeze({include:Object.freeze([`./src/modules`])}),libraries:Object.freeze({include:Object.freeze([])}),apps:Object.freeze({include:Object.freeze([])})});function s(e){let n=t.readFileSync(e,`utf8`),r=i.parseConfigFileTextToJson(e,n);if(r.error)throw Error(ne(r.error));if(r.config==null||typeof r.config!=`object`||Array.isArray(r.config))throw Error(`Invalid tsconfig object: ${e}`);return r.config}function c(e,t=`tsconfig`){let n=e.compilerOptions;if(n==null)return{};if(typeof n!=`object`||Array.isArray(n))throw Error(`Tsconfig compilerOptions must be an object: ${t}`);return n}function l(e,t){let n=e.extends;if(n===void 0)return[];if(typeof n==`string`)return[u(t,n)];if(Array.isArray(n)&&n.every(e=>typeof e==`string`))return n.map(e=>u(t,e));throw Error(`Tsconfig extends must be a string or string array: ${t}`)}function ee(t,r){return n.isAbsolute(r)||r.startsWith(`.`)?d(n.resolve(t,r),r):te(e(n.join(t,o.configFileName)),r,r)}function u(t,r){return n.isAbsolute(r)||r.startsWith(`.`)?d(n.resolve(n.dirname(t),r),t):te(e(t),r,t)}function te(e,t,n){for(let n of f(t))try{return e.resolve(n)}catch{continue}throw Error(`Unable to resolve tsconfig extends "${t}": ${n}`)}function d(e,n){for(let n of f(e))if(t.existsSync(n)&&t.statSync(n).isFile())return n;throw Error(`Unable to resolve tsconfig extends "${e}": ${n}`)}function f(e){return[e,`${e}.json`,n.join(e,o.typescript.consumerTsconfigFileName)]}function ne(e){let t=i.flattenDiagnosticMessageText(e.messageText,`
|
|
2
|
+
`);if(e.file&&e.start!==void 0){let n=e.file.getLineAndCharacterOfPosition(e.start);return`${e.file.fileName}:${n.line+1}:${n.character+1} - ${t}`}return t}async function re(e=o.configFileName){let r=process.cwd(),i=n.resolve(r,e);if(!t.existsSync(i))throw Error(`Archicat config was not found: ${i}`);let a=await ie(i,r);ce(a,i);let s=ae(a),c=n.resolve(r,s.root),l=n.resolve(c,s.outDir),ee=n.resolve(l,o.generated.reportsDirName),u=se(c,s.typescript.tsConfig.extends);return{configFilePath:i,rootDir:c,outDir:l,reportsDir:ee,...u?{tsconfigPath:u}:{},config:a,resolvedConfig:s}}async function ie(e,t){return await r(t,{interopDefault:!0,extensions:[`.js`,`.cjs`,`.mjs`,`.ts`,`.cts`,`.mts`,`.json`]}).import(e,{default:!0})}function ae(e){return{root:e.root??o.root,outDir:e.outDir??o.outDir,typescript:oe(e),alias:{...o.alias,...e.alias??{}},prefixes:{module:e.prefixes?.module??o.prefixes.module,library:e.prefixes?.library??o.prefixes.library},modules:p(e.modules,o.modules),libraries:p(e.libraries,o.libraries),apps:p(e.apps,o.apps)}}function oe(e){let t=e.typescript?.tsConfig,n=o.typescript.tsConfig,r={include:[...t?.include??n.include],exclude:[...t?.exclude??n.exclude],files:[...t?.files??n.files]};return t?.extends&&(r.extends=t.extends),{tsConfig:r}}function p(e,t){return{include:[...e?.include??t.include]}}function se(e,t){if(t)return ee(e,t)}function ce(e,t){if(typeof e!=`object`||!e)throw Error(`Invalid Archicat config: ${t}`);let n=e;m(n.root,`root`,t),m(n.outDir,`outDir`,t),le(n.typescript?.tsConfig,t),h(n.modules?.include,`modules.include`,t),h(n.libraries?.include,`libraries.include`,t),h(n.apps?.include,`apps.include`,t),de(n.alias,`alias`,t),g(n.prefixes?.module,`prefixes.module`,t),g(n.prefixes?.library,`prefixes.library`,t)}function le(e,t){if(e===void 0)return;if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Archicat config typescript.tsConfig must be an object: ${t}`);let n=e;m(n.extends,`typescript.tsConfig.extends`,t),h(n.include,`typescript.tsConfig.include`,t),h(n.exclude,`typescript.tsConfig.exclude`,t),h(n.files,`typescript.tsConfig.files`,t),ue(n.compilerOptions,t)}function ue(e,t){if(e===void 0)return;if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Archicat config typescript.tsConfig.compilerOptions must be an object: ${t}`);let n=e;if(Object.hasOwn(n,`paths`))throw Error(`Archicat config typescript.tsConfig.compilerOptions.paths is not supported. Move aliases into archicat.config.ts alias.`);if(Object.hasOwn(n,`baseUrl`))throw Error(`Archicat config typescript.tsConfig.compilerOptions.baseUrl is not supported. Move aliases into archicat.config.ts alias.`);if(Object.keys(n).length>0)throw Error(`Archicat config typescript.tsConfig.compilerOptions is not supported. Put compiler options in the base or app tsconfig.`)}function m(e,t,n){if(e!==void 0&&(typeof e!=`string`||e.trim()===``))throw Error(`Archicat ${t} must be a non-empty string when defined: ${n}`)}function h(e,t,n){if(e!==void 0&&(!Array.isArray(e)||e.some(e=>typeof e!=`string`||e.trim()===``)))throw Error(`Archicat config ${t} must be an array of non-empty strings: ${n}`)}function g(e,t,n){if(e!==void 0&&(typeof e!=`string`||e.trim()===``||e.includes(`*`)||e.endsWith(`/`)))throw Error(`Archicat config ${t} must be a non-empty prefix without wildcard or trailing slash: ${n}`)}function de(e,t,n){if(e!==void 0){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Archicat config ${t} must be an object of non-empty string aliases: ${n}`);for(let[r,i]of Object.entries(e))if(r.trim()===``||typeof i!=`string`||i.trim()===``)throw Error(`Archicat config ${t} must contain non-empty string aliases: ${n}`)}}function _(e,t,n){let r=t.flatMap(t=>fe(e,t,n));return Array.from(new Set(r)).sort((e,t)=>e.localeCompare(t))}function fe(e,r,i){let a=n.resolve(e,r);if(r.includes(`*`))return pe(e,r).filter(e=>n.basename(e)===i);if(!t.existsSync(a))return[];let o=t.statSync(a);return o.isFile()?n.basename(a)===i?[a]:[]:o.isDirectory()?v(a,i):[]}function v(e,r){let i=[],a=t.readdirSync(e,{withFileTypes:!0});for(let t of a){if(he(t.name))continue;let a=n.join(e,t.name);if(t.isDirectory()){i.push(...v(a,r));continue}t.isFile()&&t.name===r&&i.push(a)}return i}function pe(e,r){let i=n.resolve(e,r).split(n.sep);if(i.filter(e=>e.includes(`*`)).length!==1)throw Error(`Archicat supports exactly one wildcard segment per include pattern: ${r}`);let a=i.findIndex(e=>e.includes(`*`)),o=i.slice(0,a).join(n.sep)||n.sep,s=i[a]??`*`,c=i.slice(a+1),l=me(s);return t.existsSync(o)?t.readdirSync(o,{withFileTypes:!0}).filter(e=>e.isDirectory()).filter(e=>l.test(e.name)).map(e=>n.join(o,e.name,...c)).filter(e=>t.existsSync(e)&&t.statSync(e).isFile()):[]}function me(e){let t=e.replace(/[.+?^${}()|[\]\\]/gu,`\\$&`).replace(/\*/gu,`.*`);return RegExp(`^${t}$`,`u`)}function he(e){return o.generated.ignoredDirectoryNames.includes(e)}async function y(e,t){switch(t){case`module`:return ge(e);case`library`:return _e(e);case`app`:return ve(e)}}async function ge(e){let t=await b(e,n.dirname(e));return x(t,e,`module`),{kind:`module`,contractFilePath:e,definitionDir:n.dirname(e),contract:t}}async function _e(e){let t=await b(e,n.dirname(e));return x(t,e,`library`),{kind:`library`,contractFilePath:e,definitionDir:n.dirname(e),contract:t}}async function ve(e){let t=await b(e,n.dirname(e));return x(t,e,`app`),{kind:`app`,contractFilePath:e,definitionDir:n.dirname(e),contract:t}}async function b(e,t){return await r(t,{interopDefault:!0,extensions:[`.js`,`.cjs`,`.mjs`,`.ts`,`.cts`,`.mts`,`.json`]}).import(e,{default:!0})}function x(e,t,n){if(typeof e!=`object`||!e)throw Error(`Invalid Archicat ${n} definition: ${t}`);let r=e;if(r.kind!==n)throw Error(`Archicat ${n} file must export define${ye(n)}(...): ${t}`);if(typeof r.name!=`string`||r.name.trim()===``)throw Error(`Archicat ${n} must define a non-empty name: ${t}`);if(n===`app`){w(r.root,`root`,t),C(r.dependencies,t,n);return}let i=r;S(i.api,`api`,t,n),S(i.impl,`impl`,t,n)}function S(e,t,n,r){if(typeof e!=`object`||!e)throw Error(`Archicat ${r}.${t} must be a surface object: ${n}`);w(e.root,`${t}.root`,n),C(e.dependencies,n,`${r}.${t}`)}function C(e,t,n){if(!Array.isArray(e)||e.some(e=>typeof e!=`string`||e.trim()===``))throw Error(`Archicat ${n} dependencies must be an array of non-empty strings: ${t}`)}function w(e,t,n){if(e!==void 0&&(typeof e!=`string`||e.trim()===``))throw Error(`Archicat ${t} must be a non-empty string when defined: ${n}`)}function ye(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function be(e){let t=new Map;for(let n of e){let e=t.get(n.from)??[];e.push(n.to),t.set(n.from,e)}let n=new Set,r=new Set;for(let e of t.keys())xe(e,t,n,r,[])}function xe(e,t,n,r,i){if(!r.has(e)){if(n.has(e)){let t=i.indexOf(e),n=[...i.slice(t<0?0:t),e];throw Error(`Cyclic Archicat dependency detected: ${n.join(` -> `)}`)}n.add(e);for(let a of t.get(e)??[])xe(a,t,n,r,[...i,e]);n.delete(e),r.add(e)}}function Se(e){let t=/^(module|library)\.([a-z][a-z0-9-]*)\.(api|impl)$/u.exec(e);if(t)return{kind:t[1],name:t[2],surface:t[3]}}function Ce(e){return`${e.kind}.${e.surface}`}function T(e,t,n){let r=Se(t);if(!r)throw Error(`${E(e)} declares invalid dependency target "${t}".`);if(!n.has(t))throw Error(`${E(e)} declares unknown dependency "${t}".`);if(e.kind===r.kind&&e.name===r.name)throw Error(`${E(e)} cannot depend on itself: ${t}`);if(!we(e,r))throw Error(`${E(e)} cannot depend on ${Ce(r)} target "${t}".`)}function we(e,t){switch(e.surface){case`api`:return e.kind===`module`?t.surface===`api`&&(t.kind===`module`||t.kind===`library`):e.kind===`library`?t.surface===`api`&&t.kind===`library`:!1;case`impl`:return e.kind===`module`?t.surface===`api`&&(t.kind===`module`||t.kind===`library`):e.kind===`library`?t.surface===`api`&&t.kind===`library`:!1;case`app`:return t.kind===`module`||t.kind===`library`}}function E(e){return e.kind===`app`?`App "${e.name}"`:`${Te(e.kind)} "${e.name}" ${e.surface}`}function Te(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function Ee(e,t){let n=t.filter(e=>e.kind===`module`).map(t=>De(e,t)),r=t.filter(e=>e.kind===`library`).map(t=>Oe(e,t)),i=t.filter(e=>e.kind===`app`).map(e=>ke(e)),a=[...n,...r];je([...a,...i]);let o=Ae(a,i);return Me(a,i,o.targets),be(o.dependencies),{rootDir:e.rootDir,outDir:e.outDir,reportsDir:e.reportsDir,...e.tsconfigPath?{tsconfigPath:e.tsconfigPath}:{},configFilePath:e.configFilePath,config:e.resolvedConfig,modules:n,libraries:r,apps:i,definitions:a,graph:o}}function De(e,t){let{contract:r,contractFilePath:i,definitionDir:a}=t;k(r.name,i,`module`);let o=r.api.root?O(a,r.api.root,`api`,r.name):void 0,s=r.impl.root?O(a,r.impl.root,`impl`,r.name):void 0,c=`${e.resolvedConfig.prefixes.module}/${r.name}`;return{kind:`module`,name:r.name,apiTarget:`module.${r.name}.api`,implTarget:`module.${r.name}.impl`,alias:c,aliasGlob:`${c}/*`,implAlias:`${c}/impl`,implAliasGlob:`${c}/impl/*`,contractFilePath:i,definitionDir:a,api:D(o,r.api.dependencies,n.join(e.outDir,`modules`,r.name,`api`)),impl:D(s,r.impl.dependencies,n.join(e.outDir,`modules`,r.name,`impl`))}}function Oe(e,t){let{contract:r,contractFilePath:i,definitionDir:a}=t;k(r.name,i,`library`);let o=r.api.root?O(a,r.api.root,`api`,r.name):void 0,s=r.impl.root?O(a,r.impl.root,`impl`,r.name):void 0,c=`${e.resolvedConfig.prefixes.library}/${r.name}`;return{kind:`library`,name:r.name,apiTarget:`library.${r.name}.api`,implTarget:`library.${r.name}.impl`,alias:c,aliasGlob:`${c}/*`,implAlias:`${c}/impl`,implAliasGlob:`${c}/impl/*`,contractFilePath:i,definitionDir:a,api:D(o,r.api.dependencies,n.join(e.outDir,`libraries`,r.name,`api`)),impl:D(s,r.impl.dependencies,n.join(e.outDir,`libraries`,r.name,`impl`))}}function ke(e){let{contract:t,contractFilePath:n,definitionDir:r}=e;return k(t.name,n,`app`),{kind:`app`,name:t.name,target:`app.${t.name}`,contractFilePath:n,definitionDir:r,rootPath:t.root?O(r,t.root,`app`,t.name):r,dependencies:[...t.dependencies]}}function D(e,t,n){return{...e?{rootPath:e}:{},mirrorRootPath:n,dependencies:[...t]}}function O(e,r,i,a){let o=n.resolve(e,r);if(!t.existsSync(o))throw Error(`Definition "${a}" declares ${i} root that does not exist: ${o}`);if(!t.statSync(o).isDirectory())throw Error(`Definition "${a}" declares ${i} root that is not a directory: ${o}`);return o}function Ae(e,t){let n=e.flatMap(e=>[{key:e.apiTarget,kind:e.kind,name:e.name,surface:`api`},{key:e.implTarget,kind:e.kind,name:e.name,surface:`impl`}]),r=[...e.flatMap(e=>[...e.api.dependencies.map(t=>({from:e.apiTarget,to:t,origin:`declared`})),...e.impl.dependencies.map(t=>({from:e.implTarget,to:t,origin:`declared`}))]),...t.flatMap(e=>e.dependencies.map(t=>({from:e.target,to:t,origin:`declared`})))];return{targets:n,dependencies:[...e.map(e=>({from:e.implTarget,to:e.apiTarget,origin:`derived`})),...r]}}function k(e,t,n){if(!/^[a-z][a-z0-9-]*$/u.test(e))throw Error(`Invalid Archicat ${n} name "${e}" in ${t}. Use ^[a-z][a-z0-9-]*$`)}function je(e){let t=new Map;for(let n of e){let e=`${n.kind}.${n.name}`,r=t.get(e);if(r)throw Error(`Duplicate Archicat ${n.kind} name "${n.name}" in ${r} and ${n.contractFilePath}`);t.set(e,n.contractFilePath)}}function Me(e,t,n){let r=new Set(n.map(e=>e.key));for(let t of e){for(let e of t.api.dependencies)T(A(t,`api`),e,r);for(let e of t.impl.dependencies)T(A(t,`impl`),e,r)}for(let e of t)for(let t of e.dependencies)T({kind:`app`,name:e.name,surface:`app`,target:e.target},t,r)}function A(e,t){return{kind:e.kind,name:e.name,surface:t,target:t===`api`?e.apiTarget:e.implTarget}}async function Ne(e){let t=await re(e),n=_(t.rootDir,t.resolvedConfig.modules.include,`archicat.module.ts`),r=_(t.rootDir,t.resolvedConfig.libraries.include,`archicat.library.ts`),i=_(t.rootDir,t.resolvedConfig.apps.include,`archicat.app.ts`);if(n.length===0&&r.length===0&&i.length===0)throw Error(`No Archicat definition files matched configured include roots.`);return Ee(t,[...await Promise.all(n.map(e=>y(e,`module`))),...await Promise.all(r.map(e=>y(e,`library`))),...await Promise.all(i.map(e=>y(e,`app`)))])}var Pe=class{options;project;constructor(e){this.options=e}async getProject(){return this.project??=await Ne(this.options.config),this.project}},j=class e{name;steps=[];constructor(e){this.name=e}static build(t){return new e(t)}use(e){return this.steps.push(e),this}async run(e){let t=new Pe(e),n=Date.now(),r=[{kind:`info`,message:`Archicat ${this.name}`},{kind:`info`,message:``}];for(let e of this.steps){let i=await e.run(t);if(r.push(...i.lines),i.exitCode!==0)return r.push({kind:`info`,message:``}),r.push({kind:`error`,message:`Failed in ${Date.now()-n}ms`}),{exitCode:i.exitCode,lines:r}}return r.push({kind:`info`,message:``}),r.push({kind:`success`,message:`Done in ${Date.now()-n}ms`}),{exitCode:0,lines:r}}};function M(e){return e.split(n.sep).join(`/`)}function Fe(e,t){let r=n.dirname(e),i=n.parse(t),a=n.join(i.dir,i.name),o=M(n.relative(r,a));return o.startsWith(`.`)||(o=`./${o}`),`${o}.js`}function N(e,t){let r=n.relative(t,e);return r===``||!!r&&!r.startsWith(`..`)&&!n.isAbsolute(r)}function P(e){return e.replace(/\.(?:js|mjs|cjs|ts|mts|cts|tsx)$/u,``)}function F(e,t){return M(n.relative(e,t))}function Ie(e){return[...Le(e),...Ge(e)]}function Le(e){let n=Ke(e);if(!t.existsSync(n))return[{severity:`warning`,message:`Consumer tsconfig was not found: ${n}`}];let r=[],i=Re(n,r);if(!i)return r;let a=ze(i,n,r);return a?(Be(r,e,i),Ve(r,a),He(r,a),Ue(r,a),We(r,i),r):r}function Re(e,t){try{return s(e)}catch(e){t.push({severity:`warning`,message:`Failed to parse consumer tsconfig: ${Xe(e)}`});return}}function ze(e,t,n){try{return c(e,t)}catch(e){n.push({severity:`warning`,message:Xe(e)});return}}function Be(e,t,n){let r=Je(t);n.extends!==r&&e.push({severity:`warning`,message:`Consumer tsconfig should extend ${r} for generated Archicat aliases to work.`})}function Ve(e,t){let n=t.rootDir;n!==`src`&&n!==`./src`||e.push({severity:`warning`,message:`compilerOptions.rootDir is set to src. Generated .archicat files live outside src and may break tsc.`})}function He(e,t){Object.hasOwn(t,`paths`)&&e.push({severity:`warning`,message:`compilerOptions.paths should move to archicat.config.ts alias. Consumer tsconfig paths can override generated Archicat aliases.`})}function Ue(e,t){Object.hasOwn(t,`baseUrl`)&&e.push({severity:`warning`,message:`compilerOptions.baseUrl is not supported. Move aliases into archicat.config.ts alias.`})}function We(e,t){t.include===void 0&&t.exclude===void 0&&t.files===void 0||e.push({severity:`warning`,message:`Consumer tsconfig include/exclude/files should move to archicat.config.ts typescript.tsConfig so generated Archicat types stay included.`})}function Ge(e){let r=[];for(let i of e.definitions){let e=n.join(i.definitionDir,`api`),a=n.join(i.definitionDir,`impl`);!i.api.rootPath&&t.existsSync(e)&&r.push({severity:`warning`,message:`${I(i.kind)} "${i.name}" has a physical api directory but its contract omits api.root. Archicat treats the public API as empty.`}),!i.impl.rootPath&&t.existsSync(a)&&r.push({severity:`warning`,message:`${I(i.kind)} "${i.name}" has a physical impl directory but its contract omits impl.root. Archicat treats the implementation as no-op.`})}return r}function Ke(e){return n.join(e.rootDir,o.typescript.consumerTsconfigFileName)}function qe(e){return n.join(e.outDir,o.generated.tsconfigFileName)}function Je(e){let t=M(n.relative(e.rootDir,qe(e)));return Ye(t)||(t=`./${t}`),t}function Ye(e){return e.startsWith(`./`)||e.startsWith(`../`)}function Xe(e){return e instanceof Error?e.message:String(e)}function I(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function L(e){return t.existsSync(e)?t.statSync(e).isFile()?R(e)?[e]:[]:z(e).filter(R).sort((e,t)=>e.localeCompare(t)):[]}function R(e){return/\.(?:ts|mts|cts|tsx)$/u.test(e)&&!/\.d\.(?:ts|mts|cts)$/u.test(e)}function z(e){let r=[],i=t.readdirSync(e,{withFileTypes:!0});for(let t of i){let i=n.join(e,t.name);if(t.isDirectory()){r.push(...z(i));continue}t.isFile()&&r.push(i)}return r}function Ze(e){let n=i.createSourceFile(e,t.readFileSync(e,`utf8`),i.ScriptTarget.Latest,!0),r=[],a=e=>{if(i.isImportDeclaration(e)&&i.isStringLiteral(e.moduleSpecifier)&&r.push({moduleSpecifier:e.moduleSpecifier.text,kind:`import`}),i.isExportDeclaration(e)&&e.moduleSpecifier&&i.isStringLiteral(e.moduleSpecifier)&&r.push({moduleSpecifier:e.moduleSpecifier.text,kind:`export`}),i.isCallExpression(e)&&e.expression.kind===i.SyntaxKind.ImportKeyword){let[t]=e.arguments;t&&i.isStringLiteral(t)&&r.push({moduleSpecifier:t.text,kind:`dynamic-import`})}i.forEachChild(e,a)};return a(n),r}function Qe(e){let n=i.createSourceFile(e,t.readFileSync(e,`utf8`),i.ScriptTarget.Latest,!0),r=!1,a=e=>{if(!r){if(i.isExportAssignment(e)&&!e.isExportEquals){r=!0;return}if($e(e)){r=!0;return}if(i.isExportDeclaration(e)&&e.exportClause&&i.isNamedExports(e.exportClause))for(let t of e.exportClause.elements){let e=t.name.text,n=t.propertyName?.text;if(e==="default"||n==="default"){r=!0;return}}i.forEachChild(e,a)}};return a(n),r}function $e(e){let t=i.canHaveModifiers(e)?i.getModifiers(e):void 0;if(!t)return!1;let n=t.some(e=>e.kind===i.SyntaxKind.ExportKeyword),r=t.some(e=>e.kind===i.SyntaxKind.DefaultKeyword);return n&&r}function et(e){return nt(e)}function tt(e){return`${e.filePath}\n import: ${e.importPath}\n ${e.message}`}function nt(e){let t=[],n=[...e.definitions.flatMap(e=>rt(e)),...e.apps.flatMap(e=>L(e.rootPath))];for(let r of n){let n=B(e,r);if(n)for(let i of Ze(r)){let a=it(e,n,r,i.moduleSpecifier);a&&t.push(a)}}return t}function rt(e){return[...e.api.rootPath?L(e.api.rootPath):[],...e.impl.rootPath?L(e.impl.rootPath):[]]}function it(e,t,n,r){let i=ct(e,r);if(i)return lt(t,i)?void 0:i.surface===`impl`&&t.kind!==`app`?V(e,n,r,`${H(t)} cannot import implementation target "${i.target}". Implementation imports are allowed only from app composition roots.`):ut(e,t.target,i.target)?void 0:V(e,n,r,`${H(t)} imports "${i.target}" but does not declare a dependency that allows it.`);if(r.startsWith(`.`)||r.startsWith(`/`))return at(e,t,n,r)}function at(e,t,n,r){let i=B(e,ot(n,r));if(!(!i||st(t,i)))return V(e,n,r,`${H(t)} imports ${H(i)} through a source path. Use an Archicat alias instead.`)}function B(e,t){let n=P(t);for(let t of e.definitions){if(t.api.rootPath&&N(n,P(t.api.rootPath)))return{kind:t.kind,name:t.name,surface:`api`,target:t.apiTarget,definition:t};if(t.impl.rootPath&&N(n,P(t.impl.rootPath)))return{kind:t.kind,name:t.name,surface:`impl`,target:t.implTarget,definition:t}}for(let t of e.apps)if(N(n,P(t.rootPath)))return{kind:`app`,name:t.name,surface:`app`,target:t.target,app:t}}function ot(e,t){return P(t.startsWith(`/`)?t:n.resolve(n.dirname(e),t))}function st(e,t){return e.kind===t.kind&&e.name===t.name}function ct(e,t){for(let n of e.definitions){if(n.implAlias&&(t===n.implAlias||t.startsWith(`${n.implAlias}/`)))return{kind:n.kind,name:n.name,surface:`impl`,target:n.implTarget};if(t===n.alias||t.startsWith(`${n.alias}/`))return{kind:n.kind,name:n.name,surface:`api`,target:n.apiTarget}}}function lt(e,t){return e.kind===t.kind&&e.name===t.name&&t.surface===`api`}function ut(e,t,n){let r=new Set,i=[t];for(;i.length>0;){let t=i.shift();if(t===n)return!0;if(!r.has(t)){r.add(t);for(let n of e.graph.dependencies.filter(e=>e.from===t))i.push(n.to)}}return!1}function V(e,t,n,r){return{filePath:F(e.rootDir,t),importPath:n,message:r}}function H(e){return e.kind===`app`?`App "${e.name}"`:`${dt(e.kind)} "${e.name}" ${e.surface}`}function dt(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function ft(e){t.existsSync(e)&&t.rmSync(e,{recursive:!0,force:!0}),t.mkdirSync(e,{recursive:!0})}function U(e,r){t.mkdirSync(n.dirname(e),{recursive:!0}),t.writeFileSync(e,r,`utf8`)}function W(e,t){U(e,`${JSON.stringify(t,null,2)}\n`)}function pt(e){let t=[...e.modules.map(e=>e.apiTarget),...e.libraries.map(e=>e.apiTarget)],r=t,i=e.libraries.map(e=>e.apiTarget),a=i,o=e.graph.targets.map(e=>e.key),s=`import 'archicat';
|
|
3
3
|
|
|
4
4
|
declare module 'archicat' {
|
|
5
|
-
${
|
|
5
|
+
${G(`ArchicatModuleApiDependencies`,t)}
|
|
6
6
|
|
|
7
|
-
${
|
|
7
|
+
${G(`ArchicatModuleImplDependencies`,r)}
|
|
8
8
|
|
|
9
|
-
${
|
|
9
|
+
${G(`ArchicatLibraryApiDependencies`,i)}
|
|
10
10
|
|
|
11
|
-
${
|
|
11
|
+
${G(`ArchicatLibraryImplDependencies`,a)}
|
|
12
12
|
|
|
13
|
-
${
|
|
13
|
+
${G(`ArchicatAppDependencies`,o)}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export {};
|
|
17
|
-
`;
|
|
18
|
-
`)}\n }`}function
|
|
19
|
-
`);return}let
|
|
20
|
-
`)}function
|
|
17
|
+
`;U(n.join(e.outDir,`types`,`graph.d.ts`),s)}function G(e,t){return` interface ${e} {\n${Array.from(new Set(t)).sort((e,t)=>e.localeCompare(t)).map(e=>` '${e}': true;`).join(`
|
|
18
|
+
`)}\n }`}function mt(e){for(let t of e)switch(t.kind){case`module`:ht(t);break;case`library`:gt(t);break}}function ht(e){K(e.api),q(e,`module`)}function gt(e){K(e.api),q(e,`library`)}function K(e){if(!e.rootPath){U(n.join(e.mirrorRootPath,`index.ts`),`${Y()}export {};
|
|
19
|
+
`);return}let t=L(e.rootPath),r=new Set;for(let i of t){let t=M(n.relative(e.rootPath,i));r.add(t),J(n.join(e.mirrorRootPath,t),i)}r.has(`index.ts`)||U(n.join(e.mirrorRootPath,`index.ts`),`${Y()}export {};
|
|
20
|
+
`)}function q(e,t){let r=e.impl.rootPath?_t(e.impl.rootPath):void 0;if(!r){let r=t===`module`?`ArchicatModuleImplementation`:`ArchicatLibraryImplementation`,i=`${Y()}
|
|
21
21
|
export const ${r} = {
|
|
22
|
-
name: '${
|
|
22
|
+
name: '${e.name}',
|
|
23
23
|
assemblies: [],
|
|
24
24
|
schemas: [],
|
|
25
25
|
routes: [],
|
|
26
26
|
} as const;
|
|
27
27
|
|
|
28
28
|
export default ${r};
|
|
29
|
-
`;
|
|
29
|
+
`;U(n.join(e.impl.mirrorRootPath,`index.ts`),i);return}J(n.join(e.impl.mirrorRootPath,`index.ts`),r)}function J(e,t){let n=Fe(e,t),r=Qe(t)?`export { default } from '${n}';\n`:``;U(e,`${Y()}
|
|
30
30
|
export * from '${n}';
|
|
31
|
-
${r}`)}function
|
|
32
|
-
`}function
|
|
33
|
-
`)
|
|
34
|
-
`))}function $(e){switch(e.kind){case`success`:console.log(`✓ ${e.message}`);return;case`warning`:console.warn(`! ${e.message}`);return;case`error`:console.error(`✗ ${e.message}`);return;case`info`:console.log(e.message);return}}export{ft as runMain};
|
|
31
|
+
${r}`)}function _t(e){for(let t of[`index.ts`,`index.mts`,`index.cts`,`index.tsx`]){let r=n.join(e,t);if(L(r).length>0)return r}}function Y(){return`// Mirrored by Archicat.
|
|
32
|
+
`}function vt(e){W(n.join(e.reportsDir,o.generated.buildReportFileName),yt(e)),W(n.join(e.reportsDir,o.generated.graphReportFileName),bt(e))}function yt(e){return{generatedBy:`archicat`,schemaVersion:1,prefixes:e.config.prefixes,outputs:{outDir:F(e.rootDir,e.outDir),reportsDir:F(e.rootDir,e.reportsDir)},targets:e.graph.targets.map(e=>e.key),definitions:[...e.definitions.map(t=>xt(e,t)),...e.apps.map(t=>({kind:t.kind,name:t.name,targets:{app:t.target},aliases:{},dependencies:t.dependencies,contractFilePath:F(e.rootDir,t.contractFilePath),source:{root:F(e.rootDir,t.rootPath)},mirror:{}}))],dependencies:e.graph.dependencies}}function bt(e){return{generatedBy:`archicat`,schemaVersion:1,targets:e.graph.targets.map(e=>e.key),dependencies:e.graph.dependencies}}function xt(e,t){return{kind:t.kind,name:t.name,targets:{api:t.apiTarget,impl:t.implTarget},aliases:{api:t.alias,impl:e.apps.length>0?t.implAlias:void 0},dependencies:{api:t.api.dependencies,impl:t.impl.dependencies},contractFilePath:F(e.rootDir,t.contractFilePath),source:{root:F(e.rootDir,t.definitionDir),api:t.api.rootPath?F(e.rootDir,t.api.rootPath):void 0,impl:t.impl.rootPath?F(e.rootDir,t.impl.rootPath):void 0},mirror:{api:F(e.rootDir,t.api.mirrorRootPath),impl:F(e.rootDir,t.impl.mirrorRootPath)}}}function St(e){Mt(e.tsconfigPath),W(n.join(e.outDir,o.generated.tsconfigFileName),Ct(e))}function Ct(e){let t={compilerOptions:wt(e),include:Et(e)},n=Tt(e),r=Dt(e),i=Ot(e);return n&&(t.extends=n),r.length>0&&(t.exclude=r),i.length>0&&(t.files=i),t}function wt(e){let t=At(e),n=kt(e);return It(e,t,n),{paths:{...t,...n}}}function Tt(e){return e.tsconfigPath?Z(e.outDir,e.tsconfigPath):void 0}function Et(e){return jt([...X(e,e.config.typescript.tsConfig.include),o.generated.typesInclude])}function Dt(e){return X(e,e.config.typescript.tsConfig.exclude)}function Ot(e){return X(e,e.config.typescript.tsConfig.files)}function kt(e){let t={},r=e.apps.length>0;for(let i of e.definitions)t[i.alias]=[Z(e.outDir,n.join(i.api.mirrorRootPath,`index.ts`))],t[i.aliasGlob]=[Z(e.outDir,n.join(i.api.mirrorRootPath,`*`))],r&&i.implAlias&&i.implAliasGlob&&(t[i.implAlias]=[Z(e.outDir,n.join(i.impl.mirrorRootPath,`index.ts`))],t[i.implAliasGlob]=[Z(e.outDir,n.join(i.impl.mirrorRootPath,`*`))]);return t}function At(e){let t={};for(let[r,i]of Object.entries(e.config.alias)){let a=n.isAbsolute(i)?i:n.resolve(e.rootDir,i);t[r]=[Z(e.outDir,a)]}return t}function X(e,t){return t.map(t=>{let r=n.isAbsolute(t)?t:n.resolve(e.rootDir,t);return Z(e.outDir,r)})}function Z(e,t){let r=M(n.relative(e,t));return r.startsWith(`.`)||(r=`./${r}`),r}function jt(e){return[...new Set(e)]}function Mt(e){e&&Nt(e,new Set,new Set)}function Nt(e,t,r){let i=n.resolve(e);if(r.has(i))return;if(t.has(i))throw Error(`Circular tsconfig extends chain detected: ${i}`);t.add(i);let a=s(i),o=c(a,i);Pt(o,i),Ft(o,i);for(let e of l(a,i))Nt(e,t,r);t.delete(i),r.add(i)}function Pt(e,t){if(Object.hasOwn(e,`paths`))throw Error(`Base tsconfig compilerOptions.paths is not supported by Archicat. Move aliases into archicat.config.ts alias: ${t}`)}function Ft(e,t){if(Object.hasOwn(e,`baseUrl`))throw Error(`Base tsconfig compilerOptions.baseUrl is not supported by Archicat. Move aliases into archicat.config.ts alias: ${t}`)}function It(e,t,n){let r=Object.keys(t),i=Object.keys(n),a=Object.values(e.config.prefixes);for(let e of r){if(i.includes(e))throw Error(`Alias conflict: archicat.config.ts alias already defines "${e}", but Archicat needs it.`);for(let t of a)if(e===t||e===`${t}/*`||e.startsWith(`${t}/`))throw Error(`Alias conflict: archicat.config.ts alias "${e}" is inside Archicat reserved prefix "${t}". Remove the alias or configure another Archicat prefix.`)}}function Lt(e){Rt(e),ft(e.outDir),t.mkdirSync(n.join(e.outDir,`modules`),{recursive:!0}),t.mkdirSync(n.join(e.outDir,`libraries`),{recursive:!0}),t.mkdirSync(n.join(e.outDir,`types`),{recursive:!0}),t.mkdirSync(e.reportsDir,{recursive:!0}),mt(e.definitions),pt(e),St(e),vt(e)}function Rt(e){if(n.resolve(e.outDir)===n.resolve(e.rootDir))throw Error(`Archicat outDir cannot be the project root.`)}function zt(){return{name:`doctor`,async run(e){let t=Ie(await e.getProject());if(t.length===0)return Ht(`doctor`,`Project diagnostics passed.`);let n=t.some(e=>e.severity===`error`);return{exitCode:+!!n,lines:[{kind:n?`error`:`warning`,message:Q(`doctor`,n?`Project diagnostics failed.`:`Project diagnostics completed with warnings.`)},...t.map(e=>({kind:e.severity===`error`?`error`:`warning`,message:` ${e.message}`}))]}}}}function Bt(){return{name:`validate`,async run(e){let t=et(await e.getProject());return t.length===0?Ht(`validate`,`Architecture boundaries passed.`):{exitCode:1,lines:[{kind:`error`,message:Q(`validate`,`Architecture validation failed.`)},...t.map(e=>({kind:`error`,message:tt(e)}))]}}}}function Vt(){return{name:`build`,async run(e){let t=await e.getProject();return Lt(t),{exitCode:0,lines:[{kind:`success`,message:Q(`build`,`Mirrored ${t.modules.length} modules.`)},{kind:`success`,message:Q(`build`,`Mirrored ${t.libraries.length} libraries.`)},{kind:`success`,message:Q(`build`,`Resolved ${t.apps.length} apps.`)}]}}}}function Ht(e,t){return{exitCode:0,lines:[{kind:`success`,message:Q(e,t)}]}}function Q(e,t){return`${e.padEnd(10,` `)} ${t}`}async function Ut(e){return await j.build(`build`).use(zt()).use(Bt()).use(Vt()).run(e)}async function Wt(e){return await j.build(`validate`).use(Bt()).run(e)}async function Gt(e){return await Wt(e)}async function Kt(e){return await j.build(`doctor`).use(zt()).run(e)}async function qt(e){return await Ut(e)}function Jt(e){let t=[`Modules: ${e.modules.length}`,``];for(let n of e.modules)t.push(n.name),t.push(` api: ${n.apiTarget}`),$(t,e.graph.dependencies.filter(e=>e.from===n.apiTarget),` api dependsOn`),t.push(` impl: ${n.implTarget}`),$(t,e.graph.dependencies.filter(e=>e.from===n.implTarget),` impl dependsOn`),t.push(``);t.push(`Libraries: ${e.libraries.length}`),e.libraries.length>0&&t.push(``);for(let n of e.libraries)t.push(n.name),t.push(` api: ${n.apiTarget}`),$(t,e.graph.dependencies.filter(e=>e.from===n.apiTarget),` api dependsOn`),t.push(` impl: ${n.implTarget}`),$(t,e.graph.dependencies.filter(e=>e.from===n.implTarget),` impl dependsOn`),t.push(``);t.push(`Apps: ${e.apps.length}`),e.apps.length>0&&t.push(``);for(let n of e.apps)t.push(n.name),t.push(` app: ${n.target}`),$(t,e.graph.dependencies.filter(e=>e.from===n.target),` dependsOn`),t.push(``);return Yt(t)}function $(e,t,n){if(t.length===0){e.push(`${n}: none`);return}e.push(`${n}:`);for(let n of t){let t=n.origin===`derived`?` (derived)`:``;e.push(` ${n.to}${t}`)}}function Yt(e){let t=[...e];for(;t.at(-1)===``;)t.pop();return t}async function Xt(e){return{exitCode:0,lines:Jt(await Ne(e.config)).map(e=>({kind:`info`,message:e}))}}var Zt=class{result(e){for(let t of e.lines)this.line(t)}line(e){if(e.message.length===0){a.log(``);return}switch(e.kind){case`success`:a.success(e.message);return;case`warning`:a.warn(e.message);return;case`error`:a.error(e.message);return;case`info`:a.info(e.message);return}}help(){a.log([`Archicat`,``,`Usage:`,` archicat build [--config archicat.config.ts]`,` archicat validate [--config archicat.config.ts]`,` archicat graph [--config archicat.config.ts]`,` archicat doctor [--config archicat.config.ts]`,``,`Aliases:`,` archicat generate -> archicat build`,` archicat check -> archicat validate`,``].join(`
|
|
33
|
+
`))}};async function Qt(e=process.argv.slice(2)){let[t,...n]=e,r=new Zt;try{let e=await $t(t,en(n),r);if(!e)return;r.result(e),process.exitCode=e.exitCode}catch(e){r.line({kind:`error`,message:e instanceof Error?e.message:String(e)}),process.exitCode=1}}async function $t(e,t,n){switch(e){case`build`:return await Ut(t);case`generate`:return await qt(t);case`validate`:return await Wt(t);case`check`:return await Gt(t);case`graph`:return await Xt(t);case`doctor`:return await Kt(t);case`help`:case`--help`:case`-h`:case void 0:n.help();return;default:return n.line({kind:`error`,message:`Unknown command: ${e}`}),n.help(),{exitCode:1,lines:[]}}}function en(e){let t={};for(let n=0;n<e.length;n+=1){let r=e[n];if(r===`--config`||r===`-c`){let i=e[n+1];if(!i)throw Error(`${r} requires a value.`);t.config=i,n+=1}}return t}export{Qt as runMain};
|
package/dist/src/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return Object.freeze({kind:`app`,name:e.name,...e.root===void 0?{}:{root:e.root},dependencies:Object.freeze([...e.dependencies??[]])})}function t(e={}
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return Object.freeze({kind:`app`,name:e.name,...e.root===void 0?{}:{root:e.root},dependencies:Object.freeze([...e.dependencies??[]])})}function t(e){let t={...e};for(let e of Object.keys(t))t[e]===void 0&&delete t[e];return Object.freeze(t)}function n(e={}){return t({root:e.root,outDir:e.outDir,typescript:e.typescript?r(e.typescript):void 0,alias:e.alias?Object.freeze({...e.alias}):void 0,prefixes:e.prefixes?a(e.prefixes):void 0,modules:e.modules?o(e.modules):void 0,libraries:e.libraries?o(e.libraries):void 0,apps:e.apps?o(e.apps):void 0})}function r(e){return t({tsConfig:e.tsConfig?i(e.tsConfig):void 0})}function i(e){return t({extends:e.extends,include:e.include?Object.freeze([...e.include]):void 0,exclude:e.exclude?Object.freeze([...e.exclude]):void 0,files:e.files?Object.freeze([...e.files]):void 0,compilerOptions:e.compilerOptions?Object.freeze({...e.compilerOptions}):void 0})}function a(e){return t({module:e.module,library:e.library})}function o(e){return t({include:e.include?Object.freeze([...e.include]):void 0})}function s(e){return typeof e==`string`?Object.freeze({root:e,dependencies:Object.freeze([])}):t({root:e?.root,dependencies:Object.freeze([...e?.dependencies??[]])})}function c(e){return Object.freeze({kind:`library`,name:e.name,api:s(e.api),impl:s(e.impl)})}function l(e){return Object.freeze({kind:`module`,name:e.name,api:s(e.api),impl:s(e.impl)})}exports.defineApp=e,exports.defineArchicatConfig=n,exports.defineLibrary=c,exports.defineModule=l;
|
package/dist/src/index.d.cts
CHANGED
|
@@ -84,6 +84,49 @@ interface ArchicatDefinitionRootConfig {
|
|
|
84
84
|
*/
|
|
85
85
|
readonly include?: readonly string[];
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* @description TypeScript config fragment merged into generated `.archicat/tsconfig.json`.
|
|
89
|
+
*/
|
|
90
|
+
interface ArchicatTypeScriptTsConfigInput {
|
|
91
|
+
/**
|
|
92
|
+
* @description Base TypeScript config extended by generated `.archicat/tsconfig.json`.
|
|
93
|
+
*/
|
|
94
|
+
readonly extends?: string;
|
|
95
|
+
/**
|
|
96
|
+
* @description Project source files merged into generated `.archicat/tsconfig.json` include.
|
|
97
|
+
* Archicat rewrites relative paths to the generated config directory and appends generated type declarations automatically.
|
|
98
|
+
*/
|
|
99
|
+
readonly include?: readonly string[];
|
|
100
|
+
/**
|
|
101
|
+
* @description Project paths merged into generated `.archicat/tsconfig.json` exclude.
|
|
102
|
+
* Archicat rewrites relative paths to the generated config directory.
|
|
103
|
+
*/
|
|
104
|
+
readonly exclude?: readonly string[];
|
|
105
|
+
/**
|
|
106
|
+
* @description Project files merged into generated `.archicat/tsconfig.json` files.
|
|
107
|
+
* Archicat rewrites relative paths to the generated config directory.
|
|
108
|
+
*/
|
|
109
|
+
readonly files?: readonly string[];
|
|
110
|
+
/**
|
|
111
|
+
* @description Unsupported. Put compiler options in the base or app tsconfig. Archicat owns generated `compilerOptions.paths` and does not support `baseUrl`.
|
|
112
|
+
*/
|
|
113
|
+
readonly compilerOptions?: {
|
|
114
|
+
readonly paths?: never;
|
|
115
|
+
readonly baseUrl?: never;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @description TypeScript integration options used to generate `.archicat/tsconfig.json`.
|
|
120
|
+
*/
|
|
121
|
+
interface ArchicatTypeScriptConfigInput {
|
|
122
|
+
/**
|
|
123
|
+
* @description Partial TypeScript config merged into generated `.archicat/tsconfig.json`.
|
|
124
|
+
* Archicat rewrites relative paths from the project root to `.archicat`, appends generated type declarations to `include`, and injects generated aliases into `compilerOptions.paths`.
|
|
125
|
+
* `compilerOptions` is not supported here. Put compiler policy in the base tsconfig and app build overrides in the app tsconfig.
|
|
126
|
+
* @default {}
|
|
127
|
+
*/
|
|
128
|
+
readonly tsConfig?: ArchicatTypeScriptTsConfigInput;
|
|
129
|
+
}
|
|
87
130
|
/**
|
|
88
131
|
* @description TypeScript alias prefixes reserved by Archicat.
|
|
89
132
|
*/
|
|
@@ -100,7 +143,8 @@ interface ArchicatPrefixConfig {
|
|
|
100
143
|
readonly library?: string;
|
|
101
144
|
}
|
|
102
145
|
/**
|
|
103
|
-
* @description User
|
|
146
|
+
* @description User import aliases generated into `.archicat/tsconfig.json` together with Archicat module and library aliases.
|
|
147
|
+
* Aliases are resolved relative to the Archicat project root. Do not define TypeScript `compilerOptions.paths` manually for an Archicat project.
|
|
104
148
|
* @default {}
|
|
105
149
|
*/
|
|
106
150
|
type ArchicatAliasConfig = Readonly<Record<string, string>>;
|
|
@@ -119,10 +163,10 @@ interface ArchicatConfigInput {
|
|
|
119
163
|
*/
|
|
120
164
|
readonly outDir?: string;
|
|
121
165
|
/**
|
|
122
|
-
* @description
|
|
123
|
-
* @default
|
|
166
|
+
* @description TypeScript integration options used to generate `.archicat/tsconfig.json`.
|
|
167
|
+
* @default {}
|
|
124
168
|
*/
|
|
125
|
-
readonly
|
|
169
|
+
readonly typescript?: ArchicatTypeScriptConfigInput;
|
|
126
170
|
/**
|
|
127
171
|
* @description User TypeScript aliases generated by Archicat.
|
|
128
172
|
* @default {}
|
|
@@ -155,7 +199,18 @@ interface ArchicatConfigInput {
|
|
|
155
199
|
type ArchicatConfig = Readonly<{
|
|
156
200
|
readonly root?: string;
|
|
157
201
|
readonly outDir?: string;
|
|
158
|
-
readonly
|
|
202
|
+
readonly typescript?: Readonly<{
|
|
203
|
+
readonly tsConfig?: Readonly<{
|
|
204
|
+
readonly extends?: string;
|
|
205
|
+
readonly include?: readonly string[];
|
|
206
|
+
readonly exclude?: readonly string[];
|
|
207
|
+
readonly files?: readonly string[];
|
|
208
|
+
readonly compilerOptions?: Readonly<{
|
|
209
|
+
readonly paths?: never;
|
|
210
|
+
readonly baseUrl?: never;
|
|
211
|
+
}>;
|
|
212
|
+
}>;
|
|
213
|
+
}>;
|
|
159
214
|
readonly alias?: ArchicatAliasConfig;
|
|
160
215
|
readonly prefixes?: Readonly<{
|
|
161
216
|
readonly module?: string;
|
package/dist/src/index.d.mts
CHANGED
|
@@ -84,6 +84,49 @@ interface ArchicatDefinitionRootConfig {
|
|
|
84
84
|
*/
|
|
85
85
|
readonly include?: readonly string[];
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* @description TypeScript config fragment merged into generated `.archicat/tsconfig.json`.
|
|
89
|
+
*/
|
|
90
|
+
interface ArchicatTypeScriptTsConfigInput {
|
|
91
|
+
/**
|
|
92
|
+
* @description Base TypeScript config extended by generated `.archicat/tsconfig.json`.
|
|
93
|
+
*/
|
|
94
|
+
readonly extends?: string;
|
|
95
|
+
/**
|
|
96
|
+
* @description Project source files merged into generated `.archicat/tsconfig.json` include.
|
|
97
|
+
* Archicat rewrites relative paths to the generated config directory and appends generated type declarations automatically.
|
|
98
|
+
*/
|
|
99
|
+
readonly include?: readonly string[];
|
|
100
|
+
/**
|
|
101
|
+
* @description Project paths merged into generated `.archicat/tsconfig.json` exclude.
|
|
102
|
+
* Archicat rewrites relative paths to the generated config directory.
|
|
103
|
+
*/
|
|
104
|
+
readonly exclude?: readonly string[];
|
|
105
|
+
/**
|
|
106
|
+
* @description Project files merged into generated `.archicat/tsconfig.json` files.
|
|
107
|
+
* Archicat rewrites relative paths to the generated config directory.
|
|
108
|
+
*/
|
|
109
|
+
readonly files?: readonly string[];
|
|
110
|
+
/**
|
|
111
|
+
* @description Unsupported. Put compiler options in the base or app tsconfig. Archicat owns generated `compilerOptions.paths` and does not support `baseUrl`.
|
|
112
|
+
*/
|
|
113
|
+
readonly compilerOptions?: {
|
|
114
|
+
readonly paths?: never;
|
|
115
|
+
readonly baseUrl?: never;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @description TypeScript integration options used to generate `.archicat/tsconfig.json`.
|
|
120
|
+
*/
|
|
121
|
+
interface ArchicatTypeScriptConfigInput {
|
|
122
|
+
/**
|
|
123
|
+
* @description Partial TypeScript config merged into generated `.archicat/tsconfig.json`.
|
|
124
|
+
* Archicat rewrites relative paths from the project root to `.archicat`, appends generated type declarations to `include`, and injects generated aliases into `compilerOptions.paths`.
|
|
125
|
+
* `compilerOptions` is not supported here. Put compiler policy in the base tsconfig and app build overrides in the app tsconfig.
|
|
126
|
+
* @default {}
|
|
127
|
+
*/
|
|
128
|
+
readonly tsConfig?: ArchicatTypeScriptTsConfigInput;
|
|
129
|
+
}
|
|
87
130
|
/**
|
|
88
131
|
* @description TypeScript alias prefixes reserved by Archicat.
|
|
89
132
|
*/
|
|
@@ -100,7 +143,8 @@ interface ArchicatPrefixConfig {
|
|
|
100
143
|
readonly library?: string;
|
|
101
144
|
}
|
|
102
145
|
/**
|
|
103
|
-
* @description User
|
|
146
|
+
* @description User import aliases generated into `.archicat/tsconfig.json` together with Archicat module and library aliases.
|
|
147
|
+
* Aliases are resolved relative to the Archicat project root. Do not define TypeScript `compilerOptions.paths` manually for an Archicat project.
|
|
104
148
|
* @default {}
|
|
105
149
|
*/
|
|
106
150
|
type ArchicatAliasConfig = Readonly<Record<string, string>>;
|
|
@@ -119,10 +163,10 @@ interface ArchicatConfigInput {
|
|
|
119
163
|
*/
|
|
120
164
|
readonly outDir?: string;
|
|
121
165
|
/**
|
|
122
|
-
* @description
|
|
123
|
-
* @default
|
|
166
|
+
* @description TypeScript integration options used to generate `.archicat/tsconfig.json`.
|
|
167
|
+
* @default {}
|
|
124
168
|
*/
|
|
125
|
-
readonly
|
|
169
|
+
readonly typescript?: ArchicatTypeScriptConfigInput;
|
|
126
170
|
/**
|
|
127
171
|
* @description User TypeScript aliases generated by Archicat.
|
|
128
172
|
* @default {}
|
|
@@ -155,7 +199,18 @@ interface ArchicatConfigInput {
|
|
|
155
199
|
type ArchicatConfig = Readonly<{
|
|
156
200
|
readonly root?: string;
|
|
157
201
|
readonly outDir?: string;
|
|
158
|
-
readonly
|
|
202
|
+
readonly typescript?: Readonly<{
|
|
203
|
+
readonly tsConfig?: Readonly<{
|
|
204
|
+
readonly extends?: string;
|
|
205
|
+
readonly include?: readonly string[];
|
|
206
|
+
readonly exclude?: readonly string[];
|
|
207
|
+
readonly files?: readonly string[];
|
|
208
|
+
readonly compilerOptions?: Readonly<{
|
|
209
|
+
readonly paths?: never;
|
|
210
|
+
readonly baseUrl?: never;
|
|
211
|
+
}>;
|
|
212
|
+
}>;
|
|
213
|
+
}>;
|
|
159
214
|
readonly alias?: ArchicatAliasConfig;
|
|
160
215
|
readonly prefixes?: Readonly<{
|
|
161
216
|
readonly module?: string;
|
package/dist/src/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){return Object.freeze({kind:`app`,name:e.name,...e.root===void 0?{}:{root:e.root},dependencies:Object.freeze([...e.dependencies??[]])})}function t(e={}
|
|
1
|
+
function e(e){return Object.freeze({kind:`app`,name:e.name,...e.root===void 0?{}:{root:e.root},dependencies:Object.freeze([...e.dependencies??[]])})}function t(e){let t={...e};for(let e of Object.keys(t))t[e]===void 0&&delete t[e];return Object.freeze(t)}function n(e={}){return t({root:e.root,outDir:e.outDir,typescript:e.typescript?r(e.typescript):void 0,alias:e.alias?Object.freeze({...e.alias}):void 0,prefixes:e.prefixes?a(e.prefixes):void 0,modules:e.modules?o(e.modules):void 0,libraries:e.libraries?o(e.libraries):void 0,apps:e.apps?o(e.apps):void 0})}function r(e){return t({tsConfig:e.tsConfig?i(e.tsConfig):void 0})}function i(e){return t({extends:e.extends,include:e.include?Object.freeze([...e.include]):void 0,exclude:e.exclude?Object.freeze([...e.exclude]):void 0,files:e.files?Object.freeze([...e.files]):void 0,compilerOptions:e.compilerOptions?Object.freeze({...e.compilerOptions}):void 0})}function a(e){return t({module:e.module,library:e.library})}function o(e){return t({include:e.include?Object.freeze([...e.include]):void 0})}function s(e){return typeof e==`string`?Object.freeze({root:e,dependencies:Object.freeze([])}):t({root:e?.root,dependencies:Object.freeze([...e?.dependencies??[]])})}function c(e){return Object.freeze({kind:`library`,name:e.name,api:s(e.api),impl:s(e.impl)})}function l(e){return Object.freeze({kind:`module`,name:e.name,api:s(e.api),impl:s(e.impl)})}export{e as defineApp,n as defineArchicatConfig,c as defineLibrary,l as defineModule};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "archicat",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "Modular mirroring (M²) for clean architecture.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"m2",
|
|
7
|
-
"
|
|
7
|
+
"mirroring",
|
|
8
|
+
"modular",
|
|
8
9
|
"module-system",
|
|
9
|
-
"clean-architecture"
|
|
10
|
-
"architecture"
|
|
10
|
+
"clean-architecture"
|
|
11
11
|
],
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"author": "Simon Rastislav Kovačič",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
+
"consola": "3.4.2",
|
|
41
42
|
"jiti": "2.7.0",
|
|
42
43
|
"typescript": "6.0.3"
|
|
43
44
|
},
|
|
@@ -56,5 +57,5 @@
|
|
|
56
57
|
"publishConfig": {
|
|
57
58
|
"registry": "https://registry.npmjs.org/"
|
|
58
59
|
},
|
|
59
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "a12dcca4618ace0754ea2097848bc818ffd21a14"
|
|
60
61
|
}
|