Skip to content

Commit

Permalink
Add type => module to module asset files
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Dec 22, 2023
1 parent 6d8f9c6 commit 6c194f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
4 changes: 4 additions & 0 deletions packages/dependency-extraction-webpack-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ class DependencyExtractionWebpackPlugin {
version: contentHash,
};

if ( this.useModules ) {
assetData.type = 'module';
}

if ( combineAssets ) {
combinedAssetsData[ chunkJSFile ] = assetData;
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DependencyExtractionWebpackPlugin modules Webpack \`combine-assets\` should produce expected output: Asset file 'assets.php' should match snapshot 1`] = `
"<?php return array('fileA.mjs' => array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '8652d2bf4a1ea1969a6e'), 'fileB.mjs' => array('dependencies' => array(array('id' => '@wordpress/token-list', 'type' => 'dynamic')), 'version' => '17d7d5b2c152592ff3a0'));
"<?php return array('fileA.mjs' => array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '8652d2bf4a1ea1969a6e', 'type' => 'module'), 'fileB.mjs' => array('dependencies' => array(array('id' => '@wordpress/token-list', 'type' => 'dynamic')), 'version' => '17d7d5b2c152592ff3a0', 'type' => 'module'));
"
`;

Expand All @@ -21,7 +21,7 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`combine-assets\` sh
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`dynamic-import\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '092c2bce8c247ee11100');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '092c2bce8c247ee11100', 'type' => 'module');
"
`;

Expand All @@ -36,7 +36,7 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`dynamic-import\` sh
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`function-output-filename\` should produce expected output: Asset file 'chunk--main--main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '5207bcd3fdd29de25f37');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '5207bcd3fdd29de25f37', 'type' => 'module');
"
`;

Expand All @@ -51,7 +51,7 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`function-output-fil
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`has-extension-suffix\` should produce expected output: Asset file 'index.min.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '9b89a3e6236b26559c4e');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '9b89a3e6236b26559c4e', 'type' => 'module');
"
`;

Expand All @@ -66,21 +66,21 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`has-extension-suffi
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`no-default\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(), 'version' => '34504aa793c63cd3d73a');
"<?php return array('dependencies' => array(), 'version' => '34504aa793c63cd3d73a', 'type' => 'module');
"
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`no-default\` should produce expected output: External modules should match snapshot 1`] = `[]`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`no-deps\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(), 'version' => 'e37fbd452a6188261d74');
"<?php return array('dependencies' => array(), 'version' => 'e37fbd452a6188261d74', 'type' => 'module');
"
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`no-deps\` should produce expected output: External modules should match snapshot 1`] = `[]`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`option-function-output-filename\` should produce expected output: Asset file 'chunk--main--main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '5207bcd3fdd29de25f37');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '5207bcd3fdd29de25f37', 'type' => 'module');
"
`;

Expand All @@ -95,7 +95,7 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`option-function-out
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`option-output-filename\` should produce expected output: Asset file 'main-foo.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '5207bcd3fdd29de25f37');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '5207bcd3fdd29de25f37', 'type' => 'module');
"
`;

Expand All @@ -109,12 +109,12 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`option-output-filen
]
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`output-format-json\` should produce expected output: Asset file 'main.asset.json' should match snapshot 1`] = `"{"dependencies":[],"version":"34504aa793c63cd3d73a"}"`;
exports[`DependencyExtractionWebpackPlugin modules Webpack \`output-format-json\` should produce expected output: Asset file 'main.asset.json' should match snapshot 1`] = `"{"dependencies":[],"version":"34504aa793c63cd3d73a","type":"module"}"`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`output-format-json\` should produce expected output: External modules should match snapshot 1`] = `[]`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`overrides\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic'), array('id' => '@wordpress/url', 'type' => 'dynamic'), array('id' => 'rxjs', 'type' => 'dynamic'), array('id' => 'rxjs/operators', 'type' => 'dynamic')), 'version' => '90f2e6327f4e8fb0264f');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic'), array('id' => '@wordpress/url', 'type' => 'dynamic'), array('id' => 'rxjs', 'type' => 'dynamic'), array('id' => 'rxjs/operators', 'type' => 'dynamic')), 'version' => '90f2e6327f4e8fb0264f', 'type' => 'module');
"
`;

Expand Down Expand Up @@ -144,17 +144,17 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`overrides\` should
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'a.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => 'aeadada5bf49ae3b9dc2');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => 'aeadada5bf49ae3b9dc2', 'type' => 'module');
"
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'b.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '10df52cc859c01faa91d');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '10df52cc859c01faa91d', 'type' => 'module');
"
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'runtime.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(), 'version' => 'd081f44e5ece6763f943');
"<?php return array('dependencies' => array(), 'version' => 'd081f44e5ece6763f943', 'type' => 'module');
"
`;

Expand All @@ -169,7 +169,7 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`runtime-chunk-singl
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`style-imports\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '2d597a618aeebe7ab323');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '2d597a618aeebe7ab323', 'type' => 'module');
"
`;

Expand All @@ -184,7 +184,7 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`style-imports\` sho
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '5207bcd3fdd29de25f37');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '5207bcd3fdd29de25f37', 'type' => 'module');
"
`;

Expand All @@ -198,7 +198,7 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress\` should
]
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress-interactivity\` should produce expected output: Asset file 'main.asset.json' should match snapshot 1`] = `"{"dependencies":[{"id":"@wordpress/interactivity","type":"dynamic"}],"version":"d91ead3ebbc3853c802b"}"`;
exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress-interactivity\` should produce expected output: Asset file 'main.asset.json' should match snapshot 1`] = `"{"dependencies":[{"id":"@wordpress/interactivity","type":"dynamic"}],"version":"d91ead3ebbc3853c802b","type":"module"}"`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress-interactivity\` should produce expected output: External modules should match snapshot 1`] = `
[
Expand All @@ -211,7 +211,7 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress-interacti
`;

exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress-require\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '7a320492a2396d955292');
"<?php return array('dependencies' => array(array('id' => '@wordpress/blob', 'type' => 'dynamic')), 'version' => '7a320492a2396d955292', 'type' => 'module');
"
`;

Expand Down

0 comments on commit 6c194f0

Please sign in to comment.