Skip to content
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
6 changes: 0 additions & 6 deletions tools/webpack-plugin/jest.config.js

This file was deleted.

5 changes: 1 addition & 4 deletions tools/webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
"clean": "tsc -b ./tsconfig.build.json --clean && rimraf \"lib\"",
"format": "prettier --write '**/*.ts'",
"lint": "eslint . --ext .ts",
"watch": "tsc -b ./tsconfig.packages.json -w",
"test": "npm run test:webpackv5 && npm run test:webpackv4",
"test:webpackv4": "NODE_ENV=test jest --config ./webpack4.jest.config.js",
"test:webpackv5": "NODE_ENV=test jest",
"watch": "tsc -b ./tsconfig.build.json -w",
"test:e2e": "npm run test:e2e:webpackv5 && npm run test:e2e:webpackv4",
"test:e2e:webpackv4": "NODE_ENV=test jest --config ./webpack4.e2e.jest.config.js",
"test:e2e:webpackv5": "NODE_ENV=test jest --config ./e2e.jest.config.js"
Expand Down
97 changes: 79 additions & 18 deletions tools/webpack-plugin/src/BacktracePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,80 @@
import webpack from 'webpack';
import { BacktracePluginV4 } from './BacktracePluginV4';
import { BacktracePluginV5 } from './BacktracePluginV5';

let BacktracePlugin: typeof BacktracePluginV4 | typeof BacktracePluginV5;

const version = process.env.WEBPACK_VERSION ?? webpack.version[0];
switch (version) {
case '4':
BacktracePlugin = BacktracePluginV4;
break;
case '5':
BacktracePlugin = BacktracePluginV5;
break;
default:
throw new Error(`Webpack version ${version} is not supported.`);
}
import { DebugIdGenerator, SourceMapUploader, SourceProcessor } from '@backtrace/sourcemap-tools';
import path from 'path';
import webpack, { WebpackPluginInstance } from 'webpack';
import { BacktracePluginOptions } from './models/BacktracePluginOptions';

export class BacktracePlugin implements WebpackPluginInstance {
private readonly _sourceProcessor: SourceProcessor;
private readonly _sourceMapUploader?: SourceMapUploader;

constructor(public readonly options?: BacktracePluginOptions) {
this._sourceProcessor = new SourceProcessor(new DebugIdGenerator());
this._sourceMapUploader = options?.uploadUrl
? new SourceMapUploader(options.uploadUrl, options.uploadOptions)
: undefined;
}

public apply(compiler: webpack.Compiler) {
compiler.hooks.afterEmit.tapPromise(BacktracePlugin.name, async (compilation) => {
const logger = compilation.getLogger(BacktracePlugin.name);
if (!compilation.outputOptions.path) {
logger.error(
'Skipping everything because outputOptions.path is not set. If you see this error, please report this to Backtrace.',
);
return;
}

const entries: [string, string, string][] = [];

for (const asset in compilation.assets) {
if (!asset.match(/\.(c|m)?jsx?$/)) {
logger.debug(`[${asset}] skipping processing, extension does not match`);
continue;
}

const map = asset + '.map';
if (!compilation.assets[map]) {
logger.debug(`[${asset}] skipping processing, map file not found`);
continue;
}

export { BacktracePlugin };
const assetPath = path.join(compilation.outputOptions.path, asset);
const sourceMapPath = path.join(compilation.outputOptions.path, map);

logger.debug(`adding asset ${assetPath} with sourcemap ${sourceMapPath}`);
entries.push([asset, assetPath, sourceMapPath]);
}

logger.log(`received ${entries.length} files for processing`);

for (const [asset, sourcePath, sourceMapPath] of entries) {
let debugId: string;

logger.time(`[${asset}] process source and sourcemap`);
try {
debugId = await this._sourceProcessor.processSourceAndSourceMapFiles(sourcePath, sourceMapPath);
} catch (err) {
logger.error(`[${asset}] process source and sourcemap failed:`, err);
continue;
} finally {
logger.timeEnd(`[${asset}] process source and sourcemap`);
}

if (!this._sourceMapUploader) {
logger.info(`[${asset}] file processed`);
continue;
}

logger.time(`[${asset}] upload sourcemap`);
try {
await this._sourceMapUploader.upload(sourceMapPath, debugId);
logger.info(`[${asset}] file processed and sourcemap uploaded`);
} catch (err) {
logger.error(`[${asset}] upload sourcemap failed:`, err);
} finally {
logger.timeEnd(`[${asset}] upload sourcemap`);
}
}
});
}
}
46 changes: 0 additions & 46 deletions tools/webpack-plugin/src/BacktracePluginV4.ts

This file was deleted.

173 changes: 0 additions & 173 deletions tools/webpack-plugin/src/BacktracePluginV5.ts

This file was deleted.

39 changes: 0 additions & 39 deletions tools/webpack-plugin/src/BacktraceWebpackSourceGenerator.ts

This file was deleted.

3 changes: 0 additions & 3 deletions tools/webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { BacktracePlugin } from './BacktracePlugin';

export { BacktracePluginV4 } from './BacktracePluginV4';
export { BacktracePluginV5 } from './BacktracePluginV5';
export { BacktracePluginOptions } from './models/BacktracePluginOptions';
export { BacktracePlugin };
export default BacktracePlugin;
Loading