mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
chore: check import map versions more strictly (#5746)
This commit is contained in:
parent
70011e9155
commit
210402c6d2
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user