@serwist/nuxt 10.0.0-preview.13 → 10.0.0-preview.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/dist/module.d.mts CHANGED
@@ -1,21 +1,7 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { Optional, Require } from '@serwist/utils';
2
3
  import { PluginOptions } from 'vite-plugin-serwist';
3
4
 
4
- /**
5
- * Make certain fields in a object type optional
6
- *
7
- * @example
8
- * interface A {
9
- * a: string;
10
- * b: string;
11
- * c: string;
12
- * }
13
- * type B = Optional<A, "b" | "c">;
14
- * const b: B = { a: "hehe" }; //valid
15
- * const b: B = {}; //invalid
16
- */
17
- type Optional<T, U extends keyof T> = Omit<T, U> & Partial<Pick<T, U>>;
18
-
19
5
  interface ClientOptions {
20
6
  /**
21
7
  * Whether this plugin should be registered.
@@ -28,8 +14,11 @@ interface ModuleOptions extends Optional<PluginOptions, "swSrc" | "swDest" | "gl
28
14
  */
29
15
  client?: ClientOptions;
30
16
  }
17
+ type DefaultModuleKeys = "base" | "scope" | "client" | "swSrc" | "swDest" | "swUrl" | "globDirectory" | "injectionPoint";
18
+ type DefaultModuleOptions = Required<Pick<ModuleOptions, DefaultModuleKeys>>;
19
+ type ResolvedModuleOptions = Require<ModuleOptions, DefaultModuleKeys>;
31
20
 
32
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
21
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, Required<Pick<ModuleOptions, DefaultModuleKeys>>, true>;
33
22
 
34
23
  export { _default as default };
35
- export type { ClientOptions, ModuleOptions };
24
+ export type { ClientOptions, DefaultModuleKeys, DefaultModuleOptions, ModuleOptions, ResolvedModuleOptions };
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.8.0 || ^4.0.0"
6
6
  },
7
- "version": "10.0.0-preview.13",
7
+ "version": "10.0.0-preview.14",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,41 +1,40 @@
1
1
  import path from 'node:path';
2
2
  import { defineNuxtModule, createResolver, addPlugin, extendWebpackConfig } from '@nuxt/kit';
3
- import { resolveEntry } from '@serwist/utils/node';
4
- import { createContext, main, dev, generateServiceWorker } from 'vite-plugin-serwist';
3
+ import { createContext, main, dev, generateServiceWorker, resolveEntry } from 'vite-plugin-serwist';
5
4
  import { createHash } from 'node:crypto';
6
5
  import { createReadStream } from 'node:fs';
7
6
  import fsp from 'node:fs/promises';
7
+ import { DEFAULT_GLOB_PATTERNS } from '@serwist/build';
8
8
 
9
- const version = "10.0.0-preview.13";
9
+ const version = "10.0.0-preview.14";
10
10
  const packageJson = {
11
11
  version: version};
12
12
 
13
- function configurePwaOptions(options, nuxt, nitroConfig) {
13
+ const configureSerwistOptions = (options, nuxt, nitroConfig) => {
14
14
  let buildAssetsDir = nuxt.options.app.buildAssetsDir ?? "_nuxt/";
15
15
  if (buildAssetsDir[0] === "/") buildAssetsDir = buildAssetsDir.slice(1);
16
16
  if (buildAssetsDir[buildAssetsDir.length - 1] !== "/") buildAssetsDir += "/";
17
17
  if (!("dontCacheBustURLsMatching" in options)) {
18
18
  options.dontCacheBustURLsMatching = new RegExp(buildAssetsDir);
19
19
  }
20
- if (nuxt.options.experimental.payloadExtraction) {
21
- const enableGlobPatterns = nuxt.options.nitro.static || nuxt.options._generate || !!nitroConfig.prerender?.routes?.length || Object.values(nitroConfig.routeRules ?? {}).some((r) => r.prerender);
22
- if (enableGlobPatterns) {
23
- options.globPatterns = options.globPatterns ?? [];
24
- options.globPatterns.push("**/_payload.json");
25
- }
20
+ options.globPatterns = options.globPatterns ?? DEFAULT_GLOB_PATTERNS;
21
+ if (nuxt.options.experimental.payloadExtraction && // Has prerendered routes
22
+ (nuxt.options.nitro.static || nuxt.options._generate || !!nitroConfig.prerender?.routes?.length || Object.values(nitroConfig.routeRules ?? {}).some((r) => r.prerender))) {
23
+ options.globPatterns.push("**/_payload.json");
26
24
  }
27
25
  let appManifestFolder;
28
26
  if (nuxt.options.experimental.appManifest) {
29
- options.globPatterns = options.globPatterns ?? [];
30
27
  appManifestFolder = `${buildAssetsDir}builds/`;
31
28
  options.globPatterns.push(`${appManifestFolder}**/*.json`);
32
29
  }
33
30
  const _public = nitroConfig.output?.publicDir ?? nuxt.options.nitro?.output?.publicDir;
34
- const publicDir = _public ? path.resolve(_public) : path.resolve(nuxt.options.buildDir, "../.output/public");
31
+ const publicDir = _public ? path.resolve(_public) : path.resolve(nuxt.options.rootDir, ".output/public");
32
+ options.swDest = options.swDest ? path.isAbsolute(options.swDest) ? options.swDest : path.resolve(publicDir, options.swDest) : path.resolve(publicDir, "sw.js");
33
+ options.globDirectory = options.globDirectory || publicDir;
35
34
  if (!nuxt.options.dev && !options.manifestTransforms) {
36
35
  options.manifestTransforms = [createManifestTransform(nuxt.options.app.baseURL ?? "/", publicDir, appManifestFolder)];
37
36
  }
38
- }
37
+ };
39
38
  function createManifestTransform(base, publicDir, appManifestFolder) {
40
39
  return async (entries) => {
41
40
  entries.filter((e) => e.url.endsWith(".html")).forEach((e) => {
@@ -79,7 +78,7 @@ function createManifestTransform(base, publicDir, appManifestFolder) {
79
78
  };
80
79
  }
81
80
 
82
- const module = defineNuxtModule({
81
+ const module = defineNuxtModule().with({
83
82
  meta: {
84
83
  name: "@serwist/nuxt",
85
84
  configKey: "serwist",
@@ -89,7 +88,6 @@ const module = defineNuxtModule({
89
88
  version: packageJson.version
90
89
  },
91
90
  defaults(nuxt) {
92
- const publicDir = path.resolve(nuxt.options.rootDir, ".output/public");
93
91
  return {
94
92
  base: nuxt.options.app.baseURL,
95
93
  scope: nuxt.options.app.baseURL,
@@ -99,16 +97,18 @@ const module = defineNuxtModule({
99
97
  // Try to find `service-worker.{ts,js}` or `service-worker/index.{ts,js}`. If not found,
100
98
  // force the user to provide a `swSrc` themself.
101
99
  swSrc: resolveEntry(path.resolve(nuxt.options.rootDir, "service-worker")) || void 0,
102
- swDest: path.resolve(publicDir, "sw.js"),
100
+ // If `swDest` is not set by `configureSerwistOptions`, something is wrong.
101
+ swDest: "",
103
102
  swUrl: "/sw.js",
104
- globDirectory: publicDir,
103
+ // If `globDirectory` is not set by `configureSerwistOptions`, something is wrong.
104
+ globDirectory: "",
105
105
  injectionPoint: "self.__SW_MANIFEST"
106
106
  };
107
107
  },
108
- async setup(options, nuxt) {
108
+ async setup(_options, nuxt) {
109
109
  const resolver = createResolver(import.meta.url);
110
110
  let ctx;
111
- const { client: _client, ...userOptions } = options;
111
+ const { client: _client, ...options } = _options;
112
112
  const client = { registerPlugin: true, ..._client };
113
113
  const runtimeDir = resolver.resolve("./runtime");
114
114
  if (!nuxt.options.ssr) nuxt.options.build.transpile.push(runtimeDir);
@@ -122,7 +122,7 @@ const module = defineNuxtModule({
122
122
  references.push({ path: resolver.resolve(runtimeDir, "plugins/augmentation.d.ts") });
123
123
  });
124
124
  nuxt.hook("nitro:init", (nitro) => {
125
- configurePwaOptions(options, nuxt, nitro.options);
125
+ configureSerwistOptions(options, nuxt, nitro.options);
126
126
  });
127
127
  nuxt.hook("vite:extend", ({ config }) => {
128
128
  const plugin = config.plugins?.find((p) => p && typeof p === "object" && "name" in p && p.name === "vite-plugin-serwist");
@@ -154,7 +154,7 @@ const module = defineNuxtModule({
154
154
  }
155
155
  });
156
156
  }
157
- ctx = createContext(userOptions, "nuxt");
157
+ ctx = createContext(options, "nuxt");
158
158
  viteInlineConfig.plugins.push(main(ctx), dev(ctx));
159
159
  });
160
160
  extendWebpackConfig(() => {
package/dist/types.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { default } from './module.mjs'
2
2
 
3
- export { type ClientOptions, type ModuleOptions } from './module.mjs'
3
+ export { type ClientOptions, type DefaultModuleKeys, type DefaultModuleOptions, type ModuleOptions, type ResolvedModuleOptions } from './module.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/nuxt",
3
- "version": "10.0.0-preview.13",
3
+ "version": "10.0.0-preview.14",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "A Nuxt module that integrates Serwist into your application.",
@@ -45,6 +45,7 @@
45
45
  "vite",
46
46
  "@nuxt/kit",
47
47
  "@serwist/build",
48
+ "@serwist/utils",
48
49
  "vite-plugin-serwist",
49
50
  "virtual:serwist-nuxt-configuration",
50
51
  "virtual:serwist"
@@ -52,10 +53,10 @@
52
53
  },
53
54
  "dependencies": {
54
55
  "@nuxt/kit": "4.0.3",
55
- "@serwist/build": "10.0.0-preview.13",
56
- "@serwist/utils": "10.0.0-preview.13",
57
- "@serwist/window": "10.0.0-preview.13",
58
- "vite-plugin-serwist": "10.0.0-preview.13"
56
+ "@serwist/build": "10.0.0-preview.14",
57
+ "@serwist/utils": "10.0.0-preview.14",
58
+ "@serwist/window": "10.0.0-preview.14",
59
+ "vite-plugin-serwist": "10.0.0-preview.14"
59
60
  },
60
61
  "devDependencies": {
61
62
  "@nuxt/module-builder": "1.0.2",
@@ -68,7 +69,7 @@
68
69
  "typescript": "5.9.2",
69
70
  "vite": "7.1.3",
70
71
  "vue-tsc": "3.0.6",
71
- "@serwist/configs": "10.0.0-preview.13"
72
+ "@serwist/configs": "10.0.0-preview.14"
72
73
  },
73
74
  "peerDependencies": {
74
75
  "typescript": ">=5.0.0",