1
0
mirror of synced 2025-11-08 12:57:47 +00:00

feat(browser): add browser build, tests, and sample sha256 library method

This commit is contained in:
Jason Dreyzehner
2017-02-23 03:06:55 -05:00
parent a56491f866
commit 01f67d103a
18 changed files with 901 additions and 65 deletions

View File

@@ -0,0 +1,37 @@
// this script watches the tests exported by typescript, copies them to the test directories, and modifies the require("PKG.NAME") statements to test each build
const cpx = require("cpx");
const separator = require("path").sep;
const Transform = require("stream").Transform;
const pkg = require('../../package');
const req = (path) => 'require("' + path + '")';
const pathUp = (levels) => Array.from(Array(levels), () => '../').join('');
// replace instances of pkg.name with the proper route to the build being tested
const makeTransform = (filePath, buildPath) => {
const buildPathParts = buildPath.split(separator);
// filePath includes build/main (-2), test/BUILD is 2 deep (+2),
// remove filename (-1). Total is length - 2
const pathToRoot = pathUp(filePath.split(separator).length - 1);
const placeholder = req(pkg.name);
return new Transform({
transform(chunk, encoding, done) {
const str = chunk.toString();
const parts = str.split(placeholder)
const newPath = req(pathToRoot + buildPath)
const result = parts.join(newPath);
this.push(result);
done();
}
});
}
// copy, then watch for changes to the tests
const testsFromRoot = 'build/main/**/*.spec.js';
const task = process.argv[2] === '-w' ? cpx.watch : cpx.copy;
task(testsFromRoot, 'test/main', {
transform: (filePath) => makeTransform(filePath, pkg.main)
})
task(testsFromRoot, 'test/browser', {
transform: (filePath) => makeTransform(filePath, pkg.browser.replace('.js', '.cjs.js'))
})

View File

@@ -0,0 +1,21 @@
// rollup.config.js
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import alias from 'rollup-plugin-alias';
const substituteModulePaths = {
'crypto': 'build/module/adapters/crypto.browser.js',
'hash.js': 'build/temp/hash.js'
}
export default {
entry: 'build/module/index.js',
sourceMap: true,
plugins: [
alias(substituteModulePaths),
nodeResolve({
browser: true
}),
commonjs()
]
}

View File

@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "../../build/module",
"rootDir": "../../src",
"module": "es6",
"declaration": false
}
}