Skip to content

Commit

Permalink
feat(back): #789 build package lock
Browse files Browse the repository at this point in the history
- Script to build `package-lock.json` using makes, to keep lock
versions between the devs involved in a project.
  • Loading branch information
jpverde committed Feb 9, 2022
1 parent 68754d5 commit f0492d0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3707,6 +3707,31 @@ It appends:
- `node_modules/.bin` to `PATH`.
- `node_modules` to [NODE_PATH][NODE_PATH].
Pre-requisites:
1. You can generate a `package-lock.json` using a specific `node` version
like this:
```bash
m github:fluidattacks/[email protected] /utils/makeNodeJsLockfile \
"${node_js_version}" \
"${package_json}" \
"${package_lock}
```
- Supported `node_js_version`s are: `10`, `12`, `14` and `16`.
- `package_json` is the **absolute path** to the `package.json` file in your
project.
- `package_lock` is the **absolute path**
to the `package-lock.json` file in your project, this file can be an empty
file.
Note: the reason behind this script is to maintain `lock` versions through the
construction of `makeNodeJsEnvironment`, since you can have an updated version
of `nodejs` or `npm` but not the same as the version stored on the
[Nixpkgs][NIXPKGS] repository. This doesn't affect your local version
of `npm` or `nodejs`.
Types:
- makeNodeJsEnvironment (`function { ... } -> package`):
Expand Down
26 changes: 26 additions & 0 deletions makes/utils/makeNodeJsLockfile/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# shellcheck shell=bash

function main {
local node_js_version="${1}"
local package_json="${2}"
local package_lock="${3}"
local npm_install_args=(
--audit false
--ignore-scripts true
)

case "${node_js_version}" in
10) npm=__argNode10__/bin/npm ;;
12) npm=__argNode12__/bin/npm ;;
14) npm=__argNode14__/bin/npm ;;
16) npm=__argNode16__/bin/npm ;;
*) critical NodeJs version not supported: "${node_js_version}" ;;
esac \
&& pushd "$(mktemp -d)" \
&& copy "${package_json}" package.json \
&& "${npm}" install "${npm_install_args[@]}" \
&& copy package-lock.json "${package_lock}" \
&& popd || return 1
}

main "${@}"
15 changes: 15 additions & 0 deletions makes/utils/makeNodeJsLockfile/main.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ __nixpkgs__
, makeNodeJsVersion
, makeScript
, ...
}:
makeScript {
entrypoint = ./entrypoint.sh;
name = "make-node-js-lockfile";
replace = {
__argNode10__ = makeNodeJsVersion "10";
__argNode12__ = makeNodeJsVersion "12";
__argNode14__ = makeNodeJsVersion "14";
__argNode16__ = makeNodeJsVersion "16";
};
}

0 comments on commit f0492d0

Please sign in to comment.