From 3ec7bd40f34adbc8be66f951edfa6d91d5794c01 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Thu, 1 Apr 2021 14:26:12 +0100 Subject: [PATCH] Make ES modules option consistent (#1188) * Make ES modules option consistent * Fix config in spec test * Change tests to test both ESM and non-ESM --- packages/optimizer/README.md | 16 ---------------- .../optimizer/lib/transformers/RewriteAmpUrls.js | 3 +++ .../experimental/RewriteAmpUrls/config.json | 2 +- .../valid/RewriteAmpUrls/adds_esm/input.html | 5 +++++ .../RewriteAmpUrls/adds_lts/expected_output.html | 8 +++----- .../adds_preloads/expected_output.html | 8 +++----- .../valid/RewriteAmpUrls/config.json | 3 +++ 7 files changed, 18 insertions(+), 27 deletions(-) create mode 100644 packages/optimizer/spec/transformers/valid/RewriteAmpUrls/config.json diff --git a/packages/optimizer/README.md b/packages/optimizer/README.md index 707adbdc9..535c8be61 100644 --- a/packages/optimizer/README.md +++ b/packages/optimizer/README.md @@ -157,22 +157,6 @@ Specifies the AMP format of the input file. Defaults to `AMP`. - default: `AMP` - used by: [AutoExtensionImport](lib/transformers/AutoExtensionImporter.js), [AddMandatoryTags](lib/transformers/AddMandatoryTags.js) -#### `experimentEsm` - -Enable [JavaScript Module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) support for AMP runtime and components. AMP Optimizer will generate module/nonmodule script imports for AMP runtime and components: - -``` - - -``` - -**Warning: this will result in invalid AMP pages.** - -- name: `experimentEsm` -- valid options: `[true|false]` -- default: `false` -- used by: [RewriteAmpUrls](lib/transformers/RewriteAmpUrls.js) - #### `imageBasePath` Specifies a base path used to resolve an image during build, diff --git a/packages/optimizer/lib/transformers/RewriteAmpUrls.js b/packages/optimizer/lib/transformers/RewriteAmpUrls.js index 630d1a386..88e823766 100644 --- a/packages/optimizer/lib/transformers/RewriteAmpUrls.js +++ b/packages/optimizer/lib/transformers/RewriteAmpUrls.js @@ -47,6 +47,9 @@ const {calculateHost} = require('../RuntimeHostHelper'); * option is ineffective with the lts flag, but will simply be ignored * rather than throwing an error. * + * * `esmModulesEnabled`: Enables the smaller ESM module version of AMP runtime + * and components. + * * All parameters are optional. If no option is provided, runtime URLs won't be * re-written. You can combine `ampRuntimeVersion` and `ampUrlPrefix` to * rewrite AMP runtime URLs to versioned URLs on a different origin. diff --git a/packages/optimizer/spec/transformers/experimental/RewriteAmpUrls/config.json b/packages/optimizer/spec/transformers/experimental/RewriteAmpUrls/config.json index 3627b268e..568fd0058 100644 --- a/packages/optimizer/spec/transformers/experimental/RewriteAmpUrls/config.json +++ b/packages/optimizer/spec/transformers/experimental/RewriteAmpUrls/config.json @@ -1,3 +1,3 @@ { - "experimentEsm": true + "esmModulesEnabled": true } diff --git a/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_esm/input.html b/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_esm/input.html index 00a0d3b6f..913ccd0fe 100644 --- a/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_esm/input.html +++ b/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_esm/input.html @@ -1,3 +1,8 @@ + diff --git a/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_lts/expected_output.html b/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_lts/expected_output.html index 5653dffbb..aa570f4cf 100644 --- a/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_lts/expected_output.html +++ b/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_lts/expected_output.html @@ -1,14 +1,12 @@ - - - - + + - + diff --git a/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_preloads/expected_output.html b/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_preloads/expected_output.html index bd3743523..4a160fd16 100644 --- a/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_preloads/expected_output.html +++ b/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/adds_preloads/expected_output.html @@ -1,14 +1,12 @@ - - - - + + - + diff --git a/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/config.json b/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/config.json new file mode 100644 index 000000000..a60a55e45 --- /dev/null +++ b/packages/optimizer/spec/transformers/valid/RewriteAmpUrls/config.json @@ -0,0 +1,3 @@ +{ + "esmModulesEnabled": false +}