From 5734c1af2ad653339d1f7124fe0db4bba7811293 Mon Sep 17 00:00:00 2001 From: Hugues Chabot Date: Mon, 9 Dec 2019 21:25:12 -0500 Subject: [PATCH] Add support for typescript with esModuleInterop --- lib/graph-script.js | 6 +++--- package.json | 2 +- test/script.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/graph-script.js b/lib/graph-script.js index 57276fe6..b25c9acd 100644 --- a/lib/graph-script.js +++ b/lib/graph-script.js @@ -59,6 +59,9 @@ function node (state, createEdge) { b.transform(sheetify) b.transform(glslify) + b.transform(brfs, { global: true }) + b.transform(nanohtml, { global: true }) + if (state.metadata.babelifyDeps) { // Dependencies should be transformed, but their .babelrc should be ignored. b.transform(tfilter(babelify, { include: /node_modules/ }), { @@ -86,9 +89,6 @@ function node (state, createEdge) { ] }) - b.transform(brfs, { global: true }) - b.transform(nanohtml, { global: true }) - if (!fullPaths) b.plugin(cssExtract, { out: bundleStyles }) // split-require does not support `fullPaths: true` at the moment. diff --git a/package.json b/package.json index 4930b388..8c76b8ee 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "keypress": "^0.2.1", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "nanohtml": "^1.2.4", + "nanohtml": "^1.7.0", "nanologger": "^2.0.0", "nanoraf": "^3.0.1", "nanotiming": "^7.2.0", diff --git a/test/script.js b/test/script.js index 345bba40..7dad7565 100644 --- a/test/script.js +++ b/test/script.js @@ -258,3 +258,34 @@ tape('envify in watch mode', function (assert) { compiler.graph.removeListener('change', next) } }) + +tape('apply nanohtml transform to scripts transpiled from typescript with esmoduleinterop', function (assert) { + assert.plan(3) + + var file = ` + "use strict"; + var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; + }; + Object.defineProperty(exports, "__esModule", { value: true }); + const choo_1 = __importDefault(require("choo")); + const html_1 = __importDefault(require("choo/html")); + const app = new choo_1.default(); + app.route('/', function () { + return html_1.default \`meow\`; + }); + module.exports = app.mount('body'); + ` + + var tmpDir = tmp.dirSync({ dir: path.join(__dirname, '../tmp'), unsafeCleanup: true }) + assert.on('end', tmpDir.removeCallback) + fs.writeFileSync(path.join(tmpDir.name, 'index.js'), file) + + var compiler = bankai(tmpDir.name, { watch: false }) + compiler.scripts('bundle.js', function (err, res) { + assert.ifError(err, 'no err bundling scripts') + var body = res.buffer.toString('utf8') + assert.equal(body.indexOf('html_1.default'), -1, 'choo/html is not used') + assert.equal(body.indexOf('meow'), -1, 'HTML string is tranformed') + }) +})