-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(plugin-vercel-analytics): add new vercel analytics plugin #9687
Merged
Merged
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
aace0bc
wip: vercel analytics
OzakIOne e6d2bf8
wip
OzakIOne 9dfea26
enable plugin without options
OzakIOne 76dd26c
add vercel documentation
OzakIOne 0164c90
remove from preset
OzakIOne 522f73e
wip
OzakIOne fcabc25
remove from preset
OzakIOne 16242ff
feat: plugin options in config
OzakIOne 6dc660e
feat: config validation
OzakIOne 772f1bf
feat: multi instance check
OzakIOne 9461ad7
remove log
OzakIOne 9d761ee
review
OzakIOne 3847883
review
OzakIOne 67576cb
export validate options
OzakIOne 097f2b4
adds doc
OzakIOne b243a96
fix doc
OzakIOne 3c1d5b1
refactor: review
OzakIOne 9730346
feat: tests
OzakIOne db11c27
wip: tests
OzakIOne 065f686
fix docs table issues
slorber b5a2efb
use DEFAULT_PLUGIN_ID constant
slorber f85345b
Improve APITable error message in case of invalid Markdown table
slorber 42bb53b
Change way to reject usage of custom plugin id with Vercel Analytics …
slorber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.tsbuildinfo* | ||
tsconfig* | ||
__tests__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# `@docusaurus/plugin-vercel-analytics` | ||
|
||
[Vercel analytics](https://vercel.com/docs/analytics) plugin for Docusaurus. | ||
|
||
## Usage | ||
|
||
TODO: add documentation | ||
|
||
See [plugin-vercel-analytics documentation](). | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "@docusaurus/plugin-vercel-analytics", | ||
"version": "3.0.0", | ||
"description": "Global vercel analytics plugin for Docusaurus.", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build": "tsc --build", | ||
"watch": "tsc --build --watch" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/facebook/docusaurus.git", | ||
"directory": "packages/docusaurus-plugin-vercel-analytics" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@docusaurus/core": "3.0.0", | ||
"@docusaurus/types": "3.0.0", | ||
"@docusaurus/utils-validation": "3.0.0", | ||
"@docusaurus/utils": "3.0.0", | ||
"@vercel/analytics": "^1.1.1", | ||
"tslib": "^2.6.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=18.0" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/docusaurus-plugin-vercel-analytics/src/analytics.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import {inject} from '@vercel/analytics'; | ||
import globalData from '@generated/globalData'; | ||
import type {PluginOptions} from '@docusaurus/plugin-vercel-analytics'; | ||
|
||
const {debug, mode} = globalData['docusaurus-plugin-vercel-analytics'] | ||
?.default as PluginOptions; | ||
|
||
slorber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
inject({ | ||
mode, | ||
debug, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {Joi} from '@docusaurus/utils-validation'; | ||
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils'; | ||
import type { | ||
LoadContext, | ||
Plugin, | ||
OptionValidationContext, | ||
} from '@docusaurus/types'; | ||
import type {PluginOptions, Options} from './options'; | ||
|
||
export default function pluginVercelAnalytics( | ||
context: LoadContext, | ||
options: PluginOptions, | ||
): Plugin { | ||
const isProd = process.env.NODE_ENV === 'production'; | ||
|
||
return { | ||
name: 'docusaurus-plugin-vercel-analytics', | ||
|
||
getClientModules() { | ||
return isProd ? ['./analytics'] : []; | ||
}, | ||
|
||
contentLoaded({actions}) { | ||
console.log('options:', options); | ||
if (options.id !== DEFAULT_PLUGIN_ID) { | ||
throw new Error( | ||
`You cannot use a custom plugin id option with the Vercel Analytics plugin`, | ||
); | ||
} | ||
OzakIOne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
actions.setGlobalData(options); | ||
}, | ||
}; | ||
} | ||
|
||
export const DEFAULT_OPTIONS: Partial<PluginOptions> = { | ||
mode: 'production', | ||
debug: false, | ||
}; | ||
|
||
const pluginOptionsSchema = Joi.object<PluginOptions>({ | ||
mode: Joi.string() | ||
.valid('auto', 'production', 'development') | ||
.default(DEFAULT_OPTIONS.mode), | ||
debug: Joi.boolean().default(DEFAULT_OPTIONS.debug), | ||
}); | ||
|
||
export function validateOptions({ | ||
validate, | ||
options, | ||
}: OptionValidationContext<Options, PluginOptions>): PluginOptions { | ||
return validate(pluginOptionsSchema, options); | ||
} | ||
OzakIOne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export type {PluginOptions, Options}; |
14 changes: 14 additions & 0 deletions
14
packages/docusaurus-plugin-vercel-analytics/src/options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export type PluginOptions = { | ||
id: string; | ||
mode: 'auto' | 'production' | 'development'; | ||
debug: boolean; | ||
}; | ||
|
||
export type Options = Partial<PluginOptions>; |
21 changes: 21 additions & 0 deletions
21
packages/docusaurus-plugin-vercel-analytics/src/plugin-vercel-analytics.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
declare module '@docusaurus/plugin-vercel-analytics' { | ||
OzakIOne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export type PluginOptions = { | ||
/** | ||
* Turn debug mode on | ||
*/ | ||
debug?: boolean; | ||
/** | ||
* TODO add description | ||
*/ | ||
mode: 'auto' | 'development' | 'production'; | ||
}; | ||
|
||
export type Options = Partial<PluginOptions>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
/// <reference types="@docusaurus/module-type-aliases" /> |
16 changes: 16 additions & 0 deletions
16
packages/docusaurus-plugin-vercel-analytics/tsconfig.client.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": false, | ||
"composite": true, | ||
"incremental": true, | ||
"tsBuildInfoFile": "./lib/.tsbuildinfo-client", | ||
"moduleResolution": "bundler", | ||
"module": "esnext", | ||
"target": "esnext", | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": ["src/analytics.ts", "src/*.d.ts"], | ||
"exclude": ["**/__tests__/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"references": [{"path": "./tsconfig.client.json"}], | ||
"compilerOptions": { | ||
"noEmit": false, | ||
"incremental": true, | ||
"tsBuildInfoFile": "./lib/.tsbuildinfo", | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": ["src"], | ||
"exclude": ["src/analytics.ts", "**/__tests__/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need plugin docs