Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions .github/scripts/check-installed-package.js
Original file line number Diff line number Diff line change
@@ -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 <installed package folder>
//
// 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 <installed package folder>');
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');
71 changes: 71 additions & 0 deletions .github/workflows/published-install-check.yml
Original file line number Diff line number Diff line change
@@ -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"
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Loading