-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automatic merging of next.config.js files (#222)
This pr adds in automatic merging of the next.config.js files. If there is no existing next.config.js file, then we will add the existing default next.config.js file in. If we are able to merge Sentry's with the existing, then the file will be updated (with the original saved as next.config.original.js). If we are unable to merge, we will create a template file and ask them to merge (the status quo approach) .
- Loading branch information
1 parent
29ab0f1
commit 8c08d50
Showing
13 changed files
with
311 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as fs from 'fs'; | ||
|
||
// merges the config files | ||
export function mergeConfigFile( | ||
sourcePath: string, | ||
templatePath: string, | ||
): boolean { | ||
try { | ||
const templateFile = fs.readFileSync(templatePath, 'utf8'); | ||
const sourceFile = fs.readFileSync(sourcePath, 'utf8'); | ||
const newText = templateFile.replace('// ORIGINAL CONFIG', sourceFile); | ||
Function(newText); // check if the file is valid javascript | ||
fs.writeFileSync(sourcePath, newText); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/// <reference types="jest" /> | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
import { mergeConfigFile } from '../MergeConfig'; | ||
|
||
const configPath = path.join(__dirname, '..', 'test-fixtures/next.config.js'); | ||
const templatePath = path.join( | ||
__dirname, | ||
'..', | ||
'..', | ||
'..', | ||
'scripts/NextJS/configs/next.config.template.js', | ||
); | ||
|
||
function configFileNames(num: number): { | ||
sourcePath: string; | ||
mergedPath: string; | ||
} { | ||
const sourcePath = path.join( | ||
__dirname, | ||
'..', | ||
`test-fixtures/next.config.${num}.js`, | ||
); | ||
const mergedPath = path.join( | ||
__dirname, | ||
'..', | ||
`test-fixtures/next.config.${num}-merged.js`, | ||
); | ||
return { sourcePath, mergedPath }; | ||
} | ||
|
||
describe('Merging next.config.js', () => { | ||
test('merge basic next.config.js', () => { | ||
const { sourcePath, mergedPath } = configFileNames(1); | ||
fs.copyFileSync(sourcePath, configPath); | ||
|
||
expect(mergeConfigFile(configPath, templatePath)).toBe(true); | ||
expect( | ||
fs.readFileSync(configPath, 'utf8') === | ||
fs.readFileSync(mergedPath, 'utf8'), | ||
).toBe(true); | ||
fs.unlinkSync(configPath); | ||
}); | ||
|
||
test('merge invalid javascript config', () => { | ||
const { sourcePath } = configFileNames(2); | ||
fs.copyFileSync(sourcePath, configPath); | ||
|
||
expect(mergeConfigFile(configPath, templatePath)).toBe(false); | ||
fs.unlinkSync(configPath); | ||
}); | ||
|
||
test('merge more complicated next.config.js', () => { | ||
const { sourcePath, mergedPath } = configFileNames(3); | ||
fs.copyFileSync(sourcePath, configPath); | ||
|
||
expect(mergeConfigFile(configPath, templatePath)).toBe(true); | ||
expect( | ||
fs.readFileSync(configPath, 'utf8') === | ||
fs.readFileSync(mergedPath, 'utf8'), | ||
).toBe(true); | ||
fs.unlinkSync(configPath); | ||
}); | ||
|
||
test('merge next.config.js with function', () => { | ||
const { sourcePath, mergedPath } = configFileNames(4); | ||
fs.copyFileSync(sourcePath, configPath); | ||
|
||
expect(mergeConfigFile(configPath, templatePath)).toBe(true); | ||
expect( | ||
fs.readFileSync(configPath, 'utf8') === | ||
fs.readFileSync(mergedPath, 'utf8'), | ||
).toBe(true); | ||
fs.unlinkSync(configPath); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This file sets a custom webpack configuration to use your Next.js app | ||
// with Sentry. | ||
// https://nextjs.org/docs/api-reference/next.config.js/introduction | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/ | ||
const { withSentryConfig } = require('@sentry/nextjs'); | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
}; | ||
|
||
module.exports = nextConfig; | ||
|
||
module.exports = withSentryConfig( | ||
module.exports, | ||
{ silent: true }, | ||
{ hideSourcemaps: true }, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
}; | ||
|
||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
|
||
|
||
|
||
|
||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This file sets a custom webpack configuration to use your Next.js app | ||
// with Sentry. | ||
// https://nextjs.org/docs/api-reference/next.config.js/introduction | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/ | ||
const { withSentryConfig } = require('@sentry/nextjs'); | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
images: { | ||
domains: [], | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig; | ||
|
||
module.exports = withSentryConfig( | ||
module.exports, | ||
{ silent: true }, | ||
{ hideSourcemaps: true }, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
images: { | ||
domains: [], | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This file sets a custom webpack configuration to use your Next.js app | ||
// with Sentry. | ||
// https://nextjs.org/docs/api-reference/next.config.js/introduction | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/ | ||
const { withSentryConfig } = require('@sentry/nextjs'); | ||
|
||
module.exports = (phase, { defaultConfig }) => { | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
/* config options here */ | ||
}; | ||
return nextConfig; | ||
}; | ||
|
||
module.exports = withSentryConfig( | ||
module.exports, | ||
{ silent: true }, | ||
{ hideSourcemaps: true }, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = (phase, { defaultConfig }) => { | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
/* config options here */ | ||
}; | ||
return nextConfig; | ||
}; |
Oops, something went wrong.