Skip to content

Commit

Permalink
Realized I need to set the testing ts transpilation config module to …
Browse files Browse the repository at this point in the history
…'commonjs' or you can't get any of the benefits of writing your test in TypeScript. mb.
  • Loading branch information
jcjolley committed Oct 26, 2017
1 parent 14ea15b commit becdcd3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions dist/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ function transpile(program, filename) {
}
exports.transpile = transpile;
function transpileTest(program, testFileName) {
const testConfig = config;
const testConfig = { compilerOptions: Object.assign({}, config.compilerOptions, { module: 'commonjs' }) };
const fileStr = fs.readFileSync(testFileName, 'utf8');
const transpiledCode = ts.transpileModule(fileStr, testConfig).outputText;
fs.writeFileSync(`${testFileName.slice(0, -3)}.js`, transpiledCode);
const preparedCode = transpiledCode.split('\n').slice(1).join('\n');
fs.writeFileSync(`${testFileName.slice(0, -3)}.js`, preparedCode);
}
exports.transpileTest = transpileTest;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "muddler",
"version": "1.5.8",
"version": "1.5.9",
"description": "A minifier for hackmud scripts",
"main": "muddle.js",
"repository": {
Expand Down
5 changes: 3 additions & 2 deletions src/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export function transpile(program, filename) {
}

export function transpileTest(program, testFileName) {
const testConfig = config //{compilerOptions: {...config.compilerOptions, module: 'commonjs'}}
const testConfig = {compilerOptions: {...config.compilerOptions, module: 'commonjs'}}
const fileStr = fs.readFileSync(testFileName, 'utf8');
const transpiledCode = ts.transpileModule(fileStr, testConfig as any).outputText;
fs.writeFileSync(`${testFileName.slice(0,-3)}.js`, transpiledCode)
const preparedCode = transpiledCode.split('\n').slice(1).join('\n') // remove 'use strict'
fs.writeFileSync(`${testFileName.slice(0,-3)}.js`, preparedCode)
}

0 comments on commit becdcd3

Please sign in to comment.