Skip to content

Commit 2c1a6f1

Browse files
committed
✨ Replace validation - only files in project dir
1 parent 97698ff commit 2c1a6f1

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/Files.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ export class Files {
1818
public static async readUtf8File(path: string) {
1919
return fsp.readFile(path, 'utf8')
2020
}
21+
public static isInProjectDir(path: string) {
22+
path = path.normalize(path)
23+
return path.startsWith(Files.PROJECT_DIR)
24+
}
2125
}

src/StarterLoader.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import glob from 'fast-glob'
22
import fs from 'node:fs'
33
import path from 'node:path'
4+
import { Files } from './Files.js'
45

56
export interface StarterConfig {
67
module: string
@@ -105,6 +106,16 @@ export class StarterLoader {
105106
`Invalid config at ${path}: "replace" must be array of files where strings should be replaced`
106107
)
107108
}
109+
if (config.replace) {
110+
const invalidReplace = config.replace.find(
111+
(replace: string) => !Files.isInProjectDir(replace)
112+
)
113+
if (invalidReplace) {
114+
throw new Error(
115+
`Invalid config at ${path}: "replace" must be array of files in the project directory, got: ${invalidReplace}`
116+
)
117+
}
118+
}
108119

109120
const invalidKeys = Object.keys(config).filter(
110121
key => !['module', 'name', 'prebuild', 'replace', 'id'].includes(key)

0 commit comments

Comments
 (0)