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

Updated dev tooling #271

Merged
merged 11 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dist
node_modules
test
colincasey marked this conversation as resolved.
Show resolved Hide resolved
76 changes: 60 additions & 16 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,65 @@
{
"extends": ["plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 6
},
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
colincasey marked this conversation as resolved.
Show resolved Hide resolved
],
colincasey marked this conversation as resolved.
Show resolved Hide resolved
"rules": {
"no-debugger": "error",
"no-var": "error",
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-template": "error",
"no-restricted-modules": ["error",
// we can't rely on node standard modules in "native" or "browser" environments
// - exceptions:
// "punycode": since it's a package.json dependency
"assert", "buffer", "child_process", "cluster", "crypto", "dgram", "dns", "domain", "events", "freelist", "fs",
"http", "https", "module", "net", "os", "path", "querystring", "readline", "repl", "smalloc", "stream",
"string_decoder", "sys", "timers", "tls", "tracing", "tty", "url", "util", "vm", "zlib"
// our parser is written with control characters
"no-control-regex": "off",
colincasey marked this conversation as resolved.
Show resolved Hide resolved

// this is only needed because `createPromiseCallback` uses arguments to support the callback-style api
// we should strongly consider dropping the callback and sync api variants (in say v6) to reduce the
// surface area and complexity of tough-cookie
"prefer-rest-params": "warn",
"@typescript-eslint/no-unused-vars": "warn",

// used by callSync which needs to use Function because it's used by several apis
"@typescript-eslint/ban-types": "warn",

// there are several areas that still have ts-ignore comments, let's try to eliminate those
"@typescript-eslint/ban-ts-comment": "warn",

// i'd like to clean up all usages of any but the current api is just too loose
"@typescript-eslint/no-explicit-any": "warn",

// we can't rely on node standard modules in "native" or "browser" environments
// - except "punycode" (since it's a package.json dependency)
"no-restricted-modules": [
colincasey marked this conversation as resolved.
Show resolved Hide resolved
"error",
"assert",
"buffer",
"child_process",
"cluster",
"crypto",
"dgram",
"dns",
"domain",
"events",
"freelist",
"fs",
"http",
"https",
"module",
"net",
"os",
"path",
"querystring",
"readline",
"repl",
"smalloc",
"stream",
"string_decoder",
"sys",
"timers",
"tls",
"tracing",
"tty",
"url",
"util",
"vm",
"zlib"
]
}
}
7 changes: 3 additions & 4 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: Actions-CI
name: Actions-CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand Down
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
lib/version.js
dist/*.js
dist
test
colincasey marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "all"
}
wjhsf marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

All notable changes to this project can be found at on the [Releases](https://github.com/salesforce/tough-cookie/releases)
page.

56 changes: 28 additions & 28 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ culture where everyone feels included.

Salesforce open-source projects are committed to providing a friendly, safe, and
welcoming environment for all, regardless of gender identity and expression,
sexual orientation, disability, physical appearance, body size, ethnicity, nationality,
race, age, religion, level of experience, education, socioeconomic status, or
sexual orientation, disability, physical appearance, body size, ethnicity, nationality,
race, age, religion, level of experience, education, socioeconomic status, or
other similar personal characteristics.

The goal of this code of conduct is to specify a baseline standard of behavior so
Expand All @@ -25,33 +25,33 @@ Open Source Conduct Committee at [email protected].

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of gender
identity and expression, sexual orientation, disability, physical appearance,
body size, ethnicity, nationality, race, age, religion, level of experience, education,
our community a harassment-free experience for everyone, regardless of gender
identity and expression, sexual orientation, disability, physical appearance,
body size, ethnicity, nationality, race, age, religion, level of experience, education,
socioeconomic status, or other similar personal characteristics.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy toward other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy toward other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Personal attacks, insulting/derogatory comments, or trolling
* Public or private harassment
* Publishing, or threatening to publish, others' private information—such as
a physical or electronic address—without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
* Advocating for or encouraging any of the above behaviors
- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Personal attacks, insulting/derogatory comments, or trolling
- Public or private harassment
- Publishing, or threatening to publish, others' private information—such as
a physical or electronic address—without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting
- Advocating for or encouraging any of the above behaviors

## Our Responsibilities

Expand All @@ -77,28 +77,28 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the Salesforce Open Source Conduct Committee
at [email protected]. All complaints will be reviewed and investigated
and will result in a response that is deemed necessary and appropriate to the
circumstances. The committee is obligated to maintain confidentiality with
regard to the reporter of an incident. Further details of specific enforcement
reported by contacting the Salesforce Open Source Conduct Committee
at [email protected]. All complaints will be reviewed and investigated
and will result in a response that is deemed necessary and appropriate to the
circumstances. The committee is obligated to maintain confidentiality with
regard to the reporter of an incident. Further details of specific enforcement
policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership and the Salesforce Open Source Conduct
members of the project's leadership and the Salesforce Open Source Conduct
Committee.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][contributor-covenant-home],
version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html.
It includes adaptions and additions from [Go Community Code of Conduct][golang-coc],
version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html.
It includes adaptions and additions from [Go Community Code of Conduct][golang-coc],
[CNCF Code of Conduct][cncf-coc], and [Microsoft Open Source Code of Conduct][microsoft-coc].

This Code of Conduct is licensed under the [Creative Commons Attribution 3.0 License][cc-by-3-us].

[contributor-covenant-home]: https://www.contributor-covenant.org (https://www.contributor-covenant.org/)
[contributor-covenant-home]: https://www.contributor-covenant.org 'https://www.contributor-covenant.org/'
[golang-coc]: https://golang.org/conduct
[cncf-coc]: https://github.com/cncf/foundation/blob/master/code-of-conduct.md
[microsoft-coc]: https://opensource.microsoft.com/codeofconduct/
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@
## Synopsis

```javascript
var tough = require("tough-cookie");
var Cookie = tough.Cookie;
var cookie = Cookie.parse(header);
cookie.value = "somethingdifferent";
header = cookie.toString();
var cookiejar = new tough.CookieJar();
var tough = require('tough-cookie')
var Cookie = tough.Cookie
var cookie = Cookie.parse(header)
cookie.value = 'somethingdifferent'
header = cookie.toString()
var cookiejar = new tough.CookieJar()

// Asynchronous!
var cookie = await cookiejar.setCookie(
cookie,
"https://currentdomain.example.com/path"
);
var cookies = await cookiejar.getCookies("https://example.com/otherpath");
'https://currentdomain.example.com/path',
)
var cookies = await cookiejar.getCookies('https://example.com/otherpath')

// Or with callbacks!
cookiejar.setCookie(
cookie,
"https://currentdomain.example.com/path",
'https://currentdomain.example.com/path',
function (err, cookie) {
/* ... */
}
);
cookiejar.getCookies("http://example.com/otherpath", function (err, cookies) {
},
)
cookiejar.getCookies('http://example.com/otherpath', function (err, cookies) {
/* ... */
});
})
```

Why the name? NPM modules `cookie`, `cookies` and `cookiejar` were already taken.
Expand Down Expand Up @@ -113,8 +113,8 @@ For use with `.sort()`, sorts a list of cookies into the recommended order given
```javascript
var cookies = [
/* unsorted array of Cookie objects */
];
cookies = cookies.sort(cookieCompare);
]
cookies = cookies.sort(cookieCompare)
```

> **Note**: Since the JavaScript `Date` is limited to a 1-ms precision, cookies within the same millisecond are entirely possible. This is especially true when using the `now` option to `.setCookie()`. The `.creationIndex` property is a per-process global counter, assigned during construction with `new Cookie()`, which preserves the spirit of the RFC sorting: older cookies go first. This works great for `MemoryCookieStore` since `Set-Cookie` headers are parsed in order, but is not so great for distributed systems. Sophisticated `Store`s may wish to set this to some other _logical clock_ so that if cookies A and B are created in the same millisecond, but cookie A is created before cookie B, then `A.creationIndex < B.creationIndex`. If you want to alter the global counter, which you probably _shouldn't_ do, it's stored in `Cookie.cookiesCreated`.
Expand Down Expand Up @@ -144,9 +144,9 @@ If options is not an object it is ignored, which means it can be used with [`Arr
To process the Set-Cookie header(s) on a node HTTP/HTTPS response:

```javascript
if (Array.isArray(res.headers["set-cookie"]))
cookies = res.headers["set-cookie"].map(Cookie.parse);
else cookies = [Cookie.parse(res.headers["set-cookie"])];
if (Array.isArray(res.headers['set-cookie']))
cookies = res.headers['set-cookie'].map(Cookie.parse)
else cookies = [Cookie.parse(res.headers['set-cookie'])]
```

_Note:_ In version 2.3.3, tough-cookie limited the number of spaces before the `=` to 256 characters. This limitation was removed in version 2.3.4.
Expand Down
12 changes: 0 additions & 12 deletions jest.config.js

This file was deleted.

15 changes: 15 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
colincasey marked this conversation as resolved.
Show resolved Hide resolved
import type { JestConfigWithTsJest } from 'ts-jest'

const config: JestConfigWithTsJest = {
preset: 'ts-jest',
testEnvironment: 'node',
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.ts$',
colincasey marked this conversation as resolved.
Show resolved Hide resolved
testPathIgnorePatterns: ['dist'],
maxWorkers: 1,
globals: {
'*.ts': ['ts-jest', { isolatedModules: false }],
},
}

export default config
16 changes: 8 additions & 8 deletions lib/__tests__/canonicalDomain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import {canonicalDomain} from "../cookie";
import { canonicalDomain } from '../cookie'

// port of tests/domain_and_path_test.js (canonicalDomain tests for domain normalization)
describe('canonicalDomain', () => {
it.each([
{
description: 'already canonical',
input: 'example.com',
output: 'example.com'
output: 'example.com',
},
{
description: 'simple',
input: 'EXAMPLE.com',
output: 'example.com'
output: 'example.com',
},
{
description: 'leading dot stripped',
input: '.EXAMPLE.com',
output: 'example.com'
output: 'example.com',
},
{
description: 'trailing dot',
input: 'EXAMPLE.com.',
output: 'example.com.'
output: 'example.com.',
},
{
description: 'leading and trailing dot',
input: '.EXAMPLE.com.',
output: 'example.com.'
output: 'example.com.',
},
{
description: 'internal dots',
input: '.EXAMPLE...com.',
output: 'example...com.'
output: 'example...com.',
},
{
description: 'IDN: test.test in greek',
input: 'δοκιμή.δοκιμή',
output: 'xn--jxalpdlp.xn--jxalpdlp'
output: 'xn--jxalpdlp.xn--jxalpdlp',
},
])('$description: $input → $output', ({ input, output }) => {
expect(canonicalDomain(input)).toBe(output)
Expand Down
Loading