@lucasacoutinho/archer 0.0.0-stage → 0.2.1
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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +459 -2
- package/dist/bun/plugin.cjs +85 -0
- package/dist/bun/plugin.d.cts +7 -0
- package/dist/bun/plugin.d.ts +7 -0
- package/dist/bun/plugin.js +11 -0
- package/dist/bun.cjs +2238 -0
- package/dist/bun.d.cts +13 -0
- package/dist/bun.d.ts +13 -0
- package/dist/bun.js +28 -0
- package/dist/chunk-2AKMBLHG.js +2165 -0
- package/dist/chunk-67YEOTXP.js +25 -0
- package/dist/chunk-IDVLHNL2.js +46 -0
- package/dist/chunk-ZZ6TR4PO.js +201 -0
- package/dist/cli.js +2643 -0
- package/dist/index.cjs +2484 -0
- package/dist/index.d.cts +45 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +54 -0
- package/dist/jest/plugin.cjs +85 -0
- package/dist/jest/plugin.d.cts +7 -0
- package/dist/jest/plugin.d.ts +7 -0
- package/dist/jest/plugin.js +11 -0
- package/dist/jest.cjs +2237 -0
- package/dist/jest.d.cts +13 -0
- package/dist/jest.d.ts +13 -0
- package/dist/jest.js +27 -0
- package/dist/matchers-Cqnbsyxe.d.cts +11 -0
- package/dist/matchers-Cqnbsyxe.d.ts +11 -0
- package/dist/node.cjs +2237 -0
- package/dist/node.d.cts +13 -0
- package/dist/node.d.ts +13 -0
- package/dist/node.js +27 -0
- package/dist/reporters-BbAXMpuW.d.cts +6 -0
- package/dist/reporters-xh-HQneS.d.ts +6 -0
- package/dist/suite-BwnPDCvU.d.cts +337 -0
- package/dist/suite-BwnPDCvU.d.ts +337 -0
- package/dist/vitest/plugin.cjs +85 -0
- package/dist/vitest/plugin.d.cts +7 -0
- package/dist/vitest/plugin.d.ts +7 -0
- package/dist/vitest/plugin.js +11 -0
- package/dist/vitest.cjs +2531 -0
- package/dist/vitest.d.cts +37 -0
- package/dist/vitest.d.ts +37 -0
- package/dist/vitest.js +139 -0
- package/package.json +216 -4
- package/skills/archer/SKILL.md +81 -0
- package/skills/archer/agents/openai.yaml +4 -0
- package/skills/archer/references/rules.md +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,460 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Archer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Architecture tests for TypeScript and JavaScript. Archer builds a resolved
|
|
4
|
+
module graph, lets you describe boundaries with a fluent API, and reports a
|
|
5
|
+
normal test failure when the code stops matching the design.
|
|
6
|
+
|
|
7
|
+
It takes its readable rule style from [Pest architecture testing](https://pestphp.com/docs/arch-testing),
|
|
8
|
+
but models files, packages, imports, exports, and TypeScript declarations.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install --save-dev @lucasacoutinho/archer
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Archer supports Node.js 20 and newer. It parses sources with its own bundled
|
|
17
|
+
TypeScript, so the project's TypeScript version does not matter. The core
|
|
18
|
+
package has no test-runner dependency.
|
|
19
|
+
|
|
20
|
+
## Start with the CLI
|
|
21
|
+
|
|
22
|
+
Create `archer.config.ts`:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { defineConfig } from '@lucasacoutinho/archer'
|
|
26
|
+
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
include: ['src/**/*.ts', 'packages/*/src/**/*.ts'],
|
|
29
|
+
exclude: ['**/*.generated.ts'],
|
|
30
|
+
|
|
31
|
+
rules(archer) {
|
|
32
|
+
archer
|
|
33
|
+
.expect('src/domain/**')
|
|
34
|
+
.not.toDependOn('src/infrastructure/**')
|
|
35
|
+
.because('The domain must remain portable.')
|
|
36
|
+
.as('boundaries/domain-isolation')
|
|
37
|
+
|
|
38
|
+
archer.expect('src/**').toBeFreeOfCycles()
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Then run:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npx archer check
|
|
47
|
+
npx archer check --watch
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`archer init` creates a starter config. Config paths, output paths, and the
|
|
51
|
+
project root are resolved relative to the config file.
|
|
52
|
+
|
|
53
|
+
## Test-runner adapters
|
|
54
|
+
|
|
55
|
+
Each adapter registers a test immediately and returns the same rule builder.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// test/architecture.test.ts
|
|
59
|
+
import { arch } from '@lucasacoutinho/archer/vitest'
|
|
60
|
+
|
|
61
|
+
arch('the domain stays independent')
|
|
62
|
+
.expect('src/domain/**')
|
|
63
|
+
.not.toDependOn('src/infrastructure/**')
|
|
64
|
+
.and.toOnlyDependOn(['src/domain/**', 'src/shared/**'])
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The other entry points are:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { arch } from '@lucasacoutinho/archer/jest'
|
|
71
|
+
import { arch } from '@lucasacoutinho/archer/bun'
|
|
72
|
+
import { arch } from '@lucasacoutinho/archer/node'
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Jest and Bun accept `timeout` as an Archer adapter option. The Node adapter
|
|
76
|
+
accepts built-in `node:test` options under `test`.
|
|
77
|
+
|
|
78
|
+
## Vitest config plugin
|
|
79
|
+
|
|
80
|
+
Vitest can run Archer once, before it starts collecting tests. The plugin loads
|
|
81
|
+
`archer.config.*` from the Vitest project root by default:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
// vitest.config.ts
|
|
85
|
+
import { archer } from '@lucasacoutinho/archer/vitest'
|
|
86
|
+
import { defineConfig } from 'vitest/config'
|
|
87
|
+
|
|
88
|
+
export default defineConfig({
|
|
89
|
+
plugins: [archer()],
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Pass `config`, `reporter`, `baseline`, `output`, or `failOnWarnings` to
|
|
94
|
+
`archer()` when the defaults are not enough. This is a configuration plugin,
|
|
95
|
+
so it performs one architecture check for the Vitest project instead of
|
|
96
|
+
registering a test in every worker.
|
|
97
|
+
|
|
98
|
+
## Matcher setup modules
|
|
99
|
+
|
|
100
|
+
Vitest, Jest, and Bun can also install Archer as an `expect` plugin. This keeps
|
|
101
|
+
the runner integration in its normal setup hook and lets architecture tests use
|
|
102
|
+
the same assertion in every runner.
|
|
103
|
+
|
|
104
|
+
For Vitest, add the plugin to `setupFiles`:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
// vitest.config.ts
|
|
108
|
+
import { defineConfig } from 'vitest/config'
|
|
109
|
+
|
|
110
|
+
export default defineConfig({
|
|
111
|
+
test: {
|
|
112
|
+
setupFiles: ['@lucasacoutinho/archer/vitest/plugin'],
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
For Jest, add it to `setupFilesAfterEnv`:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
// jest.config.ts
|
|
121
|
+
export default {
|
|
122
|
+
setupFilesAfterEnv: ['@lucasacoutinho/archer/jest/plugin'],
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
For Bun, preload it from `bunfig.toml`:
|
|
127
|
+
|
|
128
|
+
```toml
|
|
129
|
+
[test]
|
|
130
|
+
preload = ["@lucasacoutinho/archer/bun/plugin"]
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Then create a normal test and await the asynchronous matcher:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { createArcher } from '@lucasacoutinho/archer'
|
|
137
|
+
|
|
138
|
+
test('the architecture is respected', async () => {
|
|
139
|
+
const archer = createArcher()
|
|
140
|
+
archer.expect('src/domain/**').not.toDependOn('src/infrastructure/**')
|
|
141
|
+
|
|
142
|
+
await expect(archer).toRespectArchitecture()
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The plugin installs the matcher; it does not silently inject a test into every
|
|
147
|
+
worker. Use the `arch()` adapter when the fluent one-call form is preferable.
|
|
148
|
+
|
|
149
|
+
## Dependency rules
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
archer
|
|
153
|
+
.expect('src/application/**')
|
|
154
|
+
.toDependOn('src/domain/**')
|
|
155
|
+
.not.toDependOn('src/web/**')
|
|
156
|
+
.toOnlyDependOn(['src/application/**', 'src/domain/**', 'npm:zod'])
|
|
157
|
+
.toBeDependedOnBy('src/http/**')
|
|
158
|
+
.toOnlyBeDependedOnBy(['src/http/**', 'src/jobs/**'])
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Aliases are available for Pest-style wording: `toUse`, `toOnlyUse`,
|
|
162
|
+
`toBeUsedIn`, `toOnlyBeUsedIn`, `toUseNothing`, and `toBeUsed`.
|
|
163
|
+
|
|
164
|
+
Modifiers apply to the next dependency rule and then reset:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
archer
|
|
168
|
+
.expect('src/application/**')
|
|
169
|
+
.typeDependencies()
|
|
170
|
+
.toOnlyDependOn('src/contracts/**')
|
|
171
|
+
.runtimeDependencies()
|
|
172
|
+
.not.toDependOn('src/testing/**')
|
|
173
|
+
.dynamicDependencies()
|
|
174
|
+
.not.toDependOn('src/admin/**')
|
|
175
|
+
.localDependencies()
|
|
176
|
+
.toOnlyDependOn(['src/application/**', 'src/domain/**'])
|
|
177
|
+
.toTransitivelyDependOn('src/domain/events.ts')
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Use `includingDependencyKinds('static', 'require')` for an exact combination,
|
|
181
|
+
or `.transitively().toDependOn(...)` for explicit reachability. Transitive
|
|
182
|
+
violations include the shortest discovered import chain.
|
|
183
|
+
|
|
184
|
+
### Selectors and resolution
|
|
185
|
+
|
|
186
|
+
| Selector | Meaning |
|
|
187
|
+
| --------------- | ------------------------------------------------ |
|
|
188
|
+
| `src/domain/**` | Files resolved inside the configured root |
|
|
189
|
+
| `npm:react` | An installed package and its subpaths |
|
|
190
|
+
| `node:fs` | A Node built-in |
|
|
191
|
+
| `bun:test` | A Bun built-in |
|
|
192
|
+
| `unresolved:*` | Imports TypeScript could not resolve |
|
|
193
|
+
| `dynamic:*` | Computed dynamic imports without a static target |
|
|
194
|
+
|
|
195
|
+
Archer resolves path aliases, package exports, project references, workspace
|
|
196
|
+
packages, symlinks, `.js` imports of TypeScript sources, re-exports,
|
|
197
|
+
`import type`, import types, CommonJS `require`, and lazy imports.
|
|
198
|
+
|
|
199
|
+
Literal lazy imports such as `import('./admin.js')` are normal resolved edges.
|
|
200
|
+
A computed import such as `import(moduleName)` becomes `dynamic:unknown`.
|
|
201
|
+
Negative boundary rules fail closed on that edge because the target cannot be
|
|
202
|
+
proven safe; an allow-list can explicitly include `dynamic:*`.
|
|
203
|
+
|
|
204
|
+
## Named layers and public APIs
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
const layers = archer.layers({
|
|
208
|
+
domain: 'src/domain/**',
|
|
209
|
+
application: 'src/application/**',
|
|
210
|
+
infrastructure: 'src/infrastructure/**',
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
layers.where('domain').mayNotDependOn('infrastructure')
|
|
214
|
+
layers.where('application').mayOnlyDependOn('domain')
|
|
215
|
+
layers.where('domain').mayOnlyBeUsedBy('application')
|
|
216
|
+
layers.where('domain').exposeThrough('src/domain/index.ts')
|
|
217
|
+
layers.toBeFreeOfCycles()
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Layer rules only constrain local project dependencies. External packages do
|
|
221
|
+
not need to be repeated in every layer allow-list. `exposeThrough` rejects
|
|
222
|
+
deep imports into a layer from outside it.
|
|
223
|
+
|
|
224
|
+
For directory-level cycles, collapse file nodes to a fixed depth:
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
archer.expect('src/**').toBeFreeOfFolderCycles(2)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## TypeScript-aware rules
|
|
231
|
+
|
|
232
|
+
Archer uses the configured TypeScript programs for declarations, resolved
|
|
233
|
+
heritage, exports, decorators, method visibility, and global-call detection.
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
archer
|
|
237
|
+
.expect('src/controllers/**')
|
|
238
|
+
.toBeClasses()
|
|
239
|
+
.toExtend('BaseController')
|
|
240
|
+
.toImplement('Runnable')
|
|
241
|
+
.toHaveDecorator('Controller')
|
|
242
|
+
.toHaveReadonlyProperties()
|
|
243
|
+
.toHaveMethods('execute')
|
|
244
|
+
.toHavePublicMethods('execute')
|
|
245
|
+
.toHaveProtectedMethods('reset')
|
|
246
|
+
.toOnlyHavePublicMethods()
|
|
247
|
+
.toBeExported()
|
|
248
|
+
|
|
249
|
+
archer.expect('src/contracts/**').toBeInterfaces()
|
|
250
|
+
archer.expect('src/base-controller.ts').toBeAbstract()
|
|
251
|
+
archer.expect('src/status.ts').toBeEnums()
|
|
252
|
+
archer.expect('src/factories/**').toBeFunctions()
|
|
253
|
+
archer.expect('src/models/**').toBeTypes()
|
|
254
|
+
archer.expect('src/index.ts').toOnlyExport('Client', 'ClientOptions')
|
|
255
|
+
archer.expect('src/**').toUseStrictEquality()
|
|
256
|
+
archer.expect('src/**').not.toUseGlobals('eval', 'Function')
|
|
257
|
+
archer.expect('src/**').not.toUseImportedSymbols('react', 'useEffect')
|
|
258
|
+
archer.expect('src/**').toHaveResolvableDependencies()
|
|
259
|
+
archer.expect('src/index.ts').toBePublicApi()
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Naming and size rules remain available through `toHavePrefix`,
|
|
263
|
+
`toHaveSuffix`, and `toHaveLineCountLessThan`.
|
|
264
|
+
|
|
265
|
+
These are static checks. Runtime dependency injection, reflection-generated
|
|
266
|
+
exports, and targets hidden behind computed imports cannot be inferred.
|
|
267
|
+
|
|
268
|
+
### Imported API policies
|
|
269
|
+
|
|
270
|
+
`toUseImportedSymbols()` matches calls by their original module and export. It
|
|
271
|
+
recognizes named-import aliases, namespace calls, default-import property
|
|
272
|
+
calls, element access with a literal name, and CommonJS destructuring.
|
|
273
|
+
|
|
274
|
+
That keeps framework names out of Archer's rule engine. A React policy can be
|
|
275
|
+
written from generic rules:
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
archer
|
|
279
|
+
.expect('src/frontend/components/**/*.{ts,tsx}')
|
|
280
|
+
.not.toBeClasses()
|
|
281
|
+
.and.not.toUseImportedSymbols('react', 'useEffect', 'useContext')
|
|
282
|
+
|
|
283
|
+
archer.expect('src/frontend/state/**').toDependOn('npm:zustand')
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
The same call rule can reject Vue `provide` and `inject`, or Svelte
|
|
287
|
+
`setContext` and `getContext`, in JavaScript and TypeScript modules:
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
archer.expect('src/vue/**').not.toUseImportedSymbols('vue', 'provide', 'inject')
|
|
291
|
+
archer.expect('src/svelte/**').not.toUseImportedSymbols('svelte', 'setContext', 'getContext')
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Vue and Svelte single-file components need their compiler parsers because a
|
|
295
|
+
`.vue` or `.svelte` file is not a TypeScript source file. Archer does not parse
|
|
296
|
+
those formats as TypeScript or claim that their template dependencies were
|
|
297
|
+
checked. They belong in source-analyzer integrations, while the core rules
|
|
298
|
+
remain framework-neutral.
|
|
299
|
+
|
|
300
|
+
## Rule metadata, custom rules, and presets
|
|
301
|
+
|
|
302
|
+
Rules default to error severity. Stable IDs make baselines and CI annotations
|
|
303
|
+
less sensitive to wording changes.
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
archer
|
|
307
|
+
.expect('src/legacy/**')
|
|
308
|
+
.not.toDependOn('src/new-core/**')
|
|
309
|
+
.as('migration/no-new-core')
|
|
310
|
+
.because('Legacy code is being removed, not expanded.')
|
|
311
|
+
.withSeverity('warning')
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Custom rules may be synchronous or asynchronous:
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
archer.expect('src/features/**').toSatisfy('features/one-entrypoint', ({ modules }) =>
|
|
318
|
+
modules.flatMap((module) =>
|
|
319
|
+
module.exports.length > 1
|
|
320
|
+
? [
|
|
321
|
+
{
|
|
322
|
+
file: module.path,
|
|
323
|
+
message: 'Feature exports more than one symbol.',
|
|
324
|
+
rule: 'features expose one entrypoint',
|
|
325
|
+
severity: 'error',
|
|
326
|
+
},
|
|
327
|
+
]
|
|
328
|
+
: [],
|
|
329
|
+
),
|
|
330
|
+
)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Built-in presets are `strict`, `node`, and `security`:
|
|
334
|
+
|
|
335
|
+
```ts
|
|
336
|
+
archer.preset('strict')
|
|
337
|
+
archer.preset('node')
|
|
338
|
+
|
|
339
|
+
registerPreset('company', (suite) => {
|
|
340
|
+
suite.expect('src/**').not.toDependOn('npm:deprecated-sdk')
|
|
341
|
+
})
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Monorepos and project references
|
|
345
|
+
|
|
346
|
+
Archer discovers npm/Yarn and pnpm workspaces plus referenced tsconfigs. You
|
|
347
|
+
can also declare projects and override their source selection:
|
|
348
|
+
|
|
349
|
+
```ts
|
|
350
|
+
export default defineConfig({
|
|
351
|
+
projects: [
|
|
352
|
+
'packages/core/tsconfig.json',
|
|
353
|
+
{
|
|
354
|
+
tsconfig: 'apps/*/tsconfig.json',
|
|
355
|
+
include: ['src/**/*.ts', 'scripts/**/*.ts'],
|
|
356
|
+
},
|
|
357
|
+
],
|
|
358
|
+
rules(archer) {
|
|
359
|
+
archer.expect('packages/**').toBeFreeOfCycles()
|
|
360
|
+
},
|
|
361
|
+
})
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Set `workspaces: false`, `followSymlinks: false`, `cache: false`, or
|
|
365
|
+
`tsconfig: false` to override the corresponding defaults.
|
|
366
|
+
|
|
367
|
+
## Reports and baselines
|
|
368
|
+
|
|
369
|
+
The CLI supports `pretty`, `agent`, `llm`, `json`, `sarif`, `github`, and `dot` reporters.
|
|
370
|
+
`agent` and its `llm` alias emit one stable, single-line record per finding without ANSI output:
|
|
371
|
+
|
|
372
|
+
```sh
|
|
373
|
+
npx archer check --reporter agent
|
|
374
|
+
npx archer check --reporter sarif --output reports/archer.sarif
|
|
375
|
+
npx archer check --reporter github
|
|
376
|
+
npx archer check --reporter dot --output reports/dependencies.dot
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Adopt Archer in an existing codebase without accepting new violations:
|
|
380
|
+
|
|
381
|
+
```sh
|
|
382
|
+
npx archer check --update-baseline
|
|
383
|
+
npx archer check
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
The default baseline is `.archer-baseline.json`. Use `--baseline <file>` or
|
|
387
|
+
the config `baseline` field to choose another path. `--fail-on-warnings` makes
|
|
388
|
+
warning-level rules affect the CLI exit code.
|
|
389
|
+
|
|
390
|
+
The core API exposes the same data for integrations:
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
import { ArchitectureError, createArcher } from '@lucasacoutinho/archer'
|
|
394
|
+
|
|
395
|
+
const archer = createArcher({ root: process.cwd() })
|
|
396
|
+
archer.expect('src/**').toBeFreeOfCycles()
|
|
397
|
+
|
|
398
|
+
const result = await archer.check()
|
|
399
|
+
if (!result.ok) throw new ArchitectureError(result)
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## Agent skill
|
|
403
|
+
|
|
404
|
+
Archer ships a portable [Agent Skill](https://openagentskills.dev/) in
|
|
405
|
+
`skills/archer`. Its source is versioned with the engine and included in the npm
|
|
406
|
+
package, so it is not tied to one developer's local agent configuration.
|
|
407
|
+
|
|
408
|
+
Install it into any supported coding agent with the Skills CLI:
|
|
409
|
+
|
|
410
|
+
```sh
|
|
411
|
+
npx skills add lucasacoutinho/archer --skill archer
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Agents can then use `$archer` to set up rules, diagnose findings, and fix source
|
|
415
|
+
violations without weakening architecture policy.
|
|
416
|
+
|
|
417
|
+
## Development
|
|
418
|
+
|
|
419
|
+
Archer dogfoods its rules in both `test/architecture.test.ts` and
|
|
420
|
+
`archer.config.ts`. The repository checks Node 20, 22, and 24 on Linux and
|
|
421
|
+
Windows, plus Jest, Bun, `node:test`, the CLI, package exports, and type
|
|
422
|
+
definitions.
|
|
423
|
+
|
|
424
|
+
```sh
|
|
425
|
+
npm install
|
|
426
|
+
npm run fmt
|
|
427
|
+
npm run lint
|
|
428
|
+
npm run check
|
|
429
|
+
npm run check:package
|
|
430
|
+
npm run release:check
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
To cross-test the adjacent tiacore checkout, build tiacore once and run:
|
|
434
|
+
|
|
435
|
+
```sh
|
|
436
|
+
npm run test:tia
|
|
437
|
+
npm run test:tia:verify
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
The scripts prefer an installed `@lucasacoutinho/tiacore` package and otherwise
|
|
441
|
+
use `../tiacore`. Set `TIACORE_VITEST_ENTRY` or `TIACORE_CLI` for a checkout in
|
|
442
|
+
another location.
|
|
443
|
+
|
|
444
|
+
## Releasing
|
|
445
|
+
|
|
446
|
+
Releases publish to the public npm registry from the `Publish package` workflow
|
|
447
|
+
(`.github/workflows/publish.yml`) with npm trusted publishing, so no npm token is
|
|
448
|
+
stored in the repository and npm attaches provenance automatically. npm can only
|
|
449
|
+
attach a trusted publisher to a package that already exists, so the first
|
|
450
|
+
version is published manually by a maintainer with two-factor authentication.
|
|
451
|
+
After that, link the workflow once:
|
|
452
|
+
|
|
453
|
+
```sh
|
|
454
|
+
npm trust github @lucasacoutinho/archer --file publish.yml --repo lucasacoutinho/archer --allow-publish
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
## License
|
|
458
|
+
|
|
459
|
+
Archer is licensed under the [Apache License, Version 2.0](LICENSE). See
|
|
460
|
+
[NOTICE](NOTICE) for attribution.
|