@sleeperhq/mini-core 1.9.0 → 1.9.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.
@@ -17,7 +17,7 @@
17
17
  "@react-navigation/native": "6.1.3",
18
18
  "@react-navigation/stack": "6.3.12",
19
19
  "@shopify/flash-list": "1.4.1",
20
- "@sleeperhq/mini-core": "1.8.7",
20
+ "@sleeperhq/mini-core": "1.9.2",
21
21
  "amazon-cognito-identity-js": "6.3.2",
22
22
  "crypto-js": "3.3.0",
23
23
  "decimal.js-light": "2.5.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleeperhq/mini-core",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "Core library frameworks for developing Sleeper Mini Apps.",
5
5
  "main": "index.ts",
6
6
  "types": "index.d.ts",
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "@babel/runtime": "7.15.4",
38
38
  "@babel/plugin-transform-runtime": "7.15.0",
39
- "@callstack/repack": "blitzstudios/repack.git#callstack-repack-v3.0.0-gitpkg",
39
+ "@callstack/repack": "blitzstudios/repack.git#callstack-repack-v3.1.0-gitpkg",
40
40
  "@callstack/repack-dev-server": "blitzstudios/repack.git#callstack-repack-dev-server-v1.0.7-gitpkg",
41
41
  "@react-native-community/cli": "6.1.0",
42
42
  "@react-native-community/cli-types": "6.0.0",
@@ -0,0 +1,37 @@
1
+ var net = require('net');
2
+ /**
3
+ * @category Webpack Plugin
4
+ */
5
+ class RebuildNotifyPlugin {
6
+
7
+ constructor(config) {
8
+ this.config = config;
9
+ }
10
+ /**
11
+ * Apply the plugin.
12
+ *
13
+ * @param compiler Webpack compiler instance.
14
+ */
15
+ apply(compiler) {
16
+ compiler.hooks.done.tap('RebuildNotifyPlugin', (stats) => {
17
+ if (stats.hasErrors()) {
18
+ return;
19
+ }
20
+
21
+ console.log('Rebuild finished. Notifying the app...');
22
+ // Notify the app that the rebuild has finished
23
+
24
+ const client = new net.Socket();
25
+ client.connect(9093, this.config.remoteIP, () => {
26
+ const json = JSON.stringify({ _webpack: 'built' });
27
+ client.write(json);
28
+ client.destroy();
29
+ });
30
+ client.on('error', () => {
31
+ client.destroy();
32
+ });
33
+ });
34
+ }
35
+ }
36
+
37
+ exports.RebuildNotifyPlugin = RebuildNotifyPlugin;
@@ -3,21 +3,30 @@ import path from 'path';
3
3
 
4
4
  const appJsonFilename = 'app.json';
5
5
  const packagerConnectPort = 9092;
6
+ const refreshTimeout = 5000; //milliseconds
7
+
8
+ const socketConnect = (client, appConfig) => {
9
+ client.connect(packagerConnectPort, appConfig.remoteIP);
10
+ };
6
11
 
7
12
  const packagerConnect = async (rootPath) => {
8
13
  const appJsonPath = path.join(rootPath, appJsonFilename);
9
- // const appConfig = await import(appJsonPath);
10
14
  const { default: appConfig } = await import(appJsonPath, { assert: { type: "json" } });
11
15
 
12
16
  if (!appConfig.remoteIP) {
13
17
  throw new Error(appJsonFilename + ' is missing remoteIP field');
14
18
  }
15
19
 
20
+ console.log('Attempting to connect to Sleeper App at ', appConfig.remoteIP);
21
+
16
22
  const client = new Socket();
17
- client.connect(packagerConnectPort, appConfig.remoteIP, () => {
23
+
24
+ client.on('connect', () => {
18
25
  console.log('Connected to Sleeper App at ', appConfig.remoteIP);
19
26
 
20
27
  client.setEncoding('utf8');
28
+ client.setKeepAlive(true);
29
+
21
30
  const json = JSON.stringify({
22
31
  _webpack: 'packager_connect',
23
32
  _name: appConfig.name ?? '',
@@ -30,12 +39,34 @@ const packagerConnect = async (rootPath) => {
30
39
  console.log('Error sending message to Sleeper App:', err);
31
40
  }
32
41
  });
42
+ });
33
43
 
34
- client.on('error', () => {
35
- client.destroy();
36
- });
44
+ client.on('error', (error) => {
45
+ if (error?.code === 'ECONNREFUSED' && error?.syscall === 'connect') {
46
+ // We don't care about this error since we will retry the connection
47
+ return;
48
+ }
49
+
50
+ console.log('Socket Error: ', error);
51
+ });
52
+
53
+ client.on('data', (data) => {
54
+ // const json = JSON.parse(data);
55
+ // switch (json?.type) {
56
+ // }
37
57
  });
38
58
 
59
+ client.on('close', (hadError) => {
60
+ if (!hadError) {
61
+ console.log('Connection to Sleeper App closed, retrying...');
62
+ }
63
+
64
+ // Retry connection
65
+ setTimeout(socketConnect, refreshTimeout, client, appConfig);
66
+ });
67
+
68
+ socketConnect(client, appConfig);
69
+
39
70
  return () => {
40
71
  client.destroy();
41
72
  };
package/webpack.config.js CHANGED
@@ -3,6 +3,7 @@ const TerserPlugin = require('../../../node_modules/terser-webpack-plugin');
3
3
  const Repack = require('../../../node_modules/@callstack/repack');
4
4
  const config = require('../../../app.json');
5
5
  const {dependencies} = require('../../../package.json');
6
+ const {RebuildNotifyPlugin} = require('./src/plugins/rebuildNotifyPlugin')
6
7
 
7
8
  const {samples, selectedSample} = config;
8
9
  const sampleClassPath = `../../../src/${samples[selectedSample]}`;
@@ -304,6 +305,8 @@ module.exports = env => {
304
305
  },
305
306
  }),
306
307
 
308
+ new RebuildNotifyPlugin(config),
309
+
307
310
  // new Repack.plugins.ChunksToHermesBytecodePlugin({
308
311
  // enabled: !dev,
309
312
  // test: /\.(js)?bundle$/,