1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//! Angular framework plugin.
//!
//! Detects Angular projects and marks component, module, service, guard,
//! pipe, directive, resolver, and interceptor files as entry points.
//! Parses `angular.json` to extract styles, scripts, main, and polyfills
//! from build targets as additional entry points.
#[cfg(test)]
use std::path::Path;
use super::config_parser;
use super::{Plugin, PluginResult};
define_plugin!(
struct AngularPlugin => "angular",
enablers: &["@angular/core"],
entry_patterns: &[
// Standard Angular CLI layout
"src/main.ts",
"src/app/**/*.component.ts",
"src/app/**/*.module.ts",
"src/app/**/*.service.ts",
"src/app/**/*.guard.ts",
"src/app/**/*.pipe.ts",
"src/app/**/*.directive.ts",
"src/app/**/*.resolver.ts",
"src/app/**/*.interceptor.ts",
// Nx monorepo layout (apps and libs under arbitrary paths)
"**/src/main.ts",
"**/src/app/**/*.component.ts",
"**/src/app/**/*.module.ts",
"**/src/app/**/*.service.ts",
"**/src/app/**/*.guard.ts",
"**/src/app/**/*.pipe.ts",
"**/src/app/**/*.directive.ts",
"**/src/app/**/*.resolver.ts",
"**/src/app/**/*.interceptor.ts",
],
config_patterns: &["angular.json", ".angular.json"],
always_used: &[
"angular.json",
".angular.json",
"src/polyfills.ts",
"src/environments/**/*.ts",
],
tooling_dependencies: &[
"@angular/cli",
"@angular-devkit/build-angular",
"@angular/compiler-cli",
"@angular/compiler",
"@angular/build",
"zone.js",
"tslib",
// Peer dependencies of @angular/core that may not be directly imported
// but are required by the Angular framework at runtime
"rxjs",
"@angular/common",
"@angular/platform-browser",
"@angular/platform-browser-dynamic",
],
resolve_config(config_path, source, _root) {
let mut result = PluginResult::default();
// angular.json: projects.*.architect.build.options.styles -> entry patterns
// These are CSS/SCSS files loaded by the Angular CLI build system.
let styles = config_parser::extract_config_object_nested_string_or_array(
source,
config_path,
&["projects"],
&["architect", "build", "options", "styles"],
);
for style in &styles {
let path = style.trim_start_matches("./");
result.push_entry_pattern(path.to_string());
}
// angular.json: projects.*.architect.build.options.scripts -> entry patterns
let scripts = config_parser::extract_config_object_nested_string_or_array(
source,
config_path,
&["projects"],
&["architect", "build", "options", "scripts"],
);
for script in &scripts {
let path = script.trim_start_matches("./");
result.push_entry_pattern(path.to_string());
}
// angular.json: projects.*.architect.build.options.main -> entry patterns
// Also check "browser" -- newer Angular CLI uses "browser" instead of "main"
for field in &["main", "browser"] {
let mains = config_parser::extract_config_object_nested_strings(
source,
config_path,
&["projects"],
&["architect", "build", "options", field],
);
for main in &mains {
let path = main.trim_start_matches("./");
result.push_entry_pattern(path.to_string());
}
}
// angular.json: projects.*.architect.build.options.polyfills -> entry patterns
// Can be a string or array
let polyfills = config_parser::extract_config_object_nested_string_or_array(
source,
config_path,
&["projects"],
&["architect", "build", "options", "polyfills"],
);
for polyfill in &polyfills {
let trimmed = polyfill.trim_start_matches("./");
// Skip npm package references like "zone.js" -- only add file paths.
// File paths contain "/" (directory separators) or start with "src/", etc.
// Bare package names like "zone.js" have no "/" and shouldn't be entry points.
if trimmed.contains('/') {
result.push_entry_pattern(trimmed.to_string());
}
}
// angular.json: projects.*.architect.test.options.main -> entry patterns
let test_mains = config_parser::extract_config_object_nested_strings(
source,
config_path,
&["projects"],
&["architect", "test", "options", "main"],
);
for main in &test_mains {
let path = main.trim_start_matches("./");
result.push_entry_pattern(path.to_string());
}
result
},
);
#[cfg(test)]
mod tests {
use super::*;
fn has_entry_pattern(result: &PluginResult, pattern: &str) -> bool {
result
.entry_patterns
.iter()
.any(|entry_pattern| entry_pattern.pattern == pattern)
}
#[test]
fn resolve_config_extracts_styles() {
let source = r#"{
"projects": {
"my-app": {
"architect": {
"build": {
"options": {
"styles": ["src/styles.css", "src/theme.scss"]
}
}
}
}
}
}"#;
let plugin = AngularPlugin;
let result =
plugin.resolve_config(Path::new("angular.json"), source, Path::new("/project"));
assert!(has_entry_pattern(&result, "src/styles.css"));
assert!(has_entry_pattern(&result, "src/theme.scss"));
}
#[test]
fn resolve_config_extracts_main() {
let source = r#"{
"projects": {
"my-app": {
"architect": {
"build": {
"options": {
"main": "src/main.ts"
}
}
}
}
}
}"#;
let plugin = AngularPlugin;
let result =
plugin.resolve_config(Path::new("angular.json"), source, Path::new("/project"));
assert!(has_entry_pattern(&result, "src/main.ts"));
}
#[test]
fn resolve_config_extracts_scripts() {
let source = r#"{
"projects": {
"my-app": {
"architect": {
"build": {
"options": {
"scripts": ["node_modules/some-lib/dist/script.js"]
}
}
}
}
}
}"#;
let plugin = AngularPlugin;
let result =
plugin.resolve_config(Path::new("angular.json"), source, Path::new("/project"));
assert!(has_entry_pattern(
&result,
"node_modules/some-lib/dist/script.js"
));
}
#[test]
fn resolve_config_multiple_projects() {
let source = r#"{
"projects": {
"app-one": {
"architect": {
"build": {
"options": {
"styles": ["apps/one/src/styles.css"],
"main": "apps/one/src/main.ts"
}
}
}
},
"app-two": {
"architect": {
"build": {
"options": {
"styles": ["apps/two/src/styles.css"],
"main": "apps/two/src/main.ts"
}
}
}
}
}
}"#;
let plugin = AngularPlugin;
let result =
plugin.resolve_config(Path::new("angular.json"), source, Path::new("/project"));
assert!(has_entry_pattern(&result, "apps/one/src/styles.css"));
assert!(has_entry_pattern(&result, "apps/two/src/styles.css"));
assert!(has_entry_pattern(&result, "apps/one/src/main.ts"));
assert!(has_entry_pattern(&result, "apps/two/src/main.ts"));
}
#[test]
fn resolve_config_polyfills_skips_packages() {
let source = r#"{
"projects": {
"my-app": {
"architect": {
"build": {
"options": {
"polyfills": ["zone.js", "src/polyfills.ts"]
}
}
}
}
}
}"#;
let plugin = AngularPlugin;
let result =
plugin.resolve_config(Path::new("angular.json"), source, Path::new("/project"));
// zone.js is a package, not a file — should be skipped
assert!(!has_entry_pattern(&result, "zone.js"));
// src/polyfills.ts is a file path — should be included
assert!(has_entry_pattern(&result, "src/polyfills.ts"));
}
}