Skip to content

Commit a9afce2

Browse files
committed
feat: cjs
1 parent 9875cdb commit a9afce2

File tree

13 files changed

+28
-29
lines changed

13 files changed

+28
-29
lines changed

src/cfg.ts renamed to src/cfg.cts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { existsSync, readFileSync } from 'fs'
22
import { dirname, resolve } from 'path'
3-
4-
import resolveMain from './resolve-main.js'
5-
import { Options } from './cli.js'
3+
import { type Options } from './cli.js'
4+
import { resolveMain } from './resolve-main.cjs'
65

76
const defaultConfig: Options = {
87
clear: false,

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from 'assert'
22
import { resolve } from 'path'
33
import minimist, { ParsedArgs } from 'minimist'
4-
import { getConfig } from './cfg.js'
4+
import { getConfig } from './cfg.cjs'
55

66
const arrayify = <T>(v: T | T[]) => (Array.isArray(v) ? [...v] : [v])
77
const argify = (key: string) => ({ arg: `--${key}`, key })
@@ -72,7 +72,7 @@ export interface Options {
7272
timestamp: string
7373
}
7474

75-
export default (argv: string[]) => {
75+
export const cli = (argv: string[]) => {
7676
const nodeCustomArgs = new Array<string>()
7777
const args = argv.slice(2).filter(nodeCustomFactory(nodeCustomArgs))
7878

src/entrypoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
import cli from './cli.js'
4-
import dev from './index.js'
3+
import { cli } from './cli.js'
4+
import { dev } from './index.js'
55

66
const {
77
script,

src/hook.ts renamed to src/hook.cts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import vm from 'vm'
22
import NodeModule from 'node:module'
33

4-
export default (patchVM: boolean, callback: (file: string) => void) => {
4+
export const hook = (patchVM: boolean, callback: (file: string) => void) => {
55
// Hook into Node's `require(...)`
66
updateHooks()
77

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { clearFactory } from './clear.js'
66
import { Options } from './cli.js'
77
import { FileWatcher } from './utils/filewatcher.js'
88
import { configureDeps, configureIgnore } from './ignore.js'
9-
import * as ipc from './ipc.js'
10-
import localPath from './local-path.js'
11-
import logFactory from './log.js'
12-
import notifyFactory from './notify.js'
13-
import resolveMain from './resolve-main.js'
9+
import * as ipc from './ipc.cjs'
10+
import { localPath } from './local-path.js'
11+
import { logFactory } from './log.js'
12+
import { notifyFactory } from './notify.js'
13+
import { resolveMain } from './resolve-main.cjs'
1414

15-
export default (script: string, scriptArgs: string[], nodeArgs: string[], {
15+
export const dev = (script: string, scriptArgs: string[], nodeArgs: string[], {
1616
clear,
1717
debounce,
1818
dedupe,

src/ipc.ts renamed to src/ipc.cts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChildProcess } from 'node:child_process'
1+
import { type ChildProcess } from 'node:child_process'
22

33
const cmd = 'NODE_DEV'
44

src/local-path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
import { join } from 'path'
2-
export default (f: string) => join(import.meta.dirname, f)
2+
export const localPath = (f: string) => join(import.meta.dirname, f)

src/log.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const colorOutput = (s: string, c: string) => '\x1B[' + c + 'm' + s + '\x1B[0m'
1818
* Logs a message to the console. The level is displayed in ANSI colors:
1919
* errors are bright red, warnings are yellow, and info is cyan.
2020
*/
21-
export default ({ noColor, timestamp }: { noColor?: boolean, timestamp: string }) => {
21+
export const logFactory = ({ noColor, timestamp }: { noColor?: boolean, timestamp: string }) => {
2222
const enableColor = !(noColor || !process.stdout.isTTY)
2323
const color = enableColor ? colorOutput : noop
2424

@@ -30,11 +30,11 @@ export default ({ noColor, timestamp }: { noColor?: boolean, timestamp: string }
3030
return output
3131
}
3232

33-
const logFactory = (level: typeof LOG_LEVELS[0]) =>
33+
const _logFactory = (level: typeof LOG_LEVELS[0]) =>
3434
(...args: any[]) => log(format.apply(null, args), level)
3535

3636
return LOG_LEVELS.reduce((logMap, level) => {
37-
logMap[level] = logFactory(level)
37+
logMap[level] = _logFactory(level)
3838
return logMap
3939
}, {} as Log)
4040
}

src/notify.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import notifier from 'node-notifier'
2-
import localPath from './local-path.js'
2+
import { localPath } from './local-path.js'
33
import { Log } from './log.js'
44

55
const iconLevelPath = (level: 'error' | 'info') => localPath(`../icons/node_${level}.png`)
66

77
// Writes a message to the console and optionally displays a desktop notification.
8-
export default (notifyEnabled: boolean, log: Log) => (title = 'node-dev', message: any, level: 'error' | 'info' = 'info') => {
8+
export const notifyFactory = (notifyEnabled: boolean, log: Log) => (title = 'node-dev', message: any, level: 'error' | 'info' = 'info') => {
99
log[level](`${title}: ${message}`)
1010

1111
if (notifyEnabled) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import resolve from 'resolve'
22

3-
export default (main: string) => {
3+
export const resolveMain = (main: string) => {
44
const basedir = process.cwd()
55
const paths = [basedir]
66
return resolve.sync(main, { basedir, paths })

0 commit comments

Comments
 (0)