mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
Add flag --recompile (#801)
This commit is contained in:
parent
17a7b03d1b
commit
3fe4be07ca
6 changed files with 33 additions and 4 deletions
|
@ -169,6 +169,8 @@ export class DenoCompiler
|
||||||
// A reference to the global scope so it can be monkey patched during
|
// A reference to the global scope so it can be monkey patched during
|
||||||
// testing
|
// testing
|
||||||
private _window = window;
|
private _window = window;
|
||||||
|
// Flags forcing recompilation of TS code
|
||||||
|
public recompile = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drain the run queue, retrieving the arguments for the module
|
* 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
|
* 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 {
|
compile(moduleMetaData: ModuleMetaData): OutputCode {
|
||||||
this._log("compiler.compile", moduleMetaData.fileName);
|
const recompile = !!this.recompile;
|
||||||
if (moduleMetaData.outputCode) {
|
this._log(
|
||||||
|
"compiler.compile",
|
||||||
|
{ filename: moduleMetaData.fileName, recompile }
|
||||||
|
);
|
||||||
|
if (!recompile && moduleMetaData.outputCode) {
|
||||||
return moduleMetaData.outputCode;
|
return moduleMetaData.outputCode;
|
||||||
}
|
}
|
||||||
const { fileName, sourceCode } = moduleMetaData;
|
const { fileName, sourceCode } = moduleMetaData;
|
||||||
|
|
|
@ -458,6 +458,23 @@ test(function compilerGetScriptFileNames() {
|
||||||
teardown();
|
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() {
|
test(function compilerGetScriptKind() {
|
||||||
assertEqual(compilerInstance.getScriptKind("foo.ts"), ts.ScriptKind.TS);
|
assertEqual(compilerInstance.getScriptKind("foo.ts"), ts.ScriptKind.TS);
|
||||||
assertEqual(compilerInstance.getScriptKind("foo.d.ts"), ts.ScriptKind.TS);
|
assertEqual(compilerInstance.getScriptKind("foo.d.ts"), ts.ScriptKind.TS);
|
||||||
|
|
|
@ -37,7 +37,7 @@ export default function denoMain() {
|
||||||
libdeno.setGlobalErrorHandler(onGlobalError);
|
libdeno.setGlobalErrorHandler(onGlobalError);
|
||||||
const compiler = DenoCompiler.instance();
|
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
|
// are ready. The response should be a "StartRes" message containing the CLI
|
||||||
// args and other info.
|
// args and other info.
|
||||||
const startResMsg = sendStart();
|
const startResMsg = sendStart();
|
||||||
|
@ -68,5 +68,6 @@ export default function denoMain() {
|
||||||
os.exit(0);
|
os.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compiler.recompile = startResMsg.recompileFlag();
|
||||||
compiler.run(inputFn, `${cwd}/`);
|
compiler.run(inputFn, `${cwd}/`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ pub struct DenoFlags {
|
||||||
pub log_debug: bool,
|
pub log_debug: bool,
|
||||||
pub version: bool,
|
pub version: bool,
|
||||||
pub reload: bool,
|
pub reload: bool,
|
||||||
|
pub recompile: bool,
|
||||||
pub allow_write: bool,
|
pub allow_write: bool,
|
||||||
pub allow_net: bool,
|
pub allow_net: bool,
|
||||||
pub allow_env: bool,
|
pub allow_env: bool,
|
||||||
|
@ -30,6 +31,7 @@ pub fn print_usage() {
|
||||||
--allow-write Allow file system write access.
|
--allow-write Allow file system write access.
|
||||||
--allow-net Allow network access.
|
--allow-net Allow network access.
|
||||||
--allow-env Allow environment access.
|
--allow-env Allow environment access.
|
||||||
|
--recompile Force recompilation of TypeScript code.
|
||||||
-v or --version Print the version.
|
-v or --version Print the version.
|
||||||
-r or --reload Reload cached remote resources.
|
-r or --reload Reload cached remote resources.
|
||||||
-D or --log-debug Log debug output.
|
-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,
|
"--log-debug" => flags.log_debug = true,
|
||||||
"--version" => flags.version = true,
|
"--version" => flags.version = true,
|
||||||
"--reload" => flags.reload = true,
|
"--reload" => flags.reload = true,
|
||||||
|
"--recompile" => flags.recompile = true,
|
||||||
"--allow-write" => flags.allow_write = true,
|
"--allow-write" => flags.allow_write = true,
|
||||||
"--allow-net" => flags.allow_net = true,
|
"--allow-net" => flags.allow_net = true,
|
||||||
"--allow-env" => flags.allow_env = true,
|
"--allow-env" => flags.allow_env = true,
|
||||||
|
|
|
@ -172,6 +172,7 @@ fn handle_start(i: *const isolate, base: &msg::Base) -> Box<Op> {
|
||||||
cwd: Some(cwd_off),
|
cwd: Some(cwd_off),
|
||||||
argv: Some(argv_off),
|
argv: Some(argv_off),
|
||||||
debug_flag: isolate.flags.log_debug,
|
debug_flag: isolate.flags.log_debug,
|
||||||
|
recompile_flag: isolate.flags.recompile,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -89,6 +89,7 @@ table StartRes {
|
||||||
argv: [string];
|
argv: [string];
|
||||||
debug_flag: bool;
|
debug_flag: bool;
|
||||||
deps_flag: bool;
|
deps_flag: bool;
|
||||||
|
recompile_flag: bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
table CodeFetch {
|
table CodeFetch {
|
||||||
|
|
Loading…
Reference in a new issue