Skip to content

Commit ee080be

Browse files
committed
Switch to type definitions from /x/deno_graph
1 parent 05d1f95 commit ee080be

4 files changed

Lines changed: 17 additions & 53 deletions

File tree

deps.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ export * as entities from "https://deno.land/x/html_entities@v1.0/lib/xml-entiti
1212

1313
export { SubProcess, type SubprocessErrorData } from "https://crux.land/4KsAxM#sub-process";
1414
export { filesize } from "https://crux.land/6wZ5Sz#filesize@v1";
15+
16+
// maybe someday we actually use deno_graph's code too
17+
export type {
18+
ModuleGraphJson,
19+
ModuleJson,
20+
} from "https://deno.land/x/deno_graph@0.43.2/lib/types.d.ts";

feat/dependencies-of/compute.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { SubProcess } from "../../deps.ts";
2-
import { DenoInfo } from "../../lib/types.ts";
1+
import { ModuleGraphJson, SubProcess } from "../../deps.ts";
32
import { computeDependencies } from "../../lib/module-map.ts";
43

54
export async function computeGraph(
@@ -14,7 +13,7 @@ export async function computeGraph(
1413
env: { "NO_COLOR": "yas" },
1514
stdin: 'null',
1615
errorPrefix: /^error: /,
17-
}).captureAllTextOutput()) as DenoInfo;
16+
}).captureAllTextOutput()) as ModuleGraphJson;
1817

1918
return computeDependencies(downloadData, args);
2019
}

lib/module-map.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { filesize } from "../deps.ts";
2-
import { CodeModule, DenoInfo, DenoModule } from "./types.ts";
1+
import { filesize, ModuleGraphJson, ModuleJson } from "../deps.ts";
2+
import { CodeModule } from "./types.ts";
33
import * as registries from "./module-registries.ts";
44

55
export class ModuleMap {
@@ -10,7 +10,7 @@ export class ModuleMap {
1010
constructor(
1111
public args: URLSearchParams,
1212
public redirects: Record<string,string>,
13-
public rootNode: DenoModule,
13+
public rootNode: ModuleJson,
1414
) {
1515
this.registryOpts = {
1616
mainModule: rootNode.specifier,
@@ -41,7 +41,7 @@ export class ModuleMap {
4141
return moduleInfo;
4242
}
4343

44-
addFile(url: string, info: DenoModule, data: DenoInfo) {
44+
addFile(url: string, info: ModuleJson, data: ModuleGraphJson) {
4545
if (info.error != null) {
4646
const module = this.grabModFor(url, '#error');
4747
if (!module.errors) module.errors = [];
@@ -58,7 +58,7 @@ export class ModuleMap {
5858
}
5959

6060
const module = this.grabModFor(url);
61-
module.totalSize += info.size;
61+
module.totalSize += info.size ?? 0;
6262
module.files.push({
6363
url: url,
6464
deps: depEdges,
@@ -176,7 +176,7 @@ export class ModuleMap {
176176

177177
}
178178

179-
export function processDenoInfo(data: DenoInfo, args?: URLSearchParams) {
179+
export function processDenoInfo(data: ModuleGraphJson, args?: URLSearchParams) {
180180
// TODO: when are there multiple roots?
181181
const roots = data.roots.map(x => data.redirects[x] || x);
182182
const rootNode = data.modules.find(x => roots.includes(x.specifier));
@@ -193,7 +193,7 @@ export function processDenoInfo(data: DenoInfo, args?: URLSearchParams) {
193193
return map;
194194
}
195195

196-
export function computeDependencies(data: DenoInfo, args: URLSearchParams) {
196+
export function computeDependencies(data: ModuleGraphJson, args: URLSearchParams) {
197197
const map = processDenoInfo(data, args);
198198

199199
// Allow output different levels of processing
@@ -218,7 +218,7 @@ export function computeDependencies(data: DenoInfo, args: URLSearchParams) {
218218
if (import.meta.main) {
219219
const rawData = new TextDecoder().decode(await Deno.readAll(Deno.stdin));
220220
if (rawData[0] !== '{') throw new Error(`Expected JSON from "deno info --json"`);
221-
const data = JSON.parse(rawData) as DenoInfo;
221+
const data = JSON.parse(rawData) as ModuleGraphJson;
222222

223223
const args = new URLSearchParams(Deno.args[0]);
224224

lib/types.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,6 @@ export interface CodeModule {
99
files: {
1010
url: string;
1111
deps: string[];
12-
size: number;
12+
size?: number;
1313
}[];
1414
};
15-
16-
17-
export interface DenoInfo {
18-
roots: string[];
19-
modules: DenoModule[];
20-
redirects: Record<string,string>;
21-
}
22-
23-
interface DenoModuleInfo {
24-
size: number;
25-
mediaType: DenoMediaType;
26-
local: string;
27-
emit?: string;
28-
error: undefined;
29-
}
30-
interface DenoModuleError {
31-
error: string;
32-
}
33-
export type DenoModule = {
34-
specifier: string;
35-
dependencies?: DenoDependency[];
36-
typesDependency?: {
37-
specifier: string;
38-
dependency: { specifier: string }; // also the span
39-
};
40-
} & (
41-
| DenoModuleInfo
42-
| DenoModuleError
43-
);
44-
45-
export interface DenoDependency {
46-
specifier: string;
47-
code?: { specifier: string }; // also the span
48-
type?: { specifier: string }; // also the span
49-
}
50-
51-
export type DenoMediaType =
52-
| "TypeScript"
53-
| "JavaScript"
54-
| "Dts"
55-
;

0 commit comments

Comments
 (0)