Skip to content

Commit

Permalink
javascript/nodejs*: adapt to JS runtime now written in TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
generalmimon committed Oct 2, 2024
1 parent e03e1c6 commit 15da60f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/javascript/_common/prepare
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,48 @@ elif echo "$NODEJS_VERSION" | grep '^v12\.'; then
MOCHA_VERSION="@<10"
fi

npm config set loglevel verbose

# Install JavaScript dependencies
npm install -g --loglevel verbose \
npm install -g \
"mocha$MOCHA_VERSION" \
iconv-lite

# Install the runtime library. We fetch
# https://www.npmjs.com/package/kaitai-struct/v/next and install it globally in
# the Docker image. This means that whenever we make a change in
# https://github.com/kaitai-io/kaitai_struct_javascript_runtime and want to test
# it in CI, we need to follow these steps:
#
# 1. Publish a new version to npm with the @next tag. In practice, this just
# means pushing a tag in [this
# format](https://github.com/kaitai-io/kaitai_struct_javascript_runtime/blob/2acb0d8b09fde9c95fc77ee3019f6d6b1c73f040/.github/workflows/build.yml#L6)
# to GitHub, which will trigger `npm publish --tag next` automatically.
# 2. Trigger the CI workflow in
# https://github.com/kaitai-io/kaitai_struct_docker_images to rebuild the
# JavaScript Docker images to fetch the new @next version.
#
# Admittedly, it's not ideal to rely on an embedded runtime library (as
# mentioned in
# https://github.com/kaitai-io/kaitai_struct/issues/187#issuecomment-2273725000).
# Most Docker images can dynamically use any version of the runtime library
# mounted at `/runtime`, which is very easy to work with. However, since the
# JavaScript runtime library was migrated to TypeScript (see
# https://github.com/kaitai-io/kaitai_struct_javascript_runtime/pull/25), this
# is not so easy because the TypeScript code must first be compiled into
# JavaScript. We may not be able to do that on old unsupported Node.js versions
# that we're still testing on (because it requires some npm dependencies and
# most npm packages don't work on old versions of Node.js unless you also use
# outdated versions of those packages).
#
# Installing our `kaitai-struct` npm package in the Docker image is much easier.
# If it causes problems in the future, we can come up with another solution.

npm install -g \
kaitai-struct@next

# Tell `npm` to use offline mode from now on (the
# [`docker-ci`](https://github.com/kaitai-io/kaitai_struct_tests/blob/f831283c0b9d84eb52f6e8ec593c496b0c254854/docker-ci)
# script runs the Docker containers with `--network none`, so if `npm` decided
# to access the network for some reason, it would lead to errors)
npm config set offline true
4 changes: 4 additions & 0 deletions src/javascript/nodejs4-linux-x86_64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ COPY 4img/* ./
# uid/gid", see https://stackoverflow.com/a/52196681
RUN npm config set unsafe-perm true

# npm v5 seems to be the latest version compatible with Node.js 4 (found
# experimentally).
RUN npm install --loglevel info -g npm@latest-5

# Install all dependencies
RUN ./prepare
RUN ./prepare-alpine-init && ./prepare-alpine-ruby && ./prepare-alpine-uninit
Expand Down

0 comments on commit 15da60f

Please sign in to comment.