@absterr/nestkit 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,61 @@
1
+ import { MODULE_SYSTEMS, RUNNERS, } from "./options.js";
2
+ // Prettier is shared by the eslint and oxlint paths
3
+ const CODE_QUALITY_OVERLAYS = {
4
+ biome: ["code-quality/biome"],
5
+ eslint: ["code-quality/prettier", "code-quality/eslint"],
6
+ oxlint: ["code-quality/prettier", "code-quality/oxlint"],
7
+ none: [],
8
+ };
9
+ // Runners that ship their own eslint.config.mjs
10
+ const ESLINT_VARIANTS = new Set(["jest", "vitest"]);
11
+ // Variant overlays live inside their parent overlay's folder
12
+ const eslintVariant = (r) => `test-runners/${r}/eslint-${r}`;
13
+ const supertestVariant = (r) => `e2e-tests/supertest/${r}-supertest`;
14
+ const seleniumVariant = (r) => `e2e-tests/selenium/${r}-selenium`;
15
+ // Mocha is configured differently per module system, so it has a folder for each
16
+ const mochaUnit = (m) => `unit-tests/mocha/${m}-mocha`;
17
+ const mochaConfig = (m) => `e2e-tests/runner-configs/mocha/${m}-mocha`;
18
+ // Runner config for e2e tests
19
+ const e2eConfig = (r, m) => r === "mocha" ? mochaConfig(m) : `e2e-tests/runner-configs/${r}`;
20
+ // The parent overlay must not copy these along with its own files
21
+ export const NESTED_OVERLAYS = [
22
+ ...RUNNERS.flatMap((r) => [
23
+ eslintVariant(r),
24
+ supertestVariant(r),
25
+ seleniumVariant(r),
26
+ ]),
27
+ ...MODULE_SYSTEMS.flatMap((m) => [mochaUnit(m), mochaConfig(m)]),
28
+ ];
29
+ // Overlays apply in order, so later ones overwrite earlier files
30
+ export function overlaysFor(s) {
31
+ const runner = s.unitTests !== "none" ? s.unitTests : s.e2eRunner;
32
+ const overlays = [];
33
+ overlays.push(`versions/${s.nest}`, ...CODE_QUALITY_OVERLAYS[s.codeQuality]);
34
+ if (runner) {
35
+ overlays.push("test-runners/common", `test-runners/${runner}`);
36
+ if (s.codeQuality === "eslint" && ESLINT_VARIANTS.has(runner)) {
37
+ overlays.push(eslintVariant(runner));
38
+ }
39
+ }
40
+ if (s.unitTests !== "none") {
41
+ overlays.push("unit-tests/common", `unit-tests/${s.unitTests}`);
42
+ if (s.unitTests === "mocha")
43
+ overlays.push(mochaUnit(s.moduleSystem));
44
+ }
45
+ if (s.e2e === "supertest" && runner) {
46
+ overlays.push("e2e-tests/supertest", supertestVariant(runner), e2eConfig(runner, s.moduleSystem));
47
+ }
48
+ if (s.e2e === "selenium" && runner) {
49
+ overlays.push("e2e-tests/e2e-scripts", "e2e-tests/selenium", seleniumVariant(runner), e2eConfig(runner, s.moduleSystem));
50
+ }
51
+ if (s.e2e === "playwright" || s.e2e === "cypress") {
52
+ overlays.push("e2e-tests/e2e-scripts", `e2e-tests/${s.e2e}`);
53
+ }
54
+ if (s.env !== "none") {
55
+ overlays.push("environment/common", `environment/${s.env}`);
56
+ }
57
+ if (s.agentFiles) {
58
+ overlays.push("agent-files/common", `agent-files/${s.nest}`);
59
+ }
60
+ return overlays;
61
+ }
package/dist/rules.js ADDED
@@ -0,0 +1,19 @@
1
+ import { RUNNERS, } from "./options.js";
2
+ export const needsRunner = (e2e) => e2e === "supertest" || e2e === "selenium";
3
+ // Runners that work for a Nest version and module system
4
+ export function runnersFor(nest, moduleSystem) {
5
+ return nest === "11" && moduleSystem === "cjs"
6
+ ? [...RUNNERS]
7
+ : ["vitest", "mocha"];
8
+ }
9
+ // Runner that gets the "recommended" hint in prompts
10
+ export const recommendedRunner = (nest, moduleSystem) => (nest === "11" && moduleSystem === "cjs" ? "jest" : "vitest");
11
+ // What nest new picks for each Nest version
12
+ export const recommendedModuleSystem = (nest) => nest === "11" ? "cjs" : "esm";
13
+ export const recommendedCodeQuality = (nest) => nest === "11" ? "eslint" : "oxlint";
14
+ // Packages TypeScript 6 must load for each runner's globals
15
+ export const RUNNER_TYPES = {
16
+ jest: ["jest"],
17
+ vitest: [],
18
+ mocha: ["mocha"],
19
+ };
@@ -0,0 +1,30 @@
1
+ import { readdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { readJson, writeJson } from "./json.js";
4
+ // ESM needs explicit extensions on relative imports. Templates are written without them.
5
+ export function rewriteRelativeImports(target) {
6
+ for (const rel of readdirSync(target, {
7
+ recursive: true,
8
+ encoding: "utf8",
9
+ })) {
10
+ if (!rel.endsWith(".ts"))
11
+ continue;
12
+ const file = path.join(target, rel);
13
+ const src = readFileSync(file, "utf8");
14
+ const out = src
15
+ .replace(/(\bfrom\s+")(\.{1,2}\/[^"]+?)(?<!\.js)"/g, '$1$2.js"')
16
+ .replace(/from "supertest\/types"/g, 'from "supertest/types.js"');
17
+ if (out !== src)
18
+ writeFileSync(file, out);
19
+ }
20
+ }
21
+ // TypeScript 6 loads only the @types packages listed in `types`
22
+ export function addTsconfigTypes(target, types) {
23
+ const file = path.join(target, "tsconfig.json");
24
+ const tsconfig = readJson(file);
25
+ const current = tsconfig.compilerOptions?.types;
26
+ if (!current || types.length === 0)
27
+ return;
28
+ tsconfig.compilerOptions.types = [...new Set([...current, ...types])];
29
+ writeJson(file, tsconfig);
30
+ }
@@ -0,0 +1,44 @@
1
+ import { appendFileSync, cpSync, existsSync, readFileSync, renameSync, writeFileSync, } from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { NESTED_OVERLAYS } from "../overlays.js";
5
+ import { mergePackageJson } from "./package-json.js";
6
+ const TEMPLATES = fileURLToPath(new URL("../../templates", import.meta.url));
7
+ const EXEC = {
8
+ npm: "npx",
9
+ pnpm: "pnpm exec",
10
+ yarn: "yarn",
11
+ bun: "bunx",
12
+ };
13
+ function fill(file, tokens) {
14
+ let text = readFileSync(file, "utf8");
15
+ for (const [key, value] of Object.entries(tokens)) {
16
+ text = text.replaceAll(`{{${key}}}`, value);
17
+ }
18
+ writeFileSync(file, text);
19
+ }
20
+ export function copyBase(target, projectName, pm) {
21
+ cpSync(path.join(TEMPLATES, "base"), target, { recursive: true });
22
+ // npm strips .gitignore from published packages, so it ships as "gitignore"
23
+ for (const name of ["gitignore", "gitattributes"]) {
24
+ renameSync(path.join(target, name), path.join(target, `.${name}`));
25
+ }
26
+ fill(path.join(target, "package.json"), { projectName });
27
+ fill(path.join(target, "README.md"), { pm, exec: EXEC[pm] });
28
+ }
29
+ // Copies the overlay's files, merges its package.json fragment and appends its gitignore
30
+ export function applyOverlay(name, target) {
31
+ const dir = path.join(TEMPLATES, name);
32
+ const fragment = path.join(dir, "package.json");
33
+ const ignore = path.join(dir, "gitignore");
34
+ const nested = NESTED_OVERLAYS.map((n) => path.join(TEMPLATES, n)).filter((n) => n.startsWith(dir + path.sep));
35
+ cpSync(dir, target, {
36
+ recursive: true,
37
+ filter: (src) => src !== fragment && src !== ignore && !nested.includes(src),
38
+ });
39
+ if (existsSync(fragment))
40
+ mergePackageJson(target, fragment);
41
+ if (existsSync(ignore)) {
42
+ appendFileSync(path.join(target, ".gitignore"), readFileSync(ignore, "utf8"));
43
+ }
44
+ }
@@ -0,0 +1,24 @@
1
+ import { overlaysFor } from "../overlays.js";
2
+ import { RUNNER_TYPES } from "../rules.js";
3
+ import { addTsconfigTypes, rewriteRelativeImports } from "./esm.js";
4
+ import { applyOverlay, copyBase } from "./files.js";
5
+ import { pnpmMajor } from "./install.js";
6
+ import { approveBuildScripts, enableEsm, targetNestMajor, trustBuildScripts, } from "./package-json.js";
7
+ // Writes the project files. No prompts, no install, no git
8
+ export function scaffoldProject(target, projectName, pm, s) {
9
+ copyBase(target, projectName, pm);
10
+ for (const overlay of overlaysFor(s))
11
+ applyOverlay(overlay, target);
12
+ const runner = s.unitTests !== "none" ? s.unitTests : s.e2eRunner;
13
+ if (runner)
14
+ addTsconfigTypes(target, RUNNER_TYPES[runner]);
15
+ targetNestMajor(target, s.nest);
16
+ if (pm === "pnpm")
17
+ approveBuildScripts(target, pnpmMajor(target));
18
+ if (pm === "bun")
19
+ trustBuildScripts(target);
20
+ if (s.moduleSystem === "esm") {
21
+ enableEsm(target);
22
+ rewriteRelativeImports(target);
23
+ }
24
+ }
@@ -0,0 +1,33 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ export function install(pm, cwd) {
5
+ const result = spawnSync(pm, ["install"], {
6
+ cwd,
7
+ stdio: "inherit",
8
+ shell: process.platform === "win32",
9
+ });
10
+ return result.status === 0;
11
+ }
12
+ export function pnpmMajor(cwd) {
13
+ const result = spawnSync("pnpm", ["--version"], {
14
+ cwd,
15
+ encoding: "utf8",
16
+ shell: process.platform === "win32",
17
+ });
18
+ return Number.parseInt(result.stdout, 10);
19
+ }
20
+ const git = (cwd, ...args) => spawnSync("git", args, { cwd, stdio: "ignore" }).status === 0;
21
+ export function gitInstalled() {
22
+ return git(process.cwd(), "--version");
23
+ }
24
+ // The target may not exist yet, so check from its nearest existing parent
25
+ export function insideGitRepo(target) {
26
+ let dir = target;
27
+ while (!existsSync(dir))
28
+ dir = path.dirname(dir);
29
+ return git(dir, "rev-parse", "--is-inside-work-tree");
30
+ }
31
+ export function initGit(cwd) {
32
+ return git(cwd, "init");
33
+ }
@@ -0,0 +1,4 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ export const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
3
+ export const readJson = (file) => JSON.parse(readFileSync(file, "utf8"));
4
+ export const writeJson = (file, data) => writeFileSync(file, `${JSON.stringify(data, null, 2)}\n`);
@@ -0,0 +1,62 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { RANGES } from "../versions.js";
4
+ import { isObject, readJson, writeJson } from "./json.js";
5
+ const sortKeys = (obj) => Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
6
+ const pkgFile = (target) => path.join(target, "package.json");
7
+ // Objects merge per key, everything else (arrays included) is replaced
8
+ export function mergePackageJson(target, fragmentPath) {
9
+ const pkg = readJson(pkgFile(target));
10
+ const fragment = readJson(fragmentPath);
11
+ for (const [key, value] of Object.entries(fragment)) {
12
+ pkg[key] = isObject(value) ? { ...pkg[key], ...value } : value;
13
+ }
14
+ for (const key of ["dependencies", "devDependencies"]) {
15
+ if (pkg[key])
16
+ pkg[key] = sortKeys(pkg[key]);
17
+ }
18
+ writeJson(pkgFile(target), pkg);
19
+ }
20
+ // Point the Nest-owned packages at the chosen major
21
+ export function targetNestMajor(target, nest) {
22
+ const pkg = readJson(pkgFile(target));
23
+ for (const field of ["dependencies", "devDependencies"]) {
24
+ for (const [name, range] of Object.entries(RANGES[nest])) {
25
+ if (pkg[field]?.[name])
26
+ pkg[field][name] = range;
27
+ }
28
+ }
29
+ writeJson(pkgFile(target), pkg);
30
+ }
31
+ export function enableEsm(target) {
32
+ const pkg = readJson(pkgFile(target));
33
+ pkg.type = "module";
34
+ writeJson(pkgFile(target), pkg);
35
+ }
36
+ // pnpm 10+ and bun skip dependency install scripts and fail the install unless approved
37
+ const BUILD_SCRIPT_PACKAGES = ["@swc/core", "cypress"];
38
+ const buildScriptPackages = (pkg) => BUILD_SCRIPT_PACKAGES.filter((name) => pkg.dependencies?.[name] || pkg.devDependencies?.[name]);
39
+ export function approveBuildScripts(target, major) {
40
+ const pkg = readJson(pkgFile(target));
41
+ const needed = buildScriptPackages(pkg);
42
+ if (needed.length === 0)
43
+ return;
44
+ if (major === 10) {
45
+ pkg.pnpm = { ...pkg.pnpm, onlyBuiltDependencies: needed };
46
+ writeJson(pkgFile(target), pkg);
47
+ }
48
+ else if (major >= 11) {
49
+ const entries = needed.map((name) => ` "${name}": true`).join("\n");
50
+ writeFileSync(path.join(target, "pnpm-workspace.yaml"), `allowBuilds:\n${entries}\n`);
51
+ }
52
+ }
53
+ export function trustBuildScripts(target) {
54
+ const pkg = readJson(pkgFile(target));
55
+ const needed = buildScriptPackages(pkg);
56
+ if (needed.length === 0)
57
+ return;
58
+ pkg.trustedDependencies = [
59
+ ...new Set([...(pkg.trustedDependencies ?? []), ...needed]),
60
+ ];
61
+ writeJson(pkgFile(target), pkg);
62
+ }
package/dist/ui.js ADDED
@@ -0,0 +1,24 @@
1
+ import * as p from "@clack/prompts";
2
+ export function fail(message) {
3
+ p.cancel(message);
4
+ process.exit(1);
5
+ }
6
+ export function ensure(value) {
7
+ if (p.isCancel(value))
8
+ fail("Cancelled.");
9
+ return value;
10
+ }
11
+ export function oneOf(flag, value, valid) {
12
+ const match = valid.find((v) => v === value);
13
+ if (!match)
14
+ fail(`Invalid --${flag} "${value}". Use: ${valid.join(", ")}`);
15
+ return match;
16
+ }
17
+ // Skip flag wins, then the yes flag, then the default when there is no TTY, then ask
18
+ export async function decide(yes, skip, message) {
19
+ if (skip)
20
+ return false;
21
+ if (yes || !process.stdin.isTTY)
22
+ return true;
23
+ return ensure(await p.confirm({ message, initialValue: true }));
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absterr/nestkit",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Scaffold NestJS projects with your own stack",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/absterr/nestkit/issues"
11
11
  },
12
- "homepage": "https://github.com/absterr/nestkit#readme",
12
+ "homepage": "https://docs-nestkit.vercel.app",
13
13
  "keywords": [
14
14
  "nestjs",
15
15
  "nest",
@@ -36,6 +36,10 @@
36
36
  "scripts": {
37
37
  "build": "tsc",
38
38
  "dev": "tsc --watch",
39
+ "check": "biome check",
40
+ "check:fix": "biome check --write",
41
+ "test": "vitest run",
42
+ "test:watch": "vitest",
39
43
  "check:templates": "node scripts/check-templates.mjs",
40
44
  "prepack": "npm run build && npm run check:templates"
41
45
  },
@@ -43,7 +47,9 @@
43
47
  "@clack/prompts": "^1.9.0"
44
48
  },
45
49
  "devDependencies": {
50
+ "@biomejs/biome": "^2.6.9",
46
51
  "@types/node": "^22.20.5",
47
- "typescript": "^6.0.3"
52
+ "typescript": "^6.0.3",
53
+ "vitest": "^5.1.2"
48
54
  }
49
55
  }
@@ -13,15 +13,15 @@
13
13
  "start:debug": "nest start --debug --watch"
14
14
  },
15
15
  "dependencies": {
16
- "@nestjs/common": "^11.0.1",
17
- "@nestjs/core": "^11.0.1",
18
- "@nestjs/platform-express": "^11.0.1",
16
+ "@nestjs/common": "*",
17
+ "@nestjs/core": "*",
18
+ "@nestjs/platform-express": "*",
19
19
  "reflect-metadata": "^0.2.2",
20
20
  "rxjs": "^7.8.1"
21
21
  },
22
22
  "devDependencies": {
23
- "@nestjs/cli": "^11.0.0",
24
- "@nestjs/schematics": "^11.0.0",
23
+ "@nestjs/cli": "*",
24
+ "@nestjs/schematics": "*",
25
25
  "@types/express": "^5.0.0",
26
26
  "@types/node": "^22.10.7",
27
27
  "ts-loader": "^9.5.2",
@@ -2,6 +2,6 @@
2
2
  "semi": true,
3
3
  "singleQuote": false,
4
4
  "tabWidth": 2,
5
- "trailingComma": "es5",
5
+ "trailingComma": "all",
6
6
  "printWidth": 80
7
7
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "dependencies": {
3
- "@nestjs/config": "^4.0.4"
3
+ "@nestjs/config": "*"
4
4
  }
5
5
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "devDependencies": {
3
- "@nestjs/testing": "^11.0.1"
3
+ "@nestjs/testing": "*"
4
4
  }
5
5
  }
package/dist/scaffold.js DELETED
@@ -1,158 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
- import { appendFileSync, cpSync, existsSync, readFileSync, readdirSync, renameSync, writeFileSync, } from "node:fs";
3
- import path from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- import { NESTED_OVERLAYS } from "./options.js";
6
- import { RANGES } from "./versions.js";
7
- const TEMPLATES = fileURLToPath(new URL("../templates", import.meta.url));
8
- const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
9
- const sortKeys = (obj) => Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
10
- const EXEC = {
11
- npm: "npx",
12
- pnpm: "pnpm exec",
13
- yarn: "yarn",
14
- bun: "bunx",
15
- };
16
- function fill(file, tokens) {
17
- let text = readFileSync(file, "utf8");
18
- for (const [key, value] of Object.entries(tokens)) {
19
- text = text.replaceAll(`{{${key}}}`, value);
20
- }
21
- writeFileSync(file, text);
22
- }
23
- export function copyBase(target, projectName, pm) {
24
- cpSync(path.join(TEMPLATES, "base"), target, { recursive: true });
25
- // npm strips .gitignore from published packages, so it ships as "gitignore"
26
- for (const name of ["gitignore", "gitattributes"]) {
27
- renameSync(path.join(target, name), path.join(target, `.${name}`));
28
- }
29
- fill(path.join(target, "package.json"), { projectName });
30
- fill(path.join(target, "README.md"), { pm, exec: EXEC[pm] });
31
- }
32
- // Copies the overlay's files, merges its package.json fragment and appends its gitignore
33
- export function applyOverlay(name, target) {
34
- const dir = path.join(TEMPLATES, name);
35
- const fragment = path.join(dir, "package.json");
36
- const ignore = path.join(dir, "gitignore");
37
- const nested = NESTED_OVERLAYS.map((n) => path.join(TEMPLATES, n)).filter((n) => n.startsWith(dir + path.sep));
38
- cpSync(dir, target, {
39
- recursive: true,
40
- filter: (src) => src !== fragment && src !== ignore && !nested.includes(src),
41
- });
42
- if (existsSync(fragment))
43
- mergePackageJson(target, fragment);
44
- if (existsSync(ignore)) {
45
- appendFileSync(path.join(target, ".gitignore"), readFileSync(ignore, "utf8"));
46
- }
47
- }
48
- function mergePackageJson(target, fragmentPath) {
49
- const pkgPath = path.join(target, "package.json");
50
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
51
- const fragment = JSON.parse(readFileSync(fragmentPath, "utf8"));
52
- for (const [key, value] of Object.entries(fragment)) {
53
- pkg[key] = isObject(value) ? { ...pkg[key], ...value } : value;
54
- }
55
- for (const key of ["dependencies", "devDependencies"]) {
56
- if (pkg[key])
57
- pkg[key] = sortKeys(pkg[key]);
58
- }
59
- writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
60
- }
61
- // Templates are authored for Nest 11. Point the Nest-owned packages at the chosen major.
62
- export function retargetNest(target, nest) {
63
- const pkgPath = path.join(target, "package.json");
64
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
65
- for (const field of ["dependencies", "devDependencies"]) {
66
- for (const [name, range] of Object.entries(RANGES[nest])) {
67
- if (pkg[field]?.[name])
68
- pkg[field][name] = range;
69
- }
70
- }
71
- writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
72
- }
73
- // ESM needs explicit extensions on relative imports. Templates are written without them.
74
- export function rewriteRelativeImports(target) {
75
- for (const rel of readdirSync(target, {
76
- recursive: true,
77
- encoding: "utf8",
78
- })) {
79
- if (!rel.endsWith(".ts"))
80
- continue;
81
- const file = path.join(target, rel);
82
- const src = readFileSync(file, "utf8");
83
- const out = src
84
- .replace(/(\bfrom\s+")(\.{1,2}\/[^"]+?)(?<!\.js)"/g, '$1$2.js"')
85
- .replace(/from "supertest\/types"/g, 'from "supertest/types.js"');
86
- if (out !== src)
87
- writeFileSync(file, out);
88
- }
89
- }
90
- // TypeScript 6 loads only the @types packages listed in `types`.
91
- export function addTsconfigTypes(target, types) {
92
- const file = path.join(target, "tsconfig.json");
93
- const tsconfig = JSON.parse(readFileSync(file, "utf8"));
94
- const current = tsconfig.compilerOptions?.types;
95
- if (!current || types.length === 0)
96
- return;
97
- tsconfig.compilerOptions.types = [...new Set([...current, ...types])];
98
- writeFileSync(file, `${JSON.stringify(tsconfig, null, 2)}\n`);
99
- }
100
- export function install(pm, cwd) {
101
- const result = spawnSync(pm, ["install"], {
102
- cwd,
103
- stdio: "inherit",
104
- shell: process.platform === "win32",
105
- });
106
- return result.status === 0;
107
- }
108
- const git = (cwd, ...args) => spawnSync("git", args, { cwd, stdio: "ignore" }).status === 0;
109
- export function gitInstalled() {
110
- return git(process.cwd(), "--version");
111
- }
112
- // The target may not exist yet, so check from its nearest existing parent
113
- export function insideGitRepo(target) {
114
- let dir = target;
115
- while (!existsSync(dir))
116
- dir = path.dirname(dir);
117
- return git(dir, "rev-parse", "--is-inside-work-tree");
118
- }
119
- export function initGit(cwd) {
120
- return git(cwd, "init");
121
- }
122
- // >=pnpm 10 and bun skip dependency install scripts and fail the install unless approved
123
- const BUILD_SCRIPT_PACKAGES = ["@swc/core", "cypress"];
124
- const buildScriptPackages = (pkg) => BUILD_SCRIPT_PACKAGES.filter((name) => pkg.dependencies?.[name] || pkg.devDependencies?.[name]);
125
- export function pnpmMajor(cwd) {
126
- const result = spawnSync("pnpm", ["--version"], {
127
- cwd,
128
- encoding: "utf8",
129
- shell: process.platform === "win32",
130
- });
131
- return Number.parseInt(result.stdout, 10);
132
- }
133
- export function approveBuildScripts(target, major) {
134
- const pkgPath = path.join(target, "package.json");
135
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
136
- const needed = buildScriptPackages(pkg);
137
- if (needed.length === 0)
138
- return;
139
- if (major === 10) {
140
- pkg.pnpm = { ...pkg.pnpm, onlyBuiltDependencies: needed };
141
- writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
142
- }
143
- else if (major >= 11) {
144
- const entries = needed.map((name) => ` "${name}": true`).join("\n");
145
- writeFileSync(path.join(target, "pnpm-workspace.yaml"), `allowBuilds:\n${entries}\n`);
146
- }
147
- }
148
- export function trustBuildScripts(target) {
149
- const pkgPath = path.join(target, "package.json");
150
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
151
- const needed = buildScriptPackages(pkg);
152
- if (needed.length === 0)
153
- return;
154
- pkg.trustedDependencies = [
155
- ...new Set([...(pkg.trustedDependencies ?? []), ...needed]),
156
- ];
157
- writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
158
- }
@@ -1,7 +0,0 @@
1
- {
2
- "devDependencies": {
3
- "ts-loader": "^9.5.2",
4
- "ts-node": "^10.9.2",
5
- "tsconfig-paths": "^4.2.0"
6
- }
7
- }
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }