-
Notifications
You must be signed in to change notification settings - Fork 524
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
Support changing working directory in npm_package_bin #1840
Comments
We could make this a built-in feature but it's pretty easy to do in userspace.
|
Note that I discussed this with @gregmagolan and the reason we didn't build it in yet is that lots of bazel path support expects "workspace-absolute" paths, so while that code snippet is working for me in a |
this method may hang so much time and due to timeout, I try to get the real exec command as follow /root/.cache/bazel/_bazel_root/install/d687aca87a7669724cc958527f2423da/process-wrapper --timeout=0 --kill_delay=15 bazel-out/host/bin/external/npm/@vue/cli-service/bin/vue-cli-service.sh build --dest=bazel-out/k8-fastbuild/bin/portal --node_options=--require=./bazel-out/k8-fastbuild/bin/portal/chdir.js --bazel_node_modules_manifest=bazel-out/k8-fastbuild/bin/portal/_build.module_mappings.json --nobazel_patch_module_resolver I exec it by hand in the workdir and got the error Error: Cannot find module './bazel-out/host/bin/external/npm/@vue/cli-service/bin/vue-cli-service.sh.runfiles/build_bazel_rules_nodejs/internal/node/node_patches.js'
Require stack:
- internal/preload
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
at Function.Module._load (internal/modules/cjs/loader.js:864:27)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at Module._preloadModules (internal/modules/cjs/loader.js:1298:12)
at loadPreloadModules (internal/bootstrap/pre_execution.js:444:5)
at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:68:3)
at internal/main/run_main_module.js:7:1 {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'internal/preload' ]
}
internal/modules/cjs/loader.js:985
throw err;
^ So I don't know why, so I use a hack method to bypass this implementation in #1776 (comment) Does anyone know why this error happened above? |
@weixiao-huang Could you provide a complete minimal (non-)working example? Alex's suggestion looks reasonable to me. Once again, if you want a module that 'just works' out of the box here it is. It's a launcher for |
@dubov94 See this: https://github.com/weixiao-huang/bazel-vue-example |
@alexeagle Unfortunately We could obviously prepend |
@weixiao-huang Thank you, I was able to reproduce the problem, and I don't see an immediate solution. For now you can use vue-cli-launcher instead of @alexeagle Isn't actually |
Yeah messing up the output directory is one of the follow-on path issues from changing the working directory that I mentioned earlier, prevents us from making this chdir trick built-in right now.
@weixiao-huang I don't think your hang is related to the original issue of setting the working directory. Note that if you want to debug by calling the bazel exec command directly, you must also run it in the same working directory (this is why bazel --subcommands prints the command wrapped in a subshell with a Let's keep this issue specifically for the working directory, I think there are other issues about vue (would be great to have an example checked in) |
I agree that ideally the tool should be target-independent, but in your suggestion aren't we passing Looks like @weixiao-huang's bazel-vue-example does not hang if we remove Anyway, even if we manage to find a shortcut for this particular case, it's likely to be quite fragile. Perhaps it shouldn't be handled on |
Apologies complete node and JS compilation noob here.Tried the approach above in a few forms, in the form below it hangs: load("@build_bazel_rules_nodejs//:index.bzl", "npm_package_bin")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
write_file(
name = "write_chdir_script",
out = "chdir.js",
content = ["process.chdir(__dirname)"],
)
npm_package_bin(
name = "app",
tool = "@npm//@vue/cli-service/bin:vue-cli-service",
args = [
"build",
"--dest", "$(@D)",
"--node_options=--require=./$(execpath chdir.js)"
],
data = [
"@npm//:node_modules",
"chdir.js"
] + glob(["src/**"]),
output_dir = 1,
visibility = ["//visibility:private"],
) If I adapt the above to provide the entry point I tried to replicate the workaround by executing in the root of our monorepo and get the following:
|
@alexeagle any thoughts on the best way forward ? I think |
Hey, yeah I agree that's a good FR for vue-cli-service, I'd recommend phrasing the issue in terms of "monorepo" rather than mention Bazel since the latter has a narrow audience right now and won't get their attention. I think for us to dig into the vue-specific parts of this issue, the best way is to add Anyone on the thread have time to contribute that example? |
I'm pretty sure vuejs/vue-cli#3150 and its references address this, but there hasn't been much activity going on recently. Do I understand correctly that you are suggesting to add the non-working example to |
Would the example be a multiproject repo or just for VueJS? |
Ideally we add a working VueJS example. There's so much discussion above I'm not sure if there is any working vue setup today? |
I am currently setting one up using the vue-cli-service tool. Had a few troubles running the build command though. I will see what I can do. If you want I could just add a standard default Vue application and put some build files in it once I got it working. |
#1915 has the vue example. |
…s in a specific working directory Fixes bazel-contrib#1840
…s in a specific working directory Fixes bazel-contrib#1840
…s in a specific working directory Fixes bazel-contrib#1840
…s in a specific working directory Fixes bazel-contrib#1840
🚀 feature request
Relevant Rules
Description
I'm trying to build a vue application (details #1831). I have had success but the resulting application is not quite correct yet.
npm_package_bin
runs from the root of the workspace however the vue cli tool expects be run in the root of vue project to pick up various build config files and directories.Describe the solution you'd like
To get past the problem we need
npm_package_bin
to support changing the working directory to the current package.The text was updated successfully, but these errors were encountered: