@azerion/bunosaurus-plugin-vercel-analytics 0.0.0-stage → 4.0.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
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # `@docusaurus/plugin-vercel-analytics`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [Vercel analytics](https://vercel.com/docs/analytics) plugin for Docusaurus.
4
+
5
+ ## Usage
6
+
7
+ See [plugin-vercel-analytics documentation](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-vercel-analytics).
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { inject } from '@vercel/analytics';
8
+ import globalData from '@generated/globalData';
9
+ const { debug, mode } = globalData['docusaurus-plugin-vercel-analytics']
10
+ ?.default;
11
+ inject({
12
+ mode,
13
+ debug,
14
+ });
package/lib/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { LoadContext, Plugin } from '@docusaurus/types';
8
+ import type { PluginOptions, Options } from './options';
9
+ export default function pluginVercelAnalytics(context: LoadContext, options: PluginOptions): Plugin | null;
10
+ export { validateOptions } from './options';
11
+ export type { PluginOptions, Options };
package/lib/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validateOptions = void 0;
10
+ exports.default = pluginVercelAnalytics;
11
+ function pluginVercelAnalytics(context, options) {
12
+ if (process.env.NODE_ENV !== 'production') {
13
+ return null;
14
+ }
15
+ return {
16
+ name: 'docusaurus-plugin-vercel-analytics',
17
+ getClientModules() {
18
+ return ['./analytics'];
19
+ },
20
+ contentLoaded({ actions }) {
21
+ actions.setGlobalData(options);
22
+ },
23
+ };
24
+ }
25
+ var options_1 = require("./options");
26
+ Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
@@ -0,0 +1,8 @@
1
+ import type { OptionValidationContext } from '@docusaurus/types';
2
+ export type PluginOptions = {
3
+ id: string;
4
+ mode: 'auto' | 'production' | 'development' | undefined;
5
+ debug: boolean | undefined;
6
+ };
7
+ export type Options = Partial<PluginOptions>;
8
+ export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
package/lib/options.js ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { DEFAULT_PLUGIN_ID } from '@docusaurus/utils';
8
+ import logger from '@docusaurus/logger';
9
+ import { Joi } from '@docusaurus/utils-validation';
10
+ const pluginOptionsSchema = Joi.object({
11
+ mode: Joi.string().valid('auto', 'production', 'development').optional(),
12
+ debug: Joi.boolean().optional(),
13
+ });
14
+ // We can't validate this through the schema
15
+ // Docusaurus core auto registers the id field to the schema already
16
+ function ensureNoMultiInstance(options) {
17
+ if (options?.id && options.id !== DEFAULT_PLUGIN_ID) {
18
+ throw new Error(logger.interpolate `You site uses the Vercel Analytics plugin with a custom plugin id (name=${options.id}).
19
+ But this plugin is only supposed to be used at most once per site. Therefore providing a custom plugin id is unsupported.`);
20
+ }
21
+ }
22
+ export function validateOptions({ validate, options, }) {
23
+ ensureNoMultiInstance(options);
24
+ return validate(pluginOptionsSchema, options);
25
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@azerion/bunosaurus-plugin-vercel-analytics",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.0.0",
4
+ "description": "Global vercel analytics plugin for Docusaurus.",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc --build",
12
+ "watch": "tsc --build --watch"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/azerion/bunosaurus.git",
17
+ "directory": "packages/docusaurus-plugin-vercel-analytics"
18
+ },
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@docusaurus/core": "npm:@azerion/bunosaurus-core@4.0.0",
22
+ "@docusaurus/logger": "npm:@azerion/bunosaurus-logger@4.0.0",
23
+ "@docusaurus/module-type-aliases": "npm:@azerion/bunosaurus-module-type-aliases@4.0.0",
24
+ "@docusaurus/types": "npm:@azerion/bunosaurus-types@4.0.0",
25
+ "@docusaurus/utils": "npm:@azerion/bunosaurus-utils@4.0.0",
26
+ "@docusaurus/utils-validation": "npm:@azerion/bunosaurus-utils-validation@4.0.0",
27
+ "@vercel/analytics": "^2.0.1",
28
+ "tslib": "^2.8.1"
29
+ },
30
+ "peerDependencies": {
31
+ "react": "^19.3.0",
32
+ "react-dom": "^19.3.0"
33
+ },
34
+ "engines": {
35
+ "bun": ">=1.4.1"
36
+ }
37
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import {inject} from '@vercel/analytics';
8
+ import globalData from '@generated/globalData';
9
+ import type {PluginOptions} from './options';
10
+
11
+ const {debug, mode} = globalData['docusaurus-plugin-vercel-analytics']
12
+ ?.default as PluginOptions;
13
+
14
+ inject({
15
+ mode,
16
+ debug,
17
+ });
package/src/index.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import type {LoadContext, Plugin} from '@docusaurus/types';
9
+ import type {PluginOptions, Options} from './options';
10
+
11
+ export default function pluginVercelAnalytics(
12
+ context: LoadContext,
13
+ options: PluginOptions,
14
+ ): Plugin | null {
15
+ if (process.env.NODE_ENV !== 'production') {
16
+ return null;
17
+ }
18
+ return {
19
+ name: 'docusaurus-plugin-vercel-analytics',
20
+
21
+ getClientModules() {
22
+ return ['./analytics'];
23
+ },
24
+
25
+ contentLoaded({actions}) {
26
+ actions.setGlobalData(options);
27
+ },
28
+ };
29
+ }
30
+
31
+ export {validateOptions} from './options';
32
+
33
+ export type {PluginOptions, Options};
package/src/options.ts ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
8
+ import logger from '@docusaurus/logger';
9
+ import {Joi} from '@docusaurus/utils-validation';
10
+ import type {OptionValidationContext} from '@docusaurus/types';
11
+
12
+ export type PluginOptions = {
13
+ id: string;
14
+ mode: 'auto' | 'production' | 'development' | undefined;
15
+ debug: boolean | undefined;
16
+ };
17
+
18
+ export type Options = Partial<PluginOptions>;
19
+
20
+ const pluginOptionsSchema = Joi.object<PluginOptions>({
21
+ mode: Joi.string().valid('auto', 'production', 'development').optional(),
22
+ debug: Joi.boolean().optional(),
23
+ });
24
+
25
+ // We can't validate this through the schema
26
+ // Docusaurus core auto registers the id field to the schema already
27
+ function ensureNoMultiInstance(options: Options) {
28
+ if (options?.id && options.id !== DEFAULT_PLUGIN_ID) {
29
+ throw new Error(
30
+ logger.interpolate`You site uses the Vercel Analytics plugin with a custom plugin id (name=${options.id}).
31
+ But this plugin is only supposed to be used at most once per site. Therefore providing a custom plugin id is unsupported.`,
32
+ );
33
+ }
34
+ }
35
+
36
+ export function validateOptions({
37
+ validate,
38
+ options,
39
+ }: OptionValidationContext<Options, PluginOptions>): PluginOptions {
40
+ ensureNoMultiInstance(options);
41
+ return validate(pluginOptionsSchema, options);
42
+ }
package/src/types.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ /// <reference types="@docusaurus/module-type-aliases" />