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

feat: add shim for URLPattern #417

Open
wants to merge 1 commit into
base: main
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
9 changes: 6 additions & 3 deletions lib/shims.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Deno.test("should get when all true", () => {
crypto: true,
domException: true,
undici: true,
urlPattern: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should use a deno fmt to fix that tabulation.

weakRef: true,
webSocket: true,
custom: [{
Expand All @@ -31,8 +32,8 @@ Deno.test("should get when all true", () => {
}],
});

assertEquals(result.shims.length, 10);
assertEquals(result.testShims.length, 11);
assertEquals(result.shims.length, 11);
assertEquals(result.testShims.length, 12);
});

Deno.test("should get when all dev", () => {
Expand All @@ -44,12 +45,13 @@ Deno.test("should get when all dev", () => {
crypto: "dev",
domException: "dev",
undici: "dev",
urlPattern: "dev",
weakRef: "dev",
webSocket: "dev",
});

assertEquals(result.shims.length, 0);
assertEquals(result.testShims.length, 9);
assertEquals(result.testShims.length, 10);
});

Deno.test("should get when all false", () => {
Expand All @@ -61,6 +63,7 @@ Deno.test("should get when all false", () => {
crypto: false,
domException: false,
undici: false,
urlPattern: false,
weakRef: false,
webSocket: false,
});
Expand Down
13 changes: 13 additions & 0 deletions lib/shims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface ShimOptions {
* using the "undici" package (https://www.npmjs.com/package/undici).
*/
undici?: ShimValue;
/** Shim `URLPattern` using the "urlpattern-polyfill" package (https://www.npmjs.com/package/urlpattern-polyfill) */
urlPattern?: ShimValue;
/** Use a sham for the `WeakRef` global, which uses `globalThis.WeakRef` when
* it exists. The sham will throw at runtime when calling `deref()` and `WeakRef`
* doesn't globally exist, so this is only intended to help type check code that
Expand Down Expand Up @@ -73,6 +75,7 @@ export function shimOptionsToTransformShims(options: ShimOptions) {
add(options.timers, getTimersShim);
add(options.domException, getDomExceptionShim);
add(options.undici, getUndiciShim);
add(options.urlPattern, getURLPatternShim);
add(options.weakRef, getWeakRefShim);
add(options.webSocket, getWebSocketShim);

Expand Down Expand Up @@ -218,6 +221,16 @@ function getUndiciShim(): Shim {
};
}

function getURLPatternShim(): Shim {
return {
package: {
name: "urlpattern-polyfill",
version: "~10.0.0",
},
globalNames: ["URLPattern"],
};
}

function getDomExceptionShim(): Shim {
return {
package: {
Expand Down