bazel-javascript
bazel-javascript copied to clipboard
Enhance import resolving
I have encountered 2 issues with import resolving:
- If I have to import a file from a
js_librarythat lives in a parent path, I have to use a lot of'../..'in the path. That makes it hard to move files around without breaking anything.
Example:
.
|-- app
|---- src
|------ index.js (import '../../lib/common/net.js';)
|-- lib
|---- commonn
|------ net.js
- I create some json files using
jsonnet. I then import them as ajs_library, but the path is something like this:bazel-out/k8-fastbuild/bin/app/config.json.
Exampe:
import '../../bazel-out/k8-fastbuild/bin/app/config.json';
The problem is that the fastbuild dir is prefixed with the target architecture (k8/darwin). Then, I cannot resolve the import in a cross platform way. If I use the k8 prefix, it won't work on MacOS, and vice versa.
I have created #48 to solve both issues. I think the implementatios is pretty generic, so it should work for anyone.
Thanks
@schoren, thanks for your change. My imports looks way nicer now.
I also have a some generated files and I was dealing with the same cross platform problem. I tried #48 but it didn't work for me because the generated files are under 'bazel-out/darwin-fastbuild/genfiles' not under 'bazel-out/darwin-fastbuild/bin' . Adding GENDIR path without modifications solves the problem.
const gendir = path.join(base, process.env["GENDIR"], '..', 'bin')
const gendir2 = path.join(base, process.env["GENDIR"])
See #53 which is currently working for me.