@flareapp/vite 1.0.3 → 1.1.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/dist/index.cjs ADDED
@@ -0,0 +1,168 @@
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;
@@ -0,0 +1,26 @@
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 };
package/dist/index.d.mts CHANGED
@@ -1,18 +1,26 @@
1
- import { Plugin } from 'vite';
1
+ import { Plugin } from "vite";
2
2
 
3
+ //#region src/index.d.ts
3
4
  type PluginConfig = {
4
- key: string;
5
- base?: string;
6
- apiEndpoint?: string;
7
- runInDevelopment?: boolean;
8
- version?: string;
9
- removeSourcemaps?: boolean;
5
+ key: string;
6
+ base?: string;
7
+ apiEndpoint?: string;
8
+ runInDevelopment?: boolean;
9
+ version?: string;
10
+ removeSourcemaps?: boolean;
10
11
  };
11
12
  type Sourcemap = {
12
- original_file: string;
13
- content: string;
14
- sourcemap_url: string;
13
+ original_file: string;
14
+ content: string;
15
+ sourcemap_url: string;
15
16
  };
16
- declare function flareSourcemapUploader({ key, base, apiEndpoint, runInDevelopment, version, removeSourcemaps, }: PluginConfig): Plugin;
17
-
18
- export { type PluginConfig, type Sourcemap, flareSourcemapUploader as default };
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 };
package/dist/index.mjs CHANGED
@@ -1,161 +1,138 @@
1
- // src/index.ts
2
1
  import glob from "fast-glob";
3
2
  import { existsSync, readFileSync, unlinkSync } from "fs";
4
3
  import { resolve } from "path";
5
-
6
- // src/flareApi.ts
7
4
  import axios from "axios";
8
5
  import https from "https";
9
6
  import { deflateRawSync } from "zlib";
7
+
8
+ //#region src/flareApi.ts
10
9
  var FlareApi = class {
11
- constructor(endpoint, key, version) {
12
- this.endpoint = endpoint;
13
- this.key = key;
14
- this.version = version;
15
- this.client = axios.create({
16
- httpsAgent: new https.Agent({ keepAlive: false })
17
- });
18
- }
19
- uploadSourcemap(sourcemap) {
20
- const base64GzipSourcemap = deflateRawSync(sourcemap.content).toString("base64");
21
- return this.postWithRetry({
22
- key: this.key,
23
- version_id: this.version,
24
- relative_filename: sourcemap.original_file,
25
- sourcemap: base64GzipSourcemap
26
- });
27
- }
28
- async postWithRetry(data, retries = 3) {
29
- for (let attempt = 1; attempt <= retries; attempt++) {
30
- try {
31
- return await this.client.post(this.endpoint, data);
32
- } catch (error) {
33
- if (axios.isAxiosError(error)) {
34
- if (error.response) {
35
- throw `${error.response.status}: ${JSON.stringify(error.response.data)}`;
36
- }
37
- if (attempt < retries) {
38
- await this.delay(attempt * 1e3);
39
- continue;
40
- }
41
- throw `Network error: ${error.message}`;
42
- }
43
- throw `Request setup error: ${error instanceof Error ? error.message : String(error)}`;
44
- }
45
- }
46
- throw "Unexpected: retry loop exited without returning or throwing";
47
- }
48
- delay(ms) {
49
- return new Promise((resolve2) => setTimeout(resolve2, ms));
50
- }
10
+ endpoint;
11
+ key;
12
+ version;
13
+ client;
14
+ constructor(endpoint, key, version) {
15
+ this.endpoint = endpoint;
16
+ this.key = key;
17
+ this.version = version;
18
+ this.client = axios.create({ httpsAgent: new https.Agent({ keepAlive: false }) });
19
+ }
20
+ uploadSourcemap(sourcemap) {
21
+ const base64GzipSourcemap = deflateRawSync(sourcemap.content).toString("base64");
22
+ return this.postWithRetry({
23
+ key: this.key,
24
+ version_id: this.version,
25
+ relative_filename: sourcemap.original_file,
26
+ sourcemap: base64GzipSourcemap
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
+ }
51
48
  };
52
49
 
53
- // src/util.ts
50
+ //#endregion
51
+ //#region src/util.ts
54
52
  function uuid() {
55
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
56
- const r = Math.random() * 16 | 0;
57
- const v = c == "x" ? r : r & 3 | 8;
58
- return v.toString(16);
59
- });
53
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
54
+ const r = Math.random() * 16 | 0;
55
+ return (c == "x" ? r : r & 3 | 8).toString(16);
56
+ });
60
57
  }
61
58
 
62
- // src/index.ts
63
- function flareSourcemapUploader({
64
- key,
65
- base,
66
- apiEndpoint = "https://flareapp.io/api/sourcemaps",
67
- runInDevelopment = false,
68
- version = uuid(),
69
- removeSourcemaps = false
70
- }) {
71
- if (!key) {
72
- flareLog("No Flare API key was provided, not uploading sourcemaps to Flare.");
73
- }
74
- const flare = new FlareApi(apiEndpoint, key, version);
75
- const enableUploadingSourcemaps = key && (process.env.NODE_ENV !== "development" || runInDevelopment) && process.env.SKIP_SOURCEMAPS !== "true";
76
- return {
77
- name: "flare-vite-plugin",
78
- apply: "build",
79
- config({ build }, { mode }) {
80
- return {
81
- // Set FLARE_SOURCEMAP_VERSION and API key so the Flare JS client can read it
82
- define: {
83
- FLARE_SOURCEMAP_VERSION: `'${version}'`,
84
- FLARE_JS_KEY: `'${key}'`
85
- },
86
- build: {
87
- sourcemap: (() => {
88
- if (build?.sourcemap !== void 0) return build.sourcemap;
89
- const enableSourcemaps = enableUploadingSourcemaps && mode !== "development";
90
- if (enableSourcemaps) return "hidden";
91
- return false;
92
- })()
93
- }
94
- };
95
- },
96
- configResolved(config) {
97
- base = base || config.base;
98
- base += base.endsWith("/") ? "" : "/";
99
- },
100
- async writeBundle(outputConfig) {
101
- if (!enableUploadingSourcemaps) {
102
- return;
103
- }
104
- const outputDir = outputConfig.dir || "";
105
- const files = await glob("./**/*.map", { cwd: outputDir });
106
- const sourcemaps = files.map((file) => {
107
- const sourcePath = file.replace(/\.map$/, "");
108
- const sourceFilename = resolve(outputDir, sourcePath);
109
- if (!existsSync(sourceFilename)) {
110
- flareLog(`no corresponding source found for "${file}"`, true);
111
- return null;
112
- }
113
- const sourcemapLocation = resolve(outputDir, file);
114
- try {
115
- return {
116
- content: readFileSync(sourcemapLocation, "utf8"),
117
- sourcemap_url: sourcemapLocation,
118
- original_file: `${base}${sourcePath}`
119
- };
120
- } catch (error) {
121
- flareLog("Error reading sourcemap file " + sourcemapLocation + ": " + error, true);
122
- return null;
123
- }
124
- }).filter((sourcemap) => sourcemap !== null);
125
- if (!sourcemaps.length) {
126
- return;
127
- }
128
- flareLog(`Uploading ${sourcemaps.length} sourcemap files to Flare.`);
129
- const pendingUploads = sourcemaps.map((sourcemap) => () => flare.uploadSourcemap(sourcemap));
130
- try {
131
- while (pendingUploads.length) {
132
- await Promise.all(pendingUploads.splice(0, 10).map((f) => f()));
133
- }
134
- flareLog("Successfully uploaded sourcemaps to Flare.");
135
- } catch (error) {
136
- flareLog(`Something went wrong while uploading the sourcemaps to Flare: ${error}`, true);
137
- }
138
- if (removeSourcemaps) {
139
- sourcemaps.forEach(({ sourcemap_url }) => {
140
- try {
141
- unlinkSync(sourcemap_url);
142
- } catch (error) {
143
- console.error("Error removing sourcemap file", sourcemap_url, ": ", error);
144
- }
145
- });
146
- flareLog("Successfully removed sourcemaps.");
147
- }
148
- }
149
- };
59
+ //#endregion
60
+ //#region src/index.ts
61
+ function flareSourcemapUploader({ key, base, apiEndpoint = "https://flareapp.io/api/sourcemaps", runInDevelopment = false, version = uuid(), removeSourcemaps = false }) {
62
+ if (!key) flareLog("No Flare API key was provided, not uploading sourcemaps to Flare.");
63
+ const flare = new FlareApi(apiEndpoint, key, version);
64
+ const enableUploadingSourcemaps = key && (process.env.NODE_ENV !== "development" || runInDevelopment) && process.env.SKIP_SOURCEMAPS !== "true";
65
+ return {
66
+ name: "flare-vite-plugin",
67
+ apply: "build",
68
+ config({ build }, { mode }) {
69
+ return {
70
+ define: {
71
+ FLARE_SOURCEMAP_VERSION: `'${version}'`,
72
+ FLARE_JS_KEY: `'${key}'`
73
+ },
74
+ build: { sourcemap: (() => {
75
+ if (build?.sourcemap !== void 0) return build.sourcemap;
76
+ if (enableUploadingSourcemaps && mode !== "development") return "hidden";
77
+ return false;
78
+ })() }
79
+ };
80
+ },
81
+ configResolved(config) {
82
+ base = base || config.base;
83
+ base += base.endsWith("/") ? "" : "/";
84
+ },
85
+ async writeBundle(outputConfig) {
86
+ if (!enableUploadingSourcemaps) return;
87
+ const outputDir = outputConfig.dir || "";
88
+ const sourcemaps = (await glob("./**/*.map", { cwd: outputDir })).map((file) => {
89
+ const sourcePath = file.replace(/\.map$/, "");
90
+ if (!existsSync(resolve(outputDir, sourcePath))) {
91
+ flareLog(`no corresponding source found for "${file}"`, true);
92
+ return null;
93
+ }
94
+ const sourcemapLocation = resolve(outputDir, file);
95
+ try {
96
+ return {
97
+ content: readFileSync(sourcemapLocation, "utf8"),
98
+ sourcemap_url: sourcemapLocation,
99
+ original_file: `${base}${sourcePath}`
100
+ };
101
+ } catch (error) {
102
+ flareLog("Error reading sourcemap file " + sourcemapLocation + ": " + error, true);
103
+ return null;
104
+ }
105
+ }).filter((sourcemap) => sourcemap !== null);
106
+ if (!sourcemaps.length) return;
107
+ flareLog(`Uploading ${sourcemaps.length} sourcemap files to Flare.`);
108
+ const pendingUploads = sourcemaps.map((sourcemap) => () => flare.uploadSourcemap(sourcemap));
109
+ try {
110
+ while (pendingUploads.length) await Promise.all(pendingUploads.splice(0, 10).map((f) => f()));
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
+ };
150
127
  }
151
128
  function flareLog(message, isError = false) {
152
- const formattedMessage = "@flareapp/vite: " + message;
153
- if (isError) {
154
- console.error(formattedMessage);
155
- return;
156
- }
157
- console.log(formattedMessage);
129
+ const formattedMessage = "@flareapp/vite: " + message;
130
+ if (isError) {
131
+ console.error(formattedMessage);
132
+ return;
133
+ }
134
+ console.log(formattedMessage);
158
135
  }
159
- export {
160
- flareSourcemapUploader as default
161
- };
136
+
137
+ //#endregion
138
+ export { flareSourcemapUploader as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flareapp/vite",
3
- "version": "1.0.3",
3
+ "version": "1.1.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,18 +10,24 @@
10
10
  },
11
11
  "license": "MIT",
12
12
  "author": "adriaan@spatie.be",
13
- "main": "./dist/index.js",
13
+ "main": "./dist/index.cjs",
14
14
  "module": "./dist/index.mjs",
15
- "types": "./dist/index.d.ts",
15
+ "types": "./dist/index.d.cts",
16
16
  "exports": {
17
17
  ".": {
18
- "require": "./dist/index.js",
19
- "import": "./dist/index.mjs"
18
+ "import": {
19
+ "types": "./dist/index.d.mts",
20
+ "default": "./dist/index.mjs"
21
+ },
22
+ "require": {
23
+ "types": "./dist/index.d.cts",
24
+ "default": "./dist/index.cjs"
25
+ }
20
26
  }
21
27
  },
22
28
  "scripts": {
23
29
  "prepublishOnly": "npm run build",
24
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
30
+ "build": "tsdown src/index.ts --format cjs,esm --dts --clean",
25
31
  "typescript": "tsc"
26
32
  },
27
33
  "dependencies": {
@@ -29,12 +35,12 @@
29
35
  "fast-glob": "^3.2.12"
30
36
  },
31
37
  "devDependencies": {
32
- "@types/node": "^18.11.17",
33
- "typescript": "^5.3.3",
34
- "vite": "^4.0.0||^5.0.0||^6.0.0||^7.0.0"
38
+ "tsdown": "^0.20.3",
39
+ "typescript": "^5.7.0",
40
+ "vite": "^4.0.0||^5.0.0||^6.0.0||^7.0.0||^8.0.0"
35
41
  },
36
42
  "peerDependencies": {
37
- "vite": "^4.0.0||^5.0.0||^6.0.0||^7.0.0"
43
+ "vite": "^4.0.0||^5.0.0||^6.0.0||^7.0.0||^8.0.0"
38
44
  },
39
45
  "publishConfig": {
40
46
  "access": "public"
package/src/index.ts CHANGED
@@ -1,7 +1,6 @@
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';
5
4
  import { Plugin, ResolvedConfig, UserConfig } from 'vite';
6
5
 
7
6
  import FlareApi from './flareApi';
@@ -66,7 +65,7 @@ export default function flareSourcemapUploader({
66
65
  base += base.endsWith('/') ? '' : '/';
67
66
  },
68
67
 
69
- async writeBundle(outputConfig: OutputOptions) {
68
+ async writeBundle(outputConfig: { dir?: string }) {
70
69
  if (!enableUploadingSourcemaps) {
71
70
  return;
72
71
  }
package/dist/index.d.ts DELETED
@@ -1,18 +0,0 @@
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 DELETED
@@ -1,192 +0,0 @@
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_https = __toESM(require("https"));
43
- var import_zlib = require("zlib");
44
- var FlareApi = class {
45
- constructor(endpoint, key, version) {
46
- this.endpoint = endpoint;
47
- this.key = key;
48
- this.version = version;
49
- this.client = import_axios.default.create({
50
- httpsAgent: new import_https.default.Agent({ keepAlive: false })
51
- });
52
- }
53
- uploadSourcemap(sourcemap) {
54
- const base64GzipSourcemap = (0, import_zlib.deflateRawSync)(sourcemap.content).toString("base64");
55
- return this.postWithRetry({
56
- key: this.key,
57
- version_id: this.version,
58
- relative_filename: sourcemap.original_file,
59
- sourcemap: base64GzipSourcemap
60
- });
61
- }
62
- async postWithRetry(data, retries = 3) {
63
- for (let attempt = 1; attempt <= retries; attempt++) {
64
- try {
65
- return await this.client.post(this.endpoint, data);
66
- } catch (error) {
67
- if (import_axios.default.isAxiosError(error)) {
68
- if (error.response) {
69
- throw `${error.response.status}: ${JSON.stringify(error.response.data)}`;
70
- }
71
- if (attempt < retries) {
72
- await this.delay(attempt * 1e3);
73
- continue;
74
- }
75
- throw `Network error: ${error.message}`;
76
- }
77
- throw `Request setup error: ${error instanceof Error ? error.message : String(error)}`;
78
- }
79
- }
80
- throw "Unexpected: retry loop exited without returning or throwing";
81
- }
82
- delay(ms) {
83
- return new Promise((resolve2) => setTimeout(resolve2, ms));
84
- }
85
- };
86
-
87
- // src/util.ts
88
- function uuid() {
89
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
90
- const r = Math.random() * 16 | 0;
91
- const v = c == "x" ? r : r & 3 | 8;
92
- return v.toString(16);
93
- });
94
- }
95
-
96
- // src/index.ts
97
- function flareSourcemapUploader({
98
- key,
99
- base,
100
- apiEndpoint = "https://flareapp.io/api/sourcemaps",
101
- runInDevelopment = false,
102
- version = uuid(),
103
- removeSourcemaps = false
104
- }) {
105
- if (!key) {
106
- flareLog("No Flare API key was provided, not uploading sourcemaps to Flare.");
107
- }
108
- const flare = new FlareApi(apiEndpoint, key, version);
109
- const enableUploadingSourcemaps = key && (process.env.NODE_ENV !== "development" || runInDevelopment) && process.env.SKIP_SOURCEMAPS !== "true";
110
- return {
111
- name: "flare-vite-plugin",
112
- apply: "build",
113
- config({ build }, { mode }) {
114
- return {
115
- // Set FLARE_SOURCEMAP_VERSION and API key so the Flare JS client can read it
116
- define: {
117
- FLARE_SOURCEMAP_VERSION: `'${version}'`,
118
- FLARE_JS_KEY: `'${key}'`
119
- },
120
- build: {
121
- sourcemap: (() => {
122
- if (build?.sourcemap !== void 0) return build.sourcemap;
123
- const enableSourcemaps = enableUploadingSourcemaps && mode !== "development";
124
- if (enableSourcemaps) return "hidden";
125
- return false;
126
- })()
127
- }
128
- };
129
- },
130
- configResolved(config) {
131
- base = base || config.base;
132
- base += base.endsWith("/") ? "" : "/";
133
- },
134
- async writeBundle(outputConfig) {
135
- if (!enableUploadingSourcemaps) {
136
- return;
137
- }
138
- const outputDir = outputConfig.dir || "";
139
- const files = await (0, import_fast_glob.default)("./**/*.map", { cwd: outputDir });
140
- const sourcemaps = files.map((file) => {
141
- const sourcePath = file.replace(/\.map$/, "");
142
- const sourceFilename = (0, import_path.resolve)(outputDir, sourcePath);
143
- if (!(0, import_fs.existsSync)(sourceFilename)) {
144
- flareLog(`no corresponding source found for "${file}"`, true);
145
- return null;
146
- }
147
- const sourcemapLocation = (0, import_path.resolve)(outputDir, file);
148
- try {
149
- return {
150
- content: (0, import_fs.readFileSync)(sourcemapLocation, "utf8"),
151
- sourcemap_url: sourcemapLocation,
152
- original_file: `${base}${sourcePath}`
153
- };
154
- } catch (error) {
155
- flareLog("Error reading sourcemap file " + sourcemapLocation + ": " + error, true);
156
- return null;
157
- }
158
- }).filter((sourcemap) => sourcemap !== null);
159
- if (!sourcemaps.length) {
160
- return;
161
- }
162
- flareLog(`Uploading ${sourcemaps.length} sourcemap files to Flare.`);
163
- const pendingUploads = sourcemaps.map((sourcemap) => () => flare.uploadSourcemap(sourcemap));
164
- try {
165
- while (pendingUploads.length) {
166
- await Promise.all(pendingUploads.splice(0, 10).map((f) => f()));
167
- }
168
- flareLog("Successfully uploaded sourcemaps to Flare.");
169
- } catch (error) {
170
- flareLog(`Something went wrong while uploading the sourcemaps to Flare: ${error}`, true);
171
- }
172
- if (removeSourcemaps) {
173
- sourcemaps.forEach(({ sourcemap_url }) => {
174
- try {
175
- (0, import_fs.unlinkSync)(sourcemap_url);
176
- } catch (error) {
177
- console.error("Error removing sourcemap file", sourcemap_url, ": ", error);
178
- }
179
- });
180
- flareLog("Successfully removed sourcemaps.");
181
- }
182
- }
183
- };
184
- }
185
- function flareLog(message, isError = false) {
186
- const formattedMessage = "@flareapp/vite: " + message;
187
- if (isError) {
188
- console.error(formattedMessage);
189
- return;
190
- }
191
- console.log(formattedMessage);
192
- }