Skip to content

Commit

Permalink
chore(bazel): Migrate to aspect rules #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ElijahKotyluk authored Oct 23, 2022
1 parent 469645e commit 1bf8163
Show file tree
Hide file tree
Showing 44 changed files with 6,897 additions and 5,464 deletions.
9 changes: 7 additions & 2 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
node_modules
dist
bazel-out
bazel-out

node_modules

packages/core/node_modules
packages/matchers/node_modules
packages/mock/node_modules
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.2
5.3.1
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
dist
bazel-*
41 changes: 41 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
env: {
node: true,
jest: true,
},
extends: [
'eslint:recommended',
],
parserOptions: {
project: './tsconfig.eslint.json',
tsconfigRootDir: __dirname,
schema: [],
},
overrides: [
{
files: ['*.ts'],
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
rules: {
"@typescript-eslint/no-namespace": "off"
}
},
],
settings: {
jsdoc: {
mode: 'typescript'
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx']
},
'import/resolver': {
'typescript': {}
}
},
rules: {
"@typescript-eslint/no-namespace": "off"
}
}
63 changes: 0 additions & 63 deletions .eslintrc.json

This file was deleted.

46 changes: 38 additions & 8 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,53 @@ on: # rebuild any PRs and main branch changes
- '**'

jobs:
format: # make sure files are linted and formatted correctly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pnpm/[email protected]
with:
version: 7

- name: Install dependencies
run: pnpm install

- name: Lint Bazel
run: pnpm bazel:lint

- name: Lint JavaScript && TypeScript
run: pnpm lint

build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn
- uses: pnpm/[email protected]
with:
version: 7

- name: Install dependencies
run: pnpm install

- name: Test package
run: yarn bazel:test
run: pnpm bazel:test

- name: Build package
run: yarn bazel:build
run: pnpm bazel:build

test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn
- uses: pnpm/[email protected]
with:
version: 7

- name: Install dependencies
run: pnpm install

- name: Test package
run: yarn bazel:test
run: pnpm bazel:test

- name: Build package
run: yarn bazel:build
run: pnpm bazel:build
30 changes: 25 additions & 5 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
exports_files(
[
"tsconfig.json",
"jest.config.js",
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
load("@npm//:defs.bzl", "npm_link_all_packages")

package(default_visibility = ["//visibility:public"])

npm_link_all_packages(name = "node_modules")

exports_files([
"tsconfig.json",
"tsconfig.eslint.json",
".eslintrc.js",
".eslintignore",
])

ts_config(
name = "tsconfig",
src = "tsconfig.json",
)

ts_project(
name = "jest_config",
srcs = ["jest.config.ts"],
tsconfig = {},
deps = [
"//:node_modules/@jest/types",
],
visibility = ["//:__subpackages__"],
)
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Elijah Kotyluk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
WIP
# Usage

## Setup

```bash
# Install dependencies
pnpm setup:deps

# Build all packages
bazel build //...

# Build target package
bazel build //packages/<package_name>

# Test all packages
bazel test //...

# Test target package
bazel test //packages/<package_name>

# Lint *.bazel files
pnpm bazel:lint

# Lint && Fix *.bazel files
pnpm bazel:lint-fix

# Lint JavaScript && TypeScript files
pnpm lint

# Lint && Fix JavaScript && TypeScript files
pnpm lint:fix
```
40 changes: 29 additions & 11 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,39 @@ workspace(
)

load("//tools:deps.bzl", "fetch_build_bazel_rules_nodejs")

fetch_build_bazel_rules_nodejs()

load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@aspect_rules_ts//ts:repositories.bzl", "LATEST_VERSION", "rules_ts_dependencies")

rules_ts_dependencies(ts_version = LATEST_VERSION)

load("@aspect_rules_jest//jest:repositories.bzl", "jest_repositories", JEST_LATEST_VERSION = "LATEST_VERSION")

build_bazel_rules_nodejs_dependencies()
jest_repositories(
name = "jest",
jest_version = JEST_LATEST_VERSION,
)

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

# The yarn_install rule runs yarn anytime the package.json or yarn.lock file changes.
# It also extracts any Bazel rules distributed in an npm package.
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
nodejs_register_toolchains(
name = "nodejs",
node_version = DEFAULT_NODE_VERSION,
)

node_repositories(package_json = ["//:package.json"])
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")

yarn_install(
name = "npm", # Name this "npm" so that Bazel Label references look like @npm//package
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
symlink_node_modules = True,
npm_translate_lock(
name = "npm",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm//:repositories.bzl", "npm_repositories")

npm_repositories()
4 changes: 0 additions & 4 deletions jest.config.js

This file was deleted.

12 changes: 12 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Config } from "@jest/types"

const config: Config.InitialOptions = {
moduleFileExtensions: ['ts', 'js'],
preset: "ts-jest",
testMatch: [
"**/*.spec.js",
"**/*.spec.ts"
],
}

export default config
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,33 @@
"private": true,
"workspaces": {
"packages": [
"./packages/*"
"./packages/*"
]
},
},
"scripts": {
"bazel:format": "find . -type f \\( -name \"*.bzl\" -or -name WORKSPACE -or -name BUILD -or -name BUILD.bazel \\) ! -path \"*/node_modules/*\" | xargs buildifier -v --warnings=attr-cfg,attr-license,attr-non-empty,attr-output-default,attr-single-file,constant-glob,ctx-actions,ctx-args,depset-iteration,depset-union,dict-concatenation,duplicated-name,filetype,git-repository,http-archive,integer-division,load,load-on-top,native-build,native-package,out-of-order-load,output-group,package-name,package-on-top,positional-args,redefined-variable,repository-name,same-origin-load,string-iteration,unsorted-dict-items,unused-variable",
"bazel:lint": "yarn bazel:format --lint=warn",
"bazel:lint-fix": "yarn bazel:format --lint=fix",
"bazel:format": "find . -type f \\( -name \"*.bazel\" -or -name WORKSPACE -or -name BUILD -or -name BUILD.bazel \\) ! -path \"*/node_modules/*\" | xargs buildifier -v --warnings=attr-cfg,attr-license,attr-non-empty,attr-output-default,attr-single-file,constant-glob,ctx-actions,ctx-args,depset-iteration,depset-union,dict-concatenation,duplicated-name,filetype,git-repository,http-archive,integer-division,load,load-on-top,native-build,native-package,out-of-order-load,output-group,package-name,package-on-top,positional-args,redefined-variable,repository-name,same-origin-load,string-iteration,unsorted-dict-items,unused-variable",
"bazel:lint": "pnpm bazel:format --lint=warn",
"bazel:lint-fix": "pnpm bazel:format --lint=fix",
"bazel:build": "bazel build //...",
"bazel:test": "bazel test //...",
"lint": "eslint . --ignore-path .eslintignore --ext ts --ext js",
"lint:fix": "eslint . --ignore-path .eslintignore --ext ts --ext js --fix",
"lint": "eslint . -c ./.eslintrc.js --ignore-path .eslintignore --ext ts --ext js",
"lint:fix": "eslint . -c ./.eslintrc.js --ignore-path .eslintignore --ext ts --ext js --fix",
"test": "jest -c jest.config.js",
"build": "tsc"
"setup:deps": "bazel run -- @pnpm//:pnpm -C $PWD i"
},
"devDependencies": {
"@bazel/bazelisk": "latest",
"@bazel/buildifier": "latest",
"@bazel/ibazel": "latest",
"@bazel/typescript": "latest",
"@types/jest": "^27.0.0",
"@typescript-eslint/eslint-plugin": "^4.29.1",
"@typescript-eslint/parser": "^4.29.1",
"eslint": "^7.32.0",
"@jest/types": "^29.2.1",
"@types/jest": "^27.5.2",
"@types/node": "^18.11.3",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"eslint": "^8.26.0",
"husky": "^7.0.1",
"jest": "^27.0.6",
"jest": "^27.5.1",
"jest-cli": "^28.0.1",
"lint-staged": "^11.1.2",
"ts-jest": "^27.0.4",
"typescript": "^4.3.5"
Expand Down
Loading

0 comments on commit 1bf8163

Please sign in to comment.