@digitak/esrun
Advanced tools
Comparing version 1.2.4 to 1.2.5
@@ -17,11 +17,12 @@ #!/usr/bin/env node | ||
while ((argument = argv[argsOffset]).startsWith("-")) { | ||
if (argument in argumentOptions) { | ||
options[argumentOptions[argument]] = true; | ||
const [command, parameters] = argument.split(':'); | ||
if (command in argumentOptions) { | ||
options[argumentOptions[command]] = parameters ? parameters.split(',') : true; | ||
argsOffset++; | ||
} | ||
else { | ||
console.log(`Unknown option ${argv[argsOffset]}`); | ||
console.log(`Unknown option ${command}`); | ||
process.exit(9); | ||
} | ||
} | ||
esrun(argv[argsOffset], argv.slice(argsOffset + 1), options.watch, options.inspect); | ||
esrun(argv[argsOffset], argv.slice(argsOffset + 1), options.watch, !!options.inspect); |
/** | ||
* Run any .ts or .js file | ||
*/ | ||
export default function esrun(inputFile: string, args?: string[], watch?: boolean, inspect?: boolean): Promise<void>; | ||
export default function esrun(inputFile: string, args?: string[], watch?: boolean | string[], inspect?: boolean): Promise<void>; |
@@ -11,3 +11,3 @@ import Runner from "./runners/Runner.js"; | ||
} | ||
return new (watch ? Watcher : Runner)(inputFile, args, inspect).run(); | ||
return new (watch ? Watcher : Runner)(inputFile, args, watch, inspect).run(); | ||
} |
@@ -7,2 +7,3 @@ import type { BuildResult, OutputFile } from "esbuild/lib/main.js"; | ||
args: string[]; | ||
protected watch: boolean | string[]; | ||
protected inspect: boolean; | ||
@@ -12,4 +13,3 @@ input: string; | ||
protected dependencies: string[]; | ||
protected watch: boolean; | ||
constructor(input: string, args?: string[], inspect?: boolean); | ||
constructor(input: string, args?: string[], watch?: boolean | string[], inspect?: boolean); | ||
get outputCode(): string; | ||
@@ -16,0 +16,0 @@ run(): Promise<void>; |
@@ -7,8 +7,8 @@ import { build } from "esbuild/lib/main.js"; | ||
export default class Runner { | ||
constructor(input, args = [], inspect = false) { | ||
constructor(input, args = [], watch = false, inspect = false) { | ||
this.args = args; | ||
this.watch = watch; | ||
this.inspect = inspect; | ||
this.output = null; | ||
this.dependencies = []; | ||
this.watch = false; | ||
this.input = findInputFile(input); | ||
@@ -65,3 +65,3 @@ } | ||
format: "esm", | ||
incremental: this.watch, | ||
incremental: !!this.watch, | ||
plugins: [ | ||
@@ -68,0 +68,0 @@ { |
import Runner from "./Runner.js"; | ||
import type { FSWatcher } from "chokidar/index.js"; | ||
export default class Watcher extends Runner { | ||
args: string[]; | ||
protected watch: never[]; | ||
protected inspect: boolean; | ||
protected watcher: FSWatcher | null; | ||
protected watch: boolean; | ||
protected inspect: boolean; | ||
constructor(input: string, args?: string[], watch?: never[], inspect?: boolean); | ||
run(): Promise<void>; | ||
@@ -8,0 +10,0 @@ rerun(): Promise<void>; |
@@ -5,7 +5,8 @@ import Runner from "./Runner.js"; | ||
export default class Watcher extends Runner { | ||
constructor() { | ||
super(...arguments); | ||
constructor(input, args = [], watch = [], inspect = false) { | ||
super(input, args, watch instanceof Array ? watch : [], inspect); | ||
this.args = args; | ||
this.watch = watch; | ||
this.inspect = inspect; | ||
this.watcher = null; | ||
this.watch = true; | ||
this.inspect = false; | ||
} | ||
@@ -17,3 +18,3 @@ async run() { | ||
this.execute(); | ||
this.watcher = watch([...this.dependencies, "package.json"]); | ||
this.watcher = watch([...this.dependencies, "package.json", ...this.watch]); | ||
this.watcher.on("change", this.rerun.bind(this)); | ||
@@ -20,0 +21,0 @@ this.watcher.on("unlink", this.rerun.bind(this)); |
{ | ||
"name": "@digitak/esrun", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"type": "module", | ||
@@ -18,3 +18,3 @@ "description": "Execute directly your Typescript files using Esbuild", | ||
"test:run": "./library/bin.js test --watch coco", | ||
"test:watch": "./library/bin.js --watch test --watch coco", | ||
"test:watch": "./library/bin.js --watch:test/*.json test --watch coco", | ||
"test:inspect": "./library/bin.js --inspect test --watch coco", | ||
@@ -21,0 +21,0 @@ "test:watch:inspect": "./library/bin.js --watch --inspect test --watch coco" |
@@ -83,2 +83,16 @@ # esrun | ||
You may want to watch other files than your code files. For example, if you load data from a configuration file. In this case you can specify a glob (or a list of globs) that have to be watched: | ||
```shell | ||
esrun --watch:src/*.json foo.ts | ||
``` | ||
Then any `json` file in the `src/`folder will re-trigger the run. | ||
You can use several globs separated by a comma (but no space): | ||
```shell | ||
esrun --watch:src/*.json,test/*.json foo.ts | ||
``` | ||
### Inspect mode | ||
@@ -139,3 +153,8 @@ | ||
esrun(filePath: string, argv: string[], watch = false): unknown | ||
esrun( | ||
filePath: string, | ||
argv: string[], | ||
watch: boolean | string[] = false, // you can pass an array of globs to watch | ||
inspect = false | ||
): unknown | ||
``` |
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
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
17132
274
159