diff --git a/.github/scripts/check-installed-package.js b/.github/scripts/check-installed-package.js new file mode 100644 index 000000000..b7fad595b --- /dev/null +++ b/.github/scripts/check-installed-package.js @@ -0,0 +1,155 @@ +#!/usr/bin/env node +// Checks FHIRsmith as installed from its published package (npm install -g fhirsmith), not as a +// clone: the published-install-check workflow packs the package, installs the tarball globally and +// runs this on the installed copy. An install from the registry differs from a clone in ways the +// other checks don't see: +// - .npmignore decides which files are in the package. A pattern that matches more than meant drops +// files the server loads (an unanchored vendor/ dropped ips/vendor/, and the server didn't start) +// - npm doesn't apply the package's overrides or (it appears) its allowScripts when the package is +// itself installed, so a native module can be left without its binary (roaring, with no error from +// npm install) +// +// Usage: node check-installed-package.js +// +// 1. every require() of a literal string in a .js file in the package has to resolve, from that file, +// in the installed tree. A require of a devDependency is a warning, not a failure: devDependencies +// aren't installed, but a file that only tests or tools load can name one +// 2. the native modules have to load, not just resolve +// +// Not checked: comments (examples and remarks name modules), minified bundles and browser assets +// (*.min.js, static/: their require()s are guarded, for when they run under a module loader), and the +// known exceptions below + +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const { createRequire, builtinModules } = require('module'); + +const pkgDir = path.resolve(process.argv[2] || ''); +const manifestPath = path.join(pkgDir, 'package.json'); +if (!process.argv[2] || !fs.existsSync(manifestPath)) { + console.error('usage: node check-installed-package.js '); + process.exit(2); +} +const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); +const devDependencies = new Set(Object.keys(manifest.devDependencies || {})); +const optionalDependencies = new Set(Object.keys(manifest.optionalDependencies || {})); +const builtins = new Set(builtinModules); + +// the package a bare specifier names: 'a/b' -> 'a', '@s/a/b' -> '@s/a' +function packageName(spec) { + const parts = spec.split('/'); + return spec.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0]; +} + +function jsFiles(dir, result = []) { + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + if (entry.name === 'node_modules') { + continue; + } + const full = path.join(dir, entry.name); + if (entry.isDirectory()) { + jsFiles(full, result); + } else if (entry.isFile() && (entry.name.endsWith('.js') || entry.name.endsWith('.cjs'))) { + result.push(full); + } + } + return result; +} + +// file (relative to the package, with /) -> the modules it may require that aren't installed, and why +const KNOWN = { + 'utilities/windows-install.js': { modules: ['node-windows'], why: 'run by hand on Windows, after npm install -g node-windows' } +}; + +function skipFile(rel) { + return rel.endsWith('.min.js') || rel.startsWith('static/'); +} + +// comments out, so that examples and remarks in them aren't taken for code. Not a parser: a block +// comment, and a line that starts with // or *, which is how comments are written here +function stripComments(source) { + return source.replace(/\/\*[\s\S]*?\*\//g, '').split('\n').filter((line) => { + const t = line.trim(); + return !t.startsWith('//') && !t.startsWith('*'); + }).join('\n'); +} + +const REQUIRE = /\brequire\(\s*(['"])([^'"\n]+)\1\s*\)/g; +const failures = []; +const warnings = []; +let checked = 0; + +// 1. the require graph +const files = jsFiles(pkgDir); +let scanned = 0; +for (const file of files) { + const rel = path.relative(pkgDir, file).split(path.sep).join('/'); + if (skipFile(rel)) { + continue; + } + scanned++; + const source = stripComments(fs.readFileSync(file, 'utf8')); + const req = createRequire(file); + for (const match of source.matchAll(REQUIRE)) { + const spec = match[2]; + if (KNOWN[rel] && KNOWN[rel].modules.includes(spec)) { + continue; + } + if (spec.startsWith('node:') || builtins.has(spec) || builtins.has(spec.split('/')[0])) { + continue; + } + checked++; + try { + req.resolve(spec); + } catch (error) { + const bare = !spec.startsWith('.') && !spec.startsWith('/'); + const name = bare ? packageName(spec) : null; + if (bare && devDependencies.has(name)) { + warnings.push(`${rel}: require('${spec}') - a devDependency, not installed`); + } else if (bare && optionalDependencies.has(name)) { + // checked below, where the native modules are loaded + warnings.push(`${rel}: require('${spec}') - an optionalDependency that isn't installed`); + } else { + failures.push(`${rel}: require('${spec}') doesn't resolve`); + } + } + } +} +console.log(`${scanned} files scanned, ${checked} requires checked`); + +// 2. the native modules load. roaring is an optionalDependency, but the tx module can't run without it +const pkgRequire = createRequire(manifestPath); +const native = [ + ['roaring', (m) => new m.RoaringBitmap32([1, 2, 3]).size], + ['better-sqlite3', (m) => m(':memory:').prepare('select sqlite_version() v').get().v], + ['sqlite3', (m) => { new m.Database(':memory:').close(); return 'opened'; }], + ['bcrypt', (m) => (m.hashSync('x', 4) ? 'hashed' : '')] +]; +for (const [name, use] of native) { + try { + console.log(`${name}: ${use(pkgRequire(name))}`); + } catch (error) { + failures.push(`${name} doesn't load: ${error.message.split('\n')[0]}`); + } +} +// koffi is optional and the server runs without it +try { + pkgRequire('koffi'); + console.log('koffi: loaded'); +} catch (error) { + warnings.push(`koffi (optional) doesn't load: ${error.message.split('\n')[0]}`); +} + +for (const w of warnings) { + console.log(`warning: ${w}`); +} +for (const f of failures) { + console.log(`::error::${f}`); +} +if (failures.length > 0) { + console.error(`${failures.length} problem(s) with the installed package`); + process.exit(1); +} +console.log('the installed package is complete, and its native modules load'); diff --git a/.github/workflows/published-install-check.yml b/.github/workflows/published-install-check.yml new file mode 100644 index 000000000..f9c3f9ff2 --- /dev/null +++ b/.github/workflows/published-install-check.yml @@ -0,0 +1,71 @@ +name: Published install check + +# Installs FHIRsmith the way a server does - npm install -g of the published package - and checks the +# installed copy (.github/scripts/check-installed-package.js): every file the code requires is in the +# package, and the native modules load. A clone (npm ci, the other checks) can't see either problem: +# .npmignore decides what is in the package, and npm applies neither the package's overrides nor +# (it appears) its allowScripts when the package is itself installed. +# +# Runs with the npm that comes with Node 24 and with the latest npm, as which install scripts npm runs +# depends on its version. The release calls it before publishing +on: + push: + branches: [main] + paths-ignore: + - '**.md' + - docs/** + pull_request: + paths-ignore: + - '**.md' + - docs/** + workflow_dispatch: + workflow_call: + +# it only reads the repository +permissions: + contents: read + +jobs: + published-install: + name: Published install (npm ${{ matrix.npm }}) + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + npm: [bundled, latest] + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: '24' + + - name: Use the latest npm + if: matrix.npm == 'latest' + run: npm install -g npm@latest + + - name: Versions + run: | + node --version + npm --version + + # the tarball npm publish would upload + - name: Pack + run: | + tgz=$(npm pack --pack-destination "$RUNNER_TEMP" --silent | tail -n 1) + echo "TGZ=$RUNNER_TEMP/$tgz" >> "$GITHUB_ENV" + echo "packed $tgz" + + # a global install, into its own prefix so it needs no sudo: the same layout as + # /usr/lib/node_modules/fhirsmith. The dependencies come from the registry, as for npm install -g fhirsmith + - name: Install the package globally + run: | + prefix="$RUNNER_TEMP/global" + npm install -g --prefix "$prefix" "$TGZ" + echo "PKG_DIR=$(npm root -g --prefix "$prefix")/fhirsmith" >> "$GITHUB_ENV" + + - name: Check the installed package + run: node .github/scripts/check-installed-package.js "$PKG_DIR" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index de2361428..69b9f07da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -156,10 +156,18 @@ jobs: prerelease: false token: ${{ secrets.GITHUB_TOKEN }} + # npm install -g of what would be published: every file the code requires is in the package, and the + # native modules load (published-install-check.yml) + published-install: + name: Published install check + permissions: + contents: read + uses: ./.github/workflows/published-install-check.yml + npm-publish: name: Publish to NPM runs-on: ubuntu-latest - needs: [verify-version, test] + needs: [verify-version, test, published-install] permissions: contents: read id-token: write diff --git a/.npmignore b/.npmignore index a255b9467..fc761fcfc 100644 --- a/.npmignore +++ b/.npmignore @@ -63,7 +63,8 @@ docs/ # Release and development scripts, and test reports release.sh -vendor/ +# anchored: an unanchored vendor/ also drops ips/vendor/, the IPS export libraries the server loads at startup +/vendor/ changelog-template.md tsconfig.eslint.json test-scripts/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 89f4c06a1..b85284dbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,32 @@ All notable changes to Health Intersections FHIRsmith will be documented in this The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.1] - 2026-mm-dd + +### Security + +- + +### Added + +- + +### Changed + +- + +### Fixed + +- + +### Removed + +- + +### Tx Conformance Statement + +(paste) + ## [1.1.0] - 2026-12-04 ### Security diff --git a/package-lock.json b/package-lock.json index 1f081be02..36d5c1677 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fhirsmith", - "version": "1.1.0", + "version": "1.1.1-snapshot", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "fhirsmith", - "version": "1.1.0", + "version": "1.1.1-snapshot", "license": "BSD-3-Clause", "dependencies": { "axios": "^1.13.4", diff --git a/package.json b/package.json index ae0b72fc0..be1331333 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fhirsmith", - "version": "1.1.0", + "version": "1.1.1-snapshot", "txVersion": "1.12.0", "description": "A Node.js server that provides a collection of tools to serve the FHIR ecosystem", "main": "server.js",