@microbit/microbit-connection 0.0.0-alpha.1

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.
Files changed (68) hide show
  1. package/README.md +36 -0
  2. package/build/accelerometer-service.d.ts +17 -0
  3. package/build/accelerometer-service.js +84 -0
  4. package/build/accelerometer-service.js.map +1 -0
  5. package/build/accelerometer.d.ts +9 -0
  6. package/build/accelerometer.js +12 -0
  7. package/build/accelerometer.js.map +1 -0
  8. package/build/async-util.d.ts +13 -0
  9. package/build/async-util.js +22 -0
  10. package/build/async-util.js.map +1 -0
  11. package/build/bluetooth-device-wrapper.d.ts +39 -0
  12. package/build/bluetooth-device-wrapper.js +316 -0
  13. package/build/bluetooth-device-wrapper.js.map +1 -0
  14. package/build/bluetooth-profile.d.ts +139 -0
  15. package/build/bluetooth-profile.js +83 -0
  16. package/build/bluetooth-profile.js.map +1 -0
  17. package/build/bluetooth.d.ts +50 -0
  18. package/build/bluetooth.js +247 -0
  19. package/build/bluetooth.js.map +1 -0
  20. package/build/board-id.d.ts +35 -0
  21. package/build/board-id.js +69 -0
  22. package/build/board-id.js.map +1 -0
  23. package/build/board-serial-info.d.ts +14 -0
  24. package/build/board-serial-info.js +47 -0
  25. package/build/board-serial-info.js.map +1 -0
  26. package/build/constants.d.ts +47 -0
  27. package/build/constants.js +69 -0
  28. package/build/constants.js.map +1 -0
  29. package/build/device.d.ts +202 -0
  30. package/build/device.js +153 -0
  31. package/build/device.js.map +1 -0
  32. package/build/events.d.ts +101 -0
  33. package/build/events.js +19 -0
  34. package/build/events.js.map +1 -0
  35. package/build/hex-flash-data-source.d.ts +9 -0
  36. package/build/hex-flash-data-source.js +50 -0
  37. package/build/hex-flash-data-source.js.map +1 -0
  38. package/build/index.d.ts +7 -0
  39. package/build/index.js +7 -0
  40. package/build/index.js.map +1 -0
  41. package/build/logging.d.ts +21 -0
  42. package/build/logging.js +10 -0
  43. package/build/logging.js.map +1 -0
  44. package/build/service-events.d.ts +9 -0
  45. package/build/service-events.js +11 -0
  46. package/build/service-events.js.map +1 -0
  47. package/build/setupTests.d.ts +6 -0
  48. package/build/setupTests.js.map +1 -0
  49. package/build/usb-device-wrapper.d.ts +46 -0
  50. package/build/usb-device-wrapper.js +347 -0
  51. package/build/usb-device-wrapper.js.map +1 -0
  52. package/build/usb-partial-flashing-utils.d.ts +17 -0
  53. package/build/usb-partial-flashing-utils.js +122 -0
  54. package/build/usb-partial-flashing-utils.js.map +1 -0
  55. package/build/usb-partial-flashing.d.ts +63 -0
  56. package/build/usb-partial-flashing.js +270 -0
  57. package/build/usb-partial-flashing.js.map +1 -0
  58. package/build/usb-radio-bridge.d.ts +28 -0
  59. package/build/usb-radio-bridge.js +318 -0
  60. package/build/usb-radio-bridge.js.map +1 -0
  61. package/build/usb-serial-protocol.d.ts +66 -0
  62. package/build/usb-serial-protocol.js +171 -0
  63. package/build/usb-serial-protocol.js.map +1 -0
  64. package/build/usb.d.ts +61 -0
  65. package/build/usb.js +451 -0
  66. package/build/usb.js.map +1 -0
  67. package/package.json +32 -0
  68. package/vite.config.ts +32 -0
package/build/usb.js ADDED
@@ -0,0 +1,451 @@
1
+ /**
2
+ * (c) 2021, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { NullLogging } from "./logging";
7
+ import { withTimeout, TimeoutError } from "./async-util";
8
+ import { DAPWrapper } from "./usb-device-wrapper";
9
+ import { PartialFlashing } from "./usb-partial-flashing";
10
+ import { ConnectionStatus, AfterRequestDevice, FlashEvent, FlashDataError, SerialDataEvent, SerialErrorEvent, SerialResetEvent, BeforeRequestDevice, ConnectionStatusEvent, DeviceError, } from "./device";
11
+ import { TypedEventTarget } from "./events";
12
+ // Temporary workaround for ChromeOS 105 bug.
13
+ // See https://bugs.chromium.org/p/chromium/issues/detail?id=1363712&q=usb&can=2
14
+ export const isChromeOS105 = () => {
15
+ const userAgent = navigator.userAgent;
16
+ return /CrOS/.test(userAgent) && /Chrome\/105\b/.test(userAgent);
17
+ };
18
+ /**
19
+ * A WebUSB connection to a micro:bit device.
20
+ */
21
+ export class MicrobitWebUSBConnection extends TypedEventTarget {
22
+ constructor(options = { logging: new NullLogging() }) {
23
+ super();
24
+ Object.defineProperty(this, "status", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: navigator.usb && !isChromeOS105()
29
+ ? ConnectionStatus.NO_AUTHORIZED_DEVICE
30
+ : ConnectionStatus.NOT_SUPPORTED
31
+ });
32
+ /**
33
+ * The USB device we last connected to.
34
+ * Cleared if it is disconnected.
35
+ */
36
+ Object.defineProperty(this, "device", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ /**
43
+ * The connection to the device.
44
+ */
45
+ Object.defineProperty(this, "connection", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ /**
52
+ * DAPLink gives us a promise that lasts as long as we're serial reading.
53
+ * When stopping serial we await it to be sure we're done.
54
+ */
55
+ Object.defineProperty(this, "serialReadInProgress", {
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true,
59
+ value: void 0
60
+ });
61
+ Object.defineProperty(this, "serialListener", {
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true,
65
+ value: (data) => {
66
+ this.dispatchTypedEvent("serialdata", new SerialDataEvent(data));
67
+ }
68
+ });
69
+ Object.defineProperty(this, "flashing", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: false
74
+ });
75
+ Object.defineProperty(this, "disconnectAfterFlash", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: false
80
+ });
81
+ Object.defineProperty(this, "visibilityReconnect", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: false
86
+ });
87
+ Object.defineProperty(this, "visibilityChangeListener", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: () => {
92
+ if (document.visibilityState === "visible") {
93
+ if (this.visibilityReconnect &&
94
+ this.status !== ConnectionStatus.CONNECTED) {
95
+ this.disconnectAfterFlash = false;
96
+ this.visibilityReconnect = false;
97
+ if (!this.flashing) {
98
+ this.log("Reconnecting visible tab");
99
+ this.connect();
100
+ }
101
+ }
102
+ }
103
+ else {
104
+ if (!this.unloading && this.status === ConnectionStatus.CONNECTED) {
105
+ if (!this.flashing) {
106
+ this.log("Disconnecting hidden tab");
107
+ this.disconnect().then(() => {
108
+ this.visibilityReconnect = true;
109
+ });
110
+ }
111
+ else {
112
+ this.log("Scheduling disconnect of hidden tab for after flash");
113
+ this.disconnectAfterFlash = true;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ });
119
+ Object.defineProperty(this, "unloading", {
120
+ enumerable: true,
121
+ configurable: true,
122
+ writable: true,
123
+ value: false
124
+ });
125
+ Object.defineProperty(this, "beforeUnloadListener", {
126
+ enumerable: true,
127
+ configurable: true,
128
+ writable: true,
129
+ value: () => {
130
+ // If serial is in progress when the page unloads with V1 DAPLink 0254 or V2 0255
131
+ // then it'll fail to reconnect with mismatched command/response errors.
132
+ // Try hard to disconnect as a workaround.
133
+ // https://github.com/microbit-foundation/python-editor-v3/issues/89
134
+ this.unloading = true;
135
+ this.stopSerialInternal();
136
+ // The user might stay on the page if they have unsaved changes and there's another beforeunload listener.
137
+ window.addEventListener("focus", () => {
138
+ const assumePageIsStayingOpenDelay = 1000;
139
+ setTimeout(() => {
140
+ if (this.status === ConnectionStatus.CONNECTED) {
141
+ this.unloading = false;
142
+ this.startSerialInternal();
143
+ }
144
+ }, assumePageIsStayingOpenDelay);
145
+ }, { once: true });
146
+ }
147
+ });
148
+ Object.defineProperty(this, "logging", {
149
+ enumerable: true,
150
+ configurable: true,
151
+ writable: true,
152
+ value: void 0
153
+ });
154
+ Object.defineProperty(this, "handleDisconnect", {
155
+ enumerable: true,
156
+ configurable: true,
157
+ writable: true,
158
+ value: (event) => {
159
+ if (event.device === this.device) {
160
+ this.connection = undefined;
161
+ this.device = undefined;
162
+ this.setStatus(ConnectionStatus.NO_AUTHORIZED_DEVICE);
163
+ }
164
+ }
165
+ });
166
+ this.logging = options.logging;
167
+ }
168
+ log(v) {
169
+ this.logging.log(v);
170
+ }
171
+ async initialize() {
172
+ if (navigator.usb) {
173
+ navigator.usb.addEventListener("disconnect", this.handleDisconnect);
174
+ }
175
+ if (typeof window !== "undefined") {
176
+ window.addEventListener("beforeunload", this.beforeUnloadListener);
177
+ if (window.document) {
178
+ window.document.addEventListener("visibilitychange", this.visibilityChangeListener);
179
+ }
180
+ }
181
+ }
182
+ dispose() {
183
+ if (navigator.usb) {
184
+ navigator.usb.removeEventListener("disconnect", this.handleDisconnect);
185
+ }
186
+ if (typeof window !== "undefined") {
187
+ window.removeEventListener("beforeunload", this.beforeUnloadListener);
188
+ if (window.document) {
189
+ window.document.removeEventListener("visibilitychange", this.visibilityChangeListener);
190
+ }
191
+ }
192
+ }
193
+ async connect(options = {}) {
194
+ return this.withEnrichedErrors(async () => {
195
+ await this.connectInternal(options);
196
+ return this.status;
197
+ });
198
+ }
199
+ getBoardVersion() {
200
+ return this.connection?.boardSerialInfo?.id.toBoardVersion();
201
+ }
202
+ async flash(dataSource, options) {
203
+ this.flashing = true;
204
+ try {
205
+ const startTime = new Date().getTime();
206
+ await this.withEnrichedErrors(() => this.flashInternal(dataSource, options));
207
+ this.dispatchTypedEvent("flash", new FlashEvent());
208
+ const flashTime = new Date().getTime() - startTime;
209
+ this.logging.event({
210
+ type: "WebUSB-time",
211
+ detail: {
212
+ flashTime,
213
+ },
214
+ });
215
+ this.logging.log("Flash complete");
216
+ }
217
+ finally {
218
+ this.flashing = false;
219
+ }
220
+ }
221
+ async flashInternal(dataSource, options) {
222
+ this.log("Stopping serial before flash");
223
+ await this.stopSerialInternal();
224
+ this.log("Reconnecting before flash");
225
+ await this.connectInternal({
226
+ serial: false,
227
+ });
228
+ if (!this.connection) {
229
+ throw new Error("Must be connected now");
230
+ }
231
+ const partial = options.partial;
232
+ const progress = options.progress || (() => { });
233
+ const boardId = this.connection.boardSerialInfo.id;
234
+ const flashing = new PartialFlashing(this.connection, this.logging);
235
+ let wasPartial = false;
236
+ try {
237
+ if (partial) {
238
+ wasPartial = await flashing.flashAsync(boardId, dataSource, progress);
239
+ }
240
+ else {
241
+ await flashing.fullFlashAsync(boardId, dataSource, progress);
242
+ }
243
+ }
244
+ finally {
245
+ progress(undefined, wasPartial);
246
+ if (this.disconnectAfterFlash) {
247
+ this.log("Disconnecting after flash due to tab visibility");
248
+ this.disconnectAfterFlash = false;
249
+ await this.disconnect();
250
+ this.visibilityReconnect = true;
251
+ }
252
+ else {
253
+ // This might not strictly be "reinstating". We should make this
254
+ // behaviour configurable when pulling out a library.
255
+ this.log("Reinstating serial after flash");
256
+ if (this.connection.daplink) {
257
+ await this.connection.daplink.connect();
258
+ await this.startSerialInternal();
259
+ }
260
+ }
261
+ }
262
+ }
263
+ async startSerialInternal() {
264
+ if (!this.connection) {
265
+ // As connecting then starting serial are async we could disconnect between them,
266
+ // so handle this gracefully.
267
+ return;
268
+ }
269
+ if (this.serialReadInProgress) {
270
+ await this.stopSerialInternal();
271
+ }
272
+ // This is async but won't return until we stop serial so we error handle with an event.
273
+ this.serialReadInProgress = this.connection
274
+ .startSerial(this.serialListener)
275
+ .then(() => this.log("Finished listening for serial data"))
276
+ .catch((e) => {
277
+ this.dispatchTypedEvent("serialerror", new SerialErrorEvent(e));
278
+ });
279
+ }
280
+ async stopSerialInternal() {
281
+ if (this.connection && this.serialReadInProgress) {
282
+ this.connection.stopSerial(this.serialListener);
283
+ await this.serialReadInProgress;
284
+ this.serialReadInProgress = undefined;
285
+ this.dispatchTypedEvent("serialreset", new SerialResetEvent());
286
+ }
287
+ }
288
+ async disconnect() {
289
+ try {
290
+ if (this.connection) {
291
+ await this.stopSerialInternal();
292
+ await this.connection.disconnectAsync();
293
+ }
294
+ }
295
+ catch (e) {
296
+ this.log("Error during disconnection:\r\n" + e);
297
+ this.logging.event({
298
+ type: "WebUSB-error",
299
+ message: "error-disconnecting",
300
+ });
301
+ }
302
+ finally {
303
+ this.connection = undefined;
304
+ this.setStatus(ConnectionStatus.NOT_CONNECTED);
305
+ this.logging.log("Disconnection complete");
306
+ this.logging.event({
307
+ type: "WebUSB-info",
308
+ message: "disconnected",
309
+ });
310
+ }
311
+ }
312
+ setStatus(newStatus) {
313
+ this.status = newStatus;
314
+ this.visibilityReconnect = false;
315
+ this.log("Device status " + newStatus);
316
+ this.dispatchTypedEvent("status", new ConnectionStatusEvent(newStatus));
317
+ }
318
+ async withEnrichedErrors(f) {
319
+ try {
320
+ return await f();
321
+ }
322
+ catch (e) {
323
+ if (e instanceof FlashDataError) {
324
+ throw e;
325
+ }
326
+ // Log error to console for feedback
327
+ this.log("An error occurred whilst attempting to use WebUSB.");
328
+ this.log("Details of the error can be found below, and may be useful when trying to replicate and debug the error.");
329
+ this.log(e);
330
+ // Disconnect from the microbit.
331
+ // Any new connection reallocates all the internals.
332
+ // Use the top-level API so any listeners reflect that we're disconnected.
333
+ await this.disconnect();
334
+ const enriched = enrichedError(e);
335
+ // Sanitise error message, replace all special chars with '-', if last char is '-' remove it
336
+ const errorMessage = e.message
337
+ ? e.message.replace(/\W+/g, "-").replace(/\W$/, "").toLowerCase()
338
+ : "";
339
+ this.logging.event({
340
+ type: "WebUSB-error",
341
+ message: e.code + "/" + errorMessage,
342
+ });
343
+ throw enriched;
344
+ }
345
+ }
346
+ serialWrite(data) {
347
+ return this.withEnrichedErrors(async () => {
348
+ if (this.connection) {
349
+ // Using WebUSB/DAPJs we're limited to 64 byte packet size with a two byte header.
350
+ // https://github.com/microbit-foundation/python-editor-v3/issues/215
351
+ const maxSerialWrite = 62;
352
+ let start = 0;
353
+ while (start < data.length) {
354
+ const end = Math.min(start + maxSerialWrite, data.length);
355
+ const chunkData = data.slice(start, end);
356
+ await this.connection.daplink.serialWrite(chunkData);
357
+ start = end;
358
+ }
359
+ }
360
+ });
361
+ }
362
+ async clearDevice() {
363
+ await this.disconnect();
364
+ this.device = undefined;
365
+ this.setStatus(ConnectionStatus.NO_AUTHORIZED_DEVICE);
366
+ }
367
+ async connectInternal(options) {
368
+ if (!this.connection) {
369
+ const device = await this.chooseDevice();
370
+ this.connection = new DAPWrapper(device, this.logging);
371
+ }
372
+ await withTimeout(this.connection.reconnectAsync(), 10_000);
373
+ if (options.serial === undefined || options.serial) {
374
+ this.startSerialInternal();
375
+ }
376
+ this.setStatus(ConnectionStatus.CONNECTED);
377
+ }
378
+ async chooseDevice() {
379
+ if (this.device) {
380
+ return this.device;
381
+ }
382
+ this.dispatchTypedEvent("beforerequestdevice", new BeforeRequestDevice());
383
+ this.device = await navigator.usb.requestDevice({
384
+ filters: [{ vendorId: 0x0d28, productId: 0x0204 }],
385
+ });
386
+ this.dispatchTypedEvent("afterrequestdevice", new AfterRequestDevice());
387
+ return this.device;
388
+ }
389
+ }
390
+ const genericErrorSuggestingReconnect = (e) => new DeviceError({
391
+ code: "reconnect-microbit",
392
+ message: e.message,
393
+ });
394
+ // tslint:disable-next-line: no-any
395
+ const enrichedError = (err) => {
396
+ if (err instanceof DeviceError) {
397
+ return err;
398
+ }
399
+ if (err instanceof TimeoutError) {
400
+ return new DeviceError({
401
+ code: "timeout-error",
402
+ message: err.message,
403
+ });
404
+ }
405
+ switch (typeof err) {
406
+ case "object":
407
+ // We might get Error objects as Promise rejection arguments
408
+ if (!err.message && err.promise && err.reason) {
409
+ err = err.reason;
410
+ }
411
+ // This is somewhat fragile but worth it for scenario specific errors.
412
+ // These messages changed to be prefixed in 2023 so we've relaxed the checks.
413
+ if (/No valid interfaces found/.test(err.message)) {
414
+ // This comes from DAPjs's WebUSB open.
415
+ return new DeviceError({
416
+ code: "update-req",
417
+ message: err.message,
418
+ });
419
+ }
420
+ else if (/No device selected/.test(err.message)) {
421
+ return new DeviceError({
422
+ code: "no-device-selected",
423
+ message: err.message,
424
+ });
425
+ }
426
+ else if (/Unable to claim interface/.test(err.message)) {
427
+ return new DeviceError({
428
+ code: "clear-connect",
429
+ message: err.message,
430
+ });
431
+ }
432
+ else if (err.name === "device-disconnected") {
433
+ return new DeviceError({
434
+ code: "device-disconnected",
435
+ message: err.message,
436
+ });
437
+ }
438
+ else {
439
+ // Unhandled error. User will need to reconnect their micro:bit
440
+ return genericErrorSuggestingReconnect(err);
441
+ }
442
+ case "string": {
443
+ // Caught a string. Example case: "Flash error" from DAPjs
444
+ return genericErrorSuggestingReconnect(err);
445
+ }
446
+ default: {
447
+ return genericErrorSuggestingReconnect(err);
448
+ }
449
+ }
450
+ };
451
+ //# sourceMappingURL=usb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usb.js","sourceRoot":"","sources":["../lib/usb.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAW,WAAW,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAEL,gBAAgB,EAIhB,kBAAkB,EAElB,UAAU,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,6CAA6C;AAC7C,gFAAgF;AAChF,MAAM,CAAC,MAAM,aAAa,GAAG,GAAY,EAAE;IACzC,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;IACtC,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACnE,CAAC,CAAC;AASF;;GAEG;AACH,MAAM,OAAO,wBACX,SAAQ,gBAA0C;IAsFlD,YACE,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AI,KAAK,qBAAqB,EAAE,CAAC;gBAC9C,OAAO,IAAI,WAAW,CAAC;oBACrB,IAAI,EAAE,qBAAqB;oBAC3B,OAAO,EAAE,GAAG,CAAC,OAAO;iBACrB,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,+DAA+D;gBAC/D,OAAO,+BAA+B,CAAC,GAAG,CAAC,CAAC;YAC9C,CAAC;QACH,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,0DAA0D;YAC1D,OAAO,+BAA+B,CAAC,GAAG,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,OAAO,+BAA+B,CAAC,GAAG,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@microbit/microbit-connection",
3
+ "version": "0.0.0-alpha.1",
4
+ "type": "module",
5
+ "module": "./build/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./build/index.js"
9
+ }
10
+ },
11
+ "scripts": {
12
+ "dev": "vite",
13
+ "build": "tsc",
14
+ "ci": "npm run build && npm run test && npx prettier --check lib src",
15
+ "test": "vitest",
16
+ "preview": "vite preview"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^20.14.10",
20
+ "jsdom": "^24.1.0",
21
+ "prettier": "3.3.2",
22
+ "typescript": "^5.2.2",
23
+ "vite": "^5.3.1",
24
+ "vitest": "^2.0.0"
25
+ },
26
+ "dependencies": {
27
+ "@microbit/microbit-universal-hex": "^0.2.2",
28
+ "@types/web-bluetooth": "^0.0.20",
29
+ "dapjs": "^2.2.0",
30
+ "nrf-intel-hex": "^1.4.0"
31
+ }
32
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * (c) 2024, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { resolve } from "path";
7
+ import { loadEnv } from "vite";
8
+ import { configDefaults, defineConfig, UserConfig } from "vitest/config";
9
+
10
+ export default defineConfig(({ mode }) => {
11
+ process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
12
+ const config: UserConfig = {
13
+ base: process.env.BASE_URL ?? "/",
14
+ build: {
15
+ sourcemap: true,
16
+ lib: {
17
+ // Could also be a dictionary or array of multiple entry points
18
+ entry: resolve(__dirname, "lib/index.ts"),
19
+ name: "MicrobitConnection",
20
+ // the proper extensions will be added
21
+ fileName: "microbit-connection",
22
+ },
23
+ },
24
+ test: {
25
+ exclude: [...configDefaults.exclude, "**/e2e/**"],
26
+ environment: "jsdom",
27
+ setupFiles: "./lib/setupTests.ts",
28
+ mockReset: true,
29
+ },
30
+ };
31
+ return config;
32
+ });