diff --git a/packages/server/lib/plugins/preprocessor.coffee b/packages/server/lib/plugins/preprocessor.coffee index c36f8e93dedc..3992edfb1939 100644 --- a/packages/server/lib/plugins/preprocessor.coffee +++ b/packages/server/lib/plugins/preprocessor.coffee @@ -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)); diff --git a/packages/server/lib/plugins/simple_tsify.js b/packages/server/lib/plugins/simple_tsify.js new file mode 100644 index 000000000000..cfca435af373 --- /dev/null +++ b/packages/server/lib/plugins/simple_tsify.js @@ -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() + }) +} diff --git a/packages/server/lib/project.js b/packages/server/lib/project.js index 9e43611f2672..a920fe5ab003 100644 --- a/packages/server/lib/project.js +++ b/packages/server/lib/project.js @@ -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) => { diff --git a/packages/server/package.json b/packages/server/package.json index 1a649dd3fedd..73fc7272fdf3 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -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",