Skip to content

Commit

Permalink
chore: fixes to types and jsr publish (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic authored Dec 8, 2024
1 parent 49d677e commit 3c53faa
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-cherries-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cdn-cache-control": patch
---

Fixes to types
16 changes: 11 additions & 5 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ const cdnCacheControlHeaderNames = new Map<CDN, string>([
["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) {
Expand Down
3 changes: 2 additions & 1 deletion fastly.test.js → test/fastly.test.js
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion index.test.js → test/index.test.js
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion netlify.test.js → test/netlify.test.js
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down

0 comments on commit 3c53faa

Please sign in to comment.