Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change How we are Rooting process directories & add path config
This PR adds a somewhat major change to how the pants-node plugin sets up the environment in which it runs npm scripts. The goal is to better support multiple projects with multiple package.jsons in a single repo. The main necessary change is that we locate package.json with the rest of the source files of the node_library instead of special casing them. a) Due to an issue with symlinks that was previously undiscovered due to webpack behavior, we are no longer installing executables to the `./node_modules/.bin` directory, this means the `'pants:build"` key in the scripts object will need to call node directly with the path of the executable script (e.g. `"node node_modules/nuxt/bin/nuxt.js"` (this is what was symlinked previously, but does not work with pants if the symlink references relative paths) [More info here](pantsbuild/pants#15211 (comment)) b) the previous code relied on package(-lock).json being in root of the repository, this PR removes special handling of the package(-lock).json files, they are now regular source files and part of the `node_library` target c) When running `npm run-script pants:build` the directory will include all source files that have been re-rooted _to the node_package target directory_ this means you can't meaningfully include files that exist outside of the node_package directory in your build, I... don't think this is a problem but it is something to keep in mind. E.g. if before your node_package was defined in src/delivery/dashboard/BUILD previously this plugin would evaluate `npm run-script pants:build` in a directory containing package.json & src/delivery/dsahboard/{all dependent source files & directories} Now {all source files & directories} will be included in the root (alongside package.json), this means that hopefully your pants:build script is simpler/does not require weird configuration to reach 3 directory layers deep. d) source roots in output files will be stripped if the output_path is not defined. This is so the bundles will overlay nicely with the packaged python code, which generally strips source roots. If output_path is defined output files will be directly appended to the output_path value. There is now a NodeSubsystem (pants terminology for configuration settings) to allow configuration of how the pants-node plugin searches for npm. Default configurations are the same as previously except /usr/local/bin is not searched by default. for more info run `./pants help node` to display the full options & format refrencing the changes above here's recommended process to upgrade your targets to include these changes. 1) Include package.json & package-lock.json in your node_library definitions. 2) update your 'pants:build' script key to directly reference the appropriate executable 3) Make sure the output file path is correct & is included correctly in the docker image you build I have tested all this in the remit-srv codebase (that PR upcoming) and it builds/includes both delivery dashboards successfully! You truly can have it all.
- Loading branch information