-
Notifications
You must be signed in to change notification settings - Fork 4
Add verbosity to Webpack. #24
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
Closed
perf2711
wants to merge
2
commits into
feature/sourcemap-uploading-webpack
from
feature/webpack-verbosity
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| webpackBuild/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ import crypto from 'crypto'; | |
| import path from 'path'; | ||
| import { Compiler, WebpackPluginInstance } from 'webpack'; | ||
| import { BacktraceWebpackSourceGenerator } from './BacktraceWebpackSourceGenerator'; | ||
| import { statsPrinter } from './helpers/statsPrinter'; | ||
| import { AssetStats } from './models/AssetStats'; | ||
| import { BacktracePluginOptions } from './models/BacktracePluginOptions'; | ||
|
|
||
| export class BacktracePluginV4 implements WebpackPluginInstance { | ||
|
|
@@ -20,62 +22,113 @@ export class BacktracePluginV4 implements WebpackPluginInstance { | |
| } | ||
|
|
||
| public apply(compiler: Compiler) { | ||
| const assetDebugIds = new Map<string, string>(); | ||
| const assetStats = new Map<string, AssetStats>(); | ||
|
|
||
| compiler.hooks.emit.tap(BacktracePluginV4.name, (compilation) => { | ||
| const logger = compilation.getLogger(BacktracePluginV4.name); | ||
| for (const key in compilation.assets) { | ||
| let source = compilation.assets[key]; | ||
|
|
||
| let debugId; | ||
| if (key.match(/.(c|m)?jsx?$/)) { | ||
| debugId = crypto.randomUUID(); | ||
| assetDebugIds.set(key, debugId); | ||
| if (key.match(/\.(c|m)?jsx?$/)) { | ||
| const debugId = crypto.randomUUID(); | ||
| const stats: AssetStats = { debugId }; | ||
| assetStats.set(key, stats); | ||
| logger.log(`[${key}] generated debug ID ${debugId}`); | ||
|
|
||
| source = this._sourceGenerator.addDebugIdToSource(source as never, debugId) as typeof source; | ||
| source = this._sourceGenerator.addDebugIdCommentToSource(source as never, debugId) as typeof source; | ||
| logger.time(`[${key}] inject source snippet`); | ||
| try { | ||
| source = this._sourceGenerator.addDebugIdToSource(source as never, debugId) as typeof source; | ||
| logger.timeEnd(`[${key}] inject source snippet`); | ||
| stats.sourceSnippet = true; | ||
| } catch (err) { | ||
| stats.sourceSnippet = err instanceof Error ? err : new Error('Unknown error.'); | ||
| } | ||
|
|
||
| logger.time(`[${key}] inject sourcemap key`); | ||
| try { | ||
| source = this._sourceGenerator.addDebugIdCommentToSource( | ||
| source as never, | ||
| debugId, | ||
| ) as typeof source; | ||
| logger.timeEnd(`[${key}] inject sourcemap key`); | ||
| stats.sourceComment = true; | ||
| } catch (err) { | ||
| stats.sourceComment = err instanceof Error ? err : new Error('Unknown error.'); | ||
| } | ||
| } else if (key.match(/\.(c|m)?jsx?\.map$/)) { | ||
| // The .map replacement should account for most of the use cases | ||
| const sourceKey = key.replace(/.map$/, ''); | ||
| debugId = assetDebugIds.get(sourceKey); | ||
| if (!debugId) { | ||
| const stats = assetStats.get(sourceKey); | ||
| if (!stats) { | ||
| continue; | ||
| } | ||
|
|
||
| source = this._sourceGenerator.addDebugIdToRawSourceMap(source as never, debugId) as never; | ||
| logger.time(`[${key}] append sourcemap key`); | ||
| try { | ||
| source = this._sourceGenerator.addDebugIdToRawSourceMap( | ||
| source as never, | ||
| stats.debugId, | ||
| ) as never; | ||
| logger.timeEnd(`[${key}] append sourcemap key`); | ||
| stats.sourceMapAppend = true; | ||
| } catch (err) { | ||
| stats.sourceMapAppend = err instanceof Error ? err : new Error('Unknown error.'); | ||
|
Collaborator
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. the time command from line 66 will not end. Should we add a log error about that? |
||
| } | ||
| } | ||
|
|
||
| compilation.assets[key] = source; | ||
| } | ||
| }); | ||
|
|
||
| const uploader = this._sourceMapUploader; | ||
| if (uploader) { | ||
| compiler.hooks.afterEmit.tapPromise(BacktracePluginV4.name, async (compilation) => { | ||
| const outputPath = compilation.outputOptions.path; | ||
| if (!outputPath) { | ||
| throw new Error('Output path is required to upload sourcemaps.'); | ||
| compiler.hooks.afterEmit.tapPromise(BacktracePluginV4.name, async (compilation) => { | ||
| const logger = compilation.getLogger(BacktracePluginV4.name); | ||
|
|
||
| const outputPath = compilation.outputOptions.path; | ||
| if (!outputPath) { | ||
| throw new Error('Output path is required to upload sourcemaps.'); | ||
| } | ||
|
|
||
| for (const key in compilation.assets) { | ||
| if (!key.match(/\.(c|m)?jsx?\.map$/)) { | ||
| continue; | ||
| } | ||
|
|
||
| for (const key in compilation.assets) { | ||
| if (!key.match(/\.(c|m)?jsx?\.map$/)) { | ||
| continue; | ||
| } | ||
| const sourceKey = key.replace(/.map$/, ''); | ||
| const stats = assetStats.get(sourceKey); | ||
| if (!stats) { | ||
| continue; | ||
| } | ||
|
|
||
| const sourceKey = key.replace(/.map$/, ''); | ||
| const debugId = assetDebugIds.get(sourceKey); | ||
| if (!debugId) { | ||
| continue; | ||
| } | ||
| const sourceMapAsset = compilation.getAsset(key); | ||
| if (!sourceMapAsset) { | ||
| stats.sourceMapUpload = false; | ||
| continue; | ||
| } | ||
|
|
||
| const sourceMapAsset = compilation.getAsset(key); | ||
| if (!sourceMapAsset) { | ||
| continue; | ||
| } | ||
| if (!this._sourceMapUploader) { | ||
| stats.sourceMapUpload = false; | ||
| continue; | ||
| } | ||
|
|
||
| const sourceMapPath = path.join(outputPath, sourceMapAsset.name); | ||
| await uploader.upload(sourceMapPath, debugId); | ||
| const sourceMapPath = path.join(outputPath, sourceMapAsset.name); | ||
|
|
||
| logger.time(`[${key}] upload sourcemap`); | ||
| try { | ||
| const result = await this._sourceMapUploader.upload(sourceMapPath, stats.debugId); | ||
| logger.timeEnd(`[${key}] upload sourcemap`); | ||
| stats.sourceMapUpload = result; | ||
| } catch (err) { | ||
| stats.sourceMapAppend = err instanceof Error ? err : new Error('Unknown error.'); | ||
| } | ||
| }); | ||
| } | ||
| logger.timeEnd(`[${key}] upload sourcemap`); | ||
| } | ||
| }); | ||
|
|
||
| compiler.hooks.afterEmit.tap(BacktracePluginV4.name, (compilation) => { | ||
| const printer = statsPrinter(compilation.getLogger(BacktracePluginV4.name)); | ||
| for (const [key, stats] of assetStats) { | ||
| printer(key, stats); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the time command from line 47 will never end. Should we add an error log about that? RIght now the user needs to check the source map comment however no one will do that in practice