Skip to content

Commit 2bad4b7

Browse files
committed
fix(spinner): replace dynamic requires with top-level imports
Replaced all dynamic require() calls for logger and debug modules with top-level imports to fix module resolution issues in CI tests on Windows. Changed: - require('./logger') → import from './logger' (top of file) - require('./debug') → import from './debug' (top of file) This fixes "Cannot find module './logger'" errors that occurred in CI when vitest ran TypeScript source files on Windows. The dynamic requires worked locally but failed in CI due to different module resolution behavior across platforms. Logger only imports types from spinner, so there's no runtime circular dependency issue with this change. Fixes test failures in #14
1 parent 35ae5bd commit 2bad4b7

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

src/spinner.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import type { Writable } from 'stream'
77

8+
import { isDebug } from './debug'
89
// Note: getAbortSignal is imported lazily to avoid circular dependencies.
910
import { getCI } from '#env/ci'
1011
import { generateSocketSpinnerFrames } from './effects/pulse-frames'
@@ -16,6 +17,12 @@ import type {
1617
} from './effects/text-shimmer'
1718
import { applyShimmer, COLOR_INHERIT, DIR_LTR } from './effects/text-shimmer'
1819
import yoctoSpinner from './external/@socketregistry/yocto-spinner'
20+
import {
21+
LOG_SYMBOLS,
22+
getDefaultLogger,
23+
incLogCallCountSymbol,
24+
lastWasBlankSymbol,
25+
} from './logger'
1926
import { hasOwn } from './objects'
2027
import { isBlankString, stringWidth } from './strings'
2128
import { getTheme } from './themes/context'
@@ -665,11 +672,6 @@ export function Spinner(options?: SpinnerOptions | undefined): Spinner {
665672
} else {
666673
super[methodName](normalized)
667674
}
668-
const {
669-
getDefaultLogger,
670-
incLogCallCountSymbol,
671-
lastWasBlankSymbol,
672-
} = /*@__PURE__*/ require('./logger')
673675
const logger = getDefaultLogger()
674676
if (methodName === 'stop') {
675677
if (wasSpinning && normalized) {
@@ -745,10 +747,6 @@ export function Spinner(options?: SpinnerOptions | undefined): Spinner {
745747
text = ''
746748
}
747749

748-
const {
749-
LOG_SYMBOLS,
750-
getDefaultLogger,
751-
} = /*@__PURE__*/ require('./logger')
752750
// Note: Status messages always go to stderr.
753751
const logger = getDefaultLogger()
754752
logger.error(`${LOG_SYMBOLS[symbolType]} ${text}`, ...extras)
@@ -775,7 +773,6 @@ export function Spinner(options?: SpinnerOptions | undefined): Spinner {
775773
* @returns This spinner for chaining
776774
*/
777775
debug(text?: string | undefined, ...extras: unknown[]) {
778-
const { isDebug } = /*@__PURE__*/ require('./debug')
779776
if (isDebug()) {
780777
return this.#showStatusAndKeepSpinning('info', [text, ...extras])
781778
}
@@ -792,7 +789,6 @@ export function Spinner(options?: SpinnerOptions | undefined): Spinner {
792789
* @returns This spinner for chaining
793790
*/
794791
debugAndStop(text?: string | undefined, ...extras: unknown[]) {
795-
const { isDebug } = /*@__PURE__*/ require('./debug')
796792
if (isDebug()) {
797793
return this.#apply('info', [text, ...extras])
798794
}
@@ -939,7 +935,6 @@ export function Spinner(options?: SpinnerOptions | undefined): Spinner {
939935
* @returns This spinner for chaining
940936
*/
941937
log(...args: unknown[]) {
942-
const { getDefaultLogger } = /*@__PURE__*/ require('./logger')
943938
const logger = getDefaultLogger()
944939
logger.log(...args)
945940
return this
@@ -1068,7 +1063,6 @@ export function Spinner(options?: SpinnerOptions | undefined): Spinner {
10681063
* ```
10691064
*/
10701065
step(text?: string | undefined, ...extras: unknown[]) {
1071-
const { getDefaultLogger } = /*@__PURE__*/ require('./logger')
10721066
if (typeof text === 'string') {
10731067
const logger = getDefaultLogger()
10741068
// Add blank line before step for visual separation.
@@ -1098,7 +1092,6 @@ export function Spinner(options?: SpinnerOptions | undefined): Spinner {
10981092
substep(text?: string | undefined, ...extras: unknown[]) {
10991093
if (typeof text === 'string') {
11001094
// Add 2-space indent for substep.
1101-
const { getDefaultLogger } = /*@__PURE__*/ require('./logger')
11021095
const logger = getDefaultLogger()
11031096
// Use error (stderr) to align with logger.substep() default stream.
11041097
logger.error(` ${text}`, ...extras)

0 commit comments

Comments
 (0)