Skip to content

ref(nextjs): Remove next.js plugin #3462

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

Merged
merged 5 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions packages/next-plugin-sentry/LICENSE

This file was deleted.

17 changes: 0 additions & 17 deletions packages/next-plugin-sentry/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions packages/next-plugin-sentry/env.js

This file was deleted.

38 changes: 0 additions & 38 deletions packages/next-plugin-sentry/package.json

This file was deleted.

11 changes: 0 additions & 11 deletions packages/next-plugin-sentry/src/on-error-client.js

This file was deleted.

36 changes: 0 additions & 36 deletions packages/next-plugin-sentry/src/on-error-server.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/next-plugin-sentry/src/on-init-client.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/next-plugin-sentry/src/on-init-server.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"dependencies": {
"@sentry/core": "6.3.1",
"@sentry/integrations": "6.3.1",
"@sentry/next-plugin-sentry": "6.3.1",
"@sentry/node": "6.3.1",
"@sentry/react": "6.3.1",
"@sentry/utils": "6.3.1",
Expand Down
89 changes: 0 additions & 89 deletions packages/nextjs/src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,87 +1,7 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { getSentryRelease } from '@sentry/node';
import { logger } from '@sentry/utils';
import defaultWebpackPlugin, { SentryCliPluginOptions } from '@sentry/webpack-plugin';
import * as SentryWebpackPlugin from '@sentry/webpack-plugin';
import * as fs from 'fs';
import * as path from 'path';

/**
* Starting at `startPath`, move up one directory at a time, searching for `searchFile`.
*
* @param startPath The location from which to start the search.
* @param searchFile The file to search for
* @returns The absolute path of the file, if it's found, or undefined if it's not
*/
function findUp(startPath: string, searchFile: string): string | undefined {
if (!fs.existsSync(startPath)) {
throw new Error(`The given \`startPath\` value (${startPath}) does not exist.`);
}

// if the last segment of `startPath` is a file, trim it off so that we start looking in its parent directory
let currentDir = fs.statSync(startPath).isFile() ? path.dirname(startPath) : startPath;
// eslint-disable-next-line no-constant-condition
while (true) {
const possiblePath = path.join(currentDir, searchFile);
if (fs.existsSync(possiblePath)) {
return possiblePath;
}

const parentDir = path.resolve(currentDir, '..');
// this means we've gotten to the root
if (currentDir === parentDir) {
break;
}
currentDir = parentDir;
}

return undefined;
}

/**
* Next requires that plugins be tagged with the same version number as the currently-running `next.js` package, so
* modify our `package.json` to trick it into thinking we comply. Run before the plugin is loaded at server startup.
*/
export function syncPluginVersionWithNextVersion(): void {
// TODO Once we get at least to TS 2.9, we can use `"resolveJsonModule": true` in our `compilerOptions` and we'll be
// able to do:
// import { version as nextVersion } from './node_modules/next/package.json';
let nextVersion;

try {
// `require.resolve` returns the location of the packages `"main"` entry point, as specified in its `package.json`
const nextResolvedMain = require.resolve('next');
// since we don't know where in the package's directory that entry point is, search upward until we find a folder
// containing `package.json`
const nextPackageJsonPath = findUp(nextResolvedMain, 'package.json');
nextVersion = nextPackageJsonPath && (require(nextPackageJsonPath) as { version: string }).version;
} catch (err) {
// eslint-disable-next-line no-console
console.error(`[next-plugin-sentry] Cannot read next.js version. Plug-in will not work.\nReceived error: ${err}`);
return;
}

let pluginPackageJsonPath, pluginPackageJson;

try {
const pluginResolvedMain = require.resolve('@sentry/next-plugin-sentry');
// see notes above about why we need to call `findUp`
pluginPackageJsonPath = findUp(pluginResolvedMain, 'package.json');
pluginPackageJson = pluginPackageJsonPath && require(pluginPackageJsonPath);
} catch (err) {
// eslint-disable-next-line no-console
console.error(
`[next-plugin-sentry] Cannot find \`@sentry/next-plugin-sentry\`. Plug-in will not work. ` +
`Please try reinstalling \`@sentry/nextjs\`.\nReceived error: ${err}`,
);
return;
}

(pluginPackageJson as { version: string }).version = nextVersion!;
fs.writeFileSync(pluginPackageJsonPath!, JSON.stringify(pluginPackageJson));
}

type WebpackConfig = { devtool: string; plugins: Array<{ [key: string]: any }> };
type NextConfigExports = {
Expand Down Expand Up @@ -120,8 +40,6 @@ export function withSentryConfig(

return {
...providedExports,
experimental: { ...(providedExports.experimental || {}), plugins: true },
plugins: [...(providedExports.plugins || []), '@sentry/next-plugin-sentry'],
productionBrowserSourceMaps: true,
webpack: (originalConfig, options) => {
let config = originalConfig;
Expand Down Expand Up @@ -149,10 +67,3 @@ export function withSentryConfig(
},
};
}

try {
syncPluginVersionWithNextVersion();
} catch (error) {
logger.warn(`[next-plugin-sentry] Cannot sync plug-in and next versions. Plug-in may not work, versions must match.`);
logger.warn('[next-plugin-sentry] A local project build should sync the versions, before deploying it.');
}