Socket
Socket
Sign inDemoInstall

@flareapp/flare-webpack-plugin-sourcemap

Package Overview
Dependencies
293
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

104

dist/index.js

@@ -12,8 +12,9 @@ (function (factory) {

Object.defineProperty(exports, "__esModule", { value: true });
const webpack_1 = require("webpack");
const zlib_1 = require("zlib");
const axios_1 = require("axios");
const util_1 = require("./util");
class FlareWebpackPluginSourcemap {
constructor({ key, apiEndpoint = 'https://flareapp.io/api/sourcemaps', runInDevelopment = false, versionId = util_1.uuidv4(), collectGitInformation = false, }) {
var webpack_1 = require("webpack");
var zlib_1 = require("zlib");
var axios = require("axios");
var util_1 = require("./util");
var FlareWebpackPluginSourcemap = /** @class */ (function () {
function FlareWebpackPluginSourcemap(_a) {
var key = _a.key, _b = _a.apiEndpoint, apiEndpoint = _b === void 0 ? 'https://flareapp.io/api/sourcemaps' : _b, _c = _a.runInDevelopment, runInDevelopment = _c === void 0 ? false : _c, _d = _a.versionId, versionId = _d === void 0 ? util_1.uuidv4() : _d, _e = _a.collectGitInformation, collectGitInformation = _e === void 0 ? false : _e;
this.key = key;

@@ -25,7 +26,8 @@ this.apiEndpoint = apiEndpoint;

}
apply(compiler) {
FlareWebpackPluginSourcemap.prototype.apply = function (compiler) {
var _this = this;
if (!this.verifyOptions(compiler)) {
return;
}
new webpack_1.default.DefinePlugin({
new webpack_1.DefinePlugin({
FLARE_SOURCEMAP_VERSION: JSON.stringify(this.versionId),

@@ -36,18 +38,18 @@ FLARE_GIT_INFO: this.collectGitInformation && compiler.options.context

}).apply(compiler);
compiler.hooks.afterEmit.tapPromise('GetSourcemapsAndUploadToFlare', compilation => {
compiler.hooks.afterEmit.tapPromise('GetSourcemapsAndUploadToFlare', function (compilation) {
util_1.flareLog('Uploading sourcemaps to Flare');
return this.sendSourcemaps(compilation)
.then(() => {
return _this.sendSourcemaps(compilation)
.then(function () {
util_1.flareLog('Successfully uploaded sourcemaps to Flare.');
})
.catch(error => {
const errorMessage = 'Something went wrong while uploading sourcemaps to Flare. ' +
.catch(function (error) {
var errorMessage = 'Something went wrong while uploading sourcemaps to Flare. ' +
'Additional information may have been outputted above.';
compilation.errors.push(`@flareapp/flare-webpack-plugin-sourcemap: ${error}`);
compilation.errors.push(`@flareapp/flare-webpack-plugin-sourcemap: ${errorMessage}`);
/* compilation.errors.push(`@flareapp/flare-webpack-plugin-sourcemap: ${error}`);
compilation.errors.push(`@flareapp/flare-webpack-plugin-sourcemap: ${errorMessage}`); */
util_1.flareLog(errorMessage);
});
});
}
verifyOptions(compiler) {
};
FlareWebpackPluginSourcemap.prototype.verifyOptions = function (compiler) {
if (!this.key) {

@@ -62,6 +64,7 @@ util_1.flareLog('No Flare project key was provided, not uploading sourcemaps to Flare.', true);

return true;
}
sendSourcemaps(compilation) {
return new Promise((resolve, reject) => {
const sourcemaps = this.getSourcemaps(compilation);
};
FlareWebpackPluginSourcemap.prototype.sendSourcemaps = function (compilation) {
var _this = this;
return new Promise(function (resolve, reject) {
var sourcemaps = _this.getSourcemaps(compilation);
if (!sourcemaps.length) {

@@ -71,5 +74,5 @@ util_1.flareLog('No sourcemap files were found. Make sure sourcemaps are being generated!', true);

}
Promise.all(sourcemaps.map(sourcemap => this.uploadSourcemap(sourcemap)))
.then(() => resolve())
.catch(error => {
Promise.all(sourcemaps.map(function (sourcemap) { return _this.uploadSourcemap(sourcemap); }))
.then(function () { return resolve(); })
.catch(function (error) {
util_1.flareLog(error, true);

@@ -79,40 +82,51 @@ return reject(error);

});
}
getSourcemaps(compilation) {
const chunks = compilation.getStats().toJson().chunks;
};
FlareWebpackPluginSourcemap.prototype.getSourcemaps = function (compilation) {
var chunks = compilation.getStats().toJson().chunks;
if (!chunks) {
return [];
}
return chunks.reduce((sourcemaps, currentChunk) => {
const filename = currentChunk.files.find(file => /\.js$/.test(file));
const sourcemapUrl = currentChunk.files.find(file => /\.js\.map$/.test(file));
return chunks.reduce(function (sourcemaps, currentChunk) {
var filename = currentChunk.files.find(function (file) { return /\.js$/.test(file); });
var sourcemapUrl = currentChunk.files.find(function (file) { return /\.js\.map$/.test(file); });
if (filename && sourcemapUrl) {
const content = compilation.assets[sourcemapUrl].source();
sourcemaps = [...sourcemaps, { filename, content }];
var content = compilation.assets[sourcemapUrl].source();
sourcemaps = sourcemaps.concat([{ filename: filename, content: content }]);
}
return sourcemaps;
}, []);
}
uploadSourcemap(sourcemap) {
return new Promise((resolve, reject) => {
const base64GzipSourcemap = zlib_1.default.deflateRawSync(sourcemap.content).toString('base64');
axios_1.default
.post(this.apiEndpoint, {
key: this.key,
version_id: this.versionId,
};
FlareWebpackPluginSourcemap.prototype.uploadSourcemap = function (sourcemap) {
var _this = this;
return new Promise(function (resolve, reject) {
var base64GzipSourcemap = zlib_1.deflateRawSync(sourcemap.content).toString('base64');
console.log(_this.apiEndpoint, {
key: _this.key,
version_id: _this.versionId,
relative_filename: sourcemap.filename,
sourcemap: base64GzipSourcemap,
});
throw new Error('kek');
// ts error: https://github.com/axios/axios/issues/1975
axios
.post(_this.apiEndpoint, {
key: _this.key,
version_id: _this.versionId,
relative_filename: sourcemap.filename,
sourcemap: base64GzipSourcemap,
})
.then(() => resolve())
.catch((error) => {
.then(function () { return resolve(); })
.catch(function (error) {
if (!error || !error.response) {
return reject('Something went wrong while uploading the sourcemaps to Flare.');
}
util_1.flareLog(`${error.response.status}: ${error.response.data.message}`, true);
util_1.flareLog(error.response.status + ": " + error.response.data.message, true);
console.error(error.response);
return reject(error);
});
});
}
}
};
return FlareWebpackPluginSourcemap;
}());
module.exports = FlareWebpackPluginSourcemap;
});
{
"name": "@flareapp/flare-webpack-plugin-sourcemap",
"version": "0.0.3",
"version": "0.0.4",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -1,4 +0,5 @@

import webpack from 'webpack';
import zlib from 'zlib';
import axios, { AxiosError } from 'axios';
import { Compiler, DefinePlugin, compilation } from 'webpack';
import { deflateRawSync } from 'zlib';
import { AxiosError } from 'axios';
import * as axios from 'axios';
import { getGitInfo, flareLog, uuidv4 } from './util';

@@ -40,3 +41,3 @@

apply(compiler: webpack.Compiler) {
apply(compiler: Compiler) {
if (!this.verifyOptions(compiler)) {

@@ -46,3 +47,3 @@ return;

new webpack.DefinePlugin({
new DefinePlugin({
FLARE_SOURCEMAP_VERSION: JSON.stringify(this.versionId),

@@ -75,3 +76,3 @@ FLARE_GIT_INFO:

verifyOptions(compiler: webpack.Compiler): boolean {
verifyOptions(compiler: Compiler): boolean {
if (!this.key) {

@@ -90,3 +91,3 @@ flareLog('No Flare project key was provided, not uploading sourcemaps to Flare.', true);

sendSourcemaps(compilation: webpack.compilation.Compilation): Promise<void> {
sendSourcemaps(compilation: compilation.Compilation): Promise<void> {
return new Promise((resolve, reject) => {

@@ -111,3 +112,3 @@ const sourcemaps = this.getSourcemaps(compilation);

getSourcemaps(compilation: webpack.compilation.Compilation): Array<Sourcemap> {
getSourcemaps(compilation: compilation.Compilation): Array<Sourcemap> {
const chunks = compilation.getStats().toJson().chunks;

@@ -138,4 +139,14 @@

return new Promise((resolve, reject) => {
const base64GzipSourcemap = zlib.deflateRawSync(sourcemap.content).toString('base64');
const base64GzipSourcemap = deflateRawSync(sourcemap.content).toString('base64');
console.log(this.apiEndpoint, {
key: this.key,
version_id: this.versionId,
relative_filename: sourcemap.filename,
sourcemap: base64GzipSourcemap,
});
throw new Error('kek');
// ts error: https://github.com/axios/axios/issues/1975
axios

@@ -155,2 +166,3 @@ .post(this.apiEndpoint, {

flareLog(`${error.response.status}: ${error.response.data.message}`, true);
console.error(error.response);

@@ -157,0 +169,0 @@ return reject(error);

@@ -33,7 +33,7 @@ import { execSync } from 'child_process';

if (isError) {
console.error('\n' + formattedMessage + '\n');
console.error(formattedMessage);
return;
}
console.log('\n' + formattedMessage + '\n');
console.log(formattedMessage);
}

@@ -40,0 +40,0 @@

{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"lib": ["es2017"],

@@ -12,3 +11,3 @@ "module": "umd",

"strict": true,
"target": "esnext",
"target": "es5",
"outDir": "dist"

@@ -15,0 +14,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc