rajt 0.0.101 → 0.0.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/auth/ability.ts +2 -2
- package/src/cli/commands/deploy.ts +1 -1
- package/src/cli/commands/dev.ts +4 -4
- package/src/cli/commands/migrate.ts +2 -2
- package/src/cli/commands/routes.ts +4 -4
- package/src/cli/index.ts +1 -1
- package/src/cli/stubs.ts +2 -2
- package/src/cli/utils.ts +6 -6
- package/src/create-app.ts +4 -4
- package/src/http.ts +3 -3
- package/src/register.ts +4 -1
- package/src/response.ts +1 -1
- package/src/routes.ts +16 -16
- package/src/utils/environment.ts +2 -2
- package/src/utils/func.ts +2 -2
- package/src/utils/log.ts +3 -3
- package/src/utils/port.ts +1 -1
- package/src/utils/resolve.ts +5 -3
package/package.json
CHANGED
package/src/auth/ability.ts
CHANGED
|
@@ -19,11 +19,11 @@ export class Ability {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
static fromAction(target: any): string {
|
|
22
|
-
return !target ? '' : this.format(typeof target
|
|
22
|
+
return !target ? '' : this.format(typeof target === 'string' ? target : (target.name.length > 3 ? target.name : (target?.p || '')))
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
static format(path: string) {
|
|
26
|
-
return path
|
|
26
|
+
return path === '/'
|
|
27
27
|
? 'index'
|
|
28
28
|
: path.normalize('NFD')
|
|
29
29
|
.replace(/[\u0300-\u036f]/g, '')
|
package/src/cli/commands/dev.ts
CHANGED
|
@@ -109,7 +109,7 @@ export default defineCommand({
|
|
|
109
109
|
|
|
110
110
|
const started = (port: number) => {
|
|
111
111
|
log(`Starting API on http://${host}:${port}`)
|
|
112
|
-
if (platform
|
|
112
|
+
if (platform === 'cf')
|
|
113
113
|
log(`Localflare on https://studio.localflare.dev`)
|
|
114
114
|
rn()
|
|
115
115
|
}
|
|
@@ -136,7 +136,7 @@ export default defineCommand({
|
|
|
136
136
|
{
|
|
137
137
|
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
138
138
|
// stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
|
|
139
|
-
shell: process.platform
|
|
139
|
+
shell: process.platform === 'win32',
|
|
140
140
|
env: {...process.env, DOCKER_HOST: getDockerHost()},
|
|
141
141
|
}
|
|
142
142
|
)
|
|
@@ -202,8 +202,8 @@ export default defineCommand({
|
|
|
202
202
|
case 'node':
|
|
203
203
|
return withPort(desiredPort, async (port) => {
|
|
204
204
|
started(port)
|
|
205
|
-
const isBun = getRuntime()
|
|
206
|
-
const isWin32 = process.platform
|
|
205
|
+
const isBun = getRuntime() === 'bun'
|
|
206
|
+
const isWin32 = process.platform === 'win32'
|
|
207
207
|
const params = isBun
|
|
208
208
|
? ['run', '--port=' + port, '--hot', '--silent', '--no-clear-screen', '--no-summary', join(_root, 'node_modules/rajt/src/dev.ts')]
|
|
209
209
|
: [join(_root, 'node_modules/.bin/tsx' + (isWin32 ? '.exe' : '')), 'watch', join(_root, 'node_modules/rajt/src/dev-node.ts')]
|
|
@@ -19,13 +19,13 @@ export default defineCommand({
|
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
21
|
async run({ args }) {
|
|
22
|
-
if (args._.length
|
|
22
|
+
if (args._.length !== 2) {
|
|
23
23
|
error('Invalid args: '+ gray('[ACTION] [DATABASE]'))
|
|
24
24
|
return rn()
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const [action, database] = args._
|
|
28
|
-
const isBun = getRuntime()
|
|
28
|
+
const isBun = getRuntime() === 'bun'
|
|
29
29
|
const isRemote = !!args?.remote
|
|
30
30
|
|
|
31
31
|
try {
|
|
@@ -46,15 +46,15 @@ export default defineCommand({
|
|
|
46
46
|
keys.add(key)
|
|
47
47
|
|
|
48
48
|
let mLength = method.length
|
|
49
|
-
if (method
|
|
49
|
+
if (method === 'GET') mLength += 5
|
|
50
50
|
|
|
51
51
|
maxMethodLength = Math.max(maxMethodLength, mLength)
|
|
52
52
|
maxPathLength = Math.max(maxPathLength, path.length)
|
|
53
53
|
|
|
54
54
|
return [
|
|
55
|
-
isMiddleware && method
|
|
55
|
+
isMiddleware && method !== 'ALL' || !isMiddleware,
|
|
56
56
|
opts.path ? path.startsWith(opts.path) : true,
|
|
57
|
-
opts.method ? method
|
|
57
|
+
opts.method ? method === opts.method : true,
|
|
58
58
|
].every(Boolean)
|
|
59
59
|
})
|
|
60
60
|
|
|
@@ -68,7 +68,7 @@ export default defineCommand({
|
|
|
68
68
|
let mLength = method.length
|
|
69
69
|
let str = highlightedMethod(method, null, true)
|
|
70
70
|
|
|
71
|
-
if (method
|
|
71
|
+
if (method === 'GET')
|
|
72
72
|
mLength += 5
|
|
73
73
|
|
|
74
74
|
console.log(str + ' '.repeat(maxMethodLength - mLength) +' '+ highlightedURI(path, method))
|
package/src/cli/index.ts
CHANGED
|
@@ -32,7 +32,7 @@ const version = [name, isColorSupported ? gray('v'+rajtVersion) : rajtVersion].j
|
|
|
32
32
|
if (directly()) {
|
|
33
33
|
const _args = process.argv.slice(2)
|
|
34
34
|
const length = _args.length
|
|
35
|
-
if (!length || (length
|
|
35
|
+
if (!length || (length === 1 && ['-v', '--version', '--v', '-version'].includes(_args[0]))) {
|
|
36
36
|
console.log(version)
|
|
37
37
|
process.exit(0)
|
|
38
38
|
}
|
package/src/cli/stubs.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export const replace = (str: string, map: Record<string, string>) => {
|
|
2
|
-
if (!str || typeof str
|
|
2
|
+
if (!str || typeof str !== 'string' || !map || typeof map !== 'object') return str
|
|
3
3
|
const entries = Object.entries(map)
|
|
4
4
|
const length = entries?.length || 0
|
|
5
5
|
if (!length) return str
|
|
6
6
|
|
|
7
7
|
str = str.trimStart()
|
|
8
|
-
if (length
|
|
8
|
+
if (length === 1)
|
|
9
9
|
return str.replaceAll(entries[0][0], entries[0][1])
|
|
10
10
|
|
|
11
11
|
return entries.reduce(
|
package/src/cli/utils.ts
CHANGED
|
@@ -44,7 +44,7 @@ export const platformError = () => error(`Provide a valid platform: ${formatArgs
|
|
|
44
44
|
|
|
45
45
|
export function getRuntime() {
|
|
46
46
|
try {
|
|
47
|
-
return process?.isBun || typeof Bun
|
|
47
|
+
return process?.isBun || typeof Bun !== 'undefined' ? 'bun' : 'node'
|
|
48
48
|
} catch {
|
|
49
49
|
return 'node'
|
|
50
50
|
}
|
|
@@ -120,7 +120,7 @@ const dist = '.rajt/dist'
|
|
|
120
120
|
export const build = async (platform: Platform, env: string = 'prd') => {
|
|
121
121
|
const startTime = Date.now()
|
|
122
122
|
|
|
123
|
-
const isCF = platform
|
|
123
|
+
const isCF = platform === 'cf'
|
|
124
124
|
cleanDir(join(_root, dist))
|
|
125
125
|
|
|
126
126
|
if (isCF) {
|
|
@@ -138,7 +138,7 @@ export const build = async (platform: Platform, env: string = 'prd') => {
|
|
|
138
138
|
const encoder = new TextEncoder()
|
|
139
139
|
|
|
140
140
|
// @ts-ignore
|
|
141
|
-
platform = platform
|
|
141
|
+
platform = platform !== 'node' ? '-'+ platform : ''
|
|
142
142
|
const opts = {
|
|
143
143
|
entryPoints: [join(_rajt, `prod${platform}.ts`)],
|
|
144
144
|
bundle: true,
|
|
@@ -258,7 +258,7 @@ export function cleanDB(key: string, config?: WranglerConfig) {
|
|
|
258
258
|
config ??= wranglerConfig()
|
|
259
259
|
if (!config?.d1_databases) return
|
|
260
260
|
for (const db of config.d1_databases) {
|
|
261
|
-
if (key
|
|
261
|
+
if (key === db.database_name || key === db.binding) {
|
|
262
262
|
const ns = 'miniflare-D1DatabaseObject'
|
|
263
263
|
const fileName = join(ns, durableObjectNamespace(db.preview_database_id || db.database_id || db.binding, ns) +'.sqlite')
|
|
264
264
|
|
|
@@ -463,7 +463,7 @@ export async function wait(ms: number) {
|
|
|
463
463
|
export function getDockerHost() {
|
|
464
464
|
const platform = process.platform
|
|
465
465
|
|
|
466
|
-
if (platform
|
|
466
|
+
if (platform === 'darwin') {
|
|
467
467
|
for (const socket of [
|
|
468
468
|
'/Users/'+ process.env.USER +'/.docker/run/docker.sock',
|
|
469
469
|
'/var/run/docker.sock',
|
|
@@ -476,7 +476,7 @@ export function getDockerHost() {
|
|
|
476
476
|
return 'tcp://localhost:2375'
|
|
477
477
|
}
|
|
478
478
|
|
|
479
|
-
return process.env.DOCKER_HOST || (platform
|
|
479
|
+
return process.env.DOCKER_HOST || (platform === 'win32' ? 'tcp://localhost:2375' : 'unix:///var/run/docker.sock')
|
|
480
480
|
}
|
|
481
481
|
|
|
482
482
|
export function makeFile(path: string, content: string) {
|
package/src/create-app.ts
CHANGED
|
@@ -21,10 +21,10 @@ const EHandler = async (e: Error | HTTPResponseError) => {
|
|
|
21
21
|
console.error(e)
|
|
22
22
|
|
|
23
23
|
switch (true) {
|
|
24
|
-
case 'status' in e && e.status
|
|
24
|
+
case 'status' in e && e.status === 401:
|
|
25
25
|
return response.unauthorized()
|
|
26
26
|
|
|
27
|
-
case 'status' in e && e.status
|
|
27
|
+
case 'status' in e && e.status === 400: // @ts-ignore
|
|
28
28
|
return response.badRequest(null, e?.message)
|
|
29
29
|
|
|
30
30
|
default:
|
|
@@ -69,13 +69,13 @@ export const createApp = <E extends Env>(options?: ServerOptions<E>) => {
|
|
|
69
69
|
if (isDev()) {
|
|
70
70
|
app.use('*', async function (c: Context, next: Next) {
|
|
71
71
|
const method = c.req.method
|
|
72
|
-
const route = matchedRoutes(c).find(route => route.method
|
|
72
|
+
const route = matchedRoutes(c).find(route => route.method === method)?.path
|
|
73
73
|
const logWithRoute = (args: string[]) => {
|
|
74
74
|
if (!route || !args.length) return args
|
|
75
75
|
return args.map(arg => {
|
|
76
76
|
if (!arg) return arg
|
|
77
77
|
const split = arg?.split(' ')
|
|
78
|
-
if (split.length < 3 || split[2]
|
|
78
|
+
if (split.length < 3 || split[2] === route)
|
|
79
79
|
return arg
|
|
80
80
|
|
|
81
81
|
split.splice(Math.min(3, split.length), 0, gray(route))
|
package/src/http.ts
CHANGED
|
@@ -29,10 +29,10 @@ export const getVerb = [
|
|
|
29
29
|
]
|
|
30
30
|
|
|
31
31
|
function method(method: string, ...args: any[]): void | ClassDecorator {
|
|
32
|
-
if (args.length
|
|
32
|
+
if (args.length === 1 && typeof args[0] === 'function')
|
|
33
33
|
return _method(method, '/', args[0])
|
|
34
34
|
|
|
35
|
-
const path = typeof args[0]
|
|
35
|
+
const path = typeof args[0] === 'string' ? args[0] : '/'
|
|
36
36
|
return (target: Function) => _method(method, path, target)
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -117,7 +117,7 @@ export function Middlewares(...handlers: MiddlewareType[]) {
|
|
|
117
117
|
export function Auth(target: Function): void
|
|
118
118
|
export function Auth(): ClassDecorator
|
|
119
119
|
export function Auth(...args: any[]): void | ClassDecorator {
|
|
120
|
-
if (args.length
|
|
120
|
+
if (args.length === 1 && typeof args[0] === 'function')
|
|
121
121
|
return _auth(args[0])
|
|
122
122
|
|
|
123
123
|
return (target: any) => _auth(target)
|
package/src/register.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { isProd } from './utils/environment'
|
|
2
|
+
const isPrd = isProd()
|
|
3
|
+
|
|
1
4
|
export const handlers: Record<string, Function> = {}
|
|
2
5
|
|
|
3
6
|
export function registerHandler(id: string, handler: any) {
|
|
@@ -6,7 +9,7 @@ export function registerHandler(id: string, handler: any) {
|
|
|
6
9
|
|
|
7
10
|
export function getHandler(id: string): Function {
|
|
8
11
|
const handler = handlers[id] || null
|
|
9
|
-
if (!handler) throw new Error(`Handler ${id} not registered`)
|
|
12
|
+
if (isPrd && !handler) throw new Error(`Handler ${id} not registered`)
|
|
10
13
|
return handler
|
|
11
14
|
}
|
|
12
15
|
|
package/src/response.ts
CHANGED
|
@@ -58,7 +58,7 @@ export default class $Response {
|
|
|
58
58
|
headers?: HeaderRecord
|
|
59
59
|
): Response | Promise<Response> {
|
|
60
60
|
const res = (html: string) => this.raw(status, html, 'text/html; charset=UTF-8' as BaseMime, headers)
|
|
61
|
-
return typeof html
|
|
61
|
+
return typeof html === 'string'
|
|
62
62
|
? res(html)
|
|
63
63
|
: resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res)
|
|
64
64
|
}
|
package/src/routes.ts
CHANGED
|
@@ -46,7 +46,7 @@ const walk = async (dir: string, baseDir: string, fn: Function, parentMw: string
|
|
|
46
46
|
|
|
47
47
|
if (stat.isDirectory()) {
|
|
48
48
|
await walk(fullPath, baseDir, fn, currentMw)
|
|
49
|
-
} else if (file
|
|
49
|
+
} else if (file !== 'index.ts' && file.endsWith('.ts') && !file.endsWith('.d.ts')) {
|
|
50
50
|
const mod = await IMPORT(fullPath)
|
|
51
51
|
fn(fullPath, baseDir, mod.default, currentMw)
|
|
52
52
|
}
|
|
@@ -56,18 +56,18 @@ const walk = async (dir: string, baseDir: string, fn: Function, parentMw: string
|
|
|
56
56
|
function isZodSchema(obj: any): obj is z.ZodType {
|
|
57
57
|
return (
|
|
58
58
|
obj &&
|
|
59
|
-
typeof obj
|
|
59
|
+
typeof obj === 'object' &&
|
|
60
60
|
('_def' in obj || '_type' in obj) &&
|
|
61
61
|
(obj.safeParse !== undefined || obj.parse !== undefined)
|
|
62
62
|
)
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
function ResolveDescribeSchema(obj: any, deep: boolean = false) {
|
|
66
|
-
if (!obj || typeof obj
|
|
66
|
+
if (!obj || typeof obj !== 'object') return obj
|
|
67
67
|
if (isZodSchema(obj))
|
|
68
68
|
return { content: {'application/json': { schema: resolver(obj as unknown as StandardSchemaV1) }} }
|
|
69
69
|
|
|
70
|
-
if (obj.content && typeof obj.content
|
|
70
|
+
if (obj.content && typeof obj.content === 'object') {
|
|
71
71
|
for (const mediaType in obj.content) {
|
|
72
72
|
const contentItem = obj.content[mediaType]
|
|
73
73
|
if (contentItem?.schema && isZodSchema(contentItem.schema))
|
|
@@ -83,7 +83,7 @@ function ResolveDescribeSchema(obj: any, deep: boolean = false) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
for (const key in obj) {
|
|
86
|
-
if (obj[key] && typeof obj[key]
|
|
86
|
+
if (obj[key] && typeof obj[key] === 'object') {
|
|
87
87
|
obj[key] = ResolveDescribeSchema(obj[key], true)
|
|
88
88
|
|
|
89
89
|
if (!deep && !obj[key]?.description) {
|
|
@@ -137,7 +137,7 @@ export async function getRoutes(
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
const mw = (handle.mw?.length ? [...handle.mw, ...middlewares] : middlewares).flatMap(obj => {
|
|
140
|
-
return typeof obj
|
|
140
|
+
return typeof obj === 'string' ? obj : obj?.name || null
|
|
141
141
|
}).filter(Boolean) as Function[]
|
|
142
142
|
|
|
143
143
|
routes.push({
|
|
@@ -193,7 +193,7 @@ function extractHttpPath(file: string) {
|
|
|
193
193
|
.map(part => part.startsWith('[') && part.endsWith(']') ? ':'+ part.slice(1, -1) : part)
|
|
194
194
|
.join('/')
|
|
195
195
|
|
|
196
|
-
return route
|
|
196
|
+
return route === '/' ? '/' : route.replace(/\/$/, '')
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
export function sortRoutes(routes: Routes) {
|
|
@@ -212,7 +212,7 @@ export function sortRoutes(routes: Routes) {
|
|
|
212
212
|
return metaB.score - metaA.score
|
|
213
213
|
})
|
|
214
214
|
|
|
215
|
-
while (list.length && list.at(-1)?.path
|
|
215
|
+
while (list.length && list.at(-1)?.path === '/') {
|
|
216
216
|
const last = list.pop()
|
|
217
217
|
last && list.unshift(last)
|
|
218
218
|
}
|
|
@@ -277,9 +277,9 @@ export async function getConfigs(
|
|
|
277
277
|
const keyPath = extractName(file).split('.')
|
|
278
278
|
|
|
279
279
|
keyPath.reduce((acc, key, index) => {
|
|
280
|
-
if (index
|
|
280
|
+
if (index === keyPath.length - 1) {
|
|
281
281
|
acc[key] = mod.default
|
|
282
|
-
} else if (!acc[key] || typeof acc[key]
|
|
282
|
+
} else if (!acc[key] || typeof acc[key] !== 'object') {
|
|
283
283
|
acc[key] = {}
|
|
284
284
|
}
|
|
285
285
|
|
|
@@ -297,15 +297,15 @@ function stringifyToJS(value: unknown): string {
|
|
|
297
297
|
|
|
298
298
|
const type = typeof value
|
|
299
299
|
|
|
300
|
-
if (type
|
|
301
|
-
if (type
|
|
302
|
-
if (type
|
|
303
|
-
if (type
|
|
300
|
+
if (type === 'string') return JSON.stringify(value)
|
|
301
|
+
if (type === 'number' || type === 'boolean') return String(value)
|
|
302
|
+
if (type === 'bigint') return `${value}n`
|
|
303
|
+
if (type === 'function') return value.toString()
|
|
304
304
|
|
|
305
305
|
if (Array.isArray(value))
|
|
306
306
|
return `[${value.map(stringifyToJS).join(',')}]`
|
|
307
307
|
|
|
308
|
-
if (type
|
|
308
|
+
if (type === 'object') {
|
|
309
309
|
const entries = Object.entries(value as Record<string, unknown>)
|
|
310
310
|
.map(([key, val]) => `${IDENTIFIER_RE.test(key) ? key : JSON.stringify(key)}:${stringifyToJS(val)}`)
|
|
311
311
|
|
|
@@ -328,7 +328,7 @@ async function dependencyPath(lib: string) {
|
|
|
328
328
|
export async function cacheRoutes() {
|
|
329
329
|
const env = Object.entries(
|
|
330
330
|
config({ path: join(_root, '.env.prod') })?.parsed || {}
|
|
331
|
-
).filter(([key, val]) => key?.toLowerCase().
|
|
331
|
+
).filter(([key, val]) => key?.toLowerCase().startsWith('aws')) // prevent AWS credentials
|
|
332
332
|
|
|
333
333
|
const version = versionSHA('../../.git') // @ts-ignore
|
|
334
334
|
env.push(['VERSION_SHA', process.env['VERSION_SHA'] = version]) // @ts-ignore
|
package/src/utils/environment.ts
CHANGED
|
@@ -2,7 +2,7 @@ const prd = Symbol('prd')
|
|
|
2
2
|
const dev = Symbol('dev')
|
|
3
3
|
|
|
4
4
|
// @ts-ignore
|
|
5
|
-
let env = process.env.RAJT_ENV ||
|
|
5
|
+
let env = process.env.RAJT_ENV || detectEnvironment()
|
|
6
6
|
|
|
7
7
|
export const getEnv = () => env // @ts-ignore
|
|
8
8
|
export const setEnv = (e: symbol) => env = e
|
|
@@ -11,7 +11,7 @@ export function detectEnvironment(): symbol {
|
|
|
11
11
|
try {
|
|
12
12
|
if (
|
|
13
13
|
process.env?.npm_lifecycle_event === 'dev'
|
|
14
|
-
|| process.env?.npm_lifecycle_script
|
|
14
|
+
|| process.env?.npm_lifecycle_script?.startsWith('rajt')
|
|
15
15
|
|| process.env?.AWS_SAM_LOCAL
|
|
16
16
|
// || process?.argv?.includes('--dev')
|
|
17
17
|
|| process?.argv?.some(arg => ['-port', '-platform', '--dev', '--development', '--watch'].includes(arg))
|
package/src/utils/func.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export const isAsyncFn = (fn: any) => {
|
|
2
|
-
return fn?.constructor?.name
|
|
2
|
+
return fn?.constructor?.name === 'AsyncFunction'
|
|
3
3
|
|| fn.toString().toLowerCase().trim().startsWith('async')
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export const isAnonFn = (fn: any) => {
|
|
7
|
-
return fn?.name
|
|
7
|
+
return fn?.name === '' || fn?.name === 'anonymous'
|
|
8
8
|
}
|
package/src/utils/log.ts
CHANGED
|
@@ -54,7 +54,7 @@ const LOGGING_METHOD = {
|
|
|
54
54
|
|
|
55
55
|
function prefixedLog(prefixType: keyof typeof prefixes, ...msg: any[]) {
|
|
56
56
|
const length = msg.length
|
|
57
|
-
if ((msg[0] === '' || msg[0] === undefined) && length
|
|
57
|
+
if ((msg[0] === '' || msg[0] === undefined) && length === 1)
|
|
58
58
|
msg.shift()
|
|
59
59
|
|
|
60
60
|
const consoleMethod: keyof typeof LOGGING_METHOD =
|
|
@@ -64,12 +64,12 @@ function prefixedLog(prefixType: keyof typeof prefixes, ...msg: any[]) {
|
|
|
64
64
|
|
|
65
65
|
const prefix = prefixes[prefixType]
|
|
66
66
|
// If there's no message, don't print the prefix but a new line
|
|
67
|
-
if (length
|
|
67
|
+
if (length === 0) {
|
|
68
68
|
console[consoleMethod]('')
|
|
69
69
|
} else {
|
|
70
70
|
// Ensure if there's ANSI escape codes it's concatenated into one string.
|
|
71
71
|
// Chrome DevTool can only handle color if it's in one string.
|
|
72
|
-
if (length
|
|
72
|
+
if (length === 1 && typeof msg[0] === 'string') {
|
|
73
73
|
console[consoleMethod](prefix +' '+ msg[0])
|
|
74
74
|
} else {
|
|
75
75
|
console[consoleMethod](prefix, ...msg)
|
package/src/utils/port.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { error, warn } from './log'
|
|
|
5
5
|
export function withPort(desiredPort: number, cb: (port: number) => void, maxAttempts = 10) {
|
|
6
6
|
getAvailablePort(desiredPort)
|
|
7
7
|
.then(([port, pid]) => {
|
|
8
|
-
if (port
|
|
8
|
+
if (port !== desiredPort)
|
|
9
9
|
warn(
|
|
10
10
|
`Port ${desiredPort} is in use by ${pid ? 'process '+ pid : 'an unknown process'}, using available port ${port} instead`
|
|
11
11
|
)
|
package/src/utils/resolve.ts
CHANGED
|
@@ -3,10 +3,12 @@ import { getHandler } from '../register'
|
|
|
3
3
|
export function resolve(...objs: any[]) {
|
|
4
4
|
const _ = []
|
|
5
5
|
for (let obj of objs) {
|
|
6
|
-
if (typeof obj
|
|
6
|
+
if (typeof obj === 'string')
|
|
7
7
|
obj = getHandler(obj)
|
|
8
8
|
|
|
9
|
-
if (
|
|
9
|
+
if (obj == null) continue
|
|
10
|
+
|
|
11
|
+
if (typeof obj === 'function' && obj?.length === 2) {
|
|
10
12
|
|
|
11
13
|
} else if (obj?.run) {
|
|
12
14
|
_.push(...obj.run())
|
|
@@ -34,7 +36,7 @@ export function resolve(...objs: any[]) {
|
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export function resolveMiddleware(obj: any) {
|
|
37
|
-
if (typeof obj
|
|
39
|
+
if (typeof obj === 'function' && obj.length === 2)
|
|
38
40
|
return obj
|
|
39
41
|
|
|
40
42
|
if (obj?.factory)
|