Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit fb2f417

Browse files
authored
fix: Handle function transforms when typescript is set (#57)
Fixes #56.
1 parent 0b94fc5 commit fb2f417

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const getBrowserifyOptions = async (entry, userBrowserifyOptions = {}, typescrip
117117
}
118118

119119
const transform = browserifyOptions.transform
120-
const hasTsifyTransform = transform.some(([name]) => name.includes('tsify'))
120+
const hasTsifyTransform = transform.some((stage) => Array.isArray(stage) && stage[0].includes('tsify'))
121121
const hastsifyPlugin = browserifyOptions.plugin.includes('tsify')
122122

123123
if (hasTsifyTransform || hastsifyPlugin) {
@@ -136,7 +136,7 @@ Please do one of the following:
136136

137137
browserifyOptions.extensions.push('.ts', '.tsx')
138138
// remove babelify setting
139-
browserifyOptions.transform = transform.filter(([name]) => !name.includes('babelify'))
139+
browserifyOptions.transform = transform.filter((stage) => !Array.isArray(stage) || !stage[0].includes('babelify'))
140140
// add typescript compiler
141141
browserifyOptions.transform.push([
142142
path.join(__dirname, './lib/simple_tsify'), {

test/unit/index_spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,21 @@ describe('browserify preprocessor', function () {
380380
})
381381
})
382382

383+
// Regression test for cypress-io/cypress-browserify-preprocessor#56
384+
it('handles transforms defined as functions', function () {
385+
this.createWriteStreamApi.on.withArgs('finish').yields()
386+
387+
const transform = [() => { }, {}]
388+
389+
this.options.browserifyOptions = { transform }
390+
391+
return this.run().then(() => {
392+
transform.forEach((stage, stageIndex) => {
393+
expect(browserify.lastCall.args[0].transform[stageIndex]).to.eql(stage)
394+
})
395+
})
396+
})
397+
383398
it('removes babelify transform', function () {
384399
this.createWriteStreamApi.on.withArgs('finish').yields()
385400

0 commit comments

Comments
 (0)