Skip to content

Commit cf79673

Browse files
committed
feat: expose cwdPath property via bundler, dev-server and the test-runner
1 parent 6298cc9 commit cf79673

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

src/bundler.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import type tsStatic from 'typescript'
1313
import { cliui } from '@poppinss/cliui'
1414
import { fileURLToPath } from 'node:url'
1515
import type Hooks from '@poppinss/hooks'
16-
import { join, relative } from 'node:path'
1716
import string from '@poppinss/utils/string'
17+
import { join, relative } from 'node:path/posix'
1818
import { detectPackageManager } from '@antfu/install-pkg'
1919

2020
import type { BundlerOptions } from './types/common.ts'
@@ -62,11 +62,6 @@ export const SUPPORTED_PACKAGE_MANAGERS: {
6262
* const success = await bundler.bundle()
6363
*/
6464
export class Bundler {
65-
/**
66-
* The current working project directory path as string
67-
*/
68-
#cwdPath: string
69-
7065
/**
7166
* Reference to the TypeScript module
7267
*/
@@ -92,12 +87,17 @@ export class Bundler {
9287
/**
9388
* The current working directory URL
9489
*/
95-
public cwd: URL
90+
cwd: URL
91+
92+
/**
93+
* The current working project directory path as string
94+
*/
95+
cwdPath: string
9696

9797
/**
9898
* Bundler configuration options including hooks and meta files
9999
*/
100-
public options: BundlerOptions
100+
options: BundlerOptions
101101

102102
/**
103103
* Create a new bundler instance
@@ -109,7 +109,7 @@ export class Bundler {
109109
constructor(cwd: URL, ts: typeof tsStatic, options: BundlerOptions) {
110110
this.cwd = cwd
111111
this.options = options
112-
this.#cwdPath = fileURLToPath(this.cwd)
112+
this.cwdPath = string.toUnixSlash(fileURLToPath(this.cwd))
113113
this.#ts = ts
114114
}
115115

@@ -118,7 +118,7 @@ export class Bundler {
118118
* file path
119119
*/
120120
#getRelativeName(filePath: string) {
121-
return string.toUnixSlash(relative(this.#cwdPath, filePath))
121+
return string.toUnixSlash(relative(this.cwdPath, filePath))
122122
}
123123

124124
/**
@@ -152,14 +152,14 @@ export class Bundler {
152152
.map((file) => file.pattern)
153153
.concat(additionalFilesToCopy)
154154

155-
await copyFiles(metaFiles, this.#cwdPath, outDir)
155+
await copyFiles(metaFiles, this.cwdPath, outDir)
156156
}
157157

158158
/**
159159
* Detect the package manager used by the project
160160
*/
161161
async #detectPackageManager(): Promise<SupportedPackageManager | null> {
162-
const pkgManager = await detectPackageManager(this.#cwdPath)
162+
const pkgManager = await detectPackageManager(this.cwdPath)
163163
if (pkgManager === 'deno') {
164164
return 'npm'
165165
}

src/dev_server.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ export class DevServer {
8383
hotReloaded: false,
8484
}
8585

86-
/**
87-
* File path computed from the cwd
88-
*/
89-
#cwdPath: string
90-
9186
/**
9287
* External listeners that are invoked when child process
9388
* gets an error or closes
@@ -223,12 +218,17 @@ export class DevServer {
223218
/**
224219
* The current working directory URL
225220
*/
226-
public cwd: URL
221+
cwd: URL
222+
223+
/**
224+
* File path computed from the cwd
225+
*/
226+
cwdPath: string
227227

228228
/**
229229
* Development server configuration options including hooks and environment variables
230230
*/
231-
public options: DevServerOptions
231+
options: DevServerOptions
232232

233233
/**
234234
* Create a new DevServer instance
@@ -239,8 +239,8 @@ export class DevServer {
239239
constructor(cwd: URL, options: DevServerOptions) {
240240
this.cwd = cwd
241241
this.options = options
242-
this.#cwdPath = string.toUnixSlash(fileURLToPath(this.cwd))
243-
this.#indexGenerator = new IndexGenerator(this.#cwdPath, this.ui.logger)
242+
this.cwdPath = string.toUnixSlash(fileURLToPath(this.cwd))
243+
this.#indexGenerator = new IndexGenerator(this.cwdPath, this.ui.logger)
244244
}
245245

246246
/**
@@ -459,7 +459,7 @@ export class DevServer {
459459
this.ui.logger.info(`starting server in ${this.#mode} mode...`)
460460

461461
this.#stickyPort = String(await getPort(this.cwd))
462-
this.#fileSystem = new FileSystem(this.#cwdPath, tsConfig, this.options)
462+
this.#fileSystem = new FileSystem(this.cwdPath, tsConfig, this.options)
463463

464464
this.ui.logger.info('loading hooks...')
465465
this.#hooks = await loadHooks(this.options.hooks, [
@@ -527,7 +527,7 @@ export class DevServer {
527527
} else if (this.#mode === 'hmr' && this.#isHotHookMessage(message)) {
528528
debug('received hot-hook message %O', message)
529529
const absolutePath = message.path ? string.toUnixSlash(message.path) : ''
530-
const relativePath = relative(this.#cwdPath, absolutePath)
530+
const relativePath = relative(this.cwdPath, absolutePath)
531531

532532
if (message.type === 'hot-hook:file-changed') {
533533
const { action } = message
@@ -656,7 +656,7 @@ export class DevServer {
656656
*/
657657
this.#watcher = watch({
658658
usePolling: options?.poll ?? false,
659-
cwd: this.#cwdPath,
659+
cwd: this.cwdPath,
660660
ignoreInitial: true,
661661
ignored: (file, stats) => {
662662
if (!stats) {
@@ -689,19 +689,19 @@ export class DevServer {
689689

690690
this.#watcher.on('add', (filePath) => {
691691
const relativePath = string.toUnixSlash(filePath)
692-
const absolutePath = join(this.#cwdPath, relativePath)
692+
const absolutePath = join(this.cwdPath, relativePath)
693693
this.#hooks.runner('fileAdded').run(relativePath, absolutePath, this)
694694
})
695695
this.#watcher.on('change', (filePath) => {
696696
const relativePath = string.toUnixSlash(filePath)
697-
const absolutePath = join(this.#cwdPath, relativePath)
697+
const absolutePath = join(this.cwdPath, relativePath)
698698
this.#hooks
699699
.runner('fileChanged')
700700
.run(relativePath, absolutePath, DevServer.#WATCHER_INFO, this)
701701
})
702702
this.#watcher.on('unlink', (filePath) => {
703703
const relativePath = string.toUnixSlash(filePath)
704-
const absolutePath = join(this.#cwdPath, relativePath)
704+
const absolutePath = join(this.cwdPath, relativePath)
705705
this.#hooks.runner('fileRemoved').run(relativePath, absolutePath, this)
706706
})
707707
}

src/test_runner.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ export class TestRunner {
9595
}
9696
>
9797

98-
/**
99-
* The current working directory path as a string
100-
*/
101-
#cwdPath: string
102-
10398
/**
10499
* Index generator for managing auto-generated index files
105100
*/
@@ -145,12 +140,17 @@ export class TestRunner {
145140
/**
146141
* The current working directory URL
147142
*/
148-
public cwd: URL
143+
cwd: URL
144+
145+
/**
146+
* The current working directory path as a string
147+
*/
148+
cwdPath: string
149149

150150
/**
151151
* Test runner configuration options including filters, reporters, and hooks
152152
*/
153-
public options: TestRunnerOptions
153+
options: TestRunnerOptions
154154

155155
/**
156156
* Create a new TestRunner instance
@@ -161,8 +161,8 @@ export class TestRunner {
161161
constructor(cwd: URL, options: TestRunnerOptions) {
162162
this.cwd = cwd
163163
this.options = options
164-
this.#cwdPath = string.toUnixSlash(fileURLToPath(this.cwd))
165-
this.#indexGenerator = new IndexGenerator(this.#cwdPath, this.ui.logger)
164+
this.cwdPath = string.toUnixSlash(fileURLToPath(this.cwd))
165+
this.#indexGenerator = new IndexGenerator(this.cwdPath, this.ui.logger)
166166
}
167167

168168
/**
@@ -462,7 +462,7 @@ export class TestRunner {
462462
}
463463

464464
this.#stickyPort = String(await getPort(this.cwd))
465-
this.#fileSystem = new FileSystem(this.#cwdPath, tsConfig, {
465+
this.#fileSystem = new FileSystem(this.cwdPath, tsConfig, {
466466
...this.options,
467467
suites: this.options.suites?.filter((suite) => {
468468
if (this.options.filters.suites) {
@@ -503,7 +503,7 @@ export class TestRunner {
503503
*/
504504
this.#watcher = watch({
505505
usePolling: options?.poll ?? false,
506-
cwd: this.#cwdPath,
506+
cwd: this.cwdPath,
507507
ignoreInitial: true,
508508
ignored: (file, stats) => {
509509
if (!stats) {
@@ -536,12 +536,12 @@ export class TestRunner {
536536

537537
this.#watcher.on('add', (filePath) => {
538538
const relativePath = string.toUnixSlash(filePath)
539-
const absolutePath = join(this.#cwdPath, filePath)
539+
const absolutePath = join(this.cwdPath, filePath)
540540
this.#hooks.runner('fileAdded').run(relativePath, absolutePath, this)
541541
})
542542
this.#watcher.on('change', (filePath) => {
543543
const relativePath = string.toUnixSlash(filePath)
544-
const absolutePath = join(this.#cwdPath, filePath)
544+
const absolutePath = join(this.cwdPath, filePath)
545545
this.#hooks.runner('fileChanged').run(
546546
relativePath,
547547
absolutePath,
@@ -555,7 +555,7 @@ export class TestRunner {
555555
})
556556
this.#watcher.on('unlink', (filePath) => {
557557
const relativePath = string.toUnixSlash(filePath)
558-
const absolutePath = join(this.#cwdPath, filePath)
558+
const absolutePath = join(this.cwdPath, filePath)
559559
this.#hooks.runner('fileRemoved').run(relativePath, absolutePath, this)
560560
})
561561
}

0 commit comments

Comments
 (0)