Skip to content

Commit

Permalink
fix: Upgrade packages prep for a few patches
Browse files Browse the repository at this point in the history
Updated packages as below

- Updated to Node 20
- Updated all deps
- Updated code to match latest linting
  • Loading branch information
cdloh committed May 1, 2024
1 parent cfedab8 commit 060c874
Show file tree
Hide file tree
Showing 14 changed files with 8,470 additions and 15,243 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [16.x]
node: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -29,7 +29,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [16.x, 17.x]
node: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
23,375 changes: 8,297 additions & 15,078 deletions package-lock.json

Large diffs are not rendered by default.

56 changes: 33 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,39 +66,49 @@
],
"rules": {
"jsdoc/no-undefined-types": 0,
"jsdoc/tag-lines": [
"error",
"any",
{
"startLines": 1
}
],
"no-new-func": [
"error"
],
"no-eval": [
"error"
],
"no-return-await": [
"error"
]
}
},
"devDependencies": {
"@cloudflare/workers-types": "^3.1.1",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.5",
"@semantic-release/npm": "^9.0.1",
"@semantic-release/release-notes-generator": "^10.0.3",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"esbuild": "^0.15.5",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-typescript": "^3.0.0",
"eslint-plugin-jsdoc": "^39.3.6",
"jest": "^27.3.1",
"jest-environment-miniflare": "2.7.1",
"miniflare": "2.7.1",
"prettier": "^2.4.1",
"semantic-release": "^19.0.4",
"ts-jest": "^27.0.7",
"typescript": "^4.4.4"
"@cloudflare/workers-types": "4.20240423.0",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/commit-analyzer": "12.0.0",
"@semantic-release/git": "10.0.1",
"@semantic-release/github": "10.0.3",
"@semantic-release/npm": "12.0.0",
"@semantic-release/release-notes-generator": "13.0.0",
"@types/jest": "29.5.12",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
"esbuild": "0.20.2",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-config-typescript": "3.0.0",
"eslint-plugin-jsdoc": "48.2.3",
"jest": "29.7.0",
"jest-environment-miniflare": "2.14.2",
"miniflare": "3.20240419.0",
"prettier": "3.2.5",
"semantic-release": "23.0.8",
"ts-jest": "29.1.2",
"typescript": "5.4.5"
},
"dependencies": {
"worktop": "^0.7.3"
"worktop": "0.7.3"
}
}
6 changes: 3 additions & 3 deletions src/headerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
*/
export function getheaderToken(
header: string,
directive: string
directive: string,
): string | null {
if (headerHasDirective(header, directive)) {
const matches = header.match(
new RegExp(
`${directive}="?([a-z0-9_~!#%&/',\`\\$\\*\\+\\-\\|\\^\\.]+)"?`,
"i"
)
"i",
),
);
if (matches) {
return matches[1];
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export type customESIVars = {
[key: string]: string | { [key: string]: string };
};
export type customESIVarsFunction = (
request: Request
request: Request,
) => Promise<customESIVars>;
export type fetchFunction = (request: string | Request) => Promise<Response>;

Expand All @@ -115,7 +115,7 @@ export class esi {
constructor(
options?: ESIConfig,
customESIFunction?: customESIVarsFunction,
fetcher = fetch
fetcher = fetch as fetchFunction,
) {
const defaultConfig = {
recursionLimit: 10,
Expand Down Expand Up @@ -225,7 +225,7 @@ export class esi {
text,
vars,
this.fetcher,
this.esiFunction
this.esiFunction,
);

return text;
Expand All @@ -237,7 +237,7 @@ export class esi {
async streamBody(
eventData: ESIEventData,
readable: ReadableStream,
writable: WritableStream
writable: WritableStream,
): Promise<void> {
const reader = readable.getReader();
const encoder = new TextEncoder();
Expand Down
12 changes: 6 additions & 6 deletions src/processConditionals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const esi_when_pattern = /(?:<esi:when)\s+(?:test="(.+?)"\s*>)/;
export async function process(
esiData: ESIEventData,
chunk: string,
res: Array<string> = []
res: Array<string> = [],
): Promise<[string, boolean]> {
const parser = new tagParser(chunk);
let after;
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function process(
const condition = match[1];
const conditionValidated = await _esi_evaluate_condition(
esiData,
condition
condition,
);

if (tag && tag.contents && conditionValidated) {
Expand Down Expand Up @@ -122,7 +122,7 @@ const reg_esi_condition =
*/
function esi_eval_var_in_when_tag(
eventData: ESIEventData,
match: [String: string, ...args: string[]]
match: [String: string, ...args: string[]],
): string {
const varInTag = esi_eval_var(eventData, match);

Expand Down Expand Up @@ -175,7 +175,7 @@ function _esi_condition_lexer(condition: string): boolean {
function esiConditionTester(
left: string,
right: string,
operator: string
operator: string,
): boolean {
switch (operator) {
case "==":
Expand Down Expand Up @@ -316,7 +316,7 @@ function esi_bracket_splitter(condition: string): boolean {
fullExpression.push(condition.substring(parsedPoint, startingIndex));
const conditionBracketed = condition.substring(
startingIndex + 1,
endIndex
endIndex,
);

// Loop it back to see if there is another bracket inside
Expand Down Expand Up @@ -348,7 +348,7 @@ function esi_bracket_splitter(condition: string): boolean {
*/
function _esi_evaluate_condition(
esiData: ESIEventData,
condition: string
condition: string,
): boolean {
// Check for variables
condition = replace_vars(esiData, condition, esi_eval_var_in_when_tag);
Expand Down
10 changes: 5 additions & 5 deletions src/processESIVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const esiLessArrow = />/g;
*/
export async function process(
eventData: ESIEventData,
chunk: string
chunk: string,
): Promise<string> {
if (chunk.indexOf("esi:vars") == -1) {
return chunk;
Expand All @@ -31,7 +31,7 @@ export async function process(

type replaceFunction = (
eventData: ESIEventData,
var_match: [String: string, ...args: string[]]
var_match: [String: string, ...args: string[]],
) => string;

/**
Expand All @@ -46,7 +46,7 @@ type replaceFunction = (
export function replace_vars(
eventData: ESIEventData,
str: string,
cb: replaceFunction = esi_eval_var
cb: replaceFunction = esi_eval_var,
): string {
return str.replace(esiVarsPatternRegex, function (...match) {
return cb(eventData, match);
Expand All @@ -63,7 +63,7 @@ export function replace_vars(
*/
export function esi_eval_var(
eventData: ESIEventData,
var_match: [String: string, ...args: string[]]
var_match: [String: string, ...args: string[]],
): string {
let escape = true;
const var_name = var_match[1];
Expand Down Expand Up @@ -93,7 +93,7 @@ export function esi_eval_var(
*/
function _esi_eval_var(
eventData: ESIEventData,
var_pattern: [String: string, ...args: string[]]
var_pattern: [String: string, ...args: string[]],
): string {
const var_name = var_pattern[1] || "";
const key = var_pattern[2] == "" ? null : var_pattern[2];
Expand Down
2 changes: 1 addition & 1 deletion src/processEscaping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { tagParser } from "./tagParser";
*/
export async function process(
chunk: string,
res: Array<string> = []
res: Array<string> = [],
): Promise<string> {
const parser = new tagParser(chunk);
let hasEscaping = false;
Expand Down
14 changes: 7 additions & 7 deletions src/processIncludes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function process(
chunk: string,
evalVars: boolean,
fetcher: fetchFunction,
customESIFunction?: customESIVarsFunction
customESIFunction?: customESIVarsFunction,
): Promise<string> {
if (chunk.indexOf("<esi:include") == -1) {
if (evalVars) {
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function process(
eventData,
includeMatch[1], // pass the src tag straight through
fetcher,
customESIFunction
customESIFunction,
);

// Already escaped by the fetcher
Expand Down Expand Up @@ -81,7 +81,7 @@ async function fetchInclude(
eventData: ESIEventData,
include: string,
fetcher: fetchFunction,
customESIFunction?: customESIVarsFunction
customESIFunction?: customESIVarsFunction,
): Promise<string> {
// replace any vars in the src string
const src = replace_vars(eventData, include);
Expand All @@ -101,27 +101,27 @@ async function fetchInclude(
if (eventData.request.headers.get("Authorization")) {
req.headers.set(
"Authorization",
eventData.request.headers.get("Authorization") as string
eventData.request.headers.get("Authorization") as string,
);
}
if (eventData.request.headers.get("Cookie")) {
req.headers.set(
"Cookie",
eventData.request.headers.get("Cookie") as string
eventData.request.headers.get("Cookie") as string,
);
}
}

// Add our recursion level and parent uri
req.headers.set(
"X-ESI-Recursion-Level",
(eventData.recursion + 1).toString()
(eventData.recursion + 1).toString(),
);
req.headers.set("X-ESI-Parent-URI", eventData.request.url);
if (eventData.request.headers.get("Cache-Control")) {
req.headers.set(
"Cache-Control",
eventData.request.headers.get("Cache-Control") as string
eventData.request.headers.get("Cache-Control") as string,
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/surrogate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import { getheaderToken } from "./headerUtils";
* @returns {Promise<Request>} Request with SurrogateControl header added
*/
export async function advertiseSurrogateControl(
request: Request
request: Request,
): Promise<Request> {
let coloName = "";
if (request.cf && request.cf.colo) {
coloName = `-${request.cf.colo}`;
}
request.headers.append(
"Surrogate-Capability",
`cloudflareWorkerESI${coloName}="${getProcessorToken()}/${getProcessorVersionString()}"`
`cloudflareWorkerESI${coloName}="${getProcessorToken()}/${getProcessorVersionString()}"`,
);
return request;
}
Expand All @@ -37,7 +37,7 @@ export async function advertiseSurrogateControl(
*/
export async function canDelegateToSurrogate(
request: Request,
config: ESIConfig
config: ESIConfig,
): Promise<boolean> {
const surrogates = config.allowSurrogateDelegation;
if (surrogates === undefined || surrogates === false) return false;
Expand All @@ -46,7 +46,7 @@ export async function canDelegateToSurrogate(
if (surrogateCapability) {
const capabilityToken = getheaderToken(
surrogateCapability,
"[!#\\$%&'\\*\\+\\-.\\^_`\\|~0-9a-zA-Z]+"
"[!#\\$%&'\\*\\+\\-.\\^_`\\|~0-9a-zA-Z]+",
);
const [capabilityProcessor, capabilityVersion] =
splitESIToken(capabilityToken);
Expand Down Expand Up @@ -79,7 +79,7 @@ export async function canDelegateToSurrogate(
* @returns {[string | null, number | null]} A valid token split or null
*/
export function splitESIToken(
token: string | null
token: string | null,
): [string | null, number | null] {
if (!token) return [null, null];
const matches = token.match(/^([A-Za-z0-9-_]+)\/(\d+\.?\d+)$/);
Expand Down
6 changes: 3 additions & 3 deletions src/tagParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class tagParser {
}

async next(
tagname?: string
tagname?: string,
): Promise<[tag | null, string | undefined, string | undefined]> {
const tag = this.findWholeTag(tagname);
let before, after;
Expand All @@ -49,7 +49,7 @@ export class tagParser {
}

return new RegExp(
`<(${tag})(?:\\s*(?:[a-z]+=\\".+?(?<!\\\\)\\"))?[^>]*?(?:\\s*)(/>|>)?`
`<(${tag})(?:\\s*(?:[a-z]+=\\".+?(?<!\\\\)\\"))?[^>]*?(?:\\s*)(/>|>)?`,
);
}

Expand All @@ -58,7 +58,7 @@ export class tagParser {
return /(?:<(!--esi)|(-->))/;
}
return new RegExp(
`<[\\/]?(${tag})(?:\\s*(?:[a-z]+=\\".+?(?<!\\\\)\\"))?[^>]*?(?:\\s*)(\\s*/>|>)?`
`<[\\/]?(${tag})(?:\\s*(?:[a-z]+=\\".+?(?<!\\\\)\\"))?[^>]*?(?:\\s*)(\\s*/>|>)?`,
);
}

Expand Down
Loading

0 comments on commit 060c874

Please sign in to comment.