@flareapp/vite 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.release-it.json +16 -0
- package/dist/index.d.mts +13 -21
- package/dist/index.d.ts +18 -0
- package/dist/index.js +169 -0
- package/dist/index.mjs +124 -124
- package/package.json +12 -17
- package/src/flareApi.ts +16 -47
- package/src/index.ts +2 -1
- package/dist/index.cjs +0 -168
- package/dist/index.d.cts +0 -26
package/.release-it.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"git": {
|
|
3
|
+
"commitMessage": "Release @flareapp/vite v${version}",
|
|
4
|
+
"tagName": "@flareapp/vite@${version}",
|
|
5
|
+
"tagAnnotation": "Release @flareapp/vite v${version}"
|
|
6
|
+
},
|
|
7
|
+
"github": {
|
|
8
|
+
"release": false
|
|
9
|
+
},
|
|
10
|
+
"npm": {
|
|
11
|
+
"publish": true
|
|
12
|
+
},
|
|
13
|
+
"hooks": {
|
|
14
|
+
"after:bump": "npm run build"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import { Plugin } from
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
//#region src/index.d.ts
|
|
4
3
|
type PluginConfig = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
key: string;
|
|
5
|
+
base?: string;
|
|
6
|
+
apiEndpoint?: string;
|
|
7
|
+
runInDevelopment?: boolean;
|
|
8
|
+
version?: string;
|
|
9
|
+
removeSourcemaps?: boolean;
|
|
11
10
|
};
|
|
12
11
|
type Sourcemap = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
original_file: string;
|
|
13
|
+
content: string;
|
|
14
|
+
sourcemap_url: string;
|
|
16
15
|
};
|
|
17
|
-
declare function flareSourcemapUploader({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
apiEndpoint,
|
|
21
|
-
runInDevelopment,
|
|
22
|
-
version,
|
|
23
|
-
removeSourcemaps
|
|
24
|
-
}: PluginConfig): Plugin;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { PluginConfig, Sourcemap, flareSourcemapUploader as default };
|
|
16
|
+
declare function flareSourcemapUploader({ key, base, apiEndpoint, runInDevelopment, version, removeSourcemaps, }: PluginConfig): Plugin;
|
|
17
|
+
|
|
18
|
+
export { type PluginConfig, type Sourcemap, flareSourcemapUploader as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type PluginConfig = {
|
|
4
|
+
key: string;
|
|
5
|
+
base?: string;
|
|
6
|
+
apiEndpoint?: string;
|
|
7
|
+
runInDevelopment?: boolean;
|
|
8
|
+
version?: string;
|
|
9
|
+
removeSourcemaps?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type Sourcemap = {
|
|
12
|
+
original_file: string;
|
|
13
|
+
content: string;
|
|
14
|
+
sourcemap_url: string;
|
|
15
|
+
};
|
|
16
|
+
declare function flareSourcemapUploader({ key, base, apiEndpoint, runInDevelopment, version, removeSourcemaps, }: PluginConfig): Plugin;
|
|
17
|
+
|
|
18
|
+
export { type PluginConfig, type Sourcemap, flareSourcemapUploader as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
default: () => flareSourcemapUploader
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
37
|
+
var import_fs = require("fs");
|
|
38
|
+
var import_path = require("path");
|
|
39
|
+
|
|
40
|
+
// src/flareApi.ts
|
|
41
|
+
var import_axios = __toESM(require("axios"));
|
|
42
|
+
var import_zlib = require("zlib");
|
|
43
|
+
var FlareApi = class {
|
|
44
|
+
constructor(endpoint, key, version) {
|
|
45
|
+
this.endpoint = endpoint;
|
|
46
|
+
this.key = key;
|
|
47
|
+
this.version = version;
|
|
48
|
+
}
|
|
49
|
+
uploadSourcemap(sourcemap) {
|
|
50
|
+
return new Promise((resolve2, reject) => {
|
|
51
|
+
const base64GzipSourcemap = (0, import_zlib.deflateRawSync)(sourcemap.content).toString("base64");
|
|
52
|
+
import_axios.default.post(this.endpoint, {
|
|
53
|
+
key: this.key,
|
|
54
|
+
version_id: this.version,
|
|
55
|
+
relative_filename: sourcemap.original_file,
|
|
56
|
+
sourcemap: base64GzipSourcemap
|
|
57
|
+
}).then(resolve2).catch((error) => {
|
|
58
|
+
return reject(`${error.response.status}: ${JSON.stringify(error.response.data)}`);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/util.ts
|
|
65
|
+
function uuid() {
|
|
66
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
67
|
+
const r = Math.random() * 16 | 0;
|
|
68
|
+
const v = c == "x" ? r : r & 3 | 8;
|
|
69
|
+
return v.toString(16);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/index.ts
|
|
74
|
+
function flareSourcemapUploader({
|
|
75
|
+
key,
|
|
76
|
+
base,
|
|
77
|
+
apiEndpoint = "https://flareapp.io/api/sourcemaps",
|
|
78
|
+
runInDevelopment = false,
|
|
79
|
+
version = uuid(),
|
|
80
|
+
removeSourcemaps = false
|
|
81
|
+
}) {
|
|
82
|
+
if (!key) {
|
|
83
|
+
flareLog("No Flare API key was provided, not uploading sourcemaps to Flare.");
|
|
84
|
+
}
|
|
85
|
+
const flare = new FlareApi(apiEndpoint, key, version);
|
|
86
|
+
const enableUploadingSourcemaps = key && (process.env.NODE_ENV !== "development" || runInDevelopment) && process.env.SKIP_SOURCEMAPS !== "true";
|
|
87
|
+
return {
|
|
88
|
+
name: "flare-vite-plugin",
|
|
89
|
+
apply: "build",
|
|
90
|
+
config({ build }, { mode }) {
|
|
91
|
+
return {
|
|
92
|
+
// Set FLARE_SOURCEMAP_VERSION and API key so the Flare JS client can read it
|
|
93
|
+
define: {
|
|
94
|
+
FLARE_SOURCEMAP_VERSION: `'${version}'`,
|
|
95
|
+
FLARE_JS_KEY: `'${key}'`
|
|
96
|
+
},
|
|
97
|
+
build: {
|
|
98
|
+
sourcemap: (() => {
|
|
99
|
+
if (build?.sourcemap !== void 0) return build.sourcemap;
|
|
100
|
+
const enableSourcemaps = enableUploadingSourcemaps && mode !== "development";
|
|
101
|
+
if (enableSourcemaps) return "hidden";
|
|
102
|
+
return false;
|
|
103
|
+
})()
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
configResolved(config) {
|
|
108
|
+
base = base || config.base;
|
|
109
|
+
base += base.endsWith("/") ? "" : "/";
|
|
110
|
+
},
|
|
111
|
+
async writeBundle(outputConfig) {
|
|
112
|
+
if (!enableUploadingSourcemaps) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const outputDir = outputConfig.dir || "";
|
|
116
|
+
const files = await (0, import_fast_glob.default)("./**/*.map", { cwd: outputDir });
|
|
117
|
+
const sourcemaps = files.map((file) => {
|
|
118
|
+
const sourcePath = file.replace(/\.map$/, "");
|
|
119
|
+
const sourceFilename = (0, import_path.resolve)(outputDir, sourcePath);
|
|
120
|
+
if (!(0, import_fs.existsSync)(sourceFilename)) {
|
|
121
|
+
flareLog(`no corresponding source found for "${file}"`, true);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const sourcemapLocation = (0, import_path.resolve)(outputDir, file);
|
|
125
|
+
try {
|
|
126
|
+
return {
|
|
127
|
+
content: (0, import_fs.readFileSync)(sourcemapLocation, "utf8"),
|
|
128
|
+
sourcemap_url: sourcemapLocation,
|
|
129
|
+
original_file: `${base}${sourcePath}`
|
|
130
|
+
};
|
|
131
|
+
} catch (error) {
|
|
132
|
+
flareLog("Error reading sourcemap file " + sourcemapLocation + ": " + error, true);
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}).filter((sourcemap) => sourcemap !== null);
|
|
136
|
+
if (!sourcemaps.length) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
flareLog(`Uploading ${sourcemaps.length} sourcemap files to Flare.`);
|
|
140
|
+
const pendingUploads = sourcemaps.map((sourcemap) => () => flare.uploadSourcemap(sourcemap));
|
|
141
|
+
try {
|
|
142
|
+
while (pendingUploads.length) {
|
|
143
|
+
await Promise.all(pendingUploads.splice(0, 10).map((f) => f()));
|
|
144
|
+
}
|
|
145
|
+
flareLog("Successfully uploaded sourcemaps to Flare.");
|
|
146
|
+
} catch (error) {
|
|
147
|
+
flareLog(`Something went wrong while uploading the sourcemaps to Flare: ${error}`, true);
|
|
148
|
+
}
|
|
149
|
+
if (removeSourcemaps) {
|
|
150
|
+
sourcemaps.forEach(({ sourcemap_url }) => {
|
|
151
|
+
try {
|
|
152
|
+
(0, import_fs.unlinkSync)(sourcemap_url);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error("Error removing sourcemap file", sourcemap_url, ": ", error);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
flareLog("Successfully removed sourcemaps.");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function flareLog(message, isError = false) {
|
|
163
|
+
const formattedMessage = "@flareapp/vite: " + message;
|
|
164
|
+
if (isError) {
|
|
165
|
+
console.error(formattedMessage);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
console.log(formattedMessage);
|
|
169
|
+
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,138 +1,138 @@
|
|
|
1
|
+
// src/index.ts
|
|
1
2
|
import glob from "fast-glob";
|
|
2
3
|
import { existsSync, readFileSync, unlinkSync } from "fs";
|
|
3
4
|
import { resolve } from "path";
|
|
5
|
+
|
|
6
|
+
// src/flareApi.ts
|
|
4
7
|
import axios from "axios";
|
|
5
|
-
import https from "https";
|
|
6
8
|
import { deflateRawSync } from "zlib";
|
|
7
|
-
|
|
8
|
-
//#region src/flareApi.ts
|
|
9
9
|
var FlareApi = class {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
async postWithRetry(data, retries = 3) {
|
|
30
|
-
for (let attempt = 1; attempt <= retries; attempt++) try {
|
|
31
|
-
return await this.client.post(this.endpoint, data);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
if (axios.isAxiosError(error)) {
|
|
34
|
-
if (error.response) throw `${error.response.status}: ${JSON.stringify(error.response.data)}`;
|
|
35
|
-
if (attempt < retries) {
|
|
36
|
-
await this.delay(attempt * 1e3);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
throw `Network error: ${error.message}`;
|
|
40
|
-
}
|
|
41
|
-
throw `Request setup error: ${error instanceof Error ? error.message : String(error)}`;
|
|
42
|
-
}
|
|
43
|
-
throw "Unexpected: retry loop exited without returning or throwing";
|
|
44
|
-
}
|
|
45
|
-
delay(ms) {
|
|
46
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
47
|
-
}
|
|
10
|
+
constructor(endpoint, key, version) {
|
|
11
|
+
this.endpoint = endpoint;
|
|
12
|
+
this.key = key;
|
|
13
|
+
this.version = version;
|
|
14
|
+
}
|
|
15
|
+
uploadSourcemap(sourcemap) {
|
|
16
|
+
return new Promise((resolve2, reject) => {
|
|
17
|
+
const base64GzipSourcemap = deflateRawSync(sourcemap.content).toString("base64");
|
|
18
|
+
axios.post(this.endpoint, {
|
|
19
|
+
key: this.key,
|
|
20
|
+
version_id: this.version,
|
|
21
|
+
relative_filename: sourcemap.original_file,
|
|
22
|
+
sourcemap: base64GzipSourcemap
|
|
23
|
+
}).then(resolve2).catch((error) => {
|
|
24
|
+
return reject(`${error.response.status}: ${JSON.stringify(error.response.data)}`);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
48
28
|
};
|
|
49
29
|
|
|
50
|
-
|
|
51
|
-
//#region src/util.ts
|
|
30
|
+
// src/util.ts
|
|
52
31
|
function uuid() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
32
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
33
|
+
const r = Math.random() * 16 | 0;
|
|
34
|
+
const v = c == "x" ? r : r & 3 | 8;
|
|
35
|
+
return v.toString(16);
|
|
36
|
+
});
|
|
57
37
|
}
|
|
58
38
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
39
|
+
// src/index.ts
|
|
40
|
+
function flareSourcemapUploader({
|
|
41
|
+
key,
|
|
42
|
+
base,
|
|
43
|
+
apiEndpoint = "https://flareapp.io/api/sourcemaps",
|
|
44
|
+
runInDevelopment = false,
|
|
45
|
+
version = uuid(),
|
|
46
|
+
removeSourcemaps = false
|
|
47
|
+
}) {
|
|
48
|
+
if (!key) {
|
|
49
|
+
flareLog("No Flare API key was provided, not uploading sourcemaps to Flare.");
|
|
50
|
+
}
|
|
51
|
+
const flare = new FlareApi(apiEndpoint, key, version);
|
|
52
|
+
const enableUploadingSourcemaps = key && (process.env.NODE_ENV !== "development" || runInDevelopment) && process.env.SKIP_SOURCEMAPS !== "true";
|
|
53
|
+
return {
|
|
54
|
+
name: "flare-vite-plugin",
|
|
55
|
+
apply: "build",
|
|
56
|
+
config({ build }, { mode }) {
|
|
57
|
+
return {
|
|
58
|
+
// Set FLARE_SOURCEMAP_VERSION and API key so the Flare JS client can read it
|
|
59
|
+
define: {
|
|
60
|
+
FLARE_SOURCEMAP_VERSION: `'${version}'`,
|
|
61
|
+
FLARE_JS_KEY: `'${key}'`
|
|
62
|
+
},
|
|
63
|
+
build: {
|
|
64
|
+
sourcemap: (() => {
|
|
65
|
+
if (build?.sourcemap !== void 0) return build.sourcemap;
|
|
66
|
+
const enableSourcemaps = enableUploadingSourcemaps && mode !== "development";
|
|
67
|
+
if (enableSourcemaps) return "hidden";
|
|
68
|
+
return false;
|
|
69
|
+
})()
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
configResolved(config) {
|
|
74
|
+
base = base || config.base;
|
|
75
|
+
base += base.endsWith("/") ? "" : "/";
|
|
76
|
+
},
|
|
77
|
+
async writeBundle(outputConfig) {
|
|
78
|
+
if (!enableUploadingSourcemaps) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const outputDir = outputConfig.dir || "";
|
|
82
|
+
const files = await glob("./**/*.map", { cwd: outputDir });
|
|
83
|
+
const sourcemaps = files.map((file) => {
|
|
84
|
+
const sourcePath = file.replace(/\.map$/, "");
|
|
85
|
+
const sourceFilename = resolve(outputDir, sourcePath);
|
|
86
|
+
if (!existsSync(sourceFilename)) {
|
|
87
|
+
flareLog(`no corresponding source found for "${file}"`, true);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const sourcemapLocation = resolve(outputDir, file);
|
|
91
|
+
try {
|
|
92
|
+
return {
|
|
93
|
+
content: readFileSync(sourcemapLocation, "utf8"),
|
|
94
|
+
sourcemap_url: sourcemapLocation,
|
|
95
|
+
original_file: `${base}${sourcePath}`
|
|
96
|
+
};
|
|
97
|
+
} catch (error) {
|
|
98
|
+
flareLog("Error reading sourcemap file " + sourcemapLocation + ": " + error, true);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}).filter((sourcemap) => sourcemap !== null);
|
|
102
|
+
if (!sourcemaps.length) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
flareLog(`Uploading ${sourcemaps.length} sourcemap files to Flare.`);
|
|
106
|
+
const pendingUploads = sourcemaps.map((sourcemap) => () => flare.uploadSourcemap(sourcemap));
|
|
107
|
+
try {
|
|
108
|
+
while (pendingUploads.length) {
|
|
109
|
+
await Promise.all(pendingUploads.splice(0, 10).map((f) => f()));
|
|
110
|
+
}
|
|
111
|
+
flareLog("Successfully uploaded sourcemaps to Flare.");
|
|
112
|
+
} catch (error) {
|
|
113
|
+
flareLog(`Something went wrong while uploading the sourcemaps to Flare: ${error}`, true);
|
|
114
|
+
}
|
|
115
|
+
if (removeSourcemaps) {
|
|
116
|
+
sourcemaps.forEach(({ sourcemap_url }) => {
|
|
117
|
+
try {
|
|
118
|
+
unlinkSync(sourcemap_url);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("Error removing sourcemap file", sourcemap_url, ": ", error);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
flareLog("Successfully removed sourcemaps.");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
127
|
}
|
|
128
128
|
function flareLog(message, isError = false) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
const formattedMessage = "@flareapp/vite: " + message;
|
|
130
|
+
if (isError) {
|
|
131
|
+
console.error(formattedMessage);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
console.log(formattedMessage);
|
|
135
135
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
export {
|
|
137
|
+
flareSourcemapUploader as default
|
|
138
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flareapp/vite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Vite plugin for flareapp.io",
|
|
5
5
|
"homepage": "https://flareapp.io",
|
|
6
6
|
"bugs": "https://github.com/spatie/flare-client-js/issues",
|
|
@@ -10,37 +10,32 @@
|
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"author": "adriaan@spatie.be",
|
|
13
|
-
"main": "./dist/index.
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
14
|
"module": "./dist/index.mjs",
|
|
15
|
-
"types": "./dist/index.d.
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"default": "./dist/index.mjs"
|
|
21
|
-
},
|
|
22
|
-
"require": {
|
|
23
|
-
"types": "./dist/index.d.cts",
|
|
24
|
-
"default": "./dist/index.cjs"
|
|
25
|
-
}
|
|
18
|
+
"require": "./dist/index.js",
|
|
19
|
+
"import": "./dist/index.mjs"
|
|
26
20
|
}
|
|
27
21
|
},
|
|
28
22
|
"scripts": {
|
|
29
23
|
"prepublishOnly": "npm run build",
|
|
30
|
-
"build": "
|
|
31
|
-
"typescript": "tsc"
|
|
24
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
25
|
+
"typescript": "tsc",
|
|
26
|
+
"release": "npx release-it"
|
|
32
27
|
},
|
|
33
28
|
"dependencies": {
|
|
34
29
|
"axios": "^1.2.1",
|
|
35
30
|
"fast-glob": "^3.2.12"
|
|
36
31
|
},
|
|
37
32
|
"devDependencies": {
|
|
38
|
-
"
|
|
39
|
-
"typescript": "^5.
|
|
40
|
-
"vite": "^4.0.0||^5.0.0||^6.0.0
|
|
33
|
+
"@types/node": "^18.11.17",
|
|
34
|
+
"typescript": "^5.3.3",
|
|
35
|
+
"vite": "^4.0.0||^5.0.0||^6.0.0"
|
|
41
36
|
},
|
|
42
37
|
"peerDependencies": {
|
|
43
|
-
"vite": "^4.0.0||^5.0.0||^6.0.0
|
|
38
|
+
"vite": "^4.0.0||^5.0.0||^6.0.0"
|
|
44
39
|
},
|
|
45
40
|
"publishConfig": {
|
|
46
41
|
"access": "public"
|
package/src/flareApi.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import axios
|
|
2
|
-
import https from 'https';
|
|
1
|
+
import axios from 'axios';
|
|
3
2
|
import { deflateRawSync } from 'zlib';
|
|
4
3
|
|
|
5
4
|
import { Sourcemap } from './index';
|
|
@@ -8,58 +7,28 @@ export default class FlareApi {
|
|
|
8
7
|
endpoint: string;
|
|
9
8
|
key: string;
|
|
10
9
|
version: string;
|
|
11
|
-
private client: AxiosInstance;
|
|
12
10
|
|
|
13
11
|
constructor(endpoint: string, key: string, version: string) {
|
|
14
12
|
this.endpoint = endpoint;
|
|
15
13
|
this.key = key;
|
|
16
14
|
this.version = version;
|
|
17
|
-
this.client = axios.create({
|
|
18
|
-
httpsAgent: new https.Agent({ keepAlive: false }),
|
|
19
|
-
});
|
|
20
15
|
}
|
|
21
16
|
|
|
22
|
-
uploadSourcemap(sourcemap: Sourcemap)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
uploadSourcemap(sourcemap: Sourcemap) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const base64GzipSourcemap = deflateRawSync(sourcemap.content).toString('base64');
|
|
20
|
+
|
|
21
|
+
axios
|
|
22
|
+
.post(this.endpoint, {
|
|
23
|
+
key: this.key,
|
|
24
|
+
version_id: this.version,
|
|
25
|
+
relative_filename: sourcemap.original_file,
|
|
26
|
+
sourcemap: base64GzipSourcemap,
|
|
27
|
+
})
|
|
28
|
+
.then(resolve)
|
|
29
|
+
.catch((error) => {
|
|
30
|
+
return reject(`${error.response.status}: ${JSON.stringify(error.response.data)}`);
|
|
31
|
+
});
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
|
-
|
|
33
|
-
private async postWithRetry(data: Record<string, string>, retries = 3): Promise<unknown> {
|
|
34
|
-
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
35
|
-
try {
|
|
36
|
-
return await this.client.post(this.endpoint, data);
|
|
37
|
-
} catch (error: unknown) {
|
|
38
|
-
if (axios.isAxiosError(error)) {
|
|
39
|
-
if (error.response) {
|
|
40
|
-
// HTTP error (4xx/5xx) - do not retry
|
|
41
|
-
throw `${error.response.status}: ${JSON.stringify(error.response.data)}`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Network error (no response) - retry if attempts remain
|
|
45
|
-
if (attempt < retries) {
|
|
46
|
-
await this.delay(attempt * 1000);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Exhausted retries for network error
|
|
51
|
-
throw `Network error: ${error.message}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Non-axios error - do not retry
|
|
55
|
-
throw `Request setup error: ${error instanceof Error ? error.message : String(error)}`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
throw 'Unexpected: retry loop exited without returning or throwing';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private delay(ms: number): Promise<void> {
|
|
63
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
64
|
-
}
|
|
65
34
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import glob from 'fast-glob';
|
|
2
2
|
import { existsSync, readFileSync, unlinkSync } from 'fs';
|
|
3
3
|
import { resolve } from 'path';
|
|
4
|
+
import { OutputOptions } from 'rollup';
|
|
4
5
|
import { Plugin, ResolvedConfig, UserConfig } from 'vite';
|
|
5
6
|
|
|
6
7
|
import FlareApi from './flareApi';
|
|
@@ -65,7 +66,7 @@ export default function flareSourcemapUploader({
|
|
|
65
66
|
base += base.endsWith('/') ? '' : '/';
|
|
66
67
|
},
|
|
67
68
|
|
|
68
|
-
async writeBundle(outputConfig:
|
|
69
|
+
async writeBundle(outputConfig: OutputOptions) {
|
|
69
70
|
if (!enableUploadingSourcemaps) {
|
|
70
71
|
return;
|
|
71
72
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
let fast_glob = require("fast-glob");
|
|
29
|
-
fast_glob = __toESM(fast_glob);
|
|
30
|
-
let fs = require("fs");
|
|
31
|
-
let path = require("path");
|
|
32
|
-
let axios = require("axios");
|
|
33
|
-
axios = __toESM(axios);
|
|
34
|
-
let https = require("https");
|
|
35
|
-
https = __toESM(https);
|
|
36
|
-
let zlib = require("zlib");
|
|
37
|
-
|
|
38
|
-
//#region src/flareApi.ts
|
|
39
|
-
var FlareApi = class {
|
|
40
|
-
endpoint;
|
|
41
|
-
key;
|
|
42
|
-
version;
|
|
43
|
-
client;
|
|
44
|
-
constructor(endpoint, key, version) {
|
|
45
|
-
this.endpoint = endpoint;
|
|
46
|
-
this.key = key;
|
|
47
|
-
this.version = version;
|
|
48
|
-
this.client = axios.default.create({ httpsAgent: new https.default.Agent({ keepAlive: false }) });
|
|
49
|
-
}
|
|
50
|
-
uploadSourcemap(sourcemap) {
|
|
51
|
-
const base64GzipSourcemap = (0, zlib.deflateRawSync)(sourcemap.content).toString("base64");
|
|
52
|
-
return this.postWithRetry({
|
|
53
|
-
key: this.key,
|
|
54
|
-
version_id: this.version,
|
|
55
|
-
relative_filename: sourcemap.original_file,
|
|
56
|
-
sourcemap: base64GzipSourcemap
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
async postWithRetry(data, retries = 3) {
|
|
60
|
-
for (let attempt = 1; attempt <= retries; attempt++) try {
|
|
61
|
-
return await this.client.post(this.endpoint, data);
|
|
62
|
-
} catch (error) {
|
|
63
|
-
if (axios.default.isAxiosError(error)) {
|
|
64
|
-
if (error.response) throw `${error.response.status}: ${JSON.stringify(error.response.data)}`;
|
|
65
|
-
if (attempt < retries) {
|
|
66
|
-
await this.delay(attempt * 1e3);
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
throw `Network error: ${error.message}`;
|
|
70
|
-
}
|
|
71
|
-
throw `Request setup error: ${error instanceof Error ? error.message : String(error)}`;
|
|
72
|
-
}
|
|
73
|
-
throw "Unexpected: retry loop exited without returning or throwing";
|
|
74
|
-
}
|
|
75
|
-
delay(ms) {
|
|
76
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/util.ts
|
|
82
|
-
function uuid() {
|
|
83
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
84
|
-
const r = Math.random() * 16 | 0;
|
|
85
|
-
return (c == "x" ? r : r & 3 | 8).toString(16);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/index.ts
|
|
91
|
-
function flareSourcemapUploader({ key, base, apiEndpoint = "https://flareapp.io/api/sourcemaps", runInDevelopment = false, version = uuid(), removeSourcemaps = false }) {
|
|
92
|
-
if (!key) flareLog("No Flare API key was provided, not uploading sourcemaps to Flare.");
|
|
93
|
-
const flare = new FlareApi(apiEndpoint, key, version);
|
|
94
|
-
const enableUploadingSourcemaps = key && (process.env.NODE_ENV !== "development" || runInDevelopment) && process.env.SKIP_SOURCEMAPS !== "true";
|
|
95
|
-
return {
|
|
96
|
-
name: "flare-vite-plugin",
|
|
97
|
-
apply: "build",
|
|
98
|
-
config({ build }, { mode }) {
|
|
99
|
-
return {
|
|
100
|
-
define: {
|
|
101
|
-
FLARE_SOURCEMAP_VERSION: `'${version}'`,
|
|
102
|
-
FLARE_JS_KEY: `'${key}'`
|
|
103
|
-
},
|
|
104
|
-
build: { sourcemap: (() => {
|
|
105
|
-
if (build?.sourcemap !== void 0) return build.sourcemap;
|
|
106
|
-
if (enableUploadingSourcemaps && mode !== "development") return "hidden";
|
|
107
|
-
return false;
|
|
108
|
-
})() }
|
|
109
|
-
};
|
|
110
|
-
},
|
|
111
|
-
configResolved(config) {
|
|
112
|
-
base = base || config.base;
|
|
113
|
-
base += base.endsWith("/") ? "" : "/";
|
|
114
|
-
},
|
|
115
|
-
async writeBundle(outputConfig) {
|
|
116
|
-
if (!enableUploadingSourcemaps) return;
|
|
117
|
-
const outputDir = outputConfig.dir || "";
|
|
118
|
-
const sourcemaps = (await (0, fast_glob.default)("./**/*.map", { cwd: outputDir })).map((file) => {
|
|
119
|
-
const sourcePath = file.replace(/\.map$/, "");
|
|
120
|
-
if (!(0, fs.existsSync)((0, path.resolve)(outputDir, sourcePath))) {
|
|
121
|
-
flareLog(`no corresponding source found for "${file}"`, true);
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
const sourcemapLocation = (0, path.resolve)(outputDir, file);
|
|
125
|
-
try {
|
|
126
|
-
return {
|
|
127
|
-
content: (0, fs.readFileSync)(sourcemapLocation, "utf8"),
|
|
128
|
-
sourcemap_url: sourcemapLocation,
|
|
129
|
-
original_file: `${base}${sourcePath}`
|
|
130
|
-
};
|
|
131
|
-
} catch (error) {
|
|
132
|
-
flareLog("Error reading sourcemap file " + sourcemapLocation + ": " + error, true);
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
}).filter((sourcemap) => sourcemap !== null);
|
|
136
|
-
if (!sourcemaps.length) return;
|
|
137
|
-
flareLog(`Uploading ${sourcemaps.length} sourcemap files to Flare.`);
|
|
138
|
-
const pendingUploads = sourcemaps.map((sourcemap) => () => flare.uploadSourcemap(sourcemap));
|
|
139
|
-
try {
|
|
140
|
-
while (pendingUploads.length) await Promise.all(pendingUploads.splice(0, 10).map((f) => f()));
|
|
141
|
-
flareLog("Successfully uploaded sourcemaps to Flare.");
|
|
142
|
-
} catch (error) {
|
|
143
|
-
flareLog(`Something went wrong while uploading the sourcemaps to Flare: ${error}`, true);
|
|
144
|
-
}
|
|
145
|
-
if (removeSourcemaps) {
|
|
146
|
-
sourcemaps.forEach(({ sourcemap_url }) => {
|
|
147
|
-
try {
|
|
148
|
-
(0, fs.unlinkSync)(sourcemap_url);
|
|
149
|
-
} catch (error) {
|
|
150
|
-
console.error("Error removing sourcemap file", sourcemap_url, ": ", error);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
flareLog("Successfully removed sourcemaps.");
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
function flareLog(message, isError = false) {
|
|
159
|
-
const formattedMessage = "@flareapp/vite: " + message;
|
|
160
|
-
if (isError) {
|
|
161
|
-
console.error(formattedMessage);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
console.log(formattedMessage);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
//#endregion
|
|
168
|
-
module.exports = flareSourcemapUploader;
|
package/dist/index.d.cts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "vite";
|
|
2
|
-
|
|
3
|
-
//#region src/index.d.ts
|
|
4
|
-
type PluginConfig = {
|
|
5
|
-
key: string;
|
|
6
|
-
base?: string;
|
|
7
|
-
apiEndpoint?: string;
|
|
8
|
-
runInDevelopment?: boolean;
|
|
9
|
-
version?: string;
|
|
10
|
-
removeSourcemaps?: boolean;
|
|
11
|
-
};
|
|
12
|
-
type Sourcemap = {
|
|
13
|
-
original_file: string;
|
|
14
|
-
content: string;
|
|
15
|
-
sourcemap_url: string;
|
|
16
|
-
};
|
|
17
|
-
declare function flareSourcemapUploader({
|
|
18
|
-
key,
|
|
19
|
-
base,
|
|
20
|
-
apiEndpoint,
|
|
21
|
-
runInDevelopment,
|
|
22
|
-
version,
|
|
23
|
-
removeSourcemaps
|
|
24
|
-
}: PluginConfig): Plugin;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { PluginConfig, Sourcemap, flareSourcemapUploader as default };
|