ripex 0.3.1

Multi-language structural parsing and fact extraction.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
name: Node Release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:
    inputs:
      version:
        description: "Version to assemble (without the leading v)"
        required: true
        default: "0.3.1"
        type: string
      publish:
        description: "Enable npm publication (also requires NPM_PUBLISH_ENABLED=true)"
        required: false
        default: false
        type: boolean

# Build and assembly jobs never receive registry or repository write access.
permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always
  RELEASE_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.version || github.ref_name }}

concurrency:
  group: node-release-${{ github.ref }}
  cancel-in-progress: false

jobs:
  validate:
    name: Validate Node release version
    runs-on: ubuntu-latest
    timeout-minutes: 20
    permissions:
      contents: read
    steps:
      # actions/checkout v4.2.2
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262

      - name: Install latest Node.js
        # actions/setup-node v4.2.0
        uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
        with:
          node-version: 22

      - name: Install Rust 1.85.0 for root metadata
        # dtolnay/rust-toolchain
        uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4
        with:
          toolchain: 1.85.0

      - name: Validate all package versions
        env:
          RELEASE_VERSION_INPUT: ${{ env.RELEASE_VERSION }}
        shell: bash
        run: |
          set -euo pipefail
          expected="${RELEASE_VERSION_INPUT#v}"
          [[ "$expected" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || {
            echo "Release version must be a semantic X.Y.Z value: $expected" >&2
            exit 1
          }
          root_version="$(
            cargo metadata --locked --no-deps --format-version 1 |
              node -e 'const fs = require("node:fs"); const m = JSON.parse(fs.readFileSync(0, "utf8")); console.log(m.packages.find((p) => p.name === "ripex").version)'
          )"
          binding_version="$(
            cargo metadata --manifest-path bindings/node/Cargo.toml --locked --no-deps --format-version 1 |
              node -e 'const fs = require("node:fs"); const m = JSON.parse(fs.readFileSync(0, "utf8")); console.log(m.packages.find((p) => p.name === "ripex-node").version)'
          )"
          npm_version="$(node -p "require('./bindings/node/package.json').version")"
          for pair in \
            "root ripex $root_version" \
            "binding ripex-node $binding_version" \
            "npm @astraive/ripex $npm_version"; do
            read -r kind package version <<<"$pair"
            test "$version" = "$expected" || {
              echo "$kind package $package is $version, expected $expected" >&2
              exit 1
            }
          done

  build:
    name: Build Node binding (${{ matrix.target }})
    needs: validate
    runs-on: ${{ matrix.os }}
    timeout-minutes: 45
    permissions:
      contents: read
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            binary: ripex.linux-x64-gnu.node
            cross: "0"
            runtime: true
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            binary: ripex.linux-arm64-gnu.node
            cross: "1"
            runtime: false
          - os: macos-14
            target: x86_64-apple-darwin
            binary: ripex.darwin-x64.node
            cross: "0"
            runtime: false
          - os: macos-14
            target: aarch64-apple-darwin
            binary: ripex.darwin-arm64.node
            cross: "0"
            runtime: true
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            binary: ripex.win32-x64-msvc.node
            cross: "0"
            runtime: true

    steps:
      # actions/checkout v4.2.2
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262

      - name: Install latest Node.js
        # actions/setup-node v4.2.0
        uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
        with:
          node-version: 22

      - name: Install latest pnpm
        run: npm install --global pnpm@10.28.2

      - name: Install latest Bun
        run: npm install --global bun@1.3.14


      - name: Install Rust 1.85.0 and target
        # dtolnay/rust-toolchain
        uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4
        with:
          toolchain: 1.85.0
          target: ${{ matrix.target }}

      - name: Install Node binding dependencies
        working-directory: bindings/node
        run: pnpm install --frozen-lockfile --ignore-scripts
      - name: Install aarch64 cross-compiler
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu

      - name: Build release binding
        working-directory: bindings/node
        env:
          NAPI_TARGET: ${{ matrix.target }}
          CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
        run: npm run build:release

      - name: Verify target binary and package metadata
        working-directory: bindings/node
        env:
          EXPECTED_BINARY: ${{ matrix.binary }}
          EXPECTED_TARGET: ${{ matrix.target }}
        shell: bash
        run: |
          set -euo pipefail
          node - "$EXPECTED_BINARY" "$EXPECTED_TARGET" <<'NODE'
          const fs = require('node:fs');
          const binary = process.argv[2];
          const target = process.argv[3];
          const binaries = fs.readdirSync('.')
            .filter((entry) => entry.endsWith('.node'))
            .filter((entry) => fs.statSync(entry).isFile())
            .sort();
          if (binaries.length !== 1 || binaries[0] !== binary) {
            throw new Error(`expected exactly ${binary}, found ${binaries.join(', ')}`);
          }
          const metadata = JSON.parse(fs.readFileSync('package.json', 'utf8'));
          const targets = metadata.napi?.targets;
          if (!Array.isArray(targets) || targets.length !== 5 || !targets.includes(target)) {
            throw new Error(`package.json does not declare target ${target}`);
          }
          if (metadata.scripts?.postinstall) {
            throw new Error('postinstall network/download hooks are forbidden');
          }
          NODE

      - name: Run native Node binding tests
        if: matrix.runtime == true
        working-directory: bindings/node
        run: npm test

      - name: Run Bun native smoke test
        if: matrix.runtime == true
        working-directory: bindings/node
        run: bun test test/index.bun.test.mjs
      - name: Check public TypeScript declarations
        if: matrix.runtime == true
        working-directory: bindings/node
        run: npm run test:types

      - name: Check package contents
        if: matrix.runtime == true
        working-directory: bindings/node
        run: npm run pack:dry

      - name: Upload target binding artifact
        # actions/upload-artifact v4.6.0
        uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
        with:
          name: node-release-target-${{ matrix.target }}
          path: |
            bindings/node/${{ matrix.binary }}
            bindings/node/index.cjs
            bindings/node/index.js
            bindings/node/index.d.ts
          if-no-files-found: error
          retention-days: 14

  assemble:
    name: Assemble npm platform packages
    needs: build
    runs-on: ubuntu-latest
    timeout-minutes: 30
    permissions:
      contents: read
    steps:
      # actions/checkout v4.2.2
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262

      - name: Install latest Node.js
        # actions/setup-node v4.2.0
        uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
        with:
          node-version: 22

      - name: Install latest pnpm
        run: npm install --global pnpm@10.28.2


      - name: Install Node binding dependencies
        working-directory: bindings/node
        run: pnpm install --frozen-lockfile --ignore-scripts


      - name: Download target artifacts
        # actions/download-artifact v4.1.8
        uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
        with:
          pattern: node-release-target-*
          path: bindings/node/artifacts
          merge-multiple: true

      - name: Normalize and validate native artifact set
        working-directory: bindings/node
        shell: bash
        run: |
          set -euo pipefail
          expected=(
            ripex.linux-x64-gnu.node
            ripex.linux-arm64-gnu.node
            ripex.darwin-x64.node
            ripex.darwin-arm64.node
            ripex.win32-x64-msvc.node
          )
          mapfile -t found < <(find artifacts -type f -name '*.node' -print | sort)
          test "${#found[@]}" -eq 5
          declare -A seen=()
          for file in "${found[@]}"; do
            base="${file##*/}"
            case " ${expected[*]} " in *" $base "*) ;; *) echo "unexpected native artifact: $base" >&2; exit 1 ;; esac
            test -z "${seen[$base]+set}" || { echo "duplicate native artifact: $base" >&2; exit 1; }
            seen[$base]=1
            if [[ "$file" != "artifacts/$base" ]]; then
              mv "$file" "artifacts/$base"
            fi
          done
          for base in "${expected[@]}"; do test -f "artifacts/$base"; done
          direct_count="$(node -e 'const fs = require("node:fs"); process.stdout.write(String(fs.readdirSync("artifacts", { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".node")).length))')"
          test "$direct_count" -eq 5

      - name: Create platform package directories
        working-directory: bindings/node
        run: pnpm exec napi create-npm-dir -t .

      - name: Assemble binaries into platform packages
        working-directory: bindings/node
        run: pnpm exec napi artifacts

      - name: Verify exactly five platform packages and binaries
        working-directory: bindings/node
        shell: bash
        run: |
          set -euo pipefail
          declare -A expected=(
            [linux-x64-gnu]=ripex.linux-x64-gnu.node
            [linux-arm64-gnu]=ripex.linux-arm64-gnu.node
            [darwin-x64]=ripex.darwin-x64.node
            [darwin-arm64]=ripex.darwin-arm64.node
            [win32-x64-msvc]=ripex.win32-x64-msvc.node
          )
          mapfile -t dirs < <(node -e "const fs = require('node:fs'); process.stdout.write(fs.readdirSync('npm', { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort().join('\\n'))")
          test "${#dirs[@]}" -eq 5
          for dir in "${dirs[@]}"; do
            test -n "${expected[$dir]+set}" || { echo "unexpected platform directory: $dir" >&2; exit 1; }
            mapfile -t binaries < <(node -e "const fs = require('node:fs'); process.stdout.write(fs.readdirSync('npm/$dir', { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith('.node')).map((entry) => entry.name).sort().join('\\n'))")
            test "${#binaries[@]}" -eq 1
            test "${binaries[0]}" = "${expected[$dir]}"
          done
          all_count="$(node -e 'const fs = require("node:fs"); let count = 0; for (const dir of fs.readdirSync("npm", { withFileTypes: true }).filter((entry) => entry.isDirectory())) count += fs.readdirSync("npm/" + dir.name, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".node")).length; process.stdout.write(String(count))')"
          test "$all_count" -eq 5
          for dir in "${!expected[@]}"; do test -d "npm/$dir"; done

      - name: Reject postinstall download hooks
        working-directory: bindings/node
        shell: bash
        run: |
          set -euo pipefail
          node <<'NODE'
          const fs = require('node:fs');
          const path = require('node:path');
          const manifests = ['package.json', ...fs.readdirSync('npm', { withFileTypes: true })
            .filter((entry) => entry.isDirectory())
            .map((entry) => path.join('npm', entry.name, 'package.json'))];
          for (const file of manifests) {
            const packageJson = JSON.parse(fs.readFileSync(file, 'utf8'));
            if (packageJson.scripts?.postinstall) {
              throw new Error(`postinstall hook is forbidden: ${file}`);
            }
          }
          NODE

      - name: Check assembled package contents
        working-directory: bindings/node
        run: npm run pack:dry

      - name: Pack assembled package
        working-directory: bindings/node
        shell: bash
        run: |
          set -euo pipefail
          pack_dir="$RUNNER_TEMP/ripex-node-package"
          rm -rf "$pack_dir"
          mkdir -p "$pack_dir"
          npm pack --ignore-scripts --pack-destination "$pack_dir"
          test "$(find "$pack_dir" -maxdepth 1 -type f -name '*.tgz' | wc -l)" -eq 1

      - name: Clean install and load assembled package
        working-directory: bindings/node
        shell: bash
        run: |
          set -euo pipefail
          pack_dir="$RUNNER_TEMP/ripex-node-package"
          smoke_dir="$RUNNER_TEMP/ripex-node-smoke"
          tarball="$(find "$pack_dir" -maxdepth 1 -type f -name '*.tgz' -print -quit)"
          rm -rf "$smoke_dir"
          mkdir -p "$smoke_dir"
          cd "$smoke_dir"
          npm init -y >/dev/null
          # The non-publishing assembly intentionally leaves optionalDependencies untouched.
          # Install the matching local platform package to exercise the packed root loader offline.
          npm install --ignore-scripts --no-audit --no-fund \
            "$tarball" \
            "$GITHUB_WORKSPACE/bindings/node/npm/linux-x64-gnu" \
            >/dev/null
          node --input-type=commonjs -e "const p=require('@astraive/ripex'); const out=p.parseSync('export const x = 1',{language:'javascript'}); if(out.language!=='javascript') process.exit(1)"
          node --input-type=module -e "import { parseSync } from '@astraive/ripex'; const out=parseSync('export const x = 1',{language:'javascript'}); if(out.language!=='javascript') process.exit(1)"

      - name: Upload assembled tarball for review
        # actions/upload-artifact v4.6.0
        uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
        with:
          name: node-release-tarball-${{ env.RELEASE_VERSION }}
          path: ${{ runner.temp }}/ripex-node-package/*.tgz
          if-no-files-found: error
          retention-days: 14

  publish:
    name: Publish npm packages
    needs: [validate, assemble]
    if: >-
      needs.assemble.result == 'success' &&
      vars.NPM_PUBLISH_ENABLED == 'true' &&
      (github.event_name == 'push' || inputs.publish == true)
    runs-on: ubuntu-latest
    timeout-minutes: 30
    permissions:
      contents: write
      id-token: write
    steps:
      # actions/checkout v4.2.2
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262

      - name: Install latest Node.js with npm provenance
        # actions/setup-node v4.2.0
        uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
        with:
          node-version: 22
          registry-url: https://registry.npmjs.org

      - name: Install latest pnpm
        run: npm install --global pnpm@10.28.2


      - name: Install Node binding dependencies
        working-directory: bindings/node
        run: pnpm install --frozen-lockfile --ignore-scripts

      - name: Download target artifacts for publication
        # actions/download-artifact v4.1.8
        uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
        with:
          pattern: node-release-target-*
          path: bindings/node/artifacts
          merge-multiple: true

      - name: Normalize target artifacts
        working-directory: bindings/node
        shell: bash
        run: |
          set -euo pipefail
          mapfile -t found < <(find artifacts -type f -name '*.node' -print | sort)
          test "${#found[@]}" -eq 5
          for file in "${found[@]}"; do
            base="${file##*/}"
            if [[ "$file" != "artifacts/$base" ]]; then mv "$file" "artifacts/$base"; fi
          done

      - name: Create npm platform packages
        working-directory: bindings/node
        run: pnpm exec napi create-npm-dir -t .

      - name: Assemble platform binaries
        working-directory: bindings/node
        run: pnpm exec napi artifacts

      - name: Publish platform packages before root package
        working-directory: bindings/node
        shell: bash
        run: |
          set -euo pipefail
          # npm publication is non-atomic: napi prepublish publishes each optional
          # platform package before the final root npm publish below.
          pnpm exec napi prepublish -t npm

      - name: Publish root package with provenance
        working-directory: bindings/node
        shell: bash
        run: npm publish --provenance