Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename --ts flag to --ts-repo and fix ts repo support #730

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion src/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/config/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const config = (searchFrom) => {
// global options
debug: false,
node: false,
ts: false,
tsRepo: false,
// old options
webpack: {},
karma: {},
Expand Down
2 changes: 1 addition & 1 deletion src/test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
4 changes: 2 additions & 2 deletions src/test/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()]))
Expand Down Expand Up @@ -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
}
})
Expand Down
36 changes: 18 additions & 18 deletions src/test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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',
Expand All @@ -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))),
Expand All @@ -100,7 +100,7 @@ function testNode (ctx, execaOptions) {
)
)
})
.then(() => postHook(ctx))
.then(() => postHook(argv))
}

module.exports = testNode
49 changes: 11 additions & 38 deletions src/ts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/

/**
Expand All @@ -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') {
Expand Down Expand Up @@ -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, '../..'),
Expand Down Expand Up @@ -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(
Expand All @@ -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'
Expand All @@ -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', '')
}