Skip to content

Commit 15da60f

Browse files
committed
javascript/nodejs*: adapt to JS runtime now written in TypeScript
See kaitai-io/kaitai_struct_javascript_runtime#25
1 parent e03e1c6 commit 15da60f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/javascript/_common/prepare

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,48 @@ elif echo "$NODEJS_VERSION" | grep '^v12\.'; then
1919
MOCHA_VERSION="@<10"
2020
fi
2121

22+
npm config set loglevel verbose
23+
2224
# Install JavaScript dependencies
23-
npm install -g --loglevel verbose \
25+
npm install -g \
2426
"mocha$MOCHA_VERSION" \
2527
iconv-lite
28+
29+
# Install the runtime library. We fetch
30+
# https://www.npmjs.com/package/kaitai-struct/v/next and install it globally in
31+
# the Docker image. This means that whenever we make a change in
32+
# https://github.com/kaitai-io/kaitai_struct_javascript_runtime and want to test
33+
# it in CI, we need to follow these steps:
34+
#
35+
# 1. Publish a new version to npm with the @next tag. In practice, this just
36+
# means pushing a tag in [this
37+
# format](https://github.com/kaitai-io/kaitai_struct_javascript_runtime/blob/2acb0d8b09fde9c95fc77ee3019f6d6b1c73f040/.github/workflows/build.yml#L6)
38+
# to GitHub, which will trigger `npm publish --tag next` automatically.
39+
# 2. Trigger the CI workflow in
40+
# https://github.com/kaitai-io/kaitai_struct_docker_images to rebuild the
41+
# JavaScript Docker images to fetch the new @next version.
42+
#
43+
# Admittedly, it's not ideal to rely on an embedded runtime library (as
44+
# mentioned in
45+
# https://github.com/kaitai-io/kaitai_struct/issues/187#issuecomment-2273725000).
46+
# Most Docker images can dynamically use any version of the runtime library
47+
# mounted at `/runtime`, which is very easy to work with. However, since the
48+
# JavaScript runtime library was migrated to TypeScript (see
49+
# https://github.com/kaitai-io/kaitai_struct_javascript_runtime/pull/25), this
50+
# is not so easy because the TypeScript code must first be compiled into
51+
# JavaScript. We may not be able to do that on old unsupported Node.js versions
52+
# that we're still testing on (because it requires some npm dependencies and
53+
# most npm packages don't work on old versions of Node.js unless you also use
54+
# outdated versions of those packages).
55+
#
56+
# Installing our `kaitai-struct` npm package in the Docker image is much easier.
57+
# If it causes problems in the future, we can come up with another solution.
58+
59+
npm install -g \
60+
kaitai-struct@next
61+
62+
# Tell `npm` to use offline mode from now on (the
63+
# [`docker-ci`](https://github.com/kaitai-io/kaitai_struct_tests/blob/f831283c0b9d84eb52f6e8ec593c496b0c254854/docker-ci)
64+
# script runs the Docker containers with `--network none`, so if `npm` decided
65+
# to access the network for some reason, it would lead to errors)
66+
npm config set offline true

src/javascript/nodejs4-linux-x86_64/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ COPY 4img/* ./
88
# uid/gid", see https://stackoverflow.com/a/52196681
99
RUN npm config set unsafe-perm true
1010

11+
# npm v5 seems to be the latest version compatible with Node.js 4 (found
12+
# experimentally).
13+
RUN npm install --loglevel info -g npm@latest-5
14+
1115
# Install all dependencies
1216
RUN ./prepare
1317
RUN ./prepare-alpine-init && ./prepare-alpine-ruby && ./prepare-alpine-uninit

0 commit comments

Comments
 (0)