Describe the bug
dependency-extraction-webpack-plugin doesn't validate import names. If an invalid name is used, the parent script will silently fail to load, which can be confusing and time-consuming to fix.
Expected behavior
The watch script should throw an error to the console, to alert the dev that they used an invalid dependency.
To reproduce
deps.json file. e.g.,wp_enqueue_script(
'foo',
plugins_url( 'dist/foo.js', __FILE__ ),
json_decode( file_get_contents( __DIR__ . '/dist/foo.deps.json' ) ),
);
import statement. e.g.,import { Button } from '@wordpress/component'; // missing an `s` at the end
It seems like this should be handled on the linter side instead. Well, at least this is what we introduced in Gutenberg lately with āimport/no-extraneous-dependenciesā rule in https://github.com/WordPress/gutenberg/pull/16969. Itās handled per package and only for non-test files in Gutenberg but it might be a good idea to set it in recommended config of ESLint and override in the project as Gutenberg is a special case here. @nerrad, @ntwb, and @swissspidy what do you think?
Ya I agree, linter. A couple IDE's I've used will also warn on invalid imports.
~My attempt to enable ESLint rule in https://github.com/WordPress/gutenberg/pull/20905 didnāt work as expected š~
It looks like the bug was fixed and it has landed in Gutenberg. Next step is to move it to the ESLing plugin.
Most helpful comment
It seems like this should be handled on the linter side instead. Well, at least this is what we introduced in Gutenberg lately with āimport/no-extraneous-dependenciesā rule in https://github.com/WordPress/gutenberg/pull/16969. Itās handled per package and only for non-test files in Gutenberg but it might be a good idea to set it in recommended config of ESLint and override in the project as Gutenberg is a special case here. @nerrad, @ntwb, and @swissspidy what do you think?