Documentation ¶
Index ¶
- Constants
- Variables
- func GazelleWalkDir(args language.GenerateArgs, recurse bool, walkFunc filepath.WalkFunc) error
- func NewLanguage() language.Language
- type Configs
- type Configurer
- type GenerationModeType
- type ImportStatement
- type JsGazelleConfig
- func (c *JsGazelleConfig) AddExcludedPattern(pattern string)
- func (c *JsGazelleConfig) AddIgnoredImport(impGlob string)
- func (c *JsGazelleConfig) AddLibraryFileGlob(srcsFileGlob string)
- func (c *JsGazelleConfig) AddResolve(imprt string, label *label.Label)
- func (c *JsGazelleConfig) AddTestFileGlob(testsFileGlob string)
- func (c *JsGazelleConfig) GenerationEnabled() bool
- func (c *JsGazelleConfig) GenerationMode() GenerationModeType
- func (c *JsGazelleConfig) GetResolution(imprt string) *label.Label
- func (c *JsGazelleConfig) GetSourceGroups() []string
- func (c *JsGazelleConfig) IsFileExcluded(fileRelPath string) bool
- func (c *JsGazelleConfig) IsImportIgnored(impt string) bool
- func (c *JsGazelleConfig) IsSourceFile(filePath string) bool
- func (c *JsGazelleConfig) IsTestFile(filePath string) bool
- func (c *JsGazelleConfig) NewChild(childPath string) *JsGazelleConfig
- func (c *JsGazelleConfig) PnpmLockfile() string
- func (c *JsGazelleConfig) RenderNpmSourceLibraryName(npmPackageName string) string
- func (c *JsGazelleConfig) RenderTargetName(name, packageName string) string
- func (c *JsGazelleConfig) SetGenerationEnabled(enabled bool)
- func (c *JsGazelleConfig) SetGenerationMode(generationMode GenerationModeType)
- func (c *JsGazelleConfig) SetLibraryNamingConvention(libraryNamingConvention string)
- func (c *JsGazelleConfig) SetNpmPackageNamingConvention(testsNamingConvention string)
- func (c *JsGazelleConfig) SetPnpmLockfile(pnpmLockPath string)
- func (c *JsGazelleConfig) SetTestsNamingLibraryConvention(testsNamingConvention string)
- func (c *JsGazelleConfig) SetValidateImportStatements(validate bool)
- func (c *JsGazelleConfig) ValidateImportStatements() bool
- type LabelSet
- type Language
- type LinkAllPackagesImports
- type NpmPackageImports
- type Parser
- type ResolutionType
- type Resolver
- type TsProjectImports
- type TypeScript
- func (ts *TypeScript) Configure(c *config.Config, rel string, f *rule.File)
- func (ts *TypeScript) Embeds(r *rule.Rule, from label.Label) []label.Label
- func (ts *TypeScript) Fix(c *config.Config, f *rule.File)
- func (ts *TypeScript) GenerateRules(args language.GenerateArgs) language.GenerateResult
- func (ts *TypeScript) GetImportLabel(imp string) *label.Label
- func (ts *TypeScript) Imports(c *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec
- func (*TypeScript) Name() string
- func (ts *TypeScript) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, r *rule.Rule, ...)
Constants ¶
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
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 )
const ( // The filename (with any of the TS extensions) imported when importing a directory. IndexFileName = "index" NpmPackageFilename = "package.json" )
const ( TsProjectKind = "ts_project" NpmPackageKind = "npm_package" NpmLinkAllKind = "npm_link_all_packages" RulesJsRepositoryName = "aspect_rules_js" RulesTsRepositoryName = "aspect_rules_ts" NpmRepositoryName = "npm" )
const ( Resolution_Error = -1 Resolution_None = 0 Resolution_NotFound = 1 Resolution_Package = 2 Resolution_Label = 3 Resolution_NativeNode = 4 Resolution_Other = 5 )
const LanguageName = "js"
Variables ¶
var BazelLog = logrus.New()
var DefaultSourceGlobs = map[string][]string{ DefaultLibraryName: {fmt.Sprintf("**/*.{%s}", strings.Join(sourceFileExtensionsArray, ","))}, DefaultTestsName: {fmt.Sprintf("**/*.{spec,test}.{%s}", strings.Join(sourceFileExtensionsArray, ","))}, }
Functions ¶
func GazelleWalkDir ¶
Walk the directory of the language.GenerateArgs, optionally recursing into subdirectories unlike the files provided in GenerateArgs.RegularFiles.
func NewLanguage ¶
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 ¶
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 ¶
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 ¶
type Language ¶
type ResolutionType ¶
type ResolutionType = int
type 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 ¶
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 ¶
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.