chore: check import map versions more strictly (#5746)

This commit is contained in:
Yoshiya Hinosawa 2024-08-21 14:43:21 +09:00 committed by GitHub
parent 70011e9155
commit 210402c6d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,23 +1,41 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import denoJson from "../import_map.json" with { type: "json" };
import denoJson from "../deno.json" with { type: "json" };
import importMap from "../import_map.json" with { type: "json" };
import { join } from "@std/path";
const invalidEntries = [];
// deno-lint-ignore no-explicit-any
const imports = importMap.imports as any;
const denoJsonList = Promise.all(
denoJson.workspace.map((w) =>
Deno.readTextFile(join(w, "deno.json")).then(JSON.parse)
),
);
for (const [key, value] of Object.entries(denoJson.imports)) {
if (key.startsWith("@std/") && !/@\^\d+\.\d+\.\d+(?:-.+)?$/.test(value)) {
invalidEntries.push([key, value]);
let failed = false;
for (const denoJson of await denoJsonList) {
const dependency = imports[denoJson.name];
if (!dependency) {
console.warn(`No import map entry found for ${denoJson.name}`);
failed = true;
continue;
}
const correctDependency = `jsr:${denoJson.name}@^${denoJson.version}`;
if (dependency !== correctDependency) {
console.warn(
`Invalid import map entry for ${denoJson.name}: ${dependency}`,
);
console.warn(
`Expected: ${correctDependency}`,
);
failed = true;
}
}
if (invalidEntries.length > 0) {
console.log("Invalid entries found in deno.json imports:");
for (const [key, value] of invalidEntries) {
console.log(` ${key}: ${value}`);
}
console.log(
"The range part of std specifier needs to be in the form of ^x.y.z",
);
if (failed) {
Deno.exit(1);
}
console.log("ok");