@digitak/esrun
Advanced tools
Comparing version 3.2.4 to 3.2.5
{ | ||
"name": "@digitak/esrun", | ||
"version": "3.2.4", | ||
"version": "3.2.5", | ||
"type": "module", | ||
@@ -48,3 +48,2 @@ "description": "Execute directly your Typescript files using Esbuild", | ||
"@digitak/grubber": "^3.1.1", | ||
"anymatch": "^3.1.2", | ||
"chokidar": "^3.5.1", | ||
@@ -51,0 +50,0 @@ "esbuild": "^0.12.4" |
@@ -30,2 +30,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
getDependencies(): readonly string[]; | ||
protected retrieveDependencies(): string[]; | ||
constructor(inputFile: string, options?: Options); | ||
@@ -32,0 +33,0 @@ run(): Promise<void>; |
@@ -6,2 +6,3 @@ import { build } from "esbuild"; | ||
import { makePackagesExternalPlugin } from "../plugins/makePackagesExternal.js"; | ||
import path from "path"; | ||
export default class Runner { | ||
@@ -32,2 +33,5 @@ constructor(inputFile, options) { | ||
} | ||
retrieveDependencies() { | ||
return Object.keys(this.buildOutput?.metafile?.inputs ?? []).map(input => path.resolve(input)); | ||
} | ||
async run() { | ||
@@ -54,11 +58,2 @@ try { | ||
} | ||
plugins.push({ | ||
name: "list-dependencies", | ||
setup: build => { | ||
build.onLoad({ filter: /.*/ }, async ({ path }) => { | ||
this.dependencies.push(path); | ||
return null; | ||
}); | ||
}, | ||
}); | ||
try { | ||
@@ -75,4 +70,6 @@ this.buildOutput = await build({ | ||
write: false, | ||
metafile: true, | ||
}); | ||
this.outputCode = this.buildOutput?.outputFiles[0]?.text || ""; | ||
this.dependencies = this.retrieveDependencies(); | ||
} | ||
@@ -79,0 +76,0 @@ catch (error) { |
import Runner from "./Runner.js"; | ||
import { watch } from "chokidar"; | ||
import path from "path"; | ||
import anymatch from "anymatch"; | ||
function debounce(func, wait) { | ||
@@ -45,19 +44,4 @@ let timeout = null; | ||
if (this.buildOutput) { | ||
const packageFile = path.resolve("package.json"); | ||
const watchedDependencies = []; | ||
for (const [directory, files] of Object.entries(watcher.getWatched())) { | ||
watchedDependencies.push(...files.map(file => path.join(directory, file))); | ||
} | ||
for (const dependency of watchedDependencies) { | ||
if (dependency != packageFile && | ||
!anymatch(this.watch, dependency) && | ||
!this.dependencies.includes(dependency)) { | ||
watcher.unwatch(dependency); | ||
} | ||
} | ||
for (const dependency of this.dependencies) { | ||
if (!watchedDependencies.includes(dependency)) { | ||
watcher.add(dependency); | ||
} | ||
} | ||
void this.watcher.close(); | ||
this.watcher = watch([...this.dependencies, "package.json", ...this.watch]); | ||
} | ||
@@ -75,2 +59,3 @@ await this.execute(); | ||
this.outputCode = this.buildOutput?.outputFiles[0]?.text || ""; | ||
this.dependencies = this.retrieveDependencies(); | ||
} | ||
@@ -77,0 +62,0 @@ catch (error) { |
3
24661
430
- Removedanymatch@^3.1.2