Skip to content

Commit ac26c70

Browse files
committed
feat: use Process.env.INIT_CWD instead of manual handling
1 parent b0e2b4b commit ac26c70

File tree

4 files changed

+4
-13
lines changed

4 files changed

+4
-13
lines changed

builder/source/build.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ export async function Build(OptionsParam?: BuildOptions): Promise<void> {
4242
}
4343
}
4444

45-
let ProjectRoot = Process.cwd()
46-
if (Process.cwd().endsWith('/builder')) {
47-
ProjectRoot = Process.cwd() + '/..'
48-
}
45+
let ProjectRoot = Process.env.INIT_CWD ? Process.env.INIT_CWD : Process.cwd()
4946

5047
const Banner = CreateBanner({
5148
Version: Options.Version ?? (await PackageJson.load(ProjectRoot)).content.version ?? '0.0.0',

builder/source/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Fs from 'node:fs'
33
import * as Process from 'node:process'
44
import { FetchAdShieldDomains } from './references/index.js'
55

6-
const CachePath = Process.cwd() + '/.buildcache'
6+
const CachePath = (Process.env.INIT_CWD ? Process.env.INIT_CWD : Process.cwd()) + '/.buildcache'
77
const CacheDomainsPath = CachePath + '/domains.json'
88

99
export function CreateCache(Domains: Set<string>) {

builder/source/debug.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import * as Fs from 'node:fs'
66
import { RunDebugServer } from './utils/http-server.js'
77
import { Build } from './build.js'
88

9-
let ProjectRoot = Process.cwd()
10-
if (Process.cwd().endsWith('/builder')) {
11-
ProjectRoot = Process.cwd().replaceAll(/\/builder$/g, '')
12-
}
9+
let ProjectRoot = Process.env.INIT_CWD ? Process.env.INIT_CWD : Process.cwd()
1310
const WatchingGlob = [];
1411
['builder/', 'userscript/', ''].forEach(Dir => {
1512
WatchingGlob.push(...Fs.globSync(`${ProjectRoot}/${Dir}source/**/*.ts`))

builder/source/utils/http-server.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ function IsLoopBack(IP: string) {
99

1010
export function RunDebugServer(Port: number, FileName: string[], ShouldPreventHTTPResponse: boolean) {
1111
const HTTPServer = HTTP.createServer((Req, Res) => {
12-
let ProjectRoot = Process.cwd()
13-
if (Process.cwd().endsWith('/builder')) {
14-
ProjectRoot = Process.cwd() + '/..'
15-
}
12+
let ProjectRoot = Process.env.INIT_CWD ? Process.env.INIT_CWD : Process.cwd()
1613
const RequestPath = Req.url?.substring(1) || ''
1714
const ResolvedPath = Path.resolve(ProjectRoot + '/dist', RequestPath)
1815
const RelativePath = Path.relative(ProjectRoot + '/dist', ResolvedPath)

0 commit comments

Comments
 (0)