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: support jsr #40

Merged
merged 3 commits into from
Apr 15, 2024
Merged
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
5 changes: 1 addition & 4 deletions default.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
],
"packageRules": [
{
"matchUpdateTypes": [
"minor",
"patch"
],
"matchUpdateTypes": ["minor", "patch"],
"matchCurrentVersion": "!/^0/",
"automerge": true
}
Expand Down
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//deno/deno-land",
"github>Omochice/renovate-config//deno/npm",
"github>Omochice/renovate-config//deno/github-tag",
"github>Omochice/renovate-config//deno/nest-land"
"github>Omochice/renovate-config//deno/nest-land",
"github>Omochice/renovate-config//deno/jsr"
]
}
23 changes: 23 additions & 0 deletions deno/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"customManagers": [
{
"customType": "regex",
"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-]+)*))?)?)?)[/\"']"
],
"datasourceTemplate": "npm"
},
{
"customType": "regex",
"fileMatch": ["\\.[jt]sx?$"],
"matchStrings": [
"((?:im|ex)port(?:.|\\s)+?from\\s*|//\\s*@deno-types=)['\"]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-]+)*))?)?)?)[/'\"]"
],
"datasourceTemplate": "npm",
"packageNameTemplate": "@jsr/{{namespace}}__{{package}}"
}
],
"npmrc": "@jsr:registry=https://npm.jsr.io"
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "2.1.0",
"private": true,
"description": "renovate configuration for me",
"keywords": [
"renovate"
],
"keywords": ["renovate"],
"license": "zlib",
"author": "Omochice",
"scripts": {
Expand Down
123 changes: 123 additions & 0 deletions test/deno/jsr.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
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", "jsr.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("jsr for import map", () => {
const testCases = [
{
title: "should accept jsr specifier",
input: `{
"imports": {
"@luca/flag": "jsr:@luca/flag@^1.0.1"
}
}`,
currentValue: "1.0.1",
depName: "@luca/flag",
},
] as const;

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("jsr for js file", () => {
const testCases = [
{
title: "should accept jsr specifier",
input: `import { printProgress } from "jsr:@luca/flag@1.0.1";`,
currentValue: "1.0.1",
depName: "@luca/flag",
},
{
title: "should accept version pinning(^)",
input: `import { printProgress } from "jsr:@luca/flag@^1.0.1";`,
currentValue: "1.0.1",
depName: "@luca/flag",
},
{
title: "should accept version pinning(~)",
input: `import { printProgress } from "jsr:@luca/flag@~1.0.1";`,
currentValue: "1.0.1",
depName: "@luca/flag",
},
{
title: "should accept only major version",
input: `import { printProgress } from "jsr:@luca/flag@1";`,
currentValue: "1",
depName: "@luca/flag",
},
{
title: "should accept jsr specifier in //@deno-types",
input: `// @deno-types="jsr:@luca/flag@1.0.1";`,
currentValue: "1.0.1",
depName: "@luca/flag",
},
{
title: "should accept jsr specifier in //@deno-types",
input: `// @deno-types="jsr:@luca/flag@1.0.1";`,
currentValue: "1.0.1",
depName: "@luca/flag",
},
{
title: "version pinning(^) with //@deno-types",
input: `// @deno-types="jsr:@luca/flag@^1.0.1";`,
currentValue: "1.0.1",
depName: "@luca/flag",
},
{
title: "version pinning(~) with //@deno-types",
input: `// @deno-types="jsr:@luca/flag@~1.0.1";`,
currentValue: "1.0.1",
depName: "@luca/flag",
},
{
title: "only major version with //@deno-types",
input: `// @deno-types="jsr:@luca/flag@1";`,
currentValue: "1",
depName: "@luca/flag",
},
] as const;

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);
});
}
});
Loading