{"id":13452322,"url":"https://github.com/jasongwartz/bazel_rules_nodejs_contrib","last_synced_at":"2025-03-23T19:34:05.790Z","repository":{"id":91282798,"uuid":"137882693","full_name":"jasongwartz/bazel_rules_nodejs_contrib","owner":"jasongwartz","description":"Ecosia specific JS Bazel rules to be used with the NodeJS rules","archived":true,"fork":false,"pushed_at":"2020-04-04T22:31:26.000Z","size":817,"stargazers_count":24,"open_issues_count":20,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-07-31T07:18:43.135Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jasongwartz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-19T11:32:07.000Z","updated_at":"2024-07-31T07:18:47.058Z","dependencies_parsed_at":null,"dependency_job_id":"a2bfcdb7-7253-4036-8b5d-ca69027c96a4","html_url":"https://github.com/jasongwartz/bazel_rules_nodejs_contrib","commit_stats":null,"previous_names":["ecosia/bazel_rules_nodejs_contrib"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasongwartz%2Fbazel_rules_nodejs_contrib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasongwartz%2Fbazel_rules_nodejs_contrib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasongwartz%2Fbazel_rules_nodejs_contrib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasongwartz%2Fbazel_rules_nodejs_contrib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasongwartz","download_url":"https://codeload.github.com/jasongwartz/bazel_rules_nodejs_contrib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245159301,"owners_count":20570358,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:01:20.605Z","updated_at":"2025-03-23T19:34:05.337Z","avatar_url":"https://github.com/jasongwartz.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# JS rules for Bazel\nEcosia specific JS Bazel rules to be used with the NodeJS rules\n\n## Setup\n\n```py\n# These rules depend on running Node.js\nhttp_archive(\n    name = \"build_bazel_rules_nodejs\",\n    urls = [\"https://github.com/bazelbuild/rules_nodejs/archive/0.30.1.tar.gz\"],\n    strip_prefix = \"rules_nodejs-0.30.1\",\n    sha256 = \"50fa0f31ca1deb1cffde4cfb546bc6d15d6cac39880f6ff3c883d66f98736f4b\",\n)\n\nhttp_archive(\n    name = \"ecosia_bazel_rules_nodejs_contrib\",\n    urls = [\"https://github.com/ecosia/bazel_rules_nodejs_contrib/archive/6450754ab9c44e627c7e90a5838a59f4cc45e76e.tar.gz\"],\n    strip_prefix = \"bazel_rules_nodejs_contrib-6450754ab9c44e627c7e90a5838a59f4cc45e76e\",\n    sha256 = \"dda6a6af4361717a36d9e3bc1c0464ff55be1aacd2a2fc6c61e6524f95930268\",\n)\n\n\nload(\"@build_bazel_rules_nodejs//:defs.bzl\", \"node_repositories\")\n\n# Point to the package.json file so Bazel can run the package manager for you.\nnode_repositories(package_json = [\"//:package.json\"])\n\n# This loads the dependencies for the rules in this repository\nload(\"@ecosia_bazel_rules_nodejs_contrib//:defs.bzl\", \"node_contrib_repositories\")\n\nnode_contrib_repositories()\n```\n\n## Rules\n\nFor usage of each rule have a look in the examples directory.\n\n### json_to_js\n\nConverts json files to treeshakable ES modules\n\n`json_to_js(name, srcs)`\n\n### toml_to_js\n\nConverts toml files to treeshakable ES modules\n\n`toml_to_js(name, srcs, strict)`\n\n### js_import\n\nProvides transitive dependcy support for custom files to be imported in js. Like svg or proto files that will get compiled to js by an upstream rule. This exists mostly for compatibility and migration reasons, as ideally each of these files would have ther own `x_to_js` or similar rules.\n\n`js_import(name, srcs)`\n\n### vue_component\n\nConverts a vue component to an ES module with the css injected into the js.\n\n`vue_component(name, src)`\n\n### js_library\n\nA generic js_library rule that provides transitive dependency support for `bazelbuild/rules_nodejs` as well as some basic interoperability with `ts_devserver`.\n\n`js_library(name, srcs, deps, module_name, module_root)`\n\n### babel_library\n\nThis rule provides compilation support with babel as well as transitive dependency support for `bazelbuild/rules_nodejs` and interoperability with `ts_devserver`.  \n\nThe default label for the `babel` binary is `@npm//@bazel/babel/bin:babel` as it is eventually expected to be a hosted package. For now you can either create a `nodejs_binary` including the `babel.js` in your workspace or add a `file:` dependency into your `package.json` similar to the example provided here. If no custom `babelrc` is provided it defaults to `@babel/preset-env` with umd compilation the way `ts_devserver` expects.\n\n`babel_library(name, srcs, deps, data, module_name, module_root, babel, babelrc)`\n\n## Build file generation\n\nBuild file generation is provided as a plugin for [gazelle](https://github.com/bazelbuild/bazel-gazelle) and still WIP and to a certain degree coupled to our internal js setup. It should not be difficult to extend / make it more generic though. It makes use of the `js_library` and `jest_node_test` provided in these rules. It also supports `ts_library` as well as an option to swap out `js_library` generation with `babel_library`.\n\nTo setup the gazlle plugin follow the installation instructions provided by the repository and additionally add the following to your root level `BUILD.bazel`:\n\n```py\nload(\"@bazel_gazelle//:def.bzl\", \"DEFAULT_LANGUAGES\", \"gazelle\", \"gazelle_binary\")\n\n# gazelle:exclude node_modules\n\ngazelle(\n    name = \"gazelle\",\n    gazelle = \":gazelle_js\",\n    # optionally to configure\n    extra_args = [\n        \"-npm_workspace_name\", # define a custom workspace name instead of @npm\n        \"my-npm\",\n        \"-js_library\", # will use babel_library instead of js_library\n        \"babel_library\",\n        \"-js_import_extensions\", # will generate js_import for .svg and .proto files\n        \".svg,.proto\",\n        \"-alias_import_support\", # support resolving alias import statements, like \"~/\"\n        \"-generate_js_tests\", # enables jest_node_test generation for .test.js files\n    ]\n)\n\ngazelle_binary(\n    name = \"gazelle_js\",\n    languages = DEFAULT_LANGUAGES + [\n        \"@ecosia_bazel_rules_nodejs_contrib//gazelle:go_default_library\",\n    ],\n    visibility = [\n        \"//visibility:public\",\n    ],\n)\n```\n\n## Contributions\n\nThe code in this repository is not actively supported / developed as these rules have currently only been used for experimentation and bazel is being evaluated for internal use. PRs and bug fixes would most likely be accepted though.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasongwartz%2Fbazel_rules_nodejs_contrib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasongwartz%2Fbazel_rules_nodejs_contrib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasongwartz%2Fbazel_rules_nodejs_contrib/lists"}