summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/compiler.ts4
-rw-r--r--cli/js/compiler/host.ts9
-rw-r--r--cli/js/compiler/imports.ts63
3 files changed, 26 insertions, 50 deletions
diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts
index 385b76eec..d3cd67119 100644
--- a/cli/js/compiler.ts
+++ b/cli/js/compiler.ts
@@ -54,6 +54,7 @@ interface CompilerRequestCompile {
unstable: boolean;
bundle: boolean;
outFile?: string;
+ cwd: string;
}
interface CompilerRequestRuntimeCompile {
@@ -100,6 +101,7 @@ async function compile(
rootNames,
target,
unstable,
+ cwd,
} = request;
util.log(">>> compile start", {
rootNames,
@@ -132,7 +134,7 @@ async function compile(
// if there is a configuration supplied, we need to parse that
if (config && config.length && configPath) {
- const configResult = host.configure(configPath, config);
+ const configResult = host.configure(cwd, configPath, config);
diagnostics = processConfigureResponse(configResult, configPath);
}
diff --git a/cli/js/compiler/host.ts b/cli/js/compiler/host.ts
index afe184d3e..de2eacfa9 100644
--- a/cli/js/compiler/host.ts
+++ b/cli/js/compiler/host.ts
@@ -2,7 +2,6 @@
import { ASSETS, MediaType, SourceFile } from "./sourcefile.ts";
import { OUT_DIR, WriteFileCallback, getAsset } from "./util.ts";
-import { cwd } from "../ops/fs/dir.ts";
import { assert, notImplemented } from "../util.ts";
import * as util from "../util.ts";
@@ -167,7 +166,11 @@ export class Host implements ts.CompilerHost {
}
}
- configure(path: string, configurationText: string): ConfigureResponse {
+ configure(
+ cwd: string,
+ path: string,
+ configurationText: string
+ ): ConfigureResponse {
util.log("compiler::host.configure", path);
assert(configurationText);
const { config, error } = ts.parseConfigFileTextToJson(
@@ -179,7 +182,7 @@ export class Host implements ts.CompilerHost {
}
const { options, errors } = ts.convertCompilerOptionsFromJson(
config.compilerOptions,
- cwd()
+ cwd
);
const ignoredOptions: string[] = [];
for (const key of Object.keys(options)) {
diff --git a/cli/js/compiler/imports.ts b/cli/js/compiler/imports.ts
index 4261a4123..de4402758 100644
--- a/cli/js/compiler/imports.ts
+++ b/cli/js/compiler/imports.ts
@@ -1,60 +1,30 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { MediaType, SourceFile, SourceFileJson } from "./sourcefile.ts";
-import { normalizeString, CHAR_FORWARD_SLASH } from "./util.ts";
-import { cwd } from "../ops/fs/dir.ts";
import { assert } from "../util.ts";
import * as util from "../util.ts";
import * as compilerOps from "../ops/compiler.ts";
-function resolvePath(...pathSegments: string[]): string {
- let resolvedPath = "";
- let resolvedAbsolute = false;
-
- for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
- let path: string;
-
- if (i >= 0) path = pathSegments[i];
- else path = cwd();
-
- // Skip empty entries
- if (path.length === 0) {
- continue;
- }
-
- resolvedPath = `${path}/${resolvedPath}`;
- resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
- }
-
- // At this point the path should be resolved to a full absolute path, but
- // handle relative paths to be safe (might happen when cwd() fails)
-
- // Normalize the path
- resolvedPath = normalizeString(
- resolvedPath,
- !resolvedAbsolute,
- "/",
- (code) => code === CHAR_FORWARD_SLASH
- );
-
- if (resolvedAbsolute) {
- if (resolvedPath.length > 0) return `/${resolvedPath}`;
- else return "/";
- } else if (resolvedPath.length > 0) return resolvedPath;
- else return ".";
-}
-
function resolveSpecifier(specifier: string, referrer: string): string {
- if (!specifier.startsWith(".")) {
- return specifier;
+ // The resolveModules op only handles fully qualified URLs for referrer.
+ // However we will have cases where referrer is "/foo.ts". We add this dummy
+ // prefix "file://" in order to use the op.
+ // TODO(ry) Maybe we should perhaps ModuleSpecifier::resolve_import() to
+ // handle this situation.
+ let dummyPrefix = false;
+ const prefix = "file://";
+ if (referrer.startsWith("/")) {
+ dummyPrefix = true;
+ referrer = prefix + referrer;
+ }
+ let r = resolveModules([specifier], referrer)[0];
+ if (dummyPrefix) {
+ r = r.replace(prefix, "");
}
- const pathParts = referrer.split("/");
- pathParts.pop();
- let path = pathParts.join("/");
- path = path.endsWith("/") ? path : `${path}/`;
- return resolvePath(path, specifier);
+ return r;
}
+// TODO(ry) Remove. Unnecessary redirection to compilerOps.resolveModules.
export function resolveModules(
specifiers: string[],
referrer?: string
@@ -63,6 +33,7 @@ export function resolveModules(
return compilerOps.resolveModules(specifiers, referrer);
}
+// TODO(ry) Remove. Unnecessary redirection to compilerOps.fetchSourceFiles.
function fetchSourceFiles(
specifiers: string[],
referrer?: string