diff --git a/deno.json b/deno.json index 6ef0f75..1aba251 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@denosaurs/typefetch", - "version": "0.0.26", + "version": "0.0.27", "exports": { ".": "./main.ts" }, diff --git a/main.ts b/main.ts index 1103d65..9236587 100644 --- a/main.ts +++ b/main.ts @@ -11,7 +11,7 @@ import manifest from "./deno.json" with { type: "json" }; export * from "./mod.ts"; -const args = parseArgs(Deno.args, { +const parseOptions = { string: [ "output", "config", @@ -28,13 +28,15 @@ const args = parseArgs(Deno.args, { alias: { "output": "o", "help": "h", "version": "V" }, default: { "output": "./typefetch.d.ts", - "import": "https://raw.githubusercontent.com/denosaurs/typefetch/main", + "import": "__npm" in globalThis + ? manifest.name + : "https://raw.githubusercontent.com/denosaurs/typefetch/main", "include-server-urls": true, "include-absolute-url": false, "include-relative-url": false, "experimental-urlsearchparams": false, }, - unknown: (arg, key) => { + unknown: (arg: string, key?: string) => { if (key === undefined) return; console.error( @@ -43,7 +45,9 @@ const args = parseArgs(Deno.args, { ); Deno.exit(1); }, -}); +} as const; + +const args = parseArgs(Deno.args, parseOptions); if (args.help) { // deno-fmt-ignore @@ -52,14 +56,14 @@ if (args.help) { `Options:\n` + ` -h, --help Print this help message\n` + ` -V, --version Print the version of TypeFetch\n` + - ` -o, --output Output file path (default: typefetch.d.ts)\n` + + ` -o, --output Output file path (default: ${parseOptions.default["output"]})\n` + ` --config File path to the tsconfig.json file\n` + - ` --import Import path for TypeFetch (default: https://raw.githubusercontent.com/denosaurs/typefetch/main)\n` + + ` --import Import path for TypeFetch (default: ${parseOptions.default["import"]})\n` + ` --base-urls A comma separated list of custom base urls for paths to start with\n` + - ` --include-server-urls Include server URLs from the schema in the generated paths (default: true)\n` + - ` --include-absolute-url Include absolute URLs in the generated paths (default: false)\n` + - ` --include-relative-url Include relative URLs in the generated paths (default: false)\n` + - ` --experimental-urlsearchparams Enable the experimental fully typed URLSearchParams type (default: false)\n`, + ` --include-server-urls Include server URLs from the schema in the generated paths (default: ${parseOptions.default["include-server-urls"]})\n` + + ` --include-absolute-url Include absolute URLs in the generated paths (default: ${parseOptions.default["include-absolute-url"]})\n` + + ` --include-relative-url Include relative URLs in the generated paths (default: ${parseOptions.default["include-relative-url"]})\n` + + ` --experimental-urlsearchparams Enable the experimental fully typed URLSearchParams type (default: ${parseOptions.default["experimental-urlsearchparams"]})\n`, ); Deno.exit(0); } diff --git a/node/shims.ts b/node/shims.ts index 310d48c..66fa4d7 100644 --- a/node/shims.ts +++ b/node/shims.ts @@ -28,3 +28,5 @@ export function addEventListener( process.on("SIGINT", listener); process.on("uncaughtException", listener); } + +export const __npm = true; diff --git a/scripts/npm.ts b/scripts/npm.ts index b575391..f030627 100644 --- a/scripts/npm.ts +++ b/scripts/npm.ts @@ -5,20 +5,35 @@ import { build, emptyDir } from "jsr:@deno/dnt"; await emptyDir("./npm"); await build({ - entryPoints: [{ - kind: "bin", - name: "typefetch", - path: "./main.ts", - }], + entryPoints: [ + { + kind: "bin", + name: "typefetch", + path: "./main.ts", + }, + "./types/headers.ts", + "./types/json.ts", + "./types/urlsearchparams.ts", + ], + filterDiagnostic: (diagnostic) => { + // Ignore excessively deep and possibly infinite type errors + if (diagnostic.code === 2589) { + return false; + } + + return true; + }, scriptModule: false, outDir: "./npm", shims: { deno: true, timers: true, - custom: [{ - globalNames: ["addEventListener"], - module: "./node/shims.ts", - }], + custom: [ + { + globalNames: ["addEventListener", "__npm"], + module: "./node/shims.ts", + }, + ], }, test: false, importMap: "./deno.json",