-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Script Modules API: Backport - Add import map polyfill #5947
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
Changes from all commits
feee589
63f7021
4156afc
d7bca4b
ff4ce0d
c0381d2
90be4f9
ba6ea74
e046610
f648520
45987c3
82121a0
fcb8f74
dc78385
5c0cc0e
d4b232f
21a3bbe
cad52d7
35d249e
f76f80f
ea3ab1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1559,16 +1559,18 @@ module.exports = function(grunt) { | |
| } ); | ||
|
|
||
| /** | ||
| * Build assertions for the lack of source maps in JavaScript files. | ||
| * Compiled JavaScript files may link to sourcemaps. In some cases, | ||
| * the source map may not be available, which can cause 404 errors when | ||
| * browsers try to download the sourcemap from the referenced URLs. | ||
| * Ensure that sourcemap links are not included in JavaScript files. | ||
| * | ||
| * @ticket 24994 | ||
| * @ticket 46218 | ||
| * @ticket 60348 | ||
| */ | ||
| grunt.registerTask( 'verify:source-maps', function() { | ||
| const ignoredFiles = [ | ||
| 'build/wp-includes/js/dist/components.js', | ||
| 'build/wp-includes/js/dist/block-editor.js', | ||
| 'build/wp-includes/js/dist/block-editor.min.js' | ||
| ]; | ||
| const files = buildFiles.reduce( ( acc, path ) => { | ||
| // Skip excluded paths and any path that isn't a file. | ||
|
|
@@ -1591,10 +1593,10 @@ module.exports = function(grunt) { | |
| encoding: 'utf8', | ||
| } ); | ||
| // `data:` URLs are allowed: | ||
| const match = contents.match( /sourceMappingURL=((?!data:).)/ ); | ||
| const doesNotHaveSourceMap = ! /^\/\/# sourceMappingURL=((?!data:).)/m.test(contents); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sharing notes on this change that I co-authored with @c4rl0sbr4v0. First, a minor change. We use Second, and more important. The expression was not specific enough and was matching JavaScript source files that were, themselves, looking for sourcemap comments. In this PR is was matching this line from es-module-shims: const sourceMapURLCommentPrefix = '\n//# sourceMappingURL=';We change to better match a source map comment by anchoring the expression to the start of the line and matching the comment opening |
||
|
|
||
| assert( | ||
| match === null, | ||
| doesNotHaveSourceMap, | ||
| `The ${ file } file must not contain a sourceMappingURL.` | ||
| ); | ||
| } ); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,11 +210,26 @@ public function print_script_module_preloads() { | |
| /** | ||
| * Prints the import map using a script tag with a type="importmap" attribute. | ||
| * | ||
| * @global WP_Scripts $wp_scripts The WP_Scripts object for printing the polyfill. | ||
| * @since 6.5.0 | ||
| */ | ||
| public function print_import_map() { | ||
| $import_map = $this->get_import_map(); | ||
| if ( ! empty( $import_map['imports'] ) ) { | ||
| global $wp_scripts; | ||
| if ( isset( $wp_scripts ) ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would be the case when I see some |
||
| wp_print_inline_script_tag( | ||
| wp_get_script_polyfill( | ||
| $wp_scripts, | ||
| array( | ||
| 'HTMLScriptElement.supports && HTMLScriptElement.supports("importmap")' => 'wp-polyfill-importmap', | ||
| ) | ||
| ), | ||
| array( | ||
| 'id' => 'wp-load-polyfill-importmap', | ||
| ) | ||
| ); | ||
| } | ||
| wp_print_inline_script_tag( | ||
| wp_json_encode( $import_map, JSON_HEX_TAG | JSON_HEX_AMP ), | ||
| array( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.