buildkeel 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  #!/bin/sh
2
- # Starts a BuildKeel component after checking for Node.js 20 or later.
2
+ # Starts a BuildKeel component after checking for Node.js 20 or later
3
+ # (the version itself is checked by bk-start.cjs).
3
4
  # Usage: bk-launch <server|hook> [args...]
4
5
  # BK_LAUNCH_DIST overrides the directory holding the built components.
5
6
  set -u
@@ -28,11 +29,6 @@ MSG
28
29
  }
29
30
 
30
31
  command -v node >/dev/null 2>&1 || fail "Node.js was not found on your PATH."
31
- version=$(node -p "process.versions.node" 2>/dev/null) || fail "Node.js could not be run."
32
- major=${version%%.*}
33
- case "$major" in
34
- ''|*[!0-9]*) fail "Could not read the Node.js version." ;;
35
- esac
36
- [ "$major" -ge "$REQUIRED_MAJOR" ] || fail "Found Node.js $version."
37
32
 
38
- exec node "$entry" "$@"
33
+ # bk-start.cjs checks the version and runs the component in one Node process.
34
+ exec node "$here/bk-start.cjs" "$entry" "$@"
@@ -1,5 +1,6 @@
1
1
  @echo off
2
- rem Starts a BuildKeel component after checking for Node.js 20 or later.
2
+ rem Starts a BuildKeel component after checking for Node.js 20 or later
3
+ rem (the version itself is checked by bk-start.cjs).
3
4
  rem Usage: bk-launch <server|hook> [args...]
4
5
  rem BK_LAUNCH_DIST overrides the directory holding the built components.
5
6
  setlocal EnableDelayedExpansion
@@ -13,7 +14,9 @@ echo usage: bk-launch ^<server^|hook^> [args...] 1>&2
13
14
  exit /b 64
14
15
 
15
16
  :target_ok
16
- if defined BK_LAUNCH_DIST (set "DIST=%BK_LAUNCH_DIST%") else (set "DIST=%~dp0..\dist")
17
+ rem Taken before the arguments are shifted: shift moves the script's own path too.
18
+ set "HERE=%~dp0"
19
+ if defined BK_LAUNCH_DIST (set "DIST=%BK_LAUNCH_DIST%") else (set "DIST=%HERE%..\dist")
17
20
 
18
21
  set "ARGS="
19
22
  :collect
@@ -28,20 +31,8 @@ if errorlevel 1 (
28
31
  set "REASON=Node.js was not found on your PATH."
29
32
  goto :fail
30
33
  )
31
- set "VERSION="
32
- for /f "delims=" %%v in ('node -p "process.versions.node" 2^>nul') do set "VERSION=%%v"
33
- if not defined VERSION (
34
- set "REASON=Node.js could not be run."
35
- goto :fail
36
- )
37
- for /f "tokens=1 delims=." %%m in ("%VERSION%") do set "MAJOR=%%m"
38
- set /a MAJOR_NUM=MAJOR 2>nul
39
- if %MAJOR_NUM% LSS %REQUIRED_MAJOR% (
40
- set "REASON=Found Node.js %VERSION%."
41
- goto :fail
42
- )
43
-
44
- node "%DIST%\%ENTRY%" %ARGS%
34
+ rem bk-start.cjs checks the version and runs the component in one Node process.
35
+ node "%HERE%bk-start.cjs" "%DIST%\%ENTRY%" %ARGS%
45
36
  exit /b %ERRORLEVEL%
46
37
 
47
38
  :fail
@@ -0,0 +1,25 @@
1
+ // Checks for Node.js 20 or later, then runs a BuildKeel component in this same
2
+ // process. Started by bk-launch, so each start costs one Node process, not two.
3
+ // Usage: node bk-start.cjs <component entry> [args...]
4
+ // Kept to old syntax so an old Node can still read it and say what is needed.
5
+ "use strict";
6
+
7
+ var REQUIRED_MAJOR = 20;
8
+
9
+ var version = process.versions.node;
10
+ var major = Number(version.split(".")[0]);
11
+ if (!(major >= REQUIRED_MAJOR)) {
12
+ process.stderr.write(
13
+ "BuildKeel needs Node.js " + REQUIRED_MAJOR + " or later. Found Node.js " + version + ".\n" +
14
+ 'Install it from https://nodejs.org or with your version manager (for example "nvm install ' + REQUIRED_MAJOR + '"), then start a new session.\n',
15
+ );
16
+ process.exit(1);
17
+ }
18
+
19
+ var entry = process.argv[2];
20
+ // The component reads its own arguments from process.argv.slice(2), as if Node had started it directly.
21
+ process.argv.splice(1, 2, entry);
22
+ import(require("node:url").pathToFileURL(entry).href).catch(function (error) {
23
+ process.stderr.write("BuildKeel could not start " + entry + ": " + (error && error.message ? error.message : String(error)) + "\n");
24
+ process.exit(1);
25
+ });