-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(nextjs): Exclude build-time files from page dependency manifests #6058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lobsterkatie
merged 3 commits into
master
from
kmclb-nextjs-exclude-build-files-from-nft
Nov 22, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1 +1,8 @@ | ||
module.exports = require('../../jest/jest.config.js'); | ||
const baseConfig = require('../../jest/jest.config.js'); | ||
|
||
module.exports = { | ||
...baseConfig, | ||
// This prevents the build tests from running when unit tests run. (If they do, they fail, because the build being | ||
// tested hasn't necessarily run yet.) | ||
testPathIgnorePatterns: ['<rootDir>/test/buildProcess/'], | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
This file contains hidden or 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 hidden or 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,4 @@ | ||
// In order to not have the build tests run as part of the unit test suite, we exclude them in | ||
// `packages/nextjs/jest.config.js`. The resets the test-matching regex so that when `runTest.ts` calls `yarn jest` with | ||
// ths config file, jest will find the tests in `tests`. | ||
module.exports = require('../../../../jest/jest.config.js'); |
This file contains hidden or 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,42 @@ | ||
/* eslint-disable no-console */ | ||
import * as childProcess from 'child_process'; | ||
import * as path from 'path'; | ||
import { sync as rimrafSync } from 'rimraf'; | ||
|
||
const TEST_APP_DIR = 'test/buildProcess/testApp'; | ||
|
||
/** | ||
* Run the given shell command, piping the shell process's `stdin`, `stdout`, and `stderr` to that of the current | ||
* process if this script is run with the `--debug` flag. Returns contents of `stdout`. | ||
*/ | ||
function run(cmd: string, options?: childProcess.ExecSyncOptions): string { | ||
return String( | ||
childProcess.execSync(cmd, { | ||
stdio: process.argv.includes('--debug') ? 'inherit' : 'ignore', | ||
...options, | ||
}), | ||
); | ||
} | ||
|
||
// Note: We use a file dependency for the SDK, rather than linking it, because if it's linked, nextjs rolls the entire | ||
// SDK and all of its dependencies into a bundle, making it impossible to tell (from the NFT file, at least) what's | ||
// being included. | ||
console.log('Installing dependencies...'); | ||
process.chdir(TEST_APP_DIR); | ||
rimrafSync('node_modules'); | ||
run('yarn'); | ||
|
||
console.log('Building app...'); | ||
rimrafSync('.next'); | ||
run('yarn build'); | ||
|
||
console.log('App built. Running tests...'); | ||
process.chdir('..'); | ||
const jestConfigFile = path.resolve(process.cwd(), 'jest.config.js'); | ||
try { | ||
// We have to specify the config file explicitly because otherwise it'll use the one at the root level of | ||
// `packages/nextjs`, since that's where the closest `package.json` file is | ||
run(`yarn jest --config ${jestConfigFile} tests`, { stdio: 'inherit' }); | ||
} catch (err) { | ||
console.log('\nNot all build process tests passed.'); | ||
} |
This file contains hidden or 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,36 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.pnpm-debug.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains hidden or 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,25 @@ | ||
// const nextConfig = { | ||
// } | ||
// | ||
// module.exports = nextConfig | ||
|
||
const { withSentryConfig } = require('@sentry/nextjs'); | ||
|
||
const moduleExports = { | ||
reactStrictMode: true, | ||
swcMinify: true, | ||
eslint: { | ||
ignoreDuringBuilds: true, | ||
}, | ||
sentry: { | ||
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts` | ||
// TODO (v8): This can come out in v8, because this option will get a default value | ||
hideSourceMaps: false, | ||
}, | ||
}; | ||
const SentryWebpackPluginOptions = { | ||
dryRun: true, | ||
silent: true, | ||
}; | ||
|
||
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions); |
This file contains hidden or 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 @@ | ||
{ | ||
"name": "testapp", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint" | ||
}, | ||
"dependencies": { | ||
"@sentry/nextjs": "file:../../../", | ||
"@vercel/nft": "latest", | ||
"next": "13.0.1", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/nextjs/test/buildProcess/testApp/sentry.client.config.js
This file contains hidden or 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,5 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
}); |
5 changes: 5 additions & 0 deletions
5
packages/nextjs/test/buildProcess/testApp/sentry.server.config.js
This file contains hidden or 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,5 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
}); |
This file contains hidden or 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,3 @@ | ||
{ | ||
"dogs": "are great" | ||
} |
This file contains hidden or 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,5 @@ | ||
function MyApp({ Component, pageProps }) { | ||
return <Component {...pageProps} />; | ||
} | ||
|
||
export default MyApp; |
8 changes: 8 additions & 0 deletions
8
packages/nextjs/test/buildProcess/testApp/src/pages/api/dogs.js
This file contains hidden or 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 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
export default function handler(req, res) { | ||
const dogData = JSON.parse(fs.readFileSync(path.resolve('../../dogs.json'))); | ||
dogData.test = 'something'; | ||
res.status(200).json(dogData); | ||
} |
This file contains hidden or 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,3 @@ | ||
export default function Home() { | ||
return <div>This is the homepage.</div>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.