Skip to content

Commit d9c8960

Browse files
committed
fix: enforce skeleton module being installed as an exact version
1 parent 8cdb595 commit d9c8960

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
import { join } from "node:path";
2-
import { rm } from "node:fs/promises";
1+
import { dirname, join } from "node:path";
2+
import { readFileSync } from "node:fs";
3+
import { readFile, rm } from "node:fs/promises";
34
import { copy, json, pkg, type Skeleton } from "code-skeleton";
5+
6+
const ownPkg = JSON.parse(
7+
readFileSync(join(dirname(__dirname), "package.json"), { encoding: "utf8" })
8+
) as { name: string; version: string };
49

510
interface Variables {
611
dogfood?: boolean;
712
library?: boolean;
813
}
914

1015
export default async function (root: string, variables: Variables) {
16+
const actualContent = await readFile(join(root, "package.json"), { encoding: "utf8" });
17+
const actualPkg = JSON.parse(actualContent) as { name: string; dependencies?: Record<string, string> };
18+
if (actualPkg.name !== ownPkg.name && actualPkg.dependencies?.[ownPkg.name] !== ownPkg.version) {
19+
console.log(`ERROR! The dependency "${ownPkg.name}" must be set to the exact version "${ownPkg.version}"`);
20+
console.log(`Try running \`npm install --save-exact -D ${ownPkg.name}\``);
21+
process.exit(1);
22+
}
23+
1124
const csBin = variables.dogfood ? "./bin/code-skeleton.ts" : "code-skeleton";
1225
const skeleton: Skeleton = {
1326
"package.json": pkg({

0 commit comments

Comments
 (0)