Skip to content

Commit

Permalink
Add --inspect flag (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager authored Jun 17, 2024
1 parent e4823b7 commit d9138f6
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 26 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ if(MSVC)
add_compile_options(/MT$<$<CONFIG:Debug>:d>)
endif()

if(WIN32)
add_definitions(-DWIN32_LEAN_AND_MEAN)
endif()

if(NOT TARGET uv)
add_subdirectory(vendor/libuv EXCLUDE_FROM_ALL)
endif()
Expand Down Expand Up @@ -323,6 +327,11 @@ link_bare_module(bare bare-url)
link_bare_module(bare_bin bare-pipe)
link_bare_module(bare_bin bare-repl)
link_bare_module(bare_bin bare-signals)
link_bare_module(bare_bin bare-crypto)
link_bare_module(bare_bin bare-dns)
link_bare_module(bare_bin bare-inspector)
link_bare_module(bare_bin bare-tcp)
link_bare_module(bare_bin bare-tls)
link_bare_module(bare_bin bare-tty)

if(PROJECT_IS_TOP_LEVEL)
Expand Down
31 changes: 21 additions & 10 deletions bin/bare.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const bare = command(
flag('--version|-v', 'Print the Bare version'),
flag('--eval|-e <script>', 'Evaluate an inline script'),
flag('--print|-p <script>', 'Evaluate an inline script and print the result'),
flag('--inspect', 'Activate the inspector'),
arg('<filename>', 'The name of a script to evaluate'),
rest('[...args]', 'Additional arguments made available to the script'),
bail((bail) => {
Expand Down Expand Up @@ -54,17 +55,27 @@ const bare = command(

Bare.argv.splice(1, Bare.argv.length - 1, ...argv)

if (flags.version) {
console.log(Bare.version)
} else if (flags.eval) {
Module.load(parentURL, `(${flags.eval})`)
} else if (flags.print) {
Module.load(parentURL, `console.log(${flags.print})`)
} else if (args.filename) {
Module.load(args.filename)
} else {
require('bare-repl').start()
if (flags.version) return console.log(Bare.version)

let server = null

if (flags.inspect) {
const inspector = require('bare-inspector')

server = new inspector.Server(9229, { path: args.filename || os.cwd() })
server.unref()
}

if (flags.eval) return Module.load(parentURL, `(${flags.eval})`)

if (flags.print) return Module.load(parentURL, `console.log(${flags.print})`)

if (args.filename) return Module.load(args.filename)

require('bare-repl').start().on('exit', () => {
if (server === null) Bare.exit()
else server.close(() => Bare.exit())
})
}
)

Expand Down
83 changes: 67 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"bare-events": "^2.0.0",
"bare-hrtime": "^2.0.0",
"bare-inspect": "^3.0.0",
"bare-inspector": "^2.3.0",
"bare-module": "^3.1.0",
"bare-os": "^2.0.0",
"bare-path": "^2.0.0",
Expand Down

0 comments on commit d9138f6

Please sign in to comment.