Skip to content

Commit a4db5dd

Browse files
matmenclaude
andcommitted
Fix JSR publishing: no global type declarations
JSR refused 3.10.0 (after npm had published it): threads.ts declared ImportMeta.url globally, which JSR doesn't allow and deno publish --dry-run doesn't check. import.meta's type is now given where it's used; the build's JavaScript still has new URL('./worker.js', import.meta.url) written out for bundlers. release-check.js fails on global type declarations, before anything is published. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BsU2GAqbnFSNaYDBGD1Km2
1 parent dc518c4 commit a4db5dd

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## 3.11.0
44

5+
### Fixes
6+
7+
- 3.10.0 is on npm but not on JSR, which refused it for declaring `import.meta.url`'s type globally; this version
8+
is published to both again.
9+
510
### Changes
611

712
- JPEG XLs with an embedded ICC profile whose pixels are in its color space (lossless ones and recompressed JPEGs, not

‎scripts/release-check.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ async function main() {
5656
if (!changelog.split('\n').some(line => /^##\s/.test(line) && line.replace(/^##\s+v?/, '').trim().split(/\s/)[0] === version))
5757
fail(`CHANGELOG.md has no "## ${version}" section`);
5858

59+
// what JSR refuses when publishing, after npm has published (deno publish --dry-run doesn't check it): declaring
60+
// global types
61+
const sources = fs.readdirSync(path.join(root, 'src'), { recursive: true }).filter(f => f.endsWith('.ts'));
62+
for (const file of sources)
63+
if (/^\s*declare\s+global\b/m.test(fs.readFileSync(path.join(root, 'src', file), 'utf8'))) fail(`src/${file} declares global types, which JSR doesn't allow`);
64+
5965
// what npm has already
6066
const res = await fetch(`https://registry.npmjs.org/${name}`, { headers: { accept: 'application/vnd.npm.install-v1+json' } });
6167
if (!res.ok && res.status !== 404) throw new Error(`npm registry answered ${res.status}`);

‎src/util/threads.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
// worker threads: Web Workers (Deno, Bun, browsers) or node:worker_threads (Node), sharing memory through
22
// SharedArrayBuffers. Accessed through feature detection with minimal local types, like node:zlib (see zlib.ts)
33

4-
// (URL and import.meta.url aren't in the es2022 lib)
4+
// (URL and import.meta.url aren't in the es2022 lib: URL declared here, import.meta's type where it's used, as JSR
5+
// doesn't allow declaring it globally; the build's JavaScript has import.meta.url written out, for bundlers)
56
declare const URL: new (url: string, base: string) => URL;
67
interface URL {
78
readonly href: string;
89
}
9-
declare global {
10-
interface ImportMeta {
11-
readonly url: string;
12-
}
13-
}
10+
type Meta = ImportMeta & { url: string };
1411

1512
interface NodeWorker {
1613
on(event: 'message' | 'error', listener: (value: unknown) => void): void;
@@ -104,7 +101,7 @@ export function startThreads(n: number): Thread[] | null {
104101
if (globals.Worker) {
105102
// (written like this, bundlers find the worker's module and bundle it too; the build points it at
106103
// worker.js)
107-
const w = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' });
104+
const w = new Worker(new URL('./worker.ts', (import.meta as Meta).url), { type: 'module' });
108105
threads.push(thread(m => w.postMessage(m), (message, error) => {
109106
w.onmessage = e => message(e.data as Reply);
110107
w.onerror = e => {
@@ -114,7 +111,8 @@ export function startThreads(n: number): Thread[] | null {
114111
}, () => w.terminate()));
115112
} else {
116113
const { Worker } = builtin('node:worker_threads') as { Worker: new (url: URL) => NodeWorker };
117-
const w = new Worker(new URL(import.meta.url.endsWith('.ts') ? './worker.ts' : './worker.js', import.meta.url));
114+
const url = (import.meta as Meta).url;
115+
const w = new Worker(new URL(url.endsWith('.ts') ? './worker.ts' : './worker.js', url));
118116
// (an idle worker doesn't keep the process alive)
119117
w.unref();
120118
threads.push(thread(m => w.postMessage(m), (message, error) => {

0 commit comments

Comments
 (0)