Skip to content

Commit

Permalink
feat: enable debugging using cli options
Browse files Browse the repository at this point in the history
  • Loading branch information
stagas committed Jun 28, 2022
1 parent 309e4a5 commit d08c45b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"github-markdown-css": "5.1.0",
"open-in-editor-connect": "1.0.0",
"qrcode-terminal": "0.12.0",
"rollup-plugin-debug": "^0.0.1",
"rollup-plugin-debug": "^0.1.0",
"running-at": "0.3.22",
"vite": "2.8.6",
"vite-plugin-babel": "1.0.0",
Expand Down
31 changes: 24 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export class Options {
@arg('--no-open', 'Do not open browser on startup')
noOpen = false

@arg('--debugging', 'Debugging pattern')
debugging = ''

@arg('--debugging-this', 'Enable debugging for current package')
debuggingThis = false

@arg('--quiet', 'Quiet output')
quiet = false

Expand Down Expand Up @@ -92,11 +98,13 @@ const html = (title: string, name: string) =>
* @param options.https Use https
* @param options.jsx JSX transformer (default: react)
* @param options.noOpen Do not open browser on startup
* @param options.debugging Debugging pattern
* @param options.debuggingThis Enable debugging for current package
* @param options.quiet Quiet output
* @return ViteDevServer
*/
export const open = async (options: Partial<Options>): Promise<ViteServer> => {
const { log, root, quiet, file, responses, jsx } = (options = Object.assign(
const { log, root, quiet, file, responses, jsx, debugging, debuggingThis } = (options = Object.assign(
new Options(),
options
))
Expand All @@ -112,15 +120,21 @@ export const open = async (options: Partial<Options>): Promise<ViteServer> => {
exclude: [],
}

const aliasPackage = () => {
const getPkgName = (): string | void => {
try {
const json = fs.readFileSync(path.resolve(path.join(root, 'package.json')), 'utf-8')
const pkg = JSON.parse(json)
return pkg.name
} catch {}
}

const aliasPackage = () => {
try {
// try to alias package name as a top-level module
const pkg = JSON.parse(json)
if ('name' in pkg) {
!quiet && log('aliasing:', chalk.cyan(pkg.name), '->', chalk.green(root))
;(resolve.alias as any)[pkg.name] = root
const name = getPkgName()
if (name) {
!quiet && log('aliasing:', chalk.cyan(name), '->', chalk.green(root))
;(resolve.alias as any)[name] = root
}
} catch {}
}
Expand Down Expand Up @@ -253,7 +267,10 @@ export const open = async (options: Partial<Options>): Promise<ViteServer> => {
filter: /\.(jsx|tsx)$/,
}),

debug({ printId: true }),
debug({
printId: true,
debugMatcher: debuggingThis ? ((getPkgName() ?? '') + ':*') : debugging,
}),

{
name: 'configure-server',
Expand Down

0 comments on commit d08c45b

Please sign in to comment.