nodejs: clean up builder

This commit is contained in:
hsjobeki 2023-01-04 14:31:18 +01:00
parent bea76f9015
commit 9b701bb6c8
5 changed files with 34 additions and 17 deletions

View File

@ -69,9 +69,12 @@ in `projects.toml` set the `builder` attribute to `'strict-builder'`
{{#include ../../../examples/nodejs_alternative_builder/projects.toml}}
```
#### Override on the `strict-builder`
#### Override on the `strict-builder` (e.g custom bundling / static pages)
As currently the builder has three outputs: `$out`, `$lib`, `$deps`.
Sometimes it may be necessary to override the installPhase to build e.g. static page with `webpack` or others like `react`, `vue`, `anuglar` etc.
When overriding the `installPhase` the user is required to create all three out-paths:
> next.js export (e.g. for static sites)
@ -108,9 +111,10 @@ installPhase = ''
└── typescript
```
- package
##### package
- consumable as bare package
- containing all files from the `source`
- containing all files from the `source` ( _install-scripts_ already executed )
```bash
$lib
@ -120,7 +124,16 @@ installPhase = ''
└── package.json
```
- standard composition
_install-scripts_ run in the following order:
> preinstall -> install -> postinstall
>
> isolated from other packages
>
> if the isolation during installScript is causing you problems, let us know.
##### standard composition
- consumable by most users
- `{pname}/bin/...` contains all executables of this package

View File

@ -268,15 +268,10 @@
then "tar --delay-directory-restore -xf $src"
else null;
preConfigurePhases = ["d2nPatchPhase" "d2nCheckPhase"];
preConfigurePhases = ["d2nCheckPhase"];
unpackPhase = import ./unpackPhase.nix {};
# nodejs expects HOME to be set
d2nPatchPhase = ''
export HOME=$TMPDIR
'';
# pre-checks:
# - platform compatibility (os + arch must match)
d2nCheckPhase = ''
@ -302,6 +297,8 @@
configurePhase = ''
runHook preConfigure
export HOME=$TMPDIR
${nodejsBuilder}/bin/d2nNodeModules
export PATH="$PATH:node_modules/.bin"

View File

@ -12,14 +12,21 @@ with pkgs;
nodeModulesDir = pkg.deps;
in ''
# rsync the node_modules folder
# is way faster than copying everything again, because it only replaces updated files
# current Options:
# - is way faster than copying everything again, because it only replaces updated files
# - rsync can be restarted from any point, if failed or aborted mid execution.
# Options:
# -a -> all files recursive, preserve symlinks, etc.
# -c -> calculate hashsums
# -E -> preserve executables
# --delete -> removes deleted files
${rsync}/bin/rsync -acE --delete ${nodeModulesDir}/* ./node_modules/
ID=${nodeModulesDir}
mkdir -p .dream2nix
if [[ "$ID" != "$(cat .dream2nix/.node_modules_id)" || ! -d "node_modules" ]];
then
echo $ID > .dream2nix/.node_modules_id
${rsync}/bin/rsync -aE --delete ${nodeModulesDir}/ ./node_modules/
fi
chmod -R +w ./node_modules
export PATH="$PATH:$(realpath ./node_modules)/.bin"

View File

@ -15,7 +15,7 @@ import os
from pathlib import Path
def check():
def checkPlatform():
"""
Checks if the package can be installed.
- platform must have compatible: os + cpu

View File

@ -6,7 +6,7 @@ authors = ["hsjobeki <hsjobeki@gmail.com>"]
[tool.poetry.scripts]
d2nNodeModules = 'nodejs_builder.main:d2nNodeModules'
d2nCheck = 'nodejs_builder.main:check'
checkPlatform = 'nodejs_builder.main:checkPlatform'
d2nMakeOutputs = 'nodejs_builder.main:makeOutputs'
[tool.poetry.dependencies]