gazelle

package
v1.502.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Directive_TypeScriptExtension represents the directive that controls whether
	// this TypeScript generation is enabled or not. Sub-packages inherit this value.
	// Can be either "enabled" or "disabled". Defaults to "enabled".
	Directive_TypeScriptExtension = "js"
	// Directive_GenerationMode represents the directive that controls the BUILD generation
	// mode. See below for the GenerationModeType constants.
	Directive_GenerationMode = "js_generation_mode"
	// The pnpm-lock.yaml file.
	Directive_Lockfile = "js_pnpm_lockfile"
	// Directive_IgnoreImports represents the directive that controls the
	// ignored dependencies from the generated targets.
	// Sub-packages extend this value.
	// Ignored imports may be file path globs.
	Directive_IgnoreImports = "js_ignore_imports"
	// Directive_Resolve represents a gazelle:resolve state which supports globs.
	Directive_Resolve = "js_resolve"
	// Directive_ValidateImportStatements represents the directive that controls
	// whether the TypeScript import statements should be validated.
	Directive_ValidateImportStatements = "js_validate_import_statements"
	// Directive_LibraryNamingConvention represents the directive that controls the
	// ts_project naming convention. It interpolates {dirname} with the
	// Bazel package name. E.g. if the Bazel package name is `foo`, setting this
	// to `{dirname}_my_lib` would render to `foo_my_lib`.
	Directive_LibraryNamingConvention = "js_project_naming_convention"
	// The target name for npm_package() rules. See npm_translate_lock(npm_package_target_name)
	Directive_NpmPackageNameConvention = "js_npm_package_target_name"
	// Directive_TestsNamingConvention represents the directive that controls the ts_project test
	// naming convention. See js_project_naming_convention for more info on
	// the package name interpolation.
	Directive_TestsNamingConvention = "js_tests_naming_convention"
	// The glob for the main library files, excludes files matching Directive_TestFiles.
	Directive_LibraryFiles = "js_files"
	// The glob for test files.
	Directive_TestFiles = "js_test_files"
)

Directives. Keep in sync with documentation in cli/core/docs/help/topics/directives.md

View Source
const (
	DefaultNpmLinkAllTargetName = "node_modules"
	TargetNameDirectoryVar      = "{dirname}"
	DefaultLibraryName          = TargetNameDirectoryVar
	DefaultTestsName            = TargetNameDirectoryVar + "_tests"
	NpmPackageContentName       = TargetNameDirectoryVar + "_lib"

	// The suffix added to the end of a target being wrapped in a package.
	PackageSrcSuffix = "_lib"

	// The default should align with the rules_js default npm_translate_lock(npm_package_target_name)
	DefaultNpmPackageTargetName = TargetNameDirectoryVar
)
View Source
const (
	// The filename (with any of the TS extensions) imported when importing a directory.
	IndexFileName = "index"

	NpmPackageFilename = "package.json"
)
View Source
const (
	TsProjectKind         = "ts_project"
	NpmPackageKind        = "npm_package"
	NpmLinkAllKind        = "npm_link_all_packages"
	RulesJsRepositoryName = "aspect_rules_js"
	RulesTsRepositoryName = "aspect_rules_ts"
	NpmRepositoryName     = "npm"
)
View Source
const (
	Resolution_Error      = -1
	Resolution_None       = 0
	Resolution_NotFound   = 1
	Resolution_Package    = 2
	Resolution_Label      = 3
	Resolution_NativeNode = 4
	Resolution_Other      = 5
)
View Source
const LanguageName = "js"

Variables

View Source
var BazelLog = logrus.New()
View Source
var DefaultSourceGlobs = map[string][]string{
	DefaultLibraryName: {fmt.Sprintf("**/*.{%s}", strings.Join(sourceFileExtensionsArray, ","))},
	DefaultTestsName:   {fmt.Sprintf("**/*.{spec,test}.{%s}", strings.Join(sourceFileExtensionsArray, ","))},
}

Functions

func GazelleWalkDir

func GazelleWalkDir(args language.GenerateArgs, recurse bool, walkFunc filepath.WalkFunc) error

Walk the directory of the language.GenerateArgs, optionally recursing into subdirectories unlike the files provided in GenerateArgs.RegularFiles.

func NewLanguage

func NewLanguage() language.Language

NewLanguage initializes a new TypeScript that satisfies the language.Language interface. This is the entrypoint for the extension initialization.

Types

type Configs

type Configs struct {
	Root *JsGazelleConfig
	// contains filtered or unexported fields
}

Basic struct to manage JsGazelleConfig for a collection of packages

func NewConfigs

func NewConfigs() Configs

func (*Configs) Get

func (c *Configs) Get(pkg string) *JsGazelleConfig

type Configurer

type Configurer struct {
	config.Configurer
}

Configurer satisfies the config.Configurer interface. It's the language-specific configuration extension.

func (*Configurer) CheckFlags

func (ts *Configurer) CheckFlags(fs *flag.FlagSet, c *config.Config) error

CheckFlags validates the configuration after command line flags are parsed. This is called once with the root configuration when Gazelle starts. CheckFlags may set default values in flags or make implied changes.

func (*Configurer) KnownDirectives

func (ts *Configurer) KnownDirectives() []string

KnownDirectives returns a list of directive keys that this Configurer can interpret. Gazelle prints errors for directives that are not recoginized by any Configurer.

func (*Configurer) RegisterFlags

func (ts *Configurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config)

RegisterFlags registers command-line flags used by the extension. This method is called once with the root configuration when Gazelle starts. RegisterFlags may set an initial values in Config.Exts. When flags are set, they should modify these values.

type GenerationModeType

type GenerationModeType string

GenerationModeType represents one of the generation modes.

const (
	GenerationModeNone GenerationModeType = "none"
	// GenerationModeDirectory defines the mode in which a coarse-grained target will
	// be generated for each sub-directory.
	GenerationModeDirectory GenerationModeType = "directory"
)

Generation modes

type ImportStatement

type ImportStatement struct {
	resolve.ImportSpec

	// The path of the file containing the import
	SourcePath string

	// The path as written in the import statement
	ImportPath string
}

ImportStatement represents an ImportSpec imported from a source file. Imports can be of any form (es6, cjs, amd, ...). Imports may be relative ot the source, absolute, workspace, named modules etc.

type JsGazelleConfig

type JsGazelleConfig struct {
	// contains filtered or unexported fields
}

JsGazelleConfig represents a config extension for a specific Bazel package.

func (*JsGazelleConfig) AddExcludedPattern

func (c *JsGazelleConfig) AddExcludedPattern(pattern string)

AddExcludedPattern adds a glob pattern parsed from the standard gazelle:exclude directive.

func (*JsGazelleConfig) AddIgnoredImport

func (c *JsGazelleConfig) AddIgnoredImport(impGlob string)

Adds a dependency to the list of ignored dependencies for a given package. Adding an ignored dependency to a package also makes it ignored on a subpackage.

func (*JsGazelleConfig) AddLibraryFileGlob

func (c *JsGazelleConfig) AddLibraryFileGlob(srcsFileGlob string)

AddLibraryFileGlob sets the glob used to find source files.

func (*JsGazelleConfig) AddResolve

func (c *JsGazelleConfig) AddResolve(imprt string, label *label.Label)

func (*JsGazelleConfig) AddTestFileGlob

func (c *JsGazelleConfig) AddTestFileGlob(testsFileGlob string)

AddTestFileGlob sets the glob used to find test source files.

func (*JsGazelleConfig) GenerationEnabled

func (c *JsGazelleConfig) GenerationEnabled() bool

GenerationEnabled returns whether the extension is enabled or not.

func (*JsGazelleConfig) GenerationMode

func (c *JsGazelleConfig) GenerationMode() GenerationModeType

GenerationMode returns whether coarse-grained targets should be generated or not.

func (*JsGazelleConfig) GetResolution

func (c *JsGazelleConfig) GetResolution(imprt string) *label.Label

func (*JsGazelleConfig) GetSourceGroups

func (c *JsGazelleConfig) GetSourceGroups() []string

func (*JsGazelleConfig) IsFileExcluded

func (c *JsGazelleConfig) IsFileExcluded(fileRelPath string) bool

Determine if the file path is ignored based on the current configuration.

func (*JsGazelleConfig) IsImportIgnored

func (c *JsGazelleConfig) IsImportIgnored(impt string) bool

Checks if a import is ignored in the given package or in one of the parent packages up to the workspace root.

func (*JsGazelleConfig) IsSourceFile

func (c *JsGazelleConfig) IsSourceFile(filePath string) bool

IsSourceFile determins if a given file path is considered a source file. See AddLibraryFileGlob().

func (*JsGazelleConfig) IsTestFile

func (c *JsGazelleConfig) IsTestFile(filePath string) bool

IsTestFile determins if a given file path is considered a test source file. See AddTestFileGlob().

func (*JsGazelleConfig) NewChild

func (c *JsGazelleConfig) NewChild(childPath string) *JsGazelleConfig

NewChild creates a new child JsGazelleConfig. It inherits desired values from the current JsGazelleConfig and sets itself as the parent to the child.

func (*JsGazelleConfig) PnpmLockfile

func (c *JsGazelleConfig) PnpmLockfile() string

func (*JsGazelleConfig) RenderNpmSourceLibraryName

func (c *JsGazelleConfig) RenderNpmSourceLibraryName(npmPackageName string) string

The library name when wrapped within an npm package.

func (*JsGazelleConfig) RenderTargetName

func (c *JsGazelleConfig) RenderTargetName(name, packageName string) string

renderTargetName returns the ts_project target name by performing all substitutions.

func (*JsGazelleConfig) SetGenerationEnabled

func (c *JsGazelleConfig) SetGenerationEnabled(enabled bool)

SetGenerationEnabled sets whether the extension is enabled or not.

func (*JsGazelleConfig) SetGenerationMode

func (c *JsGazelleConfig) SetGenerationMode(generationMode GenerationModeType)

SetGenerationMode sets whether coarse-grained targets should be generated or not.

func (*JsGazelleConfig) SetLibraryNamingConvention

func (c *JsGazelleConfig) SetLibraryNamingConvention(libraryNamingConvention string)

SetLibraryNamingConvention sets the ts_project target naming convention.

func (*JsGazelleConfig) SetNpmPackageNamingConvention

func (c *JsGazelleConfig) SetNpmPackageNamingConvention(testsNamingConvention string)

func (*JsGazelleConfig) SetPnpmLockfile

func (c *JsGazelleConfig) SetPnpmLockfile(pnpmLockPath string)

Set the pnpm-workspace.yaml file path.

func (*JsGazelleConfig) SetTestsNamingLibraryConvention

func (c *JsGazelleConfig) SetTestsNamingLibraryConvention(testsNamingConvention string)

SetTestsNamingLibraryConvention sets the ts_project test target naming convention.

func (*JsGazelleConfig) SetValidateImportStatements

func (c *JsGazelleConfig) SetValidateImportStatements(validate bool)

SetValidateImportStatements sets whether TypeScript import statements should be validated or not. It throws an error if this is set multiple times, i.e. if the directive is specified multiple times in the Bazel workspace.

func (*JsGazelleConfig) ValidateImportStatements

func (c *JsGazelleConfig) ValidateImportStatements() bool

ValidateImportStatements returns whether the TypeScript import statements should be validated or not. If this option was not explicitly specified by the user, it defaults to true.

type LabelSet

type LabelSet struct {
	// contains filtered or unexported fields
}

A basic set of label.Labels with logging of set modifications.

func NewLabelSet

func NewLabelSet(from label.Label) *LabelSet

func (*LabelSet) Add

func (s *LabelSet) Add(l *label.Label)

type Language

type Language struct {
	language.Language
}

func (*Language) Kinds

func (*Language) Kinds() map[string]rule.KindInfo

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.

func (*Language) Loads

func (ts *Language) Loads() []rule.LoadInfo

Loads returns .bzl files and symbols they define. Every rule generated by GenerateRules, now or in the past, should be loadable from one of these files.

type LinkAllPackagesImports

type LinkAllPackagesImports struct{}

Npm link-all rule import data

type NpmPackageImports

type NpmPackageImports struct{}

NpmPackage rule import data

type Parser

type Parser struct {
}

func NewParser

func NewParser() *Parser

func (*Parser) ParseImports

func (p *Parser) ParseImports(filePath, source string) ([]string, []error)

ParseImports returns all the imports from a file after parsing it.

type ResolutionType

type ResolutionType = int

type Resolver

type Resolver struct {
	resolve.Resolver
}

Resolver satisfies the resolve.Resolver interface. It resolves dependencies in rules generated by this extension.

type TsProjectImports

type TsProjectImports struct {
	// contains filtered or unexported fields
}

TsProject rule import data

func (*TsProjectImports) Add

func (i *TsProjectImports) Add(impt ImportStatement)

type TypeScript

type TypeScript struct {
	Configurer
	Resolver
	Language
	// contains filtered or unexported fields
}

The Gazelle extension for TypeScript rules. TypeScript satisfies the language.Language interface including the Configurer and Resolver types.

func (*TypeScript) Configure

func (ts *TypeScript) Configure(c *config.Config, rel string, f *rule.File)

Configure modifies the configuration using directives and other information extracted from a build file. Configure is called in each directory.

c is the configuration for the current directory. It starts out as a copy of the configuration for the parent directory.

rel is the slash-separated relative path from the repository root to the current directory. It is "" for the root directory itself.

f is the build file for the current directory or nil if there is no existing build file.

func (*TypeScript) Embeds

func (ts *TypeScript) Embeds(r *rule.Rule, from label.Label) []label.Label

Embeds returns a list of labels of rules that the given rule embeds. If a rule is embedded by another importable rule of the same language, only the embedding rule will be indexed. The embedding rule will inherit the imports of the embedded rule.

func (*TypeScript) Fix

func (ts *TypeScript) Fix(c *config.Config, f *rule.File)

Fix repairs deprecated usage of language-specific rules in f. This is called before the file is indexed. Unless c.ShouldFix is true, fixes that delete or rename rules should not be performed.

func (*TypeScript) GenerateRules

func (ts *TypeScript) GenerateRules(args language.GenerateArgs) language.GenerateResult

GenerateRules extracts build metadata from source files in a directory. GenerateRules is called in each directory where an update is requested in depth-first post-order.

func (*TypeScript) GetImportLabel

func (ts *TypeScript) GetImportLabel(imp string) *label.Label

func (*TypeScript) Imports

func (ts *TypeScript) Imports(c *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec

Determine what rule (r) outputs which can be imported. For TypeScript this is all the import-paths pointing to files within the rule.

func (*TypeScript) Name

func (*TypeScript) Name() string

Name returns the name of the language. This is the prefix of the kinds of rules generated. E.g. ts_project

func (*TypeScript) Resolve

func (ts *TypeScript) Resolve(
	c *config.Config,
	ix *resolve.RuleIndex,
	rc *repo.RemoteCache,
	r *rule.Rule,
	importData interface{},
	from label.Label,
)

Resolve translates imported libraries for a given rule into Bazel dependencies. Information about imported libraries is returned for each rule generated by language.GenerateRules in language.GenerateResult.Imports. Resolve generates a "deps" attribute (or the appropriate language-specific equivalent) for each import according to language-specific rules and heuristics.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL