nuxt-processor 0.0.2 → 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,6 +3,7 @@
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
+ [![Known Vulnerabilities](https://snyk.io/test/github/aidanhibbard/nuxt-processor/badge.svg)](https://snyk.io/test/github/aidanhibbard/nuxt-processor)
6
7
 
7
8
  Background job processing for Nuxt using BullMQ with a dedicated workers process.
8
9
 
@@ -40,7 +41,7 @@ Add the module in `nuxt.config.ts` and set your Redis connection.
40
41
  // nuxt.config.ts
41
42
  export default defineNuxtConfig({
42
43
  modules: ['nuxt-processor'],
43
- workers: {
44
+ processor: {
44
45
  redis: {
45
46
  host: process.env.NUXT_REDIS_HOST ?? '127.0.0.1', // defaults '127.0.0.1'
46
47
  port: Number(process.env.NUXT_REDIS_PORT ?? 6379), // defaults 6379
@@ -55,7 +56,7 @@ export default defineNuxtConfig({
55
56
  Create `server/queues/index.ts`:
56
57
 
57
58
  ```ts
58
- import { defineQueue } from '#workers'
59
+ import { defineQueue } from '#processor'
59
60
 
60
61
  export default defineQueue({
61
62
  name: 'hello',
@@ -67,7 +68,7 @@ export default defineQueue({
67
68
  Create `server/workers/index.ts`:
68
69
 
69
70
  ```ts
70
- import { defineWorker } from '#workers'
71
+ import { defineWorker } from '#processor'
71
72
  import type { Job } from '#bullmq'
72
73
 
73
74
  export default defineWorker({
@@ -83,8 +84,15 @@ export default defineWorker({
83
84
 
84
85
  ## Running
85
86
 
86
- - Start your Nuxt app normally (dev or build). This module generates a dedicated workers entry.
87
- - 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`:
88
96
 
89
97
  ```bash
90
98
  nuxi build
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.2",
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.2";
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.2",
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": {