Skip to content

Commit

Permalink
chore!: Switch Next.js to peer dependency (#339)
Browse files Browse the repository at this point in the history
Closes #336

Next.js uses symbols on their objects, which breaks TypeScript compilation if you have version mismatches. This moves it to a peer dependency so the application version is always used. The peer dep version range is anything from 13, 14, and up because I don't really like putting an upper cap on it (what if Next.js 15 releases and it doesn't break our usage... it shouldn't cause churn for our users).
  • Loading branch information
blaine-arcjet authored Mar 11, 2024
1 parent f398c28 commit cb82883
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions arcjet-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
"dependencies": {
"@arcjet/ip": "1.0.0-alpha.9",
"@connectrpc/connect-web": "1.4.0",
"arcjet": "1.0.0-alpha.9",
"next": "14.1.1"
"arcjet": "1.0.0-alpha.9"
},
"peerDependencies": {
"next": ">=13"
},
"devDependencies": {
"@arcjet/eslint-config": "1.0.0-alpha.9",
Expand Down
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion rollup-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function createConfig(root, { plugins = [] } = {}) {
const pkg = JSON.parse(fs.readFileSync(packageJson));
const dependencies = Object.keys(pkg.dependencies ?? {});
const devDependencies = Object.keys(pkg.devDependencies ?? {});
const peerDependencies = Object.keys(pkg.peerDependencies ?? {});

function isDependency(id) {
return dependencies.some((dep) => id.startsWith(dep));
Expand All @@ -29,6 +30,10 @@ export function createConfig(root, { plugins = [] } = {}) {
return devDependencies.some((dep) => id.startsWith(dep));
}

function isPeerDependency(id) {
return peerDependencies.some((dep) => id.startsWith(dep));
}

const rootDir = fileURLToPath(new URL(".", root));
const testDir = fileURLToPath(new URL("test/", root));

Expand Down Expand Up @@ -67,7 +72,12 @@ export function createConfig(root, { plugins = [] } = {}) {
preserveModules: true,
},
external(id) {
return isBuiltin(id) || isDependency(id) || isDevDependency(id);
return (
isBuiltin(id) ||
isDependency(id) ||
isDevDependency(id) ||
isPeerDependency(id)
);
},
plugins: [
// Replace always comes first to ensure the replaced values exist for all
Expand Down

0 comments on commit cb82883

Please sign in to comment.