@flareapp/vite 1.0.0 → 1.0.2

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.js CHANGED
@@ -28,30 +28,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  default: () => flareSourcemapUploader
34
34
  });
35
- module.exports = __toCommonJS(src_exports);
36
- var import_path = require("path");
37
- var import_fs = require("fs");
35
+ module.exports = __toCommonJS(index_exports);
38
36
  var import_fast_glob = __toESM(require("fast-glob"));
39
-
40
- // src/util.ts
41
- function uuid() {
42
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
43
- /[xy]/g,
44
- function(c) {
45
- const r = Math.random() * 16 | 0;
46
- const v = c == "x" ? r : r & 3 | 8;
47
- return v.toString(16);
48
- }
49
- );
50
- }
37
+ var import_fs = require("fs");
38
+ var import_path = require("path");
51
39
 
52
40
  // src/flareApi.ts
53
- var import_zlib = require("zlib");
54
41
  var import_axios = __toESM(require("axios"));
42
+ var import_zlib = require("zlib");
55
43
  var FlareApi = class {
56
44
  constructor(endpoint, key, version) {
57
45
  this.endpoint = endpoint;
@@ -60,25 +48,28 @@ var FlareApi = class {
60
48
  }
61
49
  uploadSourcemap(sourcemap) {
62
50
  return new Promise((resolve2, reject) => {
63
- const base64GzipSourcemap = (0, import_zlib.deflateRawSync)(
64
- sourcemap.content
65
- ).toString("base64");
51
+ const base64GzipSourcemap = (0, import_zlib.deflateRawSync)(sourcemap.content).toString("base64");
66
52
  import_axios.default.post(this.endpoint, {
67
53
  key: this.key,
68
54
  version_id: this.version,
69
55
  relative_filename: sourcemap.original_file,
70
56
  sourcemap: base64GzipSourcemap
71
57
  }).then(resolve2).catch((error) => {
72
- return reject(
73
- `${error.response.status}: ${JSON.stringify(
74
- error.response.data
75
- )}`
76
- );
58
+ return reject(`${error.response.status}: ${JSON.stringify(error.response.data)}`);
77
59
  });
78
60
  });
79
61
  }
80
62
  };
81
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
+
82
73
  // src/index.ts
83
74
  function flareSourcemapUploader({
84
75
  key,
@@ -89,9 +80,7 @@ function flareSourcemapUploader({
89
80
  removeSourcemaps = false
90
81
  }) {
91
82
  if (!key) {
92
- flareLog(
93
- "No Flare API key was provided, not uploading sourcemaps to Flare."
94
- );
83
+ flareLog("No Flare API key was provided, not uploading sourcemaps to Flare.");
95
84
  }
96
85
  const flare = new FlareApi(apiEndpoint, key, version);
97
86
  const enableUploadingSourcemaps = key && (process.env.NODE_ENV !== "development" || runInDevelopment) && process.env.SKIP_SOURCEMAPS !== "true";
@@ -107,11 +96,9 @@ function flareSourcemapUploader({
107
96
  },
108
97
  build: {
109
98
  sourcemap: (() => {
110
- if (build?.sourcemap !== void 0)
111
- return build.sourcemap;
99
+ if (build?.sourcemap !== void 0) return build.sourcemap;
112
100
  const enableSourcemaps = enableUploadingSourcemaps && mode !== "development";
113
- if (enableSourcemaps)
114
- return "hidden";
101
+ if (enableSourcemaps) return "hidden";
115
102
  return false;
116
103
  })()
117
104
  }
@@ -131,10 +118,7 @@ function flareSourcemapUploader({
131
118
  const sourcePath = file.replace(/\.map$/, "");
132
119
  const sourceFilename = (0, import_path.resolve)(outputDir, sourcePath);
133
120
  if (!(0, import_fs.existsSync)(sourceFilename)) {
134
- flareLog(
135
- `no corresponding source found for "${file}"`,
136
- true
137
- );
121
+ flareLog(`no corresponding source found for "${file}"`, true);
138
122
  return null;
139
123
  }
140
124
  const sourcemapLocation = (0, import_path.resolve)(outputDir, file);
@@ -145,46 +129,29 @@ function flareSourcemapUploader({
145
129
  original_file: `${base}${sourcePath}`
146
130
  };
147
131
  } catch (error) {
148
- flareLog(
149
- "Error reading sourcemap file " + sourcemapLocation + ": " + error,
150
- true
151
- );
132
+ flareLog("Error reading sourcemap file " + sourcemapLocation + ": " + error, true);
152
133
  return null;
153
134
  }
154
135
  }).filter((sourcemap) => sourcemap !== null);
155
136
  if (!sourcemaps.length) {
156
137
  return;
157
138
  }
158
- flareLog(
159
- `Uploading ${sourcemaps.length} sourcemap files to Flare.`
160
- );
161
- const pendingUploads = sourcemaps.map(
162
- (sourcemap) => () => flare.uploadSourcemap(sourcemap)
163
- );
139
+ flareLog(`Uploading ${sourcemaps.length} sourcemap files to Flare.`);
140
+ const pendingUploads = sourcemaps.map((sourcemap) => () => flare.uploadSourcemap(sourcemap));
164
141
  try {
165
142
  while (pendingUploads.length) {
166
- await Promise.all(
167
- pendingUploads.splice(0, 10).map((f) => f())
168
- );
143
+ await Promise.all(pendingUploads.splice(0, 10).map((f) => f()));
169
144
  }
170
145
  flareLog("Successfully uploaded sourcemaps to Flare.");
171
146
  } catch (error) {
172
- flareLog(
173
- `Something went wrong while uploading the sourcemaps to Flare: ${error}`,
174
- true
175
- );
147
+ flareLog(`Something went wrong while uploading the sourcemaps to Flare: ${error}`, true);
176
148
  }
177
149
  if (removeSourcemaps) {
178
150
  sourcemaps.forEach(({ sourcemap_url }) => {
179
151
  try {
180
152
  (0, import_fs.unlinkSync)(sourcemap_url);
181
153
  } catch (error) {
182
- console.error(
183
- "Error removing sourcemap file",
184
- sourcemap_url,
185
- ": ",
186
- error
187
- );
154
+ console.error("Error removing sourcemap file", sourcemap_url, ": ", error);
188
155
  }
189
156
  });
190
157
  flareLog("Successfully removed sourcemaps.");
package/dist/index.mjs CHANGED
@@ -1,23 +1,11 @@
1
1
  // src/index.ts
2
- import { resolve } from "path";
3
- import { existsSync, readFileSync, unlinkSync } from "fs";
4
2
  import glob from "fast-glob";
5
-
6
- // src/util.ts
7
- function uuid() {
8
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
9
- /[xy]/g,
10
- function(c) {
11
- const r = Math.random() * 16 | 0;
12
- const v = c == "x" ? r : r & 3 | 8;
13
- return v.toString(16);
14
- }
15
- );
16
- }
3
+ import { existsSync, readFileSync, unlinkSync } from "fs";
4
+ import { resolve } from "path";
17
5
 
18
6
  // src/flareApi.ts
19
- import { deflateRawSync } from "zlib";
20
7
  import axios from "axios";
8
+ import { deflateRawSync } from "zlib";
21
9
  var FlareApi = class {
22
10
  constructor(endpoint, key, version) {
23
11
  this.endpoint = endpoint;
@@ -26,25 +14,28 @@ var FlareApi = class {
26
14
  }
27
15
  uploadSourcemap(sourcemap) {
28
16
  return new Promise((resolve2, reject) => {
29
- const base64GzipSourcemap = deflateRawSync(
30
- sourcemap.content
31
- ).toString("base64");
17
+ const base64GzipSourcemap = deflateRawSync(sourcemap.content).toString("base64");
32
18
  axios.post(this.endpoint, {
33
19
  key: this.key,
34
20
  version_id: this.version,
35
21
  relative_filename: sourcemap.original_file,
36
22
  sourcemap: base64GzipSourcemap
37
23
  }).then(resolve2).catch((error) => {
38
- return reject(
39
- `${error.response.status}: ${JSON.stringify(
40
- error.response.data
41
- )}`
42
- );
24
+ return reject(`${error.response.status}: ${JSON.stringify(error.response.data)}`);
43
25
  });
44
26
  });
45
27
  }
46
28
  };
47
29
 
30
+ // src/util.ts
31
+ function uuid() {
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
+ });
37
+ }
38
+
48
39
  // src/index.ts
49
40
  function flareSourcemapUploader({
50
41
  key,
@@ -55,9 +46,7 @@ function flareSourcemapUploader({
55
46
  removeSourcemaps = false
56
47
  }) {
57
48
  if (!key) {
58
- flareLog(
59
- "No Flare API key was provided, not uploading sourcemaps to Flare."
60
- );
49
+ flareLog("No Flare API key was provided, not uploading sourcemaps to Flare.");
61
50
  }
62
51
  const flare = new FlareApi(apiEndpoint, key, version);
63
52
  const enableUploadingSourcemaps = key && (process.env.NODE_ENV !== "development" || runInDevelopment) && process.env.SKIP_SOURCEMAPS !== "true";
@@ -73,11 +62,9 @@ function flareSourcemapUploader({
73
62
  },
74
63
  build: {
75
64
  sourcemap: (() => {
76
- if (build?.sourcemap !== void 0)
77
- return build.sourcemap;
65
+ if (build?.sourcemap !== void 0) return build.sourcemap;
78
66
  const enableSourcemaps = enableUploadingSourcemaps && mode !== "development";
79
- if (enableSourcemaps)
80
- return "hidden";
67
+ if (enableSourcemaps) return "hidden";
81
68
  return false;
82
69
  })()
83
70
  }
@@ -97,10 +84,7 @@ function flareSourcemapUploader({
97
84
  const sourcePath = file.replace(/\.map$/, "");
98
85
  const sourceFilename = resolve(outputDir, sourcePath);
99
86
  if (!existsSync(sourceFilename)) {
100
- flareLog(
101
- `no corresponding source found for "${file}"`,
102
- true
103
- );
87
+ flareLog(`no corresponding source found for "${file}"`, true);
104
88
  return null;
105
89
  }
106
90
  const sourcemapLocation = resolve(outputDir, file);
@@ -111,46 +95,29 @@ function flareSourcemapUploader({
111
95
  original_file: `${base}${sourcePath}`
112
96
  };
113
97
  } catch (error) {
114
- flareLog(
115
- "Error reading sourcemap file " + sourcemapLocation + ": " + error,
116
- true
117
- );
98
+ flareLog("Error reading sourcemap file " + sourcemapLocation + ": " + error, true);
118
99
  return null;
119
100
  }
120
101
  }).filter((sourcemap) => sourcemap !== null);
121
102
  if (!sourcemaps.length) {
122
103
  return;
123
104
  }
124
- flareLog(
125
- `Uploading ${sourcemaps.length} sourcemap files to Flare.`
126
- );
127
- const pendingUploads = sourcemaps.map(
128
- (sourcemap) => () => flare.uploadSourcemap(sourcemap)
129
- );
105
+ flareLog(`Uploading ${sourcemaps.length} sourcemap files to Flare.`);
106
+ const pendingUploads = sourcemaps.map((sourcemap) => () => flare.uploadSourcemap(sourcemap));
130
107
  try {
131
108
  while (pendingUploads.length) {
132
- await Promise.all(
133
- pendingUploads.splice(0, 10).map((f) => f())
134
- );
109
+ await Promise.all(pendingUploads.splice(0, 10).map((f) => f()));
135
110
  }
136
111
  flareLog("Successfully uploaded sourcemaps to Flare.");
137
112
  } catch (error) {
138
- flareLog(
139
- `Something went wrong while uploading the sourcemaps to Flare: ${error}`,
140
- true
141
- );
113
+ flareLog(`Something went wrong while uploading the sourcemaps to Flare: ${error}`, true);
142
114
  }
143
115
  if (removeSourcemaps) {
144
116
  sourcemaps.forEach(({ sourcemap_url }) => {
145
117
  try {
146
118
  unlinkSync(sourcemap_url);
147
119
  } catch (error) {
148
- console.error(
149
- "Error removing sourcemap file",
150
- sourcemap_url,
151
- ": ",
152
- error
153
- );
120
+ console.error("Error removing sourcemap file", sourcemap_url, ": ", error);
154
121
  }
155
122
  });
156
123
  flareLog("Successfully removed sourcemaps.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flareapp/vite",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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",
@@ -31,10 +31,10 @@
31
31
  "devDependencies": {
32
32
  "@types/node": "^18.11.17",
33
33
  "typescript": "^5.3.3",
34
- "vite": "^4.0.0||^5.0.0"
34
+ "vite": "^4.0.0||^5.0.0||^6.0.0||^7.0.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "vite": "^4.0.0||^5.0.0"
37
+ "vite": "^4.0.0||^5.0.0||^6.0.0||^7.0.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
package/src/flareApi.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { deflateRawSync } from 'zlib';
2
1
  import axios from 'axios';
2
+ import { deflateRawSync } from 'zlib';
3
+
3
4
  import { Sourcemap } from './index';
4
5
 
5
6
  export default class FlareApi {
@@ -15,9 +16,7 @@ export default class FlareApi {
15
16
 
16
17
  uploadSourcemap(sourcemap: Sourcemap) {
17
18
  return new Promise((resolve, reject) => {
18
- const base64GzipSourcemap = deflateRawSync(
19
- sourcemap.content,
20
- ).toString('base64');
19
+ const base64GzipSourcemap = deflateRawSync(sourcemap.content).toString('base64');
21
20
 
22
21
  axios
23
22
  .post(this.endpoint, {
@@ -28,11 +27,7 @@ export default class FlareApi {
28
27
  })
29
28
  .then(resolve)
30
29
  .catch((error) => {
31
- return reject(
32
- `${error.response.status}: ${JSON.stringify(
33
- error.response.data,
34
- )}`,
35
- );
30
+ return reject(`${error.response.status}: ${JSON.stringify(error.response.data)}`);
36
31
  });
37
32
  });
38
33
  }
package/src/index.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { resolve } from 'path';
2
- import { existsSync, readFileSync, unlinkSync } from 'fs';
3
1
  import glob from 'fast-glob';
4
- import { Plugin, ResolvedConfig, UserConfig } from 'vite';
2
+ import { existsSync, readFileSync, unlinkSync } from 'fs';
3
+ import { resolve } from 'path';
5
4
  import { OutputOptions } from 'rollup';
6
- import { uuid } from './util';
5
+ import { Plugin, ResolvedConfig, UserConfig } from 'vite';
6
+
7
7
  import FlareApi from './flareApi';
8
+ import { uuid } from './util';
8
9
 
9
10
  export type PluginConfig = {
10
11
  key: string;
@@ -30,17 +31,13 @@ export default function flareSourcemapUploader({
30
31
  removeSourcemaps = false,
31
32
  }: PluginConfig): Plugin {
32
33
  if (!key) {
33
- flareLog(
34
- 'No Flare API key was provided, not uploading sourcemaps to Flare.',
35
- );
34
+ flareLog('No Flare API key was provided, not uploading sourcemaps to Flare.');
36
35
  }
37
36
 
38
37
  const flare = new FlareApi(apiEndpoint, key, version);
39
38
 
40
39
  const enableUploadingSourcemaps =
41
- key &&
42
- (process.env.NODE_ENV !== 'development' || runInDevelopment) &&
43
- process.env.SKIP_SOURCEMAPS !== 'true';
40
+ key && (process.env.NODE_ENV !== 'development' || runInDevelopment) && process.env.SKIP_SOURCEMAPS !== 'true';
44
41
 
45
42
  return {
46
43
  name: 'flare-vite-plugin',
@@ -55,10 +52,8 @@ export default function flareSourcemapUploader({
55
52
  },
56
53
  build: {
57
54
  sourcemap: (() => {
58
- if (build?.sourcemap !== undefined)
59
- return build.sourcemap;
60
- const enableSourcemaps =
61
- enableUploadingSourcemaps && mode !== 'development';
55
+ if (build?.sourcemap !== undefined) return build.sourcemap;
56
+ const enableSourcemaps = enableUploadingSourcemaps && mode !== 'development';
62
57
  if (enableSourcemaps) return 'hidden';
63
58
  return false;
64
59
  })(),
@@ -85,10 +80,7 @@ export default function flareSourcemapUploader({
85
80
  const sourceFilename = resolve(outputDir, sourcePath);
86
81
 
87
82
  if (!existsSync(sourceFilename)) {
88
- flareLog(
89
- `no corresponding source found for "${file}"`,
90
- true,
91
- );
83
+ flareLog(`no corresponding source found for "${file}"`, true);
92
84
  return null;
93
85
  }
94
86
 
@@ -101,13 +93,7 @@ export default function flareSourcemapUploader({
101
93
  original_file: `${base}${sourcePath}`,
102
94
  };
103
95
  } catch (error) {
104
- flareLog(
105
- 'Error reading sourcemap file ' +
106
- sourcemapLocation +
107
- ': ' +
108
- error,
109
- true,
110
- );
96
+ flareLog('Error reading sourcemap file ' + sourcemapLocation + ': ' + error, true);
111
97
  return null;
112
98
  }
113
99
  })
@@ -117,28 +103,19 @@ export default function flareSourcemapUploader({
117
103
  return;
118
104
  }
119
105
 
120
- flareLog(
121
- `Uploading ${sourcemaps.length} sourcemap files to Flare.`,
122
- );
106
+ flareLog(`Uploading ${sourcemaps.length} sourcemap files to Flare.`);
123
107
 
124
- const pendingUploads = sourcemaps.map(
125
- (sourcemap) => () => flare.uploadSourcemap(sourcemap),
126
- );
108
+ const pendingUploads = sourcemaps.map((sourcemap) => () => flare.uploadSourcemap(sourcemap));
127
109
 
128
110
  try {
129
111
  while (pendingUploads.length) {
130
112
  // Maximum 10 at once https://stackoverflow.com/a/58686835
131
- await Promise.all(
132
- pendingUploads.splice(0, 10).map((f) => f()),
133
- );
113
+ await Promise.all(pendingUploads.splice(0, 10).map((f) => f()));
134
114
  }
135
115
 
136
116
  flareLog('Successfully uploaded sourcemaps to Flare.');
137
117
  } catch (error) {
138
- flareLog(
139
- `Something went wrong while uploading the sourcemaps to Flare: ${error}`,
140
- true,
141
- );
118
+ flareLog(`Something went wrong while uploading the sourcemaps to Flare: ${error}`, true);
142
119
  }
143
120
 
144
121
  if (removeSourcemaps) {
@@ -146,12 +123,7 @@ export default function flareSourcemapUploader({
146
123
  try {
147
124
  unlinkSync(sourcemap_url);
148
125
  } catch (error) {
149
- console.error(
150
- 'Error removing sourcemap file',
151
- sourcemap_url,
152
- ': ',
153
- error,
154
- );
126
+ console.error('Error removing sourcemap file', sourcemap_url, ': ', error);
155
127
  }
156
128
  });
157
129
 
package/src/util.ts CHANGED
@@ -1,11 +1,8 @@
1
1
  export function uuid() {
2
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
3
- /[xy]/g,
4
- function (c) {
5
- const r = (Math.random() * 16) | 0;
6
- const v = c == 'x' ? r : (r & 0x3) | 0x8;
2
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
3
+ const r = (Math.random() * 16) | 0;
4
+ const v = c == 'x' ? r : (r & 0x3) | 0x8;
7
5
 
8
- return v.toString(16);
9
- },
10
- );
6
+ return v.toString(16);
7
+ });
11
8
  }
package/tsconfig.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
- "include": ["src"],
3
+ "include": ["src"]
4
4
  }