Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ESM instead of CJS #435

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default tseslint.config(
},
{
// Once we remove the legacy vows tests in ./test, we can remove these JS-specific rules
files: ['test/**/*.js', 'eslint.config.mjs'],
files: ['test/**/*.cjs', 'eslint.config.mjs'],
...tseslint.configs.disableTypeChecked,
rules: {
...tseslint.configs.disableTypeChecked.rules,
Expand Down
9 changes: 6 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { JestConfigWithTsJest } from "ts-jest";
import type { JestConfigWithTsJest } from 'ts-jest'

const config: JestConfigWithTsJest = {
preset: 'ts-jest',
testEnvironment: 'node',
rootDir: './lib/',
testPathIgnorePatterns: ['./lib/__tests__/data/'],
fakeTimers: {
enableGlobally: true
}
enableGlobally: true,
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
}

export default config
2 changes: 1 addition & 1 deletion lib/__tests__/canonicalDomain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { canonicalDomain } from '../cookie/canonicalDomain'
import { canonicalDomain } from '../cookie/canonicalDomain.js'

// port of tests/domain_and_path_test.js (canonicalDomain tests for domain normalization)
describe('canonicalDomain', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/cookie.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

import { Cookie } from '../cookie/cookie'
import { Cookie } from '../cookie/cookie.js'

// ported from test/api_test.js (cookie tests)
describe('Cookie', () => {
Expand Down
10 changes: 5 additions & 5 deletions lib/__tests__/cookieJar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

import { Cookie } from '../cookie/cookie'
import { CookieJar } from '../cookie/cookieJar'
import type { SerializedCookieJar } from '../cookie/constants'
import { MemoryCookieStore } from '../memstore'
import { Store } from '../store'
import { Cookie } from '../cookie/cookie.js'
import { CookieJar } from '../cookie/cookieJar.js'
import type { SerializedCookieJar } from '../cookie/constants.js'
import { MemoryCookieStore } from '../memstore.js'
import { Store } from '../store.js'

// ported from:
// - test/api_test.js (cookie jar tests)
Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/cookiePrefixes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrefixSecurityEnum } from '../cookie/constants'
import { CookieJar } from '../cookie/cookieJar'
import { PrefixSecurityEnum } from '../cookie/constants.js'
import { CookieJar } from '../cookie/cookieJar.js'

let cookieJar: CookieJar
const insecureUrl = 'http://www.example.com'
Expand Down
6 changes: 3 additions & 3 deletions lib/__tests__/cookieSorting.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Cookie } from '../cookie/cookie'
import { cookieCompare } from '../cookie/cookieCompare'
import { CookieJar } from '../cookie/cookieJar'
import { Cookie } from '../cookie/cookie.js'
import { cookieCompare } from '../cookie/cookieCompare.js'
import { CookieJar } from '../cookie/cookieJar.js'

describe('Cookie sorting', () => {
describe('assumptions', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/cookieToAndFromJson.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cookie } from '../cookie/cookie'
import { Cookie } from '../cookie/cookie.js'

describe('Cookie.toJSON()', () => {
it('should serialize a cookie to JSON', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/cookieToString.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cookie } from '../cookie/cookie'
import { Cookie } from '../cookie/cookie.js'

describe('Cookie.toString()', () => {
const parse = (cookieString: string): Cookie => {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/cookieUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inspect } from 'node:util'
import { Cookie } from '../cookie/cookie'
import { Cookie } from '../cookie/cookie.js'

describe('Cookie utils', () => {
describe('custom inspect', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type EquivalenceDateParsingTestCase = {
[key: string]: string
}

import { parseDate } from '../cookie/parseDate'
import { parseDate } from '../cookie/parseDate.js'

const dateTests: DateParsingTestCase = {
'Wed, 09 Jun 2021 10:18:14 GMT': true,
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/defaultPath.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultPath } from '../cookie/defaultPath'
import { defaultPath } from '../cookie/defaultPath.js'

// port of tests/domain_and_path_test.js (default path tests)
describe('defaultPath', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/domainMatch.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { domainMatch } from '../cookie/domainMatch'
import { domainMatch } from '../cookie/domainMatch.js'

// port of tests/domain_and_path_test.js (domain match tests)
describe('domainMatch', () => {
Expand Down
10 changes: 5 additions & 5 deletions lib/__tests__/ietf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
*/

import url from 'url'
import parserData from './data/parser'
import bsdExampleDates from './data/dates/bsd-examples'
import exampleDates from './data/dates/examples'
import { CookieJar } from '../cookie/cookieJar'
import { parseDate } from '../cookie/parseDate'
import parserData from './data/parser.js'
import bsdExampleDates from './data/dates/bsd-examples.js'
import exampleDates from './data/dates/examples.js'
import { CookieJar } from '../cookie/cookieJar.js'
import { parseDate } from '../cookie/parseDate.js'

describe('IETF http state tests', () => {
describe('Set/get cookie tests', () => {
Expand Down
15 changes: 9 additions & 6 deletions lib/__tests__/jarSerialization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import { Cookie } from '../cookie/cookie'
import { CookieJar } from '../cookie/cookieJar'
import type { SerializedCookie, SerializedCookieJar } from '../cookie/constants'
import { MemoryCookieStore } from '../memstore'
import { Store } from '../store'
import { version } from '../version'
import { Cookie } from '../cookie/cookie.js'
import { CookieJar } from '../cookie/cookieJar.js'
import type {
SerializedCookie,
SerializedCookieJar,
} from '../cookie/constants.js'
import { MemoryCookieStore } from '../memstore.js'
import { Store } from '../store.js'
import { version } from '../version.js'

describe('cookieJar serialization', () => {
it('should use the expected version', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/lifetime.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cookie } from '../cookie/cookie'
import { Cookie } from '../cookie/cookie.js'

describe('Lifetime', () => {
it('should be able to set a TTL using max-age', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/memoryCookieStore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Cookie } from '../cookie/cookie'
import { MemoryCookieStore } from '../memstore'
import { Cookie } from '../cookie/cookie.js'
import { MemoryCookieStore } from '../memstore.js'

describe('MemoryCookieStore', () => {
it('should have no static methods', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cookie } from '../cookie/cookie'
import { Cookie } from '../cookie/cookie.js'
import { performance } from 'node:perf_hooks'

describe('Cookie.parse', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/pathMatch.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathMatch } from '../pathMatch'
import { pathMatch } from '../pathMatch.js'

// port of tests/domain_and_path_test.js (path match tests)
describe('pathMatch', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/permuteDomain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { permuteDomain } from '../permuteDomain'
import { permuteDomain } from '../permuteDomain.js'

// port of tests/domain_and_path_test.js (permute domain tests)
describe('permuteDomain', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/permutePath.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { permutePath } from '../cookie/permutePath'
import { pathMatch } from '../pathMatch'
import { permutePath } from '../cookie/permutePath.js'
import { pathMatch } from '../pathMatch.js'

// port of tests/domain_and_path_test.js (permute path tests)
describe('permutePath', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/regression.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Cookie } from '../cookie/cookie'
import { CookieJar } from '../cookie/cookieJar'
import type { Cookie } from '../cookie/cookie.js'
import { CookieJar } from '../cookie/cookieJar.js'

const url = 'http://www.example.com'

Expand Down
10 changes: 5 additions & 5 deletions lib/__tests__/removeAll.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Cookie } from '../cookie/cookie'
import { CookieJar } from '../cookie/cookieJar'
import { MemoryCookieStore } from '../memstore'
import { Store } from '../store'
import type { Callback, ErrorCallback } from '../utils'
import type { Cookie } from '../cookie/cookie.js'
import { CookieJar } from '../cookie/cookieJar.js'
import { MemoryCookieStore } from '../memstore.js'
import { Store } from '../store.js'
import type { Callback, ErrorCallback } from '../utils.js'

const url = 'http://example.com/index.html'

Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/sameSite.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Cookie } from '../cookie/cookie'
import { CookieJar } from '../cookie/cookieJar'
import { Cookie } from '../cookie/cookie.js'
import { CookieJar } from '../cookie/cookieJar.js'

const url = 'http://example.com/index.html'

Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { safeToString } from '../utils'
import { safeToString } from '../utils.js'

describe('safeToString', () => {
const recursiveArray: unknown[] = [1]
Expand Down
4 changes: 2 additions & 2 deletions lib/cookie/canonicalDomain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IP_V6_REGEX_OBJECT } from './constants'
import type { Nullable } from '../utils'
import { IP_V6_REGEX_OBJECT } from './constants.js'
import type { Nullable } from '../utils.js'
import { domainToASCII } from 'node:url'

/**
Expand Down
16 changes: 8 additions & 8 deletions lib/cookie/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import { getPublicSuffix } from '../getPublicSuffix'
import * as validators from '../validators'
import { inOperator } from '../utils'

import { formatDate } from './formatDate'
import { parseDate } from './parseDate'
import { canonicalDomain } from './canonicalDomain'
import type { SerializedCookie } from './constants'
import { getPublicSuffix } from '../getPublicSuffix.js'
import * as validators from '../validators.js'
import { inOperator } from '../utils.js'

import { formatDate } from './formatDate.js'
import { parseDate } from './parseDate.js'
import { canonicalDomain } from './canonicalDomain.js'
import type { SerializedCookie } from './constants.js'

// From RFC6265 S4.1.1
// note that it excludes \x3B ";"
Expand Down
2 changes: 1 addition & 1 deletion lib/cookie/cookieCompare.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Cookie } from './cookie'
import type { Cookie } from './cookie.js'

/**
* The maximum timestamp a cookie, in milliseconds. The value is (2^31 - 1) seconds since the Unix
Expand Down
28 changes: 14 additions & 14 deletions lib/cookie/cookieJar.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { getPublicSuffix } from '../getPublicSuffix'
import * as validators from '../validators'
import { ParameterError } from '../validators'
import { Store } from '../store'
import { MemoryCookieStore } from '../memstore'
import { pathMatch } from '../pathMatch'
import { Cookie } from './cookie'
import { getPublicSuffix } from '../getPublicSuffix.js'
import * as validators from '../validators.js'
import { ParameterError } from '../validators.js'
import { Store } from '../store.js'
import { MemoryCookieStore } from '../memstore.js'
import { pathMatch } from '../pathMatch.js'
import { Cookie } from './cookie.js'
import {
Callback,
createPromiseCallback,
ErrorCallback,
inOperator,
Nullable,
safeToString,
} from '../utils'
import { canonicalDomain } from './canonicalDomain'
} from '../utils.js'
import { canonicalDomain } from './canonicalDomain.js'
import {
IP_V6_REGEX_OBJECT,
PrefixSecurityEnum,
SerializedCookieJar,
} from './constants'
import { defaultPath } from './defaultPath'
import { domainMatch } from './domainMatch'
import { cookieCompare } from './cookieCompare'
import { version } from '../version'
} from './constants.js'
import { defaultPath } from './defaultPath.js'
import { domainMatch } from './domainMatch.js'
import { cookieCompare } from './cookieCompare.js'
import { version } from '../version.js'

const defaultSetCookieOptions: SetCookieOptions = {
loose: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/cookie/defaultPath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Nullable } from '../utils'
import type { Nullable } from '../utils.js'

/**
* Given a current request/response path, gives the path appropriate for storing
Expand Down
4 changes: 2 additions & 2 deletions lib/cookie/domainMatch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Nullable } from '../utils'
import { canonicalDomain } from './canonicalDomain'
import type { Nullable } from '../utils.js'
import { canonicalDomain } from './canonicalDomain.js'

// Dumped from ip-regex@4.0.0, with the following changes:
// * all capturing groups converted to non-capturing -- "(?:)"
Expand Down
38 changes: 19 additions & 19 deletions lib/cookie/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
export { MemoryCookieStore, MemoryCookieStoreIndex } from '../memstore'
export { pathMatch } from '../pathMatch'
export { permuteDomain } from '../permuteDomain'
export { getPublicSuffix, GetPublicSuffixOptions } from '../getPublicSuffix'
export { Store } from '../store'
export { ParameterError } from '../validators'
export { version } from '../version'
export { Callback, ErrorCallback, Nullable } from '../utils'
export { canonicalDomain } from './canonicalDomain'
export { MemoryCookieStore, MemoryCookieStoreIndex } from '../memstore.js'
export { pathMatch } from '../pathMatch.js'
export { permuteDomain } from '../permuteDomain.js'
export { getPublicSuffix, GetPublicSuffixOptions } from '../getPublicSuffix.js'
export { Store } from '../store.js'
export { ParameterError } from '../validators.js'
export { version } from '../version.js'
export { Callback, ErrorCallback, Nullable } from '../utils.js'
export { canonicalDomain } from './canonicalDomain.js'
export {
PrefixSecurityEnum,
SerializedCookie,
SerializedCookieJar,
} from './constants'
export { Cookie, CreateCookieOptions, ParseCookieOptions } from './cookie'
export { cookieCompare } from './cookieCompare'
} from './constants.js'
export { Cookie, CreateCookieOptions, ParseCookieOptions } from './cookie.js'
export { cookieCompare } from './cookieCompare.js'
export {
CookieJar,
CreateCookieJarOptions,
GetCookiesOptions,
SetCookieOptions,
} from './cookieJar'
export { defaultPath } from './defaultPath'
export { domainMatch } from './domainMatch'
export { formatDate } from './formatDate'
export { parseDate } from './parseDate'
export { permutePath } from './permutePath'
} from './cookieJar.js'
export { defaultPath } from './defaultPath.js'
export { domainMatch } from './domainMatch.js'
export { formatDate } from './formatDate.js'
export { parseDate } from './parseDate.js'
export { permutePath } from './permutePath.js'

import { Cookie, ParseCookieOptions } from './cookie'
import { Cookie, ParseCookieOptions } from './cookie.js'

/**
* {@inheritDoc Cookie.parse}
Expand Down
2 changes: 1 addition & 1 deletion lib/cookie/parseDate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// date-time parsing constants (RFC6265 S5.1.1)

import type { Nullable } from '../utils'
import type { Nullable } from '../utils.js'

// eslint-disable-next-line no-control-regex
const DATE_DELIM = /[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]/
Expand Down
Loading
Loading