Skip to content
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

process: sync commits from Aspect-internal silo #749

Merged
merged 35 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
94a6775
fix(cli): tsconfig paths extending from parent dir (#6505)
jbedard Aug 23, 2024
246f593
build: upgrade deps
jbedard Sep 27, 2024
5b35254
refactor(cli): remove parser interface with single implementation (#6…
jbedard Aug 23, 2024
707ca6f
docs: update docs/aspect_lint.md
jbedard Sep 27, 2024
1c00c1e
build: upgrade bazel to 7.3.1
jbedard Sep 27, 2024
50fdedd
build: fix references to cli/core
jbedard Sep 27, 2024
8e5180b
feat(cli): add js_npm_package to opt-out of package generation (#6422)
jbedard Aug 23, 2024
80d7391
fix: use non-cancellable context for reading lint results (#6555)
gregmagolan Aug 26, 2024
3b3d8cc
fix(lint): Handle '--' properly (#6548)
JesseTatasciore Aug 26, 2024
61e14ba
fix(cli): passthru configure cli arguments to gazelle (#6566)
jbedard Aug 27, 2024
059961c
fix(cli): do not spam stdout when extending non-existing tsconfig (#6…
jbedard Aug 27, 2024
8877cec
fix: wait for BES completion event before reading lint results files …
gregmagolan Aug 28, 2024
6c05502
fix: lint fixes for 5.11 release (#6585)
gregmagolan Aug 28, 2024
32964a1
chore: upgrade gazelle to head@2d6805c8b74e (#6471)
jbedard Aug 28, 2024
5ffd14e
fix(cli): support {cjs,mjs} imports (#6596)
jbedard Aug 28, 2024
026bfe5
fix: use rules_lint_machine output group since rules_lint_report is d…
gregmagolan Aug 29, 2024
f8b32eb
chore(deps): upgrade Go sdk to 1.23 (#6628)
alexeagle Sep 3, 2024
7a51098
feat(lint): Show human readable output by default (#6625)
JesseTatasciore Sep 3, 2024
8c6b5d6
fix(cli): remove unnecessary warning log (#6623)
jbedard Sep 4, 2024
ec61f31
perf(cli): run starzelle queries in parallel (#6624)
jbedard Sep 4, 2024
df89555
test(cli): add tsconfig test extending named import with lockfile in …
jbedard Sep 9, 2024
392b09f
refactor(cli): remove support for non-patched gazelle library (#6645)
jbedard Sep 11, 2024
979f09a
fix(cli): normalize all starzelle attribute label values (#6693)
jbedard Sep 12, 2024
dcf8700
feat(cli): replace js_generation_mode with generic generation_mode sh…
jbedard Sep 13, 2024
36eaec2
refactor(cli): ignore empty and comment .gitignore lines (#6728)
jbedard Sep 13, 2024
482c522
chore(cli): upgrade gazelle to HEAD@089096315dca (#6729)
jbedard Sep 13, 2024
2a83c08
chore(deps): update dependency aspect_bazel_lib to v2.8.1 (#6789)
renovate[bot] Sep 17, 2024
cb7d3d3
feat(cli): support package.json main,exports (#6809)
jbedard Sep 17, 2024
6485e37
chore: Run pnpm upgrade (#6804)
mrmeku Sep 18, 2024
035949c
test(cli): fix gazelle test snapshot updating (#6794)
jbedard Sep 19, 2024
ad58bb2
feat(cli): add starzelle builtin rules for sh_*, filegroup (#6852)
jbedard Sep 19, 2024
b1c15de
fix(cli): support package.json exports object (#6855)
jbedard Sep 20, 2024
fe86591
refactor(cli): align aspect configure gitignore feature with proposed…
jbedard Sep 24, 2024
bad5d9d
fix: disable python extension on windows (#6879)
thesayyn Sep 26, 2024
bcd669b
fix(cli): support js_ignore_imports for package.json imports (#6926)
jbedard Sep 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.2.1
7.3.1
11 changes: 8 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,15 @@ http_archive(
patches = [
"//:patches/bazelbuild_bazel-gazelle_aspect-cli.patch",
"//:patches/bazelbuild_bazel-gazelle_aspect-walk-subdir.patch",
"//:patches/bazelbuild_bazel-gazelle_aspect-gitignore.patch",
],
sha256 = "c6c87f08f3534612da5e1250c5f4dc7b8c0135b22f102fc6d1bfa76f3bdbd1fa",
strip_prefix = "bazel-gazelle-2d6805c8b74e44add398c5c70279648b36c11d58",
urls = ["https://github.com/bazelbuild/bazel-gazelle/archive/2d6805c8b74e44add398c5c70279648b36c11d58.tar.gz"],
sha256 = "872f1532567cdc53dc8e9f4681cd45021cd6787e2bde8a022bcec24a5867ce4c",
# Ensure this version always matches the go.mod version.
#
# :notice: Care should be taken when upgrading gazelle since we have vendored & modified parts of gazelle
# in the CLI configure command (pkg/aspect/configure).
strip_prefix = "bazel-gazelle-571d953b2bb9534c145242ead08eb35b3b096a5e",
urls = ["https://github.com/bazelbuild/bazel-gazelle/archive/571d953b2bb9534c145242ead08eb35b3b096a5e.tar.gz"],
)

http_archive(
Expand Down
19 changes: 0 additions & 19 deletions bazel/BUILD.bazel

This file was deleted.

61 changes: 60 additions & 1 deletion bazel/ts/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,67 @@
"""
Defaults for Typescript projects in aspect-cli
Defaults for Typescript projects in Silo
"""

load("@aspect_rules_swc//swc:defs.bzl", _swc = "swc")
load("@aspect_rules_ts//ts:defs.bzl", _ts_config = "ts_config", _ts_project = "ts_project")
load("@aspect_rules_ts//ts:proto.bzl", _ts_proto_library = "ts_proto_library")
load("@bazel_skylib//lib:partial.bzl", "partial")
load("@bazel_skylib//rules:write_file.bzl", _write_file = "write_file")

ts_config = _ts_config

def ts_project(name, module_type = "commonjs", **kwargs):
"""Macro around ts_project for silo.

Args:
name: Name of the ts_project target
module_type: Type of module swc should transpile to
**kwargs: Additional attributes to pass to the ts_project rule
"""
swcrc = ".swcrc_%s" % name
_write_file(
name = "swcrc_%s" % name,
out = swcrc,
content = json.encode({
"inlineSourcesContent": True,
"jsc": {
"keepClassNames": True,
"parser": {
"decorators": True,
"decoratorsBeforeExport": False,
"dynamicImport": True,
"syntax": "typescript",
},
"transform": {
"decoratorMetadata": True,
"legacyDecorator": True,
"react": {
"runtime": "automatic",
},
},
},
"module": {
"type": module_type,
},
"sourceMaps": True,
}).splitlines(),
)

tsconfig = kwargs.pop("tsconfig", "//bazel/ts:tsconfig.node")

_ts_project(
name = name,
declaration = True,
source_map = True,
tsconfig = {"include": ["**/*.{ts,tsx}"]},
extends = tsconfig,
transpiler = partial.make(
_swc,
source_maps = "true",
swcrc = swcrc,
),
**kwargs
)

def ts_proto_library(name, protoc_gen_options = {
"js_import_style": "legacy_commonjs",
Expand Down
4 changes: 2 additions & 2 deletions docs/help/topics/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Test source files are source files ending with `.spec.ts` (and other ts extensio
The test file pattern can be configured with the 'js*test*\*' directives.

By default `aspect configure` creates new BUILD files for each directory containing source files.
This can be configured to only edit existing BUILD files using the `js_generation_mode` directive.
This can be configured to only edit existing BUILD files using the `generation_mode` directive.

Each BUILD file may have a `ts_project` rule for sources, another for tests,
a `npm_package` rule for pnpm workspace projects, and `npm_link_all_packages` for linking node_modules.
Expand Down Expand Up @@ -83,7 +83,7 @@ enable other projects to declare dependencies on the package.
| Equivalent to `js_files` but for the test `ts_project` rule. |
| `# gazelle:js_npm_package_target_name _name_` | `{dirname}` |
| The format used to generate the name of the `npm_package` rule. |
| `# gazelle:js_generation_mode none\|directory` | `directory` |
| `# gazelle:generation_mode update\|create` | `create` |
| DEPRECATED: see `generation_mode` directive. |
| `# gazelle:js_custom_files _name_ _glob_` | |
| DEPRECATED:Generate additional custom `ts_project` targets |
Expand Down
3 changes: 1 addition & 2 deletions gazelle/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go_library(
srcs = [
"bazel.go",
"directives.go",
"excludes.go",
"regex.go",
"rules.go",
"set.go",
Expand All @@ -19,7 +18,7 @@ go_library(
"@bazel_gazelle//label:go_default_library",
"@bazel_gazelle//language:go_default_library",
"@bazel_gazelle//rule:go_default_library",
"@bazel_gazelle//walk:go_default_library",
"@com_github_emirpasic_gods//sets/treeset",
"@com_github_emirpasic_gods//utils",
],
)
3 changes: 0 additions & 3 deletions gazelle/common/directives.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ type GenerationModeType string

// Generation modes
const (
// None: do not update or create any BUILD files
GenerationModeNone GenerationModeType = "none"

// Update: update and maintain existing BUILD files
GenerationModeUpdate GenerationModeType = "update"

Expand Down
33 changes: 0 additions & 33 deletions gazelle/common/excludes.go

This file was deleted.

1 change: 1 addition & 0 deletions gazelle/common/git/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ go_test(
name = "git_test",
srcs = ["gitignore_test.go"],
embed = [":git"],
deps = ["@bazel_gazelle//config:go_default_library"],
)
120 changes: 70 additions & 50 deletions gazelle/common/git/gitignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,99 @@ import (
gitignore "github.com/go-git/go-git/v5/plumbing/format/gitignore"
)

// Wrap the ignore files along with the relative path they were loaded from
// to enable quick-exit checks.
type ignoreEntry struct {
i gitignore.Matcher
base string
}
// Must align with patched bazel-gazelle
const ASPECT_GITIGNORE = "__aspect:gitignore"

type GitIgnore struct {
ignores []ignoreEntry
}
// Directive to enable/disable gitignore support
const Directive_GitIgnore = "gitignore"

// Internal
const enabledExt = Directive_GitIgnore
const lastConfiguredExt = "gitignore:dir"
const ignorePatternsExt = "gitignore:patterns"

func NewGitIgnore() *GitIgnore {
return &GitIgnore{
ignores: make([]ignoreEntry, 0),
func CollectIgnoreFiles(c *config.Config, rel string) {
// Only parse once per directory.
if lastCollected, hasCollected := c.Exts[lastConfiguredExt]; hasCollected && lastCollected == rel {
return
}
}
c.Exts[lastConfiguredExt] = rel

func (i *GitIgnore) CollectIgnoreFiles(c *config.Config, rel string) {
// Collect gitignore style ignore files in this directory.
// Find and add .gitignore files from this directory
ignoreFilePath := path.Join(c.RepoRoot, rel, ".gitignore")

if ignoreReader, ignoreErr := os.Open(ignoreFilePath); ignoreErr == nil {
ignoreReader, ignoreErr := os.Open(ignoreFilePath)
if ignoreErr == nil {
BazelLog.Tracef("Add ignore file %s/.gitignore", rel)
defer ignoreReader.Close()
addIgnore(c, rel, ignoreReader)
} else if !os.IsNotExist(ignoreErr) {
BazelLog.Errorf("Failed to open %s/.gitignore: %v", rel, ignoreErr)
}
}

i.addIgnore(rel, ignoreReader)
func EnableGitignore(c *config.Config, enabled bool) {
c.Exts[enabledExt] = enabled
if enabled {
c.Exts[ASPECT_GITIGNORE] = createMatcherFunc(c)
} else {
c.Exts[ASPECT_GITIGNORE] = nil
}
}

func (i *GitIgnore) addIgnore(rel string, ignoreReader io.Reader) {
// Persist a relative path to the ignore file to enable quick-exit checks.
base := path.Clean(rel)
if base == "." {
base = ""
func isEnabled(c *config.Config) bool {
enabled, hasEnabled := c.Exts[enabledExt]
return hasEnabled && enabled.(bool)
}

func addIgnore(c *config.Config, rel string, ignoreReader io.Reader) {
var ignorePatterns []gitignore.Pattern

// Load parent ignore patterns
if c.Exts[ignorePatternsExt] != nil {
ignorePatterns = c.Exts[ignorePatternsExt].([]gitignore.Pattern)
}

domain := []string{}
if base != "" {
domain = strings.Split(base, "/")
// Append new ignore patterns
ignorePatterns = append(ignorePatterns, parseIgnore(rel, ignoreReader)...)

// Persist appended ignore patterns
c.Exts[ignorePatternsExt] = ignorePatterns

// Persist a matcher function with the updated ignore patterns if enabled
if isEnabled(c) {
c.Exts[ASPECT_GITIGNORE] = createMatcherFunc(c)
}
}

func parseIgnore(rel string, ignoreReader io.Reader) []gitignore.Pattern {
var domain []string
if rel != "" {
domain = strings.Split(path.Clean(rel), "/")
}

matcherPatterns := make([]gitignore.Pattern, 0)

reader := bufio.NewScanner(ignoreReader)
for reader.Scan() {
p := gitignore.ParsePattern(reader.Text(), domain)
matcherPatterns = append(matcherPatterns, p)
}

ignore := gitignore.NewMatcher(matcherPatterns)
p := strings.TrimSpace(reader.Text())
if p == "" || strings.HasPrefix(p, "#") {
continue
}

// Add a trailing slash to the base path to ensure the ignore file only
// processes paths within that directory.
if base != "" && !strings.HasSuffix(base, "/") {
base += "/"
matcherPatterns = append(matcherPatterns, gitignore.ParsePattern(p, domain))
}

i.ignores = append(i.ignores, ignoreEntry{
i: ignore,
base: base,
})
return matcherPatterns
}

func (i *GitIgnore) Matches(p string) bool {
for _, ignore := range i.ignores {
// Ensure the path is within the base path of the ignore file
// to avoid strings.Split unless necessary.
if !strings.HasPrefix(p, ignore.base) {
continue
}
if ignore.i.Match(strings.Split(p, "/"), false) {
return true
}
func createMatcherFunc(c *config.Config) func(string) bool {
patterns, patternsFound := c.Exts[ignorePatternsExt]
if !patternsFound {
return nil
}

return false
matcher := gitignore.NewMatcher(patterns.([]gitignore.Pattern))
return func(s string) bool {
return matcher.Match(strings.Split(s, "/"), false)
}
}
Loading
Loading