| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  | # Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:01 +01:00
										 |  |  | # | 
					
						
							|  |  |  | # Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  | # found in the LICENSE file at https://angular.io/license | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MADGE_CONFIG_LABEL = "//tools/circular_dependency_test:madge-resolve.config.js" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  |   Creates a test target that ensures that no circular dependencies can | 
					
						
							|  |  |  |   be found in the given entry point file. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def circular_dependency_test(name, deps, entry_point, **kwargs): | 
					
						
							|  |  |  |     nodejs_test( | 
					
						
							|  |  |  |         name = name, | 
					
						
							|  |  |  |         data = ["@npm//madge", MADGE_CONFIG_LABEL] + deps, | 
					
						
							|  |  |  |         entry_point = "@npm//:node_modules/madge/bin/cli.js", | 
					
						
							|  |  |  |         templated_args = [ | 
					
						
							|  |  |  |             "--circular", | 
					
						
							|  |  |  |             "--no-spinner", | 
					
						
							| 
									
										
										
										
											2020-03-29 13:29:50 -07:00
										 |  |  |             # NOTE: We cannot use `$(rootpath)` to resolve labels. This is because `ts_library` | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:01 +01:00
										 |  |  |             # does not pre-declare outputs in the rule. Hence, the outputs cannot be referenced | 
					
						
							|  |  |  |             # through labels (i.e. `//packages/core:index.js`). Read more here: | 
					
						
							|  |  |  |             # https://docs.bazel.build/versions/2.0.0/skylark/rules.html#outputs | 
					
						
							|  |  |  |             # TODO: revisit once https://github.com/bazelbuild/rules_nodejs/issues/1563 is solved. | 
					
						
							| 
									
										
										
										
											2020-03-29 13:29:50 -07:00
										 |  |  |             "$$(rlocation %s)" % entry_point, | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:01 +01:00
										 |  |  |             # Madge supports custom module resolution, but expects a configuration file | 
					
						
							|  |  |  |             # similar to a Webpack configuration file setting the `resolve` option. | 
					
						
							|  |  |  |             "--webpack-config", | 
					
						
							| 
									
										
										
										
											2020-03-29 13:29:50 -07:00
										 |  |  |             "$$(rlocation $(rootpath %s))" % MADGE_CONFIG_LABEL, | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:01 +01:00
										 |  |  |         ], | 
					
						
							|  |  |  |         testonly = 1, | 
					
						
							|  |  |  |         expected_exit_code = 0, | 
					
						
							|  |  |  |         **kwargs | 
					
						
							|  |  |  |     ) |