Skip to content

Commit

Permalink
feat: transform CommonJS for old runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Sep 4, 2023
1 parent 27e6935 commit 52fb9f7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'@babel/plugin-transform-logical-assignment-operators',
],
};
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"main": "lib/commonjs/index",
"module": "lib/module/index",
"types": "lib/typescript/index.d.ts",
"react-native": {
"net": "react-native-tcp-socket"
},
"source": "src/index",
"files": [
"src",
Expand Down Expand Up @@ -54,6 +51,7 @@
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@babel/plugin-transform-logical-assignment-operators": "^7.22.11",
"@commitlint/config-conventional": "^17.0.2",
"@evilmartians/lefthook": "^1.2.2",
"@react-native-community/eslint-config": "^3.0.2",
Expand Down Expand Up @@ -150,7 +148,7 @@
"source": "src",
"output": "lib",
"targets": [
"commonjs",
["commonjs", { "configFile": true }],
"module",
[
"typescript",
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as mqtt from 'mqtt';
import net, { AddressInfo } from 'net';
import { SimpleMQBroker } from '../index';

jest.mock('react-native-tcp-socket', () => require('net'));

const getFreePort = () =>
new Promise<number>((resolve, reject) => {
const server = net.createServer();
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Buffer } from 'buffer';
import type { Packet, Parser } from 'mqtt-packet';
import net from 'net';
import net from 'react-native-tcp-socket';
import mqtt from 'mqtt-packet';
import { EventEmitter } from 'events';

Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,14 @@
dependencies:
"@babel/helper-plugin-utils" "^7.22.5"

"@babel/plugin-transform-logical-assignment-operators@^7.22.11":
version "7.22.11"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-logical-assignment-operators/-/plugin-transform-logical-assignment-operators-7.22.11.tgz#24c522a61688bde045b7d9bc3c2597a4d948fc9c"
integrity sha512-qQwRTP4+6xFCDV5k7gZBF3C31K34ut0tbEcTKxlX/0KXxm9GLcO14p570aWxFvVzx6QAfPgq7gaeIHXJC8LswQ==
dependencies:
"@babel/helper-plugin-utils" "^7.22.5"
"@babel/plugin-syntax-logical-assignment-operators" "^7.10.4"

"@babel/plugin-transform-logical-assignment-operators@^7.22.5":
version "7.22.5"
resolved "https://registry.npmjs.org/@babel/plugin-transform-logical-assignment-operators/-/plugin-transform-logical-assignment-operators-7.22.5.tgz"
Expand Down

0 comments on commit 52fb9f7

Please sign in to comment.