Skip to content

Commit

Permalink
feat: add //@deno-types support (#31)
Browse files Browse the repository at this point in the history
* feat: add `//@deno-types` support

* chore: remove trailing commas

I don't think these were intentional
  • Loading branch information
nekowinston authored Dec 28, 2023
1 parent b0fed4d commit a416fb0
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 12 deletions.
2 changes: 1 addition & 1 deletion deno/deno-land.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"customType": "regex",
"fileMatch": ["\\.[jt]sx?$"],
"matchStrings": [
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"](?<depName>https://deno.land/(?:x?.+?|std))@(?<currentValue>v?(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[/'\"]"
"((?:im|ex)port(?:.|\\s)+?from\\s*|//\\s*@deno-types=)['\"](?<depName>https://deno.land/(?:x?.+?|std))@(?<currentValue>v?(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[/'\"]"
],
"datasourceTemplate": "deno"
}
Expand Down
4 changes: 2 additions & 2 deletions deno/github-tag.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"customType": "regex",
"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>[^'\"]+?)[/'\"]"
"((?:im|ex)port(?:.|\\s)+?from\\s*|//\\s*@deno-types=)['\"]https://pax.deno.dev/(?<depName>.+?/.+?)@(?<currentValue>[^/\"']+?)[/\"']",
"((?:im|ex)port(?:.|\\s)+?from\\s*|//\\s*@deno-types=)['\"]https://raw.githubusercontent.com/(?<depName>.+?/.+?)/(?<currentValue>[^'\"]+?)[/'\"]"
],
"datasourceTemplate": "github-tags"
}
Expand Down
2 changes: 1 addition & 1 deletion deno/nest-land.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"customType": "regex",
"fileMatch": ["\\.[jt]sx?$"],
"matchStrings": [
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]https://x.nest.land/(?<depName>.+?)@(?<currentValue>v?(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[/'\"]"
"((?:im|ex)port(?:.|\\s)+?from\\s*|//\\s*@deno-types=)['\"]https://x.nest.land/(?<depName>.+?)@(?<currentValue>v?(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[/'\"]"
],
"datasourceTemplate": "custom.nest-land"
}
Expand Down
8 changes: 4 additions & 4 deletions deno/npm.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"customType": "regex",
"fileMatch": ["\\.[jt]sx?$"],
"matchStrings": [
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]https://esm.sh/(v\\d{1,3}/)?(?<depName>.+?)@v?(?<currentValue>(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[?/'\"]",
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]npm:(?<depName>.+?)@v?(?<currentValue>(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[/'\"]",
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]https?://unpkg.com/(?<depName>(?:@[^/\"']*/)?[^/\"']*?)@v?(?<currentValue>(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[/'\"]",
"(?:im|ex)port(?:.|\\s)+?from\\s*['\"]https?://cdn.skypack.dev/(?<depName>(?:@[^/\"']*/)?[^/\"']*?)@v?(?<currentValue>(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[?/'\"]"
"((?:im|ex)port(?:.|\\s)+?from\\s*|//\\s*@deno-types=)['\"]https://esm.sh/(v\\d{1,3}/)?(?<depName>.+?)@v?(?<currentValue>(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[?/'\"]",
"((?:im|ex)port(?:.|\\s)+?from\\s*|//\\s*@deno-types=)['\"]npm:(?<depName>.+?)@v?(?<currentValue>(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[/'\"]",
"((?:im|ex)port(?:.|\\s)+?from\\s*|//\\s*@deno-types=)['\"]https?://unpkg.com/(?<depName>(?:@[^/\"']*/)?[^/\"']*?)@v?(?<currentValue>(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[/'\"]",
"((?:im|ex)port(?:.|\\s)+?from\\s*|//\\s*@deno-types=)['\"]https?://cdn.skypack.dev/(?<depName>(?:@[^/\"']*/)?[^/\"']*?)@v?(?<currentValue>(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)?)?)[?/'\"]"
],
"datasourceTemplate": "npm"
}
Expand Down
18 changes: 18 additions & 0 deletions test/deno/deno-land.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ describe("deno.land for import map", () => {
currentValue: "0.1.0",
depName: "https://deno.land/x/some_module",
},
{
title: "should accept deno.land/std in //@deno-types",
input: `// @deno-types="https://deno.land/std@0.204.0/path/mod.ts";`,
currentValue: "0.204.0",
depName: "https://deno.land/std",
},
{
title: "should accept if 'v' in version in //@deno-types",
input: `// @deno-types="https://deno.land/std@v1.0.0/some/mod.ts";`,
currentValue: "v1.0.0",
depName: "https://deno.land/std",
},
{
title: "should accept deno.land/x in //@deno-types",
input: `// @deno-types="https://deno.land/x/some_module@0.1.0/some/mod.ts";`,
currentValue: "0.1.0",
depName: "https://deno.land/x/some_module",
},
] as const;

for (const testCase of testCases) {
Expand Down
37 changes: 34 additions & 3 deletions test/deno/github-tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ describe("github tag for js file", () => {
const testCases = [
{
title: "should accept raw.githubusercontent.com",
input: `import { sample } from "https://raw.githubusercontent.com/user/repo/1.0.0/mod.ts",`,
input: `import { sample } from "https://raw.githubusercontent.com/user/repo/1.0.0/mod.ts"`,
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept pax.deno.dev",
input: `import { sample } from "https://pax.deno.dev/user/repo@1.0.0/mod.ts",`,
input: `import { sample } from "https://pax.deno.dev/user/repo@1.0.0/mod.ts"`,
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept omit 'mod.ts' when specify pax.deno.dev",
input: `import { sample } from "https://pax.deno.dev/user/repo@1.0.0",`,
input: `import { sample } from "https://pax.deno.dev/user/repo@1.0.0"`,
currentValue: "1.0.0",
depName: "user/repo",
},
Expand All @@ -124,6 +124,37 @@ describe("github tag for js file", () => {
currentValue: "sampleversion",
depName: "user/repo",
},
{
title: "should accept raw.githubusercontent.com in //@deno-types",
input: `// @deno-types="https://raw.githubusercontent.com/user/repo/1.0.0/mod.ts"`,
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept pax.deno.dev in //@deno-types",
input: `// @deno-types="https://pax.deno.dev/user/repo@1.0.0/mod.ts"`,
currentValue: "1.0.0",
depName: "user/repo",
},
{
title:
"should accept omit 'mod.ts' when specify pax.deno.dev in //@deno-types",
input: `// @deno-types="https://pax.deno.dev/user/repo@1.0.0"`,
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept complex semver version in //@deno-types",
input: `// @deno-types="https://raw.githubusercontent.com/user/repo/1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay/mod.ts"`,
currentValue: "1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay",
depName: "user/repo",
},
{
title: "should accept un-semver version in //@deno-types",
input: `// @deno-types="https://raw.githubusercontent.com/user/repo/sampleversion/mod.ts"`,
currentValue: "sampleversion",
depName: "user/repo",
},
];

for (const testCase of testCases) {
Expand Down
12 changes: 12 additions & 0 deletions test/deno/nest-land.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ describe("x.nest.land for js file", () => {
currentValue: "v0.0.1",
depName: "sample",
},
{
title: "should accept x.nest.land in //@deno-types",
input: `// @deno-types="https://x.nest.land/sample@0.0.1/mod.ts";`,
currentValue: "0.0.1",
depName: "sample",
},
{
title: "should accept x.nest.land with `v` in //@deno-types",
input: `// @deno-types="https://x.nest.land/sample@v0.0.1/mod.ts";`,
currentValue: "v0.0.1",
depName: "sample",
},
];

for (const testCase of testCases) {
Expand Down
44 changes: 43 additions & 1 deletion test/deno/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ describe("npm for js file", () => {
},
{
title: "should accept only major version",

input: `import chalk from "npm:chalk@5";`,
currentValue: "5",
depName: "chalk",
Expand Down Expand Up @@ -177,6 +176,49 @@ describe("npm for js file", () => {
currentValue: "10.5.5",
depName: "@scope/package",
},
{
title: "should accept npm specifier in //@deno-types",
input: `// @deno-types="npm:chalk@5.0.1";`,
currentValue: "5.0.1",
depName: "chalk",
},
{
title: "should accept esm.sh specifier with query in //@deno-types",
input: `// @deno-types="https://esm.sh/tslib@2.6.2?exports=__await,__rest";`,
currentValue: "2.6.2",
depName: "tslib",
},
{
title: "should accept only major version in //@deno-types",
input: `// @deno-types="npm:chalk@5";`,
currentValue: "5",
depName: "chalk",
},
{
title: "should accept unpkg.com specifier in //@deno-types",
input: `// @deno-types="https://unpkg.com/@bar/foo@0.1.0/foo.ts";`,
currentValue: "0.1.0",
depName: "@bar/foo",
},
{
title:
"should accept unpkg.com specifier without @scope in //@deno-types",
input: `// @deno-types="https://unpkg.com/foo@0.1.0/umd/foo.production.min.js";`,
currentValue: "0.1.0",
depName: "foo",
},
{
title: "should accept skypack.dev specifier in //@deno-types",
input: `// @deno-types="https://cdn.skypack.dev/@scope/package@10.5.5";`,
currentValue: "10.5.5",
depName: "@scope/package",
},
{
title: "should accept skypack.dev with query in //@deno-types",
input: `// @deno-types="https://cdn.skypack.dev/@scope/package@10.5.5?min";`,
currentValue: "10.5.5",
depName: "@scope/package",
},
] as const;

for (const testCase of testCases) {
Expand Down

0 comments on commit a416fb0

Please sign in to comment.