Skip to content

Commit

Permalink
Use stanza-shims to handle different runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
legastero committed Oct 16, 2019
1 parent 9978550 commit d5b26be
Show file tree
Hide file tree
Showing 29 changed files with 236 additions and 1,523 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ coverage
.nyc_output
.vscode

# ignore node_modules symlink
node_modules
node_modules.nosync
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ client.connect();

MUC Room: [discuss@stanzajs.org](https://stanzajs.org/discuss/logs) / [Logs](https://stanzajs.org/discuss/logs)

## Related Modules

These are related modules that form part of StanzaJS:

| Name | Description | Source |
| ------------------------------------------------------ | -------------------------------------------------------------------- | --------------------------------------------------- |
| [stanza-shims](https://npmjs.org/package/stanza-shims) | Runtime shims used by StanzaJS for node, browsers, and React Native. | [Source](https://github.com/legastero/stanza-shims) |

## Recommended Modules

These are some additional modules that are highly recommended for use with StanzaJS:
Expand Down
413 changes: 188 additions & 225 deletions package-lock.json

Large diffs are not rendered by default.

48 changes: 17 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,47 @@
"description": "Modern XMPP in the browser, with a JSON API",
"version": "12.3.3",
"author": "Lance Stout <lancestout@gmail.com>",
"bugs": "https://github.com/legastero/stanza.io/issues",
"bugs": "https://github.com/legastero/stanza/issues",
"contributors": [
"Philipp Hancke <fippo@andyet.net>",
"Steven Lloyd Watkin <lloyd@evilprofessor.co.uk>"
],
"dependencies": {
"@types/async": "^3.0.1",
"@types/node": "^12.7.4",
"@types/async": "^3.0.3",
"@types/node": "^12.11.1",
"@types/punycode": "^2.1.0",
"@types/readable-stream": "^2.3.3",
"@types/readable-stream": "^2.3.5",
"@types/ws": "^6.0.2",
"async": "^3.0.1",
"node-fetch": "^2.6.0",
"punycode": "^2.1.1",
"react-native-randombytes": "^3.5.3",
"readable-stream": "^2.3.6",
"sdp": "^2.10.0",
"stanza-shims": "^1.0.0",
"tslib": "^1.9.3",
"ws": "^7.1.1"
},
"devDependencies": {
"@types/jest": "^24.0.18",
"@types/jest": "^24.0.19",
"expect": "^24.9.0",
"husky": "^3.0.5",
"husky": "^3.0.9",
"jest": "^24.9.0",
"jest-mock": "^24.9.0",
"prettier": "^1.18.2",
"pretty-quick": "^1.11.0",
"pretty-quick": "^2.0.0",
"rimraf": "^3.0.0",
"rollup": "^1.20.3",
"rollup": "^1.24.0",
"rollup-plugin-node-resolve": "^5.0.1",
"rollup-plugin-visualizer": "^2.5.4",
"ts-jest": "^24.0.2",
"ts-node": "^8.2.0",
"tslint": "^5.17.0",
"ts-jest": "^24.1.0",
"ts-node": "^8.4.1",
"tslint": "^5.20.0",
"tslint-sonarts": "^1.9.0",
"typedoc": "^0.15.0",
"typescript": "^3.6.2",
"webpack": "^4.39.3",
"webpack-bundle-analyzer": "^3.4.1",
"webpack-cli": "^3.3.6"
"typescript": "^3.6.4",
"webpack": "^4.41.2",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-cli": "^3.3.9"
},
"homepage": "https://stanzajs.org",
"husky": {
Expand Down Expand Up @@ -80,7 +80,7 @@
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/legastero/stanza.io.git"
"url": "https://github.com/legastero/stanza.git"
},
"scripts": {
"build": "ts-node scripts/build",
Expand All @@ -89,24 +89,10 @@
"compile": "tsc -p .",
"compile:module": "tsc -p . --outDir ./dist/es --target es2015 --module es2015",
"compile:rollup": "rollup -c rollup.config.js",
"compile:rollup-browser": "rollup -c rollup-browser.config.js",
"compile:rollup-react-native": "rollup -c rollup-react-native.config.js",
"compile:webpack": "webpack --mode production",
"license-check": "npx license-checker --production --excludePrivatePackages --summary",
"lint": "tslint -p .",
"test": "jest",
"validate": "npm ls"
},
"stanzajs_env_mappings": {
"browser": {
"./dist/es/lib/crypto/index.js": "./dist/es/lib/crypto/index-browser.js",
"./dist/es/lib/fetch/index.js": "./dist/es/lib/fetch/index-browser.js",
"./dist/es/lib/ws/index.js": "./dist/es/lib/ws/index-browser.js"
},
"react-native": {
"./dist/es/lib/crypto/index.js": "./dist/es/lib/crypto/index-react-native.js",
"./dist/es/lib/fetch/index.js": "./dist/es/lib/fetch/index-browser.js",
"./dist/es/lib/ws/index.js": "./dist/es/lib/ws/index-browser.js"
}
}
}
23 changes: 0 additions & 23 deletions rollup-browser.config.js

This file was deleted.

16 changes: 0 additions & 16 deletions rollup-react-native.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export default {
file: 'dist/es/index.module.js',
format: 'es'
},
plugins: [resolve()]
plugins: [resolve({ browser: true })]
};
35 changes: 2 additions & 33 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,6 @@ function fileReplace(fileName: string, placeholder: string, value: string) {
FS.writeFileSync(fileName, originalFile.replace(placeholder, value));
}

interface Overrides {
[key: string]: string;
}
function writeOverrides(overrides?: Overrides) {
FS.writeFileSync(
'package.json',
JSON.stringify(
{
...Pkg,
browser: overrides
},
null,
4
) + '\n'
);
}

// Copy local package files
Child('npm run clean');
Child('npm run compile');
Expand All @@ -36,22 +19,9 @@ fileReplace('dist/es/Constants.js', '__STANZAJS_VERSION__', Pkg.version);

Child('npm run compile:rollup');

// Create browser specific module
writeOverrides(Pkg.stanzajs_env_mappings.browser);
Child('npm run compile:rollup-browser');

// Create react-native specific module
writeOverrides(Pkg.stanzajs_env_mappings['react-native']);
Child('npm run compile:rollup-react-native');

// Clean up overrides
writeOverrides(undefined);

Child('mkdir dist/npm');
Child('cp -r dist/cjs/* dist/npm/');
Child('cp dist/es/index.module.js dist/npm/module.js');
Child('cp dist/es/index-browser.module.js dist/npm/browser-module.js');
Child('cp dist/es/index-rn.module.js dist/npm/rn-module.js');
Child(`cp ${__dirname}/../*.md dist/npm`);
Child('npm run compile:webpack');

Expand All @@ -61,15 +31,14 @@ FS.writeFileSync(
JSON.stringify(
{
...Pkg,
browser: './browser-module.js',
browser: './module.js',
devDependencies: undefined,
main: './index.js',
module: './module.js',
private: false,
'react-native': './rn-module.js',
'react-native': './index.js',
scripts: undefined,
sideEffects: false,
stanzajs_env_mappings: undefined,
typings: './index'
},
null,
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// tslint:disable no-bitwise

import { randomBytes } from './lib/crypto';
import { randomBytes } from 'stanza-shims';

const bth: string[] = [];
for (let i = 0; i < 256; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/LegacyEntityCapabilities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Hashes from '../lib/crypto';
import * as Hashes from 'stanza-shims';
import { octetCompare } from '../Utils';

import { DataForm, DataFormField, DiscoInfo, DiscoInfoIdentity } from '../protocol';
Expand Down
2 changes: 1 addition & 1 deletion src/jingle/FileTransferSession.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventEmitter } from 'events';
import * as Hashes from 'stanza-shims';

import { JINGLE_INFO_CHECKSUM_5, JingleAction, JingleSessionRole } from '../Constants';
import * as Hashes from '../lib/crypto';
import { NS_JINGLE_FILE_TRANSFER_5 } from '../Namespaces';
import {
FileDescription,
Expand Down
142 changes: 0 additions & 142 deletions src/lib/crypto/Hash.ts

This file was deleted.

Loading

0 comments on commit d5b26be

Please sign in to comment.