feat(browser): add browser build, tests, and sample sha256 library method
This commit is contained in:
37
config/exports/build-tests.js
Normal file
37
config/exports/build-tests.js
Normal 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'))
|
||||
})
|
||||
21
config/exports/rollup.config.js
Normal file
21
config/exports/rollup.config.js
Normal 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()
|
||||
]
|
||||
}
|
||||
9
config/exports/tsconfig.module.json
Normal file
9
config/exports/tsconfig.module.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../build/module",
|
||||
"rootDir": "../../src",
|
||||
"module": "es6",
|
||||
"declaration": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user