@docusaurus/plugin-vercel-analytics 0.0.0-5831
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/LICENSE +21 -0
- package/README.md +7 -0
- package/lib/analytics.d.ts +1 -0
- package/lib/analytics.js +14 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +24 -0
- package/lib/options.d.ts +8 -0
- package/lib/options.js +25 -0
- package/package.json +37 -0
- package/src/analytics.ts +17 -0
- package/src/index.ts +32 -0
- package/src/options.ts +42 -0
- package/src/types.d.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/analytics.js
ADDED
|
@@ -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;
|
|
10
|
+
export { validateOptions } from './options';
|
|
11
|
+
export type { PluginOptions, Options };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
function pluginVercelAnalytics(context, options) {
|
|
11
|
+
const isProd = process.env.NODE_ENV === 'production';
|
|
12
|
+
return {
|
|
13
|
+
name: 'docusaurus-plugin-vercel-analytics',
|
|
14
|
+
getClientModules() {
|
|
15
|
+
return isProd ? ['./analytics'] : [];
|
|
16
|
+
},
|
|
17
|
+
contentLoaded({ actions }) {
|
|
18
|
+
actions.setGlobalData(options);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.default = pluginVercelAnalytics;
|
|
23
|
+
var options_1 = require("./options");
|
|
24
|
+
Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
|
package/lib/options.d.ts
ADDED
|
@@ -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
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@docusaurus/plugin-vercel-analytics",
|
|
3
|
+
"version": "0.0.0-5831",
|
|
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/facebook/docusaurus.git",
|
|
17
|
+
"directory": "packages/docusaurus-plugin-vercel-analytics"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@docusaurus/core": "0.0.0-5831",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-5831",
|
|
23
|
+
"@docusaurus/types": "0.0.0-5831",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-5831",
|
|
25
|
+
"@docusaurus/utils-validation": "0.0.0-5831",
|
|
26
|
+
"@vercel/analytics": "^1.1.1",
|
|
27
|
+
"tslib": "^2.6.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": "^18.0.0",
|
|
31
|
+
"react-dom": "^18.0.0"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18.0"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "ae029ea17949629c9ab651e035696f21660b0330"
|
|
37
|
+
}
|
package/src/analytics.ts
ADDED
|
@@ -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,32 @@
|
|
|
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 {
|
|
15
|
+
const isProd = process.env.NODE_ENV === 'production';
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
name: 'docusaurus-plugin-vercel-analytics',
|
|
19
|
+
|
|
20
|
+
getClientModules() {
|
|
21
|
+
return isProd ? ['./analytics'] : [];
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
contentLoaded({actions}) {
|
|
25
|
+
actions.setGlobalData(options);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {validateOptions} from './options';
|
|
31
|
+
|
|
32
|
+
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