From f79144fd45ecc29918a6eb2d7971d80ebf460c66 Mon Sep 17 00:00:00 2001 From: Will Harney Date: Thu, 9 Jan 2025 10:23:57 -0500 Subject: [PATCH 1/3] refactor: almost isolated declarations --- lib/__tests__/data/dates/bsd-examples.ts | 2 +- lib/__tests__/data/dates/examples.ts | 2 +- lib/__tests__/data/parser.ts | 2 +- lib/__tests__/ietf.spec.ts | 7 ++++--- lib/cookie/constants.ts | 7 ++++--- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/__tests__/data/dates/bsd-examples.ts b/lib/__tests__/data/dates/bsd-examples.ts index a7daf2fb..aed59711 100644 --- a/lib/__tests__/data/dates/bsd-examples.ts +++ b/lib/__tests__/data/dates/bsd-examples.ts @@ -219,4 +219,4 @@ export default [ test: 'IAintNoDateFool', expected: null, }, -] +] as const diff --git a/lib/__tests__/data/dates/examples.ts b/lib/__tests__/data/dates/examples.ts index 2ce3b762..8c920f65 100644 --- a/lib/__tests__/data/dates/examples.ts +++ b/lib/__tests__/data/dates/examples.ts @@ -59,4 +59,4 @@ export default [ test: 'Thu, 10 Dec 2009 13:57:2 GMT', expected: 'Thu, 10 Dec 2009 13:57:02 GMT', }, -] +] as const diff --git a/lib/__tests__/data/parser.ts b/lib/__tests__/data/parser.ts index 7618a7bf..67ea69e9 100644 --- a/lib/__tests__/data/parser.ts +++ b/lib/__tests__/data/parser.ts @@ -1330,4 +1330,4 @@ export default [ received: ['\tfoo\t=\tbar\t \t;\tttt'], sent: [{ name: 'foo', value: 'bar' }], }, -] +] as const diff --git a/lib/__tests__/ietf.spec.ts b/lib/__tests__/ietf.spec.ts index 7d523663..791faf7d 100644 --- a/lib/__tests__/ietf.spec.ts +++ b/lib/__tests__/ietf.spec.ts @@ -42,9 +42,10 @@ describe('IETF http state tests', () => { const jar = new CookieJar() const expected = testCase.sent const sentFrom = `http://home.example.org/cookie-parser?${testCase.test}` - const sentTo = testCase['sent-to'] - ? url.resolve('http://home.example.org', testCase['sent-to']) - : `http://home.example.org/cookie-parser-result?${testCase.test}` + const sentTo = + 'sent-to' in testCase + ? url.resolve('http://home.example.org', testCase['sent-to']) + : `http://home.example.org/cookie-parser-result?${testCase.test}` testCase['received'].forEach((cookieStr) => { jar.setCookieSync(cookieStr, sentFrom, { ignoreError: true }) diff --git a/lib/cookie/constants.ts b/lib/cookie/constants.ts index ed08ac80..c2753c0b 100644 --- a/lib/cookie/constants.ts +++ b/lib/cookie/constants.ts @@ -11,11 +11,12 @@ * - `unsafe-disabled` - Disables cookie prefix checking. * @public */ -export const PrefixSecurityEnum = Object.freeze({ +export const PrefixSecurityEnum = { SILENT: 'silent', STRICT: 'strict', DISABLED: 'unsafe-disabled', -}) +} as const +Object.freeze(PrefixSecurityEnum) const IP_V6_REGEX = ` \\[?(?: @@ -32,7 +33,7 @@ const IP_V6_REGEX = ` .replace(/\s*\/\/.*$/gm, '') .replace(/\n/g, '') .trim() -export const IP_V6_REGEX_OBJECT = new RegExp(`^${IP_V6_REGEX}$`) +export const IP_V6_REGEX_OBJECT: RegExp = new RegExp(`^${IP_V6_REGEX}$`) /** * A JSON representation of a {@link CookieJar}. From 8e39ae145dc9b054a1cfbad7172a469c2f317d63 Mon Sep 17 00:00:00 2001 From: Will Harney Date: Thu, 9 Jan 2025 10:28:11 -0500 Subject: [PATCH 2/3] chore: use isolated modules --- lib/cookie/index.ts | 25 ++++++++++++++++--------- tsconfig.json | 3 ++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/cookie/index.ts b/lib/cookie/index.ts index d6245054..a06d3c4a 100644 --- a/lib/cookie/index.ts +++ b/lib/cookie/index.ts @@ -1,24 +1,31 @@ -export { MemoryCookieStore, MemoryCookieStoreIndex } from '../memstore' +export { MemoryCookieStore, type MemoryCookieStoreIndex } from '../memstore' export { pathMatch } from '../pathMatch' export { permuteDomain } from '../permuteDomain' -export { getPublicSuffix, GetPublicSuffixOptions } from '../getPublicSuffix' +export { + getPublicSuffix, + type GetPublicSuffixOptions, +} from '../getPublicSuffix' export { Store } from '../store' export { ParameterError } from '../validators' export { version } from '../version' -export { Callback, ErrorCallback, Nullable } from '../utils' +export { type Callback, type ErrorCallback, type Nullable } from '../utils' export { canonicalDomain } from './canonicalDomain' export { PrefixSecurityEnum, - SerializedCookie, - SerializedCookieJar, + type SerializedCookie, + type SerializedCookieJar, } from './constants' -export { Cookie, CreateCookieOptions, ParseCookieOptions } from './cookie' +export { + Cookie, + type CreateCookieOptions, + type ParseCookieOptions, +} from './cookie' export { cookieCompare } from './cookieCompare' export { CookieJar, - CreateCookieJarOptions, - GetCookiesOptions, - SetCookieOptions, + type CreateCookieJarOptions, + type GetCookiesOptions, + type SetCookieOptions, } from './cookieJar' export { defaultPath } from './defaultPath' export { domainMatch } from './domainMatch' diff --git a/tsconfig.json b/tsconfig.json index b090ae11..af6a13f0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,7 +26,8 @@ "allowUnusedLabels": false, "allowUnreachableCode": false, /* Compatibility */ - "ignoreDeprecations": "5.0" + "ignoreDeprecations": "5.0", + "isolatedModules": true }, "include": ["lib"], "exclude": ["jest.config.ts"] From 0b9d798acb8890ae3a96170ca2d205a2345bec29 Mon Sep 17 00:00:00 2001 From: Will Harney Date: Thu, 9 Jan 2025 10:45:12 -0500 Subject: [PATCH 3/3] update docs --- api/docs/tough-cookie.prefixsecurityenum.md | 10 +++++----- api/tough-cookie.api.md | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/docs/tough-cookie.prefixsecurityenum.md b/api/docs/tough-cookie.prefixsecurityenum.md index 399e9071..9e93c181 100644 --- a/api/docs/tough-cookie.prefixsecurityenum.md +++ b/api/docs/tough-cookie.prefixsecurityenum.md @@ -17,9 +17,9 @@ The following values can be used to configure how a [CookieJar](./tough-cookie.c **Signature:** ```typescript -PrefixSecurityEnum: Readonly<{ - SILENT: "silent"; - STRICT: "strict"; - DISABLED: "unsafe-disabled"; -}> +PrefixSecurityEnum: { + readonly SILENT: "silent"; + readonly STRICT: "strict"; + readonly DISABLED: "unsafe-disabled"; +} ``` diff --git a/api/tough-cookie.api.md b/api/tough-cookie.api.md index bc7b969c..8237d4f3 100644 --- a/api/tough-cookie.api.md +++ b/api/tough-cookie.api.md @@ -245,11 +245,11 @@ export function permuteDomain(domain: string, allowSpecialUseDomain?: boolean): export function permutePath(path: string): string[]; // @public -export const PrefixSecurityEnum: Readonly<{ - SILENT: "silent"; - STRICT: "strict"; - DISABLED: "unsafe-disabled"; -}>; +export const PrefixSecurityEnum: { + readonly SILENT: "silent"; + readonly STRICT: "strict"; + readonly DISABLED: "unsafe-disabled"; +}; // @public export type SerializedCookie = {