-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add js_rule_kind directive for per-group rule kind override #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -484,7 +484,11 @@ func hasTranspiledSources(sourceFiles *treeset.Set[string]) bool { | |
|
|
||
| func (ts *typeScriptLang) addProjectRule(cfg *JsGazelleConfig, tsconfigRel string, tsconfig *typescript.TsConfig, args language.GenerateArgs, group *TargetGroup, targetName string, sourceFiles, genFiles, dataFiles []string, result *language.GenerateResult) (*rule.Rule, error) { | ||
| // Check for name-collisions with the rule being generated. | ||
| colError := ruleUtils.CheckCollisionErrors(targetName, TsProjectKind, sourceRuleKinds, args) | ||
| expectedKind := TsProjectKind | ||
| if group.ruleKind != "" { | ||
| expectedKind = group.ruleKind | ||
| } | ||
| colError := ruleUtils.CheckCollisionErrors(targetName, expectedKind, sourceRuleKinds, args) | ||
| if colError != nil { | ||
|
Comment on lines
485
to
492
|
||
| return nil, fmt.Errorf("%v "+ | ||
| "Use the '# aspect:%s' directive to change the naming convention.\n\n"+ | ||
|
|
@@ -569,9 +573,14 @@ func (ts *typeScriptLang) addProjectRule(cfg *JsGazelleConfig, tsconfigRel strin | |
| // A rule of the same name might already exist | ||
| existing := ruleUtils.GetFileRuleByName(args, targetName) | ||
|
|
||
| ruleKind := TsProjectKind | ||
| defaultKind := TsProjectKind | ||
| if !hasTranspiledSources(info.sources) { | ||
| ruleKind = JsLibraryKind | ||
| defaultKind = JsLibraryKind | ||
| } | ||
|
|
||
| ruleKind := defaultKind | ||
| if group.ruleKind != "" { | ||
| ruleKind = group.ruleKind | ||
| } | ||
| sourceRule := rule.NewRule(ruleKind, targetName) | ||
|
|
||
|
|
@@ -604,7 +613,7 @@ func (ts *typeScriptLang) addProjectRule(cfg *JsGazelleConfig, tsconfigRel strin | |
| sourceRule.DelAttr("assets") | ||
| } | ||
|
|
||
| if group.testonly { | ||
| if group.testonly && ruleKind != JsTestKind { | ||
| sourceRule.SetAttr("testonly", true) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ const ( | |
| TsProjectKind = "ts_project" | ||
| TsProtoLibraryKind = "ts_proto_library" | ||
| JsLibraryKind = "js_library" | ||
| JsTestKind = "js_test" | ||
| JsBinaryKind = "js_binary" | ||
| JsRunBinaryKind = "js_run_binary" | ||
| TsConfigKind = "ts_config" | ||
|
|
@@ -23,7 +24,7 @@ const ( | |
| NpmRepositoryName = "npm" | ||
| ) | ||
|
|
||
| var sourceRuleKinds = treeset.NewWith(strings.Compare, TsProjectKind, JsLibraryKind, TsProtoLibraryKind) | ||
| var sourceRuleKinds = treeset.NewWith(strings.Compare, TsProjectKind, JsLibraryKind, JsTestKind, TsProtoLibraryKind) | ||
|
|
||
| // Kinds returns a map that maps rule names (kinds) and information on how to | ||
| // match and merge attributes that may be found in rules of those kinds. | ||
|
|
@@ -78,6 +79,19 @@ var tsKinds = map[string]rule.KindInfo{ | |
| "deps": true, | ||
| }, | ||
| }, | ||
| JsTestKind: { | ||
| MatchAny: false, | ||
| NonEmptyAttrs: map[string]bool{ | ||
| "srcs": true, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this incorrect?
|
||
| }, | ||
| SubstituteAttrs: map[string]bool{}, | ||
| MergeableAttrs: map[string]bool{ | ||
| "srcs": true, | ||
| }, | ||
| ResolveAttrs: map[string]bool{ | ||
| "deps": true, | ||
| }, | ||
| }, | ||
| JsBinaryKind: { | ||
| MatchAny: false, | ||
| NonEmptyAttrs: map[string]bool{ | ||
|
|
@@ -183,7 +197,7 @@ func (h *typeScriptLang) ApparentLoads(moduleToApparentName func(string) string) | |
| { | ||
| Name: "@" + jsModName + "//js:defs.bzl", | ||
| Symbols: []string{ | ||
| JsLibraryKind, JsBinaryKind, JsRunBinaryKind, | ||
| JsLibraryKind, JsTestKind, JsBinaryKind, JsRunBinaryKind, | ||
| }, | ||
| }, | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # gazelle:js_test_files e2e *.e2e.ts | ||
| # gazelle:js_rule_kind e2e js_test | ||
| # gazelle:map_kind js_test jest_test //:defs.bzl |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| load("@aspect_rules_ts//ts:defs.bzl", "ts_project") | ||
| load("//:defs.bzl", "jest_test") | ||
|
|
||
| # gazelle:js_test_files e2e *.e2e.ts | ||
| # gazelle:js_rule_kind e2e js_test | ||
| # gazelle:map_kind js_test jest_test //:defs.bzl | ||
|
|
||
| ts_project( | ||
| name = "rule_kind_custom_group", | ||
| srcs = ["main.ts"], | ||
| ) | ||
|
|
||
| ts_project( | ||
| name = "rule_kind_custom_group_tests", | ||
| testonly = True, | ||
| srcs = ["main.spec.ts"], | ||
| deps = [":rule_kind_custom_group"], | ||
| ) | ||
|
|
||
| jest_test( | ||
| name = "e2e", | ||
| srcs = ["main.e2e.ts"], | ||
| deps = [":rule_kind_custom_group"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # This is a Bazel workspace for the Gazelle test data. | ||
| workspace(name = "rule_kind_custom_group") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { A } from './main'; | ||
|
|
||
| console.log('e2e', A); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { A } from './main'; | ||
|
|
||
| console.log(A); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const A = 'hello'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # gazelle:js_rule_kind {dirname}_tests js_test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| load("@aspect_rules_js//js:defs.bzl", "js_test") | ||
| load("@aspect_rules_ts//ts:defs.bzl", "ts_project") | ||
|
|
||
| # gazelle:js_rule_kind {dirname}_tests js_test | ||
|
|
||
| ts_project( | ||
| name = "rule_kind_override", | ||
| srcs = ["main.ts"], | ||
| ) | ||
|
|
||
| js_test( | ||
| name = "rule_kind_override_tests", | ||
| srcs = ["main.spec.ts"], | ||
| deps = [":rule_kind_override"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # This is a Bazel workspace for the Gazelle test data. | ||
| workspace(name = "rule_kind_override") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { A } from './main'; | ||
|
|
||
| console.log(A); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const A = 'hello'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| load("@aspect_rules_js//js:defs.bzl", "js_test") | ||
| load("@aspect_rules_ts//ts:defs.bzl", "ts_project") | ||
|
|
||
| ts_project( | ||
| name = "sub", | ||
| srcs = ["lib.ts"], | ||
| ) | ||
|
|
||
| js_test( | ||
| name = "sub_tests", | ||
| srcs = ["lib.spec.ts"], | ||
| deps = [":sub"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { B } from './lib'; | ||
|
|
||
| console.log(B); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const B = 'world'; |
Uh oh!
There was an error while loading. Please reload this page.