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

fix: handle empty build #357

Merged
merged 2 commits into from
Jan 23, 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
10 changes: 9 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@
? new SourceMapSource(
result.code,
asset.name,
result.map as any,

Check warning on line 107 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Test

Unexpected any. Specify a different type
sourceAsString,
map as any,

Check warning on line 109 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Test

Unexpected any. Specify a different type
true,
)
: new RawSource(result.code)
) as any,

Check warning on line 113 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Test

Unexpected any. Specify a different type
{
...asset.info,
minimized,
Expand Down Expand Up @@ -138,7 +138,7 @@
this.options = options;
}

apply(compiler: Compiler) {

Check warning on line 141 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Test

Method 'apply' has a complexity of 14. Maximum allowed is 10
const {
implementation,
...options
Expand Down Expand Up @@ -201,6 +201,12 @@
* Webpack 5: https://github.com/webpack/webpack/blob/v5.75.0/lib/SourceMapDevToolModuleOptionsPlugin.js#LL27
*/
let useSourceMap = false;

/**
* `finishModules` hook is called after all the `buildModule` hooks are called,
* which is where the `useSourceMap` flag is set
* https://webpack.js.org/api/compilation-hooks/#finishmodules
*/
compilation.hooks.finishModules.tap(
pluginName,
(modules) => {
Expand All @@ -209,7 +215,9 @@
? modules[0]
: (modules as Set<webpack5.Module>).values().next().value as webpack5.Module
);
useSourceMap = firstModule.useSourceMap;
if (firstModule) {
useSourceMap = firstModule.useSourceMap;
}
},
);

Expand Down
12 changes: 12 additions & 0 deletions tests/specs/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,5 +738,17 @@ export default testSuite(({ describe }, webpack: typeof webpack4 | typeof webpac
expect(exportedFunction('hello world')).toBe('hello world');
assertMinified(exportedFunction.toString());
});

// https://github.com/privatenumber/esbuild-loader/issues/356
test('can handle empty modules set', async () => {
await expect(build(
fixtures.blank,
(config) => {
config.entry = 'not-there.js';
configureEsbuildMinifyPlugin(config);
},
webpack,
)).resolves.toBeTruthy();
});
});
});
Loading