@betterer/cli
Advanced tools
Comparing version 5.4.0 to 6.0.0-alpha.1
@@ -1,2 +0,2 @@ | ||
import { Command } from 'commander'; | ||
import type { Command } from 'commander'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Run **Betterer** in `ci` mode. |
@@ -1,17 +0,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ci = void 0; | ||
const betterer_1 = require("@betterer/betterer"); | ||
const options_1 = require("./options"); | ||
const types_1 = require("./types"); | ||
import { betterer } from '@betterer/betterer'; | ||
import { ciCommand } from './options.js'; | ||
/** | ||
* Run **Betterer** in `ci` mode. | ||
*/ | ||
function ci(cwd) { | ||
const command = (0, options_1.cliCommand)(types_1.BettererCommand.ci); | ||
export function ci(cwd) { | ||
const command = ciCommand(); | ||
command.description('run Betterer in CI mode'); | ||
command.action(async (config, command) => { | ||
(0, options_1.setEnv)(config); | ||
// Mark options as unknown... | ||
const options = { | ||
// Cast the options to BettererOptions. This is possibly invalid, | ||
// but it's nicer to do the validation in @betterer/betterer | ||
const { error } = await betterer({ | ||
basePath: config.basePath, | ||
cache: config.cache, | ||
@@ -25,23 +22,16 @@ cachePath: config.cachePath, | ||
includes: command.args, | ||
logo: config.logo, | ||
reporters: config.reporter, | ||
repoPath: config.repoPath, | ||
resultsPath: config.results, | ||
silent: config.silent, | ||
tsconfigPath: config.tsconfig, | ||
strictDeadlines: config.strictDeadlines, | ||
workers: config.workers | ||
}; | ||
try { | ||
// And then cast to BettererOptionsStart. This is possibly invalid, | ||
// but it's nicer to do the options validation in @betterer/betterer | ||
const suiteSummary = await (0, betterer_1.betterer)(options); | ||
if (suiteSummary.changed.length > 0 || suiteSummary.failed.length > 0) { | ||
process.exitCode = 1; | ||
} | ||
}); | ||
if (error) { | ||
throw error; | ||
} | ||
catch (_a) { | ||
process.exitCode = 1; | ||
} | ||
}); | ||
return command; | ||
} | ||
exports.ci = ci; | ||
//# sourceMappingURL=ci.js.map |
@@ -1,2 +0,2 @@ | ||
import { BettererCLIArguments } from './types'; | ||
import type { BettererCLIArguments } from './types.js'; | ||
/** | ||
@@ -7,3 +7,3 @@ * @internal This could change at any point! Please don't use! | ||
*/ | ||
export declare function cli__(cwd: string, argv: BettererCLIArguments, isCI?: boolean): Promise<void>; | ||
export declare function cliΔ(cwd: string, argv: BettererCLIArguments, isCI?: boolean, isTest?: boolean): Promise<void>; | ||
//# sourceMappingURL=cli.d.ts.map |
@@ -1,19 +0,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.cli__ = void 0; | ||
const commander_1 = require("commander"); | ||
const ci_1 = require("./ci"); | ||
const init_1 = require("./init"); | ||
const merge_1 = require("./merge"); | ||
const precommit_1 = require("./precommit"); | ||
const start_1 = require("./start"); | ||
const results_1 = require("./results"); | ||
const types_1 = require("./types"); | ||
const watch_1 = require("./watch"); | ||
const upgrade_1 = require("./upgrade"); | ||
// HACK: | ||
// It's easier to use require than to try to get `await import` | ||
// to work right for the package.json... | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const { version } = require('../package.json'); | ||
import { isBettererErrorΔ } from '@betterer/errors'; | ||
import { Command } from 'commander'; | ||
import { ci } from './ci.js'; | ||
import { init } from './init.js'; | ||
import { merge } from './merge.js'; | ||
import { precommit } from './precommit.js'; | ||
import { start } from './start.js'; | ||
import { results } from './results.js'; | ||
import { BettererCommand } from './types.js'; | ||
import { watch } from './watch.js'; | ||
import { upgrade } from './upgrade.js'; | ||
import { getVersion } from './version.js'; | ||
/** | ||
@@ -24,30 +18,71 @@ * @internal This could change at any point! Please don't use! | ||
*/ | ||
async function cli__(cwd, argv, isCI = process.env.CI === 'true') { | ||
const program = new commander_1.Command('Betterer'); | ||
export async function cliΔ(cwd, argv, isCI = process.env.CI === 'true', isTest = process.env.TEST === 'true') { | ||
const program = new Command('Betterer'); | ||
const version = await getVersion(); | ||
program.version(version); | ||
// Init: | ||
program.addCommand((0, init_1.init)(cwd)); | ||
program.addCommand(init(cwd)); | ||
// Run: | ||
program.addCommand((0, start_1.start)(cwd, isCI)); | ||
program.addCommand((0, watch_1.watch)(cwd)); | ||
program.addCommand(start(cwd, isCI)); | ||
program.addCommand(watch(cwd)); | ||
// Precommit: | ||
// Throw if test run is worse, `git add` if better | ||
program.addCommand((0, precommit_1.precommit)(cwd)); | ||
program.addCommand(precommit(cwd)); | ||
// CI: | ||
// Throw if test run creates a diff | ||
program.addCommand((0, ci_1.ci)(cwd)); | ||
program.addCommand(ci(cwd)); | ||
// Merge: | ||
program.addCommand((0, merge_1.merge)(cwd)); | ||
program.addCommand(merge(cwd)); | ||
// Results: | ||
program.addCommand((0, results_1.results)(cwd)); | ||
program.addCommand(results(cwd)); | ||
// Upgrade: | ||
program.addCommand((0, upgrade_1.upgrade)(cwd)); | ||
program.addCommand(upgrade(cwd)); | ||
const args = argv.slice(0); | ||
const [, , command] = args; | ||
if (!types_1.BettererCommand[command]) { | ||
args.splice(2, 0, types_1.BettererCommand.start); | ||
// `BettererCommand` is an enum, so this conditional *is* necessary! | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- see above! | ||
if (!BettererCommand[command]) { | ||
args.splice(2, 0, BettererCommand.start); | ||
} | ||
await program.parseAsync(args); | ||
try { | ||
await program.parseAsync(args); | ||
} | ||
catch (error) { | ||
if (isBettererErrorΔ(error)) { | ||
error.details = flattenErrors(error.details); | ||
} | ||
if (!isTest) { | ||
/* v8 ignore next */ | ||
process.exitCode = 1; | ||
} | ||
throw error; | ||
} | ||
} | ||
exports.cli__ = cli__; | ||
function flattenErrors(details) { | ||
return details | ||
.flatMap((detail) => { | ||
if (isBettererErrorΔ(detail)) { | ||
const flattened = [detail, ...flattenErrors(detail.details)]; | ||
detail.details = []; | ||
return flattened; | ||
} | ||
return detail; | ||
}) | ||
.map((detail) => { | ||
const error = new Error(); | ||
if (isError(detail)) { | ||
error.message = detail.message; | ||
error.name = detail.name; | ||
error.stack = detail.stack; | ||
} | ||
else { | ||
error.message = detail; | ||
} | ||
return error; | ||
}); | ||
} | ||
function isError(value) { | ||
const { message, stack } = value; | ||
return message != null && stack != null; | ||
} | ||
//# sourceMappingURL=cli.js.map |
@@ -10,4 +10,4 @@ /** | ||
*/ | ||
export { cli__ } from './cli'; | ||
export { BettererCLIArguments, BettererPackageJSON } from './types'; | ||
export type { BettererCLIArguments, BettererPackageJSON } from './types.js'; | ||
export { cliΔ } from './cli.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -11,6 +10,3 @@ * CLI module for {@link https://github.com/phenomnomnominal/betterer | **Betterer**}. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.cli__ = void 0; | ||
var cli_1 = require("./cli"); | ||
Object.defineProperty(exports, "cli__", { enumerable: true, get: function () { return cli_1.cli__; } }); | ||
export { cliΔ } from './cli.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { Command } from 'commander'; | ||
import type { Command } from 'commander'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Run the **Betterer** `init` command to initialise **Betterer** in a new project. |
@@ -1,28 +0,20 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.init = void 0; | ||
const tslib_1 = require("tslib"); | ||
const render_1 = require("@betterer/render"); | ||
const path_1 = (0, tslib_1.__importDefault)(require("path")); | ||
const init_1 = require("./init/init"); | ||
const options_1 = require("./options"); | ||
import { React, getRenderOptionsΔ, render } from '@betterer/render'; | ||
import path from 'node:path'; | ||
import { Init } from './init/init.js'; | ||
import { initCommand } from './options.js'; | ||
const BETTERER_TS = './.betterer.ts'; | ||
const BETTERER_RESULTS = './.betterer.results'; | ||
const TS_EXTENSION = '.ts'; | ||
/** | ||
* Run the **Betterer** `init` command to initialise **Betterer** in a new project. | ||
*/ | ||
function init(cwd) { | ||
const command = (0, options_1.initCommand)(); | ||
export function init(cwd) { | ||
const command = initCommand(); | ||
command.description('init Betterer in a project'); | ||
command.action(async (config) => { | ||
(0, options_1.setEnv)(config); | ||
const RENDER_OPTIONS = { | ||
debug: process.env.NODE_ENV === 'test' | ||
}; | ||
const finalConfig = config.config || BETTERER_TS; | ||
const finalRepo = config.repoPath || cwd; | ||
const finalResults = config.results || BETTERER_RESULTS; | ||
const ext = path_1.default.extname(finalConfig); | ||
const ts = ext === TS_EXTENSION; | ||
const app = (0, render_1.render)(render_1.React.createElement(init_1.Init, { automerge: config.automerge, configPath: finalConfig, cwd: cwd, resultsPath: finalResults, ts: ts }), RENDER_OPTIONS); | ||
const ext = path.extname(finalConfig); | ||
const ts = ext === path.extname(BETTERER_TS); | ||
const app = render(React.createElement(Init, { automerge: config.automerge, configPath: finalConfig, cwd: cwd, logo: config.logo, repoPath: finalRepo, resultsPath: finalResults, ts: ts }), getRenderOptionsΔ(process.env.NODE_ENV)); | ||
await app.waitUntilExit(); | ||
@@ -32,3 +24,2 @@ }); | ||
} | ||
exports.init = init; | ||
//# sourceMappingURL=init.js.map |
@@ -1,3 +0,3 @@ | ||
/// <reference types="react" /> | ||
import { FC } from '@betterer/render'; | ||
import type { FC } from '@betterer/render'; | ||
/** @knipignore used by an exported function */ | ||
export interface InitProps { | ||
@@ -7,2 +7,4 @@ automerge: boolean; | ||
cwd: string; | ||
logo: boolean; | ||
repoPath: string; | ||
resultsPath: string; | ||
@@ -9,0 +11,0 @@ ts: boolean; |
@@ -1,12 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Init = void 0; | ||
const render_1 = require("@betterer/render"); | ||
const tasks_1 = require("@betterer/tasks"); | ||
const worker_require_1 = require("@phenomnomnominal/worker-require"); | ||
const Init = function Init({ automerge, cwd, configPath, resultsPath, ts }) { | ||
const runCreateTestFile = (0, render_1.useCallback)(async (logger) => { | ||
const createTestFile = (0, worker_require_1.workerRequire)('./create-test-file'); | ||
import { Box, React, useCallback } from '@betterer/render'; | ||
import { BettererLogo, BettererTaskLogger, BettererTasksLogger } from '@betterer/tasks'; | ||
import { exposeToWorkerΔ, importWorkerΔ } from '@betterer/worker'; | ||
export const Init = function Init({ automerge, cwd, configPath, logo, repoPath, resultsPath, ts }) { | ||
const runCreateTestFile = useCallback(async (logger, status) => { | ||
const createTestFile = await importWorkerΔ('./create-test-file.worker.js'); | ||
try { | ||
await createTestFile.run(logger, cwd, configPath, ts); | ||
await createTestFile.api.run(exposeToWorkerΔ(logger), exposeToWorkerΔ(status), cwd, configPath); | ||
} | ||
@@ -16,7 +13,7 @@ finally { | ||
} | ||
}, [cwd, configPath, ts]); | ||
const runUpdagePackageJSON = (0, render_1.useCallback)(async (logger) => { | ||
const updatePackageJSON = (0, worker_require_1.workerRequire)('./update-package-json'); | ||
}, [cwd, configPath]); | ||
const runUpdatePackageJSON = useCallback(async (logger, status) => { | ||
const updatePackageJSON = await importWorkerΔ('./update-package-json.worker.js'); | ||
try { | ||
await updatePackageJSON.run(logger, cwd, ts); | ||
await updatePackageJSON.api.run(exposeToWorkerΔ(logger), exposeToWorkerΔ(status), cwd, ts); | ||
} | ||
@@ -27,6 +24,6 @@ finally { | ||
}, [cwd, ts]); | ||
const runEnableAutomerge = (0, render_1.useCallback)(async (logger) => { | ||
const enableAutomerge = (0, worker_require_1.workerRequire)('./enable-automerge'); | ||
const runEnableAutomerge = useCallback(async (logger, status) => { | ||
const enableAutomerge = await importWorkerΔ('./enable-automerge.worker.js'); | ||
try { | ||
await enableAutomerge.run(logger, cwd, resultsPath); | ||
await enableAutomerge.api.run(exposeToWorkerΔ(logger), exposeToWorkerΔ(status), cwd, repoPath, resultsPath); | ||
} | ||
@@ -36,11 +33,10 @@ finally { | ||
} | ||
}, []); | ||
return (render_1.React.createElement(render_1.Box, { flexDirection: "column" }, | ||
render_1.React.createElement(tasks_1.BettererLogo, null), | ||
render_1.React.createElement(tasks_1.BettererTasksLogger, { name: "Initialising Betterer" }, | ||
render_1.React.createElement(tasks_1.BettererTaskLogger, { name: "Create test file", task: runCreateTestFile }), | ||
render_1.React.createElement(tasks_1.BettererTaskLogger, { name: "Update package.json", task: runUpdagePackageJSON }), | ||
automerge && render_1.React.createElement(tasks_1.BettererTaskLogger, { name: "Enable automerge", task: runEnableAutomerge })))); | ||
}, [cwd, resultsPath]); | ||
return (React.createElement(Box, { flexDirection: "column" }, | ||
logo && React.createElement(BettererLogo, null), | ||
React.createElement(BettererTasksLogger, { name: "Initialising Betterer" }, | ||
React.createElement(BettererTaskLogger, { name: "Create test file", task: runCreateTestFile }), | ||
React.createElement(BettererTaskLogger, { name: "Update package.json", task: runUpdatePackageJSON }), | ||
automerge && React.createElement(BettererTaskLogger, { name: "Enable automerge", task: runEnableAutomerge })))); | ||
}; | ||
exports.Init = Init; | ||
//# sourceMappingURL=init.js.map |
@@ -1,5 +0,5 @@ | ||
import { WorkerRequireModule } from '@phenomnomnominal/worker-require'; | ||
export declare type CreateTestFileWorker = WorkerRequireModule<typeof import('./create-test-file')>; | ||
export declare type EnableAutomergeWorker = WorkerRequireModule<typeof import('./enable-automerge')>; | ||
export declare type UpdatePackageJSONWorker = WorkerRequireModule<typeof import('./update-package-json')>; | ||
import type { BettererWorkerAPI } from '@betterer/worker'; | ||
export type CreateTestFileWorker = BettererWorkerAPI<typeof import('./create-test-file.worker')>; | ||
export type EnableAutomergeWorker = BettererWorkerAPI<typeof import('./enable-automerge.worker')>; | ||
export type UpdatePackageJSONWorker = BettererWorkerAPI<typeof import('./update-package-json.worker')>; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=types.js.map |
@@ -1,2 +0,2 @@ | ||
import { Command } from 'commander'; | ||
import type { Command } from 'commander'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Run the **Betterer** `merge` command to resolve any merge conflicts in the |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.merge = void 0; | ||
const betterer_1 = require("@betterer/betterer"); | ||
const options_1 = require("./options"); | ||
import { betterer } from '@betterer/betterer'; | ||
import { mergeCommand } from './options.js'; | ||
/** | ||
@@ -10,7 +7,6 @@ * Run the **Betterer** `merge` command to resolve any merge conflicts in the | ||
*/ | ||
function merge(cwd) { | ||
const command = (0, options_1.mergeCommand)(); | ||
export function merge(cwd) { | ||
const command = mergeCommand(); | ||
command.description('merge the Betterer results file'); | ||
command.action(async (config, command) => { | ||
(0, options_1.setEnv)(config); | ||
// Mark options as unknown... | ||
@@ -22,12 +18,6 @@ const options = { | ||
}; | ||
try { | ||
await betterer_1.betterer.merge(options); | ||
} | ||
catch (_a) { | ||
process.exitCode = 1; | ||
} | ||
await betterer.merge(options); | ||
}); | ||
return command; | ||
} | ||
exports.merge = merge; | ||
//# sourceMappingURL=merge.js.map |
import { Command } from 'commander'; | ||
import { BettererCLIEnvConfig, BettererCommand } from './types'; | ||
export declare function cliCommand(name: BettererCommand): Command; | ||
export declare function ciCommand(): Command; | ||
export declare function precommitCommand(): Command; | ||
export declare function startCommand(): Command; | ||
export declare function watchCommand(): Command; | ||
export declare function initCommand(): Command; | ||
@@ -8,3 +10,2 @@ export declare function mergeCommand(): Command; | ||
export declare function upgradeCommand(): Command; | ||
export declare function setEnv(config: BettererCLIEnvConfig): void; | ||
//# sourceMappingURL=options.d.ts.map |
@@ -1,9 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setEnv = exports.upgradeCommand = exports.resultsCommand = exports.mergeCommand = exports.initCommand = exports.cliCommand = void 0; | ||
const commander_1 = require("commander"); | ||
const types_1 = require("./types"); | ||
import { Command } from 'commander'; | ||
import { BettererCommand } from './types.js'; | ||
let command; | ||
function cliCommand(name) { | ||
command = new commander_1.Command(name); | ||
const DEPRECATED_V7 = 'This is now a noop and will be removed in v7.0.0 🚨'; | ||
export function ciCommand() { | ||
command = new Command(BettererCommand.ci); | ||
cacheOption(); | ||
@@ -13,7 +11,37 @@ configPathsOption(); | ||
filtersOption(); | ||
ignoresOption(); | ||
reportersOption(); | ||
pathOptions(); | ||
reportersOptions(); | ||
resultsPathOption(); | ||
silentOption(); | ||
strictDeadlinesOption(); | ||
tsconfigPathOption(); | ||
workersOption(); | ||
debug(); | ||
return command; | ||
} | ||
export function precommitCommand() { | ||
command = new Command(BettererCommand.precommit); | ||
cacheOption(); | ||
configPathsOption(); | ||
excludesOption(); | ||
filtersOption(); | ||
pathOptions(); | ||
reportersOptions(); | ||
resultsPathOption(); | ||
strictDeadlinesOption(); | ||
tsconfigPathOption(); | ||
workersOption(); | ||
debug(); | ||
return command; | ||
} | ||
export function startCommand() { | ||
command = new Command(BettererCommand.start); | ||
cacheOption(); | ||
configPathsOption(); | ||
excludesOption(); | ||
filtersOption(); | ||
pathOptions(); | ||
reportersOptions(); | ||
resultsPathOption(); | ||
strictOption(); | ||
strictDeadlinesOption(); | ||
tsconfigPathOption(); | ||
@@ -25,14 +53,28 @@ updateOption(); | ||
} | ||
exports.cliCommand = cliCommand; | ||
function initCommand() { | ||
command = new commander_1.Command(types_1.BettererCommand.init); | ||
export function watchCommand() { | ||
command = new Command(BettererCommand.watch); | ||
cacheOption(); | ||
configPathsOption(); | ||
filtersOption(); | ||
ignoresOption(); | ||
pathOptions(); | ||
reportersOptions(); | ||
resultsPathOption(); | ||
tsconfigPathOption(); | ||
workersOption(); | ||
debug(); | ||
return command; | ||
} | ||
export function initCommand() { | ||
command = new Command(BettererCommand.init); | ||
automergeOption(); | ||
configPathOption(); | ||
logoOption(); | ||
resultsPathOption(); | ||
repoPathOption(); | ||
debug(); | ||
return command; | ||
} | ||
exports.initCommand = initCommand; | ||
function mergeCommand() { | ||
command = new commander_1.Command(types_1.BettererCommand.merge); | ||
export function mergeCommand() { | ||
command = new Command(BettererCommand.merge); | ||
resultsPathOption(); | ||
@@ -42,8 +84,9 @@ debug(); | ||
} | ||
exports.mergeCommand = mergeCommand; | ||
function resultsCommand() { | ||
command = new commander_1.Command(types_1.BettererCommand.results); | ||
export function resultsCommand() { | ||
command = new Command(BettererCommand.results); | ||
configPathsOption(); | ||
excludesOption(); | ||
filtersOption(); | ||
logoOption(); | ||
pathOptions(); | ||
resultsPathOption(); | ||
@@ -53,6 +96,6 @@ debug(); | ||
} | ||
exports.resultsCommand = resultsCommand; | ||
function upgradeCommand() { | ||
command = new commander_1.Command(types_1.BettererCommand.upgrade); | ||
export function upgradeCommand() { | ||
command = new Command(BettererCommand.upgrade); | ||
configPathsOption(); | ||
logoOption(); | ||
saveOption(); | ||
@@ -62,18 +105,9 @@ debug(); | ||
} | ||
exports.upgradeCommand = upgradeCommand; | ||
function debug() { | ||
command.option('-d, --debug', 'Enable verbose debug logging', false); | ||
command.option('-l, --debug-log [value]', 'File path to save verbose debug logging to disk', './betterer.log'); | ||
command.option('-d, --debug', `Enable verbose debug logging. ${DEPRECATED_V7}`); | ||
command.option('-l, --debug-log [value]', `File path to save verbose debug logging to disk. ${DEPRECATED_V7}`); | ||
} | ||
function setEnv(config) { | ||
if (config.debug) { | ||
process.env.BETTERER_DEBUG = '1'; | ||
process.env.BETTERER_DEBUG_TIME = '1'; | ||
process.env.BETTERER_DEBUG_VALUES = '1'; | ||
if (config.debugLog) { | ||
process.env.BETTERER_DEBUG_LOG = config.debugLog; | ||
} | ||
} | ||
function tsconfigPathOption() { | ||
command.option('-t, --tsconfig [value]', `Path to TypeScript config file relative to CWD. ${DEPRECATED_V7}`); | ||
} | ||
exports.setEnv = setEnv; | ||
function cacheOption() { | ||
@@ -90,3 +124,3 @@ command.option('--cache', 'When present, Betterer will only run on changed files.'); | ||
function automergeOption() { | ||
command.option('--automerge', 'Enable automatic merging for the Betterer results file'); | ||
command.option('--automerge', 'Enable automatic merging for the Betterer results file. Only valid in a Git repository'); | ||
} | ||
@@ -96,5 +130,2 @@ function resultsPathOption() { | ||
} | ||
function tsconfigPathOption() { | ||
command.option('-t, --tsconfig [value]', 'Path to TypeScript config file relative to CWD'); | ||
} | ||
function filtersOption() { | ||
@@ -109,14 +140,19 @@ command.option('-f, --filter [value]', 'RegExp filter for tests to run. Add "!" at the start to negate. Takes multiple values', argsToArray); | ||
} | ||
function reportersOption() { | ||
function reportersOptions() { | ||
command.option('-R, --reporter [value]', 'npm package name for a Betterer reporter. Takes multiple values', argsToArray); | ||
command.option('-s, --silent', 'When present, all default reporters will be disabled. Custom reporters will still work normally.'); | ||
logoOption(); | ||
} | ||
function logoOption() { | ||
command.option('--logo', 'When set to `false` the default reporter will not emit a logo. Defaults to `true`', argsToPrimitive); | ||
} | ||
function saveOption() { | ||
command.option('--save', 'When present, Betterer will save the result of an upgrade to disk.'); | ||
} | ||
function silentOption() { | ||
command.option('-s, --silent', 'When present, all default reporters will be disabled. Custom reporters will still work normally.'); | ||
} | ||
function strictOption() { | ||
command.option('--strict', 'When present, the "how to update" message will not be shown and the `--update` option will be set to false.'); | ||
} | ||
function strictDeadlinesOption() { | ||
command.option('--strictDeadlines', 'When present, Betterer will throw an error if any tests have passed their deadline without meeting their goal.'); | ||
} | ||
function updateOption() { | ||
@@ -128,2 +164,12 @@ command.option('-u, --update', 'When present, the results file will be updated, even if things get worse.'); | ||
} | ||
function pathOptions() { | ||
basePathOption(); | ||
repoPathOption(); | ||
} | ||
function basePathOption() { | ||
command.option('--basePath [value]', 'The path to the directory containing the code to be covered by Betterer.'); | ||
} | ||
function repoPathOption() { | ||
command.option('--repoPath [value]', 'The path to the root of the repository.'); | ||
} | ||
function argsToArray(value, previous = []) { | ||
@@ -130,0 +176,0 @@ return previous.concat([value]); |
@@ -1,2 +0,2 @@ | ||
import { Command } from 'commander'; | ||
import type { Command } from 'commander'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Run **Betterer** in `precommit` mode. |
@@ -1,17 +0,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.precommit = void 0; | ||
const betterer_1 = require("@betterer/betterer"); | ||
const options_1 = require("./options"); | ||
const types_1 = require("./types"); | ||
import { betterer } from '@betterer/betterer'; | ||
import { precommitCommand } from './options.js'; | ||
/** | ||
* Run **Betterer** in `precommit` mode. | ||
*/ | ||
function precommit(cwd) { | ||
const command = (0, options_1.cliCommand)(types_1.BettererCommand.precommit); | ||
export function precommit(cwd) { | ||
const command = precommitCommand(); | ||
command.description('run Betterer in precommit mode'); | ||
command.action(async (config, command) => { | ||
(0, options_1.setEnv)(config); | ||
// Mark options as unknown... | ||
const options = { | ||
// Cast the options to BettererOptions. This is possibly invalid, | ||
// but it's nicer to do the validation in @betterer/betterer | ||
const { error } = await betterer({ | ||
basePath: config.basePath, | ||
cache: config.cache, | ||
@@ -24,24 +21,17 @@ cachePath: config.cachePath, | ||
includes: command.args, | ||
logo: config.logo, | ||
precommit: true, | ||
reporters: config.reporter, | ||
repoPath: config.repoPath, | ||
resultsPath: config.results, | ||
silent: config.silent, | ||
tsconfigPath: config.tsconfig, | ||
strictDeadlines: config.strictDeadlines, | ||
workers: config.workers | ||
}; | ||
try { | ||
// And then cast to BettererOptionsStart. This is possibly invalid, | ||
// but it's nicer to do the options validation in @betterer/betterer | ||
const suiteSummary = await (0, betterer_1.betterer)(options); | ||
if (suiteSummary.worse.length > 0 || suiteSummary.failed.length > 0) { | ||
process.exitCode = 1; | ||
} | ||
}); | ||
if (error) { | ||
throw error; | ||
} | ||
catch (_a) { | ||
process.exitCode = 1; | ||
} | ||
}); | ||
return command; | ||
} | ||
exports.precommit = precommit; | ||
//# sourceMappingURL=precommit.js.map |
@@ -1,2 +0,2 @@ | ||
import { Command } from 'commander'; | ||
import type { Command } from 'commander'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Run the **Betterer** `results` command to see the status of the {@link @betterer/betterer#BettererTest | `BettererTest`s} |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.results = void 0; | ||
const render_1 = require("@betterer/render"); | ||
const options_1 = require("./options"); | ||
const results_1 = require("./results/results"); | ||
import { React, getRenderOptionsΔ, render } from '@betterer/render'; | ||
import { resultsCommand } from './options.js'; | ||
import { Results } from './results/results.js'; | ||
/** | ||
@@ -11,12 +8,9 @@ * Run the **Betterer** `results` command to see the status of the {@link @betterer/betterer#BettererTest | `BettererTest`s} | ||
*/ | ||
function results(cwd) { | ||
const command = (0, options_1.resultsCommand)(); | ||
export function results(cwd) { | ||
const command = resultsCommand(); | ||
command.description(); | ||
command.action(async (config, command) => { | ||
(0, options_1.setEnv)(config); | ||
const RENDER_OPTIONS = { | ||
debug: process.env.NODE_ENV === 'test' | ||
}; | ||
// Mark options as unknown... | ||
const options = { | ||
basePath: config.basePath, | ||
configPaths: config.config, | ||
@@ -27,17 +21,12 @@ cwd, | ||
includes: command.args, | ||
repoPath: config.repoPath, | ||
resultsPath: config.results | ||
}; | ||
try { | ||
// And then cast to BettererOptionsResults. This is possibly invalid, | ||
// but it's nicer to do the options validation in @betterer/betterer | ||
const app = (0, render_1.render)(render_1.React.createElement(results_1.Results, { options: options }), RENDER_OPTIONS); | ||
await app.waitUntilExit(); | ||
} | ||
catch (_a) { | ||
process.exitCode = 1; | ||
} | ||
// And then cast to BettererOptionsResults. This is possibly invalid, | ||
// but it's nicer to do the options validation in @betterer/betterer | ||
const app = render(React.createElement(Results, { options: options, logo: config.logo }), getRenderOptionsΔ(process.env.NODE_ENV)); | ||
await app.waitUntilExit(); | ||
}); | ||
return command; | ||
} | ||
exports.results = results; | ||
//# sourceMappingURL=results.js.map |
@@ -1,8 +0,9 @@ | ||
/// <reference types="react" /> | ||
import { BettererOptionsResults } from '@betterer/betterer'; | ||
import { FC } from '@betterer/render'; | ||
import type { FC } from '@betterer/render'; | ||
import type { BettererOptionsResults } from '@betterer/betterer'; | ||
/** @knipignore used by an exported function */ | ||
export interface ResultsProps { | ||
options: BettererOptionsResults; | ||
logo: boolean; | ||
} | ||
export declare const Results: FC<ResultsProps>; | ||
//# sourceMappingURL=results.d.ts.map |
@@ -1,14 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Results = void 0; | ||
const render_1 = require("@betterer/render"); | ||
const worker_require_1 = require("@phenomnomnominal/worker-require"); | ||
const tasks_1 = require("@betterer/tasks"); | ||
const Results = function Results({ options }) { | ||
const [resultsSummary, setResultsSummary] = (0, render_1.useState)(null); | ||
(0, render_1.useEffect)(() => { | ||
import { React, Box, Text, useApp, useEffect, useState } from '@betterer/render'; | ||
import { BettererLogo } from '@betterer/tasks'; | ||
import { importWorkerΔ } from '@betterer/worker'; | ||
export const Results = function Results({ options, logo }) { | ||
const [resultsSummary, setResultsSummary] = useState(null); | ||
useEffect(() => { | ||
void (async () => { | ||
const getResultsSummary = (0, worker_require_1.workerRequire)('./get-results-summary'); | ||
const getResultsSummary = await importWorkerΔ('./get-results-summary.worker.js'); | ||
try { | ||
setResultsSummary(await getResultsSummary.run(options)); | ||
setResultsSummary(await getResultsSummary.api.run(options)); | ||
} | ||
@@ -20,32 +17,32 @@ finally { | ||
}, [options]); | ||
const app = (0, render_1.useApp)(); | ||
(0, render_1.useEffect)(() => { | ||
const app = useApp(); | ||
useEffect(() => { | ||
if (resultsSummary) { | ||
setImmediate(() => app.exit()); | ||
setImmediate(() => { | ||
app.exit(); | ||
}); | ||
} | ||
}, [resultsSummary]); | ||
return (render_1.React.createElement(render_1.Box, { flexDirection: "column" }, | ||
render_1.React.createElement(tasks_1.BettererLogo, null), | ||
resultsSummary && (render_1.React.createElement(render_1.Box, { flexDirection: "column" }, resultsSummary.resultSummaries.map((resultSummary) => { | ||
return (React.createElement(Box, { flexDirection: "column" }, | ||
logo && React.createElement(BettererLogo, null), | ||
resultsSummary && (React.createElement(Box, { flexDirection: "column" }, resultsSummary.resultSummaries.map((resultSummary) => { | ||
if (resultSummary.isFileTest) { | ||
return (render_1.React.createElement(render_1.Box, { key: resultSummary.name, flexDirection: "column" }, | ||
render_1.React.createElement(render_1.Text, { color: "yellowBright" }, `${resultSummary.name}: `), | ||
render_1.React.createElement(render_1.Box, { flexDirection: "column", paddingTop: 1, paddingLeft: 2 }, Object.keys(resultSummary.details).map((filePath) => { | ||
const issues = resultSummary.details[filePath]; | ||
return issues.map((issue, index) => (render_1.React.createElement(render_1.Box, { key: index }, | ||
render_1.React.createElement(render_1.Text, null, issue.message), | ||
render_1.React.createElement(render_1.Text, null, " - "), | ||
render_1.React.createElement(render_1.Text, { color: "cyan" }, filePath), | ||
render_1.React.createElement(render_1.Text, null, ":"), | ||
render_1.React.createElement(render_1.Text, { color: "yellow" }, issue.line + 1), | ||
render_1.React.createElement(render_1.Text, null, ":"), | ||
render_1.React.createElement(render_1.Text, { color: "yellow" }, issue.column)))); | ||
return (React.createElement(Box, { key: resultSummary.name, flexDirection: "column" }, | ||
React.createElement(Text, { color: "yellowBright" }, `${resultSummary.name}: `), | ||
React.createElement(Box, { flexDirection: "column", paddingTop: 1, paddingLeft: 2 }, Object.entries(resultSummary.details).map(([filePath, issues]) => { | ||
return issues.map((issue, index) => (React.createElement(Box, { key: index }, | ||
React.createElement(Text, null, issue.message), | ||
React.createElement(Text, null, " - "), | ||
React.createElement(Text, { color: "cyan" }, filePath), | ||
React.createElement(Text, null, ":"), | ||
React.createElement(Text, { color: "yellow" }, issue.line + 1), | ||
React.createElement(Text, null, ":"), | ||
React.createElement(Text, { color: "yellow" }, issue.column)))); | ||
})))); | ||
} | ||
return (render_1.React.createElement(render_1.Box, { key: resultSummary.name }, | ||
render_1.React.createElement(render_1.Text, { color: "yellowBright" }, `${resultSummary.name}: `), | ||
render_1.React.createElement(render_1.Text, null, resultSummary.details))); | ||
return (React.createElement(Box, { key: resultSummary.name }, | ||
React.createElement(Text, { color: "yellowBright" }, `${resultSummary.name}: `), | ||
React.createElement(Text, null, resultSummary.details))); | ||
}))))); | ||
}; | ||
exports.Results = Results; | ||
//# sourceMappingURL=results.js.map |
@@ -1,3 +0,3 @@ | ||
import { WorkerRequireModule } from '@phenomnomnominal/worker-require'; | ||
export declare type GetResultsSummaryWorker = WorkerRequireModule<typeof import('./get-results-summary')>; | ||
import type { BettererWorkerAPI } from '@betterer/worker'; | ||
export type GetResultsSummaryWorker = BettererWorkerAPI<typeof import('./get-results-summary.worker')>; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=types.js.map |
@@ -1,2 +0,2 @@ | ||
import { Command } from 'commander'; | ||
import type { Command } from 'commander'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Run **Betterer** in the default mode. |
@@ -1,17 +0,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.start = void 0; | ||
const betterer_1 = require("@betterer/betterer"); | ||
const options_1 = require("./options"); | ||
const types_1 = require("./types"); | ||
import { betterer } from '@betterer/betterer'; | ||
import { startCommand } from './options.js'; | ||
/** | ||
* Run **Betterer** in the default mode. | ||
*/ | ||
function start(cwd, ci) { | ||
const command = (0, options_1.cliCommand)(types_1.BettererCommand.start); | ||
export function start(cwd, ci) { | ||
const command = startCommand(); | ||
command.description('run Betterer'); | ||
command.action(async (config, command) => { | ||
(0, options_1.setEnv)(config); | ||
// Mark options as unknown... | ||
const options = { | ||
// Cast the options to BettererOptions. This is possibly invalid, | ||
// but it's nicer to do the validation in @betterer/betterer | ||
const { error } = await betterer({ | ||
basePath: config.basePath, | ||
cache: config.cache, | ||
@@ -25,25 +22,18 @@ cachePath: config.cachePath, | ||
includes: command.args, | ||
logo: config.logo, | ||
reporters: config.reporter, | ||
repoPath: config.repoPath, | ||
resultsPath: config.results, | ||
silent: config.silent, | ||
strict: config.strict, | ||
tsconfigPath: config.tsconfig, | ||
strictDeadlines: config.strictDeadlines, | ||
update: config.update, | ||
workers: config.workers | ||
}; | ||
try { | ||
// And then cast to BettererOptionsStart. This is possibly invalid, | ||
// but it's nicer to do the options validation in @betterer/betterer | ||
const suiteSummary = await (0, betterer_1.betterer)(options); | ||
if (suiteSummary.worse.length > 0 || suiteSummary.failed.length > 0) { | ||
process.exitCode = 1; | ||
} | ||
}); | ||
if (error) { | ||
throw error; | ||
} | ||
catch (_a) { | ||
process.exitCode = 1; | ||
} | ||
}); | ||
return command; | ||
} | ||
exports.start = start; | ||
//# sourceMappingURL=start.js.map |
@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard. | ||
"packageName": "@microsoft/api-extractor", | ||
"packageVersion": "7.18.20" | ||
"packageVersion": "7.47.7" | ||
} | ||
] | ||
} |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export declare type BettererCLIArguments = Array<string>; | ||
export type BettererCLIArguments = Array<string>; | ||
export declare enum BettererCommand { | ||
@@ -18,8 +18,5 @@ ci = "ci", | ||
} | ||
export declare type BettererCommandName = `${BettererCommand}`; | ||
export interface BettererCLIEnvConfig { | ||
debug: boolean; | ||
debugLog: string; | ||
} | ||
export interface BettererCLIConfig extends BettererCLIEnvConfig { | ||
export type BettererCommandName = `${BettererCommand}`; | ||
export interface BettererCLIConfig { | ||
basePath: string; | ||
cache: boolean; | ||
@@ -32,6 +29,9 @@ cachePath: string; | ||
include: BettererCLIArguments; | ||
logo: boolean; | ||
reporter: BettererCLIArguments; | ||
repoPath: string; | ||
results: string; | ||
silent: boolean; | ||
strict: boolean; | ||
strictDeadlines: boolean; | ||
tsconfig: string; | ||
@@ -41,12 +41,16 @@ update: boolean; | ||
} | ||
export interface BettererCLIInitConfig extends BettererCLIEnvConfig { | ||
export interface BettererCLIInitConfig { | ||
automerge: boolean; | ||
config: string; | ||
logo: boolean; | ||
repoPath: string; | ||
results: string; | ||
} | ||
export interface BettererCLIMergeConfig extends BettererCLIEnvConfig { | ||
export interface BettererCLIMergeConfig { | ||
contents: Array<string>; | ||
logo: boolean; | ||
results: string; | ||
contents: Array<string>; | ||
} | ||
export interface BettererCLIResultsConfig extends BettererCLIEnvConfig { | ||
export interface BettererCLIResultsConfig { | ||
basePath: string; | ||
config: BettererCLIArguments; | ||
@@ -56,6 +60,9 @@ exclude: BettererCLIArguments; | ||
include: BettererCLIArguments; | ||
logo: boolean; | ||
repoPath: string; | ||
results: string; | ||
} | ||
export interface BettererCLIUpgradeConfig extends BettererCLIEnvConfig { | ||
config: BettererCLIArguments; | ||
export interface BettererCLIUpgradeConfig { | ||
config?: BettererCLIArguments; | ||
logo: boolean; | ||
save: boolean; | ||
@@ -69,8 +76,15 @@ } | ||
export interface BettererPackageJSON { | ||
/** | ||
* the current version of the package | ||
*/ | ||
version: string; | ||
scripts: Record<string, string> & { | ||
betterer: string; | ||
}; | ||
devDependencies: Record<string, string>; | ||
/** | ||
* "scripts" will be updated to add new `betterer` run commands | ||
*/ | ||
scripts?: Record<string, string>; | ||
/** | ||
* "devDependencies" will be updated to add `betterer@latest` | ||
*/ | ||
devDependencies?: Record<string, string>; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BettererCommand = void 0; | ||
var BettererCommand; | ||
export var BettererCommand; | ||
(function (BettererCommand) { | ||
@@ -14,3 +11,3 @@ BettererCommand["ci"] = "ci"; | ||
BettererCommand["watch"] = "watch"; | ||
})(BettererCommand = exports.BettererCommand || (exports.BettererCommand = {})); | ||
})(BettererCommand || (BettererCommand = {})); | ||
//# sourceMappingURL=types.js.map |
@@ -1,2 +0,2 @@ | ||
import { Command } from 'commander'; | ||
import type { Command } from 'commander'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Run the **Betterer** `upgrade` command to upgrade **Betterer** in an existing project. |
@@ -1,20 +0,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.upgrade = void 0; | ||
const render_1 = require("@betterer/render"); | ||
const upgrade_1 = require("./upgrade/upgrade"); | ||
const options_1 = require("./options"); | ||
import { React, getRenderOptionsΔ, render } from '@betterer/render'; | ||
import { Upgrade } from './upgrade/upgrade.js'; | ||
import { upgradeCommand } from './options.js'; | ||
const DEFAULT_CONFIG_PATHS = ['./.betterer.ts']; | ||
/** | ||
* Run the **Betterer** `upgrade` command to upgrade **Betterer** in an existing project. | ||
*/ | ||
function upgrade(cwd) { | ||
const command = (0, options_1.upgradeCommand)(); | ||
export function upgrade(cwd) { | ||
const command = upgradeCommand(); | ||
command.description('upgrade Betterer files in a project'); | ||
command.action(async (config) => { | ||
(0, options_1.setEnv)(config); | ||
const RENDER_OPTIONS = { | ||
debug: process.env.NODE_ENV === 'test' | ||
}; | ||
const configPaths = config.config ? config.config : ['./.betterer.ts']; | ||
const app = (0, render_1.render)(render_1.React.createElement(upgrade_1.Upgrade, { configPaths: configPaths, cwd: cwd, save: config.save }), RENDER_OPTIONS); | ||
const configPaths = config.config ? config.config : DEFAULT_CONFIG_PATHS; | ||
const app = render(React.createElement(Upgrade, { configPaths: configPaths, cwd: cwd, save: config.save, logo: config.logo }), getRenderOptionsΔ(process.env.NODE_ENV)); | ||
await app.waitUntilExit(); | ||
@@ -24,3 +18,2 @@ }); | ||
} | ||
exports.upgrade = upgrade; | ||
//# sourceMappingURL=upgrade.js.map |
@@ -1,19 +0,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.diff = void 0; | ||
const logger_1 = require("@betterer/logger"); | ||
const chalk_1 = require("chalk"); | ||
import { diffStringsΔ } from '@betterer/logger'; | ||
import chalk from 'chalk'; | ||
const DIFF_OPTIONS = { | ||
aAnnotation: 'Before', | ||
aIndicator: '-', | ||
aColor: chalk_1.gray, | ||
aColor: chalk.gray, | ||
bAnnotation: 'After', | ||
bColor: chalk_1.greenBright, | ||
bColor: chalk.greenBright, | ||
bIndicator: '+', | ||
expand: true | ||
}; | ||
function diff(before, after) { | ||
return (0, logger_1.diffStrings__)(before, after, DIFF_OPTIONS); | ||
export function diff(before, after) { | ||
return diffStringsΔ(before, after, DIFF_OPTIONS); | ||
} | ||
exports.diff = diff; | ||
//# sourceMappingURL=diff.js.map |
@@ -1,3 +0,3 @@ | ||
import { WorkerRequireModule } from '@phenomnomnominal/worker-require'; | ||
export declare type UpgradeConfigFileWorker = WorkerRequireModule<typeof import('./upgrade-config-file')>; | ||
import type { BettererWorkerAPI } from '@betterer/worker'; | ||
export type UpgradeConfigFileWorker = BettererWorkerAPI<typeof import('./upgrade-config-file.worker.js')>; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=types.js.map |
@@ -1,3 +0,3 @@ | ||
import { SourceFile } from 'typescript'; | ||
import type { SourceFile } from 'typescript'; | ||
export declare function upgradeCJS(originalSourceFile: SourceFile, configPath: string): SourceFile; | ||
//# sourceMappingURL=upgrade-cjs.d.ts.map |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.upgradeCJS = void 0; | ||
const tsquery_1 = require("@phenomnomnominal/tsquery"); | ||
const typescript_1 = require("typescript"); | ||
const utils_1 = require("./utils"); | ||
import { tsquery } from '@phenomnomnominal/tsquery'; | ||
import { factory, isObjectLiteralExpression } from 'typescript'; | ||
import { reparse, wrapTest, wrapTests } from './utils.js'; | ||
// foo | ||
@@ -13,21 +10,20 @@ const TEST_NAME_QUERY = 'Identifier[name!=/module/][name!=/exports/]'; | ||
const EXPORT_TEST_QUERY = `BinaryExpression:has(BinaryExpression > PropertyAccessExpression:has(PropertyAccessExpression > ${TEST_NAME_QUERY}))`; | ||
function upgradeCJS(originalSourceFile, configPath) { | ||
let upgraded = (0, utils_1.reparse)(tsquery_1.tsquery.map(originalSourceFile, EXPORT_TESTS_QUERY, (configExports) => { | ||
export function upgradeCJS(originalSourceFile, configPath) { | ||
let upgraded = reparse(tsquery.map(originalSourceFile, EXPORT_TESTS_QUERY, (configExports) => { | ||
const { left, operatorToken, right } = configExports; | ||
if ((0, typescript_1.isObjectLiteralExpression)(right)) { | ||
return typescript_1.factory.createBinaryExpression(left, operatorToken, (0, utils_1.wrapTests)(right)); | ||
if (isObjectLiteralExpression(right)) { | ||
return factory.createBinaryExpression(left, operatorToken, wrapTests(right)); | ||
} | ||
return configExports; | ||
}), configPath); | ||
upgraded = (0, utils_1.reparse)(tsquery_1.tsquery.map(upgraded, EXPORT_TEST_QUERY, (configExportConst) => { | ||
upgraded = reparse(tsquery.map(upgraded, EXPORT_TEST_QUERY, (configExportConst) => { | ||
const { left, operatorToken, right } = configExportConst; | ||
const wrapped = !!right && (0, utils_1.wrapTest)(right); | ||
const wrapped = wrapTest(right); | ||
if (!wrapped) { | ||
return configExportConst; | ||
} | ||
return typescript_1.factory.createBinaryExpression(left, operatorToken, wrapped); | ||
return factory.createBinaryExpression(left, operatorToken, wrapped); | ||
}), configPath); | ||
return upgraded; | ||
} | ||
exports.upgradeCJS = upgradeCJS; | ||
//# sourceMappingURL=upgrade-cjs.js.map |
@@ -1,3 +0,3 @@ | ||
import { SourceFile } from 'typescript'; | ||
import type { SourceFile } from 'typescript'; | ||
export declare function upgradeESM(originalSourceFile: SourceFile, configPath: string): SourceFile; | ||
//# sourceMappingURL=upgrade-esm.d.ts.map |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.upgradeESM = void 0; | ||
const tsquery_1 = require("@phenomnomnominal/tsquery"); | ||
const typescript_1 = require("typescript"); | ||
const utils_1 = require("./utils"); | ||
import { tsquery } from '@phenomnomnominal/tsquery'; | ||
import { factory, isObjectLiteralExpression } from 'typescript'; | ||
import { reparse, wrapTest, wrapTests } from './utils.js'; | ||
// export const foo | ||
@@ -11,21 +8,20 @@ const EXPORT_TEST_QUERY = 'VariableStatement:has(ExportKeyword) VariableDeclaration'; | ||
const EXPORT_TESTS_QUERY = 'ExportAssignment:has(PropertyAssignment)'; | ||
function upgradeESM(originalSourceFile, configPath) { | ||
let upgraded = (0, utils_1.reparse)(tsquery_1.tsquery.map(originalSourceFile, EXPORT_TESTS_QUERY, (configExports) => { | ||
const { expression, decorators, modifiers, isExportEquals } = configExports; | ||
if ((0, typescript_1.isObjectLiteralExpression)(expression)) { | ||
return typescript_1.factory.createExportAssignment(decorators, modifiers, isExportEquals, (0, utils_1.wrapTests)(expression)); | ||
export function upgradeESM(originalSourceFile, configPath) { | ||
let upgraded = reparse(tsquery.map(originalSourceFile, EXPORT_TESTS_QUERY, (configExports) => { | ||
const { expression, modifiers, isExportEquals } = configExports; | ||
if (isObjectLiteralExpression(expression)) { | ||
return factory.createExportAssignment(modifiers, isExportEquals, wrapTests(expression)); | ||
} | ||
return configExports; | ||
}), configPath); | ||
upgraded = (0, utils_1.reparse)(tsquery_1.tsquery.map(upgraded, EXPORT_TEST_QUERY, (configExportConst) => { | ||
upgraded = reparse(tsquery.map(upgraded, EXPORT_TEST_QUERY, (configExportConst) => { | ||
const { name, exclamationToken, type, initializer } = configExportConst; | ||
const wrapped = !!initializer && (0, utils_1.wrapTest)(initializer); | ||
const wrapped = !!initializer && wrapTest(initializer); | ||
if (!wrapped) { | ||
return configExportConst; | ||
} | ||
return typescript_1.factory.createVariableDeclaration(name, exclamationToken, type, wrapped); | ||
return factory.createVariableDeclaration(name, exclamationToken, type, wrapped); | ||
}), configPath); | ||
return upgraded; | ||
} | ||
exports.upgradeESM = upgradeESM; | ||
//# sourceMappingURL=upgrade-esm.js.map |
@@ -1,7 +0,8 @@ | ||
/// <reference types="react" /> | ||
import { BettererConfigPaths } from '@betterer/betterer'; | ||
import { FC } from '@betterer/render'; | ||
import type { BettererConfigPaths } from '@betterer/betterer'; | ||
import type { FC } from '@betterer/render'; | ||
/** @knipignore used by an exported function */ | ||
export interface UpgradeProps { | ||
configPaths: BettererConfigPaths; | ||
cwd: string; | ||
logo: boolean; | ||
save: boolean; | ||
@@ -8,0 +9,0 @@ } |
@@ -1,17 +0,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Upgrade = void 0; | ||
const tslib_1 = require("tslib"); | ||
const render_1 = require("@betterer/render"); | ||
const tasks_1 = require("@betterer/tasks"); | ||
const worker_require_1 = require("@phenomnomnominal/worker-require"); | ||
const path = (0, tslib_1.__importStar)(require("path")); | ||
const Upgrade = function Upgrade({ configPaths, cwd, save }) { | ||
return (render_1.React.createElement(render_1.Box, { flexDirection: "column" }, | ||
render_1.React.createElement(tasks_1.BettererLogo, null), | ||
render_1.React.createElement(tasks_1.BettererTasksLogger, { name: "Upgrading Betterer" }, configPaths.map((configPath) => { | ||
const runUpgradeConfigFile = (0, render_1.useCallback)(async (logger) => { | ||
const upgradeConfigFile = (0, worker_require_1.workerRequire)('./upgrade-config-file'); | ||
import { React, Box, useCallback } from '@betterer/render'; | ||
import { BettererLogo, BettererTaskLogger, BettererTasksLogger } from '@betterer/tasks'; | ||
import { exposeToWorkerΔ, importWorkerΔ } from '@betterer/worker'; | ||
import path from 'node:path'; | ||
export const Upgrade = function Upgrade({ configPaths, cwd, logo, save }) { | ||
return (React.createElement(Box, { flexDirection: "column" }, | ||
logo && React.createElement(BettererLogo, null), | ||
React.createElement(BettererTasksLogger, { name: "Upgrading Betterer" }, configPaths.map((configPath) => { | ||
const runUpgradeConfigFile = useCallback(async (logger, status) => { | ||
const upgradeConfigFile = await importWorkerΔ('./upgrade-config-file.worker.js'); | ||
try { | ||
await upgradeConfigFile.run(logger, path.resolve(cwd, configPath), save); | ||
await upgradeConfigFile.api.run(exposeToWorkerΔ(logger), exposeToWorkerΔ(status), path.resolve(cwd, configPath), save); | ||
} | ||
@@ -22,6 +18,5 @@ finally { | ||
}, [cwd, configPath]); | ||
return (render_1.React.createElement(tasks_1.BettererTaskLogger, { key: configPath, name: `Upgrading "${configPath}"`, task: runUpgradeConfigFile })); | ||
return React.createElement(BettererTaskLogger, { key: configPath, name: `Upgrading "${configPath}"`, task: runUpgradeConfigFile }); | ||
})))); | ||
}; | ||
exports.Upgrade = Upgrade; | ||
//# sourceMappingURL=upgrade.js.map |
@@ -1,2 +0,2 @@ | ||
import { ArrowFunction, Node, ObjectLiteralExpression, SourceFile } from 'typescript'; | ||
import type { ArrowFunction, Node, ObjectLiteralExpression, SourceFile } from 'typescript'; | ||
export declare function reparse(upgradedSourceFile: SourceFile, configPath: string): SourceFile; | ||
@@ -3,0 +3,0 @@ export declare function wrapTest(node: Node): ArrowFunction | null; |
@@ -1,11 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.wrapTests = exports.wrapTest = exports.reparse = void 0; | ||
const tsquery_1 = require("@phenomnomnominal/tsquery"); | ||
const tstemplate_1 = require("@phenomnomnominal/tstemplate"); | ||
const typescript_1 = require("typescript"); | ||
function reparse(upgradedSourceFile, configPath) { | ||
return tsquery_1.tsquery.ast((0, typescript_1.createPrinter)().printFile(upgradedSourceFile), configPath); | ||
import { tsquery } from '@phenomnomnominal/tsquery'; | ||
import { tstemplate } from '@phenomnomnominal/tstemplate'; | ||
import { createPrinter, factory, isFunctionLike, isPropertyAssignment } from 'typescript'; | ||
export function reparse(upgradedSourceFile, configPath) { | ||
return tsquery.ast(createPrinter().printFile(upgradedSourceFile), configPath); | ||
} | ||
exports.reparse = reparse; | ||
// new BettererTest(); | ||
@@ -21,17 +17,17 @@ // new BettererTest().include(); | ||
const OBJECT_TEST = 'ObjectLiteralExpression:has(PropertyAssignment:has(Identifier[name="test"]))'; | ||
function wrapTest(node) { | ||
const [testCall] = (0, tsquery_1.tsquery)(node, `${NEW_BETTERER_TEST}, ${NEW_BETTERER_FILE_TEST}, ${TEST_FACTORY_CALL}`); | ||
export function wrapTest(node) { | ||
const [testCall] = tsquery(node, `${NEW_BETTERER_TEST}, ${NEW_BETTERER_FILE_TEST}, ${TEST_FACTORY_CALL}`); | ||
if (testCall) { | ||
const code = (0, tstemplate_1.tstemplate)(` | ||
const code = tstemplate(` | ||
() => <%= testCall %> | ||
`, { testCall }); | ||
const [wrapped] = (0, tsquery_1.tsquery)(code, 'ArrowFunction'); | ||
const [wrapped] = tsquery(code, 'ArrowFunction'); | ||
return wrapped; | ||
} | ||
const [testObject] = (0, tsquery_1.tsquery)(node, OBJECT_TEST); | ||
const [testObject] = tsquery(node, OBJECT_TEST); | ||
if (testObject) { | ||
const code = (0, tstemplate_1.tstemplate)(` | ||
const code = tstemplate(` | ||
() => new BettererTest(%= testObject %) | ||
`, { testObject }); | ||
const [wrapped] = (0, tsquery_1.tsquery)(code, 'ArrowFunction'); | ||
const [wrapped] = tsquery(code, 'ArrowFunction'); | ||
return wrapped; | ||
@@ -41,7 +37,6 @@ } | ||
} | ||
exports.wrapTest = wrapTest; | ||
function wrapTests(expression) { | ||
export function wrapTests(expression) { | ||
const { properties } = expression; | ||
return typescript_1.factory.createObjectLiteralExpression(properties.map((property) => { | ||
if ((0, typescript_1.isPropertyAssignment)(property) && !(0, typescript_1.isFunctionLike)(property.initializer)) { | ||
return factory.createObjectLiteralExpression(properties.map((property) => { | ||
if (isPropertyAssignment(property) && !isFunctionLike(property.initializer)) { | ||
const wrapped = wrapTest(property.initializer); | ||
@@ -51,3 +46,3 @@ if (!wrapped) { | ||
} | ||
return typescript_1.factory.createPropertyAssignment(property.name, wrapped); | ||
return factory.createPropertyAssignment(property.name, wrapped); | ||
} | ||
@@ -57,3 +52,2 @@ return property; | ||
} | ||
exports.wrapTests = wrapTests; | ||
//# sourceMappingURL=utils.js.map |
@@ -1,2 +0,2 @@ | ||
import { Command } from 'commander'; | ||
import type { Command } from 'commander'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Run **Betterer** in `watch` mode. |
@@ -1,17 +0,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.watch = void 0; | ||
const betterer_1 = require("@betterer/betterer"); | ||
const options_1 = require("./options"); | ||
const types_1 = require("./types"); | ||
import { betterer } from '@betterer/betterer'; | ||
import { watchCommand } from './options.js'; | ||
/** | ||
* Run **Betterer** in `watch` mode. | ||
*/ | ||
function watch(cwd) { | ||
const command = (0, options_1.cliCommand)(types_1.BettererCommand.watch); | ||
export function watch(cwd) { | ||
const command = watchCommand(); | ||
command.description('run Betterer in watch mode'); | ||
command.action(async (config) => { | ||
(0, options_1.setEnv)(config); | ||
// Mark options as unknown... | ||
const options = { | ||
// Cast the options to BettererOptions. This is possibly invalid, | ||
// but it's nicer to do the validation in @betterer/betterer | ||
await betterer.watch({ | ||
basePath: config.basePath, | ||
cache: config.cache, | ||
@@ -23,17 +20,12 @@ cachePath: config.cachePath, | ||
ignores: config.ignore, | ||
logo: config.logo, | ||
reporters: config.reporter, | ||
repoPath: config.repoPath, | ||
resultsPath: config.results, | ||
silent: config.silent, | ||
strict: config.strict, | ||
tsconfigPath: config.tsconfig, | ||
update: config.update, | ||
workers: config.workers | ||
}; | ||
// And then cast to BettererOptionsWatch. This is possibly invalid, | ||
// but it's nicer to do the options validation in @betterer/betterer | ||
await betterer_1.betterer.watch(options); | ||
}); | ||
}); | ||
return command; | ||
} | ||
exports.watch = watch; | ||
//# sourceMappingURL=watch.js.map |
{ | ||
"name": "@betterer/cli", | ||
"description": "betterer CLI", | ||
"version": "5.4.0", | ||
"version": "6.0.0-alpha.1", | ||
"license": "MIT", | ||
@@ -11,2 +11,3 @@ "publishConfig": { | ||
"types": "dist/index.d.ts", | ||
"type": "module", | ||
"files": [ | ||
@@ -17,3 +18,3 @@ "bin", | ||
"bin": { | ||
"betterer": "./bin/betterer" | ||
"betterer": "./bin/betterer.js" | ||
}, | ||
@@ -34,23 +35,19 @@ "author": "Craig Spence <craigspence0@gmail.com>", | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=16" | ||
}, | ||
"dependencies": { | ||
"@betterer/betterer": "^5.4.0", | ||
"@betterer/errors": "^5.3.0", | ||
"@betterer/render": "^5.3.4", | ||
"@betterer/tasks": "^5.3.6", | ||
"@phenomnomnominal/tsquery": "^4.1.1", | ||
"@betterer/betterer": "^6.0.0-alpha.1", | ||
"@betterer/errors": "^6.0.0-alpha.1", | ||
"@betterer/logger": "^6.0.0-alpha.1", | ||
"@betterer/render": "^6.0.0-alpha.1", | ||
"@betterer/tasks": "^6.0.0-alpha.1", | ||
"@betterer/worker": "^6.0.0-alpha.1", | ||
"@phenomnomnominal/tsquery": "^6.1.3", | ||
"@phenomnomnominal/tstemplate": "^0.1.0", | ||
"@phenomnomnominal/worker-require": "^0.0.34", | ||
"chalk": "^4.1.2", | ||
"chalk": "^5.3.0", | ||
"commander": "^8.3.0", | ||
"find-up": "^5.0.0", | ||
"jest-diff": "^27.1.0", | ||
"prettier": "^2.3.2", | ||
"tslib": "^2.3.1" | ||
"find-up": "^7.0.0", | ||
"prettier": "^3.2.5" | ||
}, | ||
"devDependencies": { | ||
"@types/prettier": "^2.3.2" | ||
}, | ||
"gitHead": "c791fe43fb94344ee33d3573a6c42f274891d266" | ||
"gitHead": "821992635c8b6a4891169dad3334203f866e5521" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
12
0
117
5
Yes
101750
1257
1
1
+ Added@betterer/betterer@6.0.0-alpha.1(transitive)
+ Added@betterer/constraints@6.0.0-alpha.1(transitive)
+ Added@betterer/errors@6.0.0-alpha.1(transitive)
+ Added@betterer/logger@6.0.0-alpha.1(transitive)
+ Added@betterer/render@6.0.0-alpha.1(transitive)
+ Added@betterer/reporter@6.0.0-alpha.1(transitive)
+ Added@betterer/tasks@6.0.0-alpha.1(transitive)
+ Added@betterer/time@6.0.0-alpha.1(transitive)
+ Added@betterer/worker@6.0.0-alpha.1(transitive)
+ Added@esbuild/aix-ppc64@0.24.0(transitive)
+ Added@esbuild/android-arm@0.24.0(transitive)
+ Added@esbuild/android-arm64@0.24.0(transitive)
+ Added@esbuild/android-x64@0.24.0(transitive)
+ Added@esbuild/darwin-arm64@0.24.0(transitive)
+ Added@esbuild/darwin-x64@0.24.0(transitive)
+ Added@esbuild/freebsd-arm64@0.24.0(transitive)
+ Added@esbuild/freebsd-x64@0.24.0(transitive)
+ Added@esbuild/linux-arm@0.24.0(transitive)
+ Added@esbuild/linux-arm64@0.24.0(transitive)
+ Added@esbuild/linux-ia32@0.24.0(transitive)
+ Added@esbuild/linux-loong64@0.24.0(transitive)
+ Added@esbuild/linux-mips64el@0.24.0(transitive)
+ Added@esbuild/linux-ppc64@0.24.0(transitive)
+ Added@esbuild/linux-riscv64@0.24.0(transitive)
+ Added@esbuild/linux-s390x@0.24.0(transitive)
+ Added@esbuild/linux-x64@0.24.0(transitive)
+ Added@esbuild/netbsd-x64@0.24.0(transitive)
+ Added@esbuild/openbsd-arm64@0.24.0(transitive)
+ Added@esbuild/openbsd-x64@0.24.0(transitive)
+ Added@esbuild/sunos-x64@0.24.0(transitive)
+ Added@esbuild/win32-arm64@0.24.0(transitive)
+ Added@esbuild/win32-ia32@0.24.0(transitive)
+ Added@esbuild/win32-x64@0.24.0(transitive)
+ Added@phenomnomnominal/tsquery@6.1.3(transitive)
+ Added@types/esquery@1.5.4(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Addedchalk@5.3.0(transitive)
+ Addedcore-js@3.39.0(transitive)
+ Addeddjb2a@2.0.0(transitive)
+ Addedesbuild@0.24.0(transitive)
+ Addedfind-up@7.0.0(transitive)
+ Addedignore-walk@7.0.0(transitive)
+ Addedlocate-path@7.2.0(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedp-limit@4.0.0(transitive)
+ Addedp-locate@6.0.0(transitive)
+ Addedpath-exists@5.0.0(transitive)
+ Addedprettier@3.4.2(transitive)
+ Addedunicorn-magic@0.1.0(transitive)
+ Addedyocto-queue@1.1.1(transitive)
- Removedjest-diff@^27.1.0
- Removedtslib@^2.3.1
- Removed@betterer/betterer@5.4.0(transitive)
- Removed@betterer/constraints@5.3.0(transitive)
- Removed@betterer/errors@5.3.0(transitive)
- Removed@betterer/logger@5.3.4(transitive)
- Removed@betterer/render@5.3.4(transitive)
- Removed@betterer/reporter@5.4.0(transitive)
- Removed@betterer/tasks@5.3.6(transitive)
- Removed@cspotcode/source-map-support@0.8.1(transitive)
- Removed@jridgewell/resolve-uri@3.1.2(transitive)
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@jridgewell/trace-mapping@0.3.9(transitive)
- Removed@phenomnomnominal/debug@0.2.5(transitive)
- Removed@phenomnomnominal/tsquery@4.2.0(transitive)
- Removed@phenomnomnominal/worker-require@0.0.34(transitive)
- Removed@tsconfig/node10@1.0.11(transitive)
- Removed@tsconfig/node12@1.0.11(transitive)
- Removed@tsconfig/node14@1.0.3(transitive)
- Removed@tsconfig/node16@1.0.4(transitive)
- Removed@types/node@22.10.2(transitive)
- Removedacorn@8.14.0(transitive)
- Removedacorn-walk@8.3.4(transitive)
- Removedarg@4.1.3(transitive)
- Removedcreate-require@1.1.1(transitive)
- Removeddiff@4.0.2(transitive)
- Removeddjb2a@1.2.0(transitive)
- Removedesprima@4.0.1(transitive)
- Removedfind-up@5.0.0(transitive)
- Removedlocate-path@6.0.0(transitive)
- Removedmake-error@1.3.6(transitive)
- Removedp-limit@3.1.0(transitive)
- Removedp-locate@5.0.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedprettier@2.8.8(transitive)
- Removedts-node@10.9.2(transitive)
- Removedtslib@1.14.12.8.1(transitive)
- Removedtypescript@4.9.5(transitive)
- Removedundici-types@6.20.0(transitive)
- Removedv8-compile-cache-lib@3.0.1(transitive)
- Removedyn@3.1.1(transitive)
- Removedyocto-queue@0.1.0(transitive)
Updatedchalk@^5.3.0
Updatedfind-up@^7.0.0
Updatedprettier@^3.2.5