@honeybadger-io/nextjs 5.7.4 → 5.7.6

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.
@@ -1,3 +1,2 @@
1
- #!/usr/bin/env node
2
1
  declare const copyConfigFiles: any;
3
2
  //# sourceMappingURL=copy-config-files-exec.d.ts.map
@@ -1,8 +1,137 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- const { copyConfigFiles } = require('./copy-config-files');
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ function getAugmentedNamespace(n) {
7
+ var f = n.default;
8
+ if (typeof f == "function") {
9
+ var a = function () {
10
+ return f.apply(this, arguments);
11
+ };
12
+ a.prototype = f.prototype;
13
+ } else a = {};
14
+ Object.defineProperty(a, '__esModule', {value: true});
15
+ Object.keys(n).forEach(function (k) {
16
+ var d = Object.getOwnPropertyDescriptor(n, k);
17
+ Object.defineProperty(a, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () {
20
+ return n[k];
21
+ }
22
+ });
23
+ });
24
+ return a;
25
+ }
26
+
27
+ var copyConfigFilesExec = {};
28
+
29
+ const path = require('path');
30
+ const fs = require('fs');
31
+ const debug = process.env.HONEYBADGER_DEBUG === 'true';
32
+ function usesTypescript() {
33
+ return fs.existsSync('tsconfig.json');
34
+ }
35
+ function usesSrcFolder() {
36
+ return fs.existsSync('src');
37
+ }
38
+ function usesPagesRouter(isUnderSrc) {
39
+ const srcFolder = isUnderSrc ? 'src' : '';
40
+ return fs.existsSync(path.join(srcFolder, 'pages'));
41
+ }
42
+ function usesAppRouter(isUnderSrc) {
43
+ const srcFolder = isUnderSrc ? 'src' : '';
44
+ return fs.existsSync(path.join(srcFolder, 'app'));
45
+ }
46
+ function getTargetPath(isUnderSrc, isAppRouter = false, isGlobalErrorComponent = false) {
47
+ if (!isAppRouter && isGlobalErrorComponent) {
48
+ throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');
49
+ }
50
+ const extension = usesTypescript() ? 'tsx' : 'js';
51
+ let srcFolder = isUnderSrc ? 'src' : '';
52
+ srcFolder = path.join(srcFolder, isAppRouter ? 'app' : 'pages');
53
+ let fileName = '';
54
+ if (isAppRouter) {
55
+ fileName = isGlobalErrorComponent ? 'global-error' : 'error';
56
+ }
57
+ else {
58
+ fileName = '_error';
59
+ }
60
+ return path.join(srcFolder, fileName + '.' + extension);
61
+ }
62
+ function getTemplate(isAppRouter = false, isGlobalErrorComponent = false) {
63
+ if (!isAppRouter && isGlobalErrorComponent) {
64
+ throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');
65
+ }
66
+ const extension = isGlobalErrorComponent ? 'tsx' : 'js';
67
+ const templateName = isAppRouter ? '_error_app_router' : '_error';
68
+ return path.resolve(__dirname, '../templates', templateName + '.' + extension);
69
+ }
70
+ async function copyErrorJs(isUnderSrc, isAppRouter = false) {
71
+ const sourcePath = getTemplate(isAppRouter);
72
+ const targetPath = getTargetPath(isUnderSrc, isAppRouter);
73
+ return copyFileWithBackup(sourcePath, targetPath);
74
+ }
75
+ function copyGlobalErrorJs(isUnderSrc) {
76
+ const sourcePath = getTemplate(true, true);
77
+ const targetPath = getTargetPath(isUnderSrc, true, true);
78
+ return copyFileWithBackup(sourcePath, targetPath);
79
+ }
80
+ async function copyFileWithBackup(sourcePath, targetPath) {
81
+ const fileAlreadyExists = fs.existsSync(targetPath);
82
+ if (fileAlreadyExists) {
83
+ // Don't overwrite an existing file without creating a backup first
84
+ const backupPath = targetPath + '.bak';
85
+ if (debug) {
86
+ console.debug('backing up', targetPath, 'to', backupPath);
87
+ }
88
+ await fs.promises.copyFile(targetPath, backupPath);
89
+ }
90
+ if (debug) {
91
+ console.debug('copying', sourcePath, 'to', targetPath);
92
+ }
93
+ return fs.promises.copyFile(sourcePath, targetPath);
94
+ }
95
+ async function copyConfigFiles$1() {
96
+ if (debug) {
97
+ console.debug('cwd', process.cwd());
98
+ }
99
+ const templateDir = path.resolve(__dirname, '../templates');
100
+ const configFiles = [
101
+ 'honeybadger.browser.config.js',
102
+ 'honeybadger.edge.config.js',
103
+ 'honeybadger.server.config.js',
104
+ ];
105
+ const copyPromises = configFiles.map((file) => {
106
+ if (debug) {
107
+ console.debug('copying', file);
108
+ }
109
+ return fs.promises.copyFile(path.join(templateDir, file), file);
110
+ });
111
+ const isUnderSrcFolder = usesSrcFolder();
112
+ if (usesPagesRouter(isUnderSrcFolder)) {
113
+ copyPromises.push(copyErrorJs(isUnderSrcFolder, false));
114
+ }
115
+ if (usesAppRouter(isUnderSrcFolder)) {
116
+ copyPromises.push(copyErrorJs(isUnderSrcFolder, true));
117
+ copyPromises.push(copyGlobalErrorJs(isUnderSrcFolder));
118
+ }
119
+ await Promise.all(copyPromises);
120
+ console.log('Done copying config files.');
121
+ }
122
+
123
+ var copyConfigFiles$2 = /*#__PURE__*/Object.freeze({
124
+ __proto__: null,
125
+ copyConfigFiles: copyConfigFiles$1
126
+ });
127
+
128
+ var require$$0 = /*@__PURE__*/getAugmentedNamespace(copyConfigFiles$2);
129
+
130
+ const { copyConfigFiles } = require$$0;
4
131
  copyConfigFiles().catch((err) => {
5
132
  console.error(err);
6
133
  process.exit(1);
7
134
  });
8
- //# sourceMappingURL=copy-config-files-exec.js.map
135
+
136
+ exports["default"] = copyConfigFilesExec;
137
+ //# sourceMappingURL=copy-config-files-exec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"copy-config-files-exec.js","sourceRoot":"","sources":["../src/copy-config-files-exec.ts"],"names":[],"mappings":";;AAEA,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;AAE1D,eAAe,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IAC9B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nconst { copyConfigFiles } = require('./copy-config-files')\n\ncopyConfigFiles().catch((err) => {\n console.error(err)\n process.exit(1)\n})\n"]}
1
+ {"version":3,"file":"copy-config-files-exec.js","sources":["../../build/copy-config-files.js","../../build/copy-config-files-exec.js"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\nconst debug = process.env.HONEYBADGER_DEBUG === 'true';\nfunction usesTypescript() {\n return fs.existsSync('tsconfig.json');\n}\nfunction usesSrcFolder() {\n return fs.existsSync('src');\n}\nfunction usesPagesRouter(isUnderSrc) {\n const srcFolder = isUnderSrc ? 'src' : '';\n return fs.existsSync(path.join(srcFolder, 'pages'));\n}\nfunction usesAppRouter(isUnderSrc) {\n const srcFolder = isUnderSrc ? 'src' : '';\n return fs.existsSync(path.join(srcFolder, 'app'));\n}\nfunction getTargetPath(isUnderSrc, isAppRouter = false, isGlobalErrorComponent = false) {\n if (!isAppRouter && isGlobalErrorComponent) {\n throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');\n }\n const extension = usesTypescript() ? 'tsx' : 'js';\n let srcFolder = isUnderSrc ? 'src' : '';\n srcFolder = path.join(srcFolder, isAppRouter ? 'app' : 'pages');\n let fileName = '';\n if (isAppRouter) {\n fileName = isGlobalErrorComponent ? 'global-error' : 'error';\n }\n else {\n fileName = '_error';\n }\n return path.join(srcFolder, fileName + '.' + extension);\n}\nfunction getTemplate(isAppRouter = false, isGlobalErrorComponent = false) {\n if (!isAppRouter && isGlobalErrorComponent) {\n throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');\n }\n const extension = isGlobalErrorComponent ? 'tsx' : 'js';\n const templateName = isAppRouter ? '_error_app_router' : '_error';\n return path.resolve(__dirname, '../templates', templateName + '.' + extension);\n}\nasync function copyErrorJs(isUnderSrc, isAppRouter = false) {\n const sourcePath = getTemplate(isAppRouter);\n const targetPath = getTargetPath(isUnderSrc, isAppRouter);\n return copyFileWithBackup(sourcePath, targetPath);\n}\nfunction copyGlobalErrorJs(isUnderSrc) {\n const sourcePath = getTemplate(true, true);\n const targetPath = getTargetPath(isUnderSrc, true, true);\n return copyFileWithBackup(sourcePath, targetPath);\n}\nasync function copyFileWithBackup(sourcePath, targetPath) {\n const fileAlreadyExists = fs.existsSync(targetPath);\n if (fileAlreadyExists) {\n // Don't overwrite an existing file without creating a backup first\n const backupPath = targetPath + '.bak';\n if (debug) {\n console.debug('backing up', targetPath, 'to', backupPath);\n }\n await fs.promises.copyFile(targetPath, backupPath);\n }\n if (debug) {\n console.debug('copying', sourcePath, 'to', targetPath);\n }\n return fs.promises.copyFile(sourcePath, targetPath);\n}\nexport async function copyConfigFiles() {\n if (debug) {\n console.debug('cwd', process.cwd());\n }\n const templateDir = path.resolve(__dirname, '../templates');\n const configFiles = [\n 'honeybadger.browser.config.js',\n 'honeybadger.edge.config.js',\n 'honeybadger.server.config.js',\n ];\n const copyPromises = configFiles.map((file) => {\n if (debug) {\n console.debug('copying', file);\n }\n return fs.promises.copyFile(path.join(templateDir, file), file);\n });\n const isUnderSrcFolder = usesSrcFolder();\n if (usesPagesRouter(isUnderSrcFolder)) {\n copyPromises.push(copyErrorJs(isUnderSrcFolder, false));\n }\n if (usesAppRouter(isUnderSrcFolder)) {\n copyPromises.push(copyErrorJs(isUnderSrcFolder, true));\n copyPromises.push(copyGlobalErrorJs(isUnderSrcFolder));\n }\n await Promise.all(copyPromises);\n console.log('Done copying config files.');\n}\n//# sourceMappingURL=copy-config-files.js.map","\"use strict\";\nconst { copyConfigFiles } = require('./copy-config-files');\ncopyConfigFiles().catch((err) => {\n console.error(err);\n process.exit(1);\n});\n//# sourceMappingURL=copy-config-files-exec.js.map"],"names":["copyConfigFiles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,MAAM,KAAK,GAAG,OAAO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AQ,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;AACxE,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,gBAAgB,GAAG,aAAa,EAAE,CAAC;AAC7C,IAAI,IAAI,eAAe,CAAC,gBAAgB,CAAC,EAAE;AAC3C,QAAQ,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC,CAAC;AAChE,KAAK;AACL,IAAI,IAAI,aAAa,CAAC,gBAAgB,CAAC,EAAE;AACzC,QAAQ,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC;AAC/D,QAAQ,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAC/D,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AACpC,IAAI,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAC9C;;;;;;;;;AC3FA,MAAM,EAAE,eAAe,EAAE,GAAG,UAA8B,CAAC;AAC3D,eAAe,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK;AACjC,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACvB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@honeybadger-io/nextjs",
3
- "version": "5.7.4",
3
+ "version": "5.7.6",
4
4
  "description": "Next.js integration for Honeybadger",
5
5
  "keywords": [
6
6
  "nextjs",
@@ -30,7 +30,7 @@
30
30
  "url": "git+https://github.com/honeybadger-io/honeybadger-js.git"
31
31
  },
32
32
  "scripts": {
33
- "build": "tsc --build tsconfig.json && rollup -c && tsc --build tsconfig.types.json",
33
+ "build": "tsc --build tsconfig.json && rollup -c && rollup -c rollup.scripts.config.js && tsc --build tsconfig.types.json",
34
34
  "test": "./node_modules/jest/bin/jest.js --config jest.config.js"
35
35
  },
36
36
  "bugs": {
@@ -41,11 +41,11 @@
41
41
  "next": "13.x"
42
42
  },
43
43
  "dependencies": {
44
- "@honeybadger-io/js": "^6.4.3",
44
+ "@honeybadger-io/js": "^6.5.1",
45
45
  "@honeybadger-io/webpack": "5.1.7"
46
46
  },
47
47
  "devDependencies": {
48
- "@honeybadger-io/react": "^6.1.5",
48
+ "@honeybadger-io/react": "^6.1.7",
49
49
  "@rollup/plugin-commonjs": "^22.0.0",
50
50
  "@types/jest": "^29.5.3",
51
51
  "jest": "^29.6.1",
@@ -53,6 +53,7 @@
53
53
  "next": "^13.2.3",
54
54
  "rollup": "^2.70.2",
55
55
  "rollup-plugin-copy": "^3.4.0",
56
+ "rollup-plugin-executable": "^1.6.3",
56
57
  "ts-jest": "^29.1.1",
57
58
  "typescript": "^4.6.3"
58
59
  },
@@ -62,5 +63,5 @@
62
63
  "publishConfig": {
63
64
  "access": "public"
64
65
  },
65
- "gitHead": "94e663836936974474628967f5c440ffa668bc9b"
66
+ "gitHead": "a94ed4f057c836cac3f6d4a85b2e42892386ad50"
66
67
  }
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env node
2
-
3
1
  const { copyConfigFiles } = require('./copy-config-files')
4
2
 
5
3
  copyConfigFiles().catch((err) => {
@@ -1,94 +0,0 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const debug = process.env.HONEYBADGER_DEBUG === 'true';
4
- function usesTypescript() {
5
- return fs.existsSync('tsconfig.json');
6
- }
7
- function usesSrcFolder() {
8
- return fs.existsSync('src');
9
- }
10
- function usesPagesRouter(isUnderSrc) {
11
- const srcFolder = isUnderSrc ? 'src' : '';
12
- return fs.existsSync(path.join(srcFolder, 'pages'));
13
- }
14
- function usesAppRouter(isUnderSrc) {
15
- const srcFolder = isUnderSrc ? 'src' : '';
16
- return fs.existsSync(path.join(srcFolder, 'app'));
17
- }
18
- function getTargetPath(isUnderSrc, isAppRouter = false, isGlobalErrorComponent = false) {
19
- if (!isAppRouter && isGlobalErrorComponent) {
20
- throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');
21
- }
22
- const extension = usesTypescript() ? 'tsx' : 'js';
23
- let srcFolder = isUnderSrc ? 'src' : '';
24
- srcFolder = path.join(srcFolder, isAppRouter ? 'app' : 'pages');
25
- let fileName = '';
26
- if (isAppRouter) {
27
- fileName = isGlobalErrorComponent ? 'global-error' : 'error';
28
- }
29
- else {
30
- fileName = '_error';
31
- }
32
- return path.join(srcFolder, fileName + '.' + extension);
33
- }
34
- function getTemplate(isAppRouter = false, isGlobalErrorComponent = false) {
35
- if (!isAppRouter && isGlobalErrorComponent) {
36
- throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');
37
- }
38
- const extension = isGlobalErrorComponent ? 'tsx' : 'js';
39
- const templateName = isAppRouter ? '_error_app_router' : '_error';
40
- return path.resolve(__dirname, '../templates', templateName + '.' + extension);
41
- }
42
- async function copyErrorJs(isUnderSrc, isAppRouter = false) {
43
- const sourcePath = getTemplate(isAppRouter);
44
- const targetPath = getTargetPath(isUnderSrc, isAppRouter);
45
- return copyFileWithBackup(sourcePath, targetPath);
46
- }
47
- function copyGlobalErrorJs(isUnderSrc) {
48
- const sourcePath = getTemplate(true, true);
49
- const targetPath = getTargetPath(isUnderSrc, true, true);
50
- return copyFileWithBackup(sourcePath, targetPath);
51
- }
52
- async function copyFileWithBackup(sourcePath, targetPath) {
53
- const fileAlreadyExists = fs.existsSync(targetPath);
54
- if (fileAlreadyExists) {
55
- // Don't overwrite an existing file without creating a backup first
56
- const backupPath = targetPath + '.bak';
57
- if (debug) {
58
- console.debug('backing up', targetPath, 'to', backupPath);
59
- }
60
- await fs.promises.copyFile(targetPath, backupPath);
61
- }
62
- if (debug) {
63
- console.debug('copying', sourcePath, 'to', targetPath);
64
- }
65
- return fs.promises.copyFile(sourcePath, targetPath);
66
- }
67
- export async function copyConfigFiles() {
68
- if (debug) {
69
- console.debug('cwd', process.cwd());
70
- }
71
- const templateDir = path.resolve(__dirname, '../templates');
72
- const configFiles = [
73
- 'honeybadger.browser.config.js',
74
- 'honeybadger.edge.config.js',
75
- 'honeybadger.server.config.js',
76
- ];
77
- const copyPromises = configFiles.map((file) => {
78
- if (debug) {
79
- console.debug('copying', file);
80
- }
81
- return fs.promises.copyFile(path.join(templateDir, file), file);
82
- });
83
- const isUnderSrcFolder = usesSrcFolder();
84
- if (usesPagesRouter(isUnderSrcFolder)) {
85
- copyPromises.push(copyErrorJs(isUnderSrcFolder, false));
86
- }
87
- if (usesAppRouter(isUnderSrcFolder)) {
88
- copyPromises.push(copyErrorJs(isUnderSrcFolder, true));
89
- copyPromises.push(copyGlobalErrorJs(isUnderSrcFolder));
90
- }
91
- await Promise.all(copyPromises);
92
- console.log('Done copying config files.');
93
- }
94
- //# sourceMappingURL=copy-config-files.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"copy-config-files.js","sourceRoot":"","sources":["../src/copy-config-files.ts"],"names":[],"mappings":"AAAA,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,SAAS,cAAc;IACrB,OAAO,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,CAAA;AACvC,CAAC;AAED,SAAS,aAAa;IACpB,OAAO,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AAC7B,CAAC;AAED,SAAS,eAAe,CAAC,UAAmB;IAC1C,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;IAEzC,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS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AA;AAC3C,CAAC","sourcesContent":["const path = require('path')\nconst fs = require('fs')\n\nconst debug = process.env.HONEYBADGER_DEBUG === 'true'\n\nfunction usesTypescript() {\n return fs.existsSync('tsconfig.json')\n}\n\nfunction usesSrcFolder() {\n return fs.existsSync('src')\n}\n\nfunction usesPagesRouter(isUnderSrc: boolean) {\n const srcFolder = isUnderSrc ? 'src' : ''\n\n return fs.existsSync(path.join(srcFolder, 'pages'))\n}\n\nfunction usesAppRouter(isUnderSrc: boolean) {\n const srcFolder = isUnderSrc ? 'src' : ''\n\n return fs.existsSync(path.join(srcFolder, 'app'))\n}\n\nfunction getTargetPath(isUnderSrc: boolean, isAppRouter = false, isGlobalErrorComponent = false) {\n if (!isAppRouter && isGlobalErrorComponent) {\n throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true')\n }\n\n const extension = usesTypescript() ? 'tsx' : 'js'\n let srcFolder = isUnderSrc ? 'src' : ''\n srcFolder = path.join(srcFolder, isAppRouter ? 'app' : 'pages')\n\n let fileName = ''\n if (isAppRouter) {\n fileName = isGlobalErrorComponent ? 'global-error' : 'error'\n }\n else {\n fileName = '_error'\n }\n\n return path.join(srcFolder, fileName + '.' + extension)\n}\n\nfunction getTemplate(isAppRouter = false, isGlobalErrorComponent = false) {\n if (!isAppRouter && isGlobalErrorComponent) {\n throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true')\n }\n\n const extension = isGlobalErrorComponent ? 'tsx' : 'js'\n const templateName = isAppRouter ? '_error_app_router' : '_error'\n\n return path.resolve(__dirname, '../templates', templateName + '.' + extension)\n}\n\nasync function copyErrorJs(isUnderSrc: boolean, isAppRouter = false) {\n const sourcePath = getTemplate(isAppRouter)\n const targetPath = getTargetPath(isUnderSrc, isAppRouter)\n\n return copyFileWithBackup(sourcePath, targetPath)\n}\n\nfunction copyGlobalErrorJs(isUnderSrc: boolean) {\n const sourcePath = getTemplate(true, true)\n const targetPath = getTargetPath(isUnderSrc, true, true)\n\n return copyFileWithBackup(sourcePath, targetPath)\n}\n\nasync function copyFileWithBackup(sourcePath, targetPath) {\n const fileAlreadyExists = fs.existsSync(targetPath)\n if (fileAlreadyExists) {\n // Don't overwrite an existing file without creating a backup first\n const backupPath = targetPath + '.bak'\n if (debug) {\n console.debug('backing up', targetPath, 'to', backupPath)\n }\n await fs.promises.copyFile(targetPath, backupPath)\n }\n\n if (debug) {\n console.debug('copying', sourcePath, 'to', targetPath)\n }\n\n return fs.promises.copyFile(sourcePath, targetPath)\n}\n\nexport async function copyConfigFiles() {\n if (debug) {\n console.debug('cwd', process.cwd())\n }\n\n const templateDir = path.resolve(__dirname, '../templates')\n const configFiles = [\n 'honeybadger.browser.config.js',\n 'honeybadger.edge.config.js',\n 'honeybadger.server.config.js',\n ]\n\n const copyPromises = configFiles.map((file) => {\n if (debug) {\n console.debug('copying', file)\n }\n return fs.promises.copyFile(path.join(templateDir, file), file)\n })\n\n const isUnderSrcFolder = usesSrcFolder()\n\n if (usesPagesRouter(isUnderSrcFolder)) {\n copyPromises.push(copyErrorJs(isUnderSrcFolder, false))\n }\n\n if (usesAppRouter(isUnderSrcFolder)) {\n copyPromises.push(copyErrorJs(isUnderSrcFolder, true))\n copyPromises.push(copyGlobalErrorJs(isUnderSrcFolder))\n }\n\n await Promise.all(copyPromises);\n\n console.log('Done copying config files.')\n}\n"]}