├── .bazelignore ├── .bazelrc ├── .bazelversion ├── .bcr ├── config.yml ├── metadata.template.json ├── presubmit.yml └── source.template.json ├── .github └── workflows │ ├── ci.yaml │ ├── release.yml │ └── workspace_snippet.sh ├── .gitignore ├── BUILD ├── LICENSE ├── MODULE.bazel ├── README.md ├── WORKSPACE ├── WORKSPACE.bzlmod ├── defs.bzl ├── deps.bzl ├── examples └── nextjs │ ├── .bazelignore │ ├── .bazelrc │ ├── .bazelversion │ ├── .eslintrc.json │ ├── .gitignore │ ├── .npmrc │ ├── .swcrc │ ├── BUILD.bazel │ ├── MODULE.bazel │ ├── README.md │ ├── WORKSPACE │ ├── WORKSPACE.bzlmod │ ├── apps │ └── alpha │ │ ├── BUILD.bazel │ │ ├── build_smoke_test.js │ │ ├── jest.config.js │ │ ├── next-env.d.ts │ │ ├── next.config.js │ │ ├── package.json │ │ ├── pages │ │ ├── BUILD.bazel │ │ ├── __snapshots__ │ │ │ └── index.test.tsx.snap │ │ ├── _app.tsx │ │ ├── api │ │ │ ├── BUILD.bazel │ │ │ └── hello.ts │ │ ├── index.test.tsx │ │ └── index.tsx │ │ ├── public │ │ ├── BUILD.bazel │ │ ├── favicon.ico │ │ └── vercel.svg │ │ └── styles │ │ ├── BUILD.bazel │ │ ├── Home.module.css │ │ └── globals.css │ ├── bazel │ ├── BUILD.bazel │ ├── jest_test.bzl │ ├── next.bzl │ ├── ts_project.bzl │ └── web_assets.bzl │ ├── package.json │ ├── packages │ └── one │ │ ├── BUILD.bazel │ │ ├── package.json │ │ └── src │ │ └── main.ts │ ├── pnpm-lock.yaml │ ├── pnpm-workspace.yaml │ └── tsconfig.json ├── gazelle ├── BUILD ├── colors.go ├── configure.go ├── generate.go ├── generate_test.go ├── kinds.go ├── lang.go ├── parse.go ├── parse_test.go ├── pkgname.go ├── pkgname_test.go └── resolve.go ├── go.mod ├── go.sum ├── internal ├── BUILD └── web_assets.bzl └── tests ├── BUILD ├── collect_all ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── index.ts ├── jest.config.js ├── my_module │ ├── BUILD.in │ ├── BUILD.out │ ├── index.ts │ ├── module_file.ts │ ├── nested_module │ │ ├── a.test.ts │ │ ├── b.test.ts │ │ ├── index.ts │ │ └── module_file.ts │ └── some_other_file.ts └── some_other_file.ts ├── collect_all_nested ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── index.ts ├── jest.config.js ├── my_module │ ├── BUILD.in │ ├── BUILD.out │ ├── index.ts │ ├── module_file.ts │ ├── nested_module │ │ ├── a.test.ts │ │ ├── b.test.ts │ │ ├── double_nested_module │ │ │ ├── BUILD.in │ │ │ ├── BUILD.out │ │ │ ├── a.test.ts │ │ │ ├── b.test.ts │ │ │ ├── index.ts │ │ │ └── module_file.ts │ │ ├── index.ts │ │ └── module_file.ts │ └── some_other_file.ts └── some_other_file.ts ├── collect_all_test_shards ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── index.ts ├── jest.config.js ├── my_module │ ├── BUILD.in │ ├── BUILD.out │ ├── index.ts │ ├── module_file.ts │ ├── nested_module │ │ ├── a.test.ts │ │ ├── b.test.ts │ │ ├── index.ts │ │ └── module_file.ts │ └── some_other_file.ts └── some_other_file.ts ├── collect_asset_modules ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a │ ├── BUILD.in │ ├── BUILD.out │ ├── data.json │ └── style.css ├── b │ ├── BUILD.in │ ├── BUILD.out │ ├── data.json │ └── style.css ├── data.json └── style.css ├── collect_asset_singletons ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a │ ├── BUILD.in │ ├── BUILD.out │ └── data.json ├── b │ ├── BUILD.in │ ├── BUILD.out │ └── style.css └── data.json ├── collect_targets ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── index.ts ├── jest.config.js └── src │ ├── page-tests │ ├── BUILD.in │ ├── BUILD.out │ └── test.test.ts │ ├── pages │ ├── 404.ts │ ├── BUILD.in │ ├── BUILD.out │ ├── index.ts │ └── my_page │ │ ├── BUILD.in │ │ ├── BUILD.out │ │ ├── index.ts │ │ └── module_file.ts │ └── pages2 │ ├── BUILD.in │ ├── BUILD.out │ └── my_page │ ├── BUILD.in │ ├── BUILD.out │ ├── index.ts │ ├── module_file.ts │ └── subpage │ └── index.ts ├── default_npm_label ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a.ts ├── b.ts └── package.json ├── disabled ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a.ts └── module │ ├── BUILD.in │ ├── BUILD.out │ └── b.ts ├── disjoint_module ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── index.ts ├── my_module │ ├── BUILD.in │ ├── BUILD.out │ ├── index.ts │ ├── module_file.ts │ ├── nested_module │ │ ├── BUILD.in │ │ ├── BUILD.out │ │ ├── index.ts │ │ └── module_file.ts │ └── some_other_file.ts └── some_other_file.ts ├── dynamic_import ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a.ts ├── b.ts ├── c.ts ├── d.ts └── package.json ├── fix ├── BUILD.in ├── BUILD.out ├── WORKSPACE └── a.ts ├── import_alias ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a.ts └── module │ ├── BUILD.in │ ├── BUILD.out │ └── b.ts ├── jest_mock ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a.ts └── package.json ├── jsx_conversion ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a.jsx ├── b.js └── package.json ├── lookup_types ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a.ts ├── b.ts ├── builtin.ts ├── package.json └── subfolder │ ├── BUILD.out │ └── c.ts ├── module_self_import ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── index.ts └── my_module │ ├── BUILD.in │ ├── BUILD.out │ ├── index.ts │ ├── my_module.ts │ └── some_other_file.ts ├── monorepo ├── BUILD.in ├── WORKSPACE ├── package.json └── project_a │ ├── BUILD.in │ ├── BUILD.out │ ├── a.ts │ └── package.json ├── react_example ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── js_with_import.jsx ├── js_without_import.jsx ├── package.json ├── with_import.tsx └── without_import.tsx ├── simple_barrel ├── BUILD.in ├── BUILD.out ├── SomeOtherFile │ ├── BUILD.in │ ├── BUILD.out │ ├── SomeOtherFile.ts │ └── index.ts ├── WORKSPACE └── index.ts ├── simple_library ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a.d.ts ├── a.ts ├── b.js └── package.json ├── simple_npm_library ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a.ts ├── b.ts └── package.json ├── test_runner.go ├── ts_conversion ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── a.d.ts ├── a.ts └── package.json ├── visibility ├── BUILD.in ├── BUILD.out ├── WORKSPACE └── a.ts └── web_assets_module ├── BUILD.in ├── BUILD.out ├── WORKSPACE ├── data.json └── style.css /.bazelignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | examples 3 | .ijwb 4 | -------------------------------------------------------------------------------- /.bazelrc: -------------------------------------------------------------------------------- 1 | 2 | test --test_output=all 3 | -------------------------------------------------------------------------------- /.bazelversion: -------------------------------------------------------------------------------- 1 | 6.4.0 2 | -------------------------------------------------------------------------------- /.bcr/config.yml: -------------------------------------------------------------------------------- 1 | fixedReleaser: 2 | login: ewianda 3 | email: elvis@benchsci.com 4 | -------------------------------------------------------------------------------- /.bcr/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/benchsci/rules_nodejs_gazelle", 3 | "maintainers": [ 4 | { 5 | "name": "Elvis Wianda", 6 | "email": "elvis@benchsci.com", 7 | "github": "ewianda" 8 | }, 9 | { 10 | "name": "Colin Heathman", 11 | "email": "cheathman@benchsci.com", 12 | "github": "ColinHeathman" 13 | } 14 | ], 15 | "repository": ["https://github.com/benchsci/rules_nodejs_gazelle"], 16 | "versions": [], 17 | "yanked_versions": {} 18 | } 19 | -------------------------------------------------------------------------------- /.bcr/presubmit.yml: -------------------------------------------------------------------------------- 1 | bcr_test_module: 2 | module_path: 'examples/nextjs' 3 | matrix: 4 | bazel: ['7.x', '6.x'] 5 | platform: ['debian10', 'macos', 'ubuntu2004', 'windows'] 6 | tasks: 7 | run_tests: 8 | name: 'Run test module' 9 | bazel: ${{ bazel }} 10 | platform: ${{ platform }} 11 | run_targets: 12 | - '//:gazelle' 13 | -------------------------------------------------------------------------------- /.bcr/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "**leave this alone**", 3 | "strip_prefix": "{REPO}-{VERSION}", 4 | "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_nodejs_gazelle-{TAG}.tar.gz" 5 | } 6 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | # Controls when the action will run. 4 | on: 5 | # Triggers the workflow on push or pull request events but only for the main branch 6 | push: 7 | branches: [main] 8 | pull_request: 9 | branches: [main] 10 | 11 | # Allows you to run this workflow manually from the Actions tab 12 | workflow_dispatch: 13 | 14 | jobs: 15 | test: 16 | # The type of runner that the job will run on 17 | runs-on: ubuntu-latest 18 | 19 | # Steps represent a sequence of tasks that will be executed as part of the job 20 | steps: 21 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 22 | - uses: actions/checkout@v2 23 | - name: Mount bazel caches 24 | uses: actions/cache@v2 25 | with: 26 | path: | 27 | "~/.cache/bazel" 28 | "~/.cache/bazel-repo" 29 | key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', '**/*.js') }} 30 | restore-keys: bazel-cache- 31 | - name: bazel test //... 32 | env: 33 | # Bazelisk will download bazel to here 34 | XDG_CACHE_HOME: ~/.cache/bazel-repo 35 | run: bazel test //... 36 | test_bzlmod: 37 | # The type of runner that the job will run on 38 | runs-on: ubuntu-latest 39 | 40 | # Steps represent a sequence of tasks that will be executed as part of the job 41 | steps: 42 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 43 | - uses: actions/checkout@v2 44 | - name: Mount bazel caches 45 | uses: actions/cache@v2 46 | with: 47 | path: | 48 | "~/.cache/bazel" 49 | "~/.cache/bazel-repo" 50 | key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', '**/*.js') }} 51 | restore-keys: bazel-cache- 52 | - name: bazel test //... --enable_bzlmod 53 | env: 54 | # Bazelisk will download bazel to here 55 | XDG_CACHE_HOME: ~/.cache/bazel-repo 56 | run: bazel test //... --enable_bzlmod 57 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # Cut a release whenever a new tag is pushed to the repo. 2 | # You should use an annotated tag, like `git tag -a v1.2.3` 3 | # and put the release notes into the commit message for the tag. 4 | name: Release 5 | 6 | on: 7 | push: 8 | tags: 9 | - 'v*.*.*' 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v3 17 | - name: Mount bazel caches 18 | uses: actions/cache@v3 19 | with: 20 | path: | 21 | "~/.cache/bazel" 22 | "~/.cache/bazel-repo" 23 | key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', '**/*.js') }} 24 | restore-keys: bazel-cache- 25 | - name: bazel test //... 26 | env: 27 | # Bazel will download bazel to here 28 | XDG_CACHE_HOME: ~/.cache/bazel-repo 29 | run: bazel test //... 30 | - name: Prepare Release 31 | run: .github/workflows/workspace_snippet.sh ${{ env.GITHUB_REF_NAME }} > release_notes.txt 32 | - name: Release 33 | uses: benchsci/action-gh-release@v1 34 | with: 35 | # Use GH feature to populate the changelog automatically 36 | generate_release_notes: true 37 | body_path: release_notes.txt 38 | files: rules_nodejs_gazelle-*.tar.gz 39 | fail_on_unmatched_files: true 40 | 41 | -------------------------------------------------------------------------------- /.github/workflows/workspace_snippet.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit -o nounset -o pipefail 4 | 5 | # Set by GH actions, see 6 | # https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables 7 | NAME=rules_nodejs_gazelle 8 | TAG=${GITHUB_REF_NAME} 9 | # The prefix is chosen to match what GitHub generates for source archives 10 | PREFIX="${NAME}-${TAG:1}" 11 | ARCHIVE="${NAME}-$TAG.tar.gz" 12 | git archive --format=tar --prefix="${PREFIX}/" "${TAG}" | gzip >"$ARCHIVE" 13 | SHA=$(shasum -a 256 "$ARCHIVE" | awk '{print $1}') 14 | 15 | cat < 99 | 100 | 101 | Directive 102 | Default value 103 | 104 | 105 | 106 | 107 | 108 | # gazelle:js_extension 109 | enabled 110 | 111 | 112 |

Controls whether the JS extension is enabled or not. Sub-packages inherit this value. Can be either "enabled" or "disabled".

113 | 114 | 115 | 116 | # gazelle:js_default_npm_label 117 | //:node_modules 118 | 119 | 120 |

Defines the label prefix for third npm dependencies. //:node_modules/ is default for Aspect's rules_js, @npm// is default for rules_nodejs

121 | 122 | 123 | 124 | # gazelle:js_lookup_types true|false 125 | true 126 | 127 | 128 |

Causes Gazelle to try and find a matching "@types/pkg" dependency for each "pkg" dependency, including @types/node for Node.js builtins

129 | 130 | 131 | 132 | # gazelle:js_package_file package.json :node_modules 133 | //:node_modules 134 | 135 | 136 |

Instructs Gazelle to use a package.json file to lookup imports from dependencies and devDependencies

137 | 138 | 139 | 140 | # gazelle:js_import_alias some_folder other 141 | none 142 | 143 | 144 |

Specifies partial string substitutions applied to imports before resolving them. Eg. # gazelle:js_import_alias foo bar means that import "foo/module" will resolve to the package bar/module. This directive can be used several times.

145 | 146 | 147 | 148 | # gazelle:js_visibility label 149 | none 150 | 151 | 152 |

By default, internal packages are only visible to its siblings. This directive adds a label internal packages should be visible to additionally. This directive can be used several times, adding a list of labels.

153 | 154 | 155 | 156 | # gazelle:js_root 157 | workspace root 158 | 159 | 160 |

Specifies the current package (folder) as a JS root. Imports for JS and TS consider this folder the root level for relative and absolute imports. This is used on monorepos with multiple Python projects that don't share the top-level of the workspace as the root.

161 | 162 | 163 | 164 | # gazelle:js_collect_all 165 | none 166 | 167 | 168 |

Stops recursion into subdirectories of the folder containing the directive, and collects all sources and tests into a single rule. Use this to reduce rule count for large repositories. See tests/folder_rules for usage.

169 | 170 | 171 | 172 | # gazelle:js_collect_barrels true|false 173 | false 174 | 175 | 176 |

Generate 1 js_library, or ts_project rule per package when a index.ts or index.js file is found, rather than 1 per file. The js_root pkg cannot be a module

177 | 178 | 179 | 180 | # gazelle:js_collect_web_assets true|false 181 | false 182 | 183 | 184 |

Causes Gazelle to generate 1 web_assets rule, rather than 1 per file

185 | 186 | 187 | 188 | # gazelle:js_collect_all_assets true|false 189 | false 190 | 191 | 192 |

Generates a web_assets rule in the configured js_root that refers to all of the web_assets rules in child packages

193 | 194 | 195 | 196 | # gazelle:js_collect_targets 197 | "" 198 | 199 | 200 |

Similar to js_collect_all_assets this directive collects all sibling and child package targets in a target with the given name. See tests/collect_targets for usage.

201 | 202 | 203 | 204 | # gazelle:js_web_asset .json,.css,.scss 205 | none 206 | 207 | 208 |

Files with a matching suffix will have web_assets rules created for them

209 | 210 | 211 | 212 | # gazelle:js_quiet true|false 213 | false 214 | 215 | 216 |

Silence extension warnings about missing imports (overrides gazelle:js_verbose)

217 | 218 | 219 | 220 | # gazelle:js_verbose true|false 221 | false 222 | 223 | 224 |

Print more information about missing imports (overrides gazelle:js_quiet)

225 | 226 | 227 | 228 | # gazelle:js_jest_config :my_config 229 | none 230 | 231 | 232 |

Provide a default label for the config attribute of generated jest_test rules. This is required when using jest_test

233 | 234 | 235 | 236 | # gazelle:js_jest_size 237 | none 238 | 239 | 240 |

Provide a default value for the size attribute of generated jest_test rules

241 | 242 | 243 | 244 | # gazelle:js_jest_test_per_shard 245 | none 246 | 247 | 248 |

Provide a ratio of number of counted tests for each increment of the shard_count attribute of generated jest_test rules

249 | 250 | 251 | 252 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Bazel Authors. All rights reserved. 2 | # Modifications copyright (C) 2021 BenchSci Analytics Inc. 3 | # Modifications copyright (C) 2018 Ecosia GmbH 4 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | workspace(name = "com_github_benchsci_rules_nodejs_gazelle") 17 | 18 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 19 | 20 | http_archive( 21 | name = "io_bazel_rules_go", 22 | sha256 = "91585017debb61982f7054c9688857a2ad1fd823fc3f9cb05048b0025c47d023", 23 | urls = [ 24 | "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.42.0/rules_go-v0.42.0.zip", 25 | "https://github.com/bazelbuild/rules_go/releases/download/v0.42.0/rules_go-v0.42.0.zip", 26 | ], 27 | ) 28 | 29 | http_archive( 30 | name = "bazel_gazelle", 31 | sha256 = "b7387f72efb59f876e4daae42f1d3912d0d45563eac7cb23d1de0b094ab588cf", 32 | urls = [ 33 | "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz", 34 | "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz", 35 | ], 36 | ) 37 | 38 | load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") 39 | load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") 40 | 41 | ############################################################ 42 | # Define your own dependencies here using go_repository. 43 | # Else, dependencies declared by rules_go/gazelle will be used. 44 | # The first declaration of an external repository "wins". 45 | ############################################################ 46 | 47 | load("//:deps.bzl", "gazelle_deps") 48 | 49 | # gazelle:repository_macro deps.bzl%gazelle_deps 50 | gazelle_deps() 51 | 52 | go_rules_dependencies() 53 | 54 | go_register_toolchains(version = "1.20.5") 55 | 56 | gazelle_dependencies() 57 | -------------------------------------------------------------------------------- /WORKSPACE.bzlmod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/WORKSPACE.bzlmod -------------------------------------------------------------------------------- /defs.bzl: -------------------------------------------------------------------------------- 1 | # This shows how you might create macros for the autogenerated rules. 2 | 3 | # You should not necessarily use all of these rules directly 4 | # and should instead map to upstream or custom rules with the map_kind 5 | # directive. Example: 6 | # #gazelle:map_kind web_assets web_assets @my_local_repo 7 | 8 | load("//internal:web_assets.bzl", _web_assets = "web_assets") 9 | web_assets = _web_assets 10 | web_asset = _web_assets 11 | -------------------------------------------------------------------------------- /deps.bzl: -------------------------------------------------------------------------------- 1 | load("@bazel_gazelle//:deps.bzl", "go_repository") 2 | 3 | def gazelle_deps(): 4 | go_repository( 5 | name = "co_honnef_go_tools", 6 | importpath = "honnef.co/go/tools", 7 | sum = "h1:/hemPrYIhOhy8zYrNj+069zDB68us2sMGsfkFJO0iZs=", 8 | version = "v0.0.0-20190523083050-ea95bdfd59fc", 9 | ) 10 | go_repository( 11 | name = "com_github_bazelbuild_bazel_gazelle", 12 | importpath = "github.com/bazelbuild/bazel-gazelle", 13 | sum = "h1:YHkwssgvCXDRU7sLCq1kGqaGYO9pKNR1Wku7UT2LhoY=", 14 | version = "v0.34.0", 15 | ) 16 | go_repository( 17 | name = "com_github_bazelbuild_buildtools", 18 | importpath = "github.com/bazelbuild/buildtools", 19 | sum = "h1:VUHCI4QRifAGYsbVJYqJndLf7YqV12YthB+PLFsEKqo=", 20 | version = "v0.0.0-20231017121127-23aa65d4e117", 21 | ) 22 | go_repository( 23 | name = "com_github_bazelbuild_rules_go", 24 | importpath = "github.com/bazelbuild/rules_go", 25 | sum = "h1:aY2smc3JWyUKOjGYmOKVLX70fPK9ON0rtwQojuIeUHc=", 26 | version = "v0.42.0", 27 | ) 28 | go_repository( 29 | name = "com_github_bmatcuk_doublestar_v4", 30 | importpath = "github.com/bmatcuk/doublestar/v4", 31 | sum = "h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I=", 32 | version = "v4.6.1", 33 | ) 34 | go_repository( 35 | name = "com_github_burntsushi_toml", 36 | importpath = "github.com/BurntSushi/toml", 37 | sum = "h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=", 38 | version = "v0.3.1", 39 | ) 40 | go_repository( 41 | name = "com_github_census_instrumentation_opencensus_proto", 42 | importpath = "github.com/census-instrumentation/opencensus-proto", 43 | sum = "h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk=", 44 | version = "v0.2.1", 45 | ) 46 | go_repository( 47 | name = "com_github_chzyer_logex", 48 | importpath = "github.com/chzyer/logex", 49 | sum = "h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=", 50 | version = "v1.1.10", 51 | ) 52 | go_repository( 53 | name = "com_github_chzyer_readline", 54 | importpath = "github.com/chzyer/readline", 55 | sum = "h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=", 56 | version = "v0.0.0-20180603132655-2972be24d48e", 57 | ) 58 | go_repository( 59 | name = "com_github_chzyer_test", 60 | importpath = "github.com/chzyer/test", 61 | sum = "h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=", 62 | version = "v0.0.0-20180213035817-a1ea475d72b1", 63 | ) 64 | go_repository( 65 | name = "com_github_client9_misspell", 66 | importpath = "github.com/client9/misspell", 67 | sum = "h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=", 68 | version = "v0.3.4", 69 | ) 70 | go_repository( 71 | name = "com_github_envoyproxy_go_control_plane", 72 | importpath = "github.com/envoyproxy/go-control-plane", 73 | sum = "h1:4cmBvAEBNJaGARUEs3/suWRyfyBfhf7I60WBZq+bv2w=", 74 | version = "v0.9.1-0.20191026205805-5f8ba28d4473", 75 | ) 76 | go_repository( 77 | name = "com_github_envoyproxy_protoc_gen_validate", 78 | importpath = "github.com/envoyproxy/protoc-gen-validate", 79 | sum = "h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=", 80 | version = "v0.1.0", 81 | ) 82 | go_repository( 83 | name = "com_github_fsnotify_fsnotify", 84 | importpath = "github.com/fsnotify/fsnotify", 85 | sum = "h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=", 86 | version = "v1.7.0", 87 | ) 88 | go_repository( 89 | name = "com_github_golang_glog", 90 | importpath = "github.com/golang/glog", 91 | sum = "h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=", 92 | version = "v0.0.0-20160126235308-23def4e6c14b", 93 | ) 94 | go_repository( 95 | name = "com_github_golang_mock", 96 | importpath = "github.com/golang/mock", 97 | sum = "h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=", 98 | version = "v1.6.0", 99 | ) 100 | go_repository( 101 | name = "com_github_golang_protobuf", 102 | importpath = "github.com/golang/protobuf", 103 | sum = "h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=", 104 | version = "v1.5.2", 105 | ) 106 | go_repository( 107 | name = "com_github_google_go_cmp", 108 | importpath = "github.com/google/go-cmp", 109 | sum = "h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=", 110 | version = "v0.6.0", 111 | ) 112 | go_repository( 113 | name = "com_github_pmezard_go_difflib", 114 | importpath = "github.com/pmezard/go-difflib", 115 | sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=", 116 | version = "v1.0.0", 117 | ) 118 | go_repository( 119 | name = "com_github_prometheus_client_model", 120 | importpath = "github.com/prometheus/client_model", 121 | sum = "h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM=", 122 | version = "v0.0.0-20190812154241-14fe0d1b01d4", 123 | ) 124 | go_repository( 125 | name = "com_google_cloud_go", 126 | importpath = "cloud.google.com/go", 127 | sum = "h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ=", 128 | version = "v0.26.0", 129 | ) 130 | go_repository( 131 | name = "net_starlark_go", 132 | importpath = "go.starlark.net", 133 | sum = "h1:xwwDQW5We85NaTk2APgoN9202w/l0DVGp+GZMfsrh7s=", 134 | version = "v0.0.0-20210223155950-e043a3d3c984", 135 | ) 136 | go_repository( 137 | name = "org_golang_google_appengine", 138 | importpath = "google.golang.org/appengine", 139 | sum = "h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=", 140 | version = "v1.4.0", 141 | ) 142 | go_repository( 143 | name = "org_golang_google_genproto", 144 | importpath = "google.golang.org/genproto", 145 | sum = "h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=", 146 | version = "v0.0.0-20200526211855-cb27e3aa2013", 147 | ) 148 | go_repository( 149 | name = "org_golang_google_grpc", 150 | importpath = "google.golang.org/grpc", 151 | sum = "h1:fPVVDxY9w++VjTZsYvXWqEf9Rqar/e+9zYfxKK+W+YU=", 152 | version = "v1.50.0", 153 | ) 154 | go_repository( 155 | name = "org_golang_google_protobuf", 156 | importpath = "google.golang.org/protobuf", 157 | sum = "h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=", 158 | version = "v1.28.0", 159 | ) 160 | go_repository( 161 | name = "org_golang_x_crypto", 162 | importpath = "golang.org/x/crypto", 163 | sum = "h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=", 164 | version = "v0.0.0-20190308221718-c2843e01d9a2", 165 | ) 166 | go_repository( 167 | name = "org_golang_x_exp", 168 | importpath = "golang.org/x/exp", 169 | sum = "h1:c2HOrn5iMezYjSlGPncknSEr/8x5LELb/ilJbXi9DEA=", 170 | version = "v0.0.0-20190121172915-509febef88a4", 171 | ) 172 | go_repository( 173 | name = "org_golang_x_lint", 174 | importpath = "golang.org/x/lint", 175 | sum = "h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0=", 176 | version = "v0.0.0-20190313153728-d0100b6bd8b3", 177 | ) 178 | go_repository( 179 | name = "org_golang_x_mod", 180 | importpath = "golang.org/x/mod", 181 | sum = "h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=", 182 | version = "v0.14.0", 183 | ) 184 | go_repository( 185 | name = "org_golang_x_net", 186 | importpath = "golang.org/x/net", 187 | sum = "h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=", 188 | version = "v0.0.0-20210405180319-a5a99cb37ef4", 189 | ) 190 | go_repository( 191 | name = "org_golang_x_oauth2", 192 | importpath = "golang.org/x/oauth2", 193 | sum = "h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=", 194 | version = "v0.0.0-20180821212333-d2e6202438be", 195 | ) 196 | go_repository( 197 | name = "org_golang_x_sync", 198 | importpath = "golang.org/x/sync", 199 | sum = "h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=", 200 | version = "v0.4.0", 201 | ) 202 | go_repository( 203 | name = "org_golang_x_sys", 204 | importpath = "golang.org/x/sys", 205 | sum = "h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=", 206 | version = "v0.14.0", 207 | ) 208 | go_repository( 209 | name = "org_golang_x_text", 210 | importpath = "golang.org/x/text", 211 | sum = "h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=", 212 | version = "v0.3.3", 213 | ) 214 | go_repository( 215 | name = "org_golang_x_tools", 216 | importpath = "golang.org/x/tools", 217 | sum = "h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=", 218 | version = "v0.13.0", 219 | ) 220 | go_repository( 221 | name = "org_golang_x_tools_go_vcs", 222 | importpath = "golang.org/x/tools/go/vcs", 223 | sum = "h1:cOIJqWBl99H1dH5LWizPa+0ImeeJq3t3cJjaeOWUAL4=", 224 | version = "v0.1.0-deprecated", 225 | ) 226 | go_repository( 227 | name = "org_golang_x_xerrors", 228 | importpath = "golang.org/x/xerrors", 229 | sum = "h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=", 230 | version = "v0.0.0-20200804184101-5ec99f83aff1", 231 | ) 232 | -------------------------------------------------------------------------------- /examples/nextjs/.bazelignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | apps/alpha/node_modules 3 | apps/alpha/pages/__snapshots__ 4 | packages/one/node_modules 5 | app/.next 6 | bazel-out 7 | bazel-bin 8 | bazel-nextjs 9 | bazel-testlogs 10 | -------------------------------------------------------------------------------- /examples/nextjs/.bazelrc: -------------------------------------------------------------------------------- 1 | common --enable_bzlmod 2 | -------------------------------------------------------------------------------- /examples/nextjs/.bazelversion: -------------------------------------------------------------------------------- 1 | 6.1.2 -------------------------------------------------------------------------------- /examples/nextjs/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /examples/nextjs/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | .pnpm-debug.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | 37 | # bazel 38 | /bazel-* -------------------------------------------------------------------------------- /examples/nextjs/.npmrc: -------------------------------------------------------------------------------- 1 | # Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on 2 | # projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what 3 | # rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules). See 4 | # https://github.com/aspect-build/rules_js/blob/7377f2d0387cc2a9251137929b1c53ccdb3fbcf0/docs/npm_import.md#npm_translate_lock 5 | # documentation for more information. 6 | hoist=false 7 | -------------------------------------------------------------------------------- /examples/nextjs/.swcrc: -------------------------------------------------------------------------------- 1 | { 2 | "jsc": { 3 | "loose": true, 4 | "target": "es2020", 5 | "parser": { 6 | "syntax": "typescript", 7 | "decorators": true, 8 | "tsx": true 9 | }, 10 | "transform": { 11 | "react": { 12 | "runtime": "automatic", 13 | "pragma": "React.createElement", 14 | "pragmaFrag": "React.Fragment", 15 | "throwIfNamespace": true, 16 | "development": false, 17 | "useBuiltins": false 18 | }, 19 | "legacyDecorator": true, 20 | "decoratorMetadata": true 21 | } 22 | }, 23 | "module": { 24 | "type": "commonjs", 25 | "strict": true, 26 | "strictMode": true, 27 | "lazy": true, 28 | "noInterop": true 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/nextjs/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_config") 3 | load("@npm//:defs.bzl", "npm_link_all_packages") 4 | load("@npm//:next/package_json.bzl", next_bin = "bin") 5 | load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary") 6 | 7 | # gazelle:exclude .next 8 | # gazelle:exclude **/node_modules 9 | # gazelle:exclude .eslintrc.json 10 | # gazelle:exclude tsconfig.json 11 | 12 | # gazelle:js_package_file package.json :node_modules 13 | # gazelle:js_collect_barrels 14 | # gazelle:js_web_asset .json,.css,.scss,.svg,.ico 15 | # gazelle:js_collect_all_assets 16 | # gazelle:js_root 17 | 18 | # gazelle:map_kind jest_test jest_test //bazel:jest_test.bzl 19 | # gazelle:map_kind ts_project ts_project //bazel:ts_project.bzl 20 | # gazelle:map_kind web_assets web_assets //bazel:web_assets.bzl 21 | 22 | gazelle( 23 | name = "gazelle", 24 | args = ["-build_file_name=BUILD.bazel"], 25 | gazelle = ":gazelle_bin", 26 | visibility = ["//visibility:private"], 27 | ) 28 | 29 | gazelle_binary( 30 | name = "gazelle_bin", 31 | languages = DEFAULT_LANGUAGES + [ 32 | "@com_github_benchsci_rules_nodejs_gazelle//gazelle:gazelle", 33 | ], 34 | visibility = ["//visibility:private"], 35 | ) 36 | 37 | npm_link_all_packages(name = "node_modules") 38 | 39 | next_bin.next_binary( 40 | name = "next_js_binary", 41 | visibility = ["//visibility:public"], 42 | ) 43 | 44 | ts_config( 45 | name = "tsconfig", 46 | src = "tsconfig.json", 47 | visibility = ["//visibility:public"], 48 | ) 49 | 50 | js_library( 51 | name = "package_json", 52 | srcs = ["package.json"], 53 | ) 54 | -------------------------------------------------------------------------------- /examples/nextjs/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "e2e_rules_nodejs_gazelle", 3 | version = "0.0.0", 4 | compatibility_level = 1, 5 | ) 6 | 7 | bazel_dep(name = "aspect_rules_js", version = "1.27.0") 8 | bazel_dep(name = "gazelle", version = "0.34.0", repo_name = "bazel_gazelle") 9 | bazel_dep(name = "rules_go", version = "0.42.0", repo_name = "io_bazel_rules_go") 10 | bazel_dep(name = "bazel_skylib", version = "1.4.1") 11 | bazel_dep(name = "aspect_rules_ts", version = "1.4.0") 12 | bazel_dep(name = "aspect_rules_jest", version = "0.0.0", repo_name = "aspect_rules_jest") 13 | bazel_dep(name = "com_github_benchsci_rules_nodejs_gazelle", version = "0.0.0", repo_name = "com_github_benchsci_rules_nodejs_gazelle") 14 | local_path_override( 15 | module_name = "com_github_benchsci_rules_nodejs_gazelle", 16 | path = "../..", 17 | ) 18 | 19 | npm = use_extension( 20 | "@aspect_rules_js//npm:extensions.bzl", 21 | "npm", 22 | dev_dependency = True, 23 | ) 24 | npm.npm_translate_lock( 25 | name = "npm", 26 | bins = { 27 | # derived from "bin" attribute in node_modules/next/package.json 28 | "next": [ 29 | "next=./dist/bin/next", 30 | ], 31 | }, 32 | # Test that lifecycle hooks can resolve node, npm as well as dep bins on that PATH. 33 | # This e2e test is run on Windows as well so this test coverage is here for now. Once 34 | # Windows CI runs on the root WORKSPACE, coverage can be moved there. 35 | # See https://github.com/aspect-build/rules_js/pull/1142 for more info. 36 | npmrc = "//:.npmrc", 37 | pnpm_lock = "//:pnpm-lock.yaml", 38 | verify_node_modules_ignored = "//:.bazelignore", 39 | ) 40 | use_repo(npm, "npm") 41 | 42 | rules_ts_ext = use_extension( 43 | "@aspect_rules_ts//ts:extensions.bzl", 44 | "ext", 45 | dev_dependency = True, 46 | ) 47 | rules_ts_ext.deps() 48 | use_repo(rules_ts_ext, "npm_typescript") 49 | 50 | archive_override( 51 | module_name = "aspect_rules_jest", 52 | integrity = "sha256-F1+SRIvRGzmO6UxrsJyr9233WnfSHJVVcjeYxYouc8g=", 53 | strip_prefix = "rules_jest-0.19.2", 54 | urls = ["https://github.com/aspect-build/rules_jest/releases/download/v0.19.2/rules_jest-v0.19.2.tar.gz"], 55 | ) 56 | -------------------------------------------------------------------------------- /examples/nextjs/README.md: -------------------------------------------------------------------------------- 1 | # Next.js Bazel // Gazelle example 2 | 3 | This is an example adapted from [aspect-build/bazel-examples](https://github.com/aspect-build/bazel-examples) with rules generation using the Gazelle plugin. A few things are still missing, notably linting using eslint. 4 | 5 | # Original Readme.MD: 6 | 7 | This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) and then Bazelified. 8 | 9 | TypeScript transpilation and type checking has been broken out into fine-grained `ts_project` targets. 10 | This is a small example with only two Typescript source directories so the performance benefit of using fine grained targets will be negligible here. 11 | 12 | In a large application or monorepo, splitting Typescript transpilation & type checking across many targets can speed up the build with parallelization and caching. It also allows for massive parallelization with remote execution. Read 13 | https://blog.aspect.dev/typescript-with-rbe for more information on using remote execution with Typescript. 14 | 15 | NB: The example is not 100% complete and there are some minor TODOs in the code including a TODO for running linting under Bazel. 16 | 17 | ## Usage 18 | 19 | The `package.json` scripts have been updated to call Bazel instead of Next.js so these scripts can be 20 | used as they would be in a typical Next.js configuration. 21 | 22 | ### Setup 23 | 24 | First run `pnpm install`. Bazel itself doesn't depend on the `node_modules` folder layed out in the 25 | source tree but it is needed so your editor can find typings and for running `ibazel` without having 26 | to install it globally. `ibazel` is a wrapper around bazel that adds watch mode used when running the 27 | devserver. 28 | 29 | ### Building 30 | 31 | Run `pnpm run build`. This runs `bazel build //apps/alpha:next`, the Bazel equivalent of running `next build`. 32 | The output `.next` folder can be found under `bazel-bin/apps/alpha/.next`. 33 | 34 | ### Production server 35 | 36 | Run `pnpm run start`. This runs `ibazel run //apps/alpha:next_start`, the Bazel equivalent of running `next start`. 37 | 38 | ### Development server 39 | 40 | Run `pnpm run dev`. This runs `ibazel run //apps/alpha:next_dev`, the Bazel equivalent of running `next dev`. 41 | 42 | ### Linting 43 | 44 | Run `pnpm run lint`. This run `bazel test //apps/alpha/... --test_tag_filters=lint --build_tests_only`, the Bazel equivalent of running `next lint`. 45 | 46 | ### Running tests 47 | 48 | Run `pnpm run test`. This runs `bazel test //apps/alpha/... --test_tag_filters=jest --build_tests_only`, the Bazel equivalent of running `jest`. 49 | 50 | ### Exporting 51 | 52 | Run `pnpm run export`. This runs `bazel build //apps/alpha:next_export`, the Bazel equivalent of running `next export`. 53 | The output `out` folder can be found under `bazel-bin/apps/alpha/out`. 54 | 55 | NB This target will fail on some systems or cause unnecessary rebuilds of the `.next` target due to `next export` writing 56 | back to the `.next` input directory which is write-protected input under Bazel. See https://github.com/vercel/next.js/issues/43344. 57 | 58 | TODO: Fix issue in Next.js (https://github.com/vercel/next.js/issues/43344) or find work-around. 59 | 60 | ### Styles 61 | 62 | This example only has the .css styles generated by [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). These don't require any build steps. Showing how to create fine grained 63 | targets to pre-process `.scss` and `.less` into `.css` would be useful in this example in the future. 64 | 65 | TODO: add .scss and/or .less styles and pre-process targets 66 | 67 | ### Releasing and deploying 68 | 69 | This examples doesn't directly cover releasing and deploying a Next.js application built with Bazel 70 | but it should not diverge much from releasing and deploying a Next.js application built outside of Bazel 71 | since the output of the Bazel build is the shape as the output you would get from running the vernacular 72 | Next.js tooling, namely a `.next` folder with all of the output artifacts that application is 73 | comprised of: 74 | 75 | ``` 76 | $ pnpm run build 77 | 78 | > next.js@0.1.0 build /Users/greg/aspect/rules/bazel-examples/next.js 79 | > bazel build //:build 80 | 81 | INFO: Analyzed target //:build (0 packages loaded, 0 targets configured). 82 | INFO: Found 1 target... 83 | Target //:build up-to-date: 84 | bazel-bin/.next 85 | INFO: Elapsed time: 0.260s, Critical Path: 0.00s 86 | INFO: 1 process: 1 internal. 87 | INFO: Build completed successfully, 1 total action 88 | 89 | $ ls -la bazel-bin/.next 90 | total 608 91 | drwxr-xr-x 16 greg wheel 512 28 Sep 14:06 . 92 | drwxr-xr-x 11 greg wheel 352 28 Sep 14:06 .. 93 | -rw-r--r-- 1 greg wheel 21 28 Sep 14:06 BUILD_ID 94 | -rw-r--r-- 1 greg wheel 1078 28 Sep 14:06 build-manifest.json 95 | drwxr-xr-x 5 greg wheel 160 28 Sep 14:06 cache 96 | -rw-r--r-- 1 greg wheel 93 28 Sep 14:06 export-marker.json 97 | -rw-r--r-- 1 greg wheel 441 28 Sep 14:06 images-manifest.json 98 | -rw-r--r-- 1 greg wheel 103383 28 Sep 14:06 next-server.js.nft.json 99 | -rw-r--r-- 1 greg wheel 20 28 Sep 14:06 package.json 100 | -rw-r--r-- 1 greg wheel 312 28 Sep 14:06 prerender-manifest.json 101 | -rw-r--r-- 1 greg wheel 2 28 Sep 14:06 react-loadable-manifest.json 102 | -rw-r--r-- 1 greg wheel 2598 28 Sep 14:06 required-server-files.json 103 | -rw-r--r-- 1 greg wheel 335 28 Sep 14:06 routes-manifest.json 104 | drwxr-xr-x 10 greg wheel 320 28 Sep 14:06 server 105 | drwxr-xr-x 5 greg wheel 160 28 Sep 14:06 static 106 | -rw-r--r-- 1 greg wheel 115279 28 Sep 14:06 trace 107 | ``` 108 | 109 | When built with Bazel, this folder doesn't end up as `.next` in your source tree 110 | because Bazel doesn't write output files to the source tree. Instead the folder can be found 111 | via the `bazel-bin` symlink create by Bazel as `bazel-bin/.next`. You release and deploy tooling 112 | would use this folder after running the Bazel build. 113 | -------------------------------------------------------------------------------- /examples/nextjs/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace( 2 | name = "nextjs_template", 3 | ) 4 | 5 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 6 | 7 | http_archive( 8 | name = "aspect_rules_js", 9 | sha256 = "dcd1567d4a93a8634ec0b888b371a60b93c18d980f77dace02eb176531a71fcf", 10 | strip_prefix = "rules_js-1.26.0", 11 | url = "https://github.com/aspect-build/rules_js/releases/download/v1.26.0/rules_js-v1.26.0.tar.gz", 12 | ) 13 | 14 | http_archive( 15 | name = "aspect_rules_ts", 16 | sha256 = "ace5b609603d9b5b875d56c9c07182357c4ee495030f40dcefb10d443ba8c208", 17 | strip_prefix = "rules_ts-1.4.0", 18 | url = "https://github.com/aspect-build/rules_ts/releases/download/v1.4.0/rules_ts-v1.4.0.tar.gz", 19 | ) 20 | 21 | http_archive( 22 | name = "aspect_rules_jest", 23 | sha256 = "098186ffc450f2a604843d8ba14217088a0e259ea6a03294af5360a7f1bcd3e8", 24 | strip_prefix = "rules_jest-0.19.5", 25 | url = "https://github.com/aspect-build/rules_jest/releases/download/v0.19.5/rules_jest-v0.19.5.tar.gz", 26 | ) 27 | 28 | load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") 29 | 30 | rules_js_dependencies() 31 | 32 | load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies") 33 | 34 | rules_ts_dependencies(ts_version_from = "//:package.json") 35 | 36 | load("@aspect_rules_jest//jest:dependencies.bzl", "rules_jest_dependencies") 37 | 38 | rules_jest_dependencies() 39 | 40 | load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains") 41 | 42 | nodejs_register_toolchains( 43 | name = "nodejs", 44 | node_version = DEFAULT_NODE_VERSION, 45 | ) 46 | 47 | load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock") 48 | 49 | npm_translate_lock( 50 | name = "npm", 51 | bins = { 52 | # derived from "bin" attribute in node_modules/next/package.json 53 | "next": { 54 | "next": "./dist/bin/next", 55 | }, 56 | }, 57 | npmrc = "//:.npmrc", 58 | pnpm_lock = "//:pnpm-lock.yaml", 59 | verify_node_modules_ignored = "//:.bazelignore", 60 | ) 61 | 62 | load("@npm//:repositories.bzl", "npm_repositories") 63 | 64 | npm_repositories() 65 | 66 | # Go dependencies 67 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 68 | 69 | http_archive( 70 | name = "io_bazel_rules_go", 71 | sha256 = "bfc5ce70b9d1634ae54f4e7b495657a18a04e0d596785f672d35d5f505ab491a", 72 | urls = [ 73 | "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.40.0/rules_go-v0.40.0.zip", 74 | "https://github.com/bazelbuild/rules_go/releases/download/v0.40.0/rules_go-v0.40.0.zip", 75 | ], 76 | ) 77 | 78 | load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") 79 | 80 | http_archive( 81 | name = "bazel_gazelle", 82 | sha256 = "b8b6d75de6e4bf7c41b7737b183523085f56283f6db929b86c5e7e1f09cf59c9", 83 | urls = [ 84 | "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.31.1/bazel-gazelle-v0.31.1.tar.gz", 85 | "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.31.1/bazel-gazelle-v0.31.1.tar.gz", 86 | ], 87 | ) 88 | 89 | load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") 90 | 91 | go_rules_dependencies() 92 | 93 | go_register_toolchains(version = "1.19") 94 | 95 | gazelle_dependencies() 96 | 97 | # Get the latest release from https://github.com/benchsci/rules_nodejs_gazelle/releases 98 | # http_archive( 99 | # name = "com_github_benchsci_rules_nodejs_gazelle", 100 | # sha256 = "************", 101 | # strip_prefix = "rules_nodejs_gazelle-0.4.0", 102 | # urls = [ 103 | # "https://github.com/benchsci/rules_nodejs_gazelle/archive/refs/tags/v0.4.0.tar.gz", 104 | # ], 105 | # ) 106 | local_repository( 107 | name = "com_github_benchsci_rules_nodejs_gazelle", 108 | path = "../..", 109 | ) 110 | -------------------------------------------------------------------------------- /examples/nextjs/WORKSPACE.bzlmod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/examples/nextjs/WORKSPACE.bzlmod -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//bazel:web_assets.bzl", "web_assets") 2 | load("@aspect_rules_js//js:defs.bzl", "js_library", "js_test") 3 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 4 | load("@npm//:defs.bzl", "npm_link_all_packages") 5 | load("//bazel:next.bzl", "next") 6 | 7 | # gazelle:exclude next-env.d.ts 8 | # gazelle:exclude next.config.js 9 | 10 | # gazelle:js_collect_web_assets 11 | # gazelle:js_collect_all_assets 12 | 13 | # gazelle:js_package_file package.json :node_modules 14 | # gazelle:js_jest_config :jest.config 15 | # gazelle:js_jest_test_per_shard 25 16 | 17 | # gazelle:js_root 18 | 19 | # gazelle:js_visibility //apps/alpha:__subpackages__ 20 | 21 | npm_link_all_packages(name = "node_modules") 22 | 23 | # Run `bazel build //apps/alpha:next` to build (equivalent to running `next build`). 24 | # 25 | # It is recommended that you use [ibazel](https://github.com/bazelbuild/bazel-watcher) 26 | # to run the devserver targets. 27 | # 28 | # Run `ibazel run //apps/alpha:next_dev` to run the development server in watch mode 29 | # (equivalent to running `next dev`). 30 | # 31 | # Run `ibazel run //apps/alpha:next_start` to run the production server in watch mode 32 | # (equivalent to running `next start`). 33 | next( 34 | name = "next", 35 | srcs = [ 36 | ":all_assets", 37 | "//apps/alpha/pages", 38 | ], 39 | data = [ 40 | "next.config.js", 41 | "package.json", 42 | ":node_modules/is-even", 43 | ], 44 | next_bin = "../../node_modules/.bin/next", 45 | next_js_binary = "//:next_js_binary", 46 | ) 47 | 48 | # A smoke test on the artifact produced by the :next target 49 | js_test( 50 | name = "build_smoke_test", 51 | size = "small", 52 | chdir = package_name(), 53 | data = [":next"], 54 | entry_point = "build_smoke_test.js", 55 | ) 56 | 57 | build_test( 58 | name = "build_test", 59 | targets = [ 60 | ":next", 61 | # Not build testing the `:next_export` target since this `next export` writes back to the `.next` directory which 62 | # causes issues with trying to write to an input. See https://github.com/vercel/next.js/issues/43344. 63 | # TODO: fix in Next.js (https://github.com/vercel/next.js/issues/43344) or find work-around. 64 | # ":next_export", 65 | ], 66 | ) 67 | 68 | web_assets( 69 | name = "all_assets", 70 | srcs = [ 71 | "//apps/alpha/public:assets", 72 | "//apps/alpha/styles:assets", 73 | ], 74 | ) 75 | 76 | js_library( 77 | name = "jest.config", 78 | srcs = ["jest.config.js"], 79 | data = ["//:node_modules/next"], 80 | visibility = ["//apps/alpha:__subpackages__"], 81 | deps = ["//:node_modules/next"], 82 | ) 83 | 84 | js_library( 85 | name = "package_json", 86 | srcs = ["package.json"], 87 | visibility = ["//apps/alpha:__subpackages__"], 88 | ) 89 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/build_smoke_test.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const fs = require('fs'); 3 | 4 | // Make sure there's a file like .next/static/chunks/main-320707e1a775df4d.js 5 | const files = fs.readdirSync('.next/static/chunks'); 6 | console.log(files); 7 | assert.ok(files.some((f) => /main-[0-9a-f]{16}\.js/.test(f))); 8 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/jest.config.js: -------------------------------------------------------------------------------- 1 | // Based on https://github.com/vercel/next.js/blob/28454c6ddbc310419467e5415aee26e48d079b46/examples/with-jest/jest.config.js 2 | 3 | const nextJest = require('next/jest'); 4 | 5 | const createJestConfig = nextJest({ 6 | // Provide the path to your Next.js app to load next.config.js and .env files in your test environment. 7 | // This path is relative to the WORKSPACE file when testing under Bazel. 8 | dir: './apps/alpha', 9 | }); 10 | 11 | // Add any custom config to be passed to Jest 12 | const customJestConfig = { 13 | moduleNameMapper: { 14 | // Handle module aliases (this will be automatically configured for you soon) 15 | '^@/components/(.*)$': '/components/$1', 16 | 17 | '^@/pages/(.*)$': '/pages/$1', 18 | }, 19 | testEnvironment: 'jest-environment-jsdom', 20 | }; 21 | 22 | // createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async 23 | module.exports = createJestConfig(customJestConfig); 24 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | reactStrictMode: true, 4 | swcMinify: true, 5 | // https://nextjs.org/docs/messages/export-image-api 6 | images: { 7 | unoptimized: true, 8 | }, 9 | }; 10 | 11 | module.exports = nextConfig; 12 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "dependencies": { 4 | "@types/is-even": "1.0.0", 5 | "is-even": "1.0.0" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/pages/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("//bazel:jest_test.bzl", "jest_test") 3 | load("//bazel:ts_project.bzl", "ts_project") 4 | 5 | # gazelle:js_collect_all 6 | # gazelle:js_collect_targets next_pages 7 | 8 | ts_project( 9 | name = "pages", 10 | srcs = [ 11 | "_app.tsx", 12 | "index.tsx", 13 | ], 14 | data = [ 15 | "//:node_modules/@nextjs-example/one", 16 | "//:node_modules/next", 17 | "//:node_modules/react", 18 | "//apps/alpha:node_modules/is-even", 19 | "//apps/alpha/styles:assets", 20 | ], 21 | visibility = ["//apps/alpha:__subpackages__"], 22 | deps = [ 23 | "//:node_modules/@nextjs-example/one", 24 | "//:node_modules/@types/react", 25 | "//:node_modules/next", 26 | "//:node_modules/react", 27 | "//apps/alpha:node_modules/@types/is-even", 28 | "//apps/alpha:node_modules/is-even", 29 | ], 30 | ) 31 | 32 | jest_test( 33 | name = "pages_test", 34 | srcs = ["index.test.tsx"], 35 | config = "//apps/alpha:jest.config", 36 | data = [ 37 | ":pages", 38 | "//:node_modules/@testing-library/jest-dom", 39 | "//:node_modules/@testing-library/react", 40 | "//:node_modules/@types/jest", 41 | "//:node_modules/jest-environment-jsdom", 42 | "//:node_modules/jest-transform-stub", 43 | "//:node_modules/react", 44 | "//apps/alpha:package_json", 45 | ], 46 | snapshots = ["__snapshots__"], 47 | visibility = ["//apps/alpha:__subpackages__"], 48 | deps = [ 49 | ":pages", 50 | "//:node_modules/@testing-library/jest-dom", 51 | "//:node_modules/@testing-library/react", 52 | "//:node_modules/@types/jest", 53 | "//:node_modules/jest-environment-jsdom", 54 | "//:node_modules/jest-transform-stub", 55 | "//:node_modules/react", 56 | ], 57 | ) 58 | 59 | js_library( 60 | name = "next_pages", 61 | visibility = ["//apps/alpha:__subpackages__"], 62 | deps = [ 63 | ":pages", 64 | "//apps/alpha/pages/api", 65 | ], 66 | ) 67 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/pages/__snapshots__/index.test.tsx.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`snapshot works 1`] = ` 4 | 5 | 110 | 111 | `; 112 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import '../styles/globals.css'; 2 | import type { AppProps } from 'next/app'; 3 | 4 | function MyApp({ Component, pageProps }: AppProps) { 5 | return ; 6 | } 7 | 8 | export default MyApp; 9 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/pages/api/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//bazel:ts_project.bzl", "ts_project") 2 | 3 | # gazelle:js_collect_all 4 | 5 | ts_project( 6 | name = "api", 7 | srcs = ["hello.ts"], 8 | data = ["//:node_modules/next"], 9 | visibility = ["//apps/alpha:__subpackages__"], 10 | deps = ["//:node_modules/next"], 11 | ) 12 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/pages/api/hello.ts: -------------------------------------------------------------------------------- 1 | // Next.js API route support: https://nextjs.org/docs/api-routes/introduction 2 | import type { NextApiRequest, NextApiResponse } from 'next'; 3 | 4 | type Data = { 5 | name: string; 6 | }; 7 | 8 | export default function handler( 9 | req: NextApiRequest, 10 | res: NextApiResponse 11 | ) { 12 | res.status(200).json({ name: 'John Doe' }); 13 | } 14 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/pages/index.test.tsx: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import Home from './index'; 3 | 4 | // Used for __tests__/testing-library.js 5 | // Learn more: https://github.com/testing-library/jest-dom 6 | import '@testing-library/jest-dom/extend-expect'; 7 | 8 | describe('Home', () => { 9 | it('renders a heading', () => { 10 | render(); 11 | 12 | const heading = screen.getByRole('heading', { 13 | name: /welcome to next\.js!/i, 14 | }); 15 | 16 | expect(heading).toBeInTheDocument(); 17 | }); 18 | }); 19 | 20 | describe('snapshot', () => { 21 | it('works', () => { 22 | const { asFragment } = render(); 23 | expect(asFragment()).toMatchSnapshot(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import type { NextPage } from 'next'; 2 | import Head from 'next/head'; 3 | import Image from 'next/image'; 4 | import styles from '../styles/Home.module.css'; 5 | import { one } from '@nextjs-example/one'; 6 | import isEven from 'is-even'; 7 | 8 | const Home: NextPage = () => { 9 | return ( 10 |
11 | 12 | Create Next App 13 | 14 | 15 | 16 | 17 |
18 |

19 | Welcome to Next.js! 20 |

21 | 22 |

23 | Get started by editing{' '} 24 | pages/index.tsx 25 |

26 | 27 | 60 |
61 | 62 | 74 |
75 | ); 76 | }; 77 | 78 | export default Home; 79 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/public/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//bazel:web_assets.bzl", "web_assets") 2 | 3 | web_assets( 4 | name = "assets", 5 | srcs = [ 6 | "favicon.ico", 7 | "vercel.svg", 8 | ], 9 | visibility = ["//apps/alpha:__subpackages__"], 10 | ) 11 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/examples/nextjs/apps/alpha/public/favicon.ico -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/styles/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//bazel:web_assets.bzl", "web_assets") 2 | 3 | web_assets( 4 | name = "assets", 5 | srcs = [ 6 | "Home.module.css", 7 | "globals.css", 8 | ], 9 | visibility = ["//apps/alpha:__subpackages__"], 10 | ) 11 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/styles/Home.module.css: -------------------------------------------------------------------------------- 1 | .container { 2 | padding: 0 2rem; 3 | } 4 | 5 | .main { 6 | min-height: 100vh; 7 | padding: 4rem 0; 8 | flex: 1; 9 | display: flex; 10 | flex-direction: column; 11 | justify-content: center; 12 | align-items: center; 13 | } 14 | 15 | .footer { 16 | display: flex; 17 | flex: 1; 18 | padding: 2rem 0; 19 | border-top: 1px solid #eaeaea; 20 | justify-content: center; 21 | align-items: center; 22 | } 23 | 24 | .footer a { 25 | display: flex; 26 | justify-content: center; 27 | align-items: center; 28 | flex-grow: 1; 29 | } 30 | 31 | .title a { 32 | color: #0070f3; 33 | text-decoration: none; 34 | } 35 | 36 | .title a:hover, 37 | .title a:focus, 38 | .title a:active { 39 | text-decoration: underline; 40 | } 41 | 42 | .title { 43 | margin: 0; 44 | line-height: 1.15; 45 | font-size: 4rem; 46 | } 47 | 48 | .title, 49 | .description { 50 | text-align: center; 51 | } 52 | 53 | .description { 54 | margin: 4rem 0; 55 | line-height: 1.5; 56 | font-size: 1.5rem; 57 | } 58 | 59 | .code { 60 | background: #fafafa; 61 | border-radius: 5px; 62 | padding: 0.75rem; 63 | font-size: 1.1rem; 64 | font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, 65 | Bitstream Vera Sans Mono, Courier New, monospace; 66 | } 67 | 68 | .grid { 69 | display: flex; 70 | align-items: center; 71 | justify-content: center; 72 | flex-wrap: wrap; 73 | max-width: 800px; 74 | } 75 | 76 | .card { 77 | margin: 1rem; 78 | padding: 1.5rem; 79 | text-align: left; 80 | color: inherit; 81 | text-decoration: none; 82 | border: 1px solid #eaeaea; 83 | border-radius: 10px; 84 | transition: color 0.15s ease, border-color 0.15s ease; 85 | max-width: 300px; 86 | } 87 | 88 | .card:hover, 89 | .card:focus, 90 | .card:active { 91 | color: #0070f3; 92 | border-color: #0070f3; 93 | } 94 | 95 | .card h2 { 96 | margin: 0 0 1rem 0; 97 | font-size: 1.5rem; 98 | } 99 | 100 | .card p { 101 | margin: 0; 102 | font-size: 1.25rem; 103 | line-height: 1.5; 104 | } 105 | 106 | .logo { 107 | height: 1em; 108 | margin-left: 0.5rem; 109 | } 110 | 111 | @media (max-width: 600px) { 112 | .grid { 113 | width: 100%; 114 | flex-direction: column; 115 | } 116 | } 117 | 118 | @media (prefers-color-scheme: dark) { 119 | .card, 120 | .footer { 121 | border-color: #222; 122 | } 123 | .code { 124 | background: #111; 125 | } 126 | .logo img { 127 | filter: invert(1); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /examples/nextjs/apps/alpha/styles/globals.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | padding: 0; 4 | margin: 0; 5 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, 6 | Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; 7 | } 8 | 9 | a { 10 | color: inherit; 11 | text-decoration: none; 12 | } 13 | 14 | * { 15 | box-sizing: border-box; 16 | } 17 | 18 | @media (prefers-color-scheme: dark) { 19 | html { 20 | color-scheme: dark; 21 | } 22 | body { 23 | color: white; 24 | background: black; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/nextjs/bazel/BUILD.bazel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/examples/nextjs/bazel/BUILD.bazel -------------------------------------------------------------------------------- /examples/nextjs/bazel/jest_test.bzl: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_jest//jest:defs.bzl", _jest_test = "jest_test") 2 | load("//bazel:ts_project.bzl", "ts_project") 3 | 4 | def jest_test(name = "", srcs = [], deps=[], data=[], **kwargs): 5 | """Provides defaults for jest_test""" 6 | 7 | node_modules = kwargs.pop("node_modules", "//:node_modules") 8 | tags = kwargs.pop("tags", ["jest"]) 9 | 10 | # This ensures that the test is typechecked. 11 | ts_project( 12 | name = "%s_js" % name, 13 | srcs = srcs, 14 | deps = deps, 15 | ) 16 | 17 | # However we run the test with the untranspiled srcs. 18 | # This is to ensure that the snapshot filenames match what would 19 | # be used when invoking the test without bazel. 20 | _jest_test( 21 | name = name, 22 | data = srcs + data + ["//:tsconfig"], 23 | node_modules = node_modules, 24 | tags = tags, 25 | **kwargs, 26 | ) 27 | -------------------------------------------------------------------------------- /examples/nextjs/bazel/next.bzl: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_run_binary", "js_run_devserver") 2 | 3 | def next( 4 | name, 5 | srcs, 6 | data, 7 | next_js_binary, 8 | next_bin, 9 | next_build_out = ".next", 10 | next_export_out = "out", 11 | **kwargs): 12 | """Generates Next.js targets build, dev & start targets. 13 | 14 | `{name}` - a js_run_binary build target that runs `next build` 15 | `{name}_dev` - a js_run_devserver binary target that runs `next dev` 16 | `{name}_start` - a js_run_devserver binary target that runs `next start` 17 | 18 | Use this macro in the BUILD file at the root of a next app where the `next.config.js` file is 19 | located. 20 | 21 | For example, a target such as 22 | 23 | ``` 24 | load("//bazel:next.bzl", "next") 25 | 26 | next( 27 | name = "next", 28 | srcs = [ 29 | "//apps/alpha/pages", 30 | "//apps/alpha/public", 31 | "//apps/alpha/styles", 32 | ], 33 | data = [ 34 | "//:node_modules/next", 35 | "//:node_modules/react-dom", 36 | "//:node_modules/react", 37 | "//:node_modules/typescript", 38 | "next.config.js", 39 | "package.json", 40 | ], 41 | next_bin = "../../node_modules/.bin/next", 42 | next_js_binary = "//:next_js_binary", 43 | ) 44 | ``` 45 | 46 | in an `apps/alpha/BUILD.bazel` file where the root `BUILD.bazel` file has 47 | next linked to `node_modules` and the `next_js_binary`: 48 | 49 | ``` 50 | load("@npm//:defs.bzl", "npm_link_all_packages") 51 | load("@npm//:next/package_json.bzl", next_bin = "bin") 52 | 53 | npm_link_all_packages(name = "node_modules") 54 | 55 | next_bin.next_binary( 56 | name = "next_js_binary", 57 | visibility = ["//visibility:public"], 58 | ) 59 | ``` 60 | 61 | will create the targets: 62 | 63 | ``` 64 | //apps/alpha:next 65 | //apps/alpha:next_dev 66 | //apps/alpha:next_start 67 | ``` 68 | 69 | To build the above next app, equivalent to running 70 | `next build` outside Bazel, run, 71 | 72 | ``` 73 | bazel build //apps/alpha:next 74 | ``` 75 | 76 | To run the development server in watch mode with 77 | [ibazel](https://github.com/bazelbuild/bazel-watcher), equivalent to running 78 | `next dev` outside Bazel, run 79 | 80 | ``` 81 | ibazel run //apps/alpha:next_dev 82 | ``` 83 | 84 | To run the production server in watch mode with 85 | [ibazel](https://github.com/bazelbuild/bazel-watcher), equivalent to running 86 | `next start` outside Bazel, 87 | 88 | ``` 89 | ibazel run //apps/alpha:next_start 90 | ``` 91 | 92 | To export the above next app, equivalent to running 93 | `next export` outside Bazel, run, 94 | 95 | ``` 96 | bazel build //apps/alpha:next_export 97 | ``` 98 | 99 | Args: 100 | name: The name of the build target. 101 | 102 | srcs: Source files to include in build & dev targets. 103 | Typically these are source files or transpiled source files in Next.js source folders 104 | such as `pages`, `public` & `styles`. 105 | 106 | data: Data files to include in all targets. 107 | These are typically npm packages required for the build & configuration files such as 108 | package.json and next.config.js. 109 | 110 | next_js_binary: The next js_binary. Used for the `build `target. 111 | 112 | Typically this is a js_binary target created using `bin` loaded from the `package_json.bzl` 113 | file of the npm package. 114 | 115 | See main docstring above for example usage. 116 | 117 | next_bin: The next bin command. Used for the `dev` and `start` targets. 118 | 119 | Typically the path to the next entry point from the current package. For example `./node_modules/.bin/next`, 120 | if next is linked to the current package, or a relative path such as `../node_modules/.bin/next`, if next is 121 | linked in the parent package. 122 | 123 | See main docstring above for example usage. 124 | 125 | next_build_out: The `next build` output directory. Defaults to `.next` which is the Next.js default output directory for the `build` command. 126 | 127 | next_export_out: The `next export` output directory. Defaults to `out` which is the Next.js default output directory for the `export` command. 128 | 129 | **kwargs: Other attributes passed to all targets such as `tags`. 130 | """ 131 | 132 | tags = kwargs.pop("tags", []) 133 | 134 | # `next build` creates an optimized bundle of the application 135 | # https://nextjs.org/docs/api-reference/cli#build 136 | js_run_binary( 137 | name = name, 138 | tool = next_js_binary, 139 | args = ["build"], 140 | srcs = srcs + data, 141 | out_dirs = [next_build_out], 142 | chdir = native.package_name(), 143 | tags = tags, 144 | **kwargs 145 | ) 146 | 147 | # `next dev` runs the application in development mode 148 | # https://nextjs.org/docs/api-reference/cli#development 149 | js_run_devserver( 150 | name = "{}_dev".format(name), 151 | command = next_bin, 152 | args = ["dev"], 153 | data = srcs + data, 154 | chdir = native.package_name(), 155 | tags = tags, 156 | **kwargs 157 | ) 158 | 159 | # `next start` runs the application in production mode 160 | # https://nextjs.org/docs/api-reference/cli#production 161 | js_run_devserver( 162 | name = "{}_start".format(name), 163 | command = next_bin, 164 | args = ["start"], 165 | data = data + [name], 166 | chdir = native.package_name(), 167 | tags = tags, 168 | **kwargs 169 | ) 170 | 171 | # `next export` runs the application in production mode 172 | # https://nextjs.org/docs/api-reference/cli#production 173 | js_run_binary( 174 | name = "{}_export".format(name), 175 | tool = next_js_binary, 176 | args = ["export"], 177 | srcs = data + [name], 178 | out_dirs = [next_export_out], 179 | chdir = native.package_name(), 180 | # Tagged as "manual" since this `next export` writes back to the `.next` directory which causes issues with 181 | # trying to write to an input. See https://github.com/vercel/next.js/issues/43344. 182 | # TODO: fix in Next.js (https://github.com/vercel/next.js/issues/43344) or find work-around. 183 | tags = tags + ["manual"], 184 | **kwargs 185 | ) 186 | -------------------------------------------------------------------------------- /examples/nextjs/bazel/ts_project.bzl: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", _ts_project = "ts_project") 2 | 3 | def ts_project(**kwargs): 4 | """Provides defaults for ts_project""" 5 | 6 | declaration = kwargs.pop("declaration", True) 7 | resolve_json_module = kwargs.pop("resolve_json_module", True) 8 | tsconfig = kwargs.pop("tsconfig", "//:tsconfig") 9 | 10 | 11 | _ts_project( 12 | declaration = declaration, 13 | resolve_json_module = resolve_json_module, 14 | tsconfig = tsconfig, 15 | **kwargs, 16 | ) 17 | -------------------------------------------------------------------------------- /examples/nextjs/bazel/web_assets.bzl: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | 3 | def web_assets(**kwargs): 4 | """Maps web_assets to js_library""" 5 | js_library(**kwargs) 6 | -------------------------------------------------------------------------------- /examples/nextjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Next.js Bazel example", 3 | "private": true, 4 | "scripts": { 5 | "dev": "ibazel run //apps/alpha:next_dev", 6 | "build": "bazel build //apps/alpha:next", 7 | "export": "bazel build //apps/alpha:next_export", 8 | "start": "ibazel run //apps/alpha:next_start", 9 | "lint": "bazel test //apps/alpha/... --test_tag_filters=lint --build_tests_only", 10 | "test": "bazel test //apps/alpha/... --test_tag_filters=jest --build_tests_only" 11 | }, 12 | "dependencies": { 13 | "next": "13.0.5", 14 | "react": "18.2.0", 15 | "react-dom": "18.2.0", 16 | "@nextjs-example/one": "workspace:*" 17 | }, 18 | "devDependencies": { 19 | "@bazel/ibazel": "0.16.2", 20 | "@testing-library/jest-dom": "4.2.4", 21 | "@testing-library/react": "13.4.0", 22 | "@types/jest": "29.2.3", 23 | "@types/node": "18.11.9", 24 | "@types/react": "18.0.25", 25 | "@types/react-dom": "18.0.9", 26 | "eslint": "8.28.0", 27 | "eslint-config-next": "13.0.5", 28 | "jest-cli": "29.5.0", 29 | "jest-junit": "16.0.0", 30 | "jest-environment-jsdom": "29.5.0", 31 | "jest-transform-stub": "2.0.0", 32 | "typescript": "4.9.3" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/nextjs/packages/one/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("//bazel:ts_project.bzl", "ts_project") 3 | load("@aspect_rules_js//npm:defs.bzl", "npm_package") 4 | load("@npm//:defs.bzl", "npm_link_all_packages") 5 | 6 | # gazelle:js_collect_all 7 | 8 | # gazelle:js_package_file package.json :node_modules 9 | # gazelle:js_root 10 | 11 | # gazelle:js_visibility //packages/one:__subpackages__ 12 | 13 | npm_link_all_packages(name = "node_modules") 14 | 15 | # make this library available via node_modules 16 | npm_package( 17 | name = "one", 18 | srcs = [ 19 | ":one_ts", 20 | ":package_json", 21 | ], 22 | # This is a perf improvement; the default will be flipped to False in rules_js 2.0 23 | # include_runfiles = False, 24 | visibility = ["//visibility:public"], 25 | ) 26 | 27 | ts_project( 28 | name = "one_ts", 29 | srcs = ["src/main.ts"], 30 | data = ["//packages/one:node_modules/is-odd"], 31 | visibility = ["//packages/one:__subpackages__"], 32 | deps = [ 33 | "//packages/one:node_modules/@types/is-odd", 34 | "//packages/one:node_modules/is-odd", 35 | ], 36 | ) 37 | 38 | js_library( 39 | name = "package_json", 40 | srcs = ["package.json"], 41 | visibility = ["//packages/one:__subpackages__"], 42 | ) 43 | -------------------------------------------------------------------------------- /examples/nextjs/packages/one/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nextjs-example/one", 3 | "private": true, 4 | "main": "src/main.js", 5 | "dependencies": { 6 | "@types/is-odd": "3.x.x", 7 | "is-odd": "3.x.x" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/nextjs/packages/one/src/main.ts: -------------------------------------------------------------------------------- 1 | import isOdd from 'is-odd'; 2 | 3 | export function one() { 4 | return `I am One, not Two! Am I odd? ${isOdd(1)}`; 5 | } 6 | -------------------------------------------------------------------------------- /examples/nextjs/pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'apps/*' 3 | - 'packages/*' 4 | -------------------------------------------------------------------------------- /examples/nextjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "declaration": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "esModuleInterop": true, 10 | "module": "commonjs", 11 | "moduleResolution": "node", 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "jsx": "react-jsx" 15 | }, 16 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], 17 | "exclude": ["node_modules"] 18 | } 19 | -------------------------------------------------------------------------------- /gazelle/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Bazel Authors. All rights reserved. 2 | # Modifications copyright (C) 2021 BenchSci Analytics Inc. 3 | # Modifications copyright (C) 2018 Ecosia GmbH 4 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 18 | 19 | go_library( 20 | name = "gazelle", 21 | srcs = [ 22 | "colors.go", 23 | "configure.go", 24 | "generate.go", 25 | "kinds.go", 26 | "lang.go", 27 | "parse.go", 28 | "pkgname.go", 29 | "resolve.go", 30 | ], 31 | importpath = "github.com/benchsci/rules_nodejs_gazelle/gazelle", 32 | visibility = ["//visibility:public"], 33 | deps = [ 34 | "@bazel_gazelle//config:go_default_library", 35 | "@bazel_gazelle//label:go_default_library", 36 | "@bazel_gazelle//language:go_default_library", 37 | "@bazel_gazelle//repo:go_default_library", 38 | "@bazel_gazelle//resolve:go_default_library", 39 | "@bazel_gazelle//rule:go_default_library", 40 | "@com_github_bazelbuild_buildtools//labels:go_default_library", 41 | ], 42 | ) 43 | 44 | go_test( 45 | name = "gazelle_test", 46 | srcs = [ 47 | "generate_test.go", 48 | "parse_test.go", 49 | "pkgname_test.go", 50 | ], 51 | embed = [":gazelle"], 52 | ) 53 | -------------------------------------------------------------------------------- /gazelle/colors.go: -------------------------------------------------------------------------------- 1 | package js 2 | 3 | import "fmt" 4 | 5 | var ( 6 | Black = Color("\033[1;30m%s\033[0m") 7 | Red = Color("\033[1;31m%s\033[0m") 8 | Green = Color("\033[1;32m%s\033[0m") 9 | Yellow = Color("\033[1;33m%s\033[0m") 10 | Purple = Color("\033[1;34m%s\033[0m") 11 | Magenta = Color("\033[1;35m%s\033[0m") 12 | Teal = Color("\033[1;36m%s\033[0m") 13 | White = Color("\033[1;37m%s\033[0m") 14 | ) 15 | 16 | var ( 17 | Info = Teal 18 | Warn = Yellow 19 | Err = Red 20 | ) 21 | 22 | func Color(colorString string) func(string, ...interface{}) string { 23 | return func(format string, args ...interface{}) string { 24 | return fmt.Sprintf(colorString, fmt.Sprintf(format, args...)) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /gazelle/generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // Modifications copyright (C) 2021 BenchSci Analytics Inc. 3 | // Modifications copyright (C) 2018 Ecosia GmbH 4 | 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | package js 18 | 19 | import ( 20 | "testing" 21 | ) 22 | 23 | func TestPattern(t *testing.T) { 24 | t.Logf("%v", indexFilePattern) 25 | if !indexFilePattern.MatchString("index.jsx") { 26 | t.FailNow() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /gazelle/kinds.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // Modifications copyright (C) 2021 BenchSci Analytics Inc. 3 | // Modifications copyright (C) 2018 Ecosia GmbH 4 | 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | package js 18 | 19 | import ( 20 | "github.com/bazelbuild/bazel-gazelle/rule" 21 | ) 22 | 23 | // Kinds returns a map of maps rule names (kinds) and information on how to 24 | // match and merge attributes that may be found in rules of those kinds. All 25 | // kinds of rules generated for this language may be found here. 26 | func (*JS) Kinds() map[string]rule.KindInfo { 27 | return map[string]rule.KindInfo{ 28 | "js_library": { 29 | MatchAny: false, 30 | NonEmptyAttrs: map[string]bool{ 31 | "srcs": true, 32 | }, 33 | MergeableAttrs: map[string]bool{ 34 | "srcs": true, 35 | "tags": true, 36 | }, 37 | ResolveAttrs: map[string]bool{ 38 | "deps": true, 39 | "data": true, 40 | }, 41 | }, 42 | "ts_project": { 43 | MatchAny: false, 44 | NonEmptyAttrs: map[string]bool{ 45 | "srcs": true, 46 | }, 47 | MergeableAttrs: map[string]bool{ 48 | "srcs": true, 49 | "tags": true, 50 | }, 51 | ResolveAttrs: map[string]bool{ 52 | "deps": true, 53 | "data": true, 54 | }, 55 | }, 56 | "ts_definition": { 57 | MatchAny: false, 58 | NonEmptyAttrs: map[string]bool{ 59 | "srcs": true, 60 | }, 61 | MergeableAttrs: map[string]bool{ 62 | "srcs": true, 63 | "tags": true, 64 | }, 65 | ResolveAttrs: map[string]bool{ 66 | "deps": true, 67 | "data": true, 68 | }, 69 | }, 70 | "jest_test": { 71 | MatchAny: false, 72 | NonEmptyAttrs: map[string]bool{ 73 | "srcs": true, 74 | }, 75 | MergeableAttrs: map[string]bool{ 76 | "srcs": true, 77 | "tags": true, 78 | }, 79 | ResolveAttrs: map[string]bool{ 80 | "deps": true, 81 | "data": true, 82 | }, 83 | }, 84 | "web_asset": { 85 | MatchAny: false, 86 | NonEmptyAttrs: map[string]bool{ 87 | "srcs": true, 88 | }, 89 | MergeableAttrs: map[string]bool{ 90 | "srcs": true, 91 | "tags": true, 92 | }, 93 | }, 94 | "web_assets": { 95 | MatchAny: false, 96 | NonEmptyAttrs: map[string]bool{ 97 | "srcs": true, 98 | }, 99 | MergeableAttrs: map[string]bool{ 100 | "srcs": true, 101 | "tags": true, 102 | }, 103 | }, 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /gazelle/lang.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // Modifications copyright (C) 2021 BenchSci Analytics Inc. 3 | // Modifications copyright (C) 2018 Ecosia GmbH 4 | 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | package js 18 | 19 | import ( 20 | "github.com/bazelbuild/bazel-gazelle/language" 21 | ) 22 | 23 | const languageName = "js" 24 | 25 | // Name returns the name of the language. This should be a prefix of the 26 | // kinds of rules generated by the language, e.g., "go" for the Go extension 27 | // since it generates "go_library" rules. 28 | func (*JS) Name() string { 29 | return "js" 30 | } 31 | 32 | type JS struct { 33 | } 34 | 35 | func NewLanguage() language.Language { 36 | return &JS{} 37 | } 38 | -------------------------------------------------------------------------------- /gazelle/parse.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // Modifications copyright (C) 2021 BenchSci Analytics Inc. 3 | // Modifications copyright (C) 2018 Ecosia GmbH 4 | 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | package js 18 | 19 | import ( 20 | "bytes" 21 | "fmt" 22 | "regexp" 23 | "sort" 24 | "strconv" 25 | "strings" 26 | ) 27 | 28 | var quotePattern = regexp.MustCompile(`([/][/].*)|(?:[/][*](?:\n|.)*?[*][/])`) 29 | 30 | func ParseJS(data []byte) ([]string, int, error) { 31 | 32 | lastCommentMatchIndex := 0 33 | codeBlocks := make([][]int, 0) 34 | for _, match := range quotePattern.FindAllIndex(data, -1) { 35 | codeBlocks = append(codeBlocks, []int{lastCommentMatchIndex, match[0]}) 36 | lastCommentMatchIndex = match[1] 37 | } 38 | codeBlocks = append(codeBlocks, []int{lastCommentMatchIndex, len(data)}) 39 | 40 | imports := make([]string, 0) 41 | jestTestCount := 0 42 | 43 | for _, block := range codeBlocks { 44 | blockImports, blockTestCount, err := parseCodeBlock(data[block[0]:block[1]]) 45 | if err != nil { 46 | return nil, 0, err 47 | } 48 | imports = append(imports, blockImports...) 49 | jestTestCount += blockTestCount 50 | } 51 | sort.Strings(imports) 52 | 53 | return imports, jestTestCount, nil 54 | } 55 | 56 | const ( 57 | IMPORT = 1 58 | REQUIRE = 2 59 | EXPORT = 3 60 | JEST_MOCK = 4 61 | DYNAMIC_IMPORT = 5 62 | ) 63 | 64 | var jsImportPattern = compileJsImportPattern() 65 | 66 | func compileJsImportPattern() *regexp.Regexp { 67 | stringLiteralPattern := `'(?:[^\n]+|")*'|"(?:[^\n]+|')*"` 68 | importPattern := `^import\s(?:(?:.|\n)+?from )??(?P` + stringLiteralPattern + `)` 69 | requirePattern := `^\s*?(?:const .+ = )?require\((?P` + stringLiteralPattern + `)\)` 70 | exportPattern := `^export\s(?:(?:.|\n)+?from )??(?P` + stringLiteralPattern + `)` 71 | jestMockPattern := `^\s*?(?:const .+ = )?jest.mock\((?P` + stringLiteralPattern + `),` 72 | dynamicImportPattern := `^.*?import\((?P` + stringLiteralPattern + `)\)` 73 | return regexp.MustCompile(`(?m)` + strings.Join([]string{importPattern, requirePattern, exportPattern, jestMockPattern, dynamicImportPattern}, "|")) 74 | } 75 | 76 | var jestTestPattern = regexp.MustCompile(`(?m)^\s*it\(`) 77 | 78 | func parseCodeBlock(data []byte) ([]string, int, error) { 79 | 80 | imports := make([]string, 0) 81 | for _, match := range jsImportPattern.FindAllSubmatch(data, -1) { 82 | switch { 83 | case match[IMPORT] != nil: 84 | unquoted, err := unquoteImportString(match[IMPORT]) 85 | if err != nil { 86 | return nil, 0, fmt.Errorf("unquoting string literal %s from js, %v", match[IMPORT], err) 87 | } 88 | imports = append(imports, unquoted) 89 | 90 | case match[REQUIRE] != nil: 91 | unquoted, err := unquoteImportString(match[REQUIRE]) 92 | if err != nil { 93 | return nil, 0, fmt.Errorf("unquoting string literal %s from js, %v", match[REQUIRE], err) 94 | } 95 | imports = append(imports, unquoted) 96 | 97 | case match[EXPORT] != nil: 98 | unquoted, err := unquoteImportString(match[EXPORT]) 99 | if err != nil { 100 | return nil, 0, fmt.Errorf("unquoting string literal %s from js, %v", match[EXPORT], err) 101 | } 102 | imports = append(imports, unquoted) 103 | 104 | case match[JEST_MOCK] != nil: 105 | unquoted, err := unquoteImportString(match[JEST_MOCK]) 106 | if err != nil { 107 | return nil, 0, fmt.Errorf("unquoting string literal %s from js, %v", match[JEST_MOCK], err) 108 | } 109 | imports = append(imports, unquoted) 110 | 111 | case match[DYNAMIC_IMPORT] != nil: 112 | unquoted, err := unquoteImportString(match[DYNAMIC_IMPORT]) 113 | if err != nil { 114 | return nil, 0, fmt.Errorf("unquoting string literal %s from js, %v", match[DYNAMIC_IMPORT], err) 115 | } 116 | imports = append(imports, unquoted) 117 | 118 | default: 119 | // Comment matched. Nothing to extract. 120 | } 121 | } 122 | sort.Strings(imports) 123 | 124 | jestTestCount := len(jestTestPattern.FindAll(data, -1)) 125 | 126 | return imports, jestTestCount, nil 127 | } 128 | 129 | // unquoteImportString takes a string that has a complex quoting around it 130 | // and returns a string without the complex quoting. 131 | func unquoteImportString(quoted []byte) (string, error) { 132 | // Adjust quotes so that Unquote is happy. We need a double quoted string 133 | // without unescaped double quote characters inside. 134 | noQuotes := bytes.Split(quoted[1:len(quoted)-1], []byte{'"'}) 135 | if len(noQuotes) != 1 { 136 | for i := 0; i < len(noQuotes)-1; i++ { 137 | if len(noQuotes[i]) == 0 || noQuotes[i][len(noQuotes[i])-1] != '\\' { 138 | noQuotes[i] = append(noQuotes[i], '\\') 139 | } 140 | } 141 | quoted = append([]byte{'"'}, bytes.Join(noQuotes, []byte{'"'})...) 142 | quoted = append(quoted, '"') 143 | } 144 | if quoted[0] == '\'' { 145 | quoted[0] = '"' 146 | quoted[len(quoted)-1] = '"' 147 | } 148 | 149 | result, err := strconv.Unquote(string(quoted)) 150 | if err != nil { 151 | return "", fmt.Errorf("unquoting string literal %s from js: %v", quoted, err) 152 | } 153 | return result, err 154 | } 155 | -------------------------------------------------------------------------------- /gazelle/parse_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // Modifications copyright (C) 2021 BenchSci Analytics Inc. 3 | // Modifications copyright (C) 2018 Ecosia GmbH 4 | 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | package js 18 | 19 | import ( 20 | "reflect" 21 | "testing" 22 | ) 23 | 24 | func TestParseJS(t *testing.T) { 25 | for _, tc := range []struct { 26 | desc, name, js string 27 | want []string 28 | }{ 29 | { 30 | desc: "empty", 31 | name: "empty^file.js", 32 | js: "", 33 | want: []string{}, 34 | }, 35 | { 36 | desc: "import single quote", 37 | name: "single.js", 38 | js: `export * from 'date-fns';`, 39 | want: []string{"date-fns"}, 40 | }, 41 | { 42 | desc: "import single quote", 43 | name: "single.js", 44 | js: `import dateFns from 'date-fns';`, 45 | want: []string{"date-fns"}, 46 | }, 47 | { 48 | desc: "import double quote", 49 | name: "double.sass", 50 | js: `import dateFns from "date-fns";`, 51 | want: []string{"date-fns"}, 52 | }, { 53 | desc: "import two", 54 | name: "two.sass", 55 | js: `import {format} from 'date-fns' 56 | import Puppy from '@/components/Puppy';`, 57 | want: []string{"@/components/Puppy", "date-fns"}, 58 | }, { 59 | desc: "import dynamic", 60 | name: "dynamic.ts", 61 | js: `let lamdba = () => import('./b').do_something("something")`, 62 | want: []string{"./b"}, 63 | }, { 64 | desc: "import special chars", 65 | name: "page.js", 66 | js: `import BlogPage from "@/app/(auth)/blog/[slug]/page";`, 67 | want: []string{"@/app/(auth)/blog/[slug]/page"}, 68 | }, { 69 | desc: "import depth", 70 | name: "deep.sass", 71 | js: `import package from "from/internal/package";`, 72 | want: []string{"from/internal/package"}, 73 | }, { 74 | desc: "import multiline", 75 | name: "multiline.js", 76 | js: `import {format} from 'date-fns' 77 | import { 78 | CONST1, 79 | CONST2, 80 | CONST3, 81 | } from '~/constants';`, 82 | want: []string{"date-fns", "~/constants"}, 83 | }, 84 | { 85 | desc: "simple require", 86 | name: "require.js", 87 | js: `const a = require("date-fns");`, 88 | want: []string{"date-fns"}, 89 | }, 90 | { 91 | desc: "ignores incorrect imports", 92 | name: "incorrect.js", 93 | js: `@import "~mapbox.js/dist/mapbox.css";`, 94 | want: []string{}, 95 | }, 96 | { 97 | desc: "ignores commented out imports", 98 | name: "comment.js", 99 | js: ` 100 | // takes ?inline out of the aliased import path, only if it's set 101 | // e.g. ~/path/to/file.svg?inline -> ~/path/to/file.svg 102 | '^~/(.+\\.svg)(\\?inline)?$': '$1', 103 | // const a = require("date-fns"); 104 | // import {format} from 'date-fns'; 105 | `, 106 | want: []string{}, 107 | }, 108 | { 109 | desc: "full import", 110 | name: "comment.js", 111 | js: `import "mypolyfill"; 112 | import "mypolyfill2";`, 113 | want: []string{"mypolyfill", "mypolyfill2"}, 114 | }, 115 | { 116 | desc: "full require", 117 | name: "full_require.js", 118 | js: `require("mypolyfill2");`, 119 | want: []string{"mypolyfill2"}, 120 | }, 121 | { 122 | desc: "imports and full imports", 123 | name: "mixed_imports.js", 124 | js: `import Vuex, { Store } from 'vuex'; 125 | import { createLocalVue, shallowMount } from '@vue/test-utils'; 126 | 127 | import '~/plugins/intersection-observer-polyfill'; 128 | import '~/plugins/intersect-directive'; 129 | import ClaimsSection from './claims-section'; 130 | `, 131 | want: []string{"./claims-section", "@vue/test-utils", "vuex", "~/plugins/intersect-directive", "~/plugins/intersection-observer-polyfill"}, 132 | }, 133 | { 134 | desc: "dynamic require", 135 | name: "dynamic_require.js", 136 | js: ` 137 | if (process.ENV.SHOULD_IMPORT) { 138 | // const old = require('oldmapbox.js'); 139 | const leaflet = require('mapbox.js'); 140 | } 141 | `, 142 | want: []string{"mapbox.js"}, 143 | }, 144 | { 145 | desc: "dynamic import", 146 | name: "dynamic_import.js", 147 | js: ` () => import('dynamic_module.js'); 148 | const foo = import('dynamic_module2.js')`, 149 | want: []string{"dynamic_module.js", "dynamic_module2.js"}, 150 | }, 151 | } { 152 | t.Run(tc.desc, func(t *testing.T) { 153 | 154 | imports, _, err := ParseJS([]byte(tc.js)) 155 | if err != nil { 156 | t.Error(err) 157 | t.FailNow() 158 | } 159 | 160 | if !reflect.DeepEqual(imports, tc.want) { 161 | t.Errorf("Inequalith.\ngot %#v;\nwant %#v", imports, tc.want) 162 | } 163 | }) 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /gazelle/pkgname.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // Modifications copyright (C) 2021 BenchSci Analytics Inc. 3 | // Modifications copyright (C) 2018 Ecosia GmbH 4 | 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | package js 18 | 19 | import "strings" 20 | 21 | func PkgName(dirpath string) string { 22 | dirpath = strings.TrimRight(dirpath, "/") 23 | n := len(dirpath) - 1 24 | for i := n; i >= 0; i-- { 25 | if dirpath[i] == '/' { 26 | return dirpath[i+1 : n+1] 27 | } 28 | } 29 | return dirpath 30 | } 31 | -------------------------------------------------------------------------------- /gazelle/pkgname_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // Modifications copyright (C) 2021 BenchSci Analytics Inc. 3 | // Modifications copyright (C) 2018 Ecosia GmbH 4 | 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | package js 18 | 19 | import ( 20 | "testing" 21 | ) 22 | 23 | func TestDirnameRel(t *testing.T) { 24 | input := "foo/bar/baz" 25 | expected := "baz" 26 | if result := PkgName(input); result != expected { 27 | t.Logf("expected %s, got %s", expected, result) 28 | t.FailNow() 29 | } 30 | } 31 | 32 | func TestDirnameAbs(t *testing.T) { 33 | input := "/abc/def/ghi" 34 | expected := "ghi" 35 | if result := PkgName(input); result != expected { 36 | t.Logf("expected %s, got %s", expected, result) 37 | t.FailNow() 38 | } 39 | } 40 | func TestDirnameTrailing(t *testing.T) { 41 | input := "abc/def/ghi/" 42 | expected := "ghi" 43 | if result := PkgName(input); result != expected { 44 | t.Logf("expected %s, got %s", expected, result) 45 | t.FailNow() 46 | } 47 | } 48 | 49 | func TestDirnameSingle(t *testing.T) { 50 | input := "abc" 51 | expected := "abc" 52 | if result := PkgName(input); result != expected { 53 | t.Logf("expected %s, got %s", expected, result) 54 | t.FailNow() 55 | } 56 | } 57 | 58 | func TestDirnameSingleAbs(t *testing.T) { 59 | input := "/abc" 60 | expected := "abc" 61 | if result := PkgName(input); result != expected { 62 | t.Logf("expected %s, got %s", expected, result) 63 | t.FailNow() 64 | } 65 | } 66 | 67 | func TestDirnameSingleTrailing(t *testing.T) { 68 | input := "/abc/" 69 | expected := "abc" 70 | if result := PkgName(input); result != expected { 71 | t.Logf("expected %s, got %s", expected, result) 72 | t.FailNow() 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/bazelbuild/rules_python 2 | 3 | go 1.21 4 | 5 | toolchain go1.23.2 6 | 7 | require ( 8 | github.com/bazelbuild/bazel-gazelle v0.34.0 9 | github.com/bazelbuild/buildtools v0.0.0-20231017121127-23aa65d4e117 10 | github.com/bazelbuild/rules_go v0.42.0 11 | ) 12 | 13 | require ( 14 | github.com/google/go-cmp v0.6.0 // indirect 15 | golang.org/x/mod v0.14.0 // indirect 16 | golang.org/x/sys v0.14.0 // indirect 17 | golang.org/x/tools/go/vcs v0.1.0-deprecated // indirect 18 | ) 19 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 3 | github.com/bazelbuild/bazel-gazelle v0.34.0 h1:YHkwssgvCXDRU7sLCq1kGqaGYO9pKNR1Wku7UT2LhoY= 4 | github.com/bazelbuild/bazel-gazelle v0.34.0/go.mod h1:3wXzAC5rTs8eTQ+t+eTqleUE9W4dDComgXgqDjnI5s4= 5 | github.com/bazelbuild/buildtools v0.0.0-20231017121127-23aa65d4e117 h1:VUHCI4QRifAGYsbVJYqJndLf7YqV12YthB+PLFsEKqo= 6 | github.com/bazelbuild/buildtools v0.0.0-20231017121127-23aa65d4e117/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo= 7 | github.com/bazelbuild/rules_go v0.42.0 h1:aY2smc3JWyUKOjGYmOKVLX70fPK9ON0rtwQojuIeUHc= 8 | github.com/bazelbuild/rules_go v0.42.0/go.mod h1:TMHmtfpvyfsxaqfL9WnahCsXMWDMICTw7XeK9yVb+YU= 9 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 10 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= 11 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= 12 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= 13 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 14 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 15 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 16 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 17 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 18 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 19 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 20 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 21 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 22 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 23 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 24 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 25 | github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= 26 | github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 27 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 28 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 29 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 30 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 31 | github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 32 | github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 33 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 34 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 35 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 36 | go.starlark.net v0.0.0-20210223155950-e043a3d3c984/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0= 37 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 38 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 39 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 40 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 41 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 42 | golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= 43 | golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= 44 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 45 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 46 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 47 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 48 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 49 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 50 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 51 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 52 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 53 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 54 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 55 | golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= 56 | golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 57 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 58 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 59 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 60 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 61 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 62 | golang.org/x/tools/go/vcs v0.1.0-deprecated h1:cOIJqWBl99H1dH5LWizPa+0ImeeJq3t3cJjaeOWUAL4= 63 | golang.org/x/tools/go/vcs v0.1.0-deprecated/go.mod h1:zUrvATBAvEI9535oC0yWYsLsHIV4Z7g63sNPVMtuBy8= 64 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 65 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 66 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 67 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 68 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 69 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 70 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= 71 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 72 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 73 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 74 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 75 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 76 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 77 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 78 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 79 | google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 80 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 81 | google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 82 | google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= 83 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 84 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 85 | -------------------------------------------------------------------------------- /internal/BUILD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/internal/BUILD -------------------------------------------------------------------------------- /internal/web_assets.bzl: -------------------------------------------------------------------------------- 1 | """web_assets 2 | 3 | This is a simple macro for "web_assets" that echo's "js_library" 4 | This is kept seperate so that users can override it with gazelle's map_kind directive 5 | """ 6 | load("@aspect_rules_js//js:defs.bzl", "js_library") 7 | 8 | def web_assets(**kwargs): 9 | js_library(**kwargs) 10 | -------------------------------------------------------------------------------- /tests/BUILD: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") 2 | 3 | # Copyright 2019 The Bazel Authors. All rights reserved. 4 | # Modifications copyright (C) 2021 BenchSci Analytics Inc. 5 | # Modifications copyright (C) 2018 Ecosia GmbH 6 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | 19 | go_library( 20 | name = "tests_lib", 21 | testonly = True, 22 | srcs = ["test_runner.go"], 23 | importpath = "github.com/benchsci/rules_nodejs_gazelle/tests", 24 | visibility = ["//visibility:private"], 25 | deps = [ 26 | "@bazel_gazelle//testtools:go_default_library", 27 | "@io_bazel_rules_go//go/tools/bazel:go_default_library", 28 | ], 29 | ) 30 | 31 | go_binary( 32 | name = "test_runner", 33 | testonly = True, 34 | data = ["//:test_gazelle_bin"], 35 | embed = [":tests_lib"], 36 | visibility = ["//visibility:private"], 37 | ) 38 | 39 | [ 40 | sh_test( 41 | name = "%s_test" % t, 42 | srcs = [":test_runner"], 43 | args = [t], 44 | data = glob(["%s/**" % t]), 45 | ) 46 | for t in [ 47 | "collect_all", 48 | "collect_all_nested", 49 | "collect_all_test_shards", 50 | "collect_asset_modules", 51 | "collect_asset_singletons", 52 | "collect_targets", 53 | "default_npm_label", 54 | "disabled", 55 | "disjoint_module", 56 | "dynamic_import", 57 | "fix", 58 | "import_alias", 59 | "jest_mock", 60 | "jsx_conversion", 61 | "lookup_types", 62 | "module_self_import", 63 | "react_example", 64 | "simple_barrel", 65 | "simple_library", 66 | "simple_npm_library", 67 | "ts_conversion", 68 | "visibility", 69 | "web_assets_module", 70 | "monorepo", 71 | ] 72 | ] 73 | -------------------------------------------------------------------------------- /tests/collect_all/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_jest_config :jest.config 3 | # gazelle:js_quiet 4 | -------------------------------------------------------------------------------- /tests/collect_all/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | # gazelle:js_jest_config :jest.config 6 | # gazelle:js_quiet 7 | 8 | ts_project( 9 | name = "index", 10 | srcs = ["index.ts"], 11 | deps = ["//my_module"], 12 | ) 13 | 14 | ts_project( 15 | name = "some_other_file", 16 | srcs = ["some_other_file.ts"], 17 | ) 18 | 19 | js_library( 20 | name = "jest.config", 21 | srcs = ["jest.config.js"], 22 | ) -------------------------------------------------------------------------------- /tests/collect_all/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "simple_module") 2 | -------------------------------------------------------------------------------- /tests/collect_all/index.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from "./my_module/nested_module" 2 | 3 | var _ = some_var 4 | -------------------------------------------------------------------------------- /tests/collect_all/jest.config.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_all/jest.config.js -------------------------------------------------------------------------------- /tests/collect_all/my_module/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_collect_all 2 | # gazelle:js_jest_size large 3 | -------------------------------------------------------------------------------- /tests/collect_all/my_module/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | load("@rules_jest//jest:defs.bzl", "jest_test") 3 | 4 | # gazelle:js_collect_all 5 | # gazelle:js_jest_size large 6 | 7 | jest_test( 8 | name = "my_module_test", 9 | size = "large", 10 | srcs = [ 11 | "nested_module/a.test.ts", 12 | "nested_module/b.test.ts", 13 | ], 14 | config = "//:jest.config", 15 | data = ["//:package_json"], 16 | ) 17 | 18 | ts_project( 19 | name = "my_module", 20 | srcs = [ 21 | "index.ts", 22 | "module_file.ts", 23 | "nested_module/index.ts", 24 | "nested_module/module_file.ts", 25 | "some_other_file.ts", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /tests/collect_all/my_module/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./module_file" 2 | -------------------------------------------------------------------------------- /tests/collect_all/my_module/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/collect_all/my_module/nested_module/a.test.ts: -------------------------------------------------------------------------------- 1 | // Empty file -------------------------------------------------------------------------------- /tests/collect_all/my_module/nested_module/b.test.ts: -------------------------------------------------------------------------------- 1 | // Empty file -------------------------------------------------------------------------------- /tests/collect_all/my_module/nested_module/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./module_file" 2 | -------------------------------------------------------------------------------- /tests/collect_all/my_module/nested_module/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/collect_all/my_module/some_other_file.ts: -------------------------------------------------------------------------------- 1 | export var baz = "qux" 2 | -------------------------------------------------------------------------------- /tests/collect_all/some_other_file.ts: -------------------------------------------------------------------------------- 1 | export var foo = "bar" 2 | -------------------------------------------------------------------------------- /tests/collect_all_nested/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_jest_config :jest.config 3 | # gazelle:js_quiet 4 | -------------------------------------------------------------------------------- /tests/collect_all_nested/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | # gazelle:js_jest_config :jest.config 6 | # gazelle:js_quiet 7 | 8 | ts_project( 9 | name = "index", 10 | srcs = ["index.ts"], 11 | deps = ["//my_module"], 12 | ) 13 | 14 | ts_project( 15 | name = "some_other_file", 16 | srcs = ["some_other_file.ts"], 17 | ) 18 | 19 | js_library( 20 | name = "jest.config", 21 | srcs = ["jest.config.js"], 22 | ) -------------------------------------------------------------------------------- /tests/collect_all_nested/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "simple_module") 2 | -------------------------------------------------------------------------------- /tests/collect_all_nested/index.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from "./my_module/nested_module" 2 | 3 | var _ = some_var 4 | -------------------------------------------------------------------------------- /tests/collect_all_nested/jest.config.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_all_nested/jest.config.js -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_collect_all 2 | # gazelle:js_jest_size large 3 | -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | load("@rules_jest//jest:defs.bzl", "jest_test") 3 | 4 | # gazelle:js_collect_all 5 | # gazelle:js_jest_size large 6 | 7 | jest_test( 8 | name = "my_module_test", 9 | size = "large", 10 | srcs = [ 11 | "nested_module/a.test.ts", 12 | "nested_module/b.test.ts", 13 | ], 14 | config = "//:jest.config", 15 | data = ["//:package_json"], 16 | ) 17 | 18 | ts_project( 19 | name = "my_module", 20 | srcs = [ 21 | "index.ts", 22 | "module_file.ts", 23 | "nested_module/index.ts", 24 | "nested_module/module_file.ts", 25 | "some_other_file.ts", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./module_file" 2 | -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/nested_module/a.test.ts: -------------------------------------------------------------------------------- 1 | // Empty file -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/nested_module/b.test.ts: -------------------------------------------------------------------------------- 1 | // Empty file -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/nested_module/double_nested_module/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_collect_all 2 | # gazelle:js_jest_size large 3 | -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/nested_module/double_nested_module/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | load("@rules_jest//jest:defs.bzl", "jest_test") 3 | 4 | # gazelle:js_collect_all 5 | # gazelle:js_jest_size large 6 | 7 | jest_test( 8 | name = "double_nested_module_test", 9 | size = "large", 10 | srcs = [ 11 | "a.test.ts", 12 | "b.test.ts", 13 | ], 14 | config = "//:jest.config", 15 | data = ["//:package_json"], 16 | ) 17 | 18 | ts_project( 19 | name = "double_nested_module", 20 | srcs = [ 21 | "index.ts", 22 | "module_file.ts", 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/nested_module/double_nested_module/a.test.ts: -------------------------------------------------------------------------------- 1 | // Empty file -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/nested_module/double_nested_module/b.test.ts: -------------------------------------------------------------------------------- 1 | // Empty file -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/nested_module/double_nested_module/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./module_file" 2 | -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/nested_module/double_nested_module/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/nested_module/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./module_file" 2 | -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/nested_module/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/collect_all_nested/my_module/some_other_file.ts: -------------------------------------------------------------------------------- 1 | export var baz = "qux" 2 | -------------------------------------------------------------------------------- /tests/collect_all_nested/some_other_file.ts: -------------------------------------------------------------------------------- 1 | export var foo = "bar" 2 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_jest_config :jest.config 3 | # gazelle:js_quiet 4 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | # gazelle:js_jest_config :jest.config 6 | # gazelle:js_quiet 7 | 8 | ts_project( 9 | name = "index", 10 | srcs = ["index.ts"], 11 | deps = ["//my_module"], 12 | ) 13 | 14 | ts_project( 15 | name = "some_other_file", 16 | srcs = ["some_other_file.ts"], 17 | ) 18 | 19 | js_library( 20 | name = "jest.config", 21 | srcs = ["jest.config.js"], 22 | ) -------------------------------------------------------------------------------- /tests/collect_all_test_shards/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "simple_module") 2 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/index.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from "./my_module/nested_module" 2 | 3 | var _ = some_var 4 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/jest.config.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_all_test_shards/jest.config.js -------------------------------------------------------------------------------- /tests/collect_all_test_shards/my_module/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_collect_all 2 | # gazelle:js_jest_size small 3 | # gazelle:js_jest_test_per_shard 2 4 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/my_module/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | load("@rules_jest//jest:defs.bzl", "jest_test") 3 | 4 | # gazelle:js_collect_all 5 | # gazelle:js_jest_size small 6 | # gazelle:js_jest_test_per_shard 2 7 | 8 | jest_test( 9 | name = "my_module_test", 10 | size = "small", 11 | srcs = [ 12 | "nested_module/a.test.ts", 13 | "nested_module/b.test.ts", 14 | ], 15 | config = "//:jest.config", 16 | data = ["//:package_json"], 17 | shard_count = 9, 18 | ) 19 | 20 | ts_project( 21 | name = "my_module", 22 | srcs = [ 23 | "index.ts", 24 | "module_file.ts", 25 | "nested_module/index.ts", 26 | "nested_module/module_file.ts", 27 | "some_other_file.ts", 28 | ], 29 | ) 30 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/my_module/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./module_file" 2 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/my_module/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/my_module/nested_module/a.test.ts: -------------------------------------------------------------------------------- 1 | // Empty file 2 | 3 | it("should run a test", () => {}); 4 | it("should run a test", () => {}); 5 | it("should run a test", () => {}); 6 | it("should run a test", () => {}); 7 | describe('NodeSearch', () => { 8 | it("should run a test", () => {}); 9 | it("should run a test", () => {}); 10 | it("should run a test", () => {}); 11 | it("should run a test", () => {}); 12 | it("should run a test", () => {}); 13 | } 14 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/my_module/nested_module/b.test.ts: -------------------------------------------------------------------------------- 1 | // Empty file 2 | 3 | it("should run a test", () => {}); 4 | it("should run a test", () => {}); 5 | it("should run a test", () => {}); 6 | it("should run a test", () => {}); 7 | it("should run a test", () => {}); 8 | it("should run a test", () => {}); 9 | it("should run a test", () => {}); 10 | it("should run a test", () => {}); 11 | it("should run a test", () => { 12 | expect(1).toBe(1); 13 | }); 14 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/my_module/nested_module/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./module_file" 2 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/my_module/nested_module/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/my_module/some_other_file.ts: -------------------------------------------------------------------------------- 1 | export var baz = "qux" 2 | -------------------------------------------------------------------------------- /tests/collect_all_test_shards/some_other_file.ts: -------------------------------------------------------------------------------- 1 | export var foo = "bar" 2 | -------------------------------------------------------------------------------- /tests/collect_asset_modules/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_web_asset json,css,scss 3 | # gazelle:js_collect_web_assets 4 | # gazelle:js_collect_all_assets 5 | -------------------------------------------------------------------------------- /tests/collect_asset_modules/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@com_github_benchsci_rules_nodejs_gazelle//:defs.bzl", "web_assets") 2 | 3 | # gazelle:js_root 4 | # gazelle:js_web_asset json,css,scss 5 | # gazelle:js_collect_web_assets 6 | # gazelle:js_collect_all_assets 7 | 8 | web_assets( 9 | name = "assets", 10 | srcs = [ 11 | "data.json", 12 | "style.css", 13 | ], 14 | ) 15 | 16 | web_assets( 17 | name = "all_assets", 18 | srcs = [ 19 | "//:assets", 20 | "//a:assets", 21 | "//b:assets", 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /tests/collect_asset_modules/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_modules/WORKSPACE -------------------------------------------------------------------------------- /tests/collect_asset_modules/a/BUILD.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_modules/a/BUILD.in -------------------------------------------------------------------------------- /tests/collect_asset_modules/a/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@com_github_benchsci_rules_nodejs_gazelle//:defs.bzl", "web_assets") 2 | 3 | web_assets( 4 | name = "assets", 5 | srcs = [ 6 | "data.json", 7 | "style.css", 8 | ], 9 | ) 10 | -------------------------------------------------------------------------------- /tests/collect_asset_modules/a/data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_modules/a/data.json -------------------------------------------------------------------------------- /tests/collect_asset_modules/a/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_modules/a/style.css -------------------------------------------------------------------------------- /tests/collect_asset_modules/b/BUILD.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_modules/b/BUILD.in -------------------------------------------------------------------------------- /tests/collect_asset_modules/b/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@com_github_benchsci_rules_nodejs_gazelle//:defs.bzl", "web_assets") 2 | 3 | web_assets( 4 | name = "assets", 5 | srcs = [ 6 | "data.json", 7 | "style.css", 8 | ], 9 | ) 10 | -------------------------------------------------------------------------------- /tests/collect_asset_modules/b/data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_modules/b/data.json -------------------------------------------------------------------------------- /tests/collect_asset_modules/b/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_modules/b/style.css -------------------------------------------------------------------------------- /tests/collect_asset_modules/data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_modules/data.json -------------------------------------------------------------------------------- /tests/collect_asset_modules/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_modules/style.css -------------------------------------------------------------------------------- /tests/collect_asset_singletons/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_web_asset json,css,scss 3 | # gazelle:js_collect_all_assets 4 | -------------------------------------------------------------------------------- /tests/collect_asset_singletons/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@com_github_benchsci_rules_nodejs_gazelle//:defs.bzl", "web_assets") 2 | 3 | # gazelle:js_root 4 | # gazelle:js_web_asset json,css,scss 5 | # gazelle:js_collect_all_assets 6 | 7 | web_assets( 8 | name = "data_json", 9 | srcs = ["data.json"], 10 | ) 11 | 12 | web_assets( 13 | name = "all_assets", 14 | srcs = [ 15 | "//:data_json", 16 | "//a:data_json", 17 | "//b:style_css", 18 | ], 19 | ) 20 | -------------------------------------------------------------------------------- /tests/collect_asset_singletons/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_singletons/WORKSPACE -------------------------------------------------------------------------------- /tests/collect_asset_singletons/a/BUILD.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_singletons/a/BUILD.in -------------------------------------------------------------------------------- /tests/collect_asset_singletons/a/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@com_github_benchsci_rules_nodejs_gazelle//:defs.bzl", "web_assets") 2 | 3 | web_assets( 4 | name = "data_json", 5 | srcs = ["data.json"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/collect_asset_singletons/a/data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_singletons/a/data.json -------------------------------------------------------------------------------- /tests/collect_asset_singletons/b/BUILD.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_singletons/b/BUILD.in -------------------------------------------------------------------------------- /tests/collect_asset_singletons/b/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@com_github_benchsci_rules_nodejs_gazelle//:defs.bzl", "web_assets") 2 | 3 | web_assets( 4 | name = "style_css", 5 | srcs = ["style.css"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/collect_asset_singletons/b/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_singletons/b/style.css -------------------------------------------------------------------------------- /tests/collect_asset_singletons/data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_asset_singletons/data.json -------------------------------------------------------------------------------- /tests/collect_targets/BUILD.in: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_root 4 | # gazelle:js_jest_config :jest.config 5 | # gazelle:js_quiet 6 | 7 | ts_project( 8 | name = "index", 9 | srcs = ["index.ts"], 10 | deps = [ 11 | "//src/pages", # keep 12 | "//src/pages2", # keep 13 | ], 14 | ) 15 | -------------------------------------------------------------------------------- /tests/collect_targets/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | # gazelle:js_jest_config :jest.config 6 | # gazelle:js_quiet 7 | 8 | ts_project( 9 | name = "index", 10 | srcs = ["index.ts"], 11 | deps = [ 12 | "//src/pages", # keep 13 | "//src/pages2", # keep 14 | ], 15 | ) 16 | 17 | js_library( 18 | name = "jest.config", 19 | srcs = ["jest.config.js"], 20 | ) 21 | -------------------------------------------------------------------------------- /tests/collect_targets/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "simple_module") 2 | -------------------------------------------------------------------------------- /tests/collect_targets/index.ts: -------------------------------------------------------------------------------- 1 | var _ = "index"; 2 | -------------------------------------------------------------------------------- /tests/collect_targets/jest.config.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/collect_targets/jest.config.js -------------------------------------------------------------------------------- /tests/collect_targets/src/page-tests/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_collect_all 2 | -------------------------------------------------------------------------------- /tests/collect_targets/src/page-tests/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@rules_jest//jest:defs.bzl", "jest_test") 2 | 3 | # gazelle:js_collect_all 4 | 5 | jest_test( 6 | name = "page-tests_test", 7 | srcs = ["test.test.ts"], 8 | config = "//:jest.config", 9 | data = [ 10 | "//:package_json", 11 | "//src/pages/my_page", 12 | ], 13 | deps = ["//src/pages/my_page"], 14 | ) 15 | -------------------------------------------------------------------------------- /tests/collect_targets/src/page-tests/test.test.ts: -------------------------------------------------------------------------------- 1 | import some_var from 'src/pages/my_page' 2 | var _ = some_var 3 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages/404.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_collect_all 2 | # gazelle:js_collect_targets next_pages 3 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_collect_all 5 | # gazelle:js_collect_targets next_pages 6 | 7 | ts_project( 8 | name = "pages", 9 | srcs = [ 10 | "404.ts", 11 | "index.ts", 12 | ], 13 | ) 14 | 15 | js_library( 16 | name = "next_pages", 17 | deps = [ 18 | ":pages", 19 | "//src/pages/my_page", 20 | ], 21 | ) 22 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages/index.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Index" 2 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages/my_page/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_collect_all -------------------------------------------------------------------------------- /tests/collect_targets/src/pages/my_page/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_collect_all 4 | 5 | ts_project( 6 | name = "my_page", 7 | srcs = [ 8 | "index.ts", 9 | "module_file.ts", 10 | ], 11 | ) 12 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages/my_page/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./module_file" 2 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages/my_page/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages2/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_collect_all 2 | # gazelle:js_collect_targets next_pages2 3 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages2/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | 3 | # gazelle:js_collect_all 4 | # gazelle:js_collect_targets next_pages2 5 | 6 | js_library( 7 | name = "next_pages2", 8 | deps = ["//src/pages2/my_page"], 9 | ) 10 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages2/my_page/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_collect_all 2 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages2/my_page/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_collect_all 4 | 5 | ts_project( 6 | name = "my_page", 7 | srcs = [ 8 | "index.ts", 9 | "module_file.ts", 10 | "subpage/index.ts", 11 | ], 12 | ) 13 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages2/my_page/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./module_file" 2 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages2/my_page/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/collect_targets/src/pages2/my_page/subpage/index.ts: -------------------------------------------------------------------------------- 1 | var _ = "foo"; -------------------------------------------------------------------------------- /tests/default_npm_label/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_web_asset json 3 | # gazelle:js_package_file package.json @npm//: 4 | # gazelle:js_default_npm_label @npm//: 5 | # gazelle:js_lookup_types false 6 | -------------------------------------------------------------------------------- /tests/default_npm_label/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | # gazelle:js_web_asset json 6 | # gazelle:js_package_file package.json @npm//: 7 | # gazelle:js_default_npm_label @npm//: 8 | # gazelle:js_lookup_types false 9 | 10 | js_library( 11 | name = "package_json", 12 | srcs = ["package.json"], 13 | ) 14 | 15 | ts_project( 16 | name = "a", 17 | srcs = ["a.ts"], 18 | data = ["@npm//:lodash"], 19 | deps = [ 20 | ":b", 21 | "@npm//:lodash", 22 | ], 23 | ) 24 | 25 | ts_project( 26 | name = "b", 27 | srcs = ["b.ts"], 28 | ) 29 | -------------------------------------------------------------------------------- /tests/default_npm_label/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/default_npm_label/WORKSPACE -------------------------------------------------------------------------------- /tests/default_npm_label/a.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from "b"; 2 | import lodash from 'lodash'; 3 | 4 | var _ = some_var 5 | var _ = lodash 6 | -------------------------------------------------------------------------------- /tests/default_npm_label/b.ts: -------------------------------------------------------------------------------- 1 | export var some_var = "Hello"; 2 | -------------------------------------------------------------------------------- /tests/default_npm_label/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple_npm_library", 3 | "description": "A test case", 4 | "version": "0.0.0", 5 | "dependencies": { 6 | "lodash": "^4.17" 7 | }, 8 | "devDependencies": { 9 | "@types/lodash": "^4.17" 10 | } 11 | } -------------------------------------------------------------------------------- /tests/disabled/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | -------------------------------------------------------------------------------- /tests/disabled/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_root 4 | 5 | ts_project( 6 | name = "a", 7 | srcs = ["a.ts"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/disabled/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/disabled/WORKSPACE -------------------------------------------------------------------------------- /tests/disabled/a.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/disabled/a.ts -------------------------------------------------------------------------------- /tests/disabled/module/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_extension disabled 2 | -------------------------------------------------------------------------------- /tests/disabled/module/BUILD.out: -------------------------------------------------------------------------------- 1 | # gazelle:js_extension disabled 2 | -------------------------------------------------------------------------------- /tests/disabled/module/b.ts: -------------------------------------------------------------------------------- 1 | export var some_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/disjoint_module/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_collect_barrels 3 | # gazelle:js_quiet 4 | -------------------------------------------------------------------------------- /tests/disjoint_module/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_root 4 | # gazelle:js_collect_barrels 5 | # gazelle:js_quiet 6 | 7 | ts_project( 8 | name = "index", 9 | srcs = ["index.ts"], 10 | deps = ["//my_module"], 11 | ) 12 | 13 | ts_project( 14 | name = "some_other_file", 15 | srcs = ["some_other_file.ts"], 16 | ) 17 | -------------------------------------------------------------------------------- /tests/disjoint_module/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "simple_module") 2 | -------------------------------------------------------------------------------- /tests/disjoint_module/index.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from "./my_module" 2 | 3 | var _ = some_var 4 | -------------------------------------------------------------------------------- /tests/disjoint_module/my_module/BUILD.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/disjoint_module/my_module/BUILD.in -------------------------------------------------------------------------------- /tests/disjoint_module/my_module/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | ts_project( 4 | name = "my_module", 5 | srcs = [ 6 | "index.ts", 7 | "module_file.ts", 8 | ], 9 | tags = ["js_barrel"], 10 | ) 11 | 12 | ts_project( 13 | name = "some_other_file", 14 | srcs = ["some_other_file.ts"], 15 | ) 16 | -------------------------------------------------------------------------------- /tests/disjoint_module/my_module/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./module_file" 2 | -------------------------------------------------------------------------------- /tests/disjoint_module/my_module/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/disjoint_module/my_module/nested_module/BUILD.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/disjoint_module/my_module/nested_module/BUILD.in -------------------------------------------------------------------------------- /tests/disjoint_module/my_module/nested_module/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | ts_project( 4 | name = "nested_module", 5 | srcs = [ 6 | "index.ts", 7 | "module_file.ts", 8 | ], 9 | tags = ["js_barrel"], 10 | ) 11 | -------------------------------------------------------------------------------- /tests/disjoint_module/my_module/nested_module/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "my_module/nested_module/module_file" 2 | -------------------------------------------------------------------------------- /tests/disjoint_module/my_module/nested_module/module_file.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/disjoint_module/my_module/some_other_file.ts: -------------------------------------------------------------------------------- 1 | export var baz = "qux" 2 | -------------------------------------------------------------------------------- /tests/disjoint_module/some_other_file.ts: -------------------------------------------------------------------------------- 1 | export var foo = "bar" 2 | -------------------------------------------------------------------------------- /tests/dynamic_import/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_web_asset json 3 | # gazelle:js_package_file package.json :node_modules 4 | -------------------------------------------------------------------------------- /tests/dynamic_import/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | # gazelle:js_web_asset json 6 | # gazelle:js_package_file package.json :node_modules 7 | 8 | js_library( 9 | name = "package_json", 10 | srcs = ["package.json"], 11 | ) 12 | 13 | ts_project( 14 | name = "a", 15 | srcs = ["a.ts"], 16 | deps = [ 17 | ":b", 18 | ":c", 19 | ], 20 | ) 21 | 22 | ts_project( 23 | name = "b", 24 | srcs = ["b.ts"], 25 | ) 26 | 27 | ts_project( 28 | name = "c", 29 | srcs = ["c.ts"], 30 | ) 31 | 32 | ts_project( 33 | name = "d", 34 | srcs = ["d.ts"], 35 | ) 36 | -------------------------------------------------------------------------------- /tests/dynamic_import/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/dynamic_import/WORKSPACE -------------------------------------------------------------------------------- /tests/dynamic_import/a.ts: -------------------------------------------------------------------------------- 1 | 2 | let lamdba = () => import('./b').do_something("something") 3 | lamdba() 4 | 5 | // some comment 6 | /* 7 | should be ignored: 8 | import('./d') 9 | */ 10 | 11 | let lamdba2 = () => import('./c') 12 | lamdba2() 13 | 14 | -------------------------------------------------------------------------------- /tests/dynamic_import/b.ts: -------------------------------------------------------------------------------- 1 | let foo = "bar" 2 | -------------------------------------------------------------------------------- /tests/dynamic_import/c.ts: -------------------------------------------------------------------------------- 1 | let baz = "qux" 2 | -------------------------------------------------------------------------------- /tests/dynamic_import/d.ts: -------------------------------------------------------------------------------- 1 | let baz = "qux" 2 | -------------------------------------------------------------------------------- /tests/dynamic_import/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jest_require", 3 | "description": "A test case", 4 | "version": "0.0.0", 5 | "dependencies": { 6 | "jwt-decode": "^3.1.2" 7 | }, 8 | "devDependencies": { 9 | "jest": "^27.0.6", 10 | "@types/jest": "^26.0.24" 11 | } 12 | } -------------------------------------------------------------------------------- /tests/fix/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_fix 2 | 3 | js_import( 4 | name = "a", 5 | srcs = ["a.ts"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/fix/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_fix 4 | 5 | ts_project( 6 | name = "a", 7 | srcs = ["a.ts"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/fix/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/fix/WORKSPACE -------------------------------------------------------------------------------- /tests/fix/a.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/fix/a.ts -------------------------------------------------------------------------------- /tests/import_alias/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_import_alias foo module 3 | -------------------------------------------------------------------------------- /tests/import_alias/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_root 4 | # gazelle:js_import_alias foo module 5 | 6 | ts_project( 7 | name = "a", 8 | srcs = ["a.ts"], 9 | deps = ["//module:b"], 10 | ) 11 | -------------------------------------------------------------------------------- /tests/import_alias/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/import_alias/WORKSPACE -------------------------------------------------------------------------------- /tests/import_alias/a.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from "foo/b" 2 | 3 | var _ = some_var 4 | -------------------------------------------------------------------------------- /tests/import_alias/module/BUILD.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/import_alias/module/BUILD.in -------------------------------------------------------------------------------- /tests/import_alias/module/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | ts_project( 4 | name = "b", 5 | srcs = ["b.ts"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/import_alias/module/b.ts: -------------------------------------------------------------------------------- 1 | export var some_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/jest_mock/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_web_asset json 3 | # gazelle:js_package_file package.json :node_modules 4 | -------------------------------------------------------------------------------- /tests/jest_mock/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | # gazelle:js_web_asset json 6 | # gazelle:js_package_file package.json :node_modules 7 | 8 | js_library( 9 | name = "package_json", 10 | srcs = ["package.json"], 11 | ) 12 | 13 | ts_project( 14 | name = "a", 15 | srcs = ["a.ts"], 16 | data = ["//:node_modules/jwt-decode"], 17 | deps = [ 18 | "//:node_modules/@types/jest", 19 | "//:node_modules/jest", 20 | "//:node_modules/jwt-decode", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /tests/jest_mock/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/jest_mock/WORKSPACE -------------------------------------------------------------------------------- /tests/jest_mock/a.ts: -------------------------------------------------------------------------------- 1 | import jest from 'jest' 2 | 3 | jest.mock('jwt-decode', () => ({ 4 | // pass 5 | })) 6 | -------------------------------------------------------------------------------- /tests/jest_mock/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jest_require", 3 | "description": "A test case", 4 | "version": "0.0.0", 5 | "dependencies": { 6 | "jwt-decode": "^3.1.2" 7 | }, 8 | "devDependencies": { 9 | "jest": "^27.0.6", 10 | "@types/jest": "^26.0.24" 11 | } 12 | } -------------------------------------------------------------------------------- /tests/jsx_conversion/BUILD.in: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "web_assets", "js_library") 2 | 3 | # gazelle:js_root 4 | # gazelle:js_web_asset json 5 | # gazelle:js_package_file package.json :node_modules 6 | 7 | js_library( 8 | name = "a", 9 | srcs = ["a.js"], 10 | deps = [], 11 | ) 12 | 13 | js_library( 14 | name = "b", 15 | srcs = ["b.js"], 16 | ) 17 | 18 | web_assets( 19 | name = "package_json", 20 | srcs = ["package.json"], 21 | ) 22 | -------------------------------------------------------------------------------- /tests/jsx_conversion/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | 3 | # gazelle:js_root 4 | # gazelle:js_web_asset json 5 | # gazelle:js_package_file package.json :node_modules 6 | 7 | js_library( 8 | name = "a", 9 | srcs = ["a.jsx"], 10 | data = [ 11 | "//:node_modules/lodash", 12 | "//:node_modules/react", 13 | ], 14 | deps = [ 15 | ":b", 16 | "//:node_modules/lodash", 17 | "//:node_modules/react", 18 | ], 19 | ) 20 | 21 | js_library( 22 | name = "b", 23 | srcs = ["b.js"], 24 | ) 25 | 26 | js_library( 27 | name = "package_json", 28 | srcs = ["package.json"], 29 | ) 30 | -------------------------------------------------------------------------------- /tests/jsx_conversion/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/jsx_conversion/WORKSPACE -------------------------------------------------------------------------------- /tests/jsx_conversion/a.jsx: -------------------------------------------------------------------------------- 1 | import { some_var } from "b" 2 | import lodash from 'lodash' 3 | 4 | var _ = some_var 5 | var _ = lodash 6 | -------------------------------------------------------------------------------- /tests/jsx_conversion/b.js: -------------------------------------------------------------------------------- 1 | export var some_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/jsx_conversion/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple_npm_library", 3 | "description": "A test case", 4 | "version": "0.0.0", 5 | "dependencies": { 6 | "lodash": "^4.17", 7 | "react": "^18.0.0" 8 | }, 9 | "devDependencies": { 10 | "@types/lodash": "^4.17", 11 | "@types/react": "^18.0.0" 12 | } 13 | } -------------------------------------------------------------------------------- /tests/lookup_types/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_web_asset json 3 | # gazelle:js_package_file package.json :node_modules 4 | # gazelle:js_lookup_types 5 | -------------------------------------------------------------------------------- /tests/lookup_types/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | # gazelle:js_web_asset json 6 | # gazelle:js_package_file package.json :node_modules 7 | # gazelle:js_lookup_types 8 | 9 | js_library( 10 | name = "package_json", 11 | srcs = ["package.json"], 12 | ) 13 | 14 | ts_project( 15 | name = "a", 16 | srcs = ["a.ts"], 17 | data = ["//:node_modules/lodash"], 18 | deps = [ 19 | ":b", 20 | "//:node_modules/@types/lodash", 21 | "//:node_modules/lodash", 22 | ], 23 | ) 24 | 25 | ts_project( 26 | name = "b", 27 | srcs = ["b.ts"], 28 | ) 29 | 30 | ts_project( 31 | name = "builtin", 32 | srcs = ["builtin.ts"], 33 | deps = ["//:node_modules/@types/node"], 34 | ) 35 | -------------------------------------------------------------------------------- /tests/lookup_types/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/lookup_types/WORKSPACE -------------------------------------------------------------------------------- /tests/lookup_types/a.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from "b"; 2 | import lodash from 'lodash'; 3 | 4 | var _ = some_var 5 | var _ = lodash 6 | -------------------------------------------------------------------------------- /tests/lookup_types/b.ts: -------------------------------------------------------------------------------- 1 | export var some_var = "Hello"; 2 | -------------------------------------------------------------------------------- /tests/lookup_types/builtin.ts: -------------------------------------------------------------------------------- 1 | import { readFile } from "fs"; -------------------------------------------------------------------------------- /tests/lookup_types/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple_npm_library", 3 | "description": "A test case", 4 | "version": "0.0.0", 5 | "dependencies": { 6 | "lodash": "^4.17", 7 | "react": "^18.2.0" 8 | }, 9 | "devDependencies": { 10 | "@types/lodash": "^4.17", 11 | "@types/node": "^18.11.10", 12 | "@types/react": "^18.0.26" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/lookup_types/subfolder/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | ts_project( 4 | name = "c", 5 | srcs = ["c.ts"], 6 | data = ["//:node_modules/react"], 7 | deps = [ 8 | "//:node_modules/@types/react", 9 | "//:node_modules/react", 10 | ], 11 | ) 12 | -------------------------------------------------------------------------------- /tests/lookup_types/subfolder/c.ts: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | 3 | console.log(React); 4 | -------------------------------------------------------------------------------- /tests/module_self_import/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | -------------------------------------------------------------------------------- /tests/module_self_import/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_root 4 | 5 | ts_project( 6 | name = "index", 7 | srcs = ["index.ts"], 8 | deps = ["//my_module:index"], 9 | ) 10 | -------------------------------------------------------------------------------- /tests/module_self_import/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "simple_module") 2 | -------------------------------------------------------------------------------- /tests/module_self_import/index.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from "./my_module" 2 | 3 | var _ = some_var 4 | -------------------------------------------------------------------------------- /tests/module_self_import/my_module/BUILD.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/module_self_import/my_module/BUILD.in -------------------------------------------------------------------------------- /tests/module_self_import/my_module/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | ts_project( 4 | name = "index", 5 | srcs = ["index.ts"], 6 | deps = [":my_module"], 7 | ) 8 | 9 | ts_project( 10 | name = "my_module", 11 | srcs = ["my_module.ts"], 12 | ) 13 | 14 | ts_project( 15 | name = "some_other_file", 16 | srcs = ["some_other_file.ts"], 17 | deps = [":index"], 18 | ) 19 | -------------------------------------------------------------------------------- /tests/module_self_import/my_module/index.ts: -------------------------------------------------------------------------------- 1 | export { some_private_var as some_var } from "./my_module" 2 | -------------------------------------------------------------------------------- /tests/module_self_import/my_module/my_module.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/module_self_import/my_module/some_other_file.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from '.' 2 | 3 | var _ = some_var 4 | -------------------------------------------------------------------------------- /tests/monorepo/BUILD.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/monorepo/BUILD.in -------------------------------------------------------------------------------- /tests/monorepo/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/monorepo/WORKSPACE -------------------------------------------------------------------------------- /tests/monorepo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "monorepo", 3 | "description": "A test case", 4 | "version": "0.0.0", 5 | "dependencies": { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/monorepo/project_a/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_package_file package.json :node_modules 2 | # gazelle:js_collect_all -------------------------------------------------------------------------------- /tests/monorepo/project_a/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_package_file package.json :node_modules 5 | # gazelle:js_collect_all 6 | 7 | js_library( 8 | name = "package_json", 9 | srcs = ["package.json"], 10 | ) 11 | 12 | ts_project( 13 | name = "project_a", 14 | srcs = ["a.ts"], 15 | data = ["//project_a:node_modules/@emotion/react"], 16 | deps = ["//project_a:node_modules/@emotion/react"], 17 | ) -------------------------------------------------------------------------------- /tests/monorepo/project_a/a.ts: -------------------------------------------------------------------------------- 1 | import '@emotion/react' -------------------------------------------------------------------------------- /tests/monorepo/project_a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "monorepo_project_a", 3 | "description": "A test case", 4 | "version": "0.0.0", 5 | "dependencies": { 6 | "@emotion/react": "11.11.4" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/react_example/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_lookup_types 3 | # gazelle:js_package_file package.json :node_modules -------------------------------------------------------------------------------- /tests/react_example/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | # gazelle:js_lookup_types 6 | # gazelle:js_package_file package.json :node_modules 7 | 8 | js_library( 9 | name = "package_json", 10 | srcs = ["package.json"], 11 | ) 12 | 13 | ts_project( 14 | name = "with_import", 15 | srcs = ["with_import.tsx"], 16 | data = ["//:node_modules/react"], 17 | deps = [ 18 | "//:node_modules/@types/react", 19 | "//:node_modules/react", 20 | ], 21 | ) 22 | 23 | ts_project( 24 | name = "without_import", 25 | srcs = ["without_import.tsx"], 26 | data = ["//:node_modules/react"], 27 | deps = [ 28 | "//:node_modules/@types/react", 29 | "//:node_modules/react", 30 | ], 31 | ) 32 | 33 | js_library( 34 | name = "js_with_import", 35 | srcs = ["js_with_import.jsx"], 36 | data = ["//:node_modules/react"], 37 | deps = ["//:node_modules/react"], 38 | ) 39 | 40 | js_library( 41 | name = "js_without_import", 42 | srcs = ["js_without_import.jsx"], 43 | data = ["//:node_modules/react"], 44 | deps = ["//:node_modules/react"], 45 | ) -------------------------------------------------------------------------------- /tests/react_example/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/react_example/WORKSPACE -------------------------------------------------------------------------------- /tests/react_example/js_with_import.jsx: -------------------------------------------------------------------------------- 1 | const React = require("react"); 2 | 3 | export const Component = () => { 4 | return
; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/react_example/js_without_import.jsx: -------------------------------------------------------------------------------- 1 | export const Component = () => { 2 | return
; 3 | }; 4 | -------------------------------------------------------------------------------- /tests/react_example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react_example", 3 | "description": "A test case", 4 | "version": "0.0.0", 5 | "dependencies": { 6 | "react": "^18.0.0", 7 | "@types/react": "^18.0.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/react_example/with_import.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export const Component: React.FC = () => { 4 | return
; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/react_example/without_import.tsx: -------------------------------------------------------------------------------- 1 | export const Component = (): any => { 2 | return
; 3 | }; 4 | -------------------------------------------------------------------------------- /tests/simple_barrel/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_collect_barrels 3 | -------------------------------------------------------------------------------- /tests/simple_barrel/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_root 4 | # gazelle:js_collect_barrels 5 | 6 | ts_project( 7 | name = "index", 8 | srcs = ["index.ts"], 9 | deps = ["//SomeOtherFile"], 10 | ) 11 | -------------------------------------------------------------------------------- /tests/simple_barrel/SomeOtherFile/BUILD.in: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_collect_barrels 4 | 5 | ts_project( 6 | name = "index", 7 | srcs = [ 8 | "index.ts", 9 | ], 10 | ) 11 | 12 | ts_project( 13 | name = "SomeOtherFile", 14 | srcs = [ 15 | "SomeOtherFile.tsx", 16 | ], 17 | ) 18 | -------------------------------------------------------------------------------- /tests/simple_barrel/SomeOtherFile/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_collect_barrels 4 | 5 | ts_project( 6 | name = "SomeOtherFile", 7 | srcs = [ 8 | "SomeOtherFile.ts", 9 | "index.ts", 10 | ], 11 | tags = ["js_barrel"], 12 | ) 13 | -------------------------------------------------------------------------------- /tests/simple_barrel/SomeOtherFile/SomeOtherFile.ts: -------------------------------------------------------------------------------- 1 | export var some_private_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/simple_barrel/SomeOtherFile/index.ts: -------------------------------------------------------------------------------- 1 | import { some_private_var as some_var } from "./SomeOtherFile"; 2 | 3 | export { some_var }; 4 | -------------------------------------------------------------------------------- /tests/simple_barrel/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "simple_module") 2 | -------------------------------------------------------------------------------- /tests/simple_barrel/index.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from "./SomeOtherFile"; 2 | 3 | var _ = some_var; 4 | -------------------------------------------------------------------------------- /tests/simple_library/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | -------------------------------------------------------------------------------- /tests/simple_library/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | 6 | js_library( 7 | name = "package_json", 8 | srcs = ["package.json"], 9 | ) 10 | 11 | ts_project( 12 | name = "a.d", 13 | srcs = ["a.d.ts"], 14 | ) 15 | 16 | ts_project( 17 | name = "a", 18 | srcs = ["a.ts"], 19 | ) 20 | 21 | js_library( 22 | name = "b", 23 | srcs = ["b.js"], 24 | ) 25 | -------------------------------------------------------------------------------- /tests/simple_library/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/simple_library/WORKSPACE -------------------------------------------------------------------------------- /tests/simple_library/a.d.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/simple_library/a.d.ts -------------------------------------------------------------------------------- /tests/simple_library/a.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/simple_library/a.ts -------------------------------------------------------------------------------- /tests/simple_library/b.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/simple_library/b.js -------------------------------------------------------------------------------- /tests/simple_library/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /tests/simple_npm_library/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_web_asset json 3 | # gazelle:js_package_file package.json :node_modules 4 | -------------------------------------------------------------------------------- /tests/simple_npm_library/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | # gazelle:js_web_asset json 6 | # gazelle:js_package_file package.json :node_modules 7 | 8 | js_library( 9 | name = "package_json", 10 | srcs = ["package.json"], 11 | ) 12 | 13 | ts_project( 14 | name = "a", 15 | srcs = ["a.ts"], 16 | data = ["//:node_modules/lodash"], 17 | deps = [ 18 | ":b", 19 | "//:node_modules/@types/lodash", 20 | "//:node_modules/lodash", 21 | ], 22 | ) 23 | 24 | ts_project( 25 | name = "b", 26 | srcs = ["b.ts"], 27 | ) 28 | -------------------------------------------------------------------------------- /tests/simple_npm_library/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/simple_npm_library/WORKSPACE -------------------------------------------------------------------------------- /tests/simple_npm_library/a.ts: -------------------------------------------------------------------------------- 1 | import { some_var } from "b" 2 | import lodash from 'lodash' 3 | 4 | var _ = some_var 5 | var _ = lodash 6 | -------------------------------------------------------------------------------- /tests/simple_npm_library/b.ts: -------------------------------------------------------------------------------- 1 | export var some_var = "Hello" 2 | -------------------------------------------------------------------------------- /tests/simple_npm_library/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple_npm_library", 3 | "description": "A test case", 4 | "version": "0.0.0", 5 | "dependencies": { 6 | "lodash": "^4.17" 7 | }, 8 | "devDependencies": { 9 | "@types/lodash": "^4.17" 10 | } 11 | } -------------------------------------------------------------------------------- /tests/test_runner.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "errors" 7 | "fmt" 8 | "os" 9 | "os/exec" 10 | "path/filepath" 11 | "strings" 12 | "testing" 13 | "time" 14 | 15 | "github.com/bazelbuild/bazel-gazelle/testtools" 16 | "github.com/bazelbuild/rules_go/go/tools/bazel" 17 | ) 18 | 19 | const ( 20 | testDataPath = "tests/" 21 | gazelleBinaryName = "test_gazelle_bin" 22 | ) 23 | 24 | func main() { 25 | // Check that we have exactly one argument 26 | if len(os.Args) != 2 { 27 | panic("expected exactly one argument") 28 | } 29 | 30 | // Get the folder name from the command line 31 | name := os.Args[1] 32 | 33 | // Wrap test with InternalTest so that it can be run by testing.Main 34 | theTest := testing.InternalTest{ 35 | Name: fmt.Sprintf("test_%s", name), 36 | F: func(t *testing.T) { RunTest(t, name) }, 37 | } 38 | 39 | // Create a matchAll function that will match all tests 40 | matchAll := func(pat, str string) (bool, error) { 41 | return true, nil // Run all tests in list 42 | } 43 | 44 | // Run the test 45 | testing.Main(matchAll, []testing.InternalTest{theTest}, nil, nil) 46 | } 47 | 48 | func RunTest(t *testing.T, name string) { 49 | 50 | // Get path to gazelle binary 51 | gazellePath, ok := bazel.FindBinary("", gazelleBinaryName) 52 | if !ok { 53 | t.Errorf("could not find gazelle binary") 54 | t.FailNow() 55 | return 56 | } 57 | 58 | // Get all Bazel runfiles 59 | runfiles, err := bazel.ListRunfiles() 60 | if err != nil { 61 | t.Fatalf("bazel.ListRunfiles() error: %v", err) 62 | } 63 | 64 | var inputs []testtools.FileSpec 65 | var goldens []testtools.FileSpec 66 | 67 | // Get the path to the test directory 68 | testDirShortPath := testDataPath + name 69 | 70 | for _, f := range runfiles { 71 | 72 | // Exclude runfiles outside of test directory 73 | if !strings.HasPrefix(f.ShortPath, testDirShortPath) { 74 | continue 75 | } 76 | 77 | // Get relative file path from inside test directory 78 | testFilePath := strings.TrimPrefix(f.ShortPath, testDirShortPath) 79 | fmt.Println(testFilePath) 80 | info, err := os.Stat(f.Path) 81 | if err != nil { 82 | t.Fatalf("os.Stat(%q) error: %v", f.Path, err) 83 | } 84 | 85 | // Skip directories 86 | if info.IsDir() { 87 | continue 88 | } 89 | 90 | // Read file contents 91 | content, err := os.ReadFile(f.Path) 92 | if err != nil { 93 | t.Errorf("os.ReadFile(%q) error: %v", f.Path, err) 94 | } 95 | 96 | // Add file to inputs or goldens 97 | if strings.HasSuffix(testFilePath, ".in") { 98 | inputs = append(inputs, testtools.FileSpec{ 99 | Path: filepath.Join(name, strings.TrimSuffix(testFilePath, ".in")), 100 | Content: string(content), 101 | }) 102 | } else if strings.HasSuffix(testFilePath, ".out") { 103 | goldens = append(goldens, testtools.FileSpec{ 104 | Path: filepath.Join(name, strings.TrimSuffix(testFilePath, ".out")), 105 | Content: string(content), 106 | }) 107 | } else { 108 | inputs = append(inputs, testtools.FileSpec{ 109 | Path: filepath.Join(name, testFilePath), 110 | Content: string(content), 111 | }) 112 | goldens = append(goldens, testtools.FileSpec{ 113 | Path: filepath.Join(name, testFilePath), 114 | Content: string(content), 115 | }) 116 | } 117 | } 118 | 119 | // Create temporary directory with input files 120 | testdataDir, cleanup := testtools.CreateFiles(t, inputs) 121 | defer cleanup() 122 | defer func() { 123 | if t.Failed() { 124 | filepath.Walk(testdataDir, func(path string, info os.FileInfo, err error) error { 125 | if err != nil { 126 | return err 127 | } 128 | t.Logf("%q exists", strings.TrimPrefix(path, testdataDir)) 129 | return nil 130 | }) 131 | } 132 | }() 133 | 134 | // Run gazelle 135 | workspaceRoot := filepath.Join(testdataDir, name) 136 | args := []string{"-build_file_name=BUILD,BUILD.bazel"} 137 | ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) 138 | defer cancel() 139 | cmd := exec.CommandContext(ctx, gazellePath, args...) 140 | var stdout, stderr bytes.Buffer 141 | cmd.Stdout = &stdout 142 | cmd.Stderr = &stderr 143 | cmd.Dir = workspaceRoot 144 | if err := cmd.Run(); err != nil { 145 | var e *exec.ExitError 146 | if !errors.As(err, &e) { 147 | t.Fatal(err) 148 | } 149 | } 150 | 151 | // Check exit code and stdout/stderr 152 | procExitCode := cmd.ProcessState.ExitCode() 153 | if procExitCode != 0 { 154 | t.Errorf("expected gazelle exit code: 0\ngot: %d", procExitCode) 155 | } 156 | procStdout := stdout.String() 157 | if strings.TrimSpace(procStdout) != "" { 158 | t.Errorf("expected no gazelle stdout\ngot: %s", procStdout) 159 | } 160 | procStderr := stderr.String() 161 | if strings.TrimSpace(procStderr) != "" { 162 | t.Errorf("expected no gazelle stderr\ngot: %s", procStderr) 163 | } 164 | 165 | // Check output files 166 | testtools.CheckFiles(t, testdataDir, goldens) 167 | } 168 | -------------------------------------------------------------------------------- /tests/ts_conversion/BUILD.in: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "web_assets", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | 6 | js_library( 7 | name = "a", 8 | srcs = ["a.js"], 9 | ) 10 | -------------------------------------------------------------------------------- /tests/ts_conversion/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_js//js:defs.bzl", "js_library") 2 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3 | 4 | # gazelle:js_root 5 | 6 | js_library( 7 | name = "package_json", 8 | srcs = ["package.json"], 9 | ) 10 | 11 | ts_project( 12 | name = "a.d", 13 | srcs = ["a.d.ts"], 14 | ) 15 | 16 | ts_project( 17 | name = "a", 18 | srcs = ["a.ts"], 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /tests/ts_conversion/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/ts_conversion/WORKSPACE -------------------------------------------------------------------------------- /tests/ts_conversion/a.d.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/ts_conversion/a.d.ts -------------------------------------------------------------------------------- /tests/ts_conversion/a.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/ts_conversion/a.ts -------------------------------------------------------------------------------- /tests/ts_conversion/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /tests/visibility/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_root 2 | # gazelle:js_visibility //visibility:public 3 | -------------------------------------------------------------------------------- /tests/visibility/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 2 | 3 | # gazelle:js_root 4 | # gazelle:js_visibility //visibility:public 5 | 6 | ts_project( 7 | name = "a", 8 | srcs = ["a.ts"], 9 | visibility = ["//visibility:public"], 10 | ) 11 | -------------------------------------------------------------------------------- /tests/visibility/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/visibility/WORKSPACE -------------------------------------------------------------------------------- /tests/visibility/a.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/visibility/a.ts -------------------------------------------------------------------------------- /tests/web_assets_module/BUILD.in: -------------------------------------------------------------------------------- 1 | # gazelle:js_web_asset json,css,scss 2 | # gazelle:js_collect_web_assets 3 | -------------------------------------------------------------------------------- /tests/web_assets_module/BUILD.out: -------------------------------------------------------------------------------- 1 | load("@com_github_benchsci_rules_nodejs_gazelle//:defs.bzl", "web_assets") 2 | 3 | # gazelle:js_web_asset json,css,scss 4 | # gazelle:js_collect_web_assets 5 | 6 | web_assets( 7 | name = "assets", 8 | srcs = [ 9 | "data.json", 10 | "style.css", 11 | ], 12 | ) 13 | -------------------------------------------------------------------------------- /tests/web_assets_module/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/web_assets_module/WORKSPACE -------------------------------------------------------------------------------- /tests/web_assets_module/data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/web_assets_module/data.json -------------------------------------------------------------------------------- /tests/web_assets_module/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benchsci/rules_nodejs_gazelle/8ba8fd736a1391373bc12c487e96459727d7ebc1/tests/web_assets_module/style.css --------------------------------------------------------------------------------