Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unexpected subpaths in import maps by updates #134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"cache": "deno cache ./lib/*/*.ts --lock",
"lock": "deno task -q cache --lock-write && git add deno.lock",
"check": "deno check ./*.ts ./lib/*.ts ./test/integration/*.ts",
"test": "NO_COLOR=1 deno test -A --no-check ./lib/*.ts",
"test": "NO_COLOR=1 deno test -A --no-check ./lib",
"all": "deno fmt && deno lint && deno task -q check && deno task lock && deno task -q test",
"integration": "NO_COLOR=1 deno test --no-lock -A ./test/integration/*.ts",
"run": "deno run --allow-env --allow-read --allow-net --allow-write=. --allow-run=git,deno cli.ts",
Expand Down
7 changes: 1 addition & 6 deletions lib/file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { assertExists } from "./std/assert.ts";
import { parse as parseJsonc } from "./std/jsonc.ts";
import { detectEOL } from "./std/fs.ts";
import { toUrl } from "./dependency.ts";
Expand Down Expand Up @@ -127,11 +126,7 @@ async function writeToImportMap(
const content = await Deno.readTextFile(update.path);
const json = parseJsonc(content) as unknown as ImportMapJson;
for (const dependency of update.dependencies) {
assertExists(dependency.map);
json.imports[dependency.map.key!] = dependency.map.resolved.replace(
toUrl(dependency.from),
toUrl(dependency.to),
);
json.imports[dependency.map!.key!] = toUrl(dependency.to);
}
await Deno.writeTextFile(update.path, JSON.stringify(json, null, 2));
}
15 changes: 7 additions & 8 deletions lib/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
type ModuleJson,
} from "./x/deno_graph.ts";
import { findFileUp, toPath, toUrl } from "./path.ts";
import { ImportMap, tryReadFromJson } from "./import_map.ts";
import {
ImportMap,
ImportMapResolveResult,
tryReadFromJson,
} from "./import_map.ts";
import {
type Dependency,
parse,
Expand Down Expand Up @@ -43,11 +47,7 @@ export interface DependencyUpdate {
/** The full path to the import map used to resolve the dependency.
* @example "/path/to/import_map.json" */
source: string;
/** The string in the dependency specifier being replaced */
key?: string;
/** The fully resolved specifier (URL) of the dependency. */
resolved: string;
};
} & ImportMapResolveResult;
}

class DenoGraph {
Expand Down Expand Up @@ -233,8 +233,7 @@ async function create(
map: mapped
? {
source: options!.importMap!.path,
key: mapped.key,
resolved: mapped.resolved,
...mapped,
}
: undefined,
};
Expand Down
2 changes: 1 addition & 1 deletion test/snapshots/file_test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ snapshot[`write - import_map/mod.ts 1`] = `
[
'{
"imports": {
"std/": "https://deno.land/std@123.456.789/assert.ts",
"std/": "https://deno.land/std@123.456.789/",
"deno_graph": "https://deno.land/x/deno_graph@123.456.789/mod.ts",
"node-emoji": "npm:node-emoji@123.456.789",
"/": "./"
Expand Down
Loading