nuxt-processor 0.0.12 → 0.0.14
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/README.md +9 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/module.cjs +94 -93
- package/dist/module.json +1 -1
- package/dist/module.mjs +96 -95
- package/dist/runtime/server/utils/workers.d.ts +1 -1
- package/dist/shared/{nuxt-processor.XeX-J1zD.cjs → nuxt-processor.B8GgoFqc.cjs} +1 -1
- package/dist/shared/{nuxt-processor.Bp92mFhC.mjs → nuxt-processor.C2dSAYu4.mjs} +1 -1
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -20,6 +20,14 @@ Note: This package is under very active development! Please consider creating is
|
|
|
20
20
|
- **Scalability**: Run multiple worker processes and instances across machines.
|
|
21
21
|
- **Simple DX**: Define queues/workers using first-class helpers.
|
|
22
22
|
|
|
23
|
+
## Used by
|
|
24
|
+
|
|
25
|
+
<div>
|
|
26
|
+
<a href="https://getminds.ai/" target="_blank" rel="noreferrer">
|
|
27
|
+
<img src="https://media.licdn.com/dms/image/v2/D4D0BAQFsL_KsNSWwow/company-logo_200_200/B4DZvtmrYRJQAI-/0/1769217898466/mindsaicompany_logo?e=1771459200&v=beta&t=FRLR2608GdLLgD9dIPqIs8wtdk-_ZAG_bWahup1kTr4" alt="Minds AI" height="72" />
|
|
28
|
+
</a>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
23
31
|
## Sections
|
|
24
32
|
|
|
25
33
|
- [Install](#install)
|
|
@@ -33,7 +41,7 @@ Note: This package is under very active development! Please consider creating is
|
|
|
33
41
|
## Install
|
|
34
42
|
|
|
35
43
|
```bash
|
|
36
|
-
npx nuxi@latest module add nuxt-processor
|
|
44
|
+
npx nuxi@latest module add nuxt-processor@latest
|
|
37
45
|
```
|
|
38
46
|
|
|
39
47
|
Add the module in `nuxt.config.ts` and set your Redis connection.
|
package/dist/cli.cjs
CHANGED
|
@@ -8,7 +8,7 @@ const pathe = require('pathe');
|
|
|
8
8
|
const consola = require('consola');
|
|
9
9
|
const citty = require('citty');
|
|
10
10
|
const kit = require('@nuxt/kit');
|
|
11
|
-
const _package = require('./shared/nuxt-processor.
|
|
11
|
+
const _package = require('./shared/nuxt-processor.B8GgoFqc.cjs');
|
|
12
12
|
|
|
13
13
|
const ensureNuxtProject = async (args) => {
|
|
14
14
|
const dir = pathe.resolve(args.dir);
|
package/dist/cli.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { resolve } from 'pathe';
|
|
|
6
6
|
import { consola } from 'consola';
|
|
7
7
|
import { createMain, defineCommand } from 'citty';
|
|
8
8
|
import { loadNuxtConfig } from '@nuxt/kit';
|
|
9
|
-
import { v as version, d as description, n as name } from './shared/nuxt-processor.
|
|
9
|
+
import { v as version, d as description, n as name } from './shared/nuxt-processor.C2dSAYu4.mjs';
|
|
10
10
|
|
|
11
11
|
const ensureNuxtProject = async (args) => {
|
|
12
12
|
const dir = resolve(args.dir);
|
package/dist/module.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const kit = require('@nuxt/kit');
|
|
4
|
-
const _package = require('./shared/nuxt-processor.
|
|
4
|
+
const _package = require('./shared/nuxt-processor.B8GgoFqc.cjs');
|
|
5
5
|
const node_path = require('node:path');
|
|
6
6
|
const fg = require('fast-glob');
|
|
7
7
|
|
|
@@ -24,6 +24,98 @@ const scanFolder = async (path) => {
|
|
|
24
24
|
return files;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
function generateWorkersEntryContent(workerFiles, redisInline) {
|
|
28
|
+
const toImportArray = workerFiles.map((id) => `() => import(${JSON.stringify(id)})`).join(",\n ");
|
|
29
|
+
return `
|
|
30
|
+
import { fileURLToPath } from 'node:url'
|
|
31
|
+
import { resolve as resolvePath } from 'node:path'
|
|
32
|
+
import { consola } from 'consola'
|
|
33
|
+
import { $workers } from '#processor-utils'
|
|
34
|
+
|
|
35
|
+
// Initialize connection as early as possible so any imports that register
|
|
36
|
+
// workers/queues have a valid connection available.
|
|
37
|
+
const api = $workers()
|
|
38
|
+
api.setConnection(${redisInline})
|
|
39
|
+
|
|
40
|
+
export async function createWorkersApp() {
|
|
41
|
+
// Avoid EPIPE when stdout/stderr are closed by terminal (e.g., Ctrl+C piping)
|
|
42
|
+
const handleStreamError = (err) => {
|
|
43
|
+
try {
|
|
44
|
+
const code = (typeof err === 'object' && err && 'code' in err) ? err.code : null
|
|
45
|
+
if (code === 'EPIPE') return
|
|
46
|
+
} catch (e) { console.warn?.('nuxt-processor: stream error inspection failed', e) }
|
|
47
|
+
throw err
|
|
48
|
+
}
|
|
49
|
+
try { process.stdout?.on?.('error', handleStreamError) } catch (err) { console.warn('nuxt-processor: failed to attach stdout error handler', err) }
|
|
50
|
+
try { process.stderr?.on?.('error', handleStreamError) } catch (err) { console.warn('nuxt-processor: failed to attach stderr error handler', err) }
|
|
51
|
+
const modules = [
|
|
52
|
+
${toImportArray}
|
|
53
|
+
]
|
|
54
|
+
for (const loader of modules) {
|
|
55
|
+
await loader()
|
|
56
|
+
}
|
|
57
|
+
const logger = consola.create({}).withTag('nuxt-processor')
|
|
58
|
+
try {
|
|
59
|
+
const workerNames = Array.isArray(api.workers) ? api.workers.map(w => w && w.name).filter(Boolean) : []
|
|
60
|
+
logger.info('starting workers:\\n' + workerNames.map(n => ' - ' + n).join('\\n'))
|
|
61
|
+
for (const w of api.workers) {
|
|
62
|
+
w.on('error', (err) => logger.error('worker error', err))
|
|
63
|
+
}
|
|
64
|
+
// Explicitly start workers since autorun is disabled
|
|
65
|
+
for (const w of api.workers) {
|
|
66
|
+
try {
|
|
67
|
+
// run() returns a promise that resolves when the worker stops; do not await to avoid blocking
|
|
68
|
+
// eslint-disable-next-line promise/catch-or-return
|
|
69
|
+
w.run().catch((err) => logger.error('worker run error', err))
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
logger.error('failed to start worker', err)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
logger.success('workers started')
|
|
76
|
+
} catch (err) {
|
|
77
|
+
logger.error('failed to initialize workers', err)
|
|
78
|
+
}
|
|
79
|
+
return { stop: api.stopAll, workers: api.workers }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const isMain = (() => {
|
|
83
|
+
try {
|
|
84
|
+
if (typeof process === 'undefined' || !process.argv || !process.argv[1]) return false
|
|
85
|
+
const argvPath = resolvePath(process.cwd?.() || '.', process.argv[1])
|
|
86
|
+
const filePath = fileURLToPath(import.meta.url)
|
|
87
|
+
return filePath === argvPath
|
|
88
|
+
} catch {
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
})()
|
|
92
|
+
if (isMain) {
|
|
93
|
+
const logger = consola.create({}).withTag('nuxt-processor')
|
|
94
|
+
const appPromise = createWorkersApp().catch((err) => {
|
|
95
|
+
logger.error('failed to start workers', err)
|
|
96
|
+
process.exit(1)
|
|
97
|
+
})
|
|
98
|
+
const shutdown = async () => {
|
|
99
|
+
try { logger.info('closing workers...') } catch (err) { console.warn('nuxt-processor: failed to log shutdown start', err) }
|
|
100
|
+
try {
|
|
101
|
+
const app = await appPromise
|
|
102
|
+
try {
|
|
103
|
+
const names = (app?.workers || []).map(w => w && w.name).filter(Boolean)
|
|
104
|
+
logger.info('closing workers:\\n' + names.map(n => ' - ' + n).join('\\n'))
|
|
105
|
+
} catch (eL) { console.warn('nuxt-processor: failed to log workers list on shutdown', eL) }
|
|
106
|
+
await app.stop()
|
|
107
|
+
try { logger.success('workers closed') } catch (err2) { console.warn('nuxt-processor: failed to log shutdown complete', err2) }
|
|
108
|
+
}
|
|
109
|
+
finally { process.exit(0) }
|
|
110
|
+
}
|
|
111
|
+
;['SIGINT','SIGTERM','SIGQUIT'].forEach(sig => process.on(sig, shutdown))
|
|
112
|
+
process.on('beforeExit', shutdown)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export default { createWorkersApp }
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
|
|
27
119
|
const module$1 = kit.defineNuxtModule({
|
|
28
120
|
meta: {
|
|
29
121
|
name: _package.name,
|
|
@@ -64,97 +156,6 @@ const module$1 = kit.defineNuxtModule({
|
|
|
64
156
|
getContents: () => nitroPlugin
|
|
65
157
|
});
|
|
66
158
|
kit.addServerPlugin(tpl.dst);
|
|
67
|
-
function generateWorkersEntryContent(workerFiles) {
|
|
68
|
-
const toImportArray = workerFiles.map((id) => `() => import(${JSON.stringify(id)})`).join(",\n ");
|
|
69
|
-
return `
|
|
70
|
-
import { fileURLToPath } from 'node:url'
|
|
71
|
-
import { resolve as resolvePath } from 'node:path'
|
|
72
|
-
import { consola } from 'consola'
|
|
73
|
-
import { $workers } from '#processor-utils'
|
|
74
|
-
|
|
75
|
-
// Initialize connection as early as possible so any imports that register
|
|
76
|
-
// workers/queues have a valid connection available.
|
|
77
|
-
const api = $workers()
|
|
78
|
-
api.setConnection(${redisInline})
|
|
79
|
-
|
|
80
|
-
export async function createWorkersApp() {
|
|
81
|
-
// Avoid EPIPE when stdout/stderr are closed by terminal (e.g., Ctrl+C piping)
|
|
82
|
-
const handleStreamError = (err) => {
|
|
83
|
-
try {
|
|
84
|
-
const code = (typeof err === 'object' && err && 'code' in err) ? err.code : null
|
|
85
|
-
if (code === 'EPIPE') return
|
|
86
|
-
} catch (e) { console.warn?.('nuxt-processor: stream error inspection failed', e) }
|
|
87
|
-
throw err
|
|
88
|
-
}
|
|
89
|
-
try { process.stdout?.on?.('error', handleStreamError) } catch (err) { console.warn('nuxt-processor: failed to attach stdout error handler', err) }
|
|
90
|
-
try { process.stderr?.on?.('error', handleStreamError) } catch (err) { console.warn('nuxt-processor: failed to attach stderr error handler', err) }
|
|
91
|
-
const modules = [
|
|
92
|
-
${toImportArray}
|
|
93
|
-
]
|
|
94
|
-
for (const loader of modules) {
|
|
95
|
-
await loader()
|
|
96
|
-
}
|
|
97
|
-
const logger = consola.create({}).withTag('nuxt-processor')
|
|
98
|
-
try {
|
|
99
|
-
const workerNames = Array.isArray(api.workers) ? api.workers.map(w => w && w.name).filter(Boolean) : []
|
|
100
|
-
logger.info('starting workers:\\n' + workerNames.map(n => ' - ' + n).join('\\n'))
|
|
101
|
-
for (const w of api.workers) {
|
|
102
|
-
w.on('error', (err) => logger.error('worker error', err))
|
|
103
|
-
}
|
|
104
|
-
// Explicitly start workers since autorun is disabled
|
|
105
|
-
for (const w of api.workers) {
|
|
106
|
-
try {
|
|
107
|
-
// run() returns a promise that resolves when the worker stops; do not await to avoid blocking
|
|
108
|
-
// eslint-disable-next-line promise/catch-or-return
|
|
109
|
-
w.run().catch((err) => logger.error('worker run error', err))
|
|
110
|
-
}
|
|
111
|
-
catch (err) {
|
|
112
|
-
logger.error('failed to start worker', err)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
logger.success('workers started')
|
|
116
|
-
} catch (err) {
|
|
117
|
-
logger.error('failed to initialize workers', err)
|
|
118
|
-
}
|
|
119
|
-
return { stop: api.stopAll, workers: api.workers }
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const isMain = (() => {
|
|
123
|
-
try {
|
|
124
|
-
if (typeof process === 'undefined' || !process.argv || !process.argv[1]) return false
|
|
125
|
-
const argvPath = resolvePath(process.cwd?.() || '.', process.argv[1])
|
|
126
|
-
const filePath = fileURLToPath(import.meta.url)
|
|
127
|
-
return filePath === argvPath
|
|
128
|
-
} catch {
|
|
129
|
-
return false
|
|
130
|
-
}
|
|
131
|
-
})()
|
|
132
|
-
if (isMain) {
|
|
133
|
-
const logger = consola.create({}).withTag('nuxt-processor')
|
|
134
|
-
const appPromise = createWorkersApp().catch((err) => {
|
|
135
|
-
logger.error('failed to start workers', err)
|
|
136
|
-
process.exit(1)
|
|
137
|
-
})
|
|
138
|
-
const shutdown = async () => {
|
|
139
|
-
try { logger.info('closing workers...') } catch (err) { console.warn('nuxt-processor: failed to log shutdown start', err) }
|
|
140
|
-
try {
|
|
141
|
-
const app = await appPromise
|
|
142
|
-
try {
|
|
143
|
-
const names = (app?.workers || []).map(w => w && w.name).filter(Boolean)
|
|
144
|
-
logger.info('closing workers:\\n' + names.map(n => ' - ' + n).join('\\n'))
|
|
145
|
-
} catch (eL) { console.warn('nuxt-processor: failed to log workers list on shutdown', eL) }
|
|
146
|
-
await app.stop()
|
|
147
|
-
try { logger.success('workers closed') } catch (err2) { console.warn('nuxt-processor: failed to log shutdown complete', err2) }
|
|
148
|
-
}
|
|
149
|
-
finally { process.exit(0) }
|
|
150
|
-
}
|
|
151
|
-
;['SIGINT','SIGTERM','SIGQUIT'].forEach(sig => process.on(sig, shutdown))
|
|
152
|
-
process.on('beforeExit', shutdown)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export default { createWorkersApp }
|
|
156
|
-
`;
|
|
157
|
-
}
|
|
158
159
|
nuxt.options.alias = nuxt.options.alias ?? {};
|
|
159
160
|
nuxt.options.alias["nuxt-processor"] = resolve("./runtime/server/handlers");
|
|
160
161
|
nuxt.options.alias["#processor"] = resolve("./runtime/server/handlers");
|
|
@@ -196,7 +197,7 @@ declare module '#bullmq' {
|
|
|
196
197
|
virtualCode = "";
|
|
197
198
|
return;
|
|
198
199
|
}
|
|
199
|
-
virtualCode = generateWorkersEntryContent(workerFiles);
|
|
200
|
+
virtualCode = generateWorkersEntryContent(workerFiles, redisInline);
|
|
200
201
|
for (const id of workerFiles) {
|
|
201
202
|
this.addWatchFile(id);
|
|
202
203
|
}
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useNuxt, createResolver, defineNuxtModule, addTemplate, addServerPlugin, addTypeTemplate } from '@nuxt/kit';
|
|
2
|
-
import { c as configKey, a as compatibility, v as version, n as name } from './shared/nuxt-processor.
|
|
2
|
+
import { c as configKey, a as compatibility, v as version, n as name } from './shared/nuxt-processor.C2dSAYu4.mjs';
|
|
3
3
|
import { relative } from 'node:path';
|
|
4
4
|
import fg from 'fast-glob';
|
|
5
5
|
|
|
@@ -17,7 +17,99 @@ const scanFolder = async (path) => {
|
|
|
17
17
|
return files;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
function generateWorkersEntryContent(workerFiles, redisInline) {
|
|
21
|
+
const toImportArray = workerFiles.map((id) => `() => import(${JSON.stringify(id)})`).join(",\n ");
|
|
22
|
+
return `
|
|
23
|
+
import { fileURLToPath } from 'node:url'
|
|
24
|
+
import { resolve as resolvePath } from 'node:path'
|
|
25
|
+
import { consola } from 'consola'
|
|
26
|
+
import { $workers } from '#processor-utils'
|
|
27
|
+
|
|
28
|
+
// Initialize connection as early as possible so any imports that register
|
|
29
|
+
// workers/queues have a valid connection available.
|
|
30
|
+
const api = $workers()
|
|
31
|
+
api.setConnection(${redisInline})
|
|
32
|
+
|
|
33
|
+
export async function createWorkersApp() {
|
|
34
|
+
// Avoid EPIPE when stdout/stderr are closed by terminal (e.g., Ctrl+C piping)
|
|
35
|
+
const handleStreamError = (err) => {
|
|
36
|
+
try {
|
|
37
|
+
const code = (typeof err === 'object' && err && 'code' in err) ? err.code : null
|
|
38
|
+
if (code === 'EPIPE') return
|
|
39
|
+
} catch (e) { console.warn?.('nuxt-processor: stream error inspection failed', e) }
|
|
40
|
+
throw err
|
|
41
|
+
}
|
|
42
|
+
try { process.stdout?.on?.('error', handleStreamError) } catch (err) { console.warn('nuxt-processor: failed to attach stdout error handler', err) }
|
|
43
|
+
try { process.stderr?.on?.('error', handleStreamError) } catch (err) { console.warn('nuxt-processor: failed to attach stderr error handler', err) }
|
|
44
|
+
const modules = [
|
|
45
|
+
${toImportArray}
|
|
46
|
+
]
|
|
47
|
+
for (const loader of modules) {
|
|
48
|
+
await loader()
|
|
49
|
+
}
|
|
50
|
+
const logger = consola.create({}).withTag('nuxt-processor')
|
|
51
|
+
try {
|
|
52
|
+
const workerNames = Array.isArray(api.workers) ? api.workers.map(w => w && w.name).filter(Boolean) : []
|
|
53
|
+
logger.info('starting workers:\\n' + workerNames.map(n => ' - ' + n).join('\\n'))
|
|
54
|
+
for (const w of api.workers) {
|
|
55
|
+
w.on('error', (err) => logger.error('worker error', err))
|
|
56
|
+
}
|
|
57
|
+
// Explicitly start workers since autorun is disabled
|
|
58
|
+
for (const w of api.workers) {
|
|
59
|
+
try {
|
|
60
|
+
// run() returns a promise that resolves when the worker stops; do not await to avoid blocking
|
|
61
|
+
// eslint-disable-next-line promise/catch-or-return
|
|
62
|
+
w.run().catch((err) => logger.error('worker run error', err))
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
logger.error('failed to start worker', err)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
logger.success('workers started')
|
|
69
|
+
} catch (err) {
|
|
70
|
+
logger.error('failed to initialize workers', err)
|
|
71
|
+
}
|
|
72
|
+
return { stop: api.stopAll, workers: api.workers }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const isMain = (() => {
|
|
76
|
+
try {
|
|
77
|
+
if (typeof process === 'undefined' || !process.argv || !process.argv[1]) return false
|
|
78
|
+
const argvPath = resolvePath(process.cwd?.() || '.', process.argv[1])
|
|
79
|
+
const filePath = fileURLToPath(import.meta.url)
|
|
80
|
+
return filePath === argvPath
|
|
81
|
+
} catch {
|
|
82
|
+
return false
|
|
83
|
+
}
|
|
84
|
+
})()
|
|
85
|
+
if (isMain) {
|
|
86
|
+
const logger = consola.create({}).withTag('nuxt-processor')
|
|
87
|
+
const appPromise = createWorkersApp().catch((err) => {
|
|
88
|
+
logger.error('failed to start workers', err)
|
|
89
|
+
process.exit(1)
|
|
90
|
+
})
|
|
91
|
+
const shutdown = async () => {
|
|
92
|
+
try { logger.info('closing workers...') } catch (err) { console.warn('nuxt-processor: failed to log shutdown start', err) }
|
|
93
|
+
try {
|
|
94
|
+
const app = await appPromise
|
|
95
|
+
try {
|
|
96
|
+
const names = (app?.workers || []).map(w => w && w.name).filter(Boolean)
|
|
97
|
+
logger.info('closing workers:\\n' + names.map(n => ' - ' + n).join('\\n'))
|
|
98
|
+
} catch (eL) { console.warn('nuxt-processor: failed to log workers list on shutdown', eL) }
|
|
99
|
+
await app.stop()
|
|
100
|
+
try { logger.success('workers closed') } catch (err2) { console.warn('nuxt-processor: failed to log shutdown complete', err2) }
|
|
101
|
+
}
|
|
102
|
+
finally { process.exit(0) }
|
|
103
|
+
}
|
|
104
|
+
;['SIGINT','SIGTERM','SIGQUIT'].forEach(sig => process.on(sig, shutdown))
|
|
105
|
+
process.on('beforeExit', shutdown)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default { createWorkersApp }
|
|
109
|
+
`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const module$1 = defineNuxtModule({
|
|
21
113
|
meta: {
|
|
22
114
|
name,
|
|
23
115
|
version,
|
|
@@ -57,97 +149,6 @@ const module = defineNuxtModule({
|
|
|
57
149
|
getContents: () => nitroPlugin
|
|
58
150
|
});
|
|
59
151
|
addServerPlugin(tpl.dst);
|
|
60
|
-
function generateWorkersEntryContent(workerFiles) {
|
|
61
|
-
const toImportArray = workerFiles.map((id) => `() => import(${JSON.stringify(id)})`).join(",\n ");
|
|
62
|
-
return `
|
|
63
|
-
import { fileURLToPath } from 'node:url'
|
|
64
|
-
import { resolve as resolvePath } from 'node:path'
|
|
65
|
-
import { consola } from 'consola'
|
|
66
|
-
import { $workers } from '#processor-utils'
|
|
67
|
-
|
|
68
|
-
// Initialize connection as early as possible so any imports that register
|
|
69
|
-
// workers/queues have a valid connection available.
|
|
70
|
-
const api = $workers()
|
|
71
|
-
api.setConnection(${redisInline})
|
|
72
|
-
|
|
73
|
-
export async function createWorkersApp() {
|
|
74
|
-
// Avoid EPIPE when stdout/stderr are closed by terminal (e.g., Ctrl+C piping)
|
|
75
|
-
const handleStreamError = (err) => {
|
|
76
|
-
try {
|
|
77
|
-
const code = (typeof err === 'object' && err && 'code' in err) ? err.code : null
|
|
78
|
-
if (code === 'EPIPE') return
|
|
79
|
-
} catch (e) { console.warn?.('nuxt-processor: stream error inspection failed', e) }
|
|
80
|
-
throw err
|
|
81
|
-
}
|
|
82
|
-
try { process.stdout?.on?.('error', handleStreamError) } catch (err) { console.warn('nuxt-processor: failed to attach stdout error handler', err) }
|
|
83
|
-
try { process.stderr?.on?.('error', handleStreamError) } catch (err) { console.warn('nuxt-processor: failed to attach stderr error handler', err) }
|
|
84
|
-
const modules = [
|
|
85
|
-
${toImportArray}
|
|
86
|
-
]
|
|
87
|
-
for (const loader of modules) {
|
|
88
|
-
await loader()
|
|
89
|
-
}
|
|
90
|
-
const logger = consola.create({}).withTag('nuxt-processor')
|
|
91
|
-
try {
|
|
92
|
-
const workerNames = Array.isArray(api.workers) ? api.workers.map(w => w && w.name).filter(Boolean) : []
|
|
93
|
-
logger.info('starting workers:\\n' + workerNames.map(n => ' - ' + n).join('\\n'))
|
|
94
|
-
for (const w of api.workers) {
|
|
95
|
-
w.on('error', (err) => logger.error('worker error', err))
|
|
96
|
-
}
|
|
97
|
-
// Explicitly start workers since autorun is disabled
|
|
98
|
-
for (const w of api.workers) {
|
|
99
|
-
try {
|
|
100
|
-
// run() returns a promise that resolves when the worker stops; do not await to avoid blocking
|
|
101
|
-
// eslint-disable-next-line promise/catch-or-return
|
|
102
|
-
w.run().catch((err) => logger.error('worker run error', err))
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
logger.error('failed to start worker', err)
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
logger.success('workers started')
|
|
109
|
-
} catch (err) {
|
|
110
|
-
logger.error('failed to initialize workers', err)
|
|
111
|
-
}
|
|
112
|
-
return { stop: api.stopAll, workers: api.workers }
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const isMain = (() => {
|
|
116
|
-
try {
|
|
117
|
-
if (typeof process === 'undefined' || !process.argv || !process.argv[1]) return false
|
|
118
|
-
const argvPath = resolvePath(process.cwd?.() || '.', process.argv[1])
|
|
119
|
-
const filePath = fileURLToPath(import.meta.url)
|
|
120
|
-
return filePath === argvPath
|
|
121
|
-
} catch {
|
|
122
|
-
return false
|
|
123
|
-
}
|
|
124
|
-
})()
|
|
125
|
-
if (isMain) {
|
|
126
|
-
const logger = consola.create({}).withTag('nuxt-processor')
|
|
127
|
-
const appPromise = createWorkersApp().catch((err) => {
|
|
128
|
-
logger.error('failed to start workers', err)
|
|
129
|
-
process.exit(1)
|
|
130
|
-
})
|
|
131
|
-
const shutdown = async () => {
|
|
132
|
-
try { logger.info('closing workers...') } catch (err) { console.warn('nuxt-processor: failed to log shutdown start', err) }
|
|
133
|
-
try {
|
|
134
|
-
const app = await appPromise
|
|
135
|
-
try {
|
|
136
|
-
const names = (app?.workers || []).map(w => w && w.name).filter(Boolean)
|
|
137
|
-
logger.info('closing workers:\\n' + names.map(n => ' - ' + n).join('\\n'))
|
|
138
|
-
} catch (eL) { console.warn('nuxt-processor: failed to log workers list on shutdown', eL) }
|
|
139
|
-
await app.stop()
|
|
140
|
-
try { logger.success('workers closed') } catch (err2) { console.warn('nuxt-processor: failed to log shutdown complete', err2) }
|
|
141
|
-
}
|
|
142
|
-
finally { process.exit(0) }
|
|
143
|
-
}
|
|
144
|
-
;['SIGINT','SIGTERM','SIGQUIT'].forEach(sig => process.on(sig, shutdown))
|
|
145
|
-
process.on('beforeExit', shutdown)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export default { createWorkersApp }
|
|
149
|
-
`;
|
|
150
|
-
}
|
|
151
152
|
nuxt.options.alias = nuxt.options.alias ?? {};
|
|
152
153
|
nuxt.options.alias["nuxt-processor"] = resolve("./runtime/server/handlers");
|
|
153
154
|
nuxt.options.alias["#processor"] = resolve("./runtime/server/handlers");
|
|
@@ -189,7 +190,7 @@ declare module '#bullmq' {
|
|
|
189
190
|
virtualCode = "";
|
|
190
191
|
return;
|
|
191
192
|
}
|
|
192
|
-
virtualCode = generateWorkersEntryContent(workerFiles);
|
|
193
|
+
virtualCode = generateWorkersEntryContent(workerFiles, redisInline);
|
|
193
194
|
for (const id of workerFiles) {
|
|
194
195
|
this.addWatchFile(id);
|
|
195
196
|
}
|
|
@@ -234,4 +235,4 @@ process.on('beforeExit', () => shutdown('beforeExit'))
|
|
|
234
235
|
}
|
|
235
236
|
});
|
|
236
237
|
|
|
237
|
-
export { module as default };
|
|
238
|
+
export { module$1 as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-processor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Nuxt Processor",
|
|
5
5
|
"repository": "https://github.com/aidanhibbard/nuxt-processor",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"dev": "npm run dev:prepare && nuxi dev playground",
|
|
36
36
|
"dev:build": "nuxi build playground",
|
|
37
37
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
38
|
-
"ci:dev:build": "npm run dev:prepare && cd playground && npm i && cd ../ && npm run dev:build",
|
|
39
38
|
"release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
40
39
|
"lint": "eslint .",
|
|
41
40
|
"test": "vitest run",
|
|
@@ -47,13 +46,13 @@
|
|
|
47
46
|
"vp:preview": "vitepress preview docs"
|
|
48
47
|
},
|
|
49
48
|
"dependencies": {
|
|
50
|
-
"@nuxt/kit": "^4.0
|
|
51
|
-
"bullmq": "^5.
|
|
52
|
-
"citty": "^0.
|
|
53
|
-
"consola": "^3.2
|
|
49
|
+
"@nuxt/kit": "^4.3.0",
|
|
50
|
+
"bullmq": "^5.67.2",
|
|
51
|
+
"citty": "^0.2.0",
|
|
52
|
+
"consola": "^3.4.2",
|
|
54
53
|
"fast-glob": "^3.3.3",
|
|
55
|
-
"ioredis": "^5.
|
|
56
|
-
"pathe": "^
|
|
54
|
+
"ioredis": "^5.9.2",
|
|
55
|
+
"pathe": "^2.0.3"
|
|
57
56
|
},
|
|
58
57
|
"devDependencies": {
|
|
59
58
|
"@nuxt/devtools": "^2.6.3",
|
|
@@ -66,7 +65,7 @@
|
|
|
66
65
|
"@vitest/coverage-v8": "^3.2.4",
|
|
67
66
|
"changelogen": "^0.6.2",
|
|
68
67
|
"eslint": "^9.34.0",
|
|
69
|
-
"happy-dom": "^
|
|
68
|
+
"happy-dom": "^20.0.11",
|
|
70
69
|
"nuxt": "^4.0.3",
|
|
71
70
|
"typescript": "~5.9.2",
|
|
72
71
|
"vitepress": "^2.0.0-alpha.12",
|