@opensip-cli/targeting 0.1.0
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 +8 -0
- package/README.md +31 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/resolve.d.ts +48 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +177 -0
- package/dist/resolve.js.map +1 -0
- package/dist/target-registry.d.ts +58 -0
- package/dist/target-registry.d.ts.map +1 -0
- package/dist/target-registry.js +83 -0
- package/dist/target-registry.js.map +1 -0
- package/package.json +48 -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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
OpenSIP CLI
|
|
2
|
+
Copyright 2026 opensip-ai
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
+
this software except in compliance with the License. A copy of the License is
|
|
6
|
+
included in the LICENSE file and is also available at:
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!-- Generated by scripts/build-package-readmes.mjs — do not edit by hand.
|
|
2
|
+
Change the package's "description" (or the generator template) and run
|
|
3
|
+
`pnpm docs:readmes`. CI enforces sync via `pnpm docs:readmes:check`. -->
|
|
4
|
+
|
|
5
|
+
# @opensip-cli/targeting
|
|
6
|
+
|
|
7
|
+
> Host file-targeting runtime substrate for OpenSIP CLI — the generic TargetRegistry, uniform glob expansion (resolveTargets/preResolveAllTargets), and globalExcludes filtering any tool consumes via scope.targets
|
|
8
|
+
|
|
9
|
+
This is an **internal library** of the opensip-cli toolkit. It is published so the CLI and tools can depend on it; most users will not install it directly.
|
|
10
|
+
|
|
11
|
+
Part of [**opensip-cli**](https://github.com/opensip-ai/opensip-cli) — an open-source codebase-analysis toolkit: fitness checks (`fit`), static call-graph analysis (`graph`), and simulation (`sim`).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
Most users install the CLI, which bundles the first-party tools:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
curl -fsSL https://opensip.ai/cli/install.sh | bash
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This package is published for the CLI and advanced plugin authors; most users should not install `@opensip-cli/targeting` directly.
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
- 📚 Project docs: https://opensip.ai/docs/opensip-cli/
|
|
26
|
+
- 🧭 Package catalog (what every package does): https://github.com/opensip-ai/opensip-cli/blob/v0.1.0/docs/public/70-reference/02-package-catalog.md
|
|
27
|
+
- 📦 Source: https://github.com/opensip-ai/opensip-cli/tree/v0.1.0/packages/targeting
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
Apache-2.0 © opensip-ai
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Uniform target glob expansion (host substrate)
|
|
3
|
+
*
|
|
4
|
+
* The generic glob mechanics any tool consumes via `scope.targets` (ADR-0037):
|
|
5
|
+
* expand a target's `include` globs to absolute paths, then apply per-target
|
|
6
|
+
* `exclude` AND the project `globalExcludes` uniformly, dedup + sort.
|
|
7
|
+
*
|
|
8
|
+
* There is ONE resolution path. The historical fitness `resolveTargetFiles`
|
|
9
|
+
* (which omitted `globalExcludes`) is gone — both excludes always apply.
|
|
10
|
+
*/
|
|
11
|
+
import type { TargetRegistry } from './target-registry.js';
|
|
12
|
+
import type { Target } from '@opensip-cli/config';
|
|
13
|
+
/**
|
|
14
|
+
* Filter a file list against the project `globalExcludes` globs (rootDir-relative,
|
|
15
|
+
* `dot: true`). A no-op when there are no excludes.
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyGlobalExcludes(files: readonly string[], rootDir: string, globalExcludes: readonly string[]): readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a set of targets to a deduplicated, sorted list of absolute file
|
|
20
|
+
* paths. Expands each target's `include` globs, then filters out per-target
|
|
21
|
+
* `exclude` AND the project `globalExcludes` uniformly.
|
|
22
|
+
*
|
|
23
|
+
* This is the single resolution path that replaces the dead `resolveTargetFiles`
|
|
24
|
+
* (which omitted `globalExcludes`) and the single-check `resolveTargetGlobs`
|
|
25
|
+
* fallback — both excludes always apply.
|
|
26
|
+
*
|
|
27
|
+
* @param targets - Targets to resolve
|
|
28
|
+
* @param rootDir - Project root for glob resolution
|
|
29
|
+
* @param globalExcludes - Project-wide exclusion globs, applied to every target
|
|
30
|
+
* @returns Sorted, deduplicated array of absolute file paths
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveTargets(targets: readonly Target[], rootDir: string, globalExcludes: readonly string[]): readonly string[];
|
|
33
|
+
/**
|
|
34
|
+
* Collect all unique glob patterns from every registered target, run a single
|
|
35
|
+
* deduplicated glob pass, then partition results per target — applying both
|
|
36
|
+
* per-target `exclude` and the project `globalExcludes` so that downstream
|
|
37
|
+
* per-unit lookups are pure in-memory.
|
|
38
|
+
*
|
|
39
|
+
* This avoids redundant filesystem traversals when targets share common
|
|
40
|
+
* patterns (e.g. multiple targets sharing the same `packages` source glob).
|
|
41
|
+
*
|
|
42
|
+
* @param registry - The target registry to expand
|
|
43
|
+
* @param globalExcludes - Project-wide exclusion globs, applied to every target
|
|
44
|
+
* @param rootDir - Project root for glob resolution
|
|
45
|
+
* @returns Map of target name → sorted, deduplicated absolute file paths
|
|
46
|
+
*/
|
|
47
|
+
export declare function preResolveAllTargets(registry: TargetRegistry, globalExcludes: readonly string[], rootDir: string): Map<string, readonly string[]>;
|
|
48
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AACA;;;;;;;;;GASG;AAQH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AASlD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,SAAS,MAAM,EAAE,GAChC,SAAS,MAAM,EAAE,CAUnB;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,SAAS,MAAM,EAAE,GAChC,SAAS,MAAM,EAAE,CAkCnB;AA8DD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,cAAc,EACxB,cAAc,EAAE,SAAS,MAAM,EAAE,EACjC,OAAO,EAAE,MAAM,GACd,GAAG,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAiDhC"}
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// @fitness-ignore-file batch-operation-limits -- iterates bounded collections (config entries, registry items, or small analysis results)
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Uniform target glob expansion (host substrate)
|
|
4
|
+
*
|
|
5
|
+
* The generic glob mechanics any tool consumes via `scope.targets` (ADR-0037):
|
|
6
|
+
* expand a target's `include` globs to absolute paths, then apply per-target
|
|
7
|
+
* `exclude` AND the project `globalExcludes` uniformly, dedup + sort.
|
|
8
|
+
*
|
|
9
|
+
* There is ONE resolution path. The historical fitness `resolveTargetFiles`
|
|
10
|
+
* (which omitted `globalExcludes`) is gone — both excludes always apply.
|
|
11
|
+
*/
|
|
12
|
+
import { relative, resolve } from 'node:path';
|
|
13
|
+
import { isPathInside } from '@opensip-cli/core';
|
|
14
|
+
import { globSync } from 'glob';
|
|
15
|
+
import { minimatch, Minimatch } from 'minimatch';
|
|
16
|
+
// Common infrastructure dirs are always ignored to prevent expensive traversals.
|
|
17
|
+
const COMMON_IGNORE = ['**/node_modules/**', '**/dist/**', '**/.git/**'];
|
|
18
|
+
// =============================================================================
|
|
19
|
+
// Global excludes
|
|
20
|
+
// =============================================================================
|
|
21
|
+
/**
|
|
22
|
+
* Filter a file list against the project `globalExcludes` globs (rootDir-relative,
|
|
23
|
+
* `dot: true`). A no-op when there are no excludes.
|
|
24
|
+
*/
|
|
25
|
+
export function applyGlobalExcludes(files, rootDir, globalExcludes) {
|
|
26
|
+
return files.filter((filePath) => {
|
|
27
|
+
// Hard guard: anything not inside the project root after realpath resolution
|
|
28
|
+
// is never returned, regardless of globalExcludes patterns. This closes
|
|
29
|
+
// symlink / ../include / absolute-outside escape vectors.
|
|
30
|
+
if (!isPathInside(filePath, rootDir))
|
|
31
|
+
return false;
|
|
32
|
+
if (globalExcludes.length === 0)
|
|
33
|
+
return true;
|
|
34
|
+
const relativePath = relative(rootDir, filePath);
|
|
35
|
+
return !globalExcludes.some((pattern) => minimatch(relativePath, pattern, { dot: true }));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// =============================================================================
|
|
39
|
+
// Single-pass resolver (the ONE public resolveTargets)
|
|
40
|
+
// =============================================================================
|
|
41
|
+
/**
|
|
42
|
+
* Resolve a set of targets to a deduplicated, sorted list of absolute file
|
|
43
|
+
* paths. Expands each target's `include` globs, then filters out per-target
|
|
44
|
+
* `exclude` AND the project `globalExcludes` uniformly.
|
|
45
|
+
*
|
|
46
|
+
* This is the single resolution path that replaces the dead `resolveTargetFiles`
|
|
47
|
+
* (which omitted `globalExcludes`) and the single-check `resolveTargetGlobs`
|
|
48
|
+
* fallback — both excludes always apply.
|
|
49
|
+
*
|
|
50
|
+
* @param targets - Targets to resolve
|
|
51
|
+
* @param rootDir - Project root for glob resolution
|
|
52
|
+
* @param globalExcludes - Project-wide exclusion globs, applied to every target
|
|
53
|
+
* @returns Sorted, deduplicated array of absolute file paths
|
|
54
|
+
*/
|
|
55
|
+
export function resolveTargets(targets, rootDir, globalExcludes) {
|
|
56
|
+
const files = new Set();
|
|
57
|
+
// Pre-compile globals once for the whole call (mirrors preResolveAllTargets).
|
|
58
|
+
const compiledGlobalExcludes = globalExcludes.map((pattern) => new Minimatch(pattern, { dot: true }));
|
|
59
|
+
for (const target of targets) {
|
|
60
|
+
const { include, exclude } = target.config;
|
|
61
|
+
for (const pattern of include) {
|
|
62
|
+
const matches = globSync(pattern, {
|
|
63
|
+
cwd: rootDir,
|
|
64
|
+
absolute: true,
|
|
65
|
+
nodir: true,
|
|
66
|
+
ignore: [...COMMON_IGNORE, ...exclude],
|
|
67
|
+
});
|
|
68
|
+
// Use the *exact same* post-glob filter as the pre-resolve assemble path
|
|
69
|
+
// (inside-root + target exclude + globalExcludes, dedup+sort) to guarantee
|
|
70
|
+
// identical output sets for equivalent inputs.
|
|
71
|
+
const filtered = filterOneTargetFiles(matches.map((m) => resolve(m)), exclude, compiledGlobalExcludes, rootDir);
|
|
72
|
+
for (const f of filtered)
|
|
73
|
+
files.add(f);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// applyGlobalExcludes is still used by the legacy direct-file-cache fallback
|
|
77
|
+
// paths and external callers; keep it, but the per-target results above have
|
|
78
|
+
// already folded globals for the main resolveTargets contract.
|
|
79
|
+
return [...files].sort();
|
|
80
|
+
}
|
|
81
|
+
// =============================================================================
|
|
82
|
+
// Shared post-glob filtering (used by both resolve paths for exact parity)
|
|
83
|
+
// =============================================================================
|
|
84
|
+
/**
|
|
85
|
+
* Filter a raw list of (already inside-root) absolute paths for one target:
|
|
86
|
+
* - apply the target's own `exclude` globs
|
|
87
|
+
* - apply the project `globalExcludes`
|
|
88
|
+
* - dedup + sort
|
|
89
|
+
*
|
|
90
|
+
* This helper is the single source of truth for "after glob, apply this target's
|
|
91
|
+
* exclude + globals" so that the single-pass `resolveTargets` and the
|
|
92
|
+
* optimized `preResolveAllTargets` (which does a cross-target deduped glob then
|
|
93
|
+
* per-target re-filter) produce byte-identical results for the same inputs.
|
|
94
|
+
*/
|
|
95
|
+
function filterOneTargetFiles(rawMatches, targetExclude, compiledGlobalExcludes, rootDir) {
|
|
96
|
+
const files = new Set();
|
|
97
|
+
for (const m of rawMatches) {
|
|
98
|
+
if (isPathInside(m, rootDir))
|
|
99
|
+
files.add(m);
|
|
100
|
+
}
|
|
101
|
+
const hasTargetExcludes = targetExclude.length > 0;
|
|
102
|
+
const hasGlobals = compiledGlobalExcludes.length > 0;
|
|
103
|
+
if (hasTargetExcludes || hasGlobals) {
|
|
104
|
+
const compiledTargetExcludes = hasTargetExcludes
|
|
105
|
+
? targetExclude.map((ex) => new Minimatch(ex, { dot: true }))
|
|
106
|
+
: [];
|
|
107
|
+
const allExcludes = [...compiledTargetExcludes, ...compiledGlobalExcludes];
|
|
108
|
+
return [...files]
|
|
109
|
+
.filter((filePath) => !allExcludes.some((m) => m.match(relative(rootDir, filePath))))
|
|
110
|
+
.sort();
|
|
111
|
+
}
|
|
112
|
+
return [...files].sort();
|
|
113
|
+
}
|
|
114
|
+
/** Assemble a single target's file list from pre-resolved pattern results, applying excludes. */
|
|
115
|
+
function assembleTargetFiles(targetConfig, patternResults, compiledGlobalExcludes, rootDir) {
|
|
116
|
+
// Collect raw matches for this target's includes (the shared glob may have
|
|
117
|
+
// over-collected for shared patterns; we filter precisely here).
|
|
118
|
+
const raw = [];
|
|
119
|
+
for (const pattern of targetConfig.include) {
|
|
120
|
+
const matches = patternResults.get(pattern) ?? [];
|
|
121
|
+
raw.push(...matches);
|
|
122
|
+
}
|
|
123
|
+
return filterOneTargetFiles(raw, targetConfig.exclude, compiledGlobalExcludes, rootDir);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Collect all unique glob patterns from every registered target, run a single
|
|
127
|
+
* deduplicated glob pass, then partition results per target — applying both
|
|
128
|
+
* per-target `exclude` and the project `globalExcludes` so that downstream
|
|
129
|
+
* per-unit lookups are pure in-memory.
|
|
130
|
+
*
|
|
131
|
+
* This avoids redundant filesystem traversals when targets share common
|
|
132
|
+
* patterns (e.g. multiple targets sharing the same `packages` source glob).
|
|
133
|
+
*
|
|
134
|
+
* @param registry - The target registry to expand
|
|
135
|
+
* @param globalExcludes - Project-wide exclusion globs, applied to every target
|
|
136
|
+
* @param rootDir - Project root for glob resolution
|
|
137
|
+
* @returns Map of target name → sorted, deduplicated absolute file paths
|
|
138
|
+
*/
|
|
139
|
+
export function preResolveAllTargets(registry, globalExcludes, rootDir) {
|
|
140
|
+
const targets = registry.getAll();
|
|
141
|
+
if (targets.length === 0)
|
|
142
|
+
return new Map();
|
|
143
|
+
// Collect all unique include patterns across targets
|
|
144
|
+
const allPatterns = new Set();
|
|
145
|
+
for (const target of targets) {
|
|
146
|
+
for (const pattern of target.config.include) {
|
|
147
|
+
allPatterns.add(pattern);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Single glob pass for each unique pattern — deduplicated across targets.
|
|
151
|
+
const patternResults = new Map();
|
|
152
|
+
for (const pattern of allPatterns) {
|
|
153
|
+
const matches = globSync(pattern, {
|
|
154
|
+
cwd: rootDir,
|
|
155
|
+
absolute: true,
|
|
156
|
+
nodir: true,
|
|
157
|
+
ignore: COMMON_IGNORE,
|
|
158
|
+
});
|
|
159
|
+
patternResults.set(pattern, matches.map((m) => resolve(m)));
|
|
160
|
+
}
|
|
161
|
+
// Pre-compile globalExcludes matchers for reuse across all targets
|
|
162
|
+
const compiledExcludes = globalExcludes.map((pattern) => new Minimatch(pattern, { dot: true }));
|
|
163
|
+
// Assemble per-target file lists by combining pattern results and filtering excludes.
|
|
164
|
+
// Both target-specific excludes AND globalExcludes are applied here so that
|
|
165
|
+
// per-unit resolution is a pure in-memory lookup with no minimatch calls.
|
|
166
|
+
const result = new Map();
|
|
167
|
+
for (const target of targets) {
|
|
168
|
+
const files = assembleTargetFiles({
|
|
169
|
+
include: target.config.include,
|
|
170
|
+
exclude: target.config.exclude,
|
|
171
|
+
name: target.config.name,
|
|
172
|
+
}, patternResults, compiledExcludes, rootDir);
|
|
173
|
+
result.set(target.config.name, files);
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,0IAA0I;AAC1I;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,QAAQ,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MAAM,CAAC,MAAM,CAAC,OAAO;YAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI;SACzB,EACD,cAAc,EACd,gBAAgB,EAChB,OAAO,CACR,CAAC;QACF,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Target Registry (host substrate)
|
|
3
|
+
*
|
|
4
|
+
* Registry for target definitions. Provides lookup by name and tags.
|
|
5
|
+
*
|
|
6
|
+
* Built on the kernel's unified `Registry<T>` with `silent-skip` —
|
|
7
|
+
* registering a target with a name that's already taken is a no-op
|
|
8
|
+
* (the historical behaviour).
|
|
9
|
+
*
|
|
10
|
+
* The entire targets module uses a synchronous API because target definitions
|
|
11
|
+
* are loaded once at startup from a small YAML config file and then held
|
|
12
|
+
* in-memory for fast, repeated lookups throughout the process lifetime. The
|
|
13
|
+
* resolver (resolve.ts) similarly uses synchronous glob expansion. Since the
|
|
14
|
+
* data set is small and bounded by project configuration, async I/O offers no
|
|
15
|
+
* practical benefit and would complicate every call site that queries targets.
|
|
16
|
+
*
|
|
17
|
+
* This is the **generic** half of file targeting (ADR-0037): register/get/byTag
|
|
18
|
+
* over the host-owned `Target` shape. The scope-matching `findByScope`
|
|
19
|
+
* (languages + concerns) stays in `@opensip-cli/fitness` — `concerns` is a
|
|
20
|
+
* check-scope concept, so the substrate carries no language-canonicalizing path
|
|
21
|
+
* and never reads the run scope.
|
|
22
|
+
*/
|
|
23
|
+
import type { Target } from '@opensip-cli/config';
|
|
24
|
+
/** Registry for target definitions with lookup by name and tags. */
|
|
25
|
+
export declare class TargetRegistry {
|
|
26
|
+
private readonly inner;
|
|
27
|
+
/**
|
|
28
|
+
* Register a target. Silently skips if a target with the same name already exists.
|
|
29
|
+
* @param target - Target definition to register
|
|
30
|
+
* @returns This registry instance for chaining
|
|
31
|
+
*/
|
|
32
|
+
register(target: Target): this;
|
|
33
|
+
/**
|
|
34
|
+
* Look up a target by its config name.
|
|
35
|
+
* @param name - Target name to find
|
|
36
|
+
* @returns The matching target, or undefined if not found
|
|
37
|
+
*/
|
|
38
|
+
getByName(name: string): Target | undefined;
|
|
39
|
+
/** Return all registered targets. */
|
|
40
|
+
getAll(): readonly Target[];
|
|
41
|
+
/**
|
|
42
|
+
* Return all targets that include the given tag.
|
|
43
|
+
* @param tag - Tag string to filter by
|
|
44
|
+
* @returns Targets whose config.tags contain the tag
|
|
45
|
+
*/
|
|
46
|
+
getByTag(tag: string): readonly Target[];
|
|
47
|
+
/**
|
|
48
|
+
* Check whether a target with the given name is registered.
|
|
49
|
+
* @param name - Target name to check
|
|
50
|
+
* @returns True if the target exists in the registry
|
|
51
|
+
*/
|
|
52
|
+
has(name: string): boolean;
|
|
53
|
+
/** Number of registered targets. */
|
|
54
|
+
get size(): number;
|
|
55
|
+
/** Remove all targets from the registry. */
|
|
56
|
+
clear(): void;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=target-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target-registry.d.ts","sourceRoot":"","sources":["../src/target-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AASlD,oEAAoE;AACpE,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAInB;IAEH;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAW9B;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI3C,qCAAqC;IACrC,MAAM,IAAI,SAAS,MAAM,EAAE;IAI3B;;;;OAIG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE;IAIxC;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,oCAAoC;IACpC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,4CAA4C;IAC5C,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Target Registry (host substrate)
|
|
3
|
+
*
|
|
4
|
+
* Registry for target definitions. Provides lookup by name and tags.
|
|
5
|
+
*
|
|
6
|
+
* Built on the kernel's unified `Registry<T>` with `silent-skip` —
|
|
7
|
+
* registering a target with a name that's already taken is a no-op
|
|
8
|
+
* (the historical behaviour).
|
|
9
|
+
*
|
|
10
|
+
* The entire targets module uses a synchronous API because target definitions
|
|
11
|
+
* are loaded once at startup from a small YAML config file and then held
|
|
12
|
+
* in-memory for fast, repeated lookups throughout the process lifetime. The
|
|
13
|
+
* resolver (resolve.ts) similarly uses synchronous glob expansion. Since the
|
|
14
|
+
* data set is small and bounded by project configuration, async I/O offers no
|
|
15
|
+
* practical benefit and would complicate every call site that queries targets.
|
|
16
|
+
*
|
|
17
|
+
* This is the **generic** half of file targeting (ADR-0037): register/get/byTag
|
|
18
|
+
* over the host-owned `Target` shape. The scope-matching `findByScope`
|
|
19
|
+
* (languages + concerns) stays in `@opensip-cli/fitness` — `concerns` is a
|
|
20
|
+
* check-scope concept, so the substrate carries no language-canonicalizing path
|
|
21
|
+
* and never reads the run scope.
|
|
22
|
+
*/
|
|
23
|
+
import { Registry } from '@opensip-cli/core';
|
|
24
|
+
/** Registry for target definitions with lookup by name and tags. */
|
|
25
|
+
export class TargetRegistry {
|
|
26
|
+
inner = new Registry({
|
|
27
|
+
module: 'targeting',
|
|
28
|
+
duplicatePolicy: 'silent-skip',
|
|
29
|
+
evtPrefix: 'target.registry',
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Register a target. Silently skips if a target with the same name already exists.
|
|
33
|
+
* @param target - Target definition to register
|
|
34
|
+
* @returns This registry instance for chaining
|
|
35
|
+
*/
|
|
36
|
+
register(target) {
|
|
37
|
+
const name = target.config.name;
|
|
38
|
+
this.inner.register({
|
|
39
|
+
id: name,
|
|
40
|
+
name,
|
|
41
|
+
target,
|
|
42
|
+
tags: target.config.tags,
|
|
43
|
+
});
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Look up a target by its config name.
|
|
48
|
+
* @param name - Target name to find
|
|
49
|
+
* @returns The matching target, or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
getByName(name) {
|
|
52
|
+
return this.inner.getById(name)?.target;
|
|
53
|
+
}
|
|
54
|
+
/** Return all registered targets. */
|
|
55
|
+
getAll() {
|
|
56
|
+
return this.inner.getAll().map((r) => r.target);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Return all targets that include the given tag.
|
|
60
|
+
* @param tag - Tag string to filter by
|
|
61
|
+
* @returns Targets whose config.tags contain the tag
|
|
62
|
+
*/
|
|
63
|
+
getByTag(tag) {
|
|
64
|
+
return this.inner.getByTag(tag).map((r) => r.target);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check whether a target with the given name is registered.
|
|
68
|
+
* @param name - Target name to check
|
|
69
|
+
* @returns True if the target exists in the registry
|
|
70
|
+
*/
|
|
71
|
+
has(name) {
|
|
72
|
+
return this.inner.has(name);
|
|
73
|
+
}
|
|
74
|
+
/** Number of registered targets. */
|
|
75
|
+
get size() {
|
|
76
|
+
return this.inner.size;
|
|
77
|
+
}
|
|
78
|
+
/** Remove all targets from the registry. */
|
|
79
|
+
clear() {
|
|
80
|
+
this.inner.clear();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=target-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target-registry.js","sourceRoot":"","sources":["../src/target-registry.ts"],"names":[],"mappings":"AAA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AC;IAED,4CAA4C;IAC5C,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opensip-cli/targeting",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "Host file-targeting runtime substrate for OpenSIP CLI — the generic TargetRegistry, uniform glob expansion (resolveTargets/preResolveAllTargets), and globalExcludes filtering any tool consumes via scope.targets",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"opensip-cli",
|
|
8
|
+
"static-analysis",
|
|
9
|
+
"code-quality"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/opensip-ai/opensip-cli.git",
|
|
14
|
+
"directory": "packages/targeting"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/opensip-ai/opensip-cli",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/opensip-ai/opensip-cli/issues"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"NOTICE"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"glob": "^13.0.0",
|
|
33
|
+
"minimatch": "^10.2.5",
|
|
34
|
+
"@opensip-cli/config": "0.1.0",
|
|
35
|
+
"@opensip-cli/core": "0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^24.13.2",
|
|
39
|
+
"typescript": "~6.0.3",
|
|
40
|
+
"vitest": "^4.1.8"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc",
|
|
44
|
+
"test": "vitest run --passWithNoTests",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"clean": "rm -rf dist"
|
|
47
|
+
}
|
|
48
|
+
}
|