Unverified Commit cbc52d1b authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Update loader-utils (#30743)

Co-authored-by: 's avatarjj@jjsweb.site <jj@jjsweb.site>
Co-authored-by: 's avatarSteven <steven@ceriously.com>
Co-authored-by: 's avatarJiachi Liu <inbox@huozhi.im>
parent d5d1bc00
import { getOptions } from 'next/dist/compiled/loader-utils'
import { Span } from '../../../trace' import { Span } from '../../../trace'
import transform from './transform' import transform from './transform'
import { NextJsLoaderContext } from './types' import { NextJsLoaderContext } from './types'
...@@ -13,7 +12,8 @@ async function nextBabelLoader( ...@@ -13,7 +12,8 @@ async function nextBabelLoader(
const target = this.target const target = this.target
const loaderOptions = parentTrace const loaderOptions = parentTrace
.traceChild('get-options') .traceChild('get-options')
.traceFn(() => getOptions(this)) // @ts-ignore TODO: remove ignore once webpack 5 types are used
.traceFn(() => this.getOptions())
const loaderSpanInner = parentTrace.traceChild('next-babel-turbo-transform') const loaderSpanInner = parentTrace.traceChild('next-babel-turbo-transform')
const { code: transformedSource, map: outputSourceMap } = const { code: transformedSource, map: outputSourceMap } =
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
MIT License http://www.opensource.org/licenses/mit-license.php MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra Author Tobias Koppers @sokra
*/ */
import { getOptions, stringifyRequest } from 'next/dist/compiled/loader-utils'
import postcss from 'postcss' import postcss from 'postcss'
import CssSyntaxError from './CssSyntaxError' import CssSyntaxError from './CssSyntaxError'
...@@ -23,9 +22,10 @@ import { ...@@ -23,9 +22,10 @@ import {
normalizeSourceMap, normalizeSourceMap,
sort, sort,
} from './utils' } from './utils'
import { stringifyRequest } from '../../../stringify-request'
export default async function loader(content, map, meta) { export default async function loader(content, map, meta) {
const rawOptions = getOptions(this) const rawOptions = this.getOptions()
const plugins = [] const plugins = []
const callback = this.async() const callback = this.async()
......
import chalk from 'chalk' import chalk from 'chalk'
import loaderUtils from 'next/dist/compiled/loader-utils'
import path from 'path' import path from 'path'
import { webpack } from 'next/dist/compiled/webpack/webpack' import { webpack } from 'next/dist/compiled/webpack/webpack'
const ErrorLoader: webpack.loader.Loader = function () { const ErrorLoader: webpack.loader.Loader = function () {
const options = loaderUtils.getOptions(this) || {} // @ts-ignore exists
const options = this.getOptions() || {}
const { reason = 'An unknown error has occurred' } = options const { reason = 'An unknown error has occurred' } = options
......
import loaderUtils from 'next/dist/compiled/loader-utils' import { stringifyRequest } from '../stringify-request'
export type ClientPagesLoaderOptions = { export type ClientPagesLoaderOptions = {
absolutePagePath: string absolutePagePath: string
...@@ -12,16 +12,12 @@ function nextClientPagesLoader(this: any) { ...@@ -12,16 +12,12 @@ function nextClientPagesLoader(this: any) {
) )
return pagesLoaderSpan.traceFn(() => { return pagesLoaderSpan.traceFn(() => {
const { absolutePagePath, page } = loaderUtils.getOptions( const { absolutePagePath, page } =
this this.getOptions() as ClientPagesLoaderOptions
) as ClientPagesLoaderOptions
pagesLoaderSpan.setAttribute('absolutePagePath', absolutePagePath) pagesLoaderSpan.setAttribute('absolutePagePath', absolutePagePath)
const stringifiedPagePath = loaderUtils.stringifyRequest( const stringifiedPagePath = stringifyRequest(this, absolutePagePath)
this,
absolutePagePath
)
const stringifiedPage = JSON.stringify(page) const stringifiedPage = JSON.stringify(page)
return ` return `
......
import loaderUtils from 'next/dist/compiled/loader-utils'
import * as acorn from 'acorn' import * as acorn from 'acorn'
import { getRawPageExtensions } from '../../utils' import { getRawPageExtensions } from '../../utils'
...@@ -81,7 +80,7 @@ export default async function transformSource( ...@@ -81,7 +80,7 @@ export default async function transformSource(
source: string source: string
): Promise<string> { ): Promise<string> {
const { client: isClientCompilation, pageExtensions: pageExtensionsJson } = const { client: isClientCompilation, pageExtensions: pageExtensionsJson } =
loaderUtils.getOptions(this) this.getOptions()
const { resourcePath } = this const { resourcePath } = this
const pageExtensions = JSON.parse(pageExtensionsJson) const pageExtensions = JSON.parse(pageExtensionsJson)
......
...@@ -8,8 +8,7 @@ const VALID_BLUR_EXT = ['jpeg', 'png', 'webp', 'avif'] // should match next/clie ...@@ -8,8 +8,7 @@ const VALID_BLUR_EXT = ['jpeg', 'png', 'webp', 'avif'] // should match next/clie
function nextImageLoader(content) { function nextImageLoader(content) {
const imageLoaderSpan = this.currentTraceSpan.traceChild('next-image-loader') const imageLoaderSpan = this.currentTraceSpan.traceChild('next-image-loader')
return imageLoaderSpan.traceAsyncFn(async () => { return imageLoaderSpan.traceAsyncFn(async () => {
const { isServer, isDev, assetPrefix, basePath } = const { isServer, isDev, assetPrefix, basePath } = this.getOptions()
loaderUtils.getOptions(this)
const context = this.rootContext const context = this.rootContext
const opts = { context, content } const opts = { context, content }
const interpolatedName = loaderUtils.interpolateName( const interpolatedName = loaderUtils.interpolateName(
......
import loaderUtils from 'next/dist/compiled/loader-utils' import { stringifyRequest } from '../stringify-request'
export type MiddlewareLoaderOptions = { export type MiddlewareLoaderOptions = {
absolutePagePath: string absolutePagePath: string
...@@ -6,12 +6,8 @@ export type MiddlewareLoaderOptions = { ...@@ -6,12 +6,8 @@ export type MiddlewareLoaderOptions = {
} }
export default function middlewareLoader(this: any) { export default function middlewareLoader(this: any) {
const { absolutePagePath, page }: MiddlewareLoaderOptions = const { absolutePagePath, page }: MiddlewareLoaderOptions = this.getOptions()
loaderUtils.getOptions(this) const stringifiedPagePath = stringifyRequest(this, absolutePagePath)
const stringifiedPagePath = loaderUtils.stringifyRequest(
this,
absolutePagePath
)
return ` return `
import { adapter } from 'next/dist/server/web/adapter' import { adapter } from 'next/dist/server/web/adapter'
......
import loaderUtils from 'next/dist/compiled/loader-utils'
import { getStringifiedAbsolutePath } from './utils' import { getStringifiedAbsolutePath } from './utils'
import { stringifyRequest } from '../../stringify-request'
const fallbackDocumentPage = ` const fallbackDocumentPage = `
import { Html, Head, Main, NextScript } from 'next/document' import { Html, Head, Main, NextScript } from 'next/document'
...@@ -31,14 +31,13 @@ export default async function middlewareRSCLoader(this: any) { ...@@ -31,14 +31,13 @@ export default async function middlewareRSCLoader(this: any) {
const { const {
absolutePagePath, absolutePagePath,
basePath, basePath,
isServerComponent, isServerComponent: isServerComponentQuery,
assetPrefix, assetPrefix,
buildId, buildId,
} = loaderUtils.getOptions(this) } = this.getOptions()
const stringifiedAbsolutePagePath = loaderUtils.stringifyRequest(
this, const isServerComponent = isServerComponentQuery === 'true'
absolutePagePath const stringifiedAbsolutePagePath = stringifyRequest(this, absolutePagePath)
)
const stringifiedAbsoluteDocumentPath = getStringifiedAbsolutePath( const stringifiedAbsoluteDocumentPath = getStringifiedAbsolutePath(
this, this,
'./pages/_document' './pages/_document'
...@@ -48,9 +47,11 @@ export default async function middlewareRSCLoader(this: any) { ...@@ -48,9 +47,11 @@ export default async function middlewareRSCLoader(this: any) {
'./pages/_app' './pages/_app'
) )
const hasProvidedAppPage = hasModule(JSON.parse(stringifiedAbsoluteAppPath)) const hasProvidedAppPage = hasModule(
this.utils.absolutify(this.rootContext, './pages/_app')
)
const hasProvidedDocumentPage = hasModule( const hasProvidedDocumentPage = hasModule(
JSON.parse(stringifiedAbsoluteDocumentPath) this.utils.absolutify(this.rootContext, './pages/_document')
) )
let appDefinition = `const App = require(${ let appDefinition = `const App = require(${
......
import loaderUtils from 'next/dist/compiled/loader-utils' import { stringifyRequest } from '../../stringify-request'
export function getStringifiedAbsolutePath(target: any, path: string) { export function getStringifiedAbsolutePath(target: any, path: string) {
return loaderUtils.stringifyRequest( return stringifyRequest(
target, target,
target.utils.absolutify(target.rootContext, path) target.utils.absolutify(target.rootContext, path)
) )
......
import devalue from 'next/dist/compiled/devalue' import devalue from 'next/dist/compiled/devalue'
import escapeRegexp from 'next/dist/compiled/escape-string-regexp' import escapeRegexp from 'next/dist/compiled/escape-string-regexp'
import loaderUtils from 'next/dist/compiled/loader-utils'
import { join } from 'path' import { join } from 'path'
import { parse } from 'querystring' import { parse } from 'querystring'
import { webpack } from 'next/dist/compiled/webpack/webpack' import { webpack } from 'next/dist/compiled/webpack/webpack'
...@@ -12,6 +11,7 @@ import { ...@@ -12,6 +11,7 @@ import {
ROUTES_MANIFEST, ROUTES_MANIFEST,
REACT_LOADABLE_MANIFEST, REACT_LOADABLE_MANIFEST,
} from '../../../../shared/lib/constants' } from '../../../../shared/lib/constants'
import { stringifyRequest } from '../../stringify-request'
export type ServerlessLoaderQuery = { export type ServerlessLoaderQuery = {
page: string page: string
...@@ -113,10 +113,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () { ...@@ -113,10 +113,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
} }
const apiHandler = getApiHandler({ const apiHandler = getApiHandler({
pageModule: require(${loaderUtils.stringifyRequest( pageModule: require(${stringifyRequest(this, absolutePagePath)}),
this,
absolutePagePath
)}),
rewrites: combinedRewrites, rewrites: combinedRewrites,
i18n: ${i18n || 'undefined'}, i18n: ${i18n || 'undefined'},
page: "${page}", page: "${page}",
...@@ -141,21 +138,15 @@ const nextServerlessLoader: webpack.loader.Loader = function () { ...@@ -141,21 +138,15 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
} }
import { getPageHandler } from 'next/dist/build/webpack/loaders/next-serverless-loader/page-handler' import { getPageHandler } from 'next/dist/build/webpack/loaders/next-serverless-loader/page-handler'
const documentModule = require(${loaderUtils.stringifyRequest( const documentModule = require(${stringifyRequest(
this, this,
absoluteDocumentPath absoluteDocumentPath
)}) )})
const appMod = require(${loaderUtils.stringifyRequest( const appMod = require(${stringifyRequest(this, absoluteAppPath)})
this,
absoluteAppPath
)})
let App = appMod.default || appMod.then && appMod.then(mod => mod.default); let App = appMod.default || appMod.then && appMod.then(mod => mod.default);
const compMod = require(${loaderUtils.stringifyRequest( const compMod = require(${stringifyRequest(this, absolutePagePath)})
this,
absolutePagePath
)})
const Component = compMod.default || compMod.then && compMod.then(mod => mod.default) const Component = compMod.default || compMod.then && compMod.then(mod => mod.default)
export default Component export default Component
...@@ -188,13 +179,10 @@ const nextServerlessLoader: webpack.loader.Loader = function () { ...@@ -188,13 +179,10 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
pageConfig: config, pageConfig: config,
appModule: App, appModule: App,
documentModule: documentModule, documentModule: documentModule,
errorModule: require(${loaderUtils.stringifyRequest( errorModule: require(${stringifyRequest(this, absoluteErrorPath)}),
this,
absoluteErrorPath
)}),
notFoundModule: ${ notFoundModule: ${
absolute404Path absolute404Path
? `require(${loaderUtils.stringifyRequest(this, absolute404Path)})` ? `require(${stringifyRequest(this, absolute404Path)})`
: undefined : undefined
}, },
pageGetStaticProps: getStaticProps, pageGetStaticProps: getStaticProps,
......
import loaderUtils from 'next/dist/compiled/loader-utils'
import path from 'path' import path from 'path'
import isEqualLocals from './runtime/isEqualLocals' import isEqualLocals from './runtime/isEqualLocals'
import { stringifyRequest } from '../../stringify-request'
const loaderApi = () => {} const loaderApi = () => {}
...@@ -8,7 +8,7 @@ loaderApi.pitch = function loader(request) { ...@@ -8,7 +8,7 @@ loaderApi.pitch = function loader(request) {
const loaderSpan = this.currentTraceSpan.traceChild('next-style-loader') const loaderSpan = this.currentTraceSpan.traceChild('next-style-loader')
return loaderSpan.traceFn(() => { return loaderSpan.traceFn(() => {
const options = loaderUtils.getOptions(this) const options = this.getOptions()
const insert = const insert =
typeof options.insert === 'undefined' typeof options.insert === 'undefined'
...@@ -28,15 +28,12 @@ loaderApi.pitch = function loader(request) { ...@@ -28,15 +28,12 @@ loaderApi.pitch = function loader(request) {
? ` ? `
if (module.hot) { if (module.hot) {
module.hot.accept( module.hot.accept(
${loaderUtils.stringifyRequest(this, `!!${request}`)}, ${stringifyRequest(this, `!!${request}`)},
function() { function() {
${ ${
esModule esModule
? 'update(content);' ? 'update(content);'
: `content = require(${loaderUtils.stringifyRequest( : `content = require(${stringifyRequest(this, `!!${request}`)});
this,
`!!${request}`
)});
content = content.__esModule ? content.default : content; content = content.__esModule ? content.default : content;
...@@ -53,22 +50,16 @@ if (module.hot) { ...@@ -53,22 +50,16 @@ if (module.hot) {
return `${ return `${
esModule esModule
? `import api from ${loaderUtils.stringifyRequest( ? `import api from ${stringifyRequest(
this, this,
`!${path.join(__dirname, 'runtime/injectStylesIntoLinkTag.js')}` `!${path.join(__dirname, 'runtime/injectStylesIntoLinkTag.js')}`
)}; )};
import content from ${loaderUtils.stringifyRequest( import content from ${stringifyRequest(this, `!!${request}`)};`
this, : `var api = require(${stringifyRequest(
`!!${request}`
)};`
: `var api = require(${loaderUtils.stringifyRequest(
this, this,
`!${path.join(__dirname, 'runtime/injectStylesIntoLinkTag.js')}` `!${path.join(__dirname, 'runtime/injectStylesIntoLinkTag.js')}`
)}); )});
var content = require(${loaderUtils.stringifyRequest( var content = require(${stringifyRequest(this, `!!${request}`)});
this,
`!!${request}`
)});
content = content.__esModule ? content.default : content;` content = content.__esModule ? content.default : content;`
} }
...@@ -96,7 +87,7 @@ if (module.hot) { ...@@ -96,7 +87,7 @@ if (module.hot) {
var oldLocals = content.locals; var oldLocals = content.locals;
module.hot.accept( module.hot.accept(
${loaderUtils.stringifyRequest(this, `!!${request}`)}, ${stringifyRequest(this, `!!${request}`)},
function () { function () {
${ ${
esModule esModule
...@@ -111,10 +102,7 @@ if (module.hot) { ...@@ -111,10 +102,7 @@ if (module.hot) {
if (update && refs > 0) { if (update && refs > 0) {
update(content); update(content);
}` }`
: `content = require(${loaderUtils.stringifyRequest( : `content = require(${stringifyRequest(this, `!!${request}`)});
this,
`!!${request}`
)});
content = content.__esModule ? content.default : content; content = content.__esModule ? content.default : content;
...@@ -144,28 +132,22 @@ if (module.hot) { ...@@ -144,28 +132,22 @@ if (module.hot) {
return `${ return `${
esModule esModule
? `import api from ${loaderUtils.stringifyRequest( ? `import api from ${stringifyRequest(
this, this,
`!${path.join( `!${path.join(
__dirname, __dirname,
'runtime/injectStylesIntoStyleTag.js' 'runtime/injectStylesIntoStyleTag.js'
)}` )}`
)}; )};
import content from ${loaderUtils.stringifyRequest( import content from ${stringifyRequest(this, `!!${request}`)};`
this, : `var api = require(${stringifyRequest(
`!!${request}`
)};`
: `var api = require(${loaderUtils.stringifyRequest(
this, this,
`!${path.join( `!${path.join(
__dirname, __dirname,
'runtime/injectStylesIntoStyleTag.js' 'runtime/injectStylesIntoStyleTag.js'
)}` )}`
)}); )});
var content = require(${loaderUtils.stringifyRequest( var content = require(${stringifyRequest(this, `!!${request}`)});
this,
`!!${request}`
)});
content = content.__esModule ? content.default : content; content = content.__esModule ? content.default : content;
...@@ -216,7 +198,7 @@ if (module.hot) { ...@@ -216,7 +198,7 @@ if (module.hot) {
var oldLocals = content.locals; var oldLocals = content.locals;
module.hot.accept( module.hot.accept(
${loaderUtils.stringifyRequest(this, `!!${request}`)}, ${stringifyRequest(this, `!!${request}`)},
function () { function () {
${ ${
esModule esModule
...@@ -229,10 +211,7 @@ if (module.hot) { ...@@ -229,10 +211,7 @@ if (module.hot) {
oldLocals = content.locals; oldLocals = content.locals;
update(content);` update(content);`
: `content = require(${loaderUtils.stringifyRequest( : `content = require(${stringifyRequest(this, `!!${request}`)});
this,
`!!${request}`
)});
content = content.__esModule ? content.default : content; content = content.__esModule ? content.default : content;
...@@ -262,28 +241,22 @@ if (module.hot) { ...@@ -262,28 +241,22 @@ if (module.hot) {
return `${ return `${
esModule esModule
? `import api from ${loaderUtils.stringifyRequest( ? `import api from ${stringifyRequest(
this, this,
`!${path.join( `!${path.join(
__dirname, __dirname,
'runtime/injectStylesIntoStyleTag.js' 'runtime/injectStylesIntoStyleTag.js'
)}` )}`
)}; )};
import content from ${loaderUtils.stringifyRequest( import content from ${stringifyRequest(this, `!!${request}`)};`
this, : `var api = require(${stringifyRequest(
`!!${request}`
)};`
: `var api = require(${loaderUtils.stringifyRequest(
this, this,
`!${path.join( `!${path.join(
__dirname, __dirname,
'runtime/injectStylesIntoStyleTag.js' 'runtime/injectStylesIntoStyleTag.js'
)}` )}`
)}); )});
var content = require(${loaderUtils.stringifyRequest( var content = require(${stringifyRequest(this, `!!${request}`)});
this,
`!!${request}`
)});
content = content.__esModule ? content.default : content; content = content.__esModule ? content.default : content;
......
...@@ -26,7 +26,6 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ...@@ -26,7 +26,6 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
import { getOptions } from 'next/dist/compiled/loader-utils'
import { transform } from '../../swc' import { transform } from '../../swc'
const nextDistPath = const nextDistPath =
...@@ -117,7 +116,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) { ...@@ -117,7 +116,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
// Make the loader async // Make the loader async
const filename = this.resourcePath const filename = this.resourcePath
let loaderOptions = getOptions(this) || {} let loaderOptions = this.getOptions() || {}
const { isServer, pagesDir, hasReactRefresh } = loaderOptions const { isServer, pagesDir, hasReactRefresh } = loaderOptions
const isPageFile = filename.startsWith(pagesDir) const isPageFile = filename.startsWith(pagesDir)
......
import Warning from './Warning' import Warning from './Warning'
import SyntaxError from './Error' import SyntaxError from './Error'
import { normalizeSourceMap, normalizeSourceMapAfterPostcss } from './utils' import { normalizeSourceMap, normalizeSourceMapAfterPostcss } from './utils'
import { getOptions } from 'next/dist/compiled/loader-utils'
/** /**
* **PostCSS Loader** * **PostCSS Loader**
...@@ -22,7 +21,7 @@ export default async function loader(content, sourceMap, meta) { ...@@ -22,7 +21,7 @@ export default async function loader(content, sourceMap, meta) {
loaderSpan loaderSpan
.traceAsyncFn(async () => { .traceAsyncFn(async () => {
const options = getOptions(this) const options = this.getOptions()
const file = this.resourcePath const file = this.resourcePath
const useSourceMap = const useSourceMap =
......
export function stringifyRequest(loaderContext: any, request: any) {
return JSON.stringify(
loaderContext.utils.contextify(
loaderContext.context || loaderContext.rootContext,
request
)
)
}
/* eslint-disable import/no-extraneous-dependencies */
const loaderUtils = require('loader-utils')
loaderUtils.getOptions = function (context) {
return context.getOptions()
}
module.exports = loaderUtils
This diff is collapsed.
This diff is collapsed.
{"name":"loader-utils","main":"index.js","author":"Tobias Koppers @sokra","license":"MIT"} {"name":"loader-utils","main":"loader-utils.js","author":"Tobias Koppers @sokra","license":"MIT"}
...@@ -224,7 +224,7 @@ ...@@ -224,7 +224,7 @@
"is-wsl": "2.2.0", "is-wsl": "2.2.0",
"json5": "2.2.0", "json5": "2.2.0",
"jsonwebtoken": "8.5.1", "jsonwebtoken": "8.5.1",
"loader-utils": "2.0.0", "loader-utils": "3.1.0",
"lodash.curry": "4.1.1", "lodash.curry": "4.1.1",
"lru-cache": "5.1.1", "lru-cache": "5.1.1",
"micromatch": "4.0.4", "micromatch": "4.0.4",
......
...@@ -359,7 +359,7 @@ export async function ncc_jsonwebtoken(task, opts) { ...@@ -359,7 +359,7 @@ export async function ncc_jsonwebtoken(task, opts) {
externals['loader-utils'] = 'next/dist/compiled/loader-utils' externals['loader-utils'] = 'next/dist/compiled/loader-utils'
export async function ncc_loader_utils(task, opts) { export async function ncc_loader_utils(task, opts) {
await task await task
.source(opts.src || relative(__dirname, require.resolve('loader-utils'))) .source(opts.src || 'bundles/loader-utils.js')
.ncc({ packageName: 'loader-utils', externals }) .ncc({ packageName: 'loader-utils', externals })
.target('compiled/loader-utils') .target('compiled/loader-utils')
} }
......
...@@ -72,7 +72,7 @@ const runTests = (isDev = false) => { ...@@ -72,7 +72,7 @@ const runTests = (isDev = false) => {
expect(html).toContain( expect(html).toContain(
`style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;filter:blur(20px);background-size:cover;background-image:url(${ `style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;filter:blur(20px);background-size:cover;background-image:url(${
isDev isDev
? '&quot;/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fmedia%2Ftest.480a01e5.jpg&amp;w=8&amp;q=70&quot;' ? '&quot;/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fmedia%2Ftest.fab2915d.jpg&amp;w=8&amp;q=70&quot;'
: '&quot;data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAYACAMBIgACEQEDEQH/xAAnAAEBAAAAAAAAAAAAAAAAAAAABwEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAAmgP/xAAcEAACAQUBAAAAAAAAAAAAAAASFBMAAQMFERX/2gAIAQEAAT8AZ1HjrKZX55JysIc4Ff/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z&quot;' : '&quot;data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAYACAMBIgACEQEDEQH/xAAnAAEBAAAAAAAAAAAAAAAAAAAABwEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAAmgP/xAAcEAACAQUBAAAAAAAAAAAAAAASFBMAAQMFERX/2gAIAQEAAT8AZ1HjrKZX55JysIc4Ff/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z&quot;'
});background-position:0% 0%"` });background-position:0% 0%"`
) )
...@@ -81,7 +81,7 @@ const runTests = (isDev = false) => { ...@@ -81,7 +81,7 @@ const runTests = (isDev = false) => {
expect(html).toContain( expect(html).toContain(
`style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;filter:blur(20px);background-size:cover;background-image:url(${ `style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;filter:blur(20px);background-size:cover;background-image:url(${
isDev isDev
? '&quot;/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fmedia%2Ftest.eba16dd4.png&amp;w=8&amp;q=70&quot;' ? '&quot;/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fmedia%2Ftest.3f1a293b.png&amp;w=8&amp;q=70&quot;'
: '&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAICAAAAAAZhBqgAAAAJklEQVR42mNgkmBkYGXgZGBoY2Co/lPAcOf/dYaCzHwGEBAVEwUAZZIG0TbWicQAAAAASUVORK5CYII=&quot;' : '&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAICAAAAAAZhBqgAAAAJklEQVR42mNgkmBkYGXgZGBoY2Co/lPAcOf/dYaCzHwGEBAVEwUAZZIG0TbWicQAAAAASUVORK5CYII=&quot;'
});background-position:0% 0%"` });background-position:0% 0%"`
) )
......
...@@ -694,7 +694,7 @@ function runTests({ ...@@ -694,7 +694,7 @@ function runTests({
if (!isDev) { if (!isDev) {
const filename = 'test' const filename = 'test'
const query = { const query = {
url: `/_next/static/media/${filename}.480a01e5.jpg`, url: `/_next/static/media/${filename}.fab2915d.jpg`,
w, w,
q: 100, q: 100,
} }
......
{
"name": "react-dom",
"version": "18.0.0-alpha-c76e4dbbc-20210722"
}
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
import { writeFile } from 'fs-extra' import { writeFile } from 'fs-extra'
import getPort from 'get-port' import getPort from 'get-port'
import http from 'http' import http from 'http'
import https from 'https'
import server from 'next/dist/server/next' import server from 'next/dist/server/next'
import _pkg from 'next/package.json' import _pkg from 'next/package.json'
import fetch from 'node-fetch' import fetch from 'node-fetch'
...@@ -102,7 +103,19 @@ export function fetchViaHTTP(appPort, pathname, query, opts) { ...@@ -102,7 +103,19 @@ export function fetchViaHTTP(appPort, pathname, query, opts) {
const url = `${pathname}${ const url = `${pathname}${
typeof query === 'string' ? query : query ? `?${qs.stringify(query)}` : '' typeof query === 'string' ? query : query ? `?${qs.stringify(query)}` : ''
}` }`
return fetch(getFullUrl(appPort, url), opts) return fetch(getFullUrl(appPort, url), {
// in node.js v17 fetch favors IPv6 but Next.js is
// listening on IPv4 by default so force IPv4 DNS resolving
agent: (parsedUrl) => {
if (parsedUrl.protocol === 'https:') {
return new https.Agent({ family: 4 })
}
if (parsedUrl.protocol === 'http:') {
return new http.Agent({ family: 4 })
}
},
...opts,
})
} }
export function findPort() { export function findPort() {
......
...@@ -10,6 +10,18 @@ const babel = async (code: string, queryOpts = {} as any) => { ...@@ -10,6 +10,18 @@ const babel = async (code: string, queryOpts = {} as any) => {
const { isServer = false, resourcePath = `index.js` } = queryOpts const { isServer = false, resourcePath = `index.js` } = queryOpts
let isAsync = false let isAsync = false
const options = {
// loader opts
cwd: dir,
isServer,
distDir: path.resolve(dir, '.next'),
pagesDir:
'pagesDir' in queryOpts ? queryOpts.pagesDir : path.resolve(dir, 'pages'),
cache: false,
development: true,
hasReactRefresh: !isServer,
}
return new Promise<string>((resolve, reject) => { return new Promise<string>((resolve, reject) => {
function callback(err, content) { function callback(err, content) {
if (err) { if (err) {
...@@ -27,18 +39,10 @@ const babel = async (code: string, queryOpts = {} as any) => { ...@@ -27,18 +39,10 @@ const babel = async (code: string, queryOpts = {} as any) => {
}, },
callback, callback,
emitWarning() {}, emitWarning() {},
query: { query: options,
// loader opts // @ts-ignore exists
cwd: dir, getOptions: function () {
isServer, return options
distDir: path.resolve(dir, '.next'),
pagesDir:
'pagesDir' in queryOpts
? queryOpts.pagesDir
: path.resolve(dir, 'pages'),
cache: false,
development: true,
hasReactRefresh: !isServer,
}, },
currentTraceSpan: new Span({ name: 'test' }), currentTraceSpan: new Span({ name: 'test' }),
})(code, null) })(code, null)
......
...@@ -19,6 +19,19 @@ const babel = async (code: string, queryOpts = {} as any) => { ...@@ -19,6 +19,19 @@ const babel = async (code: string, queryOpts = {} as any) => {
} }
} }
const options = {
// loader opts
cwd: dir,
isServer,
distDir: path.resolve(dir, '.next'),
pagesDir:
'pagesDir' in queryOpts
? queryOpts.pagesDir
: path.resolve(dir, 'pages'),
cache: false,
hasReactRefresh: false,
}
const res = loader.bind({ const res = loader.bind({
resourcePath, resourcePath,
async() { async() {
...@@ -27,17 +40,10 @@ const babel = async (code: string, queryOpts = {} as any) => { ...@@ -27,17 +40,10 @@ const babel = async (code: string, queryOpts = {} as any) => {
}, },
callback, callback,
emitWarning() {}, emitWarning() {},
query: { query: options,
// loader opts // @ts-ignore exists
cwd: dir, getOptions: function () {
isServer, return options
distDir: path.resolve(dir, '.next'),
pagesDir:
'pagesDir' in queryOpts
? queryOpts.pagesDir
: path.resolve(dir, 'pages'),
cache: false,
hasReactRefresh: false,
}, },
currentTraceSpan: new Span({ name: 'test' }), currentTraceSpan: new Span({ name: 'test' }),
})(code, null) })(code, null)
......
...@@ -6319,6 +6319,11 @@ big.js@^5.2.2: ...@@ -6319,6 +6319,11 @@ big.js@^5.2.2:
version "5.2.2" version "5.2.2"
resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328" resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
big.js@^6.1.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/big.js/-/big.js-6.1.1.tgz#63b35b19dc9775c94991ee5db7694880655d5537"
integrity sha512-1vObw81a8ylZO5ePrtMay0n018TcftpTA5HFKDaSuiUDBo8biRBtjIobw60OpwuvrGk+FsxKamqN4cnmj/eXdg==
binary-extensions@^1.0.0: binary-extensions@^1.0.0:
version "1.13.1" version "1.13.1"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65" resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65"
...@@ -12729,13 +12734,12 @@ loader-utils@1.2.3: ...@@ -12729,13 +12734,12 @@ loader-utils@1.2.3:
emojis-list "^2.0.0" emojis-list "^2.0.0"
json5 "^1.0.1" json5 "^1.0.1"
loader-utils@2.0.0, loader-utils@^2.0.0: loader-utils@3.1.0:
version "2.0.0" version "3.1.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.0.tgz#e4cace5b816d425a166b5f097e10cd12b36064b0" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-3.1.0.tgz#5d6583148713e4c022b3dac9daac0efd9b6bca42"
integrity sha512-7YF6k8Q9xXFHkQhVaX76PyJVAIcPAKNk+7zJs5w2k/wVqkb8uq8O6MIWuY50BkuinY2WD5Ugmpu0oVipDexFkQ==
dependencies: dependencies:
big.js "^5.2.2" big.js "^6.1.1"
emojis-list "^3.0.0"
json5 "^2.1.2"
loader-utils@^1.1.0, loader-utils@^1.2.3: loader-utils@^1.1.0, loader-utils@^1.2.3:
version "1.4.0" version "1.4.0"
...@@ -12745,6 +12749,14 @@ loader-utils@^1.1.0, loader-utils@^1.2.3: ...@@ -12745,6 +12749,14 @@ loader-utils@^1.1.0, loader-utils@^1.2.3:
emojis-list "^3.0.0" emojis-list "^3.0.0"
json5 "^1.0.1" json5 "^1.0.1"
loader-utils@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.0.tgz#e4cace5b816d425a166b5f097e10cd12b36064b0"
dependencies:
big.js "^5.2.2"
emojis-list "^3.0.0"
json5 "^2.1.2"
locate-path@^2.0.0: locate-path@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e" resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment