Skip to content

Commit

Permalink
fix empty string imports and change order because the transpiler is w…
Browse files Browse the repository at this point in the history
…eird about removing comments
  • Loading branch information
ForsakenHarmony committed Oct 13, 2023
1 parent 41f75ba commit 6713a53
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/next/src/build/load-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ export async function loadEntrypoint(
`// OPTIONAL_IMPORT:(\\* as )?(${Object.keys(imports).join('|')})`,
'g'
),
(_, asNamespace, key) => {
(_, asNamespace = '', key) => {
if (!(key in imports)) {
throw new Error(`Invariant: Unexpected optional import ${key}`)
}

importsAdded.add(key)

if (imports[key] != null) {
if (imports[key]) {
return `import ${asNamespace}${key} from ${JSON.stringify(
imports[key]
)}`
Expand Down
14 changes: 6 additions & 8 deletions packages/next/src/build/templates/edge-ssr-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,32 @@ import type { BuildManifest } from '../../server/get-page-files'
import type { RequestData } from '../../server/web/types'
import type { NextConfigComplete } from '../../server/config-shared'

declare const incrementalCacheHandler: any
// OPTIONAL_IMPORT:incrementalCacheHandler

const Document: DocumentType = null!
const appMod = null
const errorMod = null
const error500Mod = null

// injected by the loader afterwards.
declare const page: string
declare const sriEnabled: boolean
declare const isServerComponent: boolean
declare const dev: boolean
declare const serverActionsBodySizeLimit: any
declare const nextConfig: NextConfigComplete
// INJECT:page
// INJECT:sriEnabled
// INJECT:isServerComponent
// INJECT:dev
// INJECT:serverActionsBodySizeLimit
// INJECT:config

declare const incrementalCacheHandler: any
// OPTIONAL_IMPORT:incrementalCacheHandler
// INJECT:nextConfig

const maybeJSONParse = (str?: string) => (str ? JSON.parse(str) : undefined)

const buildManifest: BuildManifest = self.__BUILD_MANIFEST as any
const prerenderManifest = maybeJSONParse(self.__PRERENDER_MANIFEST)
const reactLoadableManifest = maybeJSONParse(self.__REACT_LOADABLE_MANIFEST)
const rscManifest = self.__RSC_MANIFEST?.[page]
const rscManifest = self.__RSC_MANIFEST?.['VAR_PAGE']
const rscServerManifest = maybeJSONParse(self.__RSC_SERVER_MANIFEST)
const subresourceIntegrityManifest = sriEnabled
? maybeJSONParse(self.__SUBRESOURCE_INTEGRITY_MANIFEST)
Expand All @@ -48,7 +46,7 @@ const nextFontManifest = maybeJSONParse(self.__NEXT_FONT_MANIFEST)
const render = getRender({
pagesType: 'app',
dev,
page,
page: 'VAR_PAGE',
appMod,
pageMod,
errorMod,
Expand Down
11 changes: 4 additions & 7 deletions packages/next/src/build/templates/edge-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import * as userlandPage from 'VAR_USERLAND'
import * as userlandErrorPage from 'VAR_MODULE_GLOBAL_ERROR'

declare const userland500Page: any
declare const incrementalCacheHandler: any
// OPTIONAL_IMPORT:* as userland500Page
// OPTIONAL_IMPORT:incrementalCacheHandler

// TODO: re-enable this once we've refactored to use implicit matches
// const renderToHTML = undefined
Expand All @@ -23,18 +25,16 @@ import type { NextConfigComplete } from '../../server/config-shared'

// injected by the loader afterwards.
declare const pagesType: 'app' | 'pages' | 'root'
declare const page: string
declare const sriEnabled: boolean
declare const dev: boolean
declare const nextConfig: NextConfigComplete
declare const pageRouteModuleOptions: any
declare const errorRouteModuleOptions: any
declare const user500RouteModuleOptions: any
// INJECT:pagesType
// INJECT:page
// INJECT:sriEnabled
// INJECT:dev
// INJECT:config
// INJECT:nextConfig
// INJECT:pageRouteModuleOptions
// INJECT:errorRouteModuleOptions
// INJECT:user500RouteModuleOptions
Expand Down Expand Up @@ -78,9 +78,6 @@ const error500Mod = userland500Page
}
: null

declare const incrementalCacheHandler: any
// OPTIONAL_IMPORT:incrementalCacheHandler

const maybeJSONParse = (str?: string) => (str ? JSON.parse(str) : undefined)

const buildManifest: BuildManifest = self.__BUILD_MANIFEST as any
Expand All @@ -94,7 +91,7 @@ const nextFontManifest = maybeJSONParse(self.__NEXT_FONT_MANIFEST)
const render = getRender({
pagesType,
dev,
page,
page: 'VAR_PAGE',
appMod,
pageMod,
errorMod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ const edgeSSRLoader: webpack.LoaderDefinitionFunction<EdgeSSRLoaderQuery> =
return await loadEntrypoint(
'edge-ssr-app',
{
VAR_BUILD_ID: buildId,
VAR_USERLAND: pageModPath,
VAR_PAGE: page,
VAR_BUILD_ID: buildId,
},
{
page,
sriEnabled: JSON.stringify(sriEnabled),
nextConfig: stringifiedConfig,
isServerComponent: JSON.stringify(isServerComponent),
Expand All @@ -162,15 +162,15 @@ const edgeSSRLoader: webpack.LoaderDefinitionFunction<EdgeSSRLoaderQuery> =
return await loadEntrypoint(
'edge-ssr',
{
VAR_USERLAND: pageModPath,
VAR_PAGE: page,
VAR_BUILD_ID: buildId,
VAR_MODULE_DOCUMENT: documentPath,
VAR_MODULE_APP: appPath,
VAR_MODULE_GLOBAL_ERROR: errorPath,
VAR_USERLAND: pageModPath,
},
{
pagesType: JSON.stringify(pagesType),
page,
sriEnabled: JSON.stringify(sriEnabled),
nextConfig: stringifiedConfig,
dev: JSON.stringify(dev),
Expand Down

0 comments on commit 6713a53

Please sign in to comment.