Skip to content

Commit

Permalink
fix(build): Windows path issue resolved for testing platform
Browse files Browse the repository at this point in the history
  • Loading branch information
mitch-b committed Sep 26, 2017
1 parent 58ee72a commit 5b059c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
22 changes: 15 additions & 7 deletions config/exports/build-tests.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
// 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 isWin = /^win/.test(process.platform);
const Transform = require("stream").Transform;
const path = require('path');
const pkg = require('../../package');
const req = (path) => 'require("' + path + '")';
const pathUp = (levels) => Array.from(Array(levels), () => '../').join('');
const req = (modulePath) => 'require("' + modulePath + '")';
const calculatedSeparator = isWin ? '\\\\' : '/';
const pathUp = (levels) => Array.from(Array(levels), () => '..' + calculatedSeparator).join('');
const normalizePath = (filePath) => filePath.replace(/\//g, calculatedSeparator);

// replace instances of pkg.name with the proper route to the build being tested
const makeTransform = (filePath, buildPath) => {
const buildPathParts = buildPath.split(separator);
if (isWin) {
filePath = normalizePath(filePath);
buildPath = normalizePath(buildPath);
}

const buildPathParts = buildPath.split(calculatedSeparator);
// 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 pathToRoot = pathUp(filePath.split(calculatedSeparator).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 parts = str.split(placeholder);
const newPath = req(pathToRoot + buildPath);
const result = parts.join(newPath);
this.push(result);
done();
Expand Down
7 changes: 0 additions & 7 deletions config/exports/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
// 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
}),
Expand Down

0 comments on commit 5b059c3

Please sign in to comment.