Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
29bace4
Initial plan
Copilot Jan 9, 2026
4f5a347
Add script to include example URLs in JSDocs for index.d.ts
Copilot Jan 9, 2026
a6156af
Fix linting issues in add-examples-to-dts.ts script
Copilot Jan 9, 2026
41cf558
Address code review feedback: add tsx as devDependency and improve co…
Copilot Jan 9, 2026
8d74970
Use node --import tsx instead of tsx directly, add as postbuild:types…
Copilot Jan 9, 2026
04a039d
Remove accidentally committed build artifacts (.d.ts files)
Copilot Jan 9, 2026
6bc42f0
Remove tsx, use Node's native TypeScript execution, commit distributi…
Copilot Jan 11, 2026
730d749
Extend existing JSDoc blocks and add validations to add-examples-to-d…
Copilot Jan 12, 2026
4e23b8a
Merge branch 'main' into copilot/include-example-urls-jsdocs
fregante Jan 12, 2026
0513c34
Remove --experimental-strip-types flag and hashbang
Copilot Jan 12, 2026
34ebeb4
Add actions/setup-node with node-version-file to all workflow jobs
Copilot Jan 12, 2026
99b8c15
Discard changes to .github/workflows/esm-lint.yml
fregante Jan 12, 2026
6d38ee7
Discard changes to .github/workflows/demo.yml
fregante Jan 12, 2026
65e3e42
Discard changes to .github/workflows/ci.yml
fregante Jan 12, 2026
f6694e6
Merge branch 'main' into copilot/include-example-urls-jsdocs
fregante Jan 13, 2026
3e9eb42
Add distribution folder back to .gitignore and remove tracked files
Copilot Jan 13, 2026
8a4d8b5
Add actions/setup-node to esm-lint Pack job only
Copilot Jan 13, 2026
05a2e67
Fix build and lint errors for Node 24 compatibility
Copilot Jan 13, 2026
4d8dadc
Revert incorrect changes and properly fix ESLint issues
Copilot Jan 13, 2026
dbbf883
Fix what copilot couldn't
fregante Jan 14, 2026
3853999
Anytime now
fregante Jan 14, 2026
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Thumbs.db
*.log
logs
*.map
distribution
Comment thread
fregante marked this conversation as resolved.
dist
.cache
.parcel-cache
51 changes: 51 additions & 0 deletions add-examples-to-dts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env node --experimental-strip-types
import {readFileSync, writeFileSync} from 'node:fs';
// Import index.ts to populate the test data via side effect
// eslint-disable-next-line import/no-unassigned-import, n/file-extension-in-import
import './index.ts';
// eslint-disable-next-line n/file-extension-in-import
import {getTests} from './collector.ts';

// Read the generated .d.ts file
const dtsPath = './distribution/index.d.ts';
const dtsContent = readFileSync(dtsPath, 'utf8');

// Process each exported function
const lines = dtsContent.split('\n');
const outputLines: string[] = [];

for (const line of lines) {
// Check if this is a function declaration
const match = /^export declare const (\w+):/.exec(line);
if (match) {
const functionName = match[1];

// Get the tests/examples for this function
const examples = getTests(functionName);

// Only add examples if they exist and aren't the special 'combinedTestOnly' marker
// 'combinedTestOnly' is used to skip tests for combined functions (e.g., isPageA() || isPageB())
if (examples && examples.length > 0 && examples[0] !== 'combinedTestOnly') {
// Filter to only include actual URLs (not references to other functions)
// getTests() recursively expands function references, so we just need to filter the final list
const urlExamples = examples.filter((url: string) => url.startsWith('http'));

if (urlExamples.length > 0) {
// Add JSDoc comment with examples before the declaration
outputLines.push('/**');
for (const url of urlExamples) {
outputLines.push(` * @example ${url}`);
}

outputLines.push(' */');
}
}
}

outputLines.push(line);
}

// Write the modified content back
writeFileSync(dtsPath, outputLines.join('\n'), 'utf8');

console.log('✓ Added example URLs to index.d.ts');
Comment thread
fregante marked this conversation as resolved.
Outdated
5 changes: 5 additions & 0 deletions distribution/collector.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @file This needs to be in a separate file so it can bee tree-shaken before being published, while still being importable by tests */
export declare const testableUrls: Map<string, string[]>;
export declare function addTests(test: string, urls: string[]): void;
export declare function getTests(detectName: string): string[];
export declare function getAllUrls(): Set<string>;
629 changes: 629 additions & 0 deletions distribution/index.d.ts

Large diffs are not rendered by default.

354 changes: 354 additions & 0 deletions distribution/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions distribution/index.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"build": "run-p build:*",
"build:esbuild": "esbuild index.ts --bundle --external:github-reserved-names --outdir=distribution --format=esm --drop-labels=TEST",
"build:typescript": "tsc --declaration --emitDeclarationOnly",
"postbuild:typescript": "node --experimental-strip-types add-examples-to-dts.ts",
"build:demo": "vite build demo",
"try": "esbuild index.ts --bundle --global-name=x --format=iife | pbcopy && echo 'Copied to clipboard'",
"fix": "xo --fix",
Expand Down
Loading