Skip to content

Commit

Permalink
remove custom arc debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstyles committed May 17, 2024
1 parent ed30905 commit 39d0f06
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 58 deletions.
4 changes: 2 additions & 2 deletions scripts/arc/rk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { hideBin } from 'yargs/helpers'
import { buildCommand } from './src/commands/build'
import { watchCommand } from './src/commands/watch'
import { getConfig } from './src/config'
import { debug } from './src/log'
import { log } from './src/log'

const config = await getConfig()
debug.rk('Using config: %o', config)
log.arc.debug('Arc config: %o', config)

yargs(hideBin(process.argv))
.config(config)
Expand Down
7 changes: 3 additions & 4 deletions scripts/arc/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import prettyTime from 'pretty-time'
import pkg from '../../package.json'
import { generateOptions } from '../arguments'
import { generateDefinitions } from '../definition'
import { createDebugger, log, padRight } from '../log'
import { log, padRight } from '../log'
import { transformFiles } from '../transform'

import { testPipeline } from '../transform/pipeline.example.ts'

const debug = createDebugger('rk::build')

type CommandOptions = Required<Config>

export const buildCommand: CommandModule = {
Expand All @@ -30,7 +28,7 @@ export const buildCommand: CommandModule = {
handler: generateOptions<CommandOptions>(
async (argv) => {
const files = await glob(argv.include)
debug('Files to transform: %o', files)
log.arc.debug('Files to transform: %o', files)

log.arc.log(`v${pkg.version}`)
log.arc.log('Entry files:', chalk.magenta(files.join(', ')))
Expand Down Expand Up @@ -97,6 +95,7 @@ export const buildCommand: CommandModule = {
)

// Event
log.arc.debug('[event] onComplete')
await opts.events.complete() // @TODO pass in run analytics

// This is tempting but ends up yielding execution and screwing up the metrics, probably would be _less_ of a problem if TS wasn't synchronous, but, still would muck with a pipeline output
Expand Down
35 changes: 17 additions & 18 deletions scripts/arc/src/commands/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { globby as glob } from 'globby'
import pkg from '../../package.json'
import { generateOptions } from '../arguments'
import { generateDefinitions } from '../definition'
import { createDebugger, log } from '../log'
import { log } from '../log'
import { transformFiles } from '../transform'

const debug = createDebugger('rk::watch')

type CommandOptions = Required<Config>

export const watchCommand: CommandModule = {
Expand All @@ -28,7 +26,7 @@ export const watchCommand: CommandModule = {
handler: generateOptions<CommandOptions>(
async (argv) => {
const files = await glob(argv.include)
debug('Files to transform: %o', files)
log.arc.debug('Files to transform: %o', files)

log.arc.log(`v${pkg.version}`)
log.arc.log('Entry files:', chalk.magenta(files.join(', ')))
Expand All @@ -41,7 +39,7 @@ export const watchCommand: CommandModule = {
}
},
async (opts) => {
debug('Watch options: %o', opts)
log.arc.debug('Watch options: %o', opts)

const client = new Client()
client.capabilityCheck(
Expand All @@ -53,10 +51,10 @@ export const watchCommand: CommandModule = {
client.end()
}

debug('Watchman capability check: %o', res)
log.arc.debug('Watchman capability check: %o', res)

const watchPath = process.cwd()
debug('Common watch path:', watchPath)
log.arc.debug('Common watch path:', watchPath)

client.command(['watch-project', watchPath], (error, resp) => {
if (error) {
Expand All @@ -67,17 +65,18 @@ export const watchCommand: CommandModule = {
log.arc.warn('Warning: ', resp.warning)
}

debug('"watch-project" started')
log.arc.debug('"watch-project" started')

// @TODO should potentially attempt to match against the initial arc config options include globs, or even the rootDir and the filter out those files that do not match the glob. Using opts.include here is the extended glob and will miss new files being added.
const query = [
'allof',
['match', 'src/**/*', 'wholename'],
['suffix', ['ts', 'tsx']],
['not', ['suffix', ['test.ts', 'test.tsx']]],
]
const sub = {
// expression: ['anyof', ['name', opts.include, 'wholename']],
expression: [
'allof',
['match', 'src/**/*', 'wholename'],
['suffix', ['ts', 'tsx']],
['not', ['suffix', ['test.ts', 'test.tsx']]],
],
expression: query,
fields: [
'name',
'size',
Expand All @@ -91,10 +90,10 @@ export const watchCommand: CommandModule = {
}
const subscriptionName = `arc:watch:${pkg.name}`

debug('Running watchman:subscribe %o', {
log.arc.debug('Running watchman:subscribe %o', {
...sub,
name: subscriptionName,
include: opts.include,
query: query,
})
client.command(
['subscribe', resp.watch, subscriptionName, sub],
Expand All @@ -111,11 +110,11 @@ export const watchCommand: CommandModule = {

client.on('subscription', async (res): Promise<void> => {
if (res.subscription !== subscriptionName) {
debug('Additional subscription: %o', res)
log.arc.debug('Additional subscription: %o', res)
return
}

debug('Subscription event received %o', res)
log.arc.debug('Subscription event received %o', res)

for (const file of res.files) {
if (file.exists === false) {
Expand Down
5 changes: 3 additions & 2 deletions scripts/arc/src/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import chalk from 'chalk'
import { parse } from 'tsconfck'
import ts from 'typescript'

import { createDebugger, log } from './log'
import { createLogger } from '@urban-ui/arc-log'
import { log } from './log'
import { Pipeline } from './transform/pipeline.ts'
import { createTask } from './transform/task.ts'

const debug = createDebugger('rk::definition')
const { debug } = createLogger('rk::definition', chalk.green)

type FilesDts = Record<string, string>

Expand Down
30 changes: 0 additions & 30 deletions scripts/arc/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,13 @@ import type { ChalkInstance } from 'chalk'

import { createLogger } from '@urban-ui/arc-log'
import chalk from 'chalk'
import createDebugger from 'debug'

export { createDebugger }

export const debug = {
rk: createDebugger('rk'),
}

export const log = {
arc: createLogger('arc', chalk.yellow),
transform: createLogger('arc-swc', chalk.cyan),
definition: createLogger('arc-dts', chalk.magenta),
}

type LogParams = Parameters<typeof console.log>

/**
* Creates a new log interface for a natural grouping.
* Output to stdout is determined by env vars.
*
* @example
*
*
* @param namespace identifier for this log output
* @param colour colour for this log output
*/
// export function createLogger(namespace: string, colour: ChalkInstance) {
// function log(...args: LogParams) {
// console.log(
// `${chalk.dim.bold('[')}${colour.bold(namespace)}${chalk.dim.bold(']')}`,
// ...args,
// )
// }

// return log
// }

export function padRight(str: string, min: number) {
const diff = min - str.length
if (diff <= 0) {
Expand Down
5 changes: 3 additions & 2 deletions scripts/arc/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import zlib from 'node:zlib'
import swc from '@swc/core'
import chalk from 'chalk'

import { createLogger } from '@urban-ui/arc-log'
import { jscOps } from './configs/jsc.ts'
import { minify } from './configs/minify.ts'
import { transformImports } from './configs/plugins.ts'
import { createDebugger, log } from './log'
import { log } from './log'
import { traceFn } from './trace.ts'
import { fileEvents, measure } from './transform/analytics.ts'
import { Pipeline } from './transform/pipeline.ts'
import { createTask } from './transform/task.ts'

const gzip = promisify(zlib.gzip)
const debug = createDebugger('rk::transform')
const { debug } = createLogger('rk::transform', chalk.blue)

enum TransformModes {
watch = 'watch',
Expand Down

0 comments on commit 39d0f06

Please sign in to comment.