Unverified Commit 98e5ee74 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure validator is included in vendored AMP validator (#70482)

This aims to provide more stability so we aren't hitting the network to
grab the validator more than we need to and instead leverage the one
from build instead which should also reduce some test flakiness we've
been seeing.
parent afb13c24
...@@ -56,6 +56,12 @@ export async function exportPagesPage( ...@@ -56,6 +56,12 @@ export async function exportPagesPage(
hybrid: components.pageConfig?.amp === 'hybrid', hybrid: components.pageConfig?.amp === 'hybrid',
} }
if (!ampValidatorPath) {
ampValidatorPath = require.resolve(
'next/dist/compiled/amphtml-validator/validator_wasm.js'
)
}
const inAmpMode = isInAmpMode(ampState) const inAmpMode = isInAmpMode(ampState)
const hybridAmp = ampState.hybrid const hybridAmp = ampState.hybrid
......
...@@ -176,9 +176,13 @@ export default class DevServer extends Server { ...@@ -176,9 +176,13 @@ export default class DevServer extends Server {
this.nextConfig.experimental?.amp?.skipValidation ?? false this.nextConfig.experimental?.amp?.skipValidation ?? false
this.renderOpts.ampValidator = (html: string, pathname: string) => { this.renderOpts.ampValidator = (html: string, pathname: string) => {
const validatorPath = const validatorPath =
this.nextConfig.experimental && (this.nextConfig.experimental &&
this.nextConfig.experimental.amp && this.nextConfig.experimental.amp &&
this.nextConfig.experimental.amp.validator this.nextConfig.experimental.amp.validator) ||
require.resolve(
'next/dist/compiled/amphtml-validator/validator_wasm.js'
)
const AmpHtmlValidator = const AmpHtmlValidator =
require('next/dist/compiled/amphtml-validator') as typeof import('next/dist/compiled/amphtml-validator') require('next/dist/compiled/amphtml-validator') as typeof import('next/dist/compiled/amphtml-validator')
return AmpHtmlValidator.getInstance(validatorPath).then((validator) => { return AmpHtmlValidator.getInstance(validatorPath).then((validator) => {
......
...@@ -2260,6 +2260,21 @@ export async function precompile(task, opts) { ...@@ -2260,6 +2260,21 @@ export async function precompile(task, opts) {
['browser_polyfills', 'copy_ncced', 'copy_styled_jsx_assets'], ['browser_polyfills', 'copy_ncced', 'copy_styled_jsx_assets'],
opts opts
) )
const validatorRes = await fetch(
'https://cdn.ampproject.org/v0/validator_wasm.js'
)
if (!validatorRes.ok) {
throw new Error(
`Failed to get the AMP validator, status: ${validatorRes.status}`
)
}
await fs.writeFile(
join(__dirname, 'dist/compiled/amphtml-validator/validator_wasm.js'),
require('buffer').Buffer.from(await validatorRes.arrayBuffer())
)
} }
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
......
This diff is collapsed.
module.exports = { module.exports = {}
experimental: {
amp: {
validator: require.resolve('./amp-validator-wasm.js'),
},
},
}
module.exports = { module.exports = {
output: 'export', output: 'export',
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
// exportPathMap // exportPathMap
} }
module.exports = { module.exports = {
experimental: { experimental: {
amp: { amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
optimizer: { optimizer: {
ampRuntimeVersion: '001515617716922', ampRuntimeVersion: '001515617716922',
rtv: true, rtv: true,
......
module.exports = { module.exports = {}
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = { module.exports = {}
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = { module.exports = {}
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
...@@ -6,10 +6,5 @@ module.exports = { ...@@ -6,10 +6,5 @@ module.exports = {
amp: { amp: {
canonicalBase: 'http://localhost:1234', canonicalBase: 'http://localhost:1234',
}, },
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
// edit here // edit here
} }
...@@ -7,9 +7,4 @@ module.exports = { ...@@ -7,9 +7,4 @@ module.exports = {
'/ssr': { page: '/ssr', query: { another: 'one' } }, '/ssr': { page: '/ssr', query: { another: 'one' } },
} }
}, },
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
} }
module.exports = { module.exports = {}
experimental: {
amp: {
validator: require.resolve('../../../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = { module.exports = {
output: 'export', output: 'export',
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
} }
module.exports = { module.exports = {
basePath: '/docs', basePath: '/docs',
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
i18n: { i18n: {
// localeDetection: false, // localeDetection: false,
locales: [ locales: [
......
module.exports = { module.exports = {
// basePath: '/docs', // basePath: '/docs',
// trailingSlash: true, // trailingSlash: true,
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
i18n: { i18n: {
// localeDetection: false, // localeDetection: false,
locales: [ locales: [
......
module.exports = { module.exports = {}
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
The `amp-validator-wasm.js` is used instead of the CDN as it isn't super reliable and causes test flakiness.
This diff is collapsed.
...@@ -2,11 +2,6 @@ ...@@ -2,11 +2,6 @@
setInterval(() => {}, 250) setInterval(() => {}, 250)
module.exports = { module.exports = {
experimental: {
amp: {
validator: require.resolve('./amp-validator-wasm.js'),
},
},
onDemandEntries: { onDemandEntries: {
// Make sure entries are not getting disposed. // Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60, maxInactiveAge: 1000 * 60 * 60,
......
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