@honeybadger-io/nextjs 5.6.3 → 5.7.0

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.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ declare const copyConfigFiles: any;
3
+ //# sourceMappingURL=copy-config-files-exec.d.ts.map
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ const { copyConfigFiles } = require('./copy-config-files');
4
+ copyConfigFiles().catch((err) => {
5
+ console.error(err);
6
+ process.exit(1);
7
+ });
8
+ //# sourceMappingURL=copy-config-files-exec.js.map
@@ -0,0 +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,13 +1,2 @@
1
- #!/usr/bin/env node
2
- declare const path: any;
3
- declare const fs: any;
4
- declare const debug: boolean;
5
- declare function usesTypescript(): any;
6
- declare function usesPagesRouter(): any;
7
- declare function usesAppRouter(): any;
8
- declare function getTargetPath(isAppRouter?: boolean, isGlobalErrorComponent?: boolean): any;
9
- declare function getTemplate(isAppRouter?: boolean, isGlobalErrorComponent?: boolean): any;
10
- declare function copyErrorJs(isAppRouter?: boolean): Promise<any>;
11
- declare function copyGlobalErrorJs(): Promise<any>;
12
- declare function copyFileWithBackup(sourcePath: any, targetPath: any): Promise<any>;
13
- declare function copyConfigFiles(): Promise<void>;
1
+ export declare function copyConfigFiles(): Promise<void>;
2
+ //# sourceMappingURL=copy-config-files.d.ts.map
@@ -1,23 +1,27 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
1
  const path = require('path');
4
2
  const fs = require('fs');
5
3
  const debug = process.env.HONEYBADGER_DEBUG === 'true';
6
4
  function usesTypescript() {
7
5
  return fs.existsSync('tsconfig.json');
8
6
  }
9
- function usesPagesRouter() {
10
- return fs.existsSync('pages');
7
+ function usesSrcFolder() {
8
+ return fs.existsSync('src');
11
9
  }
12
- function usesAppRouter() {
13
- return fs.existsSync('app');
10
+ function usesPagesRouter(isUnderSrc) {
11
+ const srcFolder = isUnderSrc ? 'src' : '';
12
+ return fs.existsSync(path.join(srcFolder, 'pages'));
14
13
  }
15
- function getTargetPath(isAppRouter = false, isGlobalErrorComponent = false) {
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) {
16
19
  if (!isAppRouter && isGlobalErrorComponent) {
17
20
  throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');
18
21
  }
19
22
  const extension = usesTypescript() ? 'tsx' : 'js';
20
- const srcFolder = isAppRouter ? 'app' : 'pages';
23
+ let srcFolder = isUnderSrc ? 'src' : '';
24
+ srcFolder = path.join(srcFolder, isAppRouter ? 'app' : 'pages');
21
25
  let fileName = '';
22
26
  if (isAppRouter) {
23
27
  fileName = isGlobalErrorComponent ? 'global-error' : 'error';
@@ -35,14 +39,14 @@ function getTemplate(isAppRouter = false, isGlobalErrorComponent = false) {
35
39
  const templateName = isAppRouter ? '_error_app_router' : '_error';
36
40
  return path.resolve(__dirname, '../templates', templateName + '.' + extension);
37
41
  }
38
- async function copyErrorJs(isAppRouter = false) {
42
+ async function copyErrorJs(isUnderSrc, isAppRouter = false) {
39
43
  const sourcePath = getTemplate(isAppRouter);
40
- const targetPath = getTargetPath(isAppRouter);
44
+ const targetPath = getTargetPath(isUnderSrc, isAppRouter);
41
45
  return copyFileWithBackup(sourcePath, targetPath);
42
46
  }
43
- function copyGlobalErrorJs() {
47
+ function copyGlobalErrorJs(isUnderSrc) {
44
48
  const sourcePath = getTemplate(true, true);
45
- const targetPath = getTargetPath(true, true);
49
+ const targetPath = getTargetPath(isUnderSrc, true, true);
46
50
  return copyFileWithBackup(sourcePath, targetPath);
47
51
  }
48
52
  async function copyFileWithBackup(sourcePath, targetPath) {
@@ -60,7 +64,7 @@ async function copyFileWithBackup(sourcePath, targetPath) {
60
64
  }
61
65
  return fs.promises.copyFile(sourcePath, targetPath);
62
66
  }
63
- async function copyConfigFiles() {
67
+ export async function copyConfigFiles() {
64
68
  if (debug) {
65
69
  console.debug('cwd', process.cwd());
66
70
  }
@@ -76,18 +80,15 @@ async function copyConfigFiles() {
76
80
  }
77
81
  return fs.promises.copyFile(path.join(templateDir, file), file);
78
82
  });
79
- if (usesPagesRouter()) {
80
- copyPromises.push(copyErrorJs(false));
83
+ const isUnderSrcFolder = usesSrcFolder();
84
+ if (usesPagesRouter(isUnderSrcFolder)) {
85
+ copyPromises.push(copyErrorJs(isUnderSrcFolder, false));
81
86
  }
82
- if (usesAppRouter()) {
83
- copyPromises.push(copyErrorJs(true));
84
- copyPromises.push(copyGlobalErrorJs());
87
+ if (usesAppRouter(isUnderSrcFolder)) {
88
+ copyPromises.push(copyErrorJs(isUnderSrcFolder, true));
89
+ copyPromises.push(copyGlobalErrorJs(isUnderSrcFolder));
85
90
  }
86
91
  await Promise.all(copyPromises);
87
92
  console.log('Done copying config files.');
88
93
  }
89
- copyConfigFiles().catch((err) => {
90
- console.error(err);
91
- process.exit(1);
92
- });
93
94
  //# sourceMappingURL=copy-config-files.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"copy-config-files.js","sourceRoot":"","sources":["../src/copy-config-files.ts"],"names":[],"mapp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,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nconst 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 usesPagesRouter() {\n return fs.existsSync('pages')\n}\n\nfunction usesAppRouter() {\n return fs.existsSync('app')\n}\n\nfunction getTargetPath(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 const 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(isAppRouter = false) {\n const sourcePath = getTemplate(isAppRouter)\n const targetPath = getTargetPath(isAppRouter)\n\n return copyFileWithBackup(sourcePath, targetPath)\n}\n\nfunction copyGlobalErrorJs() {\n const sourcePath = getTemplate(true, true)\n const targetPath = getTargetPath(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\nasync 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 if (usesPagesRouter()) {\n copyPromises.push(copyErrorJs(false))\n }\n\n if (usesAppRouter()) {\n copyPromises.push(copyErrorJs(true))\n copyPromises.push(copyGlobalErrorJs())\n }\n\n await Promise.all(copyPromises);\n\n console.log('Done copying config files.')\n}\n\ncopyConfigFiles().catch((err) => {\n console.error(err)\n process.exit(1)\n})\n"]}
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,EAAE,OAAO,CAAC,CAAC,CAAA;AACrD,C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st 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"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=copy-config-files.test.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { HoneybadgerNextJsConfig } from './types';
2
2
  export declare function setupHoneybadger(config: any, honeybadgerNextJsConfig: HoneybadgerNextJsConfig): any;
3
+ //# sourceMappingURL=index.d.ts.map
package/dist/types.d.ts CHANGED
@@ -19,3 +19,4 @@ export type HoneybadgerWebpackPluginOptions = {
19
19
  localUsername?: string;
20
20
  };
21
21
  };
22
+ //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@honeybadger-io/nextjs",
3
- "version": "5.6.3",
3
+ "version": "5.7.0",
4
4
  "description": "Next.js integration for Honeybadger",
5
5
  "keywords": [
6
6
  "nextjs",
@@ -23,14 +23,15 @@
23
23
  "templates"
24
24
  ],
25
25
  "bin": {
26
- "honeybadger-copy-config-files": "dist/copy-config-files.js"
26
+ "honeybadger-copy-config-files": "dist/copy-config-files-exec.js"
27
27
  },
28
28
  "repository": {
29
29
  "type": "git",
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 && tsc --build tsconfig.types.json",
34
+ "test": "./node_modules/jest/bin/jest.js --config jest.config.js"
34
35
  },
35
36
  "bugs": {
36
37
  "url": "https://github.com/honeybadger-io/honeybadger-js/issues"
@@ -40,15 +41,19 @@
40
41
  "next": "13.x"
41
42
  },
42
43
  "dependencies": {
43
- "@honeybadger-io/js": "^6.2.0",
44
+ "@honeybadger-io/js": "^6.3.0",
44
45
  "@honeybadger-io/webpack": "5.1.7"
45
46
  },
46
47
  "devDependencies": {
47
- "@honeybadger-io/react": "5.1.3",
48
+ "@honeybadger-io/react": "^6.1.1",
48
49
  "@rollup/plugin-commonjs": "^22.0.0",
50
+ "@types/jest": "^29.5.3",
51
+ "jest": "^29.6.1",
52
+ "mock-fs": "^5.2.0",
49
53
  "next": "^13.2.3",
50
54
  "rollup": "^2.70.2",
51
55
  "rollup-plugin-copy": "^3.4.0",
56
+ "ts-jest": "^29.1.1",
52
57
  "typescript": "^4.6.3"
53
58
  },
54
59
  "engines": {
@@ -57,5 +62,5 @@
57
62
  "publishConfig": {
58
63
  "access": "public"
59
64
  },
60
- "gitHead": "81975a98dd8ac13e75a58d460ba58e4cc6a28fbd"
65
+ "gitHead": "5eb6dea8f1099331b6b3205be1711de8cd5bf088"
61
66
  }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { copyConfigFiles } = require('./copy-config-files')
4
+
5
+ copyConfigFiles().catch((err) => {
6
+ console.error(err)
7
+ process.exit(1)
8
+ })
@@ -0,0 +1,172 @@
1
+ import mock from 'mock-fs'
2
+ import fs from 'fs'
3
+ import path from 'path'
4
+ import { copyConfigFiles } from './copy-config-files';
5
+ describe('copy-config-files', () => {
6
+
7
+ afterEach(() => {
8
+ mock.restore()
9
+ })
10
+
11
+ it('should copy config files to a project with pages router', async () => {
12
+ mock({
13
+ 'templates': mock.load(path.resolve(__dirname, '..', 'templates')),
14
+ 'pages': {
15
+ 'index.js': 'dummy content'
16
+ }
17
+ })
18
+
19
+ await copyConfigFiles()
20
+
21
+ expect(fs.existsSync('honeybadger.browser.config.js')).toBe(true)
22
+ expect(fs.existsSync('honeybadger.edge.config.js')).toBe(true)
23
+ expect(fs.existsSync('honeybadger.server.config.js')).toBe(true)
24
+ expect(fs.existsSync('pages/_error.js')).toBe(true)
25
+ expect(fs.existsSync('app/error.js')).toBe(false)
26
+ })
27
+
28
+ it('should copy config files to a project with app router', async () => {
29
+ mock({
30
+ 'templates': mock.load(path.resolve(__dirname, '..', 'templates')),
31
+ 'app': {
32
+ 'index.js': 'dummy content'
33
+ }
34
+ })
35
+
36
+ await copyConfigFiles()
37
+
38
+ expect(fs.existsSync('honeybadger.browser.config.js')).toBe(true)
39
+ expect(fs.existsSync('honeybadger.edge.config.js')).toBe(true)
40
+ expect(fs.existsSync('honeybadger.server.config.js')).toBe(true)
41
+ expect(fs.existsSync('app/error.js')).toBe(true)
42
+ expect(fs.existsSync('app/global-error.js')).toBe(true)
43
+ expect(fs.existsSync('pages/_error.js')).toBe(false)
44
+ })
45
+
46
+ it('should copy config files to a project with pages router under src folder', async () => {
47
+ mock({
48
+ 'templates': mock.load(path.resolve(__dirname, '..', 'templates')),
49
+ 'src': {
50
+ 'pages': {
51
+ 'index.js': 'dummy content'
52
+ }
53
+ }
54
+ })
55
+
56
+ await copyConfigFiles()
57
+
58
+ expect(fs.existsSync('honeybadger.browser.config.js')).toBe(true)
59
+ expect(fs.existsSync('honeybadger.edge.config.js')).toBe(true)
60
+ expect(fs.existsSync('honeybadger.server.config.js')).toBe(true)
61
+ expect(fs.existsSync('src/pages/_error.js')).toBe(true)
62
+ expect(fs.existsSync('pages/_error.js')).toBe(false)
63
+ })
64
+
65
+ it('should copy config files to a project with app router under src folder', async () => {
66
+ mock({
67
+ 'templates': mock.load(path.resolve(__dirname, '..', 'templates')),
68
+ 'src': {
69
+ 'app': {
70
+ 'index.js': 'dummy content'
71
+ }
72
+ }
73
+ })
74
+
75
+ await copyConfigFiles()
76
+
77
+ expect(fs.existsSync('honeybadger.browser.config.js')).toBe(true)
78
+ expect(fs.existsSync('honeybadger.edge.config.js')).toBe(true)
79
+ expect(fs.existsSync('honeybadger.server.config.js')).toBe(true)
80
+ expect(fs.existsSync('src/app/error.js')).toBe(true)
81
+ expect(fs.existsSync('src/app/global-error.js')).toBe(true)
82
+ expect(fs.existsSync('app/error.js')).toBe(false)
83
+ expect(fs.existsSync('app/global-error.js')).toBe(false)
84
+ })
85
+
86
+ it('should copy config files to a typescript project with pages router', async () => {
87
+ mock({
88
+ 'templates': mock.load(path.resolve(__dirname, '..', 'templates')),
89
+ 'pages': {
90
+ 'index.ts': 'dummy content'
91
+ },
92
+ 'tsconfig.json': 'dummy content'
93
+ })
94
+
95
+ await copyConfigFiles()
96
+
97
+ expect(fs.existsSync('honeybadger.browser.config.js')).toBe(true)
98
+ expect(fs.existsSync('honeybadger.edge.config.js')).toBe(true)
99
+ expect(fs.existsSync('honeybadger.server.config.js')).toBe(true)
100
+ expect(fs.existsSync('pages/_error.tsx')).toBe(true)
101
+ expect(fs.existsSync('pages/_error.js')).toBe(false)
102
+ expect(fs.existsSync('app/error.tsx')).toBe(false)
103
+ })
104
+
105
+ it('should copy config files to a typescript project with app router', async () => {
106
+ mock({
107
+ 'templates': mock.load(path.resolve(__dirname, '..', 'templates')),
108
+ 'app': {
109
+ 'index.ts': 'dummy content'
110
+ },
111
+ 'tsconfig.json': 'dummy content'
112
+ })
113
+
114
+ await copyConfigFiles()
115
+
116
+ expect(fs.existsSync('honeybadger.browser.config.js')).toBe(true)
117
+ expect(fs.existsSync('honeybadger.edge.config.js')).toBe(true)
118
+ expect(fs.existsSync('honeybadger.server.config.js')).toBe(true)
119
+ expect(fs.existsSync('app/error.tsx')).toBe(true)
120
+ expect(fs.existsSync('app/global-error.tsx')).toBe(true)
121
+ expect(fs.existsSync('app/error.js')).toBe(false)
122
+ expect(fs.existsSync('app/global-error.js')).toBe(false)
123
+ expect(fs.existsSync('pages/error.tsx')).toBe(false)
124
+ })
125
+
126
+ it('should copy config files to a typescript project with pages router under src folder', async () => {
127
+ mock({
128
+ 'templates': mock.load(path.resolve(__dirname, '..', 'templates')),
129
+ 'src': {
130
+ 'pages': {
131
+ 'index.ts': 'dummy content'
132
+ },
133
+ },
134
+ 'tsconfig.json': 'dummy content'
135
+ })
136
+
137
+ await copyConfigFiles()
138
+
139
+ expect(fs.existsSync('honeybadger.browser.config.js')).toBe(true)
140
+ expect(fs.existsSync('honeybadger.edge.config.js')).toBe(true)
141
+ expect(fs.existsSync('honeybadger.server.config.js')).toBe(true)
142
+ expect(fs.existsSync('src/pages/_error.tsx')).toBe(true)
143
+ expect(fs.existsSync('src/pages/_error.js')).toBe(false)
144
+ expect(fs.existsSync('pages/_error.tsx')).toBe(false)
145
+ expect(fs.existsSync('pages/_error.js')).toBe(false)
146
+ })
147
+
148
+ it('should copy config files to a typescript project with app router under src folder', async () => {
149
+ mock({
150
+ 'templates': mock.load(path.resolve(__dirname, '..', 'templates')),
151
+ 'src': {
152
+ 'app': {
153
+ 'index.ts': 'dummy content'
154
+ },
155
+ },
156
+ 'tsconfig.json': 'dummy content'
157
+ })
158
+
159
+ await copyConfigFiles()
160
+
161
+ expect(fs.existsSync('honeybadger.browser.config.js')).toBe(true)
162
+ expect(fs.existsSync('honeybadger.edge.config.js')).toBe(true)
163
+ expect(fs.existsSync('honeybadger.server.config.js')).toBe(true)
164
+ expect(fs.existsSync('src/app/error.tsx')).toBe(true)
165
+ expect(fs.existsSync('src/app/global-error.tsx')).toBe(true)
166
+ expect(fs.existsSync('src/app/error.js')).toBe(false)
167
+ expect(fs.existsSync('src/app/global-error.js')).toBe(false)
168
+ expect(fs.existsSync('app/error.tsx')).toBe(false)
169
+ expect(fs.existsSync('app/error.js')).toBe(false)
170
+ })
171
+
172
+ })
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env node
2
-
3
1
  const path = require('path')
4
2
  const fs = require('fs')
5
3
 
@@ -9,21 +7,30 @@ function usesTypescript() {
9
7
  return fs.existsSync('tsconfig.json')
10
8
  }
11
9
 
12
- function usesPagesRouter() {
13
- return fs.existsSync('pages')
10
+ function usesSrcFolder() {
11
+ return fs.existsSync('src')
14
12
  }
15
13
 
16
- function usesAppRouter() {
17
- return fs.existsSync('app')
14
+ function usesPagesRouter(isUnderSrc: boolean) {
15
+ const srcFolder = isUnderSrc ? 'src' : ''
16
+
17
+ return fs.existsSync(path.join(srcFolder, 'pages'))
18
18
  }
19
19
 
20
- function getTargetPath(isAppRouter = false, isGlobalErrorComponent = false) {
20
+ function usesAppRouter(isUnderSrc: boolean) {
21
+ const srcFolder = isUnderSrc ? 'src' : ''
22
+
23
+ return fs.existsSync(path.join(srcFolder, 'app'))
24
+ }
25
+
26
+ function getTargetPath(isUnderSrc: boolean, isAppRouter = false, isGlobalErrorComponent = false) {
21
27
  if (!isAppRouter && isGlobalErrorComponent) {
22
28
  throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true')
23
29
  }
24
30
 
25
31
  const extension = usesTypescript() ? 'tsx' : 'js'
26
- const srcFolder = isAppRouter ? 'app' : 'pages'
32
+ let srcFolder = isUnderSrc ? 'src' : ''
33
+ srcFolder = path.join(srcFolder, isAppRouter ? 'app' : 'pages')
27
34
 
28
35
  let fileName = ''
29
36
  if (isAppRouter) {
@@ -47,16 +54,16 @@ function getTemplate(isAppRouter = false, isGlobalErrorComponent = false) {
47
54
  return path.resolve(__dirname, '../templates', templateName + '.' + extension)
48
55
  }
49
56
 
50
- async function copyErrorJs(isAppRouter = false) {
57
+ async function copyErrorJs(isUnderSrc: boolean, isAppRouter = false) {
51
58
  const sourcePath = getTemplate(isAppRouter)
52
- const targetPath = getTargetPath(isAppRouter)
59
+ const targetPath = getTargetPath(isUnderSrc, isAppRouter)
53
60
 
54
61
  return copyFileWithBackup(sourcePath, targetPath)
55
62
  }
56
63
 
57
- function copyGlobalErrorJs() {
64
+ function copyGlobalErrorJs(isUnderSrc: boolean) {
58
65
  const sourcePath = getTemplate(true, true)
59
- const targetPath = getTargetPath(true, true)
66
+ const targetPath = getTargetPath(isUnderSrc, true, true)
60
67
 
61
68
  return copyFileWithBackup(sourcePath, targetPath)
62
69
  }
@@ -79,7 +86,7 @@ async function copyFileWithBackup(sourcePath, targetPath) {
79
86
  return fs.promises.copyFile(sourcePath, targetPath)
80
87
  }
81
88
 
82
- async function copyConfigFiles() {
89
+ export async function copyConfigFiles() {
83
90
  if (debug) {
84
91
  console.debug('cwd', process.cwd())
85
92
  }
@@ -98,21 +105,18 @@ async function copyConfigFiles() {
98
105
  return fs.promises.copyFile(path.join(templateDir, file), file)
99
106
  })
100
107
 
101
- if (usesPagesRouter()) {
102
- copyPromises.push(copyErrorJs(false))
108
+ const isUnderSrcFolder = usesSrcFolder()
109
+
110
+ if (usesPagesRouter(isUnderSrcFolder)) {
111
+ copyPromises.push(copyErrorJs(isUnderSrcFolder, false))
103
112
  }
104
113
 
105
- if (usesAppRouter()) {
106
- copyPromises.push(copyErrorJs(true))
107
- copyPromises.push(copyGlobalErrorJs())
114
+ if (usesAppRouter(isUnderSrcFolder)) {
115
+ copyPromises.push(copyErrorJs(isUnderSrcFolder, true))
116
+ copyPromises.push(copyGlobalErrorJs(isUnderSrcFolder))
108
117
  }
109
118
 
110
119
  await Promise.all(copyPromises);
111
120
 
112
121
  console.log('Done copying config files.')
113
122
  }
114
-
115
- copyConfigFiles().catch((err) => {
116
- console.error(err)
117
- process.exit(1)
118
- })