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
26 changes: 24 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: actions/cache@v5
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}-${{ matrix.node-version }}
key: ${{ runner.os }}-modules-${{ hashFiles('**/package.json') }}-${{ matrix.node-version }}
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install
Expand All @@ -37,6 +37,28 @@ jobs:
- name: Run examples
run: node examples/example.js

verify-package:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v5
- name: Use Node.js 22 (LTS)
uses: actions/setup-node@v5
with:
node-version: '22'
check-latest: true
- name: Cache Node.js modules
id: yarn-cache
uses: actions/cache@v5
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/package.json') }}-22
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install
- name: Verify published artifact (pack, publint, attw)
run: yarn verify:package

deno:
runs-on: ubuntu-latest
strategy:
Expand All @@ -54,7 +76,7 @@ jobs:
uses: actions/cache@v5
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}-${{ matrix.node-version }}-deno
key: ${{ runner.os }}-modules-${{ hashFiles('**/package.json') }}-${{ matrix.node-version }}-deno
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install
Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
"ntp-packet-parser": "^0.6.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "0.18.2",
"@types/node": "^20 || ^22 || ^24 || ^25",
"prettier": "3.8.3",
"publint": "0.3.18",
"ts-node": "10.9.2",
"typescript": "6.0.3"
},
Expand All @@ -39,8 +41,13 @@
"test:integration:esm": "node test/integration/esm.mjs",
"test:integration:deno": "deno run --allow-read test/integration/deno.ts && deno run --allow-read test/integration/deno-esm.ts",
"test:integration": "yarn test:integration:cjs && yarn test:integration:esm",
"test:unit": "node scripts/run-unit-tests.mjs",
"prettier": "prettier --write src/**/*.ts",
"prettier:lint": "prettier --list-different src/**/*.ts"
"prettier:lint": "prettier --list-different src/**/*.ts",
"verify:pack": "npm pack --dry-run",
"verify:publint": "publint",
"verify:attw": "attw --pack .",
"verify:package": "yarn build && yarn verify:pack && yarn verify:publint && yarn verify:attw"
},
"keywords": [
"ntp",
Expand All @@ -53,7 +60,7 @@
"author": "Laurens Stötzel",
"repository": {
"type": "git",
"url": "https://github.com/buffcode/ntp-time-sync.git"
"url": "git+https://github.com/buffcode/ntp-time-sync.git"
},
"files": [
"dist"
Expand Down
53 changes: 53 additions & 0 deletions scripts/run-unit-tests.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Runner for the unit test suite.
//
// Discovers every test/unit/**/*.test.ts file and spawns `node --test` with
// ts-node's transpile-only CJS hook registered. Uses TS_NODE_COMPILER_OPTIONS
// to force CommonJS compilation with bundler resolution so that the source's
// `.js`-suffixed ESM-style imports resolve correctly under Yarn PnP without
// pulling in a PnP ESM loader.

import { readdirSync, statSync } from "node:fs";
import { join, relative } from "node:path";
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";

const projectRoot = fileURLToPath(new URL("..", import.meta.url));
const testRoot = join(projectRoot, "test", "unit");

function collectTestFiles(dir) {
const out = [];
for (const entry of readdirSync(dir)) {
const full = join(dir, entry);
const st = statSync(full);
if (st.isDirectory()) {
out.push(...collectTestFiles(full));
} else if (st.isFile() && entry.endsWith(".test.ts")) {
out.push(relative(projectRoot, full));
}
}
return out;
}

const testFiles = collectTestFiles(testRoot).sort();
if (testFiles.length === 0) {
console.error("No test files found under test/unit/");
process.exit(1);
}

const result = spawnSync(
process.execPath,
["--test", "--require", "ts-node/register/transpile-only", ...testFiles],
{
stdio: "inherit",
cwd: projectRoot,
env: {
...process.env,
TS_NODE_COMPILER_OPTIONS: JSON.stringify({
module: "commonjs",
moduleResolution: "bundler",
}),
},
}
);

process.exit(result.status ?? 1);
Loading