Skip to content

Commit

Permalink
feat: Support unpkg (#11)
Browse files Browse the repository at this point in the history
* feat: Add support `unpkg`

* test: test for unpkg
  • Loading branch information
Omochice authored Oct 24, 2023
1 parent 419ca62 commit 88d9973
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
15 changes: 6 additions & 9 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"fileMatch": ["^import_map.json$", "^deno.jsonc?$"],
"matchStrings": [
"['\"].+?['\"]\\s*:\\s*['\"]https://esm.sh/(?<depName>.+?)@v?(?<currentValue>\\d+?(?:\\.\\d+?){0,2}).*?['\"]",
"['\"].+?['\"]\\s*:\\s*['\"]npm:(?<depName>.+?)@(?<currentValue>\\d+?(?:\\.\\d+?){0,2}).*?['\"]"
"['\"].+?['\"]\\s*:\\s*['\"]npm:(?<depName>.+?)@(?<currentValue>\\d+?(?:\\.\\d+?){0,2}).*?['\"]",
"['\"].+?['\"]\\s*:\\s*['\"]https?://unpkg.com/(?<depName>(?:@[^/\"']*/)?[^/\"']*?)@(?<currentValue>[^'\"]*?)[/'\"]"
],
"datasourceTemplate": "npm"
},
Expand All @@ -32,16 +33,14 @@
"fileMatch": ["\\.[jt]sx?$"],
"matchStrings": [
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]https://esm.sh/(?<depName>.+?)@v?(?<currentValue>\\d+?(?:\\.\\d+?){0,2}).*?['\"]",
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]npm:(?<depName>.+?)@(?<currentValue>\\d+?(?:\\.\\d+?){0,2}).*?['\"]"
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]npm:(?<depName>.+?)@(?<currentValue>\\d+?(?:\\.\\d+?){0,2}).*?['\"]",
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]https?://unpkg.com/(?<depName>(?:@[^/\"']*/)?[^/\"']*?)@(?<currentValue>[^'\"]*?)[/'\"]"
],
"datasourceTemplate": "npm"
},
{
"customType": "regex",
"fileMatch": [
"^import_map.json$",
"^deno.jsonc?$"
],
"fileMatch": ["^import_map.json$", "^deno.jsonc?$"],
"matchStrings": [
"\".+?\"\\s*:\\s*['\"]https://pax.deno.dev/(?<depName>.+?/.+?)@(?<currentValue>.+?)[/'\"]",
"\".+?\"\\s*:\\s*['\"]https://raw.githubusercontent.com/(?<depName>.+?/.+?)/(?<currentValue>.+?)[/'\"]"
Expand All @@ -50,9 +49,7 @@
},
{
"customType": "regex",
"fileMatch": [
"\\.[jt]sx?$"
],
"fileMatch": ["\\.[jt]sx?$"],
"matchStrings": [
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]https://pax.deno.dev/(?<depName>.+?/.+?)@(?<currentValue>.+?)[/'\"]",
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]https://raw.githubusercontent.com/(?<depName>.+?/.+?)/(?<currentValue>.+?)[/'\"]"
Expand Down
28 changes: 26 additions & 2 deletions test/deno.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ describe("2: npm for import map", () => {
"chalk": "npm:chalk@5.0.1",
"chalk": "https://esm.sh/chalk@5.0.1",
"chalk": "npm:chalk@5",
"foo": "https://unpkg.com/@bar/foo@0.1.0/foo.ts",
"foo": "https://unpkg.com/foo@0.1.0/umd/foo.production.min.js",
}
}`;
const expects = [
Expand All @@ -89,6 +91,16 @@ describe("2: npm for import map", () => {
currentValue: "5",
depName: "chalk",
},
{
title: "should accept unpkg.com specifier",
currentValue: "0.1.0",
depName: "@bar/foo",
},
{
title: "should accept unpkg.com specifier without @scope",
currentValue: "0.1.0",
depName: "foo",
},
];
const matches = regexps[1]
.map((re) =>
Expand Down Expand Up @@ -159,6 +171,8 @@ describe("4: npm for js file", () => {
import chalk from "npm:chalk@5.0.1";
export chalk from "https://esm.sh/chalk@5.0.1";
import chalk from "npm:chalk@5";
import foo from "https://unpkg.com/@bar/foo@0.1.0/foo.ts";
import foo from "https://unpkg.com/foo@0.1.0/umd/foo.production.min.js";
`;

const expects = [
Expand All @@ -177,6 +191,16 @@ describe("4: npm for js file", () => {
currentValue: "5",
depName: "chalk",
},
{
title: "should accept unpkg.com specifier",
currentValue: "0.1.0",
depName: "@bar/foo",
},
{
title: "should accept unpkg.com specifier without @scope",
currentValue: "0.1.0",
depName: "foo",
},
];

const matches = regexps[3]
Expand Down Expand Up @@ -227,7 +251,7 @@ describe("5: github tag for import_map", () => {
title: "should accept un-semver version",
currentValue: "someversion",
depName: "user/repo",
}
},
];

const matches = regexps[4]
Expand Down Expand Up @@ -275,7 +299,7 @@ describe("6: github tag for js file", () => {
title: "should accept un-semver version",
currentValue: "someversion",
depName: "user/repo",
}
},
];

const matches = regexps[5]
Expand Down

0 comments on commit 88d9973

Please sign in to comment.