Skip to content

Commit

Permalink
feat(cross): fluidattacks#1043 use node2nix
Browse files Browse the repository at this point in the history
- Use node2nix for building node modules
- Update documentation
- Update locks to include name as it is now required by node2nix

Signed-off-by: Daniel Salazar <[email protected]>
  • Loading branch information
dsalaza4 committed Dec 26, 2023
1 parent bab198e commit bc0320f
Show file tree
Hide file tree
Showing 13 changed files with 1,974 additions and 221 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__pycache__
.vscode
node_modules
48 changes: 30 additions & 18 deletions docs/src/api/extensions/node.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Get a specific Node.js version interpreter.
Types:

- makeNodeJsVersion (`function str -> package`):
- (`enum [ "14" "16" "18" ]`):
- (`enum [ "18" "20" "21" ]`):
Node.js version to use.

Example:
Expand All @@ -25,7 +25,7 @@ Example:
'';
name = "example";
searchPaths = {
bin = [ (makeNodeJsVersion "16") ];
bin = [ (makeNodeJsVersion "18") ];
};
}
```
Expand All @@ -41,25 +41,24 @@ Example:
## makeNodeJsModules

Cook the `node_modules` directory
for the given Node.js project.
for the given Node.js project
using [node2nix](https://github.com/svanderburg/node2nix).

Types:

- makeNodeJsModules (`function { ... } -> package`):
- name (`str`):
Custom name to assign to the build step, be creative, it helps in debugging.
- nodeJsVersion (`enum [ "14" "16" "18" ]`):
- nodeJsVersion (`enum [ "18" ]`):
Node.js version to use.
- packageJson (`package`):
Path to the `package.json` of your project.
- packageLockJson (`package`):
Path to the `package-lock.json` of your project.
- searchPaths (`asIn makeSearchPaths`): Optional.
Arguments here will be passed as-is to `makeSearchPaths`.
Defaults to `makeSearchPaths`'s defaults.
- shouldIgnoreScripts (`bool`): Optional.
Enable to propagate the `--ignore-scripts true` flag to npm.
Defaults to `false`.
- packageOverrides (`Attrs`): Optional.
Override behaviors when building `node_modules`.
See [node2nix arguments](https://github.com/svanderburg/node2nix/blob/315e1b85a6761152f57a41ccea5e2570981ec670/nix/node-env.nix#L568)
for more.

Example:

Expand Down Expand Up @@ -96,6 +95,7 @@ Example:
```nix
# /path/to/my/project/makes/example/main.nix
{
inputs,
makeNodeJsModules,
makeScript,
projectPath,
Expand All @@ -109,6 +109,12 @@ Example:
projectPath "/path/to/my/project/makes/example/package.json";
packageLockJson =
projectPath "/path/to/my/project/makes/example/package-lock.json";
packageOverrides = {
# Ignore post-install scripts
npmFlags = "--ignore-scripts true";
# Provide patchelf when building node_modules
buildInputs = [inputs.nixpkgs.patchelf];
};
};
in
makeScript {
Expand All @@ -117,6 +123,7 @@ Example:
};
entrypoint = ''
ls __argHello__
ls __argHello__/lib
'';
name = "example";
}
Expand All @@ -127,7 +134,8 @@ Example:
```bash
$ m . /example

hello-world-npm
/bin /lib
/node_modules
```

## makeNodeJsEnvironment
Expand All @@ -148,18 +156,16 @@ Types:
- makeNodeJsEnvironment (`function { ... } -> package`):
- name (`str`):
Custom name to assign to the build step, be creative, it helps in debugging.
- nodeJsVersion (`enum [ "14" "16" "18" ]`):
- nodeJsVersion (`enum [ "18" ]`):
Node.js version to use.
- packageJson (`package`):
Path to the `package.json` of your project.
- packageLockJson (`package`):
Path to the `package-lock.json` of your project.
- searchPaths (`asIn makeSearchPaths`): Optional.
Arguments here will be passed as-is to `makeSearchPaths`.
Defaults to `makeSearchPaths`'s defaults.
- shouldIgnoreScripts (`bool`): Optional.
Enable to propagate the `--ignore-scripts true` flag to npm.
Defaults to `false`.
- packageOverrides (`Attrs`): Optional.
Override behaviors when building `node_modules`.
See [node2nix arguments](https://github.com/svanderburg/node2nix/blob/315e1b85a6761152f57a41ccea5e2570981ec670/nix/node-env.nix#L568)
for more.

Example:

Expand Down Expand Up @@ -208,6 +214,12 @@ Example:
projectPath "/path/to/my/project/makes/example/package.json";
packageLockJson =
projectPath "/path/to/my/project/makes/example/package-lock.json";
packageOverrides = {
# Ignore post-install scripts
npmFlags = "--ignore-scripts true";
# Provide patchelf when building node_modules
buildInputs = [inputs.nixpkgs.patchelf];
};
};
in
makeScript {
Expand Down
Loading

0 comments on commit bc0320f

Please sign in to comment.