@nuxtjs/prismic 3.0.0-alpha.9 → 3.0.0-rc.0

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
@@ -26,7 +26,7 @@ Easily connect your Nuxt.js application to your content hosted on [Prismic][pris
26
26
  ## Install
27
27
 
28
28
  ```bash
29
- npm install --save-dev @nuxtjs/prismic@alpha # or yarn add --dev @nuxtjs/prismic@alpha
29
+ npm install --save-dev @nuxtjs/prismic@rc # or yarn add --dev @nuxtjs/prismic@rc
30
30
  ```
31
31
 
32
32
  Then, add `@nuxtjs/prismic` to the `modules` section of your Nuxt config and configure your Prismic API endpoint:
package/dist/module.d.ts CHANGED
@@ -7,6 +7,7 @@ declare type PrismicModuleOptions = Omit<PrismicPluginOptions, 'endpoint' | 'cli
7
7
  linkResolver?: string;
8
8
  htmlSerializer?: string;
9
9
  preview?: string | false;
10
+ toolbar?: boolean;
10
11
  };
11
12
 
12
13
  declare const _default: _nuxt_schema.NuxtModule<PrismicModuleOptions>;
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/prismic",
3
- "version": "3.0.0-alpha.9",
3
+ "version": "3.0.0-rc.0",
4
4
  "configKey": "prismic",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.0.0"
package/dist/module.mjs CHANGED
@@ -1,13 +1,15 @@
1
- import { join } from 'path';
1
+ import { join } from 'node:path';
2
2
  import { defineNuxtModule, createResolver, addPlugin, addComponent, addAutoImport, extendPages, addTemplate } from '@nuxt/kit';
3
3
  import { cleanDoubleSlashes } from 'ufo';
4
4
  import { isRepositoryEndpoint, getRepositoryName } from '@prismicio/client';
5
5
  import * as prismicVue from '@prismicio/vue';
6
- import { existsSync } from 'fs';
7
6
  import consola from 'consola';
7
+ import { existsSync } from 'node:fs';
8
8
 
9
9
  const name = "@nuxtjs/prismic";
10
- const version = "3.0.0-alpha.9";
10
+ const version = "3.0.0-rc.0";
11
+
12
+ const logger = consola.withScope("nuxt:prismic");
11
13
 
12
14
  const fileExists = (path, extensions = ["js", "ts"]) => {
13
15
  if (!path) {
@@ -19,8 +21,6 @@ const fileExists = (path, extensions = ["js", "ts"]) => {
19
21
  return extension ? `${path}.${extension}` : null;
20
22
  };
21
23
 
22
- const logger = consola.withScope("nuxt:prismic");
23
-
24
24
  const module = defineNuxtModule({
25
25
  meta: {
26
26
  name: name,
@@ -36,7 +36,8 @@ const module = defineNuxtModule({
36
36
  htmlSerializer: cleanDoubleSlashes(`~/${nuxt.options.dir.app}/prismic/htmlSerializer`),
37
37
  injectComponents: true,
38
38
  components: {},
39
- preview: "/preview"
39
+ preview: "/preview",
40
+ toolbar: true
40
41
  }),
41
42
  hooks: {},
42
43
  setup(mergedOptions, nuxt) {
@@ -49,7 +50,7 @@ const module = defineNuxtModule({
49
50
  nuxt.options.build.transpile.push(resolver.resolve("runtime"), "@nuxtjs/prismic", "@prismicio/vue");
50
51
  const proxyUserFileWithUndefinedFallback = (filename, path, extensions = ["js", "mjs", "ts"]) => {
51
52
  const resolvedFilename = `prismic/proxy/${filename}.ts`;
52
- const resolvedPath = path ? path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir) : void 0;
53
+ const resolvedPath = path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir);
53
54
  const maybeUserFile = fileExists(resolvedPath, extensions);
54
55
  if (maybeUserFile) {
55
56
  logger.info(`Using user-defined \`${filename}\` at \`${maybeUserFile.replace(nuxt.options.srcDir, "~").replace(nuxt.options.rootDir, "~~").replace(/\\/g, "/")}\``);
@@ -114,11 +115,19 @@ const module = defineNuxtModule({
114
115
  });
115
116
  });
116
117
  }
118
+ if (!mergedOptions.toolbar) {
119
+ logger.warn("`toolbar` option is disabled but `preview` is enabled. Previews won't work unless you manually load the toolbar.");
120
+ }
121
+ }
122
+ if (mergedOptions.toolbar) {
117
123
  const repositoryName = isRepositoryEndpoint(mergedOptions.endpoint) ? getRepositoryName(mergedOptions.endpoint) : mergedOptions.endpoint;
118
124
  (_b = nuxt.options.app).head || (_b.head = {});
119
125
  (_c = nuxt.options.app.head).script || (_c.script = []);
120
126
  nuxt.options.app.head.script.push({
121
- src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`
127
+ hid: "prismic-preview",
128
+ src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`,
129
+ async: true,
130
+ defer: true
122
131
  });
123
132
  }
124
133
  }
@@ -1,4 +1,4 @@
1
- import { defineNuxtPlugin, useCookie, refreshNuxtData } from "#app";
1
+ import { defineNuxtPlugin, useCookie, useRequestEvent, refreshNuxtData } from "#app";
2
2
  import NuxtLink from "#app/components/nuxt-link";
3
3
  import { createPrismic } from "@prismicio/vue";
4
4
  import client from "#build/prismic/proxy/client";
@@ -32,6 +32,7 @@ export default defineNuxtPlugin((nuxtApp) => {
32
32
  refreshNuxtData();
33
33
  }
34
34
  } catch (error) {
35
+ console.warn("Failed to parse Prismic preview cookie", error);
35
36
  }
36
37
  }
37
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/prismic",
3
- "version": "3.0.0-alpha.9",
3
+ "version": "3.0.0-rc.0",
4
4
  "description": "Easily connect your Nuxt 3 application to your content hosted on Prismic",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -38,27 +38,32 @@
38
38
  "dev:build": "nuxi build playground",
39
39
  "lint": "eslint --ext .js,.ts .",
40
40
  "prepare": "nuxi prepare playground && npm run build",
41
- "release": "npm run build && npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
42
- "release:alpha": "npm run build && npm run test && standard-version --release-as major --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
43
- "release:alpha:dry": "standard-version --release-as major --prerelease alpha --dry-run",
41
+ "release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
42
+ "release:rc": "npm run test && standard-version --release-as major --prerelease rc && git push --follow-tags && npm run build && npm publish --tag rc",
43
+ "release:rc:dry": "standard-version --release-as major --prerelease rc --dry-run",
44
44
  "release:dry": "standard-version --dry-run",
45
- "test": "npm run lint && npm run unit",
46
- "unit": "echo \"TODO: vitest & nuxt-test-utils\""
45
+ "test": "npm run lint && npm run unit && npm run build",
46
+ "unit": "vitest run --coverage",
47
+ "unit:watch": "vitest watch"
47
48
  },
48
49
  "dependencies": {
49
50
  "@nuxt/kit": "^3.0.0-rc",
50
51
  "@prismicio/client": "^6.6.1",
51
- "@prismicio/vue": "^3.0.0-beta",
52
+ "@prismicio/vue": "^3.0.0",
52
53
  "consola": "^2.15.3",
53
- "ufo": "^0.8.4"
54
+ "ufo": "^0.8.5"
54
55
  },
55
56
  "devDependencies": {
56
57
  "@nuxt/module-builder": "latest",
58
+ "@nuxt/test-utils": "npm:@nuxt/test-utils-edge@latest",
57
59
  "@nuxtjs/eslint-config-typescript": "latest",
58
- "eslint": "^8.18.0",
60
+ "c8": "^7.11.3",
61
+ "eslint": "^8.20.0",
62
+ "mock-fs": "^5.1.2",
59
63
  "nuxt": "^3.0.0-rc",
60
64
  "standard-version": "^9.5.0",
61
- "typescript": "^4.7.4"
65
+ "typescript": "^4.7.4",
66
+ "vitest": "^0.18.1"
62
67
  },
63
68
  "engines": {
64
69
  "node": ">=14.15.0"
@@ -1,4 +1,4 @@
1
- import { existsSync } from 'fs'
1
+ import { existsSync } from 'node:fs'
2
2
 
3
3
  export const fileExists = (path?: string, extensions = ['js', 'ts']): string | null => {
4
4
  if (!path) {
@@ -0,0 +1,2 @@
1
+ export { logger } from './logger'
2
+ export { fileExists } from './fileExists'
File without changes
package/src/module.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { join } from 'path'
1
+ import { join } from 'node:path'
2
2
 
3
3
  import {
4
4
  defineNuxtModule,
@@ -15,9 +15,8 @@ import { isRepositoryEndpoint, getRepositoryName } from '@prismicio/client'
15
15
  import * as prismicVue from '@prismicio/vue'
16
16
 
17
17
  import { name as pkgName, version as pkgVersion } from '../package.json'
18
+ import { logger, fileExists } from './lib'
18
19
  import type { PrismicModuleOptions } from './types'
19
- import { fileExists } from './utils'
20
- import { logger } from './logger'
21
20
 
22
21
  // Options export
23
22
  export type { PrismicModuleOptions } from './types'
@@ -39,7 +38,8 @@ export default defineNuxtModule<PrismicModuleOptions>({
39
38
  htmlSerializer: cleanDoubleSlashes(`~/${nuxt.options.dir.app}/prismic/htmlSerializer`),
40
39
  injectComponents: true,
41
40
  components: {},
42
- preview: '/preview'
41
+ preview: '/preview',
42
+ toolbar: true
43
43
  }),
44
44
  hooks: {},
45
45
  setup (mergedOptions, nuxt) {
@@ -53,11 +53,9 @@ export default defineNuxtModule<PrismicModuleOptions>({
53
53
  nuxt.options.build.transpile.push(resolver.resolve('runtime'), '@nuxtjs/prismic', '@prismicio/vue')
54
54
 
55
55
  // Add runtime user code
56
- const proxyUserFileWithUndefinedFallback = (filename: string, path?: string, extensions = ['js', 'mjs', 'ts']) => {
56
+ const proxyUserFileWithUndefinedFallback = (filename: string, path: string, extensions = ['js', 'mjs', 'ts']) => {
57
57
  const resolvedFilename = `prismic/proxy/${filename}.ts`
58
- const resolvedPath = path
59
- ? path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir)
60
- : undefined
58
+ const resolvedPath = path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir)
61
59
  const maybeUserFile = fileExists(resolvedPath, extensions)
62
60
 
63
61
  if (maybeUserFile) {
@@ -76,9 +74,9 @@ export default defineNuxtModule<PrismicModuleOptions>({
76
74
  })
77
75
  }
78
76
  }
79
- proxyUserFileWithUndefinedFallback('client', mergedOptions.client)
80
- proxyUserFileWithUndefinedFallback('linkResolver', mergedOptions.linkResolver)
81
- proxyUserFileWithUndefinedFallback('htmlSerializer', mergedOptions.htmlSerializer)
77
+ proxyUserFileWithUndefinedFallback('client', mergedOptions.client!)
78
+ proxyUserFileWithUndefinedFallback('linkResolver', mergedOptions.linkResolver!)
79
+ proxyUserFileWithUndefinedFallback('htmlSerializer', mergedOptions.htmlSerializer!)
82
80
 
83
81
  // Expose options through public runtime config
84
82
  nuxt.options.runtimeConfig.public ||= {} as typeof nuxt.options.runtimeConfig.public
@@ -143,6 +141,12 @@ export default defineNuxtModule<PrismicModuleOptions>({
143
141
  })
144
142
  }
145
143
 
144
+ if (!mergedOptions.toolbar) {
145
+ logger.warn('`toolbar` option is disabled but `preview` is enabled. Previews won\'t work unless you manually load the toolbar.')
146
+ }
147
+ }
148
+
149
+ if (mergedOptions.toolbar) {
146
150
  // Add toolbar
147
151
  const repositoryName = isRepositoryEndpoint(mergedOptions.endpoint)
148
152
  ? getRepositoryName(mergedOptions.endpoint)
@@ -150,7 +154,10 @@ export default defineNuxtModule<PrismicModuleOptions>({
150
154
  nuxt.options.app.head ||= {}
151
155
  nuxt.options.app.head.script ||= []
152
156
  nuxt.options.app.head.script.push({
153
- src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`
157
+ hid: 'prismic-preview',
158
+ src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`,
159
+ async: true,
160
+ defer: true
154
161
  })
155
162
  }
156
163
  }
@@ -1,4 +1,4 @@
1
- import { defineNuxtPlugin, useCookie, refreshNuxtData } from '#app'
1
+ import { defineNuxtPlugin, useCookie, useRequestEvent, refreshNuxtData } from '#app'
2
2
  import NuxtLink from '#app/components/nuxt-link'
3
3
 
4
4
  import { createPrismic } from '@prismicio/vue'
@@ -59,7 +59,8 @@ export default defineNuxtPlugin((nuxtApp) => {
59
59
  refreshNuxtData()
60
60
  }
61
61
  } catch (error) {
62
- // noop
62
+ // eslint-disable-next-line no-console
63
+ console.warn('Failed to parse Prismic preview cookie', error)
63
64
  }
64
65
  }
65
66
  }
package/src/types.ts CHANGED
@@ -6,4 +6,5 @@ export type PrismicModuleOptions = Omit<PrismicPluginOptions, 'endpoint' | 'clie
6
6
  linkResolver?: string;
7
7
  htmlSerializer?: string;
8
8
  preview?: string | false;
9
+ toolbar?: boolean;
9
10
  };