@nuxtjs/prismic 3.0.0-alpha.8 → 3.0.0-rc.1

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,8 +3,8 @@
3
3
  Replace all on all files (README.md, CONTRIBUTING.md, bug_report.md, package.json):
4
4
  - @nuxtjs/prismic
5
5
  - Easily connect your Nuxt 3 application to your content hosted on Prismic
6
- - nuxt-community/prismic-module
7
- - prismic-module
6
+ - nuxt-modules/prismic
7
+ - prismic
8
8
 
9
9
  -->
10
10
 
@@ -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:
@@ -76,9 +76,9 @@ Whether you're helping us fix bugs, improve the docs, or spread the word, we'd l
76
76
  <!-- TODO: Replace link with a more useful one if available -->
77
77
 
78
78
  [forum-question]: https://community.prismic.io
79
- [repo-bug-report]: https://github.com/nuxt-community/prismic-module/issues/new?assignees=&labels=bug&template=bug_report.md&title=
80
- [repo-feature-request]: https://github.com/nuxt-community/prismic-module/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=
81
- [repo-pull-requests]: https://github.com/nuxt-community/prismic-module/pulls
79
+ [repo-bug-report]: https://github.com/nuxt-modules/prismic/issues/new?assignees=&labels=bug&template=bug_report.md&title=
80
+ [repo-feature-request]: https://github.com/nuxt-modules/prismic/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=
81
+ [repo-pull-requests]: https://github.com/nuxt-modules/prismic/pulls
82
82
 
83
83
  <!-- Badges -->
84
84
 
@@ -86,10 +86,10 @@ Whether you're helping us fix bugs, improve the docs, or spread the word, we'd l
86
86
  [npm-version-href]: https://npmjs.com/package/@nuxtjs/prismic
87
87
  [npm-downloads-src]: https://img.shields.io/npm/dm/@nuxtjs/prismic.svg
88
88
  [npm-downloads-href]: https://npmjs.com/package/@nuxtjs/prismic
89
- [github-actions-ci-src]: https://github.com/nuxt-community/prismic-module/workflows/ci/badge.svg
90
- [github-actions-ci-href]: https://github.com/nuxt-community/prismic-module/actions?query=workflow%3Aci
91
- [codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/prismic-module.svg
92
- [codecov-href]: https://codecov.io/gh/nuxt-community/prismic-module
89
+ [github-actions-ci-src]: https://github.com/nuxt-modules/prismic/workflows/ci/badge.svg
90
+ [github-actions-ci-href]: https://github.com/nuxt-modules/prismic/actions?query=workflow%3Aci
91
+ [codecov-src]: https://img.shields.io/codecov/c/github/nuxt-modules/prismic.svg
92
+ [codecov-href]: https://codecov.io/gh/nuxt-modules/prismic
93
93
  [conventional-commits-src]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg
94
94
  [conventional-commits-href]: https://conventionalcommits.org
95
95
  [license-src]: https://img.shields.io/npm/l/@nuxtjs/prismic.svg
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,8 +1,8 @@
1
1
  {
2
2
  "name": "@nuxtjs/prismic",
3
- "version": "3.0.0-alpha.8",
3
+ "version": "3.0.0-rc.1",
4
4
  "configKey": "prismic",
5
5
  "compatibility": {
6
- "nuxt": "^3.0.0"
6
+ "nuxt": "^3.0.0-rc.6"
7
7
  }
8
8
  }
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.8";
10
+ const version = "3.0.0-rc.1";
11
+
12
+ const logger = consola.withScope("nuxt:prismic");
11
13
 
12
14
  const fileExists = (path, extensions = ["js", "ts"]) => {
13
15
  if (!path) {
@@ -19,14 +21,12 @@ 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,
27
27
  version: version,
28
28
  configKey: "prismic",
29
- compatibility: { nuxt: "^3.0.0" }
29
+ compatibility: { nuxt: "^3.0.0-rc.6" }
30
30
  },
31
31
  defaults: (nuxt) => ({
32
32
  endpoint: "",
@@ -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,13 +1,11 @@
1
- import { defineNuxtPlugin } from "#app";
1
+ import { defineNuxtPlugin, refreshNuxtData } from "#app";
2
2
  const pkgName = "@nuxtjs/prismic";
3
3
  export default defineNuxtPlugin((nuxtApp) => {
4
4
  const mergedOptions = nuxtApp.payload.config[pkgName] ?? nuxtApp.payload.config.public[pkgName] ?? {};
5
5
  if (mergedOptions.preview) {
6
6
  window.addEventListener("prismicPreviewUpdate", (event) => {
7
- if (refreshNuxtData) {
8
- event.preventDefault();
9
- refreshNuxtData();
10
- }
7
+ event.preventDefault();
8
+ refreshNuxtData();
11
9
  });
12
10
  }
13
11
  });
@@ -1,4 +1,4 @@
1
- import { defineNuxtPlugin } 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.8",
3
+ "version": "3.0.0-rc.1",
4
4
  "description": "Easily connect your Nuxt 3 application to your content hosted on Prismic",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "ssh://git@github.com/nuxt-community/prismic-module.git"
15
+ "url": "ssh://git@github.com/nuxt-modules/prismic.git"
16
16
  },
17
17
  "license": "MIT",
18
18
  "author": "Nuxt.js Community",
@@ -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'
@@ -29,7 +28,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
29
28
  name: pkgName,
30
29
  version: pkgVersion,
31
30
  configKey: 'prismic',
32
- compatibility: { nuxt: '^3.0.0' }
31
+ compatibility: { nuxt: '^3.0.0-rc.6' }
33
32
  },
34
33
  defaults: nuxt => ({
35
34
  endpoint: '',
@@ -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 } from '#app'
1
+ import { defineNuxtPlugin, refreshNuxtData } from '#app'
2
2
 
3
3
  // import { name as pkgName } from '../../package.json'
4
4
  import { PrismicModuleOptions } from '../types'
@@ -15,10 +15,8 @@ export default defineNuxtPlugin((nuxtApp) => {
15
15
  // Hot reload preview updates
16
16
  if (mergedOptions.preview) {
17
17
  window.addEventListener('prismicPreviewUpdate', (event) => {
18
- if (refreshNuxtData) {
19
- event.preventDefault()
20
- refreshNuxtData()
21
- }
18
+ event.preventDefault()
19
+ refreshNuxtData()
22
20
  })
23
21
  }
24
22
  })
@@ -1,4 +1,4 @@
1
- import { defineNuxtPlugin } 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
  };