Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure validator is included in vendored AMP validator #70482

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/next/src/export/routes/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions packages/next/src/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
15 changes: 15 additions & 0 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2,254 changes: 0 additions & 2,254 deletions test/e2e/async-modules/amp-validator-wasm.js

This file was deleted.

8 changes: 1 addition & 7 deletions test/e2e/async-modules/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
module.exports = {
experimental: {
amp: {
validator: require.resolve('./amp-validator-wasm.js'),
},
},
}
module.exports = {}
5 changes: 0 additions & 5 deletions test/integration/amp-export-validation/next.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
module.exports = {
output: 'export',
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
// exportPathMap
}
1 change: 0 additions & 1 deletion test/integration/amphtml-custom-optimizer/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
optimizer: {
ampRuntimeVersion: '001515617716922',
rtv: true,
Expand Down
8 changes: 1 addition & 7 deletions test/integration/amphtml-custom-validator/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
module.exports = {
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = {}
8 changes: 1 addition & 7 deletions test/integration/amphtml-fragment-style/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
module.exports = {
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = {}
8 changes: 1 addition & 7 deletions test/integration/amphtml-ssg/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
module.exports = {
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = {}
5 changes: 0 additions & 5 deletions test/integration/amphtml/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,5 @@ module.exports = {
amp: {
canonicalBase: 'http://localhost:1234',
},
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
// edit here
}
5 changes: 0 additions & 5 deletions test/integration/auto-export-query-error/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,4 @@ module.exports = {
'/ssr': { page: '/ssr', query: { another: 'one' } },
}
},
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
module.exports = {
experimental: {
amp: {
validator: require.resolve('../../../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = {}
5 changes: 0 additions & 5 deletions test/integration/export-default-map/next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
module.exports = {
output: 'export',
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
5 changes: 0 additions & 5 deletions test/integration/i18n-support-base-path/next.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module.exports = {
basePath: '/docs',
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
i18n: {
// localeDetection: false,
locales: [
Expand Down
5 changes: 0 additions & 5 deletions test/integration/i18n-support/next.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
module.exports = {
// basePath: '/docs',
// trailingSlash: true,
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
i18n: {
// localeDetection: false,
locales: [
Expand Down
8 changes: 1 addition & 7 deletions test/integration/page-config/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
module.exports = {
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}
module.exports = {}
1 change: 0 additions & 1 deletion test/lib/amp-readme.md

This file was deleted.

2,254 changes: 0 additions & 2,254 deletions test/lib/amp-validator-wasm.js

This file was deleted.

2,254 changes: 0 additions & 2,254 deletions test/production/pages-dir/production/fixture/amp-validator-wasm.js

This file was deleted.

5 changes: 0 additions & 5 deletions test/production/pages-dir/production/fixture/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading