Skip to content
Permalink
Browse files

Create react-native build pipeline

  • Loading branch information...
legastero committed Apr 23, 2019
1 parent 07bfeb8 commit 87f21a79f9d56fc40ff9101282ee68b7dd985e5a
@@ -3,13 +3,21 @@
"description": "Modern XMPP in the browser, with a JSON API",
"version": "11.2.1",
"author": "Lance Stout <lancestout@gmail.com>",
"browser": {
"node-stringprep": false,
"ws": false,
"stream": "readable-stream",
"./dist/es/lib/async/index.js": "./dist/es/lib/async/index-browser.js",
"./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"
"stanzajs_env_mappings": {
"browser": {
"./dist/es/lib/async/index.js": "./dist/es/lib/async/index-browser.js",
"./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/stringprep/index.js": "./dist/es/lib/stringprep/index-browser.js",
"./dist/es/lib/ws/index.js": "./dist/es/lib/ws/index-browser.js"
},
"react-native": {
"./dist/es/lib/async/index.js": "./dist/es/lib/async/index-browser.js",
"./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/stringprep/index.js": "./dist/es/lib/stringprep/index-browser.js",
"./dist/es/lib/ws/index.js": "./dist/es/lib/ws/index-browser.js"
}
},
"bugs": "https://github.com/legastero/stanza.io/issues",
"contributors": [
@@ -19,11 +27,14 @@
"dependencies": {
"@types/async": "^2.4.0",
"@types/node": "^11.13.6",
"@types/readable-stream": "^2.3.1",
"@types/ws": "^6.0.1",
"async": "^2.6.2",
"async-es": "^2.6.2",
"cross-fetch": "^3.0.2",
"jxt": "^4.0.0",
"react-native-randombytes": "^3.5.2",
"readable-stream": "^2.3.6",
"sdp": "^2.9.0",
"tslib": "^1.9.3",
"uuid": "^3.3.2",
@@ -38,7 +49,6 @@
"rimraf": "^2.6.2",
"rollup": "^1.0.0",
"rollup-plugin-node-resolve": "^4.0.0",
"string-replace-loader": "^2.1.1",
"tap-spec": "^5.0.0",
"tape": "^4.8.0",
"ts-node": "^8.0.3",
@@ -95,6 +105,7 @@
"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",
"lint": "tslint -p .",
"test": "nyc ts-node --files test/index.js | tap-spec && nyc report --reporter=text",
@@ -1,4 +1,5 @@
import resolve from 'rollup-plugin-node-resolve';

import baseconfig from './rollup.config';

export default {
@@ -0,0 +1,9 @@
import baseconfig from './rollup-browser.config';

export default {
...baseconfig,
output: {
file: 'dist/es/index-rn.module.js',
format: 'es'
}
};
@@ -10,6 +10,7 @@ export default {
'jxt',
'punycode',
'sdp',
'readable-stream',
'stream',
'tslib',
'uuid',
@@ -1,35 +1,69 @@
const FS = require('fs');
const Child = require('child_process').execSync;

const Pkg = JSON.parse(FS.readFileSync('package.json'));

function fileReplace(fileName, placeholder, value) {
const originalFile = FS.readFileSync(fileName).toString();
FS.writeFileSync(fileName, originalFile.replace(placeholder, value));
}

function writeOverrides(overrides = undefined) {
FS.writeFileSync(
'package.json',
JSON.stringify(
{
...Pkg,
browser: overrides
},
null,
4
) + '\n'
);
}

// Copy local package files
Child('npm run clean');
Child('npm run compile');
Child('npm run compile:module');

// Embed package version into CJS and ES modules
fileReplace('dist/cjs/index.js', '__STANZAJS_VERSION__', Pkg.version);
fileReplace('dist/es/index.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');

// Create package.json file
const Pkg = JSON.parse(FS.readFileSync('package.json'));
FS.writeFileSync(
'dist/npm/package.json',
JSON.stringify(
{
...Pkg,
browser: {
...Pkg.browser,
'./module.js': './browser-module.js'
},
browser: './browser-module.js',
devDependencies: undefined,
'jsnext:main': './module.js',
main: './index.js',
module: './module.js',
private: false,
'react-native': './rn-module.js',
scripts: undefined,
sideEffects: false,
typings: './index'
@@ -3,7 +3,7 @@ import * as jid from './protocol/jid';
import Client from './client';
import Plugins from './plugins';

export const VERSION = '__STANZAIO_VERSION__';
export const VERSION = '__STANZAJS_VERSION__';
export const JID = jid.JID;

export { Client, jid };
@@ -1,6 +1,6 @@
// tslint:disable no-bitwise

import { Transform } from 'stream';
import { Transform } from 'readable-stream';

export default abstract class Hash extends Transform {
protected _block: Buffer;
@@ -1,6 +1,6 @@
// tslint:disable no-bitwise

import { Transform } from 'stream';
import { Transform } from 'readable-stream';

import Hash from './Hash';
import MD5 from './MD5';
@@ -0,0 +1,9 @@
import * as RNRandomBytes from 'react-native-randombytes';

import { createHash, createHmac, getHashes, Hash, Hmac } from './index-browser';

export { Hash, Hmac, createHash, createHmac, getHashes };

export function randomBytes(size: number) {
return RNRandomBytes.randomBytes(size);
}
@@ -0,0 +1,19 @@
const punycode = require('punycode');

export const NATIVE_STRINGPREP = false;

export function toUnicode(data) {
return punycode.toUnicode(data);
}

export function nameprep(str) {
return str.toLowerCase();
}

export function nodeprep(str) {
return str.toLowerCase();
}

export function resourceprep(str) {
return str;
}
@@ -0,0 +1,46 @@
const punycode = require('punycode');

let StringPrep;
try {
StringPrep = require('node-stringprep');
} catch (err) {
StringPrep = false;
}

const HAS_STRINGPREP = !!StringPrep && !!StringPrep.StringPrep;
export const NATIVE_STRINGPREP = HAS_STRINGPREP && new StringPrep.StringPrep('nodeprep').isNative();

export function toUnicode(data) {
if (HAS_STRINGPREP) {
return punycode.toUnicode(StringPrep.toUnicode(data));
} else {
return punycode.toUnicode(data);
}
}

export function nameprep(str) {
if (HAS_STRINGPREP) {
const name = new StringPrep.StringPrep('nameprep');
return name.prepare(str);
} else {
return str.toLowerCase();
}
}

export function nodeprep(str) {
if (HAS_STRINGPREP) {
const node = new StringPrep.StringPrep('nodeprep');
return node.prepare(str);
} else {
return str.toLowerCase();
}
}

export function resourceprep(str) {
if (HAS_STRINGPREP) {
const resource = new StringPrep.StringPrep('resourceprep');
return resource.prepare(str);
} else {
return str;
}
}
@@ -0,0 +1 @@
export default WebSocket;
@@ -0,0 +1,3 @@
import WS from 'ws';

export default WS;
@@ -1,49 +1,4 @@
const punycode = require('punycode');

let StringPrep;
try {
StringPrep = require('node-stringprep');
} catch (err) {
StringPrep = false;
}

const HAS_STRINGPREP = !!StringPrep && !!StringPrep.StringPrep;
export const NATIVE_STRINGPREP = HAS_STRINGPREP && new StringPrep.StringPrep('nodeprep').isNative();

export function toUnicode(data) {
if (HAS_STRINGPREP) {
return punycode.toUnicode(StringPrep.toUnicode(data));
} else {
return punycode.toUnicode(data);
}
}

export function nameprep(str) {
if (HAS_STRINGPREP) {
const name = new StringPrep.StringPrep('nameprep');
return name.prepare(str);
} else {
return str.toLowerCase();
}
}

export function nodeprep(str) {
if (HAS_STRINGPREP) {
const node = new StringPrep.StringPrep('nodeprep');
return node.prepare(str);
} else {
return str.toLowerCase();
}
}

export function resourceprep(str) {
if (HAS_STRINGPREP) {
const resource = new StringPrep.StringPrep('resourceprep');
return resource.prepare(str);
} else {
return str;
}
}
import { NATIVE_STRINGPREP, toUnicode, nameprep, nodeprep, resourceprep } from '../lib/stringprep';

// All of our StringPrep fallbacks work correctly
// in the ASCII range, so we can reliably mark
@@ -1,10 +1,7 @@
import WildEmitter from 'wildemitter';
import * as async from '../lib/async';
import WS from '../lib/ws';

let WS = require('ws');
if (typeof WS !== 'function') {
WS = window.WebSocket;
}
const WS_OPEN = 1;

export default class WSConnection extends WildEmitter {
@@ -0,0 +1,3 @@
declare module 'react-native-randombytes' {
export function randomBytes(size: number): Buffer;
}
@@ -12,19 +12,6 @@ module.exports = {
path: Path.resolve('dist')
},

module: {
rules: [
{
loader: 'string-replace-loader',
options: {
replace: Pkg.version,
search: '__STANZAIO_VERSION__'
},
test: /index\.[jt]s/
}
]
},

plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static',

0 comments on commit 87f21a7

Please sign in to comment.
You can’t perform that action at this time.