mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
Implementing --deps flag
- Adding a ModuleId type alias to specify original url or local file of dependency - Modifying ModuleMetaData class to contain ModuleId - Adding a --deps flag
This commit is contained in:
parent
7784b0e17e
commit
fcdfacc2de
6 changed files with 34 additions and 8 deletions
|
@ -37,6 +37,11 @@ type ContainingFile = string;
|
|||
* like `/home/ry/.deno/gen/f7b4605dfbc4d3bb356e98fda6ceb1481e4a8df5.js`
|
||||
*/
|
||||
type ModuleFileName = string;
|
||||
/**
|
||||
* The original resolved resource name.
|
||||
* Path to cached module file or URL from which dependency was retrieved
|
||||
*/
|
||||
type ModuleId = string;
|
||||
/**
|
||||
* The external name of a module - could be a URL or could be a relative path.
|
||||
* Examples `http://gist.github.com/somefile.ts` or `./somefile.ts`
|
||||
|
@ -84,6 +89,7 @@ export class ModuleMetaData implements ts.IScriptSnapshot {
|
|||
public scriptVersion = "";
|
||||
|
||||
constructor(
|
||||
public readonly moduleId: ModuleId,
|
||||
public readonly fileName: ModuleFileName,
|
||||
public readonly sourceCode = "",
|
||||
public outputCode = ""
|
||||
|
@ -415,7 +421,7 @@ export class DenoCompiler implements ts.LanguageServiceHost {
|
|||
);
|
||||
this._gatherDependencies(moduleMetaData);
|
||||
const dependencies = this._runQueue.map(
|
||||
moduleMetaData => moduleMetaData.fileName
|
||||
moduleMetaData => moduleMetaData.moduleId
|
||||
);
|
||||
// empty the run queue, to free up references to factories we have collected
|
||||
// and to ensure that if there is a further invocation of `.run()` the
|
||||
|
@ -491,6 +497,7 @@ export class DenoCompiler implements ts.LanguageServiceHost {
|
|||
if (fileName && this._moduleMetaDataMap.has(fileName)) {
|
||||
return this._moduleMetaDataMap.get(fileName)!;
|
||||
}
|
||||
let moduleId: ModuleId = "";
|
||||
let sourceCode: string | undefined;
|
||||
let outputCode: string | undefined;
|
||||
if (
|
||||
|
@ -518,6 +525,7 @@ export class DenoCompiler implements ts.LanguageServiceHost {
|
|||
containingFile
|
||||
);
|
||||
}
|
||||
moduleId = fetchResponse.moduleName || "";
|
||||
fileName = fetchResponse.filename || undefined;
|
||||
sourceCode = fetchResponse.sourceCode || undefined;
|
||||
outputCode = fetchResponse.outputCode || undefined;
|
||||
|
@ -535,7 +543,12 @@ export class DenoCompiler implements ts.LanguageServiceHost {
|
|||
if (fileName && this._moduleMetaDataMap.has(fileName)) {
|
||||
return this._moduleMetaDataMap.get(fileName)!;
|
||||
}
|
||||
const moduleMetaData = new ModuleMetaData(fileName, sourceCode, outputCode);
|
||||
const moduleMetaData = new ModuleMetaData(
|
||||
moduleId,
|
||||
fileName,
|
||||
sourceCode,
|
||||
outputCode
|
||||
);
|
||||
this._moduleMetaDataMap.set(fileName, moduleMetaData);
|
||||
return moduleMetaData;
|
||||
}
|
||||
|
|
|
@ -112,13 +112,13 @@ const moduleMap: {
|
|||
} = {
|
||||
"/root/project": {
|
||||
"foo/bar.ts": mockModuleInfo(
|
||||
"foo/bar",
|
||||
"/root/project/foo/bar.ts",
|
||||
"/root/project/foo/bar.ts",
|
||||
fooBarTsSource,
|
||||
null
|
||||
),
|
||||
"foo/baz.ts": mockModuleInfo(
|
||||
"foo/baz",
|
||||
"/root/project/foo/baz.ts",
|
||||
"/root/project/foo/baz.ts",
|
||||
fooBazTsSource,
|
||||
fooBazTsOutput
|
||||
|
@ -127,7 +127,7 @@ const moduleMap: {
|
|||
},
|
||||
"/root/project/foo/baz.ts": {
|
||||
"./bar.ts": mockModuleInfo(
|
||||
"foo/bar",
|
||||
"/root/project/foo/bar.ts",
|
||||
"/root/project/foo/bar.ts",
|
||||
fooBarTsSource,
|
||||
fooBarTsOutput
|
||||
|
|
|
@ -85,5 +85,13 @@ export default function denoMain() {
|
|||
os.exit(1);
|
||||
}
|
||||
|
||||
const printDeps = startResMsg.depsFlag();
|
||||
if (printDeps) {
|
||||
for (const dep of compiler.getModuleDependencies(inputFn, `${cwd}/`)) {
|
||||
console.log(dep);
|
||||
}
|
||||
os.exit(0);
|
||||
}
|
||||
|
||||
compiler.run(inputFn, `${cwd}/`);
|
||||
}
|
||||
|
|
|
@ -21,12 +21,12 @@ pub struct DenoFlags {
|
|||
pub allow_write: bool,
|
||||
pub allow_net: bool,
|
||||
pub allow_env: bool,
|
||||
pub deps_flag: bool,
|
||||
}
|
||||
|
||||
pub fn print_usage() {
|
||||
println!(
|
||||
"Usage: deno script.ts
|
||||
|
||||
--allow-write Allow file system write access.
|
||||
--allow-net Allow network access.
|
||||
--allow-env Allow environment access.
|
||||
|
@ -34,7 +34,8 @@ pub fn print_usage() {
|
|||
-r or --reload Reload cached remote resources.
|
||||
-D or --log-debug Log debug output.
|
||||
-h or --help Print this message.
|
||||
--v8-options Print V8 command line options."
|
||||
--v8-options Print V8 command line options.
|
||||
--deps Print module dependencies."
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -54,6 +55,7 @@ pub fn set_flags(args: Vec<String>) -> (DenoFlags, Vec<String>) {
|
|||
"--allow-write" => flags.allow_write = true,
|
||||
"--allow-net" => flags.allow_net = true,
|
||||
"--allow-env" => flags.allow_env = true,
|
||||
"--deps" => flags.deps_flag = true,
|
||||
"--" => break,
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
|
@ -108,13 +110,14 @@ fn test_set_flags_2() {
|
|||
#[test]
|
||||
fn test_set_flags_3() {
|
||||
let (flags, rest) =
|
||||
set_flags(svec!["deno", "-r", "script.ts", "--allow-write"]);
|
||||
set_flags(svec!["deno", "-r", "--deps", "script.ts", "--allow-write"]);
|
||||
assert_eq!(rest, svec!["deno", "script.ts"]);
|
||||
assert_eq!(
|
||||
flags,
|
||||
DenoFlags {
|
||||
reload: true,
|
||||
allow_write: true,
|
||||
deps_flag: true,
|
||||
..DenoFlags::default()
|
||||
}
|
||||
);
|
||||
|
|
|
@ -116,6 +116,7 @@ fn handle_start(
|
|||
cwd: Some(cwd_off),
|
||||
argv: Some(argv_off),
|
||||
debug_flag: deno.flags.log_debug,
|
||||
deps_flag: deno.flags.deps_flag,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
|
|
@ -87,6 +87,7 @@ table StartRes {
|
|||
cwd: string;
|
||||
argv: [string];
|
||||
debug_flag: bool;
|
||||
deps_flag: bool;
|
||||
}
|
||||
|
||||
table CodeFetch {
|
||||
|
|
Loading…
Add table
Reference in a new issue