plantr 1.0.1 → 2.1.0
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/LICENSE +21 -0
- package/dist/index.d.ts +23 -20
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +906 -235
- package/dist/src/cli.d.ts +23 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/create-seeder-instance.d.ts +73 -83
- package/dist/src/create-seeder-instance.d.ts.map +1 -0
- package/dist/src/define-seeder.d.ts +4 -3
- package/dist/src/define-seeder.d.ts.map +1 -0
- package/dist/src/dependency-resolver.d.ts +18 -2
- package/dist/src/dependency-resolver.d.ts.map +1 -0
- package/dist/src/formatting.d.ts +31 -12
- package/dist/src/formatting.d.ts.map +1 -0
- package/dist/src/lazy-faker.d.ts +12 -0
- package/dist/src/lazy-faker.d.ts.map +1 -0
- package/dist/src/run-seeders.d.ts +57 -17
- package/dist/src/run-seeders.d.ts.map +1 -0
- package/dist/src/seeding-state.d.ts +17 -2
- package/dist/src/seeding-state.d.ts.map +1 -0
- package/dist/src/step.d.ts +97 -15
- package/dist/src/step.d.ts.map +1 -0
- package/dist/src/types.d.ts +132 -29
- package/dist/src/types.d.ts.map +1 -0
- package/dist/state.d.ts +12 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +20 -0
- package/index.ts +60 -24
- package/package.json +20 -10
- package/readme.md +169 -49
- package/src/cli.ts +251 -0
- package/src/create-seeder-instance.ts +254 -173
- package/src/define-seeder.ts +14 -7
- package/src/dependency-resolver.ts +59 -30
- package/src/formatting.ts +142 -39
- package/src/lazy-faker.ts +46 -0
- package/src/run-seeders.ts +413 -123
- package/src/seeding-state.ts +32 -5
- package/src/step.ts +247 -46
- package/src/types.ts +184 -32
- package/state.ts +11 -0
- package/dist/cli.d.ts +0 -17
- package/dist/cli.js +0 -59
- package/dist/index-a1s5r901.js +0 -4
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { SeederAny } from './types'
|
|
1
|
+
import type { SeederAny } from './types.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Error thrown when circular dependencies are detected in seeders
|
|
5
5
|
*/
|
|
6
6
|
export class CircularDependencyError extends Error {
|
|
7
7
|
constructor(cycle: string[]) {
|
|
8
|
-
super(`Circular dependency detected in seeders: ${cycle.join(' -> ')} -> ${cycle[0]}`)
|
|
8
|
+
super(`Circular dependency detected in seeders: ${cycle.join(' -> ')} -> ${cycle[0] ?? ''}`)
|
|
9
9
|
this.name = 'CircularDependencyError'
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -20,49 +20,67 @@ export class MissingDependencyError extends Error {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Error thrown when two seeders share a name
|
|
25
|
+
*/
|
|
26
|
+
export class DuplicateSeederError extends Error {
|
|
27
|
+
constructor(name: string) {
|
|
28
|
+
super(`Two seeders are named "${name}"; seeder names must be unique`)
|
|
29
|
+
this.name = 'DuplicateSeederError'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Error thrown when a seeder is selected by a name that is not registered
|
|
35
|
+
*/
|
|
36
|
+
export class UnknownSeederError extends Error {
|
|
37
|
+
constructor(name: string, known: readonly string[]) {
|
|
38
|
+
super(`Unknown seeder "${name}". Registered seeders: ${known.join(', ') || '(none)'}`)
|
|
39
|
+
this.name = 'UnknownSeederError'
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
23
43
|
/**
|
|
24
44
|
* Resolves the execution order of seeders based on their dependencies
|
|
25
45
|
* using Kahn's algorithm (topological sort)
|
|
26
46
|
*
|
|
27
47
|
* @param seeders - Array of seeders to sort
|
|
48
|
+
* @param only - Optional names to select: returns them and everything they depend on
|
|
28
49
|
* @returns Array of seeder names in execution order
|
|
50
|
+
* @throws {DuplicateSeederError} If two seeders share a name
|
|
51
|
+
* @throws {UnknownSeederError} If a name in `only` is not registered
|
|
29
52
|
* @throws {CircularDependencyError} If circular dependencies are detected
|
|
30
53
|
* @throws {MissingDependencyError} If a seeder depends on a non-existent seeder
|
|
31
54
|
*/
|
|
32
|
-
export function resolveDependencyOrder(
|
|
55
|
+
export function resolveDependencyOrder(
|
|
56
|
+
seeders: readonly SeederAny[],
|
|
57
|
+
only?: readonly string[],
|
|
58
|
+
): string[] {
|
|
33
59
|
// Build a map of seeder names for quick lookup
|
|
34
60
|
const seederMap = new Map<string, SeederAny>()
|
|
35
61
|
for (const seeder of seeders) {
|
|
62
|
+
if (seederMap.has(seeder.name)) throw new DuplicateSeederError(seeder.name)
|
|
36
63
|
seederMap.set(seeder.name, seeder)
|
|
37
64
|
}
|
|
38
65
|
|
|
39
|
-
//
|
|
40
|
-
for (const seeder of seeders) {
|
|
41
|
-
for (const dep of seeder.dependsOn) {
|
|
42
|
-
if (!seederMap.has(dep)) {
|
|
43
|
-
throw new MissingDependencyError(seeder.name, dep)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Build adjacency list and in-degree count
|
|
66
|
+
// Build adjacency list and in-degree count (deduplicating repeated deps per seeder)
|
|
49
67
|
const inDegree = new Map<string, number>()
|
|
50
68
|
const dependents = new Map<string, string[]>()
|
|
51
69
|
|
|
52
|
-
// Initialize
|
|
53
70
|
for (const seeder of seeders) {
|
|
54
71
|
inDegree.set(seeder.name, 0)
|
|
55
72
|
dependents.set(seeder.name, [])
|
|
56
73
|
}
|
|
57
74
|
|
|
58
|
-
// Build the graph
|
|
59
75
|
for (const seeder of seeders) {
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
const uniqueDeps = new Set(seeder.dependsOn)
|
|
77
|
+
inDegree.set(seeder.name, uniqueDeps.size)
|
|
78
|
+
for (const dep of uniqueDeps) {
|
|
62
79
|
const deps = dependents.get(dep)
|
|
63
|
-
if (deps) {
|
|
64
|
-
|
|
80
|
+
if (!deps) {
|
|
81
|
+
throw new MissingDependencyError(seeder.name, dep)
|
|
65
82
|
}
|
|
83
|
+
deps.push(seeder.name)
|
|
66
84
|
}
|
|
67
85
|
}
|
|
68
86
|
|
|
@@ -74,14 +92,15 @@ export function resolveDependencyOrder(seeders: readonly SeederAny[]): string[]
|
|
|
74
92
|
}
|
|
75
93
|
}
|
|
76
94
|
|
|
77
|
-
// Process the queue
|
|
95
|
+
// Process the queue with an index pointer (O(V + E))
|
|
78
96
|
const result: string[] = []
|
|
79
|
-
|
|
80
|
-
|
|
97
|
+
let head = 0
|
|
98
|
+
while (head < queue.length) {
|
|
99
|
+
const current = queue[head++]!
|
|
81
100
|
result.push(current)
|
|
82
101
|
|
|
83
|
-
|
|
84
|
-
|
|
102
|
+
const deps = dependents.get(current)
|
|
103
|
+
if (!deps) continue
|
|
85
104
|
for (const dependent of deps) {
|
|
86
105
|
const newDegree = (inDegree.get(dependent) ?? 0) - 1
|
|
87
106
|
inDegree.set(dependent, newDegree)
|
|
@@ -93,13 +112,26 @@ export function resolveDependencyOrder(seeders: readonly SeederAny[]): string[]
|
|
|
93
112
|
|
|
94
113
|
// Check for circular dependencies
|
|
95
114
|
if (result.length !== seeders.length) {
|
|
96
|
-
|
|
97
|
-
const remaining = seeders.filter((s) => !
|
|
115
|
+
const resolved = new Set(result)
|
|
116
|
+
const remaining = seeders.filter((s) => !resolved.has(s.name))
|
|
98
117
|
const cycle = findCycle(remaining, seederMap)
|
|
99
118
|
throw new CircularDependencyError(cycle)
|
|
100
119
|
}
|
|
101
120
|
|
|
102
|
-
return result
|
|
121
|
+
if (!only) return result
|
|
122
|
+
|
|
123
|
+
// Keep the selected seeders and their transitive dependencies, in execution order
|
|
124
|
+
const selected = new Set<string>()
|
|
125
|
+
const visit = (name: string) => {
|
|
126
|
+
if (selected.has(name)) return
|
|
127
|
+
selected.add(name)
|
|
128
|
+
for (const dep of seederMap.get(name)?.dependsOn ?? []) visit(dep)
|
|
129
|
+
}
|
|
130
|
+
for (const name of only) {
|
|
131
|
+
if (!seederMap.has(name)) throw new UnknownSeederError(name, [...seederMap.keys()])
|
|
132
|
+
visit(name)
|
|
133
|
+
}
|
|
134
|
+
return result.filter((name) => selected.has(name))
|
|
103
135
|
}
|
|
104
136
|
|
|
105
137
|
/**
|
|
@@ -114,7 +146,6 @@ function findCycle(remaining: readonly SeederAny[], seederMap: Map<string, Seede
|
|
|
114
146
|
function dfs(name: string): boolean {
|
|
115
147
|
const existingIndex = path.indexOf(name)
|
|
116
148
|
if (existingIndex !== -1) {
|
|
117
|
-
// Found cycle - record where it starts
|
|
118
149
|
cycleStart = existingIndex
|
|
119
150
|
return true
|
|
120
151
|
}
|
|
@@ -142,11 +173,9 @@ function findCycle(remaining: readonly SeederAny[], seederMap: Map<string, Seede
|
|
|
142
173
|
path.length = 0
|
|
143
174
|
cycleStart = -1
|
|
144
175
|
if (dfs(seeder.name)) {
|
|
145
|
-
// Return only the cycle portion of the path
|
|
146
176
|
return cycleStart >= 0 ? path.slice(cycleStart) : path
|
|
147
177
|
}
|
|
148
178
|
}
|
|
149
179
|
|
|
150
|
-
// Fallback: just return the names of remaining seeders
|
|
151
180
|
return remaining.map((s) => s.name)
|
|
152
181
|
}
|
package/src/formatting.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SeederResult } from './types'
|
|
1
|
+
import type { SeederResult } from './types.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* ANSI color codes for terminal output
|
|
@@ -15,13 +15,21 @@ const colors = {
|
|
|
15
15
|
gray: '\x1b[90m',
|
|
16
16
|
} as const
|
|
17
17
|
|
|
18
|
-
type ColorName = 'red' | 'green' | 'yellow' | 'cyan' | 'white' | 'gray' | 'dim'
|
|
19
|
-
type StyleName = 'bold' | 'dim'
|
|
18
|
+
export type ColorName = 'red' | 'green' | 'yellow' | 'cyan' | 'white' | 'gray' | 'dim'
|
|
19
|
+
export type StyleName = 'bold' | 'dim'
|
|
20
|
+
|
|
21
|
+
function supportsColor(): boolean {
|
|
22
|
+
if (process.env.NO_COLOR !== undefined && process.env.NO_COLOR !== '') return false
|
|
23
|
+
if (process.env.FORCE_COLOR !== undefined && process.env.FORCE_COLOR !== '0') return true
|
|
24
|
+
return Boolean(process.stdout.isTTY)
|
|
25
|
+
}
|
|
20
26
|
|
|
21
27
|
/**
|
|
22
|
-
* Simple colorize function for terminal output
|
|
28
|
+
* Simple colorize function for terminal output.
|
|
29
|
+
* Respects `NO_COLOR`, `FORCE_COLOR`, and stdout TTY state.
|
|
23
30
|
*/
|
|
24
31
|
export function colorize(text: string, color: ColorName, style?: StyleName): string {
|
|
32
|
+
if (!supportsColor()) return text
|
|
25
33
|
let result = ''
|
|
26
34
|
if (style === 'bold') result += colors.bold
|
|
27
35
|
if (style === 'dim') result += colors.dim
|
|
@@ -33,7 +41,7 @@ export function colorize(text: string, color: ColorName, style?: StyleName): str
|
|
|
33
41
|
* Format duration in a human-readable way
|
|
34
42
|
*/
|
|
35
43
|
export function formatDuration(ms: number): string {
|
|
36
|
-
if (ms < 1000) return `${ms}ms`
|
|
44
|
+
if (ms < 1000) return `${Math.round(ms)}ms`
|
|
37
45
|
if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`
|
|
38
46
|
return `${(ms / 60000).toFixed(1)}m`
|
|
39
47
|
}
|
|
@@ -41,13 +49,12 @@ export function formatDuration(ms: number): string {
|
|
|
41
49
|
/**
|
|
42
50
|
* Print a formatted table of seeder results
|
|
43
51
|
*/
|
|
44
|
-
export function printResultsTable(results: SeederResult[]): void {
|
|
52
|
+
export function printResultsTable(results: readonly SeederResult[]): void {
|
|
45
53
|
if (results.length === 0) {
|
|
46
54
|
console.log('No seeders registered')
|
|
47
55
|
return
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
// Calculate column widths
|
|
51
58
|
const nameHeader = 'Seeder'
|
|
52
59
|
const statusHeader = 'Status'
|
|
53
60
|
const durationHeader = 'Duration'
|
|
@@ -55,11 +62,16 @@ export function printResultsTable(results: SeederResult[]): void {
|
|
|
55
62
|
const maxNameLen = Math.max(nameHeader.length, ...results.map((r) => r.name.length))
|
|
56
63
|
const maxStatusLen = Math.max(
|
|
57
64
|
statusHeader.length,
|
|
58
|
-
10, // "
|
|
65
|
+
10, // "⊘ Skipped" / "○ Pending" fit with padding
|
|
59
66
|
)
|
|
60
67
|
const maxDurationLen = Math.max(
|
|
61
68
|
durationHeader.length,
|
|
62
|
-
...results.map((r) =>
|
|
69
|
+
...results.map((r) => {
|
|
70
|
+
if (r.status === 'completed' || r.status === 'failed') {
|
|
71
|
+
return formatDuration(r.durationMs).length
|
|
72
|
+
}
|
|
73
|
+
return 1 // "-"
|
|
74
|
+
}),
|
|
63
75
|
)
|
|
64
76
|
|
|
65
77
|
const topBorder = `┌${'─'.repeat(maxNameLen + 2)}┬${'─'.repeat(maxStatusLen + 2)}┬${'─'.repeat(maxDurationLen + 2)}┐`
|
|
@@ -76,31 +88,29 @@ export function printResultsTable(results: SeederResult[]): void {
|
|
|
76
88
|
for (const result of results) {
|
|
77
89
|
let statusDisplay: string
|
|
78
90
|
let statusColor: ColorName
|
|
91
|
+
let duration = '-'
|
|
79
92
|
|
|
80
93
|
switch (result.status) {
|
|
81
94
|
case 'completed':
|
|
82
95
|
statusDisplay = '✓ Done'
|
|
83
96
|
statusColor = 'green'
|
|
97
|
+
duration = formatDuration(result.durationMs)
|
|
84
98
|
break
|
|
85
99
|
case 'failed':
|
|
86
100
|
statusDisplay = '✗ Failed'
|
|
87
101
|
statusColor = 'red'
|
|
102
|
+
duration = formatDuration(result.durationMs)
|
|
88
103
|
break
|
|
89
104
|
case 'skipped':
|
|
90
105
|
statusDisplay = '⊘ Skipped'
|
|
91
106
|
statusColor = 'yellow'
|
|
92
107
|
break
|
|
93
|
-
case '
|
|
94
|
-
statusDisplay = '⟳ Running'
|
|
95
|
-
statusColor = 'yellow'
|
|
96
|
-
break
|
|
97
|
-
default:
|
|
108
|
+
case 'pending':
|
|
98
109
|
statusDisplay = '○ Pending'
|
|
99
110
|
statusColor = 'gray'
|
|
111
|
+
break
|
|
100
112
|
}
|
|
101
113
|
|
|
102
|
-
const duration = result.durationMs !== undefined ? formatDuration(result.durationMs) : '-'
|
|
103
|
-
|
|
104
114
|
console.log(
|
|
105
115
|
`│ ${result.name.padEnd(maxNameLen)} │ ${colorize(statusDisplay.padEnd(maxStatusLen), statusColor)} │ ${colorize(duration.padEnd(maxDurationLen), 'dim')} │`,
|
|
106
116
|
)
|
|
@@ -110,22 +120,35 @@ export function printResultsTable(results: SeederResult[]): void {
|
|
|
110
120
|
console.log('')
|
|
111
121
|
}
|
|
112
122
|
|
|
123
|
+
const escapeAnnotation = (text: string) =>
|
|
124
|
+
text.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A')
|
|
125
|
+
|
|
113
126
|
/**
|
|
114
|
-
* Print error details for failed seeders
|
|
127
|
+
* Print error details for failed seeders: the failing step, the full error (message,
|
|
128
|
+
* stack, cause and own fields via Bun.inspect) and a hint when cached steps ran first.
|
|
129
|
+
* Under GitHub Actions, also prints one `::error` annotation per failed seeder.
|
|
115
130
|
*/
|
|
116
|
-
export function printErrors(results: SeederResult[]): void {
|
|
131
|
+
export function printErrors(results: readonly SeederResult[]): void {
|
|
117
132
|
const failed = results.filter((r) => r.status === 'failed')
|
|
118
133
|
|
|
119
134
|
for (const result of failed) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
const where = result.failedStep ? ` in step "${result.failedStep}"` : ''
|
|
136
|
+
console.log(colorize(`❌ Seeder "${result.name}" failed${where}:`, 'red'))
|
|
137
|
+
const details = Bun.inspect(result.error, { colors: supportsColor() })
|
|
138
|
+
for (const line of details.split('\n')) console.log(` ${line}`)
|
|
139
|
+
if (result.cachedSteps.length > 0) {
|
|
140
|
+
console.log(
|
|
141
|
+
colorize(
|
|
142
|
+
` ${result.cachedSteps.length} earlier step(s) came from the cache: ${result.cachedSteps.join(', ')}. If they are stale, run this seeder fresh (CLI: --only ${result.name} --fresh).`,
|
|
143
|
+
'yellow',
|
|
144
|
+
),
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
if (process.env.GITHUB_ACTIONS === 'true') {
|
|
148
|
+
const title = `Seeder ${result.name} failed${where}`.replace(/[:,]/g, ' ')
|
|
149
|
+
console.log(
|
|
150
|
+
`::error title=${escapeAnnotation(title)}::${escapeAnnotation(result.error.message || 'failed')}`,
|
|
151
|
+
)
|
|
129
152
|
}
|
|
130
153
|
console.log('')
|
|
131
154
|
}
|
|
@@ -150,7 +173,7 @@ export function printSeederHeader(
|
|
|
150
173
|
}
|
|
151
174
|
|
|
152
175
|
/**
|
|
153
|
-
* Print completion status after a seeder runs
|
|
176
|
+
* Print completion status after a seeder runs (sequential mode)
|
|
154
177
|
*/
|
|
155
178
|
export function printSeederComplete(durationMs: number, success: boolean): void {
|
|
156
179
|
console.log('')
|
|
@@ -162,18 +185,57 @@ export function printSeederComplete(durationMs: number, success: boolean): void
|
|
|
162
185
|
console.log('')
|
|
163
186
|
}
|
|
164
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Print compact prefixed completion status (concurrent mode)
|
|
190
|
+
*/
|
|
191
|
+
export function printConcurrentComplete(
|
|
192
|
+
seederName: string,
|
|
193
|
+
durationMs: number,
|
|
194
|
+
success: boolean,
|
|
195
|
+
): void {
|
|
196
|
+
const tag = colorize(`[${seederName}]`, 'cyan', 'bold')
|
|
197
|
+
if (success) {
|
|
198
|
+
console.log(` ${tag} ${colorize(`✓ Completed in ${formatDuration(durationMs)}`, 'green')}`)
|
|
199
|
+
} else {
|
|
200
|
+
console.log(` ${tag} ${colorize(`✗ Failed after ${formatDuration(durationMs)}`, 'red')}`)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Print compact prefixed skip status (concurrent mode)
|
|
206
|
+
*/
|
|
207
|
+
export function printConcurrentSkipped(seederName: string, failedDeps: readonly string[]): void {
|
|
208
|
+
const tag = colorize(`[${seederName}]`, 'cyan', 'bold')
|
|
209
|
+
console.log(
|
|
210
|
+
` ${tag} ${colorize(`⊘ Skipped (depends on failed: ${failedDeps.join(', ')})`, 'yellow')}`,
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
|
|
165
214
|
/**
|
|
166
215
|
* Print the initial banner when seeding starts
|
|
167
216
|
*/
|
|
168
|
-
export function printStartBanner(
|
|
169
|
-
|
|
170
|
-
|
|
217
|
+
export function printStartBanner(options?: {
|
|
218
|
+
name?: string | undefined
|
|
219
|
+
count?: number | undefined
|
|
220
|
+
target?: { label: string; local: boolean } | undefined
|
|
221
|
+
concurrency?: number | undefined
|
|
222
|
+
}): void {
|
|
223
|
+
const name = options?.name ?? 'Seeders'
|
|
224
|
+
const countText =
|
|
225
|
+
options?.count !== undefined
|
|
226
|
+
? ` ${colorize(`(${options.count} ${options.count === 1 ? 'seeder' : 'seeders'}${options.concurrency && options.concurrency > 1 ? `, concurrency: ${options.concurrency === Number.POSITIVE_INFINITY ? '∞' : options.concurrency}` : ''})`, 'dim')}`
|
|
227
|
+
: ''
|
|
228
|
+
const target = options?.target
|
|
229
|
+
const targetText = target
|
|
230
|
+
? ` ${colorize(`→ ${target.label}`, 'dim')}${target.local ? '' : ` ${colorize('(remote, allowed)', 'yellow')}`}`
|
|
231
|
+
: ''
|
|
232
|
+
console.log(`\n${colorize(`🌱 Running ${name}`, 'cyan', 'bold')}${countText}${targetText}\n`)
|
|
171
233
|
}
|
|
172
234
|
|
|
173
235
|
/**
|
|
174
236
|
* Print message when a seeder is skipped due to failed dependencies
|
|
175
237
|
*/
|
|
176
|
-
export function printSeederSkipped(failedDeps: string[]): void {
|
|
238
|
+
export function printSeederSkipped(failedDeps: readonly string[]): void {
|
|
177
239
|
console.log('')
|
|
178
240
|
console.log(colorize(` ⊘ Skipped (depends on failed: ${failedDeps.join(', ')})`, 'yellow'))
|
|
179
241
|
console.log('')
|
|
@@ -182,21 +244,62 @@ export function printSeederSkipped(failedDeps: string[]): void {
|
|
|
182
244
|
/**
|
|
183
245
|
* Print the final summary after all seeders complete
|
|
184
246
|
*/
|
|
185
|
-
export function printSummary(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
247
|
+
export function printSummary(
|
|
248
|
+
results: readonly SeederResult[],
|
|
249
|
+
totalDurationMs?: number,
|
|
250
|
+
concurrency = 1,
|
|
251
|
+
): void {
|
|
252
|
+
let completed = 0
|
|
253
|
+
let failed = 0
|
|
254
|
+
let skipped = 0
|
|
255
|
+
let pending = 0
|
|
256
|
+
let cachedCount = 0
|
|
257
|
+
let totalWorkMs = 0
|
|
258
|
+
|
|
259
|
+
for (const r of results) {
|
|
260
|
+
switch (r.status) {
|
|
261
|
+
case 'completed':
|
|
262
|
+
completed++
|
|
263
|
+
cachedCount += r.cachedSteps.length
|
|
264
|
+
totalWorkMs += r.durationMs
|
|
265
|
+
break
|
|
266
|
+
case 'failed':
|
|
267
|
+
failed++
|
|
268
|
+
cachedCount += r.cachedSteps.length
|
|
269
|
+
totalWorkMs += r.durationMs
|
|
270
|
+
break
|
|
271
|
+
case 'skipped':
|
|
272
|
+
skipped++
|
|
273
|
+
break
|
|
274
|
+
case 'pending':
|
|
275
|
+
pending++
|
|
276
|
+
break
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const durationSuffix =
|
|
281
|
+
totalDurationMs !== undefined ? ` in ${formatDuration(totalDurationMs)}` : ''
|
|
282
|
+
const speedupSuffix =
|
|
283
|
+
concurrency > 1 &&
|
|
284
|
+
totalDurationMs !== undefined &&
|
|
285
|
+
totalDurationMs > 0 &&
|
|
286
|
+
totalWorkMs > totalDurationMs * 1.1
|
|
287
|
+
? ` ${colorize(`(${formatDuration(totalWorkMs)} work, ${(totalWorkMs / totalDurationMs).toFixed(1)}× faster)`, 'dim')}`
|
|
288
|
+
: ''
|
|
289
|
+
const cacheSuffix =
|
|
290
|
+
cachedCount > 0
|
|
291
|
+
? ` ${colorize(`(${cachedCount} cached ${cachedCount === 1 ? 'step' : 'steps'})`, 'cyan')}`
|
|
292
|
+
: ''
|
|
190
293
|
|
|
191
294
|
if (failed > 0 || skipped > 0) {
|
|
192
295
|
const parts = [`${completed} completed`]
|
|
193
296
|
if (failed > 0) parts.push(`${failed} failed`)
|
|
194
297
|
if (skipped > 0) parts.push(`${skipped} skipped`)
|
|
195
298
|
if (pending > 0) parts.push(`${pending} pending`)
|
|
196
|
-
console.log(colorize(`Seeding failed: ${parts.join(', ')}`, 'red'))
|
|
299
|
+
console.log(colorize(`Seeding failed: ${parts.join(', ')}${durationSuffix}`, 'red'))
|
|
197
300
|
} else {
|
|
198
301
|
console.log(
|
|
199
|
-
`${colorize('✓ Seeding complete:', 'green')} ${completed} seeders executed successfully\n`,
|
|
302
|
+
`${colorize('✓ Seeding complete:', 'green')} ${completed} ${completed === 1 ? 'seeder' : 'seeders'} executed successfully${durationSuffix}${speedupSuffix}${cacheSuffix}\n`,
|
|
200
303
|
)
|
|
201
304
|
}
|
|
202
305
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
2
|
+
import type { Faker } from '@faker-js/faker'
|
|
3
|
+
|
|
4
|
+
let loadedFaker: Faker | undefined
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Synchronously load the default English Faker instance on first access.
|
|
8
|
+
* Defers the ~35ms locale initialization cost until a seeder actually uses `faker`.
|
|
9
|
+
*/
|
|
10
|
+
export function getDefaultFaker(): Faker {
|
|
11
|
+
if (!loadedFaker) {
|
|
12
|
+
const req = createRequire(import.meta.url)
|
|
13
|
+
const mod = req('@faker-js/faker/locale/en') as { faker: Faker }
|
|
14
|
+
loadedFaker = mod.faker
|
|
15
|
+
}
|
|
16
|
+
return loadedFaker
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Lazy proxy for the default English Faker instance.
|
|
21
|
+
* Importing `plantr` does not pay the faker load cost until a property is accessed.
|
|
22
|
+
*/
|
|
23
|
+
export const lazyFaker: Faker = new Proxy({} as Faker, {
|
|
24
|
+
get(_target, prop) {
|
|
25
|
+
const instance = getDefaultFaker()
|
|
26
|
+
const value = Reflect.get(instance, prop, instance)
|
|
27
|
+
return typeof value === 'function' && prop !== 'constructor' ? value.bind(instance) : value
|
|
28
|
+
},
|
|
29
|
+
set(_target, prop, value) {
|
|
30
|
+
const instance = getDefaultFaker()
|
|
31
|
+
return Reflect.set(instance, prop, value, instance)
|
|
32
|
+
},
|
|
33
|
+
has(_target, prop) {
|
|
34
|
+
return Reflect.has(getDefaultFaker(), prop)
|
|
35
|
+
},
|
|
36
|
+
ownKeys() {
|
|
37
|
+
return Reflect.ownKeys(getDefaultFaker())
|
|
38
|
+
},
|
|
39
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
40
|
+
const desc = Reflect.getOwnPropertyDescriptor(getDefaultFaker(), prop)
|
|
41
|
+
return desc ? { ...desc, configurable: true } : undefined
|
|
42
|
+
},
|
|
43
|
+
getPrototypeOf() {
|
|
44
|
+
return Reflect.getPrototypeOf(getDefaultFaker())
|
|
45
|
+
},
|
|
46
|
+
})
|