From 4542f0be9c76b2c79601411e0640a66ea970767c Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Tue, 26 Jan 2021 21:47:35 +0000 Subject: [PATCH] feat: rename --ts flag to --ts-repo and fix ts repo support - we need to rename the flag to avoid conflicts in the options object with the `ts` cmd - generate js files in TS repos --- cli.js | 8 ++++---- src/build/index.js | 2 +- src/config/user.js | 2 +- src/test/browser.js | 2 +- src/test/electron.js | 4 ++-- src/test/node.js | 36 ++++++++++++++++---------------- src/ts/index.js | 49 ++++++++++---------------------------------- 7 files changed, 38 insertions(+), 65 deletions(-) diff --git a/cli.js b/cli.js index be297adc8..9e18f62bd 100755 --- a/cli.js +++ b/cli.js @@ -46,12 +46,12 @@ cli describe: 'Flag to control if bundler should inject node globals or built-ins.', default: userConfig.node }) - .options('ts', { + .options('ts-repo', { type: 'boolean', - describe: 'Enable support for Typescript', - default: userConfig.ts // needs to be changed to another name to not conflict with the ts cmd options + describe: 'Enable support for Typescript repos.', + default: userConfig.tsRepo }) - .group(['help', 'version', 'debug', 'node', 'ts'], 'Global Options:') + .group(['help', 'version', 'debug', 'node', 'ts-repo'], 'Global Options:') .demandCommand(1, 'You need at least one command.') .wrap(cli.terminalWidth()) .parserConfiguration({ 'populate--': true }) diff --git a/src/build/index.js b/src/build/index.js index b71f77677..85790b212 100644 --- a/src/build/index.js +++ b/src/build/index.js @@ -39,7 +39,7 @@ module.exports = async (argv) => { NODE_ENV: process.env.NODE_ENV || 'production', AEGIR_BUILD_ANALYZE: argv.bundlesize, AEGIR_NODE: argv.node, - AEGIR_TS: argv.ts + AEGIR_TS: argv.tsRepo }, localDir: path.join(__dirname, '../..'), preferLocal: true, diff --git a/src/config/user.js b/src/config/user.js index 8180d4c57..e9254a9f5 100644 --- a/src/config/user.js +++ b/src/config/user.js @@ -54,7 +54,7 @@ const config = (searchFrom) => { // global options debug: false, node: false, - ts: false, + tsRepo: false, // old options webpack: {}, karma: {}, diff --git a/src/test/browser.js b/src/test/browser.js index 091a1d859..1fd949aba 100644 --- a/src/test/browser.js +++ b/src/test/browser.js @@ -41,7 +41,7 @@ module.exports = (argv, execaOptions) => { NODE_ENV: process.env.NODE_ENV || 'test', AEGIR_RUNNER: argv.webworker ? 'webworker' : 'browser', AEGIR_NODE: argv.node, - AEGIR_TS: argv.ts, + AEGIR_TS: argv.tsRepo, IS_WEBPACK_BUILD: true, ...hook.env }, diff --git a/src/test/electron.js b/src/test/electron.js index 3d10340e9..0c6a3483c 100644 --- a/src/test/electron.js +++ b/src/test/electron.js @@ -15,7 +15,7 @@ module.exports = (argv) => { const bail = argv.bail ? ['--bail', argv.bail] : [] const timeout = argv.timeout ? ['--timeout', argv.timeout] : [] const renderer = argv.renderer ? ['--renderer'] : [] - const ts = argv.ts ? ['--require', fromAegir('src/config/register.js')] : [] + const ts = argv.tsRepo ? ['--require', fromAegir('src/config/register.js')] : [] return hook('browser', 'pre')(argv.userConfig) .then((hook = {}) => Promise.all([hook, getElectron()])) @@ -43,7 +43,7 @@ module.exports = (argv) => { NODE_ENV: process.env.NODE_ENV || 'test', AEGIR_RUNNER: argv.renderer ? 'electron-renderer' : 'electron-main', ELECTRON_PATH: electronPath, - AEGIR_TS: argv.ts, + AEGIR_TS: argv.tsRepo, ...hook.env } }) diff --git a/src/test/node.js b/src/test/node.js index fee7c3492..8a2b75d1d 100644 --- a/src/test/node.js +++ b/src/test/node.js @@ -9,17 +9,17 @@ const DEFAULT_TIMEOUT = global.DEFAULT_TIMEOUT || 5 * 1000 /** @typedef { import("execa").Options} ExecaOptions */ -function testNode (ctx, execaOptions) { +function testNode (argv, execaOptions) { let exec = 'mocha' const env = { NODE_ENV: 'test', AEGIR_RUNNER: 'node', - AEGIR_TS: ctx.ts + AEGIR_TS: argv.tsRepo } - const timeout = ctx.timeout || DEFAULT_TIMEOUT + const timeout = argv.timeout || DEFAULT_TIMEOUT let args = [ - ctx.progress && '--reporter=progress', + argv.progress && '--reporter=progress', '--ui', 'bdd', '--timeout', timeout ].filter(Boolean) @@ -29,48 +29,48 @@ function testNode (ctx, execaOptions) { 'test/**/*.spec.{js,ts}' ] - if (ctx.colors) { + if (argv.colors) { args.push('--colors') } else { args.push('--no-colors') } - if (ctx.grep) { - args.push(`--grep=${ctx.grep}`) + if (argv.grep) { + args.push(`--grep=${argv.grep}`) } - if (ctx.invert) { + if (argv.invert) { args.push('--invert') } - if (ctx.files && ctx.files.length > 0) { - files = ctx.files + if (argv.files && argv.files.length > 0) { + files = argv.files } - if (ctx.verbose) { + if (argv.verbose) { args.push('--verbose') } - if (ctx.watch) { + if (argv.watch) { args.push('--watch') } - if (ctx.exit) { + if (argv.exit) { args.push('--exit') } - if (ctx.bail) { + if (argv.bail) { args.push('--bail') } - if (ctx.ts) { + if (argv.tsRepo) { args.push(...['--require', fromAegir('src/config/register.js')]) } const postHook = hook('node', 'post') const preHook = hook('node', 'pre') - if (ctx['100']) { + if (argv['100']) { args = [ '--check-coverage', '--branches=100', @@ -82,7 +82,7 @@ function testNode (ctx, execaOptions) { exec = 'nyc' } - return preHook(ctx) + return preHook(argv) .then((hook = {}) => { return execa(exec, args.concat(files.map((p) => path.normalize(p))), @@ -100,7 +100,7 @@ function testNode (ctx, execaOptions) { ) ) }) - .then(() => postHook(ctx)) + .then(() => postHook(argv)) } module.exports = testNode diff --git a/src/ts/index.js b/src/ts/index.js index 0bfbeb9a8..a5aaecd4f 100644 --- a/src/ts/index.js +++ b/src/ts/index.js @@ -5,7 +5,7 @@ const execa = require('execa') const fs = require('fs-extra') const globby = require('globby') const merge = require('merge-options') -const { fromRoot, fromAegir, hasFile, readJson } = require('../utils') +const { fromRoot, hasFile, readJson } = require('../utils') const hasConfig = hasFile('tsconfig.json') /** * @typedef {import("yargs").Argv} Argv @@ -14,6 +14,7 @@ const hasConfig = hasFile('tsconfig.json') * @property {"config" | "check" | "types" | "docs"} preset * @property {string[]} forwardOptions - Extra options to forward to the backend * @property {string[]} extraInclude - Extra include files for the TS Config + * @property {boolean} tsRepo - Typescript repo support. */ /** @@ -26,7 +27,8 @@ module.exports = async (argv) => { const opts = { forwardOptions: argv['--'] ? argv['--'] : [], extraInclude: (argv.include && argv.include.length > 0) ? await globby(argv.include) : [], - preset: argv.preset + preset: argv.preset, + tsRepo: argv.tsRepo } if (argv.preset === 'config') { @@ -62,8 +64,6 @@ module.exports = async (argv) => { return check(userTSConfig, opts) case 'types': return types(userTSConfig, opts) - case 'docs': - return docs(userTSConfig, opts) default: return execa('tsc', ['--build', ...opts.forwardOptions], { localDir: path.join(__dirname, '../..'), @@ -111,7 +111,7 @@ const check = async (userTSConfig, { extraInclude, forwardOptions }) => { * @param {any} userTSConfig * @param {Options} opts */ -const types = async (userTSConfig, { extraInclude, forwardOptions }) => { +const types = async (userTSConfig, opts) => { const configPath = fromRoot('tsconfig-types.aegir.json') try { fs.writeJsonSync( @@ -120,15 +120,17 @@ const types = async (userTSConfig, { extraInclude, forwardOptions }) => { userTSConfig, { compilerOptions: { - noEmit: false, - emitDeclarationOnly: true + noEmit: !opts.tsRepo, + emitDeclarationOnly: !opts.tsRepo, + declaration: true, + declarationMap: true }, - include: extraInclude, + include: opts.extraInclude, exclude: ['test'] } ]) ) - await execa('tsc', ['--build', configPath, ...forwardOptions], { + await execa('tsc', ['--build', configPath, ...opts.forwardOptions], { localDir: path.join(__dirname, '../..'), preferLocal: true, stdio: 'inherit' @@ -143,32 +145,3 @@ const types = async (userTSConfig, { extraInclude, forwardOptions }) => { fs.removeSync(fromRoot('dist', 'tsconfig-types.aegir.tsbuildinfo')) } } - -/** - * Docs preset - * - * @param {any} userTSConfig - * @param {Options} opts - */ -const docs = async (userTSConfig, opts) => { - // run typedoc - await execa( - 'typedoc', - [ - fromRoot('src/index.js'), - '--out', 'docs', - '--hideGenerator', - '--includeVersion', - '--gitRevision', 'master', - '--plugin', fromAegir('src/ts/typedoc-plugin.js') - ], - { - localDir: path.join(__dirname, '..'), - preferLocal: true, - stdio: 'inherit' - } - ) - - // write .nojekyll file - fs.writeFileSync('docs/.nojekyll', '') -}