Skip to content

Commit

Permalink
feat: match all config for workspace and to test npm: specifier wit…
Browse files Browse the repository at this point in the history
…h subpath exports in import map (#45)

* fix: regex to test `npm:` specifier with subpath exports in import map

* feat: match all file of import map and deno config for workspace

* fix: regex of fileMatch

* Update test/deno/npm.test.ts

Co-authored-by: Omochice <44566328+Omochice@users.noreply.github.com>

* fix: following bdd test format

* chore: fmt

* chore: remove unused import

---------

Co-authored-by: Omochice <44566328+Omochice@users.noreply.github.com>
  • Loading branch information
Hajime-san and Omochice authored May 4, 2024
1 parent e4c8a3d commit aa5b7b5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion deno/deno-land.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"customManagers": [
{
"customType": "regex",
"fileMatch": ["^import_map.json$", "^deno.jsonc?$"],
"fileMatch": ["(?:^|/)import_map.json$", "(?:^|/)deno.jsonc?$"],
"matchStrings": [
"['\"].+?['\"]\\s*:\\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-]+)*))?)?)?)[/'\"]"
],
Expand Down
2 changes: 1 addition & 1 deletion deno/github-tag.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"customManagers": [
{
"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 Down
2 changes: 1 addition & 1 deletion deno/jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"customManagers": [
{
"customType": "regex",
"fileMatch": ["^import_map.json$", "^deno.jsonc?$"],
"fileMatch": ["(?:^|/)import_map.json$", "(?:^|/)deno.jsonc?$"],
"matchStrings": [
"['\"].+?['\"]\\s*:\\s*['\"]jsr:(?<depName>@(?<namespace>.+?)/(?<package>.+?))@[\\^~]?(?<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-]+)*))?)?)?)[/\"']"
],
Expand Down
2 changes: 1 addition & 1 deletion deno/nest-land.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"customManagers": [
{
"customType": "regex",
"fileMatch": ["^import_map.json$", "^deno.jsonc?$"],
"fileMatch": ["(?:^|/)import_map.json$", "(?:^|/)deno.jsonc?$"],
"matchStrings": [
"['\"].+?['\"]\\s*:\\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-]+)*))?)?)?)[/'\"]"
],
Expand Down
4 changes: 2 additions & 2 deletions deno/npm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"customManagers": [
{
"customType": "regex",
"fileMatch": ["^import_map.json$", "^deno.jsonc?$"],
"fileMatch": ["(?:^|/)import_map.json$", "(?:^|/)deno.jsonc?$"],
"matchStrings": [
"['\"].+?['\"]\\s*:\\s*['\"]https://esm.sh/(?<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-]+)*))?)?)?)[?/\"']",
"['\"].+?['\"]\\s*:\\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-]+)*))?)?)?)[/\"']",
"['\"].+?['\"]\\s*:\\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-]+)*))?)?)?)[/\"']",
"['\"].+?['\"]\\s*:\\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-]+)*))?)?)?)[/\"']",
"['\"].+?['\"]\\s*:\\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-]+)*))?)?)?)[?/\"']"
],
Expand Down
29 changes: 29 additions & 0 deletions test/deno/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,35 @@ describe("npm for import map", () => {
}
});

// NOTE: This feature is not required in the imports field in deno.json and source files.
// https://github.com/denoland/deno/pull/22087
// https://deno.com/blog/v1.40#simpler-imports-in-denojson
describe("should accept npm specifier with subpath exports in import map", () => {
it("should match all exports of preact", () => {
const testCase = {
input: `{
"imports": {
"preact": "npm:preact@10.5.13",
"preact/": "npm:/preact@10.5.13/"
}
}`,
currentValue: "10.5.13",
depName: "preact",
} as const;

const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(2);
for (const match of matches) {
expect(match?.currentValue).toBe(testCase.currentValue);
expect(match?.depName).toBe(testCase.depName);
}
});
});

describe("npm for js file", () => {
const testCases = [
{
Expand Down

0 comments on commit aa5b7b5

Please sign in to comment.