summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/compiler.ts12
-rw-r--r--js/compiler_test.ts17
-rw-r--r--js/main.ts3
-rw-r--r--src/flags.rs3
-rw-r--r--src/handlers.rs1
-rw-r--r--src/msg.fbs1
6 files changed, 33 insertions, 4 deletions
diff --git a/js/compiler.ts b/js/compiler.ts
index 624aab201..f0f82ffb1 100644
--- a/js/compiler.ts
+++ b/js/compiler.ts
@@ -169,6 +169,8 @@ export class DenoCompiler
// A reference to the global scope so it can be monkey patched during
// testing
private _window = window;
+ // Flags forcing recompilation of TS code
+ public recompile = false;
/**
* Drain the run queue, retrieving the arguments for the module
@@ -412,11 +414,15 @@ export class DenoCompiler
/**
* Retrieve the output of the TypeScript compiler for a given module and
- * cache the result.
+ * cache the result. Re-compilation can be forced using '--recompile' flag.
*/
compile(moduleMetaData: ModuleMetaData): OutputCode {
- this._log("compiler.compile", moduleMetaData.fileName);
- if (moduleMetaData.outputCode) {
+ const recompile = !!this.recompile;
+ this._log(
+ "compiler.compile",
+ { filename: moduleMetaData.fileName, recompile }
+ );
+ if (!recompile && moduleMetaData.outputCode) {
return moduleMetaData.outputCode;
}
const { fileName, sourceCode } = moduleMetaData;
diff --git a/js/compiler_test.ts b/js/compiler_test.ts
index fdb5fe03b..fef18ec3d 100644
--- a/js/compiler_test.ts
+++ b/js/compiler_test.ts
@@ -458,6 +458,23 @@ test(function compilerGetScriptFileNames() {
teardown();
});
+test(function compilerRecompileFlag() {
+ setup();
+ compilerInstance.run("foo/bar.ts", "/root/project");
+ assertEqual(getEmitOutputStack.length, 1, "Expected only a single emitted file.");
+ // running compiler against same file should use cached code
+ compilerInstance.run("foo/bar.ts", "/root/project");
+ assertEqual(getEmitOutputStack.length, 1, "Expected only a single emitted file.");
+ compilerInstance.recompile = true;
+ compilerInstance.run("foo/bar.ts", "/root/project");
+ assertEqual(getEmitOutputStack.length, 2, "Expected two emitted file.");
+ assert(
+ getEmitOutputStack[0] === getEmitOutputStack[1],
+ "Expected same file to be emitted twice."
+ );
+ teardown();
+});
+
test(function compilerGetScriptKind() {
assertEqual(compilerInstance.getScriptKind("foo.ts"), ts.ScriptKind.TS);
assertEqual(compilerInstance.getScriptKind("foo.d.ts"), ts.ScriptKind.TS);
diff --git a/js/main.ts b/js/main.ts
index e927710a7..63d72e87f 100644
--- a/js/main.ts
+++ b/js/main.ts
@@ -37,7 +37,7 @@ export default function denoMain() {
libdeno.setGlobalErrorHandler(onGlobalError);
const compiler = DenoCompiler.instance();
- // First we send an empty "Start" message to let the privlaged side know we
+ // First we send an empty "Start" message to let the privileged side know we
// are ready. The response should be a "StartRes" message containing the CLI
// args and other info.
const startResMsg = sendStart();
@@ -68,5 +68,6 @@ export default function denoMain() {
os.exit(0);
}
+ compiler.recompile = startResMsg.recompileFlag();
compiler.run(inputFn, `${cwd}/`);
}
diff --git a/src/flags.rs b/src/flags.rs
index 102fc7f8e..ceeb9e564 100644
--- a/src/flags.rs
+++ b/src/flags.rs
@@ -18,6 +18,7 @@ pub struct DenoFlags {
pub log_debug: bool,
pub version: bool,
pub reload: bool,
+ pub recompile: bool,
pub allow_write: bool,
pub allow_net: bool,
pub allow_env: bool,
@@ -30,6 +31,7 @@ pub fn print_usage() {
--allow-write Allow file system write access.
--allow-net Allow network access.
--allow-env Allow environment access.
+--recompile Force recompilation of TypeScript code.
-v or --version Print the version.
-r or --reload Reload cached remote resources.
-D or --log-debug Log debug output.
@@ -52,6 +54,7 @@ pub fn set_flags(args: Vec<String>) -> (DenoFlags, Vec<String>) {
"--log-debug" => flags.log_debug = true,
"--version" => flags.version = true,
"--reload" => flags.reload = true,
+ "--recompile" => flags.recompile = true,
"--allow-write" => flags.allow_write = true,
"--allow-net" => flags.allow_net = true,
"--allow-env" => flags.allow_env = true,
diff --git a/src/handlers.rs b/src/handlers.rs
index 10d899557..eef091174 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -172,6 +172,7 @@ fn handle_start(i: *const isolate, base: &msg::Base) -> Box<Op> {
cwd: Some(cwd_off),
argv: Some(argv_off),
debug_flag: isolate.flags.log_debug,
+ recompile_flag: isolate.flags.recompile,
..Default::default()
},
);
diff --git a/src/msg.fbs b/src/msg.fbs
index 5a8d52f09..ee3930729 100644
--- a/src/msg.fbs
+++ b/src/msg.fbs
@@ -89,6 +89,7 @@ table StartRes {
argv: [string];
debug_flag: bool;
deps_flag: bool;
+ recompile_flag: bool;
}
table CodeFetch {