fix(sourcemap-uploader): 3.0.6 - server parameter to the upload functions instead of being global
This commit is contained in:
parent
11ee390f8d
commit
b498427601
5 changed files with 29 additions and 24 deletions
|
|
@ -10,28 +10,31 @@ npm i -D @openreplay/sourcemap-uploader
|
|||
|
||||
## CLI
|
||||
|
||||
Upload sourcemap for one file:
|
||||
### Upload a sourcemap for one file:
|
||||
|
||||
```
|
||||
sourcemap-uploader -s https://opnereplay.mycompany.com/api -k API_KEY -p PROJECT_KEY file -m ./dist/index.js.map -u https://myapp.com/index.js
|
||||
```
|
||||
|
||||
Upload all sourcemaps in a given directory. The URL must correspond to the root where you upload JS files from the directory. In other words, 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 your OpenReplay instance so it can be reachable through the link `https://myapp.com/static/app-42.js`, then the command should be like:
|
||||
### Upload all sourcemaps in a given directory.
|
||||
The URL must correspond to the root where you upload JS files from the directory. In other words, 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 your OpenReplay instance so it can be reachable through the link `https://myapp.com/static/app-42.js`, then the command should be like:
|
||||
|
||||
```
|
||||
sourcemap-uploader -s https://opnereplay.mycompany.com/api -k API_KEY -p PROJECT_KEY dir -m ./build -u https://myapp.com/static
|
||||
```
|
||||
|
||||
- Use `-s` (`--server`) to specify the URL of your OpenReplay instance (make to append it with /api)
|
||||
- Use `-s` (`--server`) to specify the URL of your OpenReplay instance (append it with /api).
|
||||
**Do not use this parameter if you use SaaS version of the OpenRplay**
|
||||
|
||||
- Use `-v` (`--verbose`) to see the logs.
|
||||
|
||||
## NPM
|
||||
|
||||
There are two functions inside `index.js` of the package:
|
||||
There are two functions you can export from the package:
|
||||
|
||||
```
|
||||
uploadFile(api_key, project_key, sourcemap_file_path, js_file_url)
|
||||
uploadDir(api_key, project_key, sourcemap_dir_path, js_dir_url)
|
||||
uploadFile(api_key, project_key, sourcemap_file_path, js_file_url, [server])
|
||||
uploadDir(api_key, project_key, sourcemap_dir_path, js_dir_url, [server])
|
||||
```
|
||||
|
||||
Both functions return Promise.
|
||||
Both functions return Promise with a result value to be the list of files for which sourcemaps were uploaded.
|
||||
|
|
|
|||
|
|
@ -58,15 +58,9 @@ const { command, api_key, project_key, server, verbose, ...args } = parser.parse
|
|||
|
||||
global._VERBOSE = !!verbose;
|
||||
|
||||
try {
|
||||
global.SERVER = new URL(server || "https://api.openreplay.com");
|
||||
} catch (e) {
|
||||
console.error(`Sourcemap Uploader: server URL parse error. ${e}`)
|
||||
}
|
||||
|
||||
(command === 'file'
|
||||
? 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)
|
||||
? uploadFile(api_key, project_key, args.sourcemap_file_path, args.js_file_url, server)
|
||||
: uploadDir(api_key, project_key, args.sourcemap_dir_path, args.js_dir_url, server)
|
||||
)
|
||||
.then((sourceFiles) =>
|
||||
sourceFiles.length > 0
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ const readFile = require('./lib/readFile.js'),
|
|||
uploadSourcemaps = require('./lib/uploadSourcemaps.js');
|
||||
|
||||
module.exports = {
|
||||
async uploadFile(api_key, project_key, sourcemap_file_path, js_file_url) {
|
||||
async uploadFile(api_key, project_key, sourcemap_file_path, js_file_url, server) {
|
||||
const sourcemap = await readFile(sourcemap_file_path, js_file_url);
|
||||
return uploadSourcemaps(api_key, project_key, [sourcemap]);
|
||||
return uploadSourcemaps(api_key, project_key, [sourcemap], server);
|
||||
},
|
||||
async uploadDir(api_key, project_key, sourcemap_dir_path, js_dir_url) {
|
||||
async uploadDir(api_key, project_key, sourcemap_dir_path, js_dir_url, server) {
|
||||
const sourcemaps = await readDir(sourcemap_dir_path, js_dir_url);
|
||||
return uploadSourcemaps(api_key, project_key, sourcemaps);
|
||||
return uploadSourcemaps(api_key, project_key, sourcemaps, server);
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,22 @@
|
|||
const https = require('https');
|
||||
|
||||
const getUploadURLs = (api_key, project_key, js_file_urls) =>
|
||||
const getUploadURLs = (api_key, project_key, js_file_urls, server) =>
|
||||
new Promise((resolve, reject) => {
|
||||
if (js_file_urls.length === 0) {
|
||||
resolve([]);
|
||||
}
|
||||
|
||||
const pathPrefix = (global.SERVER.pathname + "/").replace(/\/+/g, '/');
|
||||
let serverURL;
|
||||
try {
|
||||
serverURL = new URL(server);
|
||||
} catch(e) {
|
||||
return reject(`Failed to parse server URL "${server}".`)
|
||||
}
|
||||
|
||||
const pathPrefix = (serverURL.pathname + "/").replace(/\/+/g, '/');
|
||||
const options = {
|
||||
method: 'PUT',
|
||||
hostname: global.SERVER.host,
|
||||
hostname: serverURL.host,
|
||||
path: pathPrefix + `${project_key}/sourcemaps/`,
|
||||
headers: { Authorization: api_key, 'Content-Type': 'application/json' },
|
||||
}
|
||||
|
|
@ -74,11 +81,12 @@ const uploadSourcemap = (upload_url, body) =>
|
|||
req.end();
|
||||
});
|
||||
|
||||
module.exports = (api_key, project_key, sourcemaps) =>
|
||||
module.exports = (api_key, project_key, sourcemaps, server) =>
|
||||
getUploadURLs(
|
||||
api_key,
|
||||
project_key,
|
||||
sourcemaps.map(({ js_file_url }) => js_file_url),
|
||||
server || "https://api.openreplay.com",
|
||||
).then(upload_urls =>
|
||||
Promise.all(
|
||||
upload_urls.map((upload_url, i) =>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@openreplay/sourcemap-uploader",
|
||||
"version": "3.0.5",
|
||||
"version": "3.0.6",
|
||||
"description": "NPM module to upload your JS sourcemaps files to OpenReplay",
|
||||
"bin": "cli.js",
|
||||
"main": "index.js",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue