From b690a6f66a2345a5234d7605c60d12e27091fc45 Mon Sep 17 00:00:00 2001 From: Arpit Sarang Date: Tue, 17 Feb 2026 16:32:01 +0530 Subject: [PATCH] fix: global types support for jsr.io --- package-lock.json | 12 ---------- src/globals-jsr.ts | 49 +++++++++++++++++++++++++++++++++++++++ src/globals.ts | 2 +- test/export.test.js | 6 +++-- test/it/build-jsr.test.js | 2 +- tsconfig.json | 4 +++- 6 files changed, 58 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3d7e497414..3957aad672 100644 --- a/package-lock.json +++ b/package-lock.json @@ -221,7 +221,6 @@ "integrity": "sha512-ZsOJqu4HOG5BlvIFnMU0YKjQ9ZI6r3C31dg2jk5kMWPSdhJpYL9xa5hEe7aieE+707dXeMI4ej3diy6mXdZpgA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@algolia/client-common": "5.46.2", "@algolia/requester-browser-xhr": "5.46.2", @@ -2115,7 +2114,6 @@ "integrity": "sha512-t7frlewr6+cbx+9Ohpl0NOTKXZNV9xHRmNOvql47BFJKcEG1CxtxlPEEe+gR9uhVWM4DwhnvTF110mIL4yP9RA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "undici-types": "~7.16.0" } @@ -2622,7 +2620,6 @@ "integrity": "sha512-qqAXW9QvKf2tTyhpDA4qXv1IfBwD2eduSW6tUEBFIfCeE9gn9HQ9I5+MaKoenRuHrzk5sQoNh1/iof8mY7uD6Q==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@algolia/abtesting": "1.12.2", "@algolia/client-abtesting": "5.46.2", @@ -3263,7 +3260,6 @@ "integrity": "sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "env-paths": "^2.2.1", "import-fresh": "^3.3.0", @@ -3807,7 +3803,6 @@ "dev": true, "hasInstallScript": true, "license": "MIT", - "peer": true, "bin": { "esbuild": "bin/esbuild" }, @@ -4256,7 +4251,6 @@ "integrity": "sha512-Pkp8m55GjxBLnhBoT6OXdMvfRr4TjMAKLvFM566zlIryq5plbhaTmLAJWTGR0EkRwLjEte1lCOG9MxF1ipJrOg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "tabbable": "^6.4.0" } @@ -6131,7 +6125,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -6870,7 +6863,6 @@ "integrity": "sha512-JBG8dioIs0m2kHOhs9jD6E/tZKD08vmbf2bfqj/rJyNWqJxk/ZcakixjhYtsqdbi+AKVbfPkt3g2RRZiKaizYA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "bytes-iec": "^3.1.1", "lilconfig": "^3.1.3", @@ -7393,7 +7385,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -7737,7 +7728,6 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -7923,7 +7913,6 @@ "integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.21.3", "postcss": "^8.4.43", @@ -8026,7 +8015,6 @@ "integrity": "sha512-SJ/NTccVyAoNUJmkM9KUqPcYlY+u8OVL1X5EW9RIs3ch5H2uERxyyIUI4MRxVCSOiEcupX9xNGde1tL9ZKpimA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@vue/compiler-dom": "3.5.26", "@vue/compiler-sfc": "3.5.26", diff --git a/src/globals-jsr.ts b/src/globals-jsr.ts index 08953088b3..5c4fbbda70 100644 --- a/src/globals-jsr.ts +++ b/src/globals-jsr.ts @@ -14,3 +14,52 @@ import * as _ from './index.ts' Object.assign(globalThis, _) + +declare global { + type ProcessPromise = _.ProcessPromise + type ProcessOutput = _.ProcessOutput + var ProcessPromise: typeof _.ProcessPromise + var ProcessOutput: typeof _.ProcessOutput + var $: typeof _.$ + var argv: typeof _.argv + var cd: typeof _.cd + var chalk: typeof _.chalk + var defaults: typeof _.defaults + var dotenv: typeof _.dotenv + var echo: typeof _.echo + var expBackoff: typeof _.expBackoff + var fs: typeof _.fs + var glob: typeof _.glob + var globby: typeof _.globby + var kill: typeof _.kill + var log: typeof _.log + var minimist: typeof _.minimist + var nothrow: typeof _.nothrow + var os: typeof _.os + var parseArgv: typeof _.parseArgv + var path: typeof _.path + var ps: typeof _.ps + var question: typeof _.question + var quiet: typeof _.quiet + var quote: typeof _.quote + var quotePowerShell: typeof _.quotePowerShell + var resolveDefaults: typeof _.resolveDefaults + var retry: typeof _.retry + var sleep: typeof _.sleep + var spinner: typeof _.spinner + var stdin: typeof _.stdin + var syncProcessCwd: typeof _.syncProcessCwd + var tempdir: typeof _.tempdir + var tempfile: typeof _.tempfile + var tmpdir: typeof _.tempdir + var tmpfile: typeof _.tempfile + var updateArgv: typeof _.updateArgv + var usePowerShell: typeof _.usePowerShell + var usePwsh: typeof _.usePwsh + var useBash: typeof _.useBash + var version: typeof _.version + var VERSION: typeof _.VERSION + var which: typeof _.which + var within: typeof _.within + var YAML: typeof _.YAML +} diff --git a/src/globals.ts b/src/globals.ts index 9afed3b212..3e596acd33 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -15,7 +15,7 @@ import * as _ from './index.ts' Object.assign(globalThis, _) -// TODO: global types not working with jsr.io + declare global { type ProcessPromise = _.ProcessPromise type ProcessOutput = _.ProcessOutput diff --git a/test/export.test.js b/test/export.test.js index 662fd96ac5..10d26d6e32 100644 --- a/test/export.test.js +++ b/test/export.test.js @@ -241,12 +241,15 @@ describe('index', () => { assert.equal(typeof index.fs, 'object', 'index.fs') assert.equal(typeof index.fs.Dir, 'function', 'index.fs.Dir') assert.equal(typeof index.fs.Dirent, 'function', 'index.fs.Dirent') + assert.equal(typeof index.fs.F_OK, 'number', 'index.fs.F_OK') assert.equal(typeof index.fs.FileReadStream, 'function', 'index.fs.FileReadStream') assert.equal(typeof index.fs.FileWriteStream, 'function', 'index.fs.FileWriteStream') + assert.equal(typeof index.fs.R_OK, 'number', 'index.fs.R_OK') assert.equal(typeof index.fs.ReadStream, 'function', 'index.fs.ReadStream') assert.equal(typeof index.fs.Stats, 'function', 'index.fs.Stats') - assert.equal(typeof index.fs.Utf8Stream, 'function', 'index.fs.Utf8Stream') + assert.equal(typeof index.fs.W_OK, 'number', 'index.fs.W_OK') assert.equal(typeof index.fs.WriteStream, 'function', 'index.fs.WriteStream') + assert.equal(typeof index.fs.X_OK, 'number', 'index.fs.X_OK') assert.equal(typeof index.fs._toUnixTimestamp, 'function', 'index.fs._toUnixTimestamp') assert.equal(typeof index.fs.access, 'function', 'index.fs.access') assert.equal(typeof index.fs.accessSync, 'function', 'index.fs.accessSync') @@ -322,7 +325,6 @@ describe('index', () => { assert.equal(typeof index.fs.mkdirs, 'function', 'index.fs.mkdirs') assert.equal(typeof index.fs.mkdirsSync, 'function', 'index.fs.mkdirsSync') assert.equal(typeof index.fs.mkdtemp, 'function', 'index.fs.mkdtemp') - assert.equal(typeof index.fs.mkdtempDisposableSync, 'function', 'index.fs.mkdtempDisposableSync') assert.equal(typeof index.fs.mkdtempSync, 'function', 'index.fs.mkdtempSync') assert.equal(typeof index.fs.move, 'function', 'index.fs.move') assert.equal(typeof index.fs.moveSync, 'function', 'index.fs.moveSync') diff --git a/test/it/build-jsr.test.js b/test/it/build-jsr.test.js index 52bd1d6de9..98a426074a 100644 --- a/test/it/build-jsr.test.js +++ b/test/it/build-jsr.test.js @@ -48,6 +48,6 @@ describe('jsr artifact', () => { it('publish --dry-run`', async () => { await t$`node scripts/build-jsr.mjs` - await t$({ quiet: false })`jsr publish --dry-run` + await t$({ quiet: false })`jsr publish --dry-run --allow-slow-types` }) }) diff --git a/tsconfig.json b/tsconfig.json index d50e0eaad2..e31d7e90ea 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,5 +14,7 @@ "types": ["node", "fs-extra"] }, "include": ["./src/**/*"], - "exclude": ["./src/globals.ts"] + "exclude": ["./src/globals.ts", "./src/globals-jsr.ts"] } +// globals-jsr.ts is excluded to prevent "Duplicate identifier" errors with globals.ts during the main build. +// It is used specifically for the JSR distribution.