@honeybadger-io/nextjs 5.3.0 → 5.3.1
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/dist/copy-config-files.d.ts +1 -0
- package/dist/copy-config-files.js +13 -1
- package/dist/copy-config-files.js.map +1 -1
- package/dist/honeybadger-nextjs.cjs.js +28 -8
- package/dist/honeybadger-nextjs.cjs.js.map +1 -1
- package/dist/honeybadger-nextjs.esm.js +27 -9
- package/dist/honeybadger-nextjs.esm.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/package.json +3 -3
- package/src/copy-config-files.ts +19 -4
- package/src/index.ts +31 -9
- package/templates/_error.js +15 -0
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const debug = process.env.HONEYBADGER_DEBUG === 'true';
|
|
6
|
+
async function copyErrorJs() {
|
|
7
|
+
const targetPath = path.join('pages', '_error.js');
|
|
8
|
+
const errorJsAlreadyExists = fs.existsSync(targetPath);
|
|
9
|
+
if (errorJsAlreadyExists) {
|
|
10
|
+
// Don't overwrite an existing _error.js file.
|
|
11
|
+
// Create a _error.js.bak file instead.
|
|
12
|
+
const backupPath = path.join('pages', '_error.js.bak');
|
|
13
|
+
await fs.promises.copyFile(targetPath, backupPath);
|
|
14
|
+
}
|
|
15
|
+
const sourcePath = path.resolve(__dirname, '../templates/_error.js');
|
|
16
|
+
return fs.promises.copyFile(sourcePath, targetPath);
|
|
17
|
+
}
|
|
6
18
|
async function copyConfigFiles() {
|
|
7
19
|
if (debug) {
|
|
8
20
|
console.debug('cwd', process.cwd());
|
|
@@ -13,7 +25,7 @@ async function copyConfigFiles() {
|
|
|
13
25
|
if (debug) {
|
|
14
26
|
console.debug('copying', file);
|
|
15
27
|
}
|
|
16
|
-
return fs.promises.copyFile(path.join(templateDir, file), file);
|
|
28
|
+
return file === '_error.js' ? copyErrorJs() : fs.promises.copyFile(path.join(templateDir, file), file);
|
|
17
29
|
});
|
|
18
30
|
await Promise.all(copyPromises);
|
|
19
31
|
console.log('Done copying config files.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy-config-files.js","sourceRoot":"","sources":["../src/copy-config-files.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,MAAM,CAAA;AAEtD,KAAK,UAAU,eAAe;IAC5B,IAAI,KAAK,EAAE;QACT,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;KACpC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"copy-config-files.js","sourceRoot":"","sources":["../src/copy-config-files.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,MAAM,CAAA;AAEtD,KAAK,UAAU,WAAW;IACxB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IAClD,MAAM,oBAAoB,GAAG,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IACtD,IAAI,oBAAoB,EAAE;QACxB,8CAA8C;QAC9C,uCAAuC;QACvC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;QACtD,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;KACnD;IAED,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function copyErrorJs() {\n const targetPath = path.join('pages', '_error.js')\n const errorJsAlreadyExists = fs.existsSync(targetPath)\n if (errorJsAlreadyExists) {\n // Don't overwrite an existing _error.js file.\n // Create a _error.js.bak file instead.\n const backupPath = path.join('pages', '_error.js.bak')\n await fs.promises.copyFile(targetPath, backupPath)\n }\n\n const sourcePath = path.resolve(__dirname, '../templates/_error.js')\n\n return fs.promises.copyFile(sourcePath, targetPath)\n}\n\nasync function copyConfigFiles() {\n if (debug) {\n console.debug('cwd', process.cwd())\n }\n\n const templateDir = path.resolve(__dirname, '../templates')\n const files = await fs.promises.readdir(templateDir)\n const copyPromises = files.map((file) => {\n if (debug) {\n console.debug('copying', file)\n }\n\n return file === '_error.js' ? copyErrorJs() : fs.promises.copyFile(path.join(templateDir, file), file)\n });\n await Promise.all(copyPromises);\n console.log('Done copying config files.')\n}\n\ncopyConfigFiles().catch((err) => {\n console.error(err)\n process.exit(1)\n})\n"]}
|
|
@@ -4,12 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
var path = require('path');
|
|
7
|
+
var Honeybadger = require('@honeybadger-io/js');
|
|
7
8
|
var HoneybadgerSourceMapPlugin = require('@honeybadger-io/webpack');
|
|
8
9
|
|
|
9
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
11
|
|
|
11
12
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
12
13
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
14
|
+
var Honeybadger__default = /*#__PURE__*/_interopDefaultLegacy(Honeybadger);
|
|
13
15
|
var HoneybadgerSourceMapPlugin__default = /*#__PURE__*/_interopDefaultLegacy(HoneybadgerSourceMapPlugin);
|
|
14
16
|
|
|
15
17
|
let _silent = true;
|
|
@@ -28,14 +30,6 @@ function shouldUploadSourceMaps(honeybadgerNextJsConfig, context) {
|
|
|
28
30
|
}
|
|
29
31
|
return true;
|
|
30
32
|
}
|
|
31
|
-
function setupHoneybadger(config, honeybadgerNextJsConfig) {
|
|
32
|
-
var _a;
|
|
33
|
-
_silent = (_a = honeybadgerNextJsConfig === null || honeybadgerNextJsConfig === void 0 ? void 0 : honeybadgerNextJsConfig.silent) !== null && _a !== void 0 ? _a : true;
|
|
34
|
-
return {
|
|
35
|
-
...config,
|
|
36
|
-
webpack: mergeWithExistingWebpackConfig(config.webpack, honeybadgerNextJsConfig)
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
33
|
function mergeWithExistingWebpackConfig(nextJsWebpackConfig, honeybadgerNextJsConfig) {
|
|
40
34
|
return function webpackFunctionMergedWithHb(webpackConfig, context) {
|
|
41
35
|
const { isServer, dir: projectDir, nextRuntime } = context;
|
|
@@ -147,6 +141,32 @@ function getWebpackPluginOptions(honeybadgerNextJsConfig) {
|
|
|
147
141
|
silent: _silent,
|
|
148
142
|
};
|
|
149
143
|
}
|
|
144
|
+
function setupHoneybadger(config, honeybadgerNextJsConfig) {
|
|
145
|
+
var _a;
|
|
146
|
+
_silent = (_a = honeybadgerNextJsConfig === null || honeybadgerNextJsConfig === void 0 ? void 0 : honeybadgerNextJsConfig.silent) !== null && _a !== void 0 ? _a : true;
|
|
147
|
+
return {
|
|
148
|
+
...config,
|
|
149
|
+
webpack: mergeWithExistingWebpackConfig(config.webpack, honeybadgerNextJsConfig)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
async function notifyFromNextErrorComponent(contextData) {
|
|
153
|
+
const { req, res, err } = contextData;
|
|
154
|
+
// exclude 40x except when this component is rendered from a routing error or a custom server
|
|
155
|
+
// https://nextjs.org/docs/advanced-features/custom-error-page#caveats
|
|
156
|
+
const statusCode = (res && res.statusCode) || contextData.statusCode;
|
|
157
|
+
if (statusCode && statusCode < 500) {
|
|
158
|
+
Honeybadger__default["default"].config.logger.debug(`_error.js skipping because statusCode is ${statusCode}`);
|
|
159
|
+
return Promise.resolve();
|
|
160
|
+
}
|
|
161
|
+
await Honeybadger__default["default"].notifyAsync(err || `_error.js called with falsy error (${err})`, {
|
|
162
|
+
context: {
|
|
163
|
+
url: req.url,
|
|
164
|
+
method: req.method,
|
|
165
|
+
statusCode: res.statusCode,
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
150
169
|
|
|
170
|
+
exports.notifyFromNextErrorComponent = notifyFromNextErrorComponent;
|
|
151
171
|
exports.setupHoneybadger = setupHoneybadger;
|
|
152
172
|
//# sourceMappingURL=honeybadger-nextjs.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"honeybadger-nextjs.cjs.js","sources":["../../build/index.js"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport HoneybadgerSourceMapPlugin from '@honeybadger-io/webpack';\nlet _silent = true;\nfunction log(type, msg) {\n if (type === 'error' || !_silent) {\n console[type]('[HoneybadgerNextJs]', msg);\n }\n}\nfunction shouldUploadSourceMaps(honeybadgerNextJsConfig, context) {\n const { dev } = context;\n if (honeybadgerNextJsConfig.disableSourceMapUpload) {\n return false;\n }\n if (dev || process.env.NODE_ENV === 'development') {\n return false;\n }\n return true;\n}\nexport function setupHoneybadger(config, honeybadgerNextJsConfig) {\n var _a;\n _silent = (_a = honeybadgerNextJsConfig === null || honeybadgerNextJsConfig === void 0 ? void 0 : honeybadgerNextJsConfig.silent) !== null && _a !== void 0 ? _a : true;\n return {\n ...config,\n webpack: mergeWithExistingWebpackConfig(config.webpack, honeybadgerNextJsConfig)\n };\n}\nfunction mergeWithExistingWebpackConfig(nextJsWebpackConfig, honeybadgerNextJsConfig) {\n return function webpackFunctionMergedWithHb(webpackConfig, context) {\n const { isServer, dir: projectDir, nextRuntime } = context;\n const configType = isServer ? (nextRuntime === 'edge' ? 'edge' : 'server') : 'browser';\n log('debug', `reached webpackFunctionMergedWithHb isServer[${isServer}] configType[${configType}]`);\n let result = { ...webpackConfig };\n if (typeof nextJsWebpackConfig === 'function') {\n result = nextJsWebpackConfig(result, context);\n }\n const originalEntry = result.entry;\n result.entry = async () => injectHoneybadgerConfigToEntry(originalEntry, projectDir, configType);\n if (shouldUploadSourceMaps(honeybadgerNextJsConfig, context)) {\n // `result.devtool` must be 'hidden-source-map' or 'source-map' to properly pass sourcemaps.\n // Next.js uses regular `source-map` which doesnt pass its sourcemaps to Webpack.\n // https://github.com/vercel/next.js/blob/89ec21ed686dd79a5770b5c669abaff8f55d8fef/packages/next/build/webpack/config/blocks/base.ts#L40\n // Use the hidden-source-map option when you don't want the source maps to be\n // publicly available on the servers, only to the error reporting\n result.devtool = 'hidden-source-map';\n if (!result.plugins) {\n result.plugins = [];\n }\n const options = getWebpackPluginOptions(honeybadgerNextJsConfig);\n if (options) {\n result.plugins.push(new HoneybadgerSourceMapPlugin(options));\n }\n }\n return result;\n };\n}\nasync function injectHoneybadgerConfigToEntry(originalEntry, projectDir, configType) {\n const hbConfigFile = getHoneybadgerConfigFile(projectDir, configType);\n if (!hbConfigFile) {\n return originalEntry;\n }\n const hbConfigFileRelativePath = `./${hbConfigFile}`;\n const result = typeof originalEntry === 'function' ? await originalEntry() : { ...originalEntry };\n if (!Object.keys(result).length) {\n log('debug', `no entry points for configType[${configType}]`);\n }\n for (const entryName in result) {\n addHoneybadgerConfigToEntry(result, entryName, hbConfigFileRelativePath, configType);\n }\n return result;\n}\nfunction addHoneybadgerConfigToEntry(entry, entryName, hbConfigFile, configType) {\n log('debug', `adding entry[${entryName}] to configType[${configType}]`);\n switch (configType) {\n case 'server':\n if (!entryName.startsWith('pages/')) {\n return;\n }\n break;\n case 'browser':\n if (!['pages/_app', 'main-app'].includes(entryName)) {\n return;\n }\n break;\n case 'edge':\n // nothing?\n break;\n }\n const currentEntryPoint = entry[entryName];\n let newEntryPoint = currentEntryPoint;\n if (typeof currentEntryPoint === 'string') {\n newEntryPoint = [hbConfigFile, currentEntryPoint];\n }\n else if (Array.isArray(currentEntryPoint)) {\n newEntryPoint = [hbConfigFile, ...currentEntryPoint];\n } // descriptor object (webpack 5+)\n else if (typeof currentEntryPoint === 'object' && currentEntryPoint && 'import' in currentEntryPoint) {\n const currentImportValue = currentEntryPoint['import'];\n const newImportValue = [hbConfigFile];\n if (typeof currentImportValue === 'string') {\n newImportValue.push(currentImportValue);\n }\n else {\n newImportValue.push(...(currentImportValue));\n }\n newEntryPoint = {\n ...currentEntryPoint,\n import: newImportValue,\n };\n }\n else {\n log('error', 'Could not inject Honeybadger config to entry point: ' + JSON.stringify(currentEntryPoint, null, 2));\n }\n entry[entryName] = newEntryPoint;\n}\nfunction getHoneybadgerConfigFile(projectDir, configType) {\n const possibilities = [`honeybadger.${configType}.config.ts`, `honeybadger.${configType}.config.js`];\n for (const filename of possibilities) {\n if (fs.existsSync(path.resolve(projectDir, filename))) {\n return filename;\n }\n }\n log('debug', `could not find config file in ${projectDir} for ${configType}`);\n return null;\n}\nfunction getWebpackPluginOptions(honeybadgerNextJsConfig) {\n var _a, _b, _c;\n const apiKey = ((_a = honeybadgerNextJsConfig.webpackPluginOptions) === null || _a === void 0 ? void 0 : _a.apiKey) || process.env.NEXT_PUBLIC_HONEYBADGER_API_KEY;\n const assetsUrl = ((_b = honeybadgerNextJsConfig.webpackPluginOptions) === null || _b === void 0 ? void 0 : _b.assetsUrl) || process.env.NEXT_PUBLIC_HONEYBADGER_ASSETS_URL;\n if (!apiKey || !assetsUrl) {\n log('error', 'Missing Honeybadger required configuration for webpack plugin. Source maps will not be uploaded to Honeybadger.');\n return null;\n }\n return {\n ...honeybadgerNextJsConfig.webpackPluginOptions,\n apiKey,\n assetsUrl,\n revision: ((_c = honeybadgerNextJsConfig.webpackPluginOptions) === null || _c === void 0 ? void 0 : _c.revision) || process.env.NEXT_PUBLIC_HONEYBADGER_REVISION,\n silent: _silent,\n };\n}\n//# sourceMappingURL=index.js.map"],"names":["HoneybadgerSourceMapPlugin","fs","path"],"mappings":";;;;;;;;;;;;;;AAGA,IAAI,OAAO,GAAG,IAAI,CAAC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oB,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,KAAK,OAAO,CAAC,GAAG,CAAC,gCAAgC;AACxK,QAAQ,MAAM,EAAE,OAAO;AACvB,KAAK,CAAC;AACN;;;;"}
|
|
1
|
+
{"version":3,"file":"honeybadger-nextjs.cjs.js","sources":["../../build/index.js"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport Honeybadger from '@honeybadger-io/js';\nimport HoneybadgerSourceMapPlugin from '@honeybadger-io/webpack';\nlet _silent = true;\nfunction log(type, msg) {\n if (type === 'error' || !_silent) {\n console[type]('[HoneybadgerNextJs]', msg);\n }\n}\nfunction shouldUploadSourceMaps(honeybadgerNextJsConfig, context) {\n const { dev } = context;\n if (honeybadgerNextJsConfig.disableSourceMapUpload) {\n return false;\n }\n if (dev || process.env.NODE_ENV === 'development') {\n return false;\n }\n return true;\n}\nfunction mergeWithExistingWebpackConfig(nextJsWebpackConfig, honeybadgerNextJsConfig) {\n return function webpackFunctionMergedWithHb(webpackConfig, context) {\n const { isServer, dir: projectDir, nextRuntime } = context;\n const configType = isServer ? (nextRuntime === 'edge' ? 'edge' : 'server') : 'browser';\n log('debug', `reached webpackFunctionMergedWithHb isServer[${isServer}] configType[${configType}]`);\n let result = { ...webpackConfig };\n if (typeof nextJsWebpackConfig === 'function') {\n result = nextJsWebpackConfig(result, context);\n }\n const originalEntry = result.entry;\n result.entry = async () => injectHoneybadgerConfigToEntry(originalEntry, projectDir, configType);\n if (shouldUploadSourceMaps(honeybadgerNextJsConfig, context)) {\n // `result.devtool` must be 'hidden-source-map' or 'source-map' to properly pass sourcemaps.\n // Next.js uses regular `source-map` which doesnt pass its sourcemaps to Webpack.\n // https://github.com/vercel/next.js/blob/89ec21ed686dd79a5770b5c669abaff8f55d8fef/packages/next/build/webpack/config/blocks/base.ts#L40\n // Use the hidden-source-map option when you don't want the source maps to be\n // publicly available on the servers, only to the error reporting\n result.devtool = 'hidden-source-map';\n if (!result.plugins) {\n result.plugins = [];\n }\n const options = getWebpackPluginOptions(honeybadgerNextJsConfig);\n if (options) {\n result.plugins.push(new HoneybadgerSourceMapPlugin(options));\n }\n }\n return result;\n };\n}\nasync function injectHoneybadgerConfigToEntry(originalEntry, projectDir, configType) {\n const hbConfigFile = getHoneybadgerConfigFile(projectDir, configType);\n if (!hbConfigFile) {\n return originalEntry;\n }\n const hbConfigFileRelativePath = `./${hbConfigFile}`;\n const result = typeof originalEntry === 'function' ? await originalEntry() : { ...originalEntry };\n if (!Object.keys(result).length) {\n log('debug', `no entry points for configType[${configType}]`);\n }\n for (const entryName in result) {\n addHoneybadgerConfigToEntry(result, entryName, hbConfigFileRelativePath, configType);\n }\n return result;\n}\nfunction addHoneybadgerConfigToEntry(entry, entryName, hbConfigFile, configType) {\n log('debug', `adding entry[${entryName}] to configType[${configType}]`);\n switch (configType) {\n case 'server':\n if (!entryName.startsWith('pages/')) {\n return;\n }\n break;\n case 'browser':\n if (!['pages/_app', 'main-app'].includes(entryName)) {\n return;\n }\n break;\n case 'edge':\n // nothing?\n break;\n }\n const currentEntryPoint = entry[entryName];\n let newEntryPoint = currentEntryPoint;\n if (typeof currentEntryPoint === 'string') {\n newEntryPoint = [hbConfigFile, currentEntryPoint];\n }\n else if (Array.isArray(currentEntryPoint)) {\n newEntryPoint = [hbConfigFile, ...currentEntryPoint];\n } // descriptor object (webpack 5+)\n else if (typeof currentEntryPoint === 'object' && currentEntryPoint && 'import' in currentEntryPoint) {\n const currentImportValue = currentEntryPoint['import'];\n const newImportValue = [hbConfigFile];\n if (typeof currentImportValue === 'string') {\n newImportValue.push(currentImportValue);\n }\n else {\n newImportValue.push(...(currentImportValue));\n }\n newEntryPoint = {\n ...currentEntryPoint,\n import: newImportValue,\n };\n }\n else {\n log('error', 'Could not inject Honeybadger config to entry point: ' + JSON.stringify(currentEntryPoint, null, 2));\n }\n entry[entryName] = newEntryPoint;\n}\nfunction getHoneybadgerConfigFile(projectDir, configType) {\n const possibilities = [`honeybadger.${configType}.config.ts`, `honeybadger.${configType}.config.js`];\n for (const filename of possibilities) {\n if (fs.existsSync(path.resolve(projectDir, filename))) {\n return filename;\n }\n }\n log('debug', `could not find config file in ${projectDir} for ${configType}`);\n return null;\n}\nfunction getWebpackPluginOptions(honeybadgerNextJsConfig) {\n var _a, _b, _c;\n const apiKey = ((_a = honeybadgerNextJsConfig.webpackPluginOptions) === null || _a === void 0 ? void 0 : _a.apiKey) || process.env.NEXT_PUBLIC_HONEYBADGER_API_KEY;\n const assetsUrl = ((_b = honeybadgerNextJsConfig.webpackPluginOptions) === null || _b === void 0 ? void 0 : _b.assetsUrl) || process.env.NEXT_PUBLIC_HONEYBADGER_ASSETS_URL;\n if (!apiKey || !assetsUrl) {\n log('error', 'Missing Honeybadger required configuration for webpack plugin. Source maps will not be uploaded to Honeybadger.');\n return null;\n }\n return {\n ...honeybadgerNextJsConfig.webpackPluginOptions,\n apiKey,\n assetsUrl,\n revision: ((_c = honeybadgerNextJsConfig.webpackPluginOptions) === null || _c === void 0 ? void 0 : _c.revision) || process.env.NEXT_PUBLIC_HONEYBADGER_REVISION,\n silent: _silent,\n };\n}\nexport function setupHoneybadger(config, honeybadgerNextJsConfig) {\n var _a;\n _silent = (_a = honeybadgerNextJsConfig === null || honeybadgerNextJsConfig === void 0 ? void 0 : honeybadgerNextJsConfig.silent) !== null && _a !== void 0 ? _a : true;\n return {\n ...config,\n webpack: mergeWithExistingWebpackConfig(config.webpack, honeybadgerNextJsConfig)\n };\n}\nexport async function notifyFromNextErrorComponent(contextData) {\n const { req, res, err } = contextData;\n // exclude 40x except when this component is rendered from a routing error or a custom server\n // https://nextjs.org/docs/advanced-features/custom-error-page#caveats\n const statusCode = (res && res.statusCode) || contextData.statusCode;\n if (statusCode && statusCode < 500) {\n Honeybadger.config.logger.debug(`_error.js skipping because statusCode is ${statusCode}`);\n return Promise.resolve();\n }\n await Honeybadger.notifyAsync(err || `_error.js called with falsy error (${err})`, {\n context: {\n url: req.url,\n method: req.method,\n statusCode: res.statusCode,\n }\n });\n}\n//# sourceMappingURL=index.js.map"],"names":["HoneybadgerSourceMapPlugin","fs","path","Honeybadger"],"mappings":";;;;;;;;;;;;;;;;AAIA,IAAI,OAAO,GAAG,IAAI,CAAC;AACnB,SAAS,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE;AACxB,IAAI,IAAI,IAAI,KAAK,OAAO,IAAI,CAAC,OAAO,EAAE;AACtC,QAAQ,OAAO,CAAC,IAAI,CAAC,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;AAClD,KAAK;AACL,CAAC;AACD,SAAS,sBAAsB,CAAC,uBAAuB,EAAE,OAAO,EAAE;AAClE,IAAI,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;AAC5B,IAAI,IAAI,uBAAuB,CAAC,sBAAsB,EAAE;AACxD,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,IAAI,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE;AACvD,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB,CAAC;AACD,SAAS,8BAA8B,CAAC,mBAAmB,EAAE,uBAAuB,EAAE;AACtF,IAAI,OAAO,SAAS,2BAA2B,CAAC,aAAa,EAAE,OAAO,EAAE;AACxE,QAAQ,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;AACnE,QAAQ,MAAM,UAAU,GAAG,QAAQ,IAAI,WAAW,KAAK,MAAM,GAAG,MAAM,GAAG,QAAQ,IAAI,SAAS,CAAC;AAC/F,QAAQ,GAAG,CAAC,OAAO,EAAE,CAAC,6CAA6C,EAAE,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5G,QAAQ,IAAI,MAAM,GAAG,EAAE,GAAG,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-io/js';
|
|
3
4
|
import HoneybadgerSourceMapPlugin from '@honeybadger-io/webpack';
|
|
4
5
|
|
|
5
6
|
let _silent = true;
|
|
@@ -18,14 +19,6 @@ function shouldUploadSourceMaps(honeybadgerNextJsConfig, context) {
|
|
|
18
19
|
}
|
|
19
20
|
return true;
|
|
20
21
|
}
|
|
21
|
-
function setupHoneybadger(config, honeybadgerNextJsConfig) {
|
|
22
|
-
var _a;
|
|
23
|
-
_silent = (_a = honeybadgerNextJsConfig === null || honeybadgerNextJsConfig === void 0 ? void 0 : honeybadgerNextJsConfig.silent) !== null && _a !== void 0 ? _a : true;
|
|
24
|
-
return {
|
|
25
|
-
...config,
|
|
26
|
-
webpack: mergeWithExistingWebpackConfig(config.webpack, honeybadgerNextJsConfig)
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
22
|
function mergeWithExistingWebpackConfig(nextJsWebpackConfig, honeybadgerNextJsConfig) {
|
|
30
23
|
return function webpackFunctionMergedWithHb(webpackConfig, context) {
|
|
31
24
|
const { isServer, dir: projectDir, nextRuntime } = context;
|
|
@@ -137,6 +130,31 @@ function getWebpackPluginOptions(honeybadgerNextJsConfig) {
|
|
|
137
130
|
silent: _silent,
|
|
138
131
|
};
|
|
139
132
|
}
|
|
133
|
+
function setupHoneybadger(config, honeybadgerNextJsConfig) {
|
|
134
|
+
var _a;
|
|
135
|
+
_silent = (_a = honeybadgerNextJsConfig === null || honeybadgerNextJsConfig === void 0 ? void 0 : honeybadgerNextJsConfig.silent) !== null && _a !== void 0 ? _a : true;
|
|
136
|
+
return {
|
|
137
|
+
...config,
|
|
138
|
+
webpack: mergeWithExistingWebpackConfig(config.webpack, honeybadgerNextJsConfig)
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async function notifyFromNextErrorComponent(contextData) {
|
|
142
|
+
const { req, res, err } = contextData;
|
|
143
|
+
// exclude 40x except when this component is rendered from a routing error or a custom server
|
|
144
|
+
// https://nextjs.org/docs/advanced-features/custom-error-page#caveats
|
|
145
|
+
const statusCode = (res && res.statusCode) || contextData.statusCode;
|
|
146
|
+
if (statusCode && statusCode < 500) {
|
|
147
|
+
Honeybadger.config.logger.debug(`_error.js skipping because statusCode is ${statusCode}`);
|
|
148
|
+
return Promise.resolve();
|
|
149
|
+
}
|
|
150
|
+
await Honeybadger.notifyAsync(err || `_error.js called with falsy error (${err})`, {
|
|
151
|
+
context: {
|
|
152
|
+
url: req.url,
|
|
153
|
+
method: req.method,
|
|
154
|
+
statusCode: res.statusCode,
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
140
158
|
|
|
141
|
-
export { setupHoneybadger };
|
|
159
|
+
export { notifyFromNextErrorComponent, setupHoneybadger };
|
|
142
160
|
//# sourceMappingURL=honeybadger-nextjs.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"honeybadger-nextjs.esm.js","sources":["../../build/index.js"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport HoneybadgerSourceMapPlugin from '@honeybadger-io/webpack';\nlet _silent = true;\nfunction log(type, msg) {\n if (type === 'error' || !_silent) {\n console[type]('[HoneybadgerNextJs]', msg);\n }\n}\nfunction shouldUploadSourceMaps(honeybadgerNextJsConfig, context) {\n const { dev } = context;\n if (honeybadgerNextJsConfig.disableSourceMapUpload) {\n return false;\n }\n if (dev || process.env.NODE_ENV === 'development') {\n return false;\n }\n return true;\n}\nexport function setupHoneybadger(config, honeybadgerNextJsConfig) {\n var _a;\n _silent = (_a = honeybadgerNextJsConfig === null || honeybadgerNextJsConfig === void 0 ? void 0 : honeybadgerNextJsConfig.silent) !== null && _a !== void 0 ? _a : true;\n return {\n ...config,\n webpack: mergeWithExistingWebpackConfig(config.webpack, honeybadgerNextJsConfig)\n };\n}\nfunction mergeWithExistingWebpackConfig(nextJsWebpackConfig, honeybadgerNextJsConfig) {\n return function webpackFunctionMergedWithHb(webpackConfig, context) {\n const { isServer, dir: projectDir, nextRuntime } = context;\n const configType = isServer ? (nextRuntime === 'edge' ? 'edge' : 'server') : 'browser';\n log('debug', `reached webpackFunctionMergedWithHb isServer[${isServer}] configType[${configType}]`);\n let result = { ...webpackConfig };\n if (typeof nextJsWebpackConfig === 'function') {\n result = nextJsWebpackConfig(result, context);\n }\n const originalEntry = result.entry;\n result.entry = async () => injectHoneybadgerConfigToEntry(originalEntry, projectDir, configType);\n if (shouldUploadSourceMaps(honeybadgerNextJsConfig, context)) {\n // `result.devtool` must be 'hidden-source-map' or 'source-map' to properly pass sourcemaps.\n // Next.js uses regular `source-map` which doesnt pass its sourcemaps to Webpack.\n // https://github.com/vercel/next.js/blob/89ec21ed686dd79a5770b5c669abaff8f55d8fef/packages/next/build/webpack/config/blocks/base.ts#L40\n // Use the hidden-source-map option when you don't want the source maps to be\n // publicly available on the servers, only to the error reporting\n result.devtool = 'hidden-source-map';\n if (!result.plugins) {\n result.plugins = [];\n }\n const options = getWebpackPluginOptions(honeybadgerNextJsConfig);\n if (options) {\n result.plugins.push(new HoneybadgerSourceMapPlugin(options));\n }\n }\n return result;\n };\n}\nasync function injectHoneybadgerConfigToEntry(originalEntry, projectDir, configType) {\n const hbConfigFile = getHoneybadgerConfigFile(projectDir, configType);\n if (!hbConfigFile) {\n return originalEntry;\n }\n const hbConfigFileRelativePath = `./${hbConfigFile}`;\n const result = typeof originalEntry === 'function' ? await originalEntry() : { ...originalEntry };\n if (!Object.keys(result).length) {\n log('debug', `no entry points for configType[${configType}]`);\n }\n for (const entryName in result) {\n addHoneybadgerConfigToEntry(result, entryName, hbConfigFileRelativePath, configType);\n }\n return result;\n}\nfunction addHoneybadgerConfigToEntry(entry, entryName, hbConfigFile, configType) {\n log('debug', `adding entry[${entryName}] to configType[${configType}]`);\n switch (configType) {\n case 'server':\n if (!entryName.startsWith('pages/')) {\n return;\n }\n break;\n case 'browser':\n if (!['pages/_app', 'main-app'].includes(entryName)) {\n return;\n }\n break;\n case 'edge':\n // nothing?\n break;\n }\n const currentEntryPoint = entry[entryName];\n let newEntryPoint = currentEntryPoint;\n if (typeof currentEntryPoint === 'string') {\n newEntryPoint = [hbConfigFile, currentEntryPoint];\n }\n else if (Array.isArray(currentEntryPoint)) {\n newEntryPoint = [hbConfigFile, ...currentEntryPoint];\n } // descriptor object (webpack 5+)\n else if (typeof currentEntryPoint === 'object' && currentEntryPoint && 'import' in currentEntryPoint) {\n const currentImportValue = currentEntryPoint['import'];\n const newImportValue = [hbConfigFile];\n if (typeof currentImportValue === 'string') {\n newImportValue.push(currentImportValue);\n }\n else {\n newImportValue.push(...(currentImportValue));\n }\n newEntryPoint = {\n ...currentEntryPoint,\n import: newImportValue,\n };\n }\n else {\n log('error', 'Could not inject Honeybadger config to entry point: ' + JSON.stringify(currentEntryPoint, null, 2));\n }\n entry[entryName] = newEntryPoint;\n}\nfunction getHoneybadgerConfigFile(projectDir, configType) {\n const possibilities = [`honeybadger.${configType}.config.ts`, `honeybadger.${configType}.config.js`];\n for (const filename of possibilities) {\n if (fs.existsSync(path.resolve(projectDir, filename))) {\n return filename;\n }\n }\n log('debug', `could not find config file in ${projectDir} for ${configType}`);\n return null;\n}\nfunction getWebpackPluginOptions(honeybadgerNextJsConfig) {\n var _a, _b, _c;\n const apiKey = ((_a = honeybadgerNextJsConfig.webpackPluginOptions) === null || _a === void 0 ? void 0 : _a.apiKey) || process.env.NEXT_PUBLIC_HONEYBADGER_API_KEY;\n const assetsUrl = ((_b = honeybadgerNextJsConfig.webpackPluginOptions) === null || _b === void 0 ? void 0 : _b.assetsUrl) || process.env.NEXT_PUBLIC_HONEYBADGER_ASSETS_URL;\n if (!apiKey || !assetsUrl) {\n log('error', 'Missing Honeybadger required configuration for webpack plugin. Source maps will not be uploaded to Honeybadger.');\n return null;\n }\n return {\n ...honeybadgerNextJsConfig.webpackPluginOptions,\n apiKey,\n assetsUrl,\n revision: ((_c = honeybadgerNextJsConfig.webpackPluginOptions) === null || _c === void 0 ? void 0 : _c.revision) || process.env.NEXT_PUBLIC_HONEYBADGER_REVISION,\n sil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d,QAAQ,SAAS;AACjB,QAAQ,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,uBAAuB,CAAC,oBAAoB,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,KAAK,OAAO,CAAC,GAAG,CAAC,gCAAgC;AACxK,QAAQ,MAAM,EAAE,OAAO;AACvB,KAAK,CAAC;AACN;;;;"}
|
|
1
|
+
{"version":3,"file":"honeybadger-nextjs.esm.js","sources":["../../build/index.js"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport Honeybadger from '@honeybadger-io/js';\nimport HoneybadgerSourceMapPlugin from '@honeybadger-io/webpack';\nlet _silent = true;\nfunction log(type, msg) {\n if (type === 'error' || !_silent) {\n console[type]('[HoneybadgerNextJs]', msg);\n }\n}\nfunction shouldUploadSourceMaps(honeybadgerNextJsConfig, context) {\n const { dev } = context;\n if (honeybadgerNextJsConfig.disableSourceMapUpload) {\n return false;\n }\n if (dev || process.env.NODE_ENV === 'development') {\n return false;\n }\n return true;\n}\nfunction mergeWithExistingWebpackConfig(nextJsWebpackConfig, honeybadgerNextJsConfig) {\n return function webpackFunctionMergedWithHb(webpackConfig, context) {\n const { isServer, dir: projectDir, nextRuntime } = context;\n const configType = isServer ? (nextRuntime === 'edge' ? 'edge' : 'server') : 'browser';\n log('debug', `reached webpackFunctionMergedWithHb isServer[${isServer}] configType[${configType}]`);\n let result = { ...webpackConfig };\n if (typeof nextJsWebpackConfig === 'function') {\n result = nextJsWebpackConfig(result, context);\n }\n const originalEntry = result.entry;\n result.entry = async () => injectHoneybadgerConfigToEntry(originalEntry, projectDir, configType);\n if (shouldUploadSourceMaps(honeybadgerNextJsConfig, context)) {\n // `result.devtool` must be 'hidden-source-map' or 'source-map' to properly pass sourcemaps.\n // Next.js uses regular `source-map` which doesnt pass its sourcemaps to Webpack.\n // https://github.com/vercel/next.js/blob/89ec21ed686dd79a5770b5c669abaff8f55d8fef/packages/next/build/webpack/config/blocks/base.ts#L40\n // Use the hidden-source-map option when you don't want the source maps to be\n // publicly available on the servers, only to the error reporting\n result.devtool = 'hidden-source-map';\n if (!result.plugins) {\n result.plugins = [];\n }\n const options = getWebpackPluginOptions(honeybadgerNextJsConfig);\n if (options) {\n result.plugins.push(new HoneybadgerSourceMapPlugin(options));\n }\n }\n return result;\n };\n}\nasync function injectHoneybadgerConfigToEntry(originalEntry, projectDir, configType) {\n const hbConfigFile = getHoneybadgerConfigFile(projectDir, configType);\n if (!hbConfigFile) {\n return originalEntry;\n }\n const hbConfigFileRelativePath = `./${hbConfigFile}`;\n const result = typeof originalEntry === 'function' ? await originalEntry() : { ...originalEntry };\n if (!Object.keys(result).length) {\n log('debug', `no entry points for configType[${configType}]`);\n }\n for (const entryName in result) {\n addHoneybadgerConfigToEntry(result, entryName, hbConfigFileRelativePath, configType);\n }\n return result;\n}\nfunction addHoneybadgerConfigToEntry(entry, entryName, hbConfigFile, configType) {\n log('debug', `adding entry[${entryName}] to configType[${configType}]`);\n switch (configType) {\n case 'server':\n if (!entryName.startsWith('pages/')) {\n return;\n }\n break;\n case 'browser':\n if (!['pages/_app', 'main-app'].includes(entryName)) {\n return;\n }\n break;\n case 'edge':\n // nothing?\n break;\n }\n const currentEntryPoint = entry[entryName];\n let newEntryPoint = currentEntryPoint;\n if (typeof currentEntryPoint === 'string') {\n newEntryPoint = [hbConfigFile, currentEntryPoint];\n }\n else if (Array.isArray(currentEntryPoint)) {\n newEntryPoint = [hbConfigFile, ...currentEntryPoint];\n } // descriptor object (webpack 5+)\n else if (typeof currentEntryPoint === 'object' && currentEntryPoint && 'import' in currentEntryPoint) {\n const currentImportValue = currentEntryPoint['import'];\n const newImportValue = [hbConfigFile];\n if (typeof currentImportValue === 'string') {\n newImportValue.push(currentImportValue);\n }\n else {\n newImportValue.push(...(currentImportValue));\n }\n newEntryPoint = {\n ...currentEntryPoint,\n import: newImportValue,\n };\n }\n else {\n log('error', 'Could not inject Honeybadger config to entry point: ' + JSON.stringify(currentEntryPoint, null, 2));\n }\n entry[entryName] = newEntryPoint;\n}\nfunction getHoneybadgerConfigFile(projectDir, configType) {\n const possibilities = [`honeybadger.${configType}.config.ts`, `honeybadger.${configType}.config.js`];\n for (const filename of possibilities) {\n if (fs.existsSync(path.resolve(projectDir, filename))) {\n return filename;\n }\n }\n log('debug', `could not find config file in ${projectDir} for ${configType}`);\n return null;\n}\nfunction getWebpackPluginOptions(honeybadgerNextJsConfig) {\n var _a, _b, _c;\n const apiKey = ((_a = honeybadgerNextJsConfig.webpackPluginOptions) === null || _a === void 0 ? void 0 : _a.apiKey) || process.env.NEXT_PUBLIC_HONEYBADGER_API_KEY;\n const assetsUrl = ((_b = honeybadgerNextJsConfig.webpackPluginOptions) === null || _b === void 0 ? void 0 : _b.assetsUrl) || process.env.NEXT_PUBLIC_HONEYBADGER_ASSETS_URL;\n if (!apiKey || !assetsUrl) {\n log('error', 'Missing Honeybadger required configuration for webpack plugin. Source maps will not be uploaded to Honeybadger.');\n return null;\n }\n return {\n ...honeybadgerNextJsConfig.webpackPluginOptions,\n apiKey,\n assetsUrl,\n revision: ((_c = honeybadgerNextJsConfig.webpackPluginOptions) === null || _c === void 0 ? void 0 : _c.revision) || process.env.NEXT_PUBLIC_HONEYBADGER_REVISION,\n silent: _silent,\n };\n}\nexport function setupHoneybadger(config, honeybadgerNextJsConfig) {\n var _a;\n _silent = (_a = honeybadgerNextJsConfig === null || honeybadgerNextJsConfig === void 0 ? void 0 : honeybadgerNextJsConfig.silent) !== null && _a !== void 0 ? _a : true;\n return {\n ...config,\n webpack: mergeWithExistingWebpackConfig(config.webpack, honeybadgerNextJsConfig)\n };\n}\nexport async function notifyFromNextErrorComponent(contextData) {\n const { req, res, err } = contextData;\n // exclude 40x except when this component is rendered from a routing error or a custom server\n // https://nextjs.org/docs/advanced-features/custom-error-page#caveats\n const statusCode = (res && res.statusCode) || contextData.statusCode;\n if (statusCode && statusCode < 500) {\n Honeybadger.config.logger.debug(`_error.js skipping because statusCode is ${statusCode}`);\n return Promise.resolve();\n }\n await Honeybadger.notifyAsync(err || `_error.js called with falsy error (${err})`, {\n context: {\n url: req.url,\n method: req.method,\n statusCode: res.statusCode,\n }\n });\n}\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;AAIA,IAAI,OAAO,GAAG,IAAI,CAAC;AACnB,SAAS,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE;AACxB,IAAI,IAAI,IAAI,KAAK,OAAO,IAAI,CAAC,OAAO,EAAE;AACtC,QAAQ,OAAO,CAAC,IAAI,CAAC,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;AAClD,KAAK;AACL,CAAC;AACD,SAAS,sBAAsB,CAAC,uBAAuB,EAAE,OAAO,EAAE;AAClE,IAAI,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;AAC5B,IAAI,IAAI,uBAAuB,CAAC,sBAAsB,EAAE;AACxD,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,IAAI,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE;AACvD,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB,CAAC;AACD,SAAS,8BAA8B,CAAC,mBAAmB,EAAE,uBAAuB,EAAE;AACtF,IAAI,OAAO,SAAS,2BAA2B,CAAC,aAAa,EAAE,OAAO,EAAE;AACxE,QAAQ,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;AACnE,QAAQ,MAAM,UAAU,GAAG,QAAQ,IAAI,WAAW,KAAK,MAAM,GAAG,MAAM,GAAG,QAAQ,IAAI,SAAS,CAAC;AAC/F,QAAQ,GAAG,CAAC,OAAO,EAAE,CAAC,6CAA6C,EAAE,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5G,Q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
|
|
2
2
|
"name": "@honeybadger-io/nextjs",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"description": "Next.js integration for Honeybadger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nextjs",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"name": "Pangratios Cosma",
|
|
13
13
|
"email": "pangratios.cosma@honeybadger.io"
|
|
14
14
|
},
|
|
15
|
-
"homepage": "https://github.com/honeybadger-io/honeybadger-js/packages/nextjs
|
|
15
|
+
"homepage": "https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/nextjs",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"main": "dist/honeybadger-nextjs.cjs.js",
|
|
18
18
|
"module": "dist/honeybadger-nextjs.esm.js",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "3f404e50b2b3a836ca9c5851833ab40050cfb20c"
|
|
61
61
|
}
|
package/src/copy-config-files.ts
CHANGED
|
@@ -5,21 +5,36 @@ const fs = require('fs')
|
|
|
5
5
|
|
|
6
6
|
const debug = process.env.HONEYBADGER_DEBUG === 'true'
|
|
7
7
|
|
|
8
|
+
async function copyErrorJs() {
|
|
9
|
+
const targetPath = path.join('pages', '_error.js')
|
|
10
|
+
const errorJsAlreadyExists = fs.existsSync(targetPath)
|
|
11
|
+
if (errorJsAlreadyExists) {
|
|
12
|
+
// Don't overwrite an existing _error.js file.
|
|
13
|
+
// Create a _error.js.bak file instead.
|
|
14
|
+
const backupPath = path.join('pages', '_error.js.bak')
|
|
15
|
+
await fs.promises.copyFile(targetPath, backupPath)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const sourcePath = path.resolve(__dirname, '../templates/_error.js')
|
|
19
|
+
|
|
20
|
+
return fs.promises.copyFile(sourcePath, targetPath)
|
|
21
|
+
}
|
|
22
|
+
|
|
8
23
|
async function copyConfigFiles() {
|
|
9
24
|
if (debug) {
|
|
10
25
|
console.debug('cwd', process.cwd())
|
|
11
26
|
}
|
|
12
27
|
|
|
13
|
-
const templateDir = path.resolve(__dirname, '../templates')
|
|
14
|
-
const files = await fs.promises.readdir(templateDir)
|
|
28
|
+
const templateDir = path.resolve(__dirname, '../templates')
|
|
29
|
+
const files = await fs.promises.readdir(templateDir)
|
|
15
30
|
const copyPromises = files.map((file) => {
|
|
16
31
|
if (debug) {
|
|
17
32
|
console.debug('copying', file)
|
|
18
33
|
}
|
|
19
|
-
|
|
34
|
+
|
|
35
|
+
return file === '_error.js' ? copyErrorJs() : fs.promises.copyFile(path.join(templateDir, file), file)
|
|
20
36
|
});
|
|
21
37
|
await Promise.all(copyPromises);
|
|
22
|
-
|
|
23
38
|
console.log('Done copying config files.')
|
|
24
39
|
}
|
|
25
40
|
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
|
+
import Honeybadger from '@honeybadger-io/js';
|
|
3
4
|
import HoneybadgerSourceMapPlugin from '@honeybadger-io/webpack'
|
|
4
5
|
import type { WebpackConfigContext } from 'next/dist/server/config-shared';
|
|
5
6
|
import { HoneybadgerNextJsConfig, NextJsRuntime, HoneybadgerWebpackPluginOptions } from './types'
|
|
@@ -25,15 +26,6 @@ function shouldUploadSourceMaps(honeybadgerNextJsConfig: HoneybadgerNextJsConfig
|
|
|
25
26
|
return true
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
export function setupHoneybadger(config, honeybadgerNextJsConfig: HoneybadgerNextJsConfig) {
|
|
29
|
-
_silent = honeybadgerNextJsConfig?.silent ?? true
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
...config,
|
|
33
|
-
webpack: mergeWithExistingWebpackConfig(config.webpack, honeybadgerNextJsConfig)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
29
|
function mergeWithExistingWebpackConfig(nextJsWebpackConfig, honeybadgerNextJsConfig: HoneybadgerNextJsConfig) {
|
|
38
30
|
return function webpackFunctionMergedWithHb(webpackConfig, context: WebpackConfigContext) {
|
|
39
31
|
|
|
@@ -167,3 +159,33 @@ function getWebpackPluginOptions(honeybadgerNextJsConfig: HoneybadgerNextJsConfi
|
|
|
167
159
|
silent: _silent,
|
|
168
160
|
}
|
|
169
161
|
}
|
|
162
|
+
|
|
163
|
+
export function setupHoneybadger(config, honeybadgerNextJsConfig: HoneybadgerNextJsConfig) {
|
|
164
|
+
_silent = honeybadgerNextJsConfig?.silent ?? true
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
...config,
|
|
168
|
+
webpack: mergeWithExistingWebpackConfig(config.webpack, honeybadgerNextJsConfig)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function notifyFromNextErrorComponent(contextData) {
|
|
173
|
+
const { req, res, err } = contextData;
|
|
174
|
+
|
|
175
|
+
// exclude 40x except when this component is rendered from a routing error or a custom server
|
|
176
|
+
// https://nextjs.org/docs/advanced-features/custom-error-page#caveats
|
|
177
|
+
const statusCode = (res && res.statusCode) || contextData.statusCode;
|
|
178
|
+
if (statusCode && statusCode < 500) {
|
|
179
|
+
Honeybadger.config.logger.debug(`_error.js skipping because statusCode is ${statusCode}`);
|
|
180
|
+
return Promise.resolve();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
await Honeybadger.notifyAsync(err || `_error.js called with falsy error (${err})`, {
|
|
184
|
+
context:
|
|
185
|
+
{
|
|
186
|
+
url: req.url,
|
|
187
|
+
method: req.method,
|
|
188
|
+
statusCode: res.statusCode,
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-unresolved
|
|
2
|
+
import { notifyFromNextErrorComponent } from '@honeybadger-io/nextjs';
|
|
3
|
+
import NextErrorComponent from 'next/error';
|
|
4
|
+
|
|
5
|
+
const CustomErrorComponent = props => {
|
|
6
|
+
return <NextErrorComponent statusCode={props.statusCode} />;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
CustomErrorComponent.getInitialProps = async contextData => {
|
|
10
|
+
await notifyFromNextErrorComponent(contextData);
|
|
11
|
+
|
|
12
|
+
return NextErrorComponent.getInitialProps(contextData);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default CustomErrorComponent;
|