Skip to content
Open
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
16 changes: 14 additions & 2 deletions feat/dependencies-of/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@ const flags = Flags.parse(Deno.args, {
alias: {
output: ['o'],
},
boolean: [
'isolate-std',
'isolate-files',
],
});
if (flags._.length !== 1) {
console.error(`usage: cli.ts <path/to/module.ts> [-o output.{png,svg,jpg,jpeg}]`);
Deno.exit(4);
}

const graphParams = new URLSearchParams();
if (flags['isolate-std']) {
graphParams.set('std', 'isolate');
}
if (flags['isolate-files']) {
graphParams.set('files', 'isolate');
}

import { computeGraph, renderGraph } from "./compute.ts";

const modUrl = `${flags._[0]}`;
Expand All @@ -25,10 +37,10 @@ if (flags.output) {
const dotProc = await renderGraph(modUrl, [
`-o${flags.output}`,
`-T${ext}`,
], new URLSearchParams());
], graphParams);
console.log(await dotProc.captureAllTextOutput());

} else {
const dotText = await computeGraph(modUrl, new URLSearchParams(), 'dot');
const dotText = await computeGraph(modUrl, graphParams, 'dot');
console.log(dotText);
}
1 change: 1 addition & 0 deletions lib/module-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class ModuleMap {
) {
this.registryOpts = {
mainModule: rootNode.specifier,
isolateFiles: this.args.get('files') === 'isolate',
isolateStd: this.args.get('std') === 'isolate',
}

Expand Down
25 changes: 24 additions & 1 deletion lib/module-registries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import type { CodeModule } from "./types.ts";

export interface RegistryOpts {
mainModule: string;
isolateFiles?: boolean;
isolateStd?: boolean;
};

export function determineModuleBase(fullUrl: string, opts: RegistryOpts): string {
const url = new URL(fullUrl);
const parts = fullUrl.split('/');
if (url.protocol === 'file:') return 'file://';
if (url.protocol === 'file:') {
if (opts.isolateFiles) return fullUrl;
if (url.pathname.endsWith('deps.ts')) return fullUrl;
return new URL('.', url).toString();
}
if (url.protocol !== 'https:') return fullUrl;
switch (url.host) {
case 'deno.land':
Expand Down Expand Up @@ -83,6 +88,24 @@ export function determineModuleBase(fullUrl: string, opts: RegistryOpts): string
export function determineModuleLabel(module: CodeModule, opts: RegistryOpts): string[] {
const url = new URL(module.base);
const parts = module.base.split('/');
if (url.protocol === 'file:') {
const mainDir = new URL('.', opts.mainModule).toString();
const thisDir = module.base;
if (thisDir.startsWith(mainDir)) {
return [`./${thisDir.slice(mainDir.length)}`];
}
const dirNames = mainDir.split('/');
dirNames.pop(); // trailing slash
let steps = 0;
while (dirNames.length > 5 && ++steps && dirNames.pop()) {
const joined = dirNames.join('/');
if (thisDir.startsWith(joined+'/')) {
const walkUp = new Array(steps).fill('..').join('/');
return [`${walkUp}/${thisDir.slice(joined.length+1)}`];
}
}
return [thisDir];
}
if (url.protocol !== 'https:') return [module.base];
switch (url.host) {
case 'deno.land': {
Expand Down