diff options
author | Mirko Jotic <joticmirko@gmail.com> | 2018-09-02 18:50:46 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-09-06 10:42:07 -0400 |
commit | fcdfacc2de72e52b3f82dbce37746d371c3ad3ab (patch) | |
tree | 59e21b83c723ec38e96d824521fe72d57b1f65d7 /js | |
parent | 7784b0e17e2d54fd130e274bdb3aba4a2d1b2e9a (diff) |
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
Diffstat (limited to 'js')
-rw-r--r-- | js/compiler.ts | 17 | ||||
-rw-r--r-- | js/compiler_test.ts | 6 | ||||
-rw-r--r-- | js/main.ts | 8 |
3 files changed, 26 insertions, 5 deletions
diff --git a/js/compiler.ts b/js/compiler.ts index eaf64ce87..d92838652 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -38,6 +38,11 @@ type ContainingFile = string; */ 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; } diff --git a/js/compiler_test.ts b/js/compiler_test.ts index d27818c9c..c056cf932 100644 --- a/js/compiler_test.ts +++ b/js/compiler_test.ts @@ -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 diff --git a/js/main.ts b/js/main.ts index 94ded73e1..538d0cc27 100644 --- a/js/main.ts +++ b/js/main.ts @@ -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}/`); } |