Skip to content

Commit

Permalink
Don't use bundled typescript.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Dec 16, 2019
1 parent 848c6ad commit 25ee491
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 93 deletions.
45 changes: 17 additions & 28 deletions packages/server/lib/plugins/preprocessor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,26 @@ setDefaultPreprocessor = (config) ->
debug("set default preprocessor")

browserify = require("@cypress/browserify-preprocessor")
# ## Commented out for test. It will be removed in the final version.
# plugins.register("file:preprocessor", browserify({
# browserifyOptions: {
# extensions: ['.ts', '.tsx'],
# plugin: [
# [resolve.sync('tsify', {
# baseDir: __dirname
# }), {
# typescript: resolve.sync('typescript', {
# baseDir: config.projectRoot,
# })
# }]
# ]
# }
# }))

options = browserify.defaultOptions;
options.browserifyOptions.extensions.push('.ts', '.tsx');
babelifyConfig = options.browserifyOptions.transform[1][1];

resolveTypeScript = ->
try
return resolve.sync('@babel/preset-typescript', {
baseDir: config.projectRoot
})
catch
return resolve.sync('@babel/preset-typescript', {
baseDir: __dirname
resolveTypeScript = () ->
try
resolve.sync('typescript', {
baseDir: config.projectRoot,
})

babelifyConfig.presets.push(resolveTypeScript());
babelifyConfig.extensions = ['.js', '.jsx', '.ts', '.tsx'];
catch
return null

tsPath = resolveTypeScript()

if tsPath isnt null
options.browserifyOptions.extensions.push('.ts', '.tsx');
options.browserifyOptions.transform.push([
path.join(__dirname, './simple_tsify'), {
typescript: require(tsPath),
},
])

plugins.register("file:preprocessor", browserify(options));

Expand Down
13 changes: 13 additions & 0 deletions packages/server/lib/plugins/simple_tsify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let through = require('through2')

module.exports = function (b, opts) {
return through(function (buf, enc, next) {
const ts = opts.typescript

this.push(ts.transpileModule(buf.toString(), {
compilerOptions: {},
}).outputText)

next()
})
}
76 changes: 13 additions & 63 deletions packages/server/lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,72 +105,22 @@ class Project extends EE {
return scaffold.plugins(path.dirname(cfg.pluginsFile), cfg)
}
}).then((cfg) => {
const setupNodePath = path.join(
this.projectRoot,
cfg.nodeSetupFile
)

return fs.pathExists(setupNodePath)
.then((exists) => {
// TODO: This part is commented out because packages/server didn't turn on
// 'strict' option for TypeScript.
// When 'strict' is on, the cypress will fail because of implicit `any`s in
// packages/server code, not in users' code.
// So, when 'strict' is turned on for packages/server, it should be revisited.
// if (exists) {
// debug('custom node setup file exists at %s', setupNodePath)

// const setupNode = require(setupNodePath)

// setupNode()

// return
// }

const resolveProjectTypeScript = () => {
try {
return resolve.sync('typescript', {
basedir: this.projectRoot,
})
} catch (e) {
return undefined
}
}

debug('typescript option value: %s', cfg.typescript)

if (cfg.typescript === 'project') {
const tsPath = resolveProjectTypeScript()

debug('typescript path: %s', tsPath)

if (tsPath) {
tsnode.register({
compiler: tsPath,
transpileOnly: true,
})
} else {
throw new Error(`The value of 'typescript' option is 'project', but typescript is not set up in the project.`)
}
} else if (cfg.typescript === 'bundled') {
tsnode.register({
transpileOnly: true,
})
} else if (cfg.typescript === 'none') {
// Do nothing
} else {
const tsPath = resolveProjectTypeScript()
try {
const tsPath = resolve.sync('typescript', {
basedir: this.projectRoot,
})

debug('typescript path: %s', tsPath)
debug('typescript path: %s', tsPath)

tsnode.register({
compiler: tsPath,
transpileOnly: true,
})
}
tsnode.register({
compiler: tsPath,
transpileOnly: true,
})
} catch (e) {
debug(`typescript doesn't exist. ts-node setup passed.`)
}

return cfg
})
return cfg
}).then((cfg) => {
return this._initPlugins(cfg, options)
.then((modifiedCfg) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@
"strip-ansi": "3.0.1",
"syntax-error": "1.4.0",
"term-size": "2.1.0",
"through2": "^2.0.0",
"tough-cookie": "3.0.1",
"trash": "5.2.0",
"ts-node": "8.5.4",
"tsify": "4.0.1",
"typescript": "3.7.2",
"underscore": "1.9.1",
"underscore.string": "3.3.5",
"url-parse": "1.4.7",
Expand Down

0 comments on commit 25ee491

Please sign in to comment.