nuxt-processor 0.0.4 → 0.0.6

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Aidan Hibbard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -5,9 +5,10 @@
5
5
  [![License][license-src]][license-href]
6
6
  [![Known Vulnerabilities](https://snyk.io/test/github/aidanhibbard/nuxt-processor/badge.svg)](https://snyk.io/test/github/aidanhibbard/nuxt-processor)
7
7
 
8
- Background job processing for Nuxt using BullMQ with a dedicated workers process.
8
+ ## Real background job processing for Nuxt
9
+
10
+ <img width="752" height="402" alt="image" src="https://github.com/user-attachments/assets/9190d8e1-8a46-4b49-be5a-20f0a49fc8fe" />
9
11
 
10
- <img width="763" height="321" alt="image" src="https://github.com/user-attachments/assets/f49d79a9-f99a-4612-b3bc-cad724475bf4" />
11
12
 
12
13
  Note: This package is under very active development! Please consider creating issues if you run into anything!
13
14
 
@@ -18,7 +19,7 @@ Note: This package is under very active development! Please consider creating is
18
19
 
19
20
  - **Dedicated processing**: Workers run in a separate Node process – no coupling to your web server.
20
21
  - **Scalability**: Run multiple worker processes and instances across machines.
21
- - **Simple DX**: Define queues/workers in `server/queues` and `server/workers` using first-class helpers.
22
+ - **Simple DX**: Define queues/workers using first-class helpers.
22
23
 
23
24
  ## Sections
24
25
 
@@ -44,9 +45,14 @@ export default defineNuxtConfig({
44
45
  modules: ['nuxt-processor'],
45
46
  processor: {
46
47
  redis: {
47
- host: process.env.NUXT_REDIS_HOST ?? '127.0.0.1', // defaults '127.0.0.1'
48
- port: Number(process.env.NUXT_REDIS_PORT ?? 6379), // defaults 6379
49
- password: process.env.NUXT_REDIS_PASSWORD ?? '', // defaults ''
48
+ // Prefer a single URL if available (takes precedence over other fields)
49
+ // e.g. redis://user:pass@host:6379/0
50
+ url: process.env.NUXT_REDIS_URL,
51
+ host: process.env.NUXT_REDIS_HOST ?? '127.0.0.1',
52
+ port: Number(process.env.NUXT_REDIS_PORT ?? 6379),
53
+ password: process.env.NUXT_REDIS_PASSWORD ?? '',
54
+ username: process.env.NUXT_REDIS_USERNAME,
55
+ db: Number(process.env.NUXT_REDIS_DB ?? 0),
50
56
  },
51
57
  },
52
58
  })
@@ -54,19 +60,20 @@ export default defineNuxtConfig({
54
60
 
55
61
  ## Define a queue and enqueue from your app
56
62
 
57
- Create `server/queues/index.ts`:
63
+ Create `server/queues/hello.ts`:
58
64
 
59
65
  ```ts
60
66
  import { defineQueue } from '#processor'
61
67
 
62
68
  export default defineQueue({
63
69
  name: 'hello',
70
+ options: {},
64
71
  })
65
72
  ```
66
73
 
67
74
  ## Define a worker
68
75
 
69
- Create `server/workers/index.ts`:
76
+ Create `server/workers/hello.ts`:
70
77
 
71
78
  ```ts
72
79
  import { defineWorker } from '#processor'
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.BqsFQtIQ.cjs');
11
+ const _package = require('./shared/nuxt-processor.BYUls4Ut.cjs');
12
12
 
13
13
  const ensureNuxtProject = async (args) => {
14
14
  const dir = pathe.resolve(args.dir);
@@ -64,7 +64,7 @@ const main = citty.createMain({
64
64
  const updated = {
65
65
  ...pkg,
66
66
  scripts: {
67
- ...pkg.scripts || {},
67
+ ...pkg.scripts ?? {},
68
68
  "processor:dev": "nuxt-processor dev"
69
69
  }
70
70
  };
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.BDPWtq8T.mjs';
9
+ import { v as version, d as description, n as name } from './shared/nuxt-processor.BhHJSy2L.mjs';
10
10
 
11
11
  const ensureNuxtProject = async (args) => {
12
12
  const dir = resolve(args.dir);
@@ -62,7 +62,7 @@ const main = createMain({
62
62
  const updated = {
63
63
  ...pkg,
64
64
  scripts: {
65
- ...pkg.scripts || {},
65
+ ...pkg.scripts ?? {},
66
66
  "processor:dev": "nuxt-processor dev"
67
67
  }
68
68
  };
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.BqsFQtIQ.cjs');
4
+ const _package = require('./shared/nuxt-processor.BYUls4Ut.cjs');
5
5
  const node_path = require('node:path');
6
6
  const fg = require('fast-glob');
7
7
 
@@ -36,13 +36,17 @@ const module$1 = kit.defineNuxtModule({
36
36
  redis: {
37
37
  host: process.env.NUXT_REDIS_HOST ?? "127.0.0.1",
38
38
  port: Number(process.env.NUXT_REDIS_PORT ?? 6379),
39
- password: process.env.NUXT_REDIS_PASSWORD ?? ""
39
+ password: process.env.NUXT_REDIS_PASSWORD ?? "",
40
+ username: process.env.NUXT_REDIS_USERNAME ?? void 0,
41
+ // needs Redis >= 6
42
+ db: Number(process.env.NUXT_REDIS_DB ?? 0),
43
+ // Defaults to 0 on ioredis
44
+ url: process.env.NUXT_REDIS_URL ?? void 0
40
45
  },
41
46
  workers: "server/workers"
42
47
  },
43
- async setup(_options, _nuxt) {
48
+ async setup(_options, nuxt) {
44
49
  const { resolve } = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
45
- const buildDir = _nuxt.options.buildDir;
46
50
  function generateWorkersEntryContent(workerFiles) {
47
51
  const redisInline = JSON.stringify(_options.redis ?? {});
48
52
  const toImportArray = workerFiles.map((id) => `() => import(${JSON.stringify(id)})`).join(",\n ");
@@ -135,16 +139,15 @@ if (isMain) {
135
139
  export default { createWorkersApp }
136
140
  `;
137
141
  }
138
- _nuxt.options.alias = _nuxt.options.alias ?? {};
139
- _nuxt.options.alias["nuxt-processor"] = resolve("./runtime/server/handlers");
140
- _nuxt.options.alias["#processor"] = resolve("./runtime/server/handlers");
141
- _nuxt.options.alias["#processor-utils"] = resolve("./runtime/server/utils/workers");
142
- if (!_nuxt.options.alias["#bullmq"]) {
143
- _nuxt.options.alias["#bullmq"] = "bullmq";
142
+ nuxt.options.alias = nuxt.options.alias ?? {};
143
+ nuxt.options.alias["nuxt-processor"] = resolve("./runtime/server/handlers");
144
+ nuxt.options.alias["#processor"] = resolve("./runtime/server/handlers");
145
+ nuxt.options.alias["#processor-utils"] = resolve("./runtime/server/utils/workers");
146
+ if (!nuxt.options.alias["#bullmq"]) {
147
+ nuxt.options.alias["#bullmq"] = "bullmq";
144
148
  }
145
- const typesDtsPath = kit.addTemplate({
149
+ kit.addTypeTemplate({
146
150
  filename: "types/nuxt-processor.d.ts",
147
- write: true,
148
151
  getContents: () => `
149
152
  declare module 'nuxt-processor' {
150
153
  export { defineQueue } from '${resolve("./runtime/server/handlers/defineQueue")}'
@@ -164,10 +167,6 @@ declare module '#bullmq' {
164
167
  export * from 'bullmq'
165
168
  }
166
169
  `
167
- }).dst;
168
- _nuxt.hooks.hook("prepare:types", (opts) => {
169
- if (!opts.tsConfig.include) opts.tsConfig.include = [];
170
- opts.tsConfig.include.push(resolve(buildDir, typesDtsPath));
171
170
  });
172
171
  function createWorkersRollupPlugin() {
173
172
  const VIRTUAL_ID = "\0nuxt-processor-entry";
@@ -191,7 +190,7 @@ declare module '#bullmq' {
191
190
  if (id === VIRTUAL_ID) return VIRTUAL_ID;
192
191
  },
193
192
  load(id) {
194
- if (id === VIRTUAL_ID) return virtualCode || "export {}\n";
193
+ if (id === VIRTUAL_ID) return virtualCode ?? "export {}\n";
195
194
  },
196
195
  generateBundle() {
197
196
  if (!virtualCode || !entryRefId) return;
@@ -211,7 +210,7 @@ process.on('beforeExit', () => shutdown('beforeExit'))
211
210
  }
212
211
  };
213
212
  }
214
- _nuxt.hooks.hook("nitro:config", (nitroConfig) => {
213
+ nuxt.hooks.hook("nitro:config", (nitroConfig) => {
215
214
  nitroConfig.rollupConfig = nitroConfig.rollupConfig ?? {};
216
215
  const plugin = createWorkersRollupPlugin();
217
216
  const current = nitroConfig.rollupConfig.plugins;
package/dist/module.d.cts CHANGED
@@ -1,8 +1,11 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  import { RedisOptions } from 'bullmq';
3
3
 
4
+ type ModuleRedisOptions = RedisOptions & {
5
+ url?: string;
6
+ };
4
7
  interface ModuleOptions {
5
- redis: RedisOptions;
8
+ redis: ModuleRedisOptions;
6
9
  /**
7
10
  * The folder containing the worker files
8
11
  * Scans for {ts,js,mjs}
package/dist/module.d.mts CHANGED
@@ -1,8 +1,11 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  import { RedisOptions } from 'bullmq';
3
3
 
4
+ type ModuleRedisOptions = RedisOptions & {
5
+ url?: string;
6
+ };
4
7
  interface ModuleOptions {
5
- redis: RedisOptions;
8
+ redis: ModuleRedisOptions;
6
9
  /**
7
10
  * The folder containing the worker files
8
11
  * Scans for {ts,js,mjs}
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-processor",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "compatibility": {
5
5
  "nuxt": "^4.0.0 || ^3.0.0"
6
6
  },
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { useNuxt, createResolver, defineNuxtModule, addTemplate } from '@nuxt/kit';
2
- import { c as configKey, a as compatibility, v as version, n as name } from './shared/nuxt-processor.BDPWtq8T.mjs';
1
+ import { useNuxt, createResolver, defineNuxtModule, addTypeTemplate } from '@nuxt/kit';
2
+ import { c as configKey, a as compatibility, v as version, n as name } from './shared/nuxt-processor.BhHJSy2L.mjs';
3
3
  import { relative } from 'node:path';
4
4
  import fg from 'fast-glob';
5
5
 
@@ -29,13 +29,17 @@ const module = defineNuxtModule({
29
29
  redis: {
30
30
  host: process.env.NUXT_REDIS_HOST ?? "127.0.0.1",
31
31
  port: Number(process.env.NUXT_REDIS_PORT ?? 6379),
32
- password: process.env.NUXT_REDIS_PASSWORD ?? ""
32
+ password: process.env.NUXT_REDIS_PASSWORD ?? "",
33
+ username: process.env.NUXT_REDIS_USERNAME ?? void 0,
34
+ // needs Redis >= 6
35
+ db: Number(process.env.NUXT_REDIS_DB ?? 0),
36
+ // Defaults to 0 on ioredis
37
+ url: process.env.NUXT_REDIS_URL ?? void 0
33
38
  },
34
39
  workers: "server/workers"
35
40
  },
36
- async setup(_options, _nuxt) {
41
+ async setup(_options, nuxt) {
37
42
  const { resolve } = createResolver(import.meta.url);
38
- const buildDir = _nuxt.options.buildDir;
39
43
  function generateWorkersEntryContent(workerFiles) {
40
44
  const redisInline = JSON.stringify(_options.redis ?? {});
41
45
  const toImportArray = workerFiles.map((id) => `() => import(${JSON.stringify(id)})`).join(",\n ");
@@ -128,16 +132,15 @@ if (isMain) {
128
132
  export default { createWorkersApp }
129
133
  `;
130
134
  }
131
- _nuxt.options.alias = _nuxt.options.alias ?? {};
132
- _nuxt.options.alias["nuxt-processor"] = resolve("./runtime/server/handlers");
133
- _nuxt.options.alias["#processor"] = resolve("./runtime/server/handlers");
134
- _nuxt.options.alias["#processor-utils"] = resolve("./runtime/server/utils/workers");
135
- if (!_nuxt.options.alias["#bullmq"]) {
136
- _nuxt.options.alias["#bullmq"] = "bullmq";
135
+ nuxt.options.alias = nuxt.options.alias ?? {};
136
+ nuxt.options.alias["nuxt-processor"] = resolve("./runtime/server/handlers");
137
+ nuxt.options.alias["#processor"] = resolve("./runtime/server/handlers");
138
+ nuxt.options.alias["#processor-utils"] = resolve("./runtime/server/utils/workers");
139
+ if (!nuxt.options.alias["#bullmq"]) {
140
+ nuxt.options.alias["#bullmq"] = "bullmq";
137
141
  }
138
- const typesDtsPath = addTemplate({
142
+ addTypeTemplate({
139
143
  filename: "types/nuxt-processor.d.ts",
140
- write: true,
141
144
  getContents: () => `
142
145
  declare module 'nuxt-processor' {
143
146
  export { defineQueue } from '${resolve("./runtime/server/handlers/defineQueue")}'
@@ -157,10 +160,6 @@ declare module '#bullmq' {
157
160
  export * from 'bullmq'
158
161
  }
159
162
  `
160
- }).dst;
161
- _nuxt.hooks.hook("prepare:types", (opts) => {
162
- if (!opts.tsConfig.include) opts.tsConfig.include = [];
163
- opts.tsConfig.include.push(resolve(buildDir, typesDtsPath));
164
163
  });
165
164
  function createWorkersRollupPlugin() {
166
165
  const VIRTUAL_ID = "\0nuxt-processor-entry";
@@ -184,7 +183,7 @@ declare module '#bullmq' {
184
183
  if (id === VIRTUAL_ID) return VIRTUAL_ID;
185
184
  },
186
185
  load(id) {
187
- if (id === VIRTUAL_ID) return virtualCode || "export {}\n";
186
+ if (id === VIRTUAL_ID) return virtualCode ?? "export {}\n";
188
187
  },
189
188
  generateBundle() {
190
189
  if (!virtualCode || !entryRefId) return;
@@ -204,7 +203,7 @@ process.on('beforeExit', () => shutdown('beforeExit'))
204
203
  }
205
204
  };
206
205
  }
207
- _nuxt.hooks.hook("nitro:config", (nitroConfig) => {
206
+ nuxt.hooks.hook("nitro:config", (nitroConfig) => {
208
207
  nitroConfig.rollupConfig = nitroConfig.rollupConfig ?? {};
209
208
  const plugin = createWorkersRollupPlugin();
210
209
  const current = nitroConfig.rollupConfig.plugins;
@@ -1,7 +1,18 @@
1
1
  import type { Job, JobsOptions, QueueOptions, WorkerOptions, Processor } from 'bullmq';
2
2
  import { Queue, Worker } from 'bullmq';
3
3
  export declare function $workers(): {
4
- setConnection: (connection: QueueOptions["connection"]) => void;
4
+ setConnection: (connection: string | import("bullmq").ConnectionOptions | (import("ioredis").CommonRedisOptions & import("ioredis").SentinelConnectionOptions & Partial<{
5
+ port: number;
6
+ host?: string | undefined | undefined;
7
+ family?: number | undefined | undefined;
8
+ } & {
9
+ path: string;
10
+ }> & {
11
+ disconnectTimeout?: number;
12
+ tls?: import("tls").ConnectionOptions;
13
+ } & {
14
+ url?: string;
15
+ })) => void;
5
16
  createQueue: (name: string, options?: Omit<QueueOptions, "connection"> & {
6
17
  defaultJobOptions?: JobsOptions;
7
18
  }) => Queue<any, any, string, any, any, string>;
@@ -1,4 +1,5 @@
1
1
  import { Queue, Worker } from "bullmq";
2
+ import IORedis from "ioredis";
2
3
  const registry = {
3
4
  connection: void 0,
4
5
  queues: [],
@@ -6,7 +7,14 @@ const registry = {
6
7
  };
7
8
  export function $workers() {
8
9
  function setConnection(connection) {
9
- registry.connection = connection;
10
+ if (connection && typeof connection === "object" && "url" in connection && connection.url) {
11
+ const { url, ...rest } = connection;
12
+ registry.connection = new IORedis(url, rest);
13
+ } else if (typeof connection === "string") {
14
+ registry.connection = new IORedis(connection);
15
+ } else {
16
+ registry.connection = connection;
17
+ }
10
18
  }
11
19
  function createQueue(name, options) {
12
20
  const queue = new Queue(name, {
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const name = "nuxt-processor";
4
- const version = "0.0.4";
4
+ const version = "0.0.6";
5
5
  const description = "Nuxt Processor";
6
6
  const configKey = "processor";
7
7
  const compatibility = {
@@ -1,5 +1,5 @@
1
1
  const name = "nuxt-processor";
2
- const version = "0.0.4";
2
+ const version = "0.0.6";
3
3
  const description = "Nuxt Processor";
4
4
  const configKey = "processor";
5
5
  const compatibility = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-processor",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Nuxt Processor",
5
5
  "repository": "https://github.com/aidanhibbard/nuxt-processor",
6
6
  "license": "MIT",
@@ -38,6 +38,7 @@
38
38
  "release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
39
39
  "lint": "eslint .",
40
40
  "test": "vitest run",
41
+ "test:coverage": "vitest run --coverage",
41
42
  "test:watch": "vitest watch",
42
43
  "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
43
44
  "vp:dev": "vitepress dev docs",
@@ -46,9 +47,9 @@
46
47
  },
47
48
  "dependencies": {
48
49
  "@nuxt/kit": "^4.0.3",
50
+ "bullmq": "^5.58.2",
49
51
  "citty": "^0.1.6",
50
52
  "consola": "^3.2.3",
51
- "bullmq": "^5.58.2",
52
53
  "fast-glob": "^3.3.3",
53
54
  "ioredis": "^5.7.0",
54
55
  "pathe": "^1.1.2"
@@ -61,6 +62,7 @@
61
62
  "@nuxt/schema": "^4.0.3",
62
63
  "@nuxt/test-utils": "^3.19.2",
63
64
  "@types/node": "latest",
65
+ "@vitest/coverage-v8": "^3.2.4",
64
66
  "changelogen": "^0.6.2",
65
67
  "eslint": "^9.34.0",
66
68
  "happy-dom": "^18.0.1",