-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Monorepo: is it possible to read dependencies from package.json? #563
Comments
I believe what you could do is to write a Bazel macro that takes dependencies as parameters, and based on these dependencies:
Something along these lines: def _format_dep(name, version):
name = "@prefix/" + name[11:]
return "\"{}\": \"^{}\"".format(name, version)
def my_ts_library(name, deps = [], dev_deps = [], **kwargs):
ts_library(
name = name,
deps = deps + dev_deps,
**kwargs
)
replacements = {
"\"DEPS_PLACEHOLDER\": \"\"": ",\n ".join(
[
_format_dep(dep, "0.0.1") for dep in deps
if dep.startswith("//packages/")
]
),
"\"DEV_DEPS_PLACEHOLDER\": \"\"": ",\n ".join(
[
_format_dep(dep, "0.0.1") for dep in dev_deps
if dep.startswith("//packages/")
]
),
}
npm_package(
name = name + "-package",
srcs = [":package.json"],
deps = [":" + name] + deps,
replacements = replacements,
) With a {
"name": "@prefix/mypackage",
"version": "0.0.0-PLACEHOLDER",
"dependencies": {
"DEPS_PLACEHOLDER": ""
},
"devDependencies": {
"DEV_DEPS_PLACEHOLDER": ""
}
} Alternatively, I would write a |
You're right, the deps are repeated right now. |
No longer in scope for rules_nodejs |
I read through the docs but I couldn't figure out how to set up bazel for a classic lerna / yarn monorepo. Specifically, I can't figure out if its possible to read the dependencies for a bazel rule from another file i.e.
package.json
What I like is to avoid duplication of specifying the dependencies twice, once in package.json for npm/yarn publishing and consumption/installation by other users, and once in Bazel for building via TypeScript in the right order.
Ideally I would have deps be generated from reading the toplevel package.json
workspaces
entry globs, filtered through the individual package's own dependencies and devDependencies as specified in package.jsonThe text was updated successfully, but these errors were encountered: