Skip to content

Commit

Permalink
feat: add support nest.land (#21)
Browse files Browse the repository at this point in the history
* feat: add support nest.land

* test: add test for nest.land
  • Loading branch information
Omochice authored Nov 13, 2023
1 parent f34c242 commit 2d4a858
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 1 deletion.
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"github>Omochice/renovate-config",
"github>Omochice/renovate-config//deno/deno-land",
"github>Omochice/renovate-config//deno/npm",
"github>Omochice/renovate-config//deno/github-tag"
"github>Omochice/renovate-config//deno/github-tag",
"github>Omochice/renovate-config//deno/nest-land"
]
}
30 changes: 30 additions & 0 deletions deno/nest-land.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"customManagers": [
{
"customType": "regex",
"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-]+)*))?)?)?)[/'\"]"
],
"datasourceTemplate": "custom.nest-land"
},
{
"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-]+)*))?)?)?)[/'\"]"
],
"datasourceTemplate": "custom.nest-land"
}
],
"customDatasources": {
"nest-land": {
"defaultRegistryUrlTemplate": "https://x.nest.land/api/package/{{packageName}}",
"format": "json",
"transformTemplates": [
"{ \"releases\": [{ \"version\": $split($string($.latestVersion), \"@\")[1], \"releaseTimestamp\": $.updatedAt, \"sourceUrl\": \"https://nest.land/package/\" & $.normalizedName }], \"sourceUrl\": \"https://nest.land/package/\" & $.normalizedName, \"homepage\": $.repository }"
]
}
}
}
93 changes: 93 additions & 0 deletions test/deno/nest-land.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { expect, expectTypeOf, describe, it } from "vitest";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";

const repositoryRoot = dirname(dirname(__dirname));

const file = readFileSync(
join(repositoryRoot, "deno", "nest-land.json"),
).toString();
const config: string[][] = JSON.parse(file)?.customManagers?.map(
(manager: { matchStrings?: string[] }) => manager.matchStrings,
);

const regexps: RegExp[][] = config.map((matchStrings: string[]) =>
matchStrings.map((re) => new RegExp(re)),
);

describe("check configuration existing", () => {
it("should be array", () => {
expect(Array.isArray(config));
});
it("should be array of regexp", () => {
expectTypeOf(regexps).toEqualTypeOf<RegExp[][]>();
});
});

describe("x.nest.land for import_map", () => {
const testCases = [
{
title: "should accept x.nest.land",
input: `{
"imports": {
"sample": "https://x.nest.land/sample@0.0.1/mod.ts",
}
}`,
currentValue: "0.0.1",
depName: "sample",
},
{
title: "should accept x.nest.land with `v`",
input: `{
"imports": {
"sample": "https://x.nest.land/sample@v0.0.1/mod.ts",
}
}`,
currentValue: "v0.0.1",
depName: "sample",
},
];

for (const testCase of testCases) {
it(testCase.title, () => {
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(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
});

describe("x.nest.land for js file", () => {
const testCases = [
{
title: "should accept x.nest.land",
input: `import { sample } from "https://x.nest.land/sample@0.0.1/mod.ts";`,
currentValue: "0.0.1",
depName: "sample",
},
{
title: "should accept x.nest.land with `v`",
input: `import { sample } from "https://x.nest.land/sample@v0.0.1/mod.ts";`,
currentValue: "v0.0.1",
depName: "sample",
},
];

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[1].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(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
});

0 comments on commit 2d4a858

Please sign in to comment.