diff --git a/types/next/constants.d.ts b/types/next/constants.d.ts new file mode 100644 index 0000000000..d2dc74dad0 --- /dev/null +++ b/types/next/constants.d.ts @@ -0,0 +1,23 @@ +export const PHASE_EXPORT: string; +export const PHASE_PRODUCTION_BUILD: string; +export const PHASE_PRODUCTION_SERVER: string; +export const PHASE_DEVELOPMENT_SERVER: string; +export const PAGES_MANIFEST: string; +export const BUILD_MANIFEST: string; +export const REACT_LOADABLE_MANIFEST: string; +export const SERVER_DIRECTORY: string; +export const CONFIG_FILE: string; +export const BUILD_ID_FILE: string; +export const BLOCKED_PAGES: string[]; + +export const CLIENT_STATIC_FILES_PATH: string; +export const CLIENT_STATIC_FILES_RUNTIME: string; +export const CLIENT_STATIC_FILES_RUNTIME_PATH: string; +/** static/runtime/main.js */ +export const CLIENT_STATIC_FILES_RUNTIME_MAIN: string; +/** static/runtime/webpack.js */ +export const CLIENT_STATIC_FILES_RUNTIME_WEBPACK: string; +/** matches static//pages/.js */ +export const IS_BUNDLED_PAGE_REGEX: RegExp; +/** matches static//pages/:page*.js */ +export const ROUTE_NAME_REGEX: RegExp; diff --git a/types/next/test/next-constants-tests.ts b/types/next/test/next-constants-tests.ts new file mode 100644 index 0000000000..64413ea97c --- /dev/null +++ b/types/next/test/next-constants-tests.ts @@ -0,0 +1,30 @@ +import { + PHASE_DEVELOPMENT_SERVER, + IS_BUNDLED_PAGE_REGEX +} from "next/constants"; + +const isIndexPage = IS_BUNDLED_PAGE_REGEX.test( + "static/CjW0mFnyG80HdP4eSUiy7/pages/index.js" +); + +// Example taken from: https://github.com/cyrilwanner/next-compose-plugins/blob/a25b313899638912cc9defc0be072f4fe4a1e855/README.md +const config = (nextConfig: any = {}) => { + return { + ...nextConfig, + + // define in which phases this plugin should get applied. + // you can also use multiple phases or negate them. + // however, users can still overwrite them in their configuration if they really want to. + phases: [PHASE_DEVELOPMENT_SERVER], + + webpack(config: any, options: any) { + // do something here which only gets applied during development server phase + + if (typeof nextConfig.webpack === "function") { + return nextConfig.webpack(config, options); + } + + return config; + } + }; +}; diff --git a/types/next/tsconfig.json b/types/next/tsconfig.json index 125953fcd6..9981affbd3 100644 --- a/types/next/tsconfig.json +++ b/types/next/tsconfig.json @@ -20,6 +20,7 @@ }, "files": [ "index.d.ts", + "constants.d.ts", "app.d.ts", "document.d.ts", "dynamic.d.ts", @@ -29,6 +30,7 @@ "router.d.ts", "config.d.ts", "test/next-tests.ts", + "test/next-constants-tests.ts", "test/next-app-tests.tsx", "test/next-error-tests.tsx", "test/next-head-tests.tsx",