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(
hybrid: components.pageConfig?.amp === 'hybrid',
}
if (!ampValidatorPath) {
ampValidatorPath = require.resolve(
'next/dist/compiled/amphtml-validator/validator_wasm.js'
)
}
const inAmpMode = isInAmpMode(ampState)
const hybridAmp = ampState.hybrid
......
......@@ -176,9 +176,13 @@ export default class DevServer extends Server {
this.nextConfig.experimental?.amp?.skipValidation ?? false
this.renderOpts.ampValidator = (html: string, pathname: string) => {
const validatorPath =
this.nextConfig.experimental &&
this.nextConfig.experimental.amp &&
this.nextConfig.experimental.amp.validator
(this.nextConfig.experimental &&
this.nextConfig.experimental.amp &&
this.nextConfig.experimental.amp.validator) ||
require.resolve(
'next/dist/compiled/amphtml-validator/validator_wasm.js'
)
const AmpHtmlValidator =
require('next/dist/compiled/amphtml-validator') as typeof import('next/dist/compiled/amphtml-validator')
return AmpHtmlValidator.getInstance(validatorPath).then((validator) => {
......
......@@ -2260,6 +2260,21 @@ export async function precompile(task, opts) {
['browser_polyfills', 'copy_ncced', 'copy_styled_jsx_assets'],
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
......
This diff is collapsed.
module.exports = {
experimental: {
amp: {
validator: require.resolve('./amp-validator-wasm.js'),
},
},
}
module.exports = {}
module.exports = {
output: 'export',
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
// exportPathMap
}
module.exports = {
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
optimizer: {
ampRuntimeVersion: '001515617716922',
rtv: true,
......
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'),
},
},
}
module.exports = {}
......@@ -6,10 +6,5 @@ module.exports = {
amp: {
canonicalBase: 'http://localhost:1234',
},
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
// edit here
}
......@@ -7,9 +7,4 @@ module.exports = {
'/ssr': { page: '/ssr', query: { another: 'one' } },
}
},
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = {
experimental: {
amp: {
validator: require.resolve('../../../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = {}
module.exports = {
output: 'export',
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = {
basePath: '/docs',
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
i18n: {
// localeDetection: false,
locales: [
......
module.exports = {
// basePath: '/docs',
// trailingSlash: true,
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
i18n: {
// localeDetection: false,
locales: [
......
module.exports = {
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = {}
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 @@
setInterval(() => {}, 250)
module.exports = {
experimental: {
amp: {
validator: require.resolve('./amp-validator-wasm.js'),
},
},
onDemandEntries: {
// Make sure entries are not getting disposed.
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