From 3c53faaac1e0d3625c42281fabbe86c1aa2b1305 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Sun, 8 Dec 2024 23:01:56 +0000 Subject: [PATCH] chore: fixes to types and jsr publish (#16) --- .changeset/new-cherries-help.md | 5 +++++ jsr.json | 16 +++++++++++----- package.json | 2 +- src/index.ts | 15 ++++++++++++--- fastly.test.js => test/fastly.test.js | 3 ++- index.test.js => test/index.test.js | 2 +- netlify.test.js => test/netlify.test.js | 2 +- 7 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 .changeset/new-cherries-help.md rename fastly.test.js => test/fastly.test.js (85%) rename index.test.js => test/index.test.js (98%) rename netlify.test.js => test/netlify.test.js (91%) diff --git a/.changeset/new-cherries-help.md b/.changeset/new-cherries-help.md new file mode 100644 index 0000000..1dfe94b --- /dev/null +++ b/.changeset/new-cherries-help.md @@ -0,0 +1,5 @@ +--- +"cdn-cache-control": patch +--- + +Fixes to types diff --git a/jsr.json b/jsr.json index 560b4bb..cf2ac1e 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,12 @@ { - "name": "@ascorbic/cdn-cache-control", - "version": "1.3.0", - "exports": "./src/index.ts", - "license": "MIT" -} + "name": "@ascorbic/cdn-cache-control", + "version": "1.3.0", + "exports": "./src/index.ts", + "license": "MIT", + "publish": { + "include": [ + "README.md", + "src/index.ts" + ] + } +} \ No newline at end of file diff --git a/package.json b/package.json index 6327131..9230c41 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "lint:package": "publint", "lint:prettier": "prettier --check src", "lint": "pnpm run '/^lint:.*/'", - "test": "pnpm build && node --test", + "test": "pnpm build && node --test test", "tsdoc": "tsdoc --src=src/index.ts && prettier --write README.md", "version": "changeset version && jq --arg version \"$(jq -r .version package.json)\" '.version = $version' jsr.json > jsr.json.tmp && mv jsr.json.tmp jsr.json" }, diff --git a/src/index.ts b/src/index.ts index f71b347..40fc649 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,11 +29,20 @@ const cdnCacheControlHeaderNames = new Map([ ["fastly", "Cache-Control"], ]); +type Global = typeof globalThis & { + process?: { + env?: { + CDN?: string; + VERCEL?: string; + }; + }; +}; + function detectCDN(): CDN | undefined { - if (globalThis?.process?.env?.CDN) { - return globalThis.process.env.CDN as CDN; + if ((globalThis as Global).process?.env?.CDN) { + return (globalThis as Global).process.env.CDN as CDN; } - if (globalThis?.process?.env.VERCEL) { + if ((globalThis as Global).process?.env.VERCEL) { return "vercel"; } if ("Netlify" in globalThis) { diff --git a/fastly.test.js b/test/fastly.test.js similarity index 85% rename from fastly.test.js rename to test/fastly.test.js index 3057a44..874737d 100644 --- a/fastly.test.js +++ b/test/fastly.test.js @@ -1,6 +1,7 @@ +// @ts-check import assert from "node:assert"; import { describe, it } from "node:test"; -import { CacheHeaders } from "./dist/index.js"; +import { CacheHeaders } from "../dist/index.js"; describe("Fastly", () => { it("merges cdn-cache-control header into cache-control", () => { diff --git a/index.test.js b/test/index.test.js similarity index 98% rename from index.test.js rename to test/index.test.js index baf5909..5875a44 100644 --- a/index.test.js +++ b/test/index.test.js @@ -1,7 +1,7 @@ // @ts-check import assert from "node:assert"; import { describe, it } from "node:test"; -import { CacheHeaders, ONE_DAY } from "./dist/index.js"; +import { CacheHeaders, ONE_DAY } from "../dist/index.js"; describe("CacheHeaders", () => { it("should append cache tags", () => { diff --git a/netlify.test.js b/test/netlify.test.js similarity index 91% rename from netlify.test.js rename to test/netlify.test.js index 78d4668..63c5d0d 100644 --- a/netlify.test.js +++ b/test/netlify.test.js @@ -1,6 +1,6 @@ import assert from "node:assert"; import { describe, it } from "node:test"; -import { CacheHeaders } from "./dist/index.js"; +import { CacheHeaders } from "../dist/index.js"; describe("Netlify", () => { it("sets tiered header on Netlify", () => {