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 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
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
dist
node_modules
test
colincasey marked this conversation as resolved.
Show resolved Hide resolved
jest.config.ts
40 changes: 25 additions & 15 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
{
"extends": ["plugin:prettier/recommended"],
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
//"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended"
],
colincasey marked this conversation as resolved.
Show resolved Hide resolved
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6
"tsconfigRootDir": "./",
"project": ["tsconfig.json"]
},
"reportUnusedDisableDirectives": true,
"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"
]
// 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"
}
}
14 changes: 8 additions & 6 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
name: Actions-CI
name: Actions-CI

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

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [latest, lts/*, lts/-1]
colincasey marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Install dependencies and test
run: npm install
- run: npm test
- run: npm run eslint
- run: npm run prettier
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ npm-debug.log
docker-compose.override.yml
.nyc_output
coverage
package-lock.json
.npm
.config
.bash_history
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 ossconduct@salesforce.com.

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 ossconduct@salesforce.com. 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 ossconduct@salesforce.com. 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
9 changes: 0 additions & 9 deletions jest.config.js

This file was deleted.

10 changes: 10 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { JestConfigWithTsJest } from "ts-jest";

const config: JestConfigWithTsJest = {
preset: 'ts-jest',
testEnvironment: 'node',
rootDir: './lib/',
testPathIgnorePatterns: ['./lib/__tests__/data/'],
}

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
18 changes: 9 additions & 9 deletions 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'
import { Cookie } from '../cookie'

jest.useFakeTimers()

Expand All @@ -40,25 +40,25 @@ describe('Cookie', () => {
describe('constructor', () => {
beforeEach(() => {
cookie = new Cookie({
key: "test",
value: "b",
maxAge: 60
key: 'test',
value: 'b',
maxAge: 60,
})
})

it("should check for key property", () => {
it('should check for key property', () => {
expect(cookie.key).toBe('test')
})

it('should check for value property', () => {
expect(cookie.value).toBe("b");
expect(cookie.value).toBe('b')
})

it("should check for maxAge", () => {
expect(cookie.maxAge).toBe(60);
it('should check for maxAge', () => {
expect(cookie.maxAge).toBe(60)
})

it("should check for default values for unspecified properties", () => {
it('should check for default values for unspecified properties', () => {
expect(cookie.expires).toBe('Infinity')
expect(cookie.secure).toBe(false)
expect(cookie.httpOnly).toBe(false)
Expand Down
Loading