Skip to content

Commit

Permalink
Merge branch 'canary' into fix/jest-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Jan 31, 2022
2 parents 5e661e4 + 5b31c18 commit e8b21b6
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 248 deletions.
6 changes: 4 additions & 2 deletions docs/testing.md
Expand Up @@ -281,7 +281,8 @@ const createJestConfig = nextJest({

// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
moduleDirectories: ['node_modules', '<rootDir>/'],
testEnvironment: 'jest-environment-jsdom',
Expand Down Expand Up @@ -329,7 +330,8 @@ module.exports = {
// Handle module aliases
'^@/components/(.*)$': '<rootDir>/components/$1',
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
testEnvironment: 'jsdom',
transform: {
Expand Down
4 changes: 4 additions & 0 deletions packages/next/build/webpack-config.ts
Expand Up @@ -48,6 +48,7 @@ import { regexLikeCss } from './webpack/config/blocks/css'
import { CopyFilePlugin } from './webpack/plugins/copy-file-plugin'
import { FlightManifestPlugin } from './webpack/plugins/flight-manifest-plugin'
import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin'
import FunctionsManifestPlugin from './webpack/plugins/functions-manifest-plugin'
import type { Span } from '../trace'
import { getRawPageExtensions } from './utils'
import browserslist from 'next/dist/compiled/browserslist'
Expand Down Expand Up @@ -1460,6 +1461,9 @@ export default async function getBaseWebpackConfig(
// replacement is done before its process.env.* handling
(!isServer || webServerRuntime) &&
new MiddlewarePlugin({ dev, webServerRuntime }),
process.env.ENABLE_FILE_SYSTEM_API === '1' &&
webServerRuntime &&
new FunctionsManifestPlugin({ dev, webServerRuntime }),
isServer && new NextJsSsrImportPlugin(),
!isServer &&
new BuildManifestPlugin({
Expand Down
68 changes: 68 additions & 0 deletions packages/next/build/webpack/plugins/functions-manifest-plugin.ts
@@ -0,0 +1,68 @@
import { sources, webpack5 } from 'next/dist/compiled/webpack/webpack'
import { collectAssets, getEntrypointInfo } from './middleware-plugin'
import { FUNCTIONS_MANIFEST } from '../../../shared/lib/constants'

const PLUGIN_NAME = 'FunctionsManifestPlugin'
export interface FunctionsManifest {
version: 1
pages: {
[page: string]: {
runtime: string
env: string[]
files: string[]
name: string
page: string
regexp: string
}
}
}

export default class FunctionsManifestPlugin {
dev: boolean
webServerRuntime: boolean

constructor({
dev,
webServerRuntime,
}: {
dev: boolean
webServerRuntime: boolean
}) {
this.dev = dev
this.webServerRuntime = webServerRuntime
}

createAssets(
compilation: webpack5.Compilation,
assets: any,
envPerRoute: Map<string, string[]>,
webServerRuntime: boolean
) {
const functionsManifest: FunctionsManifest = {
version: 1,
pages: {},
}

const infos = getEntrypointInfo(compilation, envPerRoute, webServerRuntime)
infos.forEach((info) => {
functionsManifest.pages[info.page] = {
runtime: 'web',
...info,
}
})

const assetPath =
(this.webServerRuntime ? '' : 'server/') + FUNCTIONS_MANIFEST
assets[assetPath] = new sources.RawSource(
JSON.stringify(functionsManifest, null, 2)
)
}

apply(compiler: webpack5.Compiler) {
collectAssets(compiler, this.createAssets.bind(this), {
dev: this.dev,
pluginName: PLUGIN_NAME,
webServerRuntime: this.webServerRuntime,
})
}
}

0 comments on commit e8b21b6

Please sign in to comment.