diff --git a/sourcemap-uploader/README.md b/sourcemap-uploader/README.md index 7e1fb5970..9bd9852bd 100644 --- a/sourcemap-uploader/README.md +++ b/sourcemap-uploader/README.md @@ -13,15 +13,18 @@ npm i @openreplay/sourcemap-uploader -D Upload sourcemap for one file ``` -sourcemap-uploader -k API_KEY -p PROJECT_KEY file -m ./dist/index.js.map -u https://openreplay.com/index.js +sourcemap-uploader -k API_KEY -p PROJECT_KEY file -m ./dist/index.js.map -u https://myapp.com/index.js ``` -Upload all sourcemaps in the directory. The path will be appended to the base url +Upload all sourcemaps in the directory. The url must correspond to the root where you upload JS files from the directory. + +Thus, if you have your `app-42.js` along with the `app-42.js.map` in the `./build` folder and then want to upload it to you server (you might want to avoid uploading soursemaps) so it can be reachable through the link `https://myapp.com/static/app-42.js`, the command would be the next: ``` -sourcemap-uploader -k API_KEY -p PROJECT_KEY dir -m ./dist -u https://openreplay.com/ +sourcemap-uploader -k API_KEY -p PROJECT_KEY dir -m ./build -u https://myapp.com/static ``` + ## NPM There are two functions inside `index.js` of the package diff --git a/sourcemap-uploader/cli.js b/sourcemap-uploader/cli.js index bdd227e82..f7b124117 100755 --- a/sourcemap-uploader/cli.js +++ b/sourcemap-uploader/cli.js @@ -48,6 +48,8 @@ dir.addArgument(['-u', '--js-dir-url'], { required: true, }); +// TODO: exclude in dir + const { command, api_key, project_key, server, ...args } = parser.parseArgs(); try { @@ -60,9 +62,11 @@ try { ? uploadFile(api_key, project_key, args.sourcemap_file_path, args.js_file_url) : uploadDir(api_key, project_key, args.sourcemap_dir_path, args.js_dir_url) ) -.then((uploadedFiles) => - console.log(`Sourcemap${uploadedFiles.length > 1 ? "s" : ""} successfully uploaded! (${uploadedFiles.length} files)\n` - + uploadedFiles.join("\t\n") +.then((sourceFiles) => + sourceFiles.length > 0 + ? console.log(`Successfully uploaded ${sourceFiles.length} sourcemap file${sourceFiles.length > 1 ? "s" : ""} for: \n` + + sourceFiles.join("\t\n") ) + : console.log(`No sourcemaps found in ${ args.js_dir_url }`) ) .catch(e => console.error(`Sourcemap Uploader: ${e}`)); diff --git a/sourcemap-uploader/lib/uploadSourcemaps.js b/sourcemap-uploader/lib/uploadSourcemaps.js index 4199d2e30..a39ce5e4d 100644 --- a/sourcemap-uploader/lib/uploadSourcemaps.js +++ b/sourcemap-uploader/lib/uploadSourcemaps.js @@ -2,6 +2,10 @@ const https = require('https'); const getUploadURLs = (api_key, project_key, js_file_urls) => new Promise((resolve, reject) => { + if (js_file_urls.length === 0) { + resolve([]); + } + const pathPrefix = (global.SERVER.pathname + "/").replace(/\/+/g, '/'); const req = https.request( { @@ -28,9 +32,9 @@ const getUploadURLs = (api_key, project_key, js_file_urls) => req.end(); }); -const uploadSourcemap = (upload_url, sourcemap) => +const uploadSourcemap = (upload_url, body) => new Promise((resolve, reject) => { - body = Buffer.from(JSON.stringify(sourcemap.body)); + body = Buffer.from(JSON.stringify(body)); const req = https.request( upload_url, { @@ -45,7 +49,7 @@ const uploadSourcemap = (upload_url, sourcemap) => reject("Unable to upload. Please, contact OpenReplay support."); return; } - resolve(sourcemap.sourcemap_file_path) + resolve(); //res.on('end', resolve); }, ); @@ -62,7 +66,8 @@ module.exports = (api_key, project_key, sourcemaps) => ).then(upload_urls => Promise.all( upload_urls.map((upload_url, i) => - uploadSourcemap(upload_url, sourcemaps[i]) + uploadSourcemap(upload_url, sourcemaps[i].body) + .then(() => sourcemaps[i].js_file_url) ), ), ); diff --git a/sourcemap-uploader/package-lock.json b/sourcemap-uploader/package-lock.json index d9423165d..40b676c79 100644 --- a/sourcemap-uploader/package-lock.json +++ b/sourcemap-uploader/package-lock.json @@ -1,6 +1,6 @@ { - "name": "@asayerio/sourcemaps-uploader", - "version": "1.0.0", + "name": "@openreplay/sourcemap-uploader", + "version": "3.0.1", "lockfileVersion": 1, "requires": true, "dependencies": {