Skip to main content

Configuring Bazel

See the aspect configure command, which generates new BUILD files and updates existing ones to reflect the dependencies and structure of the code.

JavaScript / TypeScript

You can expect the following behavior when running aspect configure in a project with JS code:

TypeScript source files are those ending in .ts, .tsx as well as .js, .mjs. Test source files are source files ending with .spec.ts (and other ts extensions). The test file pattern can be configured with Aspect directives.

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

Each BUILD file may have ts_project rules for sources as well as one for tests, a npm_package rule for pnpm workspace projects, and npm_link_all_packages for linking node_modules. Which rules are configured depends on the source files and potentially how aspect configure has been configured.

Next, all source files are collected into the srcs of the ts_project, either the primary rule or tests rule.

Finally, the import statements in the source files are parsed, and dependencies are added to the deps attribute of the appropriate ts_project rule which the source file belongs to.

Dependencies may also be found other ways such as from the CommonJS require function.

If a package.json file exists declaring npm dependencies, a npm_link_all_packages rule is generated for declaring depending on individual NPM packages.

If the package.json is a pnpm workspace project a npm_package rule may be generated to enable other projects to declare dependencies on the package.