@living-architecture/riviere-role-enforcement-use-cases 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.
Files changed (47) hide show
  1. package/LICENSE +190 -0
  2. package/dist/features/enforcement/adapters/oxlint/oxlint-role-enforcement-runner.d.ts +5 -0
  3. package/dist/features/enforcement/adapters/oxlint/oxlint-role-enforcement-runner.d.ts.map +1 -0
  4. package/dist/features/enforcement/adapters/oxlint/oxlint-role-enforcement-runner.js +58 -0
  5. package/dist/features/enforcement/commands/run-role-enforcement-input.d.ts +7 -0
  6. package/dist/features/enforcement/commands/run-role-enforcement-input.d.ts.map +1 -0
  7. package/dist/features/enforcement/commands/run-role-enforcement-input.js +1 -0
  8. package/dist/features/enforcement/commands/run-role-enforcement-result.d.ts +8 -0
  9. package/dist/features/enforcement/commands/run-role-enforcement-result.d.ts.map +1 -0
  10. package/dist/features/enforcement/commands/run-role-enforcement-result.js +1 -0
  11. package/dist/features/enforcement/commands/run-role-enforcement.d.ts +17 -0
  12. package/dist/features/enforcement/commands/run-role-enforcement.d.ts.map +1 -0
  13. package/dist/features/enforcement/commands/run-role-enforcement.js +36 -0
  14. package/dist/features/enforcement/data-access/role-enforcement/role-enforcement-project-load-error.d.ts +4 -0
  15. package/dist/features/enforcement/data-access/role-enforcement/role-enforcement-project-load-error.d.ts.map +1 -0
  16. package/dist/features/enforcement/data-access/role-enforcement/role-enforcement-project-load-error.js +3 -0
  17. package/dist/features/enforcement/data-access/role-enforcement/role-enforcement-project-repository.d.ts +23 -0
  18. package/dist/features/enforcement/data-access/role-enforcement/role-enforcement-project-repository.d.ts.map +1 -0
  19. package/dist/features/enforcement/data-access/role-enforcement/role-enforcement-project-repository.js +98 -0
  20. package/dist/index.d.ts +7 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +376 -0
  23. package/dist/infra/external-clients/filesystem/find-file-up.d.ts +3 -0
  24. package/dist/infra/external-clients/filesystem/find-file-up.d.ts.map +1 -0
  25. package/dist/infra/external-clients/filesystem/find-file-up.js +12 -0
  26. package/dist/infra/external-clients/filesystem/find-files-matching-patterns.d.ts +13 -0
  27. package/dist/infra/external-clients/filesystem/find-files-matching-patterns.d.ts.map +1 -0
  28. package/dist/infra/external-clients/filesystem/find-files-matching-patterns.js +44 -0
  29. package/dist/infra/external-clients/filesystem/read-workspace-package-patterns.d.ts +8 -0
  30. package/dist/infra/external-clients/filesystem/read-workspace-package-patterns.d.ts.map +1 -0
  31. package/dist/infra/external-clients/filesystem/read-workspace-package-patterns.js +24 -0
  32. package/dist/infra/external-clients/oxlint/oxlint-client.d.ts +21 -0
  33. package/dist/infra/external-clients/oxlint/oxlint-client.d.ts.map +1 -0
  34. package/dist/infra/external-clients/oxlint/oxlint-client.js +43 -0
  35. package/dist/infra/external-clients/oxlint/oxlint-config.d.ts +24 -0
  36. package/dist/infra/external-clients/oxlint/oxlint-config.d.ts.map +1 -0
  37. package/dist/infra/external-clients/oxlint/oxlint-config.js +1 -0
  38. package/dist/infra/external-clients/oxlint/oxlint-execution-error.d.ts +5 -0
  39. package/dist/infra/external-clients/oxlint/oxlint-execution-error.d.ts.map +1 -0
  40. package/dist/infra/external-clients/oxlint/oxlint-execution-error.js +7 -0
  41. package/dist/infra/external-clients/oxlint/oxlint-path-resolution.d.ts +3 -0
  42. package/dist/infra/external-clients/oxlint/oxlint-path-resolution.d.ts.map +1 -0
  43. package/dist/infra/external-clients/oxlint/oxlint-path-resolution.js +7 -0
  44. package/dist/infra/external-clients/typescript/load-typescript-module.d.ts +3 -0
  45. package/dist/infra/external-clients/typescript/load-typescript-module.d.ts.map +1 -0
  46. package/dist/infra/external-clients/typescript/load-typescript-module.js +6 -0
  47. package/package.json +31 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright
52
+ owner or by an individual or Legal Entity authorized to submit on behalf
53
+ of the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Nick Tune
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ import { type OxlintClient } from '../../../../infra/external-clients/oxlint/oxlint-config';
2
+ import type { RoleEnforcementRunner } from '@living-architecture/riviere-role-enforcement-domain-model';
3
+ /** @riviere-role domain-port-adapter */
4
+ export declare function createOxlintRoleEnforcementRunner(oxlintClient: OxlintClient, pluginPath: string | undefined): RoleEnforcementRunner;
5
+ //# sourceMappingURL=oxlint-role-enforcement-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oxlint-role-enforcement-runner.d.ts","sourceRoot":"","sources":["../../../../../src/features/enforcement/adapters/oxlint/oxlint-role-enforcement-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAElB,MAAM,yDAAyD,CAAA;AAGhE,OAAO,KAAK,EACV,qBAAqB,EAEtB,MAAM,4DAA4D,CAAA;AAEnE,wCAAwC;AACxC,wBAAgB,iCAAiC,CAC/C,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,qBAAqB,CAmBvB"}
@@ -0,0 +1,58 @@
1
+ import {} from '../../../../infra/external-clients/oxlint/oxlint-config';
2
+ import { OxlintExecutionError } from '../../../../infra/external-clients/oxlint/oxlint-execution-error';
3
+ import { createOxlintImportSpecifier } from '../../../../infra/external-clients/oxlint/oxlint-path-resolution';
4
+ /** @riviere-role domain-port-adapter */
5
+ export function createOxlintRoleEnforcementRunner(oxlintClient, pluginPath) {
6
+ return (input) => {
7
+ if (pluginPath === undefined) {
8
+ return failure('Cannot find role-enforcement-plugin.mjs');
9
+ }
10
+ try {
11
+ return oxlintClient({
12
+ config: createOxlintConfig(input.config, input.configDir, pluginPath),
13
+ configDir: input.configDir,
14
+ lintTargets: input.lintTargets,
15
+ });
16
+ }
17
+ catch (error) {
18
+ if (error instanceof OxlintExecutionError) {
19
+ return failure(error.message);
20
+ }
21
+ throw error;
22
+ }
23
+ };
24
+ }
25
+ function failure(message) {
26
+ return {
27
+ exitCode: 1,
28
+ stderr: `${message}\n`,
29
+ stdout: '',
30
+ };
31
+ }
32
+ function createOxlintConfig(config, configDir, pluginPath) {
33
+ return {
34
+ ignorePatterns: config.ignorePatterns,
35
+ jsPlugins: [
36
+ {
37
+ name: 'riviere-role-enforcement',
38
+ specifier: createOxlintImportSpecifier(configDir, pluginPath),
39
+ },
40
+ ],
41
+ plugins: ['import'],
42
+ rules: {
43
+ 'import/no-cycle': 'error',
44
+ 'riviere-role-enforcement/enforce-roles': [
45
+ 'error',
46
+ {
47
+ configDir,
48
+ configDisplayPath: 'role-enforcement.config.ts',
49
+ ignorePatterns: config.ignorePatterns,
50
+ ...(config.importAliases !== undefined && { importAliases: config.importAliases }),
51
+ locationHierarchy: config.locationHierarchy,
52
+ roleDefinitionsDir: config.roleDefinitionsDir,
53
+ roles: config.roles,
54
+ },
55
+ ],
56
+ },
57
+ };
58
+ }
@@ -0,0 +1,7 @@
1
+ /** @riviere-role command-use-case-input */
2
+ export interface RunRoleEnforcementInput {
3
+ configModulePath: string;
4
+ configDir: string;
5
+ packageFilter?: string;
6
+ }
7
+ //# sourceMappingURL=run-role-enforcement-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-role-enforcement-input.d.ts","sourceRoot":"","sources":["../../../../src/features/enforcement/commands/run-role-enforcement-input.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB"}
@@ -0,0 +1,8 @@
1
+ /** @riviere-role command-use-case-result */
2
+ export interface RunRoleEnforcementResult {
3
+ durationMs: number;
4
+ exitCode: number;
5
+ stderr: string;
6
+ stdout: string;
7
+ }
8
+ //# sourceMappingURL=run-role-enforcement-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-role-enforcement-result.d.ts","sourceRoot":"","sources":["../../../../src/features/enforcement/commands/run-role-enforcement-result.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf"}
@@ -0,0 +1,17 @@
1
+ import { RoleEnforcementProjectRepository } from '../data-access/role-enforcement/role-enforcement-project-repository';
2
+ import { type RoleEnforcementRunner } from '@living-architecture/riviere-role-enforcement-domain-model';
3
+ import type { RunRoleEnforcementInput } from './run-role-enforcement-input';
4
+ import type { RunRoleEnforcementResult } from './run-role-enforcement-result';
5
+ interface RunRoleEnforcementDependencies {
6
+ now: () => number;
7
+ projectRepository: RoleEnforcementProjectRepository;
8
+ runner: RoleEnforcementRunner;
9
+ }
10
+ /** @riviere-role command-use-case */
11
+ export declare class RunRoleEnforcement {
12
+ private readonly deps;
13
+ constructor(deps: RunRoleEnforcementDependencies);
14
+ execute(input: RunRoleEnforcementInput): RunRoleEnforcementResult;
15
+ }
16
+ export {};
17
+ //# sourceMappingURL=run-role-enforcement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-role-enforcement.d.ts","sourceRoot":"","sources":["../../../../src/features/enforcement/commands/run-role-enforcement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,qEAAqE,CAAA;AACtH,OAAO,EAEL,KAAK,qBAAqB,EAE3B,MAAM,4DAA4D,CAAA;AACnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAC3E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AAG7E,UAAU,8BAA8B;IACtC,GAAG,EAAE,MAAM,MAAM,CAAA;IACjB,iBAAiB,EAAE,gCAAgC,CAAA;IACnD,MAAM,EAAE,qBAAqB,CAAA;CAC9B;AAED,qCAAqC;AACrC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgC;gBAEzC,IAAI,EAAE,8BAA8B;IAIhD,OAAO,CAAC,KAAK,EAAE,uBAAuB,GAAG,wBAAwB;CA2BlE"}
@@ -0,0 +1,36 @@
1
+ import { RoleEnforcementProjectRepository } from '../data-access/role-enforcement/role-enforcement-project-repository';
2
+ import { PackageFilterError, RoleEnforcementExecutionError, } from '@living-architecture/riviere-role-enforcement-domain-model';
3
+ import { RoleEnforcementProjectLoadError } from '../data-access/role-enforcement/role-enforcement-project-load-error';
4
+ /** @riviere-role command-use-case */
5
+ export class RunRoleEnforcement {
6
+ deps;
7
+ constructor(deps) {
8
+ this.deps = deps;
9
+ }
10
+ execute(input) {
11
+ const start = this.deps.now();
12
+ try {
13
+ const project = this.deps.projectRepository.load(input.configModulePath, input.configDir);
14
+ const adapterResult = project.execute(this.deps.runner, input.packageFilter);
15
+ return {
16
+ durationMs: this.deps.now() - start,
17
+ exitCode: adapterResult.exitCode,
18
+ stderr: adapterResult.stderr,
19
+ stdout: adapterResult.stdout,
20
+ };
21
+ }
22
+ catch (error) {
23
+ if (error instanceof RoleEnforcementExecutionError ||
24
+ error instanceof PackageFilterError ||
25
+ error instanceof RoleEnforcementProjectLoadError) {
26
+ return {
27
+ durationMs: this.deps.now() - start,
28
+ exitCode: 1,
29
+ stderr: `${error.message}\n`,
30
+ stdout: '',
31
+ };
32
+ }
33
+ throw error;
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,4 @@
1
+ /** @riviere-role data-access-error */
2
+ export declare class RoleEnforcementProjectLoadError extends Error {
3
+ }
4
+ //# sourceMappingURL=role-enforcement-project-load-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-enforcement-project-load-error.d.ts","sourceRoot":"","sources":["../../../../../src/features/enforcement/data-access/role-enforcement/role-enforcement-project-load-error.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,qBAAa,+BAAgC,SAAQ,KAAK;CAAG"}
@@ -0,0 +1,3 @@
1
+ /** @riviere-role data-access-error */
2
+ export class RoleEnforcementProjectLoadError extends Error {
3
+ }
@@ -0,0 +1,23 @@
1
+ import { RoleEnforcementProject } from '@living-architecture/riviere-role-enforcement-domain-model';
2
+ import type { findFilesMatchingPatterns } from '../../../../infra/external-clients/filesystem/find-files-matching-patterns';
3
+ import { readWorkspacePackagePatterns as defaultReadWorkspacePackagePatterns } from '../../../../infra/external-clients/filesystem/read-workspace-package-patterns';
4
+ import { loadTypeScriptModule as defaultLoadTypeScriptModule } from '../../../../infra/external-clients/typescript/load-typescript-module';
5
+ type ReadDirectory = Parameters<typeof findFilesMatchingPatterns>[3];
6
+ declare const defaultDependencies: {
7
+ findFilesMatchingPatterns: typeof findFilesMatchingPatterns;
8
+ loadTypeScriptModule: typeof defaultLoadTypeScriptModule;
9
+ readDirectory: typeof defaultReadDirectory;
10
+ readRoleDefinitionFileNames: typeof defaultReadRoleDefinitionFileNames;
11
+ readWorkspacePackagePatterns: typeof defaultReadWorkspacePackagePatterns;
12
+ realpath: (filePath: string) => string;
13
+ };
14
+ declare function defaultReadDirectory(rootDir: Parameters<ReadDirectory>[0], options: Parameters<ReadDirectory>[1]): ReturnType<ReadDirectory>;
15
+ declare function defaultReadRoleDefinitionFileNames(directoryPath: string): readonly string[];
16
+ /** @riviere-role aggregate-repository */
17
+ export declare class RoleEnforcementProjectRepository {
18
+ private readonly dependencies;
19
+ constructor(dependencies?: Partial<typeof defaultDependencies>);
20
+ load(configModulePath: string, configDir: string): RoleEnforcementProject;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=role-enforcement-project-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-enforcement-project-repository.d.ts","sourceRoot":"","sources":["../../../../../src/features/enforcement/data-access/role-enforcement/role-enforcement-project-repository.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,sBAAsB,EACvB,MAAM,4DAA4D,CAAA;AACnE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4EAA4E,CAAA;AAE3H,OAAO,EAAE,4BAA4B,IAAI,mCAAmC,EAAE,MAAM,+EAA+E,CAAA;AACnK,OAAO,EAAE,oBAAoB,IAAI,2BAA2B,EAAE,MAAM,sEAAsE,CAAA;AAG1I,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAAA;AAEpE,QAAA,MAAM,mBAAmB;;;;;;yBAMF,MAAM;CAC5B,CAAA;AAED,iBAAS,oBAAoB,CAC3B,OAAO,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EACrC,OAAO,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GACpC,UAAU,CAAC,aAAa,CAAC,CAE3B;AAED,iBAAS,kCAAkC,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAIpF;AAED,yCAAyC;AACzC,qBAAa,gCAAgC;IAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA4B;gBAE7C,YAAY,GAAE,OAAO,CAAC,OAAO,mBAAmB,CAAM;IAOlE,IAAI,CAAC,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,sBAAsB;CA8B1E"}
@@ -0,0 +1,98 @@
1
+ import { readdirSync, realpathSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { RoleEnforcementConfiguration, RoleEnforcementProject, } from '@living-architecture/riviere-role-enforcement-domain-model';
4
+ import { findFilesMatchingPatterns as defaultFindFilesMatchingPatterns } from '../../../../infra/external-clients/filesystem/find-files-matching-patterns';
5
+ import { readWorkspacePackagePatterns as defaultReadWorkspacePackagePatterns } from '../../../../infra/external-clients/filesystem/read-workspace-package-patterns';
6
+ import { loadTypeScriptModule as defaultLoadTypeScriptModule } from '../../../../infra/external-clients/typescript/load-typescript-module';
7
+ import { RoleEnforcementProjectLoadError } from './role-enforcement-project-load-error';
8
+ const defaultDependencies = {
9
+ findFilesMatchingPatterns: defaultFindFilesMatchingPatterns,
10
+ loadTypeScriptModule: defaultLoadTypeScriptModule,
11
+ readDirectory: defaultReadDirectory,
12
+ readRoleDefinitionFileNames: defaultReadRoleDefinitionFileNames,
13
+ readWorkspacePackagePatterns: defaultReadWorkspacePackagePatterns,
14
+ realpath: (filePath) => realpathSync(filePath),
15
+ };
16
+ function defaultReadDirectory(rootDir, options) {
17
+ return readdirSync(rootDir, options);
18
+ }
19
+ function defaultReadRoleDefinitionFileNames(directoryPath) {
20
+ return readdirSync(directoryPath, { withFileTypes: true })
21
+ .filter((entry) => entry.isFile())
22
+ .map((entry) => entry.name);
23
+ }
24
+ /** @riviere-role aggregate-repository */
25
+ export class RoleEnforcementProjectRepository {
26
+ dependencies;
27
+ constructor(dependencies = {}) {
28
+ this.dependencies = {
29
+ ...defaultDependencies,
30
+ ...dependencies,
31
+ };
32
+ }
33
+ load(configModulePath, configDir) {
34
+ const canonicalConfigDir = this.dependencies.realpath(configDir);
35
+ const config = readConfig(this.dependencies.loadTypeScriptModule(path.resolve(canonicalConfigDir, configModulePath)));
36
+ validateRoleDefinitionFiles(config, this.dependencies.readRoleDefinitionFileNames(path.resolve(canonicalConfigDir, config.roleDefinitionsDir)));
37
+ const workspacePatterns = this.dependencies.readWorkspacePackagePatterns(canonicalConfigDir);
38
+ const packagePatterns = workspacePatterns ?? packagePatternsFromConfiguration(config);
39
+ const workspacePackageManifests = this.dependencies.findFilesMatchingPatterns(canonicalConfigDir, packagePatterns.include.map((pattern) => `${withoutTrailingSlash(pattern)}/package.json`), packagePatterns.ignore.map((pattern) => `${withoutTrailingSlash(pattern)}/package.json`), this.dependencies.readDirectory);
40
+ config.validateWorkspacePackages(workspacePackageManifests.map((manifestPath) => path.posix.dirname(manifestPath)));
41
+ const lintTargets = this.dependencies.findFilesMatchingPatterns(canonicalConfigDir, config.include, config.ignorePatterns, this.dependencies.readDirectory);
42
+ return new RoleEnforcementProject(config, canonicalConfigDir, lintTargets);
43
+ }
44
+ }
45
+ function validateRoleDefinitionFiles(config, fileNames) {
46
+ const definitionFiles = fileNames.filter((fileName) => fileName.endsWith('.md') && fileName !== 'index.md');
47
+ const definedRoles = new Set(definitionFiles.map((fileName) => fileName.slice(0, -3)));
48
+ for (const configuredRole of config.roles) {
49
+ if (!definedRoles.has(configuredRole.name)) {
50
+ throw new RoleEnforcementProjectLoadError(`Role '${configuredRole.name}' has no definition file at '${config.roleDefinitionsDir}/${configuredRole.name}.md'.`);
51
+ }
52
+ }
53
+ const configuredRoles = new Set(config.roles.map((role) => role.name));
54
+ for (const definitionFile of definitionFiles) {
55
+ const roleName = definitionFile.slice(0, -3);
56
+ if (!configuredRoles.has(roleName)) {
57
+ throw new RoleEnforcementProjectLoadError(`Role definition '${definitionFile}' has no configured role.`);
58
+ }
59
+ }
60
+ }
61
+ function packagePatternsFromConfiguration(config) {
62
+ const packageRoots = [
63
+ ...new Set([...config.assignedPackages, ...config.unassignedPackages].map((packagePath) => packagePath.split('/')[0])),
64
+ ].filter((root) => root !== undefined && root.length > 0);
65
+ return {
66
+ include: packageRoots.flatMap((root) => [`${root}/*`, `${root}/*/*`]),
67
+ ignore: [],
68
+ };
69
+ }
70
+ function withoutTrailingSlash(value) {
71
+ return value.endsWith('/') ? value.slice(0, -1) : value;
72
+ }
73
+ function readConfig(configModule) {
74
+ const exportedConfiguration = readConfigExport(resolveModuleExports(configModule));
75
+ const parsed = RoleEnforcementConfiguration.parse(exportedConfiguration);
76
+ if (!parsed.success) {
77
+ throw parsed.error;
78
+ }
79
+ return parsed.data;
80
+ }
81
+ function resolveModuleExports(loaded) {
82
+ if (typeof loaded !== 'object' || loaded === null) {
83
+ return loaded;
84
+ }
85
+ if ('config' in loaded) {
86
+ return loaded;
87
+ }
88
+ if ('default' in loaded) {
89
+ return loaded.default;
90
+ }
91
+ return loaded;
92
+ }
93
+ function readConfigExport(moduleExports) {
94
+ if (typeof moduleExports === 'object' && moduleExports !== null && 'config' in moduleExports) {
95
+ return moduleExports.config;
96
+ }
97
+ return undefined;
98
+ }
@@ -0,0 +1,7 @@
1
+ export { createOxlintRoleEnforcementRunner } from './features/enforcement/adapters/oxlint/oxlint-role-enforcement-runner';
2
+ export { RunRoleEnforcement } from './features/enforcement/commands/run-role-enforcement';
3
+ export type { RunRoleEnforcementInput } from './features/enforcement/commands/run-role-enforcement-input';
4
+ export type { RunRoleEnforcementResult } from './features/enforcement/commands/run-role-enforcement-result';
5
+ export { RoleEnforcementProjectRepository } from './features/enforcement/data-access/role-enforcement/role-enforcement-project-repository';
6
+ export { runOxlint } from './infra/external-clients/oxlint/oxlint-client';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,uEAAuE,CAAA;AACzH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sDAAsD,CAAA;AACzF,YAAY,EAAE,uBAAuB,EAAE,MAAM,4DAA4D,CAAA;AACzG,YAAY,EAAE,wBAAwB,EAAE,MAAM,6DAA6D,CAAA;AAC3G,OAAO,EAAE,gCAAgC,EAAE,MAAM,yFAAyF,CAAA;AAC1I,OAAO,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,376 @@
1
+ // src/infra/external-clients/oxlint/oxlint-execution-error.ts
2
+ var OxlintExecutionError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "OxlintExecutionError";
6
+ }
7
+ };
8
+
9
+ // src/infra/external-clients/oxlint/oxlint-path-resolution.ts
10
+ import path from "node:path";
11
+ function createOxlintImportSpecifier(configDir, pluginPath) {
12
+ const relativePath = path.relative(configDir, pluginPath);
13
+ const normalizedPath = relativePath.replaceAll("\\", "/");
14
+ return normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
15
+ }
16
+
17
+ // src/features/enforcement/adapters/oxlint/oxlint-role-enforcement-runner.ts
18
+ function createOxlintRoleEnforcementRunner(oxlintClient, pluginPath) {
19
+ return (input) => {
20
+ if (pluginPath === void 0) {
21
+ return failure("Cannot find role-enforcement-plugin.mjs");
22
+ }
23
+ try {
24
+ return oxlintClient({
25
+ config: createOxlintConfig(input.config, input.configDir, pluginPath),
26
+ configDir: input.configDir,
27
+ lintTargets: input.lintTargets
28
+ });
29
+ } catch (error) {
30
+ if (error instanceof OxlintExecutionError) {
31
+ return failure(error.message);
32
+ }
33
+ throw error;
34
+ }
35
+ };
36
+ }
37
+ function failure(message) {
38
+ return {
39
+ exitCode: 1,
40
+ stderr: `${message}
41
+ `,
42
+ stdout: ""
43
+ };
44
+ }
45
+ function createOxlintConfig(config, configDir, pluginPath) {
46
+ return {
47
+ ignorePatterns: config.ignorePatterns,
48
+ jsPlugins: [
49
+ {
50
+ name: "riviere-role-enforcement",
51
+ specifier: createOxlintImportSpecifier(configDir, pluginPath)
52
+ }
53
+ ],
54
+ plugins: ["import"],
55
+ rules: {
56
+ "import/no-cycle": "error",
57
+ "riviere-role-enforcement/enforce-roles": [
58
+ "error",
59
+ {
60
+ configDir,
61
+ configDisplayPath: "role-enforcement.config.ts",
62
+ ignorePatterns: config.ignorePatterns,
63
+ ...config.importAliases !== void 0 && { importAliases: config.importAliases },
64
+ locationHierarchy: config.locationHierarchy,
65
+ roleDefinitionsDir: config.roleDefinitionsDir,
66
+ roles: config.roles
67
+ }
68
+ ]
69
+ }
70
+ };
71
+ }
72
+
73
+ // src/features/enforcement/data-access/role-enforcement/role-enforcement-project-repository.ts
74
+ import { readdirSync, realpathSync } from "node:fs";
75
+ import path4 from "node:path";
76
+ import {
77
+ RoleEnforcementConfiguration,
78
+ RoleEnforcementProject
79
+ } from "@living-architecture/riviere-role-enforcement-domain-model";
80
+
81
+ // src/infra/external-clients/filesystem/find-files-matching-patterns.ts
82
+ import { minimatch } from "minimatch";
83
+ import path2 from "node:path";
84
+ function findFilesMatchingPatterns(rootDir, includePatterns, ignorePatterns, readDirectory) {
85
+ const scanDirectories = includePatterns.map((pattern) => extractScanDirectory(pattern));
86
+ const files = scanDirectories.flatMap(
87
+ (scanDirectory) => walkFiles(rootDir, scanDirectory, readDirectory)
88
+ );
89
+ return files.filter((filePath) => matchesAny(filePath, includePatterns)).filter((filePath) => !matchesAny(filePath, ignorePatterns));
90
+ }
91
+ function extractScanDirectory(includePattern) {
92
+ const segments = includePattern.split("/");
93
+ const staticSegments = [];
94
+ for (const segment of segments) {
95
+ if (segment.includes("*") || segment.includes("{") || segment.includes("?")) {
96
+ break;
97
+ }
98
+ staticSegments.push(segment);
99
+ }
100
+ return staticSegments.join("/");
101
+ }
102
+ function walkFiles(rootDir, scanDirectory, readDirectory) {
103
+ const absoluteScanDirectory = path2.join(rootDir, scanDirectory);
104
+ return walkDirectory(absoluteScanDirectory, scanDirectory, readDirectory);
105
+ }
106
+ function walkDirectory(absoluteDirectory, relativeDirectory, readDirectory) {
107
+ return readDirectory(absoluteDirectory, { withFileTypes: true }).flatMap((entry) => {
108
+ const absolutePath = path2.join(absoluteDirectory, entry.name);
109
+ const relativePath = normalizePath(path2.join(relativeDirectory, entry.name));
110
+ if (entry.isFile()) {
111
+ return [relativePath];
112
+ }
113
+ if (entry.isDirectory() && !entry.isSymbolicLink()) {
114
+ return walkDirectory(absolutePath, relativePath, readDirectory);
115
+ }
116
+ return [];
117
+ });
118
+ }
119
+ function matchesAny(filePath, patterns) {
120
+ return patterns.some((pattern) => minimatch(filePath, pattern, { dot: true }));
121
+ }
122
+ function normalizePath(value) {
123
+ return value.replaceAll("\\", "/");
124
+ }
125
+
126
+ // src/infra/external-clients/filesystem/read-workspace-package-patterns.ts
127
+ import { existsSync, readFileSync } from "node:fs";
128
+ import path3 from "node:path";
129
+ import { parse } from "yaml";
130
+ function readWorkspacePackagePatterns(workspaceDir) {
131
+ const workspaceFile = path3.join(workspaceDir, "pnpm-workspace.yaml");
132
+ if (!existsSync(workspaceFile)) {
133
+ return null;
134
+ }
135
+ const document = parse(readFileSync(workspaceFile, "utf8"));
136
+ if (typeof document !== "object" || document === null || !("packages" in document) || !Array.isArray(document.packages) || !document.packages.every((pattern) => typeof pattern === "string")) {
137
+ throw new TypeError("pnpm-workspace.yaml must contain a 'packages' array of paths.");
138
+ }
139
+ return {
140
+ ignore: document.packages.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1)),
141
+ include: document.packages.filter((pattern) => !pattern.startsWith("!"))
142
+ };
143
+ }
144
+
145
+ // src/infra/external-clients/typescript/load-typescript-module.ts
146
+ import { require as requireTypeScript } from "tsx/cjs/api";
147
+ var loadModule = requireTypeScript;
148
+ function loadTypeScriptModule(modulePath) {
149
+ return loadModule(modulePath, import.meta.url);
150
+ }
151
+
152
+ // src/features/enforcement/data-access/role-enforcement/role-enforcement-project-load-error.ts
153
+ var RoleEnforcementProjectLoadError = class extends Error {
154
+ };
155
+
156
+ // src/features/enforcement/data-access/role-enforcement/role-enforcement-project-repository.ts
157
+ var defaultDependencies = {
158
+ findFilesMatchingPatterns,
159
+ loadTypeScriptModule,
160
+ readDirectory: defaultReadDirectory,
161
+ readRoleDefinitionFileNames: defaultReadRoleDefinitionFileNames,
162
+ readWorkspacePackagePatterns,
163
+ realpath: (filePath) => realpathSync(filePath)
164
+ };
165
+ function defaultReadDirectory(rootDir, options) {
166
+ return readdirSync(rootDir, options);
167
+ }
168
+ function defaultReadRoleDefinitionFileNames(directoryPath) {
169
+ return readdirSync(directoryPath, { withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => entry.name);
170
+ }
171
+ var RoleEnforcementProjectRepository = class {
172
+ dependencies;
173
+ constructor(dependencies = {}) {
174
+ this.dependencies = {
175
+ ...defaultDependencies,
176
+ ...dependencies
177
+ };
178
+ }
179
+ load(configModulePath, configDir) {
180
+ const canonicalConfigDir = this.dependencies.realpath(configDir);
181
+ const config = readConfig(
182
+ this.dependencies.loadTypeScriptModule(path4.resolve(canonicalConfigDir, configModulePath))
183
+ );
184
+ validateRoleDefinitionFiles(
185
+ config,
186
+ this.dependencies.readRoleDefinitionFileNames(
187
+ path4.resolve(canonicalConfigDir, config.roleDefinitionsDir)
188
+ )
189
+ );
190
+ const workspacePatterns = this.dependencies.readWorkspacePackagePatterns(canonicalConfigDir);
191
+ const packagePatterns = workspacePatterns ?? packagePatternsFromConfiguration(config);
192
+ const workspacePackageManifests = this.dependencies.findFilesMatchingPatterns(
193
+ canonicalConfigDir,
194
+ packagePatterns.include.map((pattern) => `${withoutTrailingSlash(pattern)}/package.json`),
195
+ packagePatterns.ignore.map((pattern) => `${withoutTrailingSlash(pattern)}/package.json`),
196
+ this.dependencies.readDirectory
197
+ );
198
+ config.validateWorkspacePackages(
199
+ workspacePackageManifests.map((manifestPath) => path4.posix.dirname(manifestPath))
200
+ );
201
+ const lintTargets = this.dependencies.findFilesMatchingPatterns(
202
+ canonicalConfigDir,
203
+ config.include,
204
+ config.ignorePatterns,
205
+ this.dependencies.readDirectory
206
+ );
207
+ return new RoleEnforcementProject(config, canonicalConfigDir, lintTargets);
208
+ }
209
+ };
210
+ function validateRoleDefinitionFiles(config, fileNames) {
211
+ const definitionFiles = fileNames.filter(
212
+ (fileName) => fileName.endsWith(".md") && fileName !== "index.md"
213
+ );
214
+ const definedRoles = new Set(definitionFiles.map((fileName) => fileName.slice(0, -3)));
215
+ for (const configuredRole of config.roles) {
216
+ if (!definedRoles.has(configuredRole.name)) {
217
+ throw new RoleEnforcementProjectLoadError(
218
+ `Role '${configuredRole.name}' has no definition file at '${config.roleDefinitionsDir}/${configuredRole.name}.md'.`
219
+ );
220
+ }
221
+ }
222
+ const configuredRoles = new Set(config.roles.map((role) => role.name));
223
+ for (const definitionFile of definitionFiles) {
224
+ const roleName = definitionFile.slice(0, -3);
225
+ if (!configuredRoles.has(roleName)) {
226
+ throw new RoleEnforcementProjectLoadError(
227
+ `Role definition '${definitionFile}' has no configured role.`
228
+ );
229
+ }
230
+ }
231
+ }
232
+ function packagePatternsFromConfiguration(config) {
233
+ const packageRoots = [
234
+ ...new Set(
235
+ [...config.assignedPackages, ...config.unassignedPackages].map(
236
+ (packagePath) => packagePath.split("/")[0]
237
+ )
238
+ )
239
+ ].filter((root) => root !== void 0 && root.length > 0);
240
+ return {
241
+ include: packageRoots.flatMap((root) => [`${root}/*`, `${root}/*/*`]),
242
+ ignore: []
243
+ };
244
+ }
245
+ function withoutTrailingSlash(value) {
246
+ return value.endsWith("/") ? value.slice(0, -1) : value;
247
+ }
248
+ function readConfig(configModule) {
249
+ const exportedConfiguration = readConfigExport(resolveModuleExports(configModule));
250
+ const parsed = RoleEnforcementConfiguration.parse(exportedConfiguration);
251
+ if (!parsed.success) {
252
+ throw parsed.error;
253
+ }
254
+ return parsed.data;
255
+ }
256
+ function resolveModuleExports(loaded) {
257
+ if (typeof loaded !== "object" || loaded === null) {
258
+ return loaded;
259
+ }
260
+ if ("config" in loaded) {
261
+ return loaded;
262
+ }
263
+ if ("default" in loaded) {
264
+ return loaded.default;
265
+ }
266
+ return loaded;
267
+ }
268
+ function readConfigExport(moduleExports) {
269
+ if (typeof moduleExports === "object" && moduleExports !== null && "config" in moduleExports) {
270
+ return moduleExports.config;
271
+ }
272
+ return void 0;
273
+ }
274
+
275
+ // src/features/enforcement/commands/run-role-enforcement.ts
276
+ import {
277
+ PackageFilterError,
278
+ RoleEnforcementExecutionError
279
+ } from "@living-architecture/riviere-role-enforcement-domain-model";
280
+ var RunRoleEnforcement = class {
281
+ deps;
282
+ constructor(deps) {
283
+ this.deps = deps;
284
+ }
285
+ execute(input) {
286
+ const start = this.deps.now();
287
+ try {
288
+ const project = this.deps.projectRepository.load(input.configModulePath, input.configDir);
289
+ const adapterResult = project.execute(this.deps.runner, input.packageFilter);
290
+ return {
291
+ durationMs: this.deps.now() - start,
292
+ exitCode: adapterResult.exitCode,
293
+ stderr: adapterResult.stderr,
294
+ stdout: adapterResult.stdout
295
+ };
296
+ } catch (error) {
297
+ if (error instanceof RoleEnforcementExecutionError || error instanceof PackageFilterError || error instanceof RoleEnforcementProjectLoadError) {
298
+ return {
299
+ durationMs: this.deps.now() - start,
300
+ exitCode: 1,
301
+ stderr: `${error.message}
302
+ `,
303
+ stdout: ""
304
+ };
305
+ }
306
+ throw error;
307
+ }
308
+ }
309
+ };
310
+
311
+ // src/infra/external-clients/oxlint/oxlint-client.ts
312
+ import { spawnSync } from "node:child_process";
313
+ import { rmSync, writeFileSync } from "node:fs";
314
+ import path6 from "node:path";
315
+ import { fileURLToPath } from "node:url";
316
+
317
+ // src/infra/external-clients/filesystem/find-file-up.ts
318
+ import { existsSync as existsSync2 } from "node:fs";
319
+ import path5 from "node:path";
320
+ function findFileUp(startDir, fileName) {
321
+ const candidate = path5.join(startDir, fileName);
322
+ if (existsSync2(candidate)) return candidate;
323
+ const parent = path5.dirname(startDir);
324
+ if (parent === startDir) return void 0;
325
+ return findFileUp(parent, fileName);
326
+ }
327
+
328
+ // src/infra/external-clients/oxlint/oxlint-client.ts
329
+ var defaultDependencies2 = {
330
+ rmSync,
331
+ spawnSync,
332
+ writeFileSync
333
+ };
334
+ function runOxlint(input, dependencies = defaultDependencies2) {
335
+ const oxlintBinaryPath = resolveOxlintBinaryPath();
336
+ const oxlintConfigPath = path6.join(
337
+ input.configDir,
338
+ `.oxlintrc.role-enforcement.${process.pid}.${Date.now()}.json`
339
+ );
340
+ dependencies.writeFileSync(oxlintConfigPath, JSON.stringify(input.config, null, 2));
341
+ try {
342
+ const commandResult = dependencies.spawnSync(
343
+ oxlintBinaryPath,
344
+ ["-c", oxlintConfigPath, ...input.lintTargets],
345
+ {
346
+ cwd: input.configDir,
347
+ encoding: "utf8",
348
+ maxBuffer: 50 * 1024 * 1024
349
+ }
350
+ );
351
+ if (commandResult.error !== void 0) {
352
+ throw new OxlintExecutionError(commandResult.error.message);
353
+ }
354
+ return {
355
+ exitCode: commandResult.status ?? 1,
356
+ stderr: commandResult.stderr,
357
+ stdout: commandResult.stdout
358
+ };
359
+ } finally {
360
+ dependencies.rmSync(oxlintConfigPath, { force: true });
361
+ }
362
+ }
363
+ function resolveOxlintBinaryPath() {
364
+ const startDirectory = path6.dirname(fileURLToPath(import.meta.url));
365
+ const found = findFileUp(startDirectory, path6.join("node_modules", ".bin", "oxlint"));
366
+ if (found === void 0) {
367
+ throw new OxlintExecutionError("Cannot find oxlint binary in node_modules");
368
+ }
369
+ return found;
370
+ }
371
+ export {
372
+ RoleEnforcementProjectRepository,
373
+ RunRoleEnforcement,
374
+ createOxlintRoleEnforcementRunner,
375
+ runOxlint
376
+ };
@@ -0,0 +1,3 @@
1
+ /** @riviere-role external-client-service */
2
+ export declare function findFileUp(startDir: string, fileName: string): string | undefined;
3
+ //# sourceMappingURL=find-file-up.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-file-up.d.ts","sourceRoot":"","sources":["../../../../src/infra/external-clients/filesystem/find-file-up.ts"],"names":[],"mappings":"AAGA,4CAA4C;AAC5C,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMjF"}
@@ -0,0 +1,12 @@
1
+ import { existsSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ /** @riviere-role external-client-service */
4
+ export function findFileUp(startDir, fileName) {
5
+ const candidate = path.join(startDir, fileName);
6
+ if (existsSync(candidate))
7
+ return candidate;
8
+ const parent = path.dirname(startDir);
9
+ if (parent === startDir)
10
+ return undefined;
11
+ return findFileUp(parent, fileName);
12
+ }
@@ -0,0 +1,13 @@
1
+ import type { PathLike } from 'node:fs';
2
+ type ReadDirectory = (rootDir: PathLike, options: {
3
+ withFileTypes: true;
4
+ }) => Array<{
5
+ isDirectory: () => boolean;
6
+ isFile: () => boolean;
7
+ isSymbolicLink: () => boolean;
8
+ name: string;
9
+ }>;
10
+ /** @riviere-role external-client-service */
11
+ export declare function findFilesMatchingPatterns(rootDir: string, includePatterns: readonly string[], ignorePatterns: readonly string[], readDirectory: ReadDirectory): string[];
12
+ export {};
13
+ //# sourceMappingURL=find-files-matching-patterns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-files-matching-patterns.d.ts","sourceRoot":"","sources":["../../../../src/infra/external-clients/filesystem/find-files-matching-patterns.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGvC,KAAK,aAAa,GAAG,CACnB,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE;IACP,aAAa,EAAE,IAAI,CAAA;CACpB,KACE,KAAK,CAAC;IACT,WAAW,EAAE,MAAM,OAAO,CAAA;IAC1B,MAAM,EAAE,MAAM,OAAO,CAAA;IACrB,cAAc,EAAE,MAAM,OAAO,CAAA;IAC7B,IAAI,EAAE,MAAM,CAAA;CACb,CAAC,CAAA;AAEF,4CAA4C;AAC5C,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,SAAS,MAAM,EAAE,EAClC,cAAc,EAAE,SAAS,MAAM,EAAE,EACjC,aAAa,EAAE,aAAa,GAC3B,MAAM,EAAE,CAQV"}
@@ -0,0 +1,44 @@
1
+ import { minimatch } from 'minimatch';
2
+ import path from 'node:path';
3
+ /** @riviere-role external-client-service */
4
+ export function findFilesMatchingPatterns(rootDir, includePatterns, ignorePatterns, readDirectory) {
5
+ const scanDirectories = includePatterns.map((pattern) => extractScanDirectory(pattern));
6
+ const files = scanDirectories.flatMap((scanDirectory) => walkFiles(rootDir, scanDirectory, readDirectory));
7
+ return files
8
+ .filter((filePath) => matchesAny(filePath, includePatterns))
9
+ .filter((filePath) => !matchesAny(filePath, ignorePatterns));
10
+ }
11
+ function extractScanDirectory(includePattern) {
12
+ const segments = includePattern.split('/');
13
+ const staticSegments = [];
14
+ for (const segment of segments) {
15
+ if (segment.includes('*') || segment.includes('{') || segment.includes('?')) {
16
+ break;
17
+ }
18
+ staticSegments.push(segment);
19
+ }
20
+ return staticSegments.join('/');
21
+ }
22
+ function walkFiles(rootDir, scanDirectory, readDirectory) {
23
+ const absoluteScanDirectory = path.join(rootDir, scanDirectory);
24
+ return walkDirectory(absoluteScanDirectory, scanDirectory, readDirectory);
25
+ }
26
+ function walkDirectory(absoluteDirectory, relativeDirectory, readDirectory) {
27
+ return readDirectory(absoluteDirectory, { withFileTypes: true }).flatMap((entry) => {
28
+ const absolutePath = path.join(absoluteDirectory, entry.name);
29
+ const relativePath = normalizePath(path.join(relativeDirectory, entry.name));
30
+ if (entry.isFile()) {
31
+ return [relativePath];
32
+ }
33
+ if (entry.isDirectory() && !entry.isSymbolicLink()) {
34
+ return walkDirectory(absolutePath, relativePath, readDirectory);
35
+ }
36
+ return [];
37
+ });
38
+ }
39
+ function matchesAny(filePath, patterns) {
40
+ return patterns.some((pattern) => minimatch(filePath, pattern, { dot: true }));
41
+ }
42
+ function normalizePath(value) {
43
+ return value.replaceAll('\\', '/');
44
+ }
@@ -0,0 +1,8 @@
1
+ type WorkspacePackagePatterns = {
2
+ readonly ignore: readonly string[];
3
+ readonly include: readonly string[];
4
+ };
5
+ /** @riviere-role external-client-service */
6
+ export declare function readWorkspacePackagePatterns(workspaceDir: string): WorkspacePackagePatterns | null;
7
+ export {};
8
+ //# sourceMappingURL=read-workspace-package-patterns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-workspace-package-patterns.d.ts","sourceRoot":"","sources":["../../../../src/infra/external-clients/filesystem/read-workspace-package-patterns.ts"],"names":[],"mappings":"AAIA,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;CACpC,CAAA;AAED,4CAA4C;AAC5C,wBAAgB,4BAA4B,CAC1C,YAAY,EAAE,MAAM,GACnB,wBAAwB,GAAG,IAAI,CAqBjC"}
@@ -0,0 +1,24 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parse } from 'yaml';
4
+ /** @riviere-role external-client-service */
5
+ export function readWorkspacePackagePatterns(workspaceDir) {
6
+ const workspaceFile = path.join(workspaceDir, 'pnpm-workspace.yaml');
7
+ if (!existsSync(workspaceFile)) {
8
+ return null;
9
+ }
10
+ const document = parse(readFileSync(workspaceFile, 'utf8'));
11
+ if (typeof document !== 'object' ||
12
+ document === null ||
13
+ !('packages' in document) ||
14
+ !Array.isArray(document.packages) ||
15
+ !document.packages.every((pattern) => typeof pattern === 'string')) {
16
+ throw new TypeError("pnpm-workspace.yaml must contain a 'packages' array of paths.");
17
+ }
18
+ return {
19
+ ignore: document.packages
20
+ .filter((pattern) => pattern.startsWith('!'))
21
+ .map((pattern) => pattern.slice(1)),
22
+ include: document.packages.filter((pattern) => !pattern.startsWith('!')),
23
+ };
24
+ }
@@ -0,0 +1,21 @@
1
+ import type { OxlintClient } from './oxlint-config';
2
+ interface OxlintClientDependencies {
3
+ rmSync: (filePath: string, options: {
4
+ force: true;
5
+ }) => void;
6
+ spawnSync: (command: string, args: string[], options: {
7
+ cwd: string;
8
+ encoding: 'utf8';
9
+ maxBuffer: number;
10
+ }) => {
11
+ error?: Error;
12
+ status: number | null;
13
+ stderr: string;
14
+ stdout: string;
15
+ };
16
+ writeFileSync: (filePath: string, contents: string) => void;
17
+ }
18
+ /** @riviere-role external-client-service */
19
+ export declare function runOxlint(input: Parameters<OxlintClient>[0], dependencies?: OxlintClientDependencies): ReturnType<OxlintClient>;
20
+ export {};
21
+ //# sourceMappingURL=oxlint-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oxlint-client.d.ts","sourceRoot":"","sources":["../../../../src/infra/external-clients/oxlint/oxlint-client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAGnD,UAAU,wBAAwB;IAChC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,KAAK,EAAE,IAAI,CAAA;KAAE,KAAK,IAAI,CAAA;IAC5D,SAAS,EAAE,CACT,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE;QACP,GAAG,EAAE,MAAM,CAAA;QACX,QAAQ,EAAE,MAAM,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;KAClB,KACE;QACH,KAAK,CAAC,EAAE,KAAK,CAAA;QACb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;QACrB,MAAM,EAAE,MAAM,CAAA;QACd,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;IACD,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CAC5D;AAQD,4CAA4C;AAC5C,wBAAgB,SAAS,CACvB,KAAK,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAClC,YAAY,GAAE,wBAA8C,GAC3D,UAAU,CAAC,YAAY,CAAC,CAgC1B"}
@@ -0,0 +1,43 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { rmSync, writeFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { findFileUp } from '../filesystem/find-file-up';
6
+ import { OxlintExecutionError } from './oxlint-execution-error';
7
+ const defaultDependencies = {
8
+ rmSync,
9
+ spawnSync,
10
+ writeFileSync,
11
+ };
12
+ /** @riviere-role external-client-service */
13
+ export function runOxlint(input, dependencies = defaultDependencies) {
14
+ const oxlintBinaryPath = resolveOxlintBinaryPath();
15
+ const oxlintConfigPath = path.join(input.configDir, `.oxlintrc.role-enforcement.${process.pid}.${Date.now()}.json`);
16
+ dependencies.writeFileSync(oxlintConfigPath, JSON.stringify(input.config, null, 2));
17
+ try {
18
+ const commandResult = dependencies.spawnSync(oxlintBinaryPath, ['-c', oxlintConfigPath, ...input.lintTargets], {
19
+ cwd: input.configDir,
20
+ encoding: 'utf8',
21
+ maxBuffer: 50 * 1024 * 1024,
22
+ });
23
+ if (commandResult.error !== undefined) {
24
+ throw new OxlintExecutionError(commandResult.error.message);
25
+ }
26
+ return {
27
+ exitCode: commandResult.status ?? 1,
28
+ stderr: commandResult.stderr,
29
+ stdout: commandResult.stdout,
30
+ };
31
+ }
32
+ finally {
33
+ dependencies.rmSync(oxlintConfigPath, { force: true });
34
+ }
35
+ }
36
+ function resolveOxlintBinaryPath() {
37
+ const startDirectory = path.dirname(fileURLToPath(import.meta.url));
38
+ const found = findFileUp(startDirectory, path.join('node_modules', '.bin', 'oxlint'));
39
+ if (found === undefined) {
40
+ throw new OxlintExecutionError('Cannot find oxlint binary in node_modules');
41
+ }
42
+ return found;
43
+ }
@@ -0,0 +1,24 @@
1
+ /** @riviere-role external-client-model */
2
+ export interface OxlintConfig {
3
+ ignorePatterns: readonly string[];
4
+ jsPlugins: Array<{
5
+ name: string;
6
+ specifier: string;
7
+ }>;
8
+ plugins: readonly string[];
9
+ rules: Record<string, unknown>;
10
+ }
11
+ interface RunOxlintInput {
12
+ config: OxlintConfig;
13
+ configDir: string;
14
+ lintTargets: readonly string[];
15
+ }
16
+ interface RunOxlintResult {
17
+ exitCode: number;
18
+ stderr: string;
19
+ stdout: string;
20
+ }
21
+ /** @riviere-role external-client-model */
22
+ export type OxlintClient = (input: RunOxlintInput) => RunOxlintResult;
23
+ export {};
24
+ //# sourceMappingURL=oxlint-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oxlint-config.d.ts","sourceRoot":"","sources":["../../../../src/infra/external-clients/oxlint/oxlint-config.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,SAAS,EAAE,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAA;QACZ,SAAS,EAAE,MAAM,CAAA;KAClB,CAAC,CAAA;IACF,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED,UAAU,cAAc;IACtB,MAAM,EAAE,YAAY,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;CAC/B;AAED,UAAU,eAAe;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED,0CAA0C;AAC1C,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,eAAe,CAAA"}
@@ -0,0 +1,5 @@
1
+ /** @riviere-role external-client-error */
2
+ export declare class OxlintExecutionError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ //# sourceMappingURL=oxlint-execution-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oxlint-execution-error.d.ts","sourceRoot":"","sources":["../../../../src/infra/external-clients/oxlint/oxlint-execution-error.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B"}
@@ -0,0 +1,7 @@
1
+ /** @riviere-role external-client-error */
2
+ export class OxlintExecutionError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = 'OxlintExecutionError';
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ /** @riviere-role external-client-service */
2
+ export declare function createOxlintImportSpecifier(configDir: string, pluginPath: string): string;
3
+ //# sourceMappingURL=oxlint-path-resolution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oxlint-path-resolution.d.ts","sourceRoot":"","sources":["../../../../src/infra/external-clients/oxlint/oxlint-path-resolution.ts"],"names":[],"mappings":"AAEA,4CAA4C;AAC5C,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAIzF"}
@@ -0,0 +1,7 @@
1
+ import path from 'node:path';
2
+ /** @riviere-role external-client-service */
3
+ export function createOxlintImportSpecifier(configDir, pluginPath) {
4
+ const relativePath = path.relative(configDir, pluginPath);
5
+ const normalizedPath = relativePath.replaceAll('\\', '/');
6
+ return normalizedPath.startsWith('.') ? normalizedPath : `./${normalizedPath}`;
7
+ }
@@ -0,0 +1,3 @@
1
+ /** @riviere-role external-client-service */
2
+ export declare function loadTypeScriptModule(modulePath: string): unknown;
3
+ //# sourceMappingURL=load-typescript-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-typescript-module.d.ts","sourceRoot":"","sources":["../../../../src/infra/external-clients/typescript/load-typescript-module.ts"],"names":[],"mappings":"AAIA,4CAA4C;AAC5C,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEhE"}
@@ -0,0 +1,6 @@
1
+ import { require as requireTypeScript } from 'tsx/cjs/api';
2
+ const loadModule = requireTypeScript;
3
+ /** @riviere-role external-client-service */
4
+ export function loadTypeScriptModule(modulePath) {
5
+ return loadModule(modulePath, import.meta.url);
6
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@living-architecture/riviere-role-enforcement-use-cases",
3
+ "version": "0.1.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ "./package.json": "./package.json",
13
+ ".": {
14
+ "@living-architecture/source": "./src/index.ts",
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "!dist/**/__fixtures__/**",
23
+ "!**/*.tsbuildinfo"
24
+ ],
25
+ "dependencies": {
26
+ "minimatch": "^10.0.1",
27
+ "tsx": "^4.21.0",
28
+ "yaml": "^2.7.0",
29
+ "@living-architecture/riviere-role-enforcement-domain-model": "0.4.0"
30
+ }
31
+ }