nuxt-processor 0.0.1 → 0.0.3

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 CHANGED
@@ -3,19 +3,32 @@
3
3
  [![npm version][npm-version-src]][npm-version-href]
4
4
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
5
  [![License][license-src]][license-href]
6
- [![Nuxt][nuxt-src]][nuxt-href]
6
+ [![Known Vulnerabilities](https://snyk.io/test/github/aidanhibbard/nuxt-processor/badge.svg)](https://snyk.io/test/github/aidanhibbard/nuxt-processor)
7
7
 
8
8
  Background job processing for Nuxt using BullMQ with a dedicated workers process.
9
9
 
10
+ <img width="763" height="321" alt="image" src="https://github.com/user-attachments/assets/f49d79a9-f99a-4612-b3bc-cad724475bf4" />
11
+
12
+ Note: This package is under very active development! Please consider creating issues if you run into anything!
13
+
10
14
  - [✨ &nbsp;Release Notes](/CHANGELOG.md)
11
15
  <!-- - [📖 &nbsp;Documentation](https://example.com) -->
12
16
 
13
17
  ## Features
14
18
 
15
19
  - **Dedicated processing**: Workers run in a separate Node process – no coupling to your web server.
16
- - **Scalability**: Run multiple worker processes and instances across machines; backed by Redis.
20
+ - **Scalability**: Run multiple worker processes and instances across machines.
17
21
  - **Simple DX**: Define queues/workers in `server/queues` and `server/workers` using first-class helpers.
18
22
 
23
+ ## Sections
24
+
25
+ - [Install](#install)
26
+ - [Define a queue and enqueue from your app](#define-a-queue-and-enqueue-from-your-app)
27
+ - [Define a worker](#define-a-worker)
28
+ - [Running](#running)
29
+ - [Bull Board](#bull-board)
30
+ - [Contribution](#contribution)
31
+
19
32
  ## Install
20
33
 
21
34
  ```bash
@@ -28,7 +41,7 @@ Add the module in `nuxt.config.ts` and set your Redis connection.
28
41
  // nuxt.config.ts
29
42
  export default defineNuxtConfig({
30
43
  modules: ['nuxt-processor'],
31
- workers: {
44
+ processor: {
32
45
  redis: {
33
46
  host: process.env.NUXT_REDIS_HOST ?? '127.0.0.1', // defaults '127.0.0.1'
34
47
  port: Number(process.env.NUXT_REDIS_PORT ?? 6379), // defaults 6379
@@ -43,7 +56,7 @@ export default defineNuxtConfig({
43
56
  Create `server/queues/index.ts`:
44
57
 
45
58
  ```ts
46
- import { defineQueue } from '#workers'
59
+ import { defineQueue } from '#processor'
47
60
 
48
61
  export default defineQueue({
49
62
  name: 'hello',
@@ -55,7 +68,7 @@ export default defineQueue({
55
68
  Create `server/workers/index.ts`:
56
69
 
57
70
  ```ts
58
- import { defineWorker } from '#workers'
71
+ import { defineWorker } from '#processor'
59
72
  import type { Job } from '#bullmq'
60
73
 
61
74
  export default defineWorker({
@@ -71,19 +84,32 @@ export default defineWorker({
71
84
 
72
85
  ## Running
73
86
 
74
- - Start your Nuxt app normally (dev or build). This module generates a dedicated workers entry.
75
- - Start workers explicitly in a separate terminal:
87
+ - Start your Nuxt app normally. This module generates a dedicated workers entry.
88
+ - In development, run workers from `.nuxt/dev/workers/index.mjs` in a separate terminal:
89
+
90
+ ```bash
91
+ nuxi dev
92
+ node .nuxt/dev/workers/index.mjs
93
+ ```
94
+
95
+ - After building for production, run workers from `.output/server/workers/index.mjs`:
76
96
 
77
97
  ```bash
78
- # after a build
79
98
  nuxi build
80
99
  node .output/server/workers/index.mjs
81
100
  ```
82
101
 
83
- ## Shutdown
102
+ ## Bull Board
103
+
104
+ [Bull Board](https://github.com/felixmosh/bull-board) is an excellent UI for watching your queues, you can follow the setup in the playground to use it.
105
+
106
+ - [Server handler](./playground/server/handlers/bull-board.ts)
107
+ - [Route: `playground/server/routes/bull-board.ts`](./playground/server/routes/bull-board.ts)
108
+ - [Route: `playground/server/routes/bull-board/[...].ts`](./playground/server/routes/bull-board/%5B...%5D.ts)
84
109
 
85
- The workers process handles graceful shutdown on `SIGINT/SIGTERM` and logs worker start/stop.
110
+ Special thanks to [@genu](https://github.com/genu) for creating the H3 adapter.
86
111
 
112
+ For more help getting set up, see this Bull Board H3 adapter comment: <https://github.com/felixmosh/bull-board/pull/669#issuecomment-1883997968>.
87
113
 
88
114
  ## Contribution
89
115
 
@@ -118,14 +144,12 @@ The workers process handles graceful shutdown on `SIGINT/SIGTERM` and logs worke
118
144
 
119
145
 
120
146
  <!-- Badges -->
121
- [npm-version-src]: https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=020420&colorB=00DC82
122
- [npm-version-href]: https://npmjs.com/package/my-module
147
+ [npm-version-src]: https://img.shields.io/npm/v/nuxt-processor/latest.svg?style=flat&colorA=020420&colorB=00DC82
148
+ [npm-version-href]: https://npmjs.com/package/nuxt-processor
123
149
 
124
- [npm-downloads-src]: https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=020420&colorB=00DC82
125
- [npm-downloads-href]: https://npm.chart.dev/my-module
150
+ [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-processor.svg?style=flat&colorA=020420&colorB=00DC82
151
+ [npm-downloads-href]: https://npm.chart.dev/nuxt-processor
126
152
 
127
- [license-src]: https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=020420&colorB=00DC82
128
- [license-href]: https://npmjs.com/package/my-module
153
+ [license-src]: https://img.shields.io/npm/l/nuxt-processor.svg?style=flat&colorA=020420&colorB=00DC82
154
+ [license-href]: https://npmjs.com/package/nuxt-processor
129
155
 
130
- [nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js
131
- [nuxt-href]: https://nuxt.com
package/dist/module.d.mts CHANGED
@@ -3,8 +3,12 @@ import { RedisOptions } from 'bullmq';
3
3
 
4
4
  interface ModuleOptions {
5
5
  redis: RedisOptions;
6
- queues: string[];
7
- workers: string[];
6
+ /**
7
+ * The folder containing the worker files
8
+ * Scans for {ts,js,mjs}
9
+ * @default 'server/workers'
10
+ */
11
+ workers: string;
8
12
  }
9
13
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
10
14
 
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-processor",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "compatibility": {
5
5
  "nuxt": "^4.0.0"
6
6
  },
package/dist/module.mjs CHANGED
@@ -1,14 +1,28 @@
1
- import { defineNuxtModule, createResolver, addTemplate, logger } from '@nuxt/kit';
2
- import { readdir } from 'node:fs/promises';
1
+ import { useNuxt, createResolver, defineNuxtModule, addTemplate } from '@nuxt/kit';
3
2
  import { relative } from 'node:path';
3
+ import fg from 'fast-glob';
4
4
 
5
5
  const name = "nuxt-processor";
6
- const version = "0.0.1";
6
+ const version = "0.0.3";
7
7
  const configKey = "processor";
8
8
  const compatibility = {
9
9
  nuxt: "^4.0.0"
10
10
  };
11
11
 
12
+ const scanFolder = async (path) => {
13
+ const nuxt = useNuxt();
14
+ const { resolve } = createResolver(import.meta.url);
15
+ const resolvedPath = resolve(nuxt.options.rootDir, path);
16
+ const files = [];
17
+ const updatedFiles = await fg("**/*.{ts,js,mjs}", {
18
+ cwd: resolvedPath,
19
+ absolute: true,
20
+ onlyFiles: true
21
+ });
22
+ files.push(...new Set(updatedFiles));
23
+ return files;
24
+ };
25
+
12
26
  const module = defineNuxtModule({
13
27
  meta: {
14
28
  name,
@@ -23,40 +37,11 @@ const module = defineNuxtModule({
23
37
  port: Number(process.env.NUXT_REDIS_PORT ?? 6379),
24
38
  password: process.env.NUXT_REDIS_PASSWORD ?? ""
25
39
  },
26
- queues: [],
27
- workers: []
40
+ workers: "server/workers"
28
41
  },
29
- setup(_options, _nuxt) {
42
+ async setup(_options, _nuxt) {
30
43
  const { resolve } = createResolver(import.meta.url);
31
44
  const buildDir = _nuxt.options.buildDir;
32
- const srcDir = _nuxt.options.srcDir;
33
- const allowedExtensions = /* @__PURE__ */ new Set([".ts", ".js", ".mjs", ".mts", ".cjs", ".cts"]);
34
- async function collectFiles(fromDir) {
35
- const results = [];
36
- async function walk(dir) {
37
- let entries = [];
38
- try {
39
- entries = await readdir(dir, { withFileTypes: true });
40
- } catch (err) {
41
- logger.withTag("nuxt-processor").warn("failed to read directory", dir, err);
42
- return;
43
- }
44
- await Promise.all(entries.map(async (entry) => {
45
- const fullPath = resolve(dir, entry.name);
46
- if (entry.isDirectory()) {
47
- await walk(fullPath);
48
- } else {
49
- const dotIndex = fullPath.lastIndexOf(".");
50
- const ext = dotIndex >= 0 ? fullPath.slice(dotIndex) : "";
51
- if (allowedExtensions.has(ext)) {
52
- results.push(fullPath);
53
- }
54
- }
55
- }));
56
- }
57
- await walk(fromDir);
58
- return results;
59
- }
60
45
  function generateWorkersEntryContent(workerFiles) {
61
46
  const redisInline = JSON.stringify(_options.redis ?? {});
62
47
  const toImportArray = workerFiles.map((id) => `() => import(${JSON.stringify(id)})`).join(",\n ");
@@ -64,7 +49,7 @@ const module = defineNuxtModule({
64
49
  import { fileURLToPath } from 'node:url'
65
50
  import { resolve as resolvePath } from 'node:path'
66
51
  import { consola } from 'consola'
67
- import { $workers } from '#workers-utils'
52
+ import { $workers } from '#processor-utils'
68
53
 
69
54
  // Initialize connection as early as possible so any imports that register
70
55
  // workers/queues have a valid connection available.
@@ -149,11 +134,10 @@ if (isMain) {
149
134
  export default { createWorkersApp }
150
135
  `;
151
136
  }
152
- const { resolve: r } = createResolver(import.meta.url);
153
- _nuxt.options.alias = _nuxt.options.alias || {};
154
- _nuxt.options.alias["nuxt-processor"] = r("./runtime/server/handlers");
155
- _nuxt.options.alias["#workers"] = r("./runtime/server/handlers");
156
- _nuxt.options.alias["#workers-utils"] = r("./runtime/server/utils/workers");
137
+ _nuxt.options.alias = _nuxt.options.alias ?? {};
138
+ _nuxt.options.alias["nuxt-processor"] = resolve("./runtime/server/handlers");
139
+ _nuxt.options.alias["#processor"] = resolve("./runtime/server/handlers");
140
+ _nuxt.options.alias["#processor-utils"] = resolve("./runtime/server/utils/workers");
157
141
  if (!_nuxt.options.alias["#bullmq"]) {
158
142
  _nuxt.options.alias["#bullmq"] = "bullmq";
159
143
  }
@@ -162,17 +146,17 @@ export default { createWorkersApp }
162
146
  write: true,
163
147
  getContents: () => `
164
148
  declare module 'nuxt-processor' {
165
- export { defineQueue } from '${r("./runtime/server/handlers/defineQueue")}'
166
- export { defineWorker } from '${r("./runtime/server/handlers/defineWorker")}'
149
+ export { defineQueue } from '${resolve("./runtime/server/handlers/defineQueue")}'
150
+ export { defineWorker } from '${resolve("./runtime/server/handlers/defineWorker")}'
167
151
  }
168
152
 
169
- declare module '#workers' {
170
- export { defineQueue } from '${r("./runtime/server/handlers/defineQueue")}'
171
- export { defineWorker } from '${r("./runtime/server/handlers/defineWorker")}'
153
+ declare module '#processor' {
154
+ export { defineQueue } from '${resolve("./runtime/server/handlers/defineQueue")}'
155
+ export { defineWorker } from '${resolve("./runtime/server/handlers/defineWorker")}'
172
156
  }
173
157
 
174
- declare module '#workers-utils' {
175
- export { $workers } from '${r("./runtime/server/utils/workers")}'
158
+ declare module '#processor-utils' {
159
+ export { $workers } from '${resolve("./runtime/server/utils/workers")}'
176
160
  }
177
161
 
178
162
  declare module '#bullmq' {
@@ -191,7 +175,7 @@ declare module '#bullmq' {
191
175
  return {
192
176
  name: "nuxt-processor-emit",
193
177
  async buildStart() {
194
- const workerFiles = await collectFiles(resolve(srcDir, "server/workers"));
178
+ const workerFiles = await scanFolder(_options.workers);
195
179
  if (workerFiles.length === 0) {
196
180
  virtualCode = "";
197
181
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-processor",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Nuxt Processor",
5
5
  "repository": "https://github.com/aidanhibbard/nuxt-processor",
6
6
  "license": "MIT",
@@ -43,6 +43,7 @@
43
43
  "dependencies": {
44
44
  "@nuxt/kit": "^4.0.3",
45
45
  "bullmq": "^5.58.2",
46
+ "fast-glob": "^3.3.3",
46
47
  "ioredis": "^5.7.0"
47
48
  },
48
49
  "devDependencies": {
@@ -55,6 +56,7 @@
55
56
  "@types/node": "latest",
56
57
  "changelogen": "^0.6.2",
57
58
  "eslint": "^9.34.0",
59
+ "happy-dom": "^18.0.1",
58
60
  "nuxt": "^4.0.3",
59
61
  "typescript": "~5.9.2",
60
62
  "vitepress": "^2.0.0-alpha.12",