Set target to ES2021

This commit is contained in:
Stan Wohlwend 2024-07-07 17:28:14 -07:00
parent 0163513bf9
commit 8e8a1b1be1
10 changed files with 36 additions and 7 deletions

View File

@ -34,6 +34,12 @@ export abstract class OAuthBaseProvider {
// facebook always return an id_token even in the OAuth2 flow, which is not supported by openid-client
const oldGrant = this.oauthClient.grant;
if (!(oldGrant as any)) {
// it seems that on Sentry, this was undefined in one scenario, so let's log some data to help debug if it happens again
// not sure if that is actually what was going on? the error log has very few details
// https://stackframe-pw.sentry.io/issues/5515577938
throw new StackAssertionError("oldGrant is undefined for some reason — that should never happen!", { options, oauthClient: this.oauthClient });
}
this.oauthClient.grant = async function (params) {
const grant = await oldGrant.call(this, params);
delete grant.id_token;

View File

@ -4,7 +4,8 @@
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"target": "ESNext",
"target": "ES2021",
"lib": ["DOM", "DOM.Iterable", "ES2021", "ES2022.Error"],
"module": "ES2015",
"moduleResolution": "Bundler",
"esModuleInterop": true,

View File

@ -4,7 +4,8 @@
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"target": "ESNext",
"target": "ES2021",
"lib": ["DOM", "DOM.Iterable", "ES2021", "ES2022.Error"],
"module": "ES2015",
"moduleResolution": "Bundler",
"esModuleInterop": true,

View File

@ -16,6 +16,16 @@ export function isShallowEqual(a: readonly any[], b: readonly any[]): boolean {
return true;
}
/**
* Ponyfill for ES2023's findLastIndex.
*/
export function findLastIndex<T>(arr: readonly T[], predicate: (item: T) => boolean): number {
for (let i = arr.length - 1; i >= 0; i--) {
if (predicate(arr[i])) return i;
}
return -1;
}
export function groupBy<T extends any, K>(
arr: Iterable<T>,
key: (item: T) => K,

View File

@ -8,6 +8,10 @@ export {
globalVar,
};
if (typeof globalThis === 'undefined') {
(globalVar as any).globalThis = globalVar;
}
const stackGlobalsSymbol = Symbol.for('__stack-globals');
globalVar[stackGlobalsSymbol] ??= {};

View File

@ -1,3 +1,4 @@
import { findLastIndex } from "./arrays";
import { StackAssertionError } from "./errors";
import { filterUndefined } from "./objects";
@ -49,7 +50,7 @@ export function trimEmptyLinesStart(s: string): string {
*/
export function trimEmptyLinesEnd(s: string): string {
const lines = s.split("\n");
const lastNonEmptyLineIndex = lines.findLastIndex((line) => line.trim() !== "");
const lastNonEmptyLineIndex = findLastIndex(lines, (line) => line.trim() !== "");
return lines.slice(0, lastNonEmptyLineIndex + 1).join("\n");
}

View File

@ -1,5 +1,8 @@
import { globalVar } from "./globals";
export function generateUuid() {
return globalVar.crypto.randomUUID();
// crypto.randomUuid is not supported in all browsers, so this is a polyfill
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
(+c ^ globalVar.crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
);
}

View File

@ -4,7 +4,8 @@
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"target": "ESNext",
"target": "ES2021",
"lib": ["DOM", "DOM.Iterable", "ES2021", "ES2022.Error"],
"module": "ES2015",
"moduleResolution": "Bundler",
"esModuleInterop": true,

View File

@ -4,7 +4,8 @@
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"target": "ESNext",
"target": "ES2021",
"lib": ["DOM", "DOM.Iterable", "ES2021", "ES2022.Error"],
"module": "ES2015",
"moduleResolution": "Bundler",
"esModuleInterop": true,

View File

@ -4,7 +4,8 @@
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"target": "ES2022",
"target": "ES2021",
"lib": ["DOM", "DOM.Iterable", "ES2021", "ES2022.Error"],
"module": "ES2020",
"moduleResolution": "Bundler",
"esModuleInterop": true,