Skip to content

Commit a809cb5

Browse files
committed
feat: support configurable deployment basepath
1 parent 68d0d13 commit a809cb5

21 files changed

+2393
-1515
lines changed

apps/remix/.eslintrc.cjs

+81-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,84 @@
1+
/**
2+
* This is intended to be a basic starting point for linting in your app.
3+
* It relies on recommended configs out of the box for simplicity, but you can
4+
* and should modify this configuration to best suit your team's needs.
5+
*/
6+
17
/** @type {import('eslint').Linter.Config} */
28
module.exports = {
3-
extends: ['@remix-run/eslint-config', '@remix-run/eslint-config/node'],
9+
root: true,
10+
parserOptions: {
11+
ecmaVersion: 'latest',
12+
sourceType: 'module',
13+
ecmaFeatures: {
14+
jsx: true,
15+
},
16+
},
17+
env: {
18+
browser: true,
19+
commonjs: true,
20+
es6: true,
21+
},
22+
ignorePatterns: ['!**/.server', '!**/.client'],
23+
24+
// Base config
25+
extends: ['eslint:recommended'],
26+
27+
overrides: [
28+
// React
29+
{
30+
files: ['**/*.{js,jsx,ts,tsx}'],
31+
plugins: ['react', 'jsx-a11y'],
32+
extends: [
33+
'plugin:react/recommended',
34+
'plugin:react/jsx-runtime',
35+
'plugin:react-hooks/recommended',
36+
'plugin:jsx-a11y/recommended',
37+
],
38+
settings: {
39+
react: {
40+
version: 'detect',
41+
},
42+
formComponents: ['Form'],
43+
linkComponents: [
44+
{ name: 'Link', linkAttribute: 'to' },
45+
{ name: 'NavLink', linkAttribute: 'to' },
46+
],
47+
'import/resolver': {
48+
typescript: {},
49+
},
50+
},
51+
},
52+
53+
// Typescript
54+
{
55+
files: ['**/*.{ts,tsx}'],
56+
plugins: ['@typescript-eslint', 'import'],
57+
parser: '@typescript-eslint/parser',
58+
settings: {
59+
'import/internal-regex': '^~/',
60+
'import/resolver': {
61+
node: {
62+
extensions: ['.ts', '.tsx'],
63+
},
64+
typescript: {
65+
alwaysTryTypes: true,
66+
},
67+
},
68+
},
69+
extends: [
70+
'plugin:@typescript-eslint/recommended',
71+
'plugin:import/recommended',
72+
'plugin:import/typescript',
73+
],
74+
},
75+
76+
// Node
77+
{
78+
files: ['.eslintrc.cjs'],
79+
env: {
80+
node: true,
81+
},
82+
},
83+
],
484
};

apps/remix/.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
node_modules
22

3+
/.cache
34
/build
4-
/public/build
55
.env
6-
.cache

apps/remix/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
11
# Remix Vercel Web Analytics Test
2+
3+
## Setup
4+
5+
This application was created with the following commands:
6+
7+
- `cd apps`
8+
- `pnpx create-remix@latest remix` (answers: no git, no dependencies installation)
9+
- `cd remix`
10+
- TODO
11+
- edit package.json to add `"@vercel/analytics": "workspace:*"`
12+
- `pnpm i`
13+
14+
## Usage
15+
16+
Start it with `pnpm -F remix dev` and browse to [http://localhost:5173](http://localhost:5173)

apps/remix/app/root.tsx

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import { cssBundleHref } from '@remix-run/css-bundle';
2-
import type { LinksFunction } from '@remix-run/node';
31
import {
42
Links,
5-
LiveReload,
63
Meta,
74
Outlet,
85
Scripts,
96
ScrollRestoration,
107
} from '@remix-run/react';
118
import { Analytics } from '@vercel/analytics/remix';
129

13-
export const links: LinksFunction = () => [
14-
...(cssBundleHref ? [{ rel: 'stylesheet', href: cssBundleHref }] : []),
15-
];
16-
17-
export default function App() {
10+
export function Layout({ children }: { children: React.ReactNode }) {
1811
return (
1912
<html lang="en">
2013
<head>
@@ -25,11 +18,14 @@ export default function App() {
2518
</head>
2619
<body>
2720
<Analytics />
28-
<Outlet />
21+
{children}
2922
<ScrollRestoration />
3023
<Scripts />
31-
<LiveReload />
3224
</body>
3325
</html>
3426
);
3527
}
28+
29+
export default function App() {
30+
return <Outlet />;
31+
}

apps/remix/app/routes/blog.$slug.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { json, type LoaderFunctionArgs } from '@remix-run/node';
22
import { Link, useLoaderData } from '@remix-run/react';
3-
import { track } from '@vercel/analytics';
43

54
export const loader = async ({ params }: LoaderFunctionArgs) => {
65
return json({ slug: params.slug });

apps/remix/package.json

+27-17
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
11
{
22
"name": "remix",
33
"private": true,
4+
"sideEffects": false,
45
"type": "module",
56
"scripts": {
6-
"build": "remix build",
7-
"dev": "remix dev --manual",
8-
"start": "remix-serve ./build/index.js",
7+
"build": "remix vite:build",
8+
"dev": "remix vite:dev",
9+
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
10+
"start": "remix-serve ./build/server/index.js",
911
"typecheck": "tsc"
1012
},
1113
"dependencies": {
12-
"@remix-run/css-bundle": "^2.5.0",
13-
"@remix-run/node": "^2.5.0",
14-
"@remix-run/react": "^2.5.0",
15-
"@remix-run/serve": "^2.5.0",
16-
"@remix-run/server-runtime": "^2.5.0",
14+
"@remix-run/node": "latest",
15+
"@remix-run/react": "latest",
16+
"@remix-run/serve": "latest",
1717
"@vercel/analytics": "workspace:*",
18-
"@vercel/remix": "2.5.0",
19-
"isbot": "^3.6.3",
18+
"isbot": "^4.1.0",
2019
"react": "^18.2.0",
2120
"react-dom": "^18.2.0"
2221
},
2322
"devDependencies": {
24-
"@remix-run/dev": "^2.5.0",
25-
"@remix-run/eslint-config": "^2.5.0",
26-
"@types/react": "^18.0.25",
27-
"@types/react-dom": "^18.0.8",
28-
"eslint": "^8.56.0",
29-
"typescript": "^5.3.3"
23+
"@remix-run/dev": "latest",
24+
"@types/react": "^18.2.20",
25+
"@types/react-dom": "^18.2.7",
26+
"@typescript-eslint/eslint-plugin": "^6.7.4",
27+
"@typescript-eslint/parser": "^6.7.4",
28+
"autoprefixer": "^10.4.19",
29+
"eslint": "^8.38.0",
30+
"eslint-import-resolver-typescript": "^3.6.1",
31+
"eslint-plugin-import": "^2.28.1",
32+
"eslint-plugin-jsx-a11y": "^6.7.1",
33+
"eslint-plugin-react": "^7.33.2",
34+
"eslint-plugin-react-hooks": "^4.6.0",
35+
"postcss": "^8.4.38",
36+
"tailwindcss": "^3.4.4",
37+
"typescript": "^5.1.6",
38+
"vite": "^5.1.0",
39+
"vite-tsconfig-paths": "^4.2.1"
3040
},
3141
"engines": {
32-
"node": ">=18"
42+
"node": ">=20.0.0"
3343
}
3444
}

apps/remix/remix.config.js

-5
This file was deleted.

apps/remix/remix.env.d.ts

-2
This file was deleted.

apps/remix/tsconfig.json

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
{
2-
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
2+
"include": [
3+
"**/*.ts",
4+
"**/*.tsx",
5+
"**/.server/**/*.ts",
6+
"**/.server/**/*.tsx",
7+
"**/.client/**/*.ts",
8+
"**/.client/**/*.tsx"
9+
],
310
"compilerOptions": {
4-
"lib": ["DOM", "DOM.Iterable", "ES2019"],
11+
"lib": ["DOM", "DOM.Iterable", "ES2022"],
12+
"types": ["@remix-run/node", "vite/client"],
513
"isolatedModules": true,
614
"esModuleInterop": true,
715
"jsx": "react-jsx",
16+
"module": "ESNext",
817
"moduleResolution": "Bundler",
918
"resolveJsonModule": true,
1019
"target": "ES2022",
1120
"strict": true,
1221
"allowJs": true,
22+
"skipLibCheck": true,
1323
"forceConsistentCasingInFileNames": true,
1424
"baseUrl": ".",
1525
"paths": {
1626
"~/*": ["./app/*"]
1727
},
1828

19-
// Remix takes care of building everything in `remix build`.
29+
// Vite takes care of building everything, not tsc.
2030
"noEmit": true
2131
}
2232
}

apps/remix/vite.config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { vitePlugin as remix } from '@remix-run/dev';
2+
import { defineConfig } from 'vite';
3+
4+
export default defineConfig({
5+
plugins: [remix()],
6+
});

packages/web/jest.setup.ts

-12
This file was deleted.

packages/web/package.json

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vercel/analytics",
3-
"version": "1.5.0-canary.1",
3+
"version": "1.5.0-canary.2",
44
"description": "Gain real-time traffic insights with Vercel Web Analytics",
55
"keywords": [
66
"analytics",
@@ -94,7 +94,7 @@
9494
"dev": "pnpm copy-astro && tsup --watch",
9595
"lint": "eslint .",
9696
"lint-fix": "eslint . --fix",
97-
"test": "jest",
97+
"test": "vitest watch",
9898
"type-check": "tsc --noEmit"
9999
},
100100
"eslintConfig": {
@@ -109,19 +109,16 @@
109109
]
110110
},
111111
"devDependencies": {
112-
"@jest/globals": "^29.7.0",
113-
"@swc/core": "^1.8.0",
114-
"@swc/jest": "^0.2.37",
112+
"@swc/core": "^1.9.2",
115113
"@testing-library/jest-dom": "^6.6.3",
116114
"@testing-library/react": "^16.0.1",
117-
"@types/node": "^20.17.6",
115+
"@types/node": "^22.9.0",
118116
"@types/react": "^18.3.12",
119117
"@vercel/eslint-config": "workspace:0.0.0",
120-
"jest": "^29.7.0",
121-
"jest-environment-jsdom": "^29.7.0",
122118
"server-only": "^0.0.1",
123119
"svelte": "^5.1.10",
124-
"tsup": "7.1.0",
120+
"tsup": "8.3.5",
121+
"vitest": "^2.1.5",
125122
"vue": "^3.5.12",
126123
"vue-router": "^4.4.5"
127124
},

packages/web/src/generic.test.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, it, expect, jest } from '@jest/globals';
1+
import { beforeEach, describe, it, expect, vi } from 'vitest';
22
import { inject, track } from './generic';
33
import type { AllowedPropertyValues, Mode } from './types';
44

@@ -7,7 +7,10 @@ describe.each([
77
mode: 'development',
88
file: 'https://va.vercel-scripts.com/v1/script.debug.js',
99
},
10-
{ mode: 'production', file: 'http://localhost/_vercel/insights/script.js' },
10+
{
11+
mode: 'production',
12+
file: 'http://localhost:3000/_vercel/insights/script.js',
13+
},
1114
] as { mode: Mode; file: string }[])('in $mode mode', ({ mode, file }) => {
1215
describe('inject', () => {
1316
it('adds the script tag correctly', () => {
@@ -49,7 +52,7 @@ describe.each([
4952
});
5053

5154
it('should strip data for nested objects', () => {
52-
jest.spyOn(global.console, 'error').mockImplementation(() => void 0);
55+
vi.spyOn(global.console, 'error').mockImplementation(() => void 0);
5356

5457
const name = 'custom event';
5558
const data = { string: 'string', number: 1 };
@@ -59,10 +62,9 @@ describe.each([
5962
});
6063

6164
if (mode === 'development') {
62-
// eslint-disable-next-line jest/no-conditional-expect, no-console -- only in development
65+
// eslint-disable-next-line no-console -- only in development
6366
expect(console.error).toHaveBeenCalledTimes(1);
6467
} else {
65-
// eslint-disable-next-line jest/no-conditional-expect -- only in production
6668
expect(window.vaq?.[0]).toEqual(['event', { name, data }]);
6769
}
6870
});

0 commit comments

Comments
 (0)