react-native-web-serial-api 0.0.2 → 0.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.
Files changed (120) hide show
  1. package/README.md +23 -0
  2. package/TESTING.md +301 -0
  3. package/android/build.gradle +2 -2
  4. package/android/src/main/java/dev/webserialapi/NativeUsbSerialModule.java +7 -1
  5. package/lib/commonjs/UsbSerial.js +58 -26
  6. package/lib/commonjs/UsbSerial.js.map +1 -1
  7. package/lib/commonjs/WebSerial.js +169 -57
  8. package/lib/commonjs/WebSerial.js.map +1 -1
  9. package/lib/commonjs/index.js +13 -1
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/lib/dom-exception.js +176 -0
  12. package/lib/commonjs/lib/dom-exception.js.map +1 -0
  13. package/lib/commonjs/lib/event-target.js +138 -0
  14. package/lib/commonjs/lib/event-target.js.map +1 -0
  15. package/lib/commonjs/lib/promise.js +23 -0
  16. package/lib/commonjs/lib/promise.js.map +1 -0
  17. package/lib/commonjs/testing/index.js +70 -0
  18. package/lib/commonjs/testing/index.js.map +1 -0
  19. package/lib/commonjs/testing/install.js +54 -0
  20. package/lib/commonjs/testing/install.js.map +1 -0
  21. package/lib/commonjs/testing/serial-device.js +164 -0
  22. package/lib/commonjs/testing/serial-device.js.map +1 -0
  23. package/lib/commonjs/testing/virtual-serial.js +615 -0
  24. package/lib/commonjs/testing/virtual-serial.js.map +1 -0
  25. package/lib/commonjs/transport.js +61 -0
  26. package/lib/commonjs/transport.js.map +1 -0
  27. package/lib/typescript/src/UsbSerial.d.ts +24 -67
  28. package/lib/typescript/src/UsbSerial.d.ts.map +1 -1
  29. package/lib/typescript/src/WebSerial.d.ts +11 -2
  30. package/lib/typescript/src/WebSerial.d.ts.map +1 -1
  31. package/lib/typescript/src/index.d.ts +2 -0
  32. package/lib/typescript/src/index.d.ts.map +1 -1
  33. package/lib/typescript/src/lib/dom-exception.d.ts +100 -0
  34. package/lib/typescript/src/lib/dom-exception.d.ts.map +1 -0
  35. package/lib/typescript/src/lib/event-target.d.ts +53 -0
  36. package/lib/typescript/src/lib/event-target.d.ts.map +1 -0
  37. package/lib/typescript/src/lib/promise.d.ts +11 -0
  38. package/lib/typescript/src/lib/promise.d.ts.map +1 -0
  39. package/lib/typescript/src/testing/index.d.ts +23 -0
  40. package/lib/typescript/src/testing/index.d.ts.map +1 -0
  41. package/lib/typescript/src/testing/install.d.ts +25 -0
  42. package/lib/typescript/src/testing/install.d.ts.map +1 -0
  43. package/lib/typescript/src/testing/serial-device.d.ts +127 -0
  44. package/lib/typescript/src/testing/serial-device.d.ts.map +1 -0
  45. package/lib/typescript/src/testing/virtual-serial.d.ts +205 -0
  46. package/lib/typescript/src/testing/virtual-serial.d.ts.map +1 -0
  47. package/lib/typescript/src/transport.d.ts +131 -0
  48. package/lib/typescript/src/transport.d.ts.map +1 -0
  49. package/package.json +38 -2
  50. package/src/UsbSerial.ts +65 -90
  51. package/src/WebSerial.ts +227 -88
  52. package/src/index.ts +2 -7
  53. package/src/lib/dom-exception.ts +129 -60
  54. package/src/lib/event-target.ts +46 -21
  55. package/src/lib/promise.ts +7 -7
  56. package/src/testing/index.ts +42 -0
  57. package/src/testing/install.ts +65 -0
  58. package/src/testing/serial-device.ts +193 -0
  59. package/src/testing/virtual-serial.ts +801 -0
  60. package/src/transport.ts +200 -0
  61. package/babel.config.js +0 -3
  62. package/biome.json +0 -35
  63. package/example/.watchmanconfig +0 -1
  64. package/example/App.tsx +0 -71
  65. package/example/__tests__/App.test.tsx +0 -16
  66. package/example/__tests__/connectEvents.test.tsx +0 -81
  67. package/example/__tests__/getPorts.test.tsx +0 -140
  68. package/example/android/app/build.gradle +0 -120
  69. package/example/android/app/debug.keystore +0 -0
  70. package/example/android/app/proguard-rules.pro +0 -10
  71. package/example/android/app/src/debug/AndroidManifest.xml +0 -9
  72. package/example/android/app/src/main/AndroidManifest.xml +0 -38
  73. package/example/android/app/src/main/java/dev/uzlopak/MainActivity.kt +0 -22
  74. package/example/android/app/src/main/java/dev/uzlopak/MainApplication.kt +0 -41
  75. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +0 -37
  76. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  77. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  78. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  79. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  80. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  81. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  82. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  83. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  84. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  85. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  86. package/example/android/app/src/main/res/values/strings.xml +0 -3
  87. package/example/android/app/src/main/res/values/styles.xml +0 -9
  88. package/example/android/build.gradle +0 -22
  89. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  90. package/example/android/gradle/wrapper/gradle-wrapper.properties +0 -7
  91. package/example/android/gradle.properties +0 -47
  92. package/example/android/gradlew +0 -252
  93. package/example/android/gradlew.bat +0 -94
  94. package/example/android/settings.gradle +0 -6
  95. package/example/app.json +0 -4
  96. package/example/babel.config.js +0 -21
  97. package/example/biome.json +0 -47
  98. package/example/deploy.sh +0 -11
  99. package/example/index.html +0 -26
  100. package/example/index.js +0 -9
  101. package/example/index.web.js +0 -8
  102. package/example/jest.config.js +0 -12
  103. package/example/metro.config.js +0 -58
  104. package/example/package-lock.json +0 -14510
  105. package/example/package.json +0 -48
  106. package/example/react-native.config.js +0 -17
  107. package/example/src/components/AppBar.tsx +0 -73
  108. package/example/src/components/Menu.tsx +0 -90
  109. package/example/src/components/SingleChoiceDialog.tsx +0 -120
  110. package/example/src/screens/ConnectScreen.tsx +0 -195
  111. package/example/src/screens/DevicesScreen.tsx +0 -248
  112. package/example/src/screens/TerminalScreen.tsx +0 -564
  113. package/example/src/settings.ts +0 -43
  114. package/example/src/theme.ts +0 -19
  115. package/example/src/util/TextUtil.ts +0 -129
  116. package/example/tsconfig.json +0 -10
  117. package/example/vite.config.mjs +0 -55
  118. package/scripts/deploy-release.sh +0 -127
  119. package/tsconfig.build.json +0 -7
  120. package/tsconfig.json +0 -20
@@ -1,47 +0,0 @@
1
- {
2
- "$schema": "https://biomejs.dev/schemas/2.4.16/schema.json",
3
- "files": {
4
- "includes": [
5
- "App.tsx",
6
- "index.js",
7
- "index.web.js",
8
- "src/**/*.{ts,tsx}",
9
- "__tests__/**/*.{ts,tsx}",
10
- "*.config.{js,mjs}",
11
- "!android",
12
- "!dist",
13
- "!node_modules"
14
- ]
15
- },
16
- "formatter": {
17
- "enabled": true,
18
- "indentStyle": "space",
19
- "indentWidth": 2,
20
- "lineWidth": 80
21
- },
22
- "javascript": {
23
- "formatter": {
24
- "quoteStyle": "single",
25
- "trailingCommas": "all",
26
- "bracketSpacing": false,
27
- "bracketSameLine": true,
28
- "arrowParentheses": "asNeeded"
29
- }
30
- },
31
- "linter": {
32
- "enabled": true,
33
- "rules": {
34
- "recommended": true,
35
- "style": {
36
- "noNonNullAssertion": "off"
37
- },
38
- "suspicious": {
39
- "noExplicitAny": "off",
40
- "noArrayIndexKey": "off"
41
- },
42
- "complexity": {
43
- "noBannedTypes": "off"
44
- }
45
- }
46
- }
47
- }
package/example/deploy.sh DELETED
@@ -1,11 +0,0 @@
1
- # Bundle neu bauen
2
- npx react-native bundle \
3
- --platform android \
4
- --dev false \
5
- --entry-file index.js \
6
- --bundle-output android/app/src/main/assets/index.android.bundle \
7
- --assets-dest android/app/src/main/res
8
-
9
- # Dann APK bauen und installieren
10
- cd android && ./gradlew assembleDebug && cd ..
11
- npm run android -- --deviceId 192.168.178.73:5555
@@ -1,26 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta
6
- name="viewport"
7
- content="width=device-width, initial-scale=1, shrink-to-fit=no"
8
- />
9
- <title>Web Serial API Demo</title>
10
- <style>
11
- html,
12
- body,
13
- #root {
14
- height: 100%;
15
- margin: 0;
16
- }
17
- #root {
18
- display: flex;
19
- }
20
- </style>
21
- </head>
22
- <body>
23
- <div id="root"></div>
24
- <script type="module" src="/index.web.js"></script>
25
- </body>
26
- </html>
package/example/index.js DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * @format
3
- */
4
-
5
- import {AppRegistry} from 'react-native';
6
- import App from './App';
7
- import {name as appName} from './app.json';
8
-
9
- AppRegistry.registerComponent(appName, () => App);
@@ -1,8 +0,0 @@
1
- import {AppRegistry} from 'react-native';
2
- import App from './App';
3
- import {name as appName} from './app.json';
4
-
5
- AppRegistry.registerComponent(appName, () => App);
6
- AppRegistry.runApplication(appName, {
7
- rootTag: document.getElementById('root'),
8
- });
@@ -1,12 +0,0 @@
1
- module.exports = {
2
- // RN 0.85 moved the Jest preset out of `react-native` into its own package.
3
- preset: '@react-native/jest-preset',
4
- // The library is consumed from ../src (via the babel module-resolver alias),
5
- // which physically lives outside this folder and would otherwise resolve a
6
- // second, un-mocked copy of react-native / react from the repo root. Pin both
7
- // to the example's copy so the RN jest preset's native mocks apply everywhere.
8
- moduleNameMapper: {
9
- '^react-native$': '<rootDir>/node_modules/react-native',
10
- '^react$': '<rootDir>/node_modules/react',
11
- },
12
- };
@@ -1,58 +0,0 @@
1
- const path = require('node:path');
2
- const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
3
-
4
- const pkg = require('../package.json');
5
-
6
- const root = path.resolve(__dirname, '..');
7
- const modules = Object.keys({...pkg.peerDependencies});
8
-
9
- // Absolute paths to the example's single copy of each peer dependency.
10
- const peerModulePaths = modules.reduce((acc, name) => {
11
- acc[name] = path.resolve(__dirname, 'node_modules', name);
12
- return acc;
13
- }, {});
14
-
15
- /**
16
- * Metro configuration for the example app inside the library monorepo.
17
- *
18
- * - watch the repo root so edits to the library's `src/` hot-reload here
19
- * - force the library's peer deps (react / react-native) to resolve to the
20
- * example's single copy. This is critical: the library source lives at the
21
- * repo root (above this folder) and there is ALSO a react-native installed at
22
- * the repo root (the library's own devDependency). Without forcing a single
23
- * copy, `src/WebSerial.ts` resolves the root react-native while the app uses
24
- * the example's copy — two separate RCTDeviceEventEmitter singletons, so
25
- * native 'data' events are emitted into one and listened for on the other,
26
- * and nothing is received. extraNodeModules alone does NOT fix this because
27
- * the importing file is outside the project root, so we also intercept via
28
- * resolveRequest.
29
- *
30
- * https://reactnative.dev/docs/metro
31
- */
32
- const config = {
33
- watchFolders: [root],
34
- resolver: {
35
- nodeModulesPaths: [
36
- path.resolve(__dirname, 'node_modules'),
37
- path.resolve(root, 'node_modules'),
38
- ],
39
- extraNodeModules: peerModulePaths,
40
- resolveRequest: (context, moduleName, platform) => {
41
- // Pin every peer dependency (and its subpaths) to the example's copy,
42
- // regardless of which file imports it.
43
- for (const name of modules) {
44
- if (moduleName === name || moduleName.startsWith(`${name}/`)) {
45
- const rest = moduleName.slice(name.length); // '' or '/subpath'
46
- return context.resolveRequest(
47
- context,
48
- peerModulePaths[name] + rest,
49
- platform,
50
- );
51
- }
52
- }
53
- return context.resolveRequest(context, moduleName, platform);
54
- },
55
- },
56
- };
57
-
58
- module.exports = mergeConfig(getDefaultConfig(__dirname), config);