Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

Commit fac2254

Browse files
authored
Merge pull request #791 from jpverde/main
feat(back): #789 build package lock
2 parents fb88d0e + f0492d0 commit fac2254

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,6 +3707,31 @@ It appends:
37073707
- `node_modules/.bin` to `PATH`.
37083708
- `node_modules` to [NODE_PATH][NODE_PATH].
37093709
3710+
Pre-requisites:
3711+
3712+
1. You can generate a `package-lock.json` using a specific `node` version
3713+
like this:
3714+
3715+
```bash
3716+
m github:fluidattacks/[email protected] /utils/makeNodeJsLockfile \
3717+
"${node_js_version}" \
3718+
"${package_json}" \
3719+
"${package_lock}
3720+
```
3721+
3722+
- Supported `node_js_version`s are: `10`, `12`, `14` and `16`.
3723+
- `package_json` is the **absolute path** to the `package.json` file in your
3724+
project.
3725+
- `package_lock` is the **absolute path**
3726+
to the `package-lock.json` file in your project, this file can be an empty
3727+
file.
3728+
3729+
Note: the reason behind this script is to maintain `lock` versions through the
3730+
construction of `makeNodeJsEnvironment`, since you can have an updated version
3731+
of `nodejs` or `npm` but not the same as the version stored on the
3732+
[Nixpkgs][NIXPKGS] repository. This doesn't affect your local version
3733+
of `npm` or `nodejs`.
3734+
37103735
Types:
37113736
37123737
- makeNodeJsEnvironment (`function { ... } -> package`):
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# shellcheck shell=bash
2+
3+
function main {
4+
local node_js_version="${1}"
5+
local package_json="${2}"
6+
local package_lock="${3}"
7+
local npm_install_args=(
8+
--audit false
9+
--ignore-scripts true
10+
)
11+
12+
case "${node_js_version}" in
13+
10) npm=__argNode10__/bin/npm ;;
14+
12) npm=__argNode12__/bin/npm ;;
15+
14) npm=__argNode14__/bin/npm ;;
16+
16) npm=__argNode16__/bin/npm ;;
17+
*) critical NodeJs version not supported: "${node_js_version}" ;;
18+
esac \
19+
&& pushd "$(mktemp -d)" \
20+
&& copy "${package_json}" package.json \
21+
&& "${npm}" install "${npm_install_args[@]}" \
22+
&& copy package-lock.json "${package_lock}" \
23+
&& popd || return 1
24+
}
25+
26+
main "${@}"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ __nixpkgs__
2+
, makeNodeJsVersion
3+
, makeScript
4+
, ...
5+
}:
6+
makeScript {
7+
entrypoint = ./entrypoint.sh;
8+
name = "make-node-js-lockfile";
9+
replace = {
10+
__argNode10__ = makeNodeJsVersion "10";
11+
__argNode12__ = makeNodeJsVersion "12";
12+
__argNode14__ = makeNodeJsVersion "14";
13+
__argNode16__ = makeNodeJsVersion "16";
14+
};
15+
}

0 commit comments

Comments
 (0)