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

Dependency tree analysis #15

Merged
merged 7 commits into from
Aug 19, 2020
Merged

Dependency tree analysis #15

merged 7 commits into from
Aug 19, 2020

Conversation

SteelAlloy
Copy link
Member

@SteelAlloy SteelAlloy commented Aug 19, 2020

@divy-work I've moved some files around, tell me how you want to structure the project between Deno's only files, those for the web and the rest.

So I propose the possibility to build a dependency tree and to analyze its imports.

function dependencyTree(path: string, options: TreeOptions): Promise<IDependencyTree>

//Where :
export type DependencyTree = Array<{
  path: string;
  imports: DependencyTree;
}>;

export interface IDependencyTree {
  tree: DependencyTree; // The actual tree
  circular: boolean; // Are there circular imports?
  count: number; // The number of imported files, by removing duplicate entries
  iterator: IterableIterator<string>; // An iterable dependency iterator to, for example, detect whether the tree contains broken dependencies. 
}

export interface TreeOptions {
  fullTree: boolean; // By default, redundant imports are ignored, i.e. they are already elsewhere in the tree and are not duplicated
}

Currently, it only works for Deno but there is almost nothing to change to make it work on the web, tell me how to make it clean without duplicate functions.

/* Resolves any path, relative or HTTP url. */
export function resolveURL(path: string, base = "") {
  if (path.match(/^https?:\/\//)) {
    return path;
  }
  if (base.match(/^https?:\/\//)) {
    return new URL(path, base).href;
  }
 - return fileURL(path, base);
}

/* Fetch data from file: or https: urls */
async function fetchData(url: string) {
-  if (url.match(/^https?:\/\//)) {
    const data = await fetch(url);
    return data.text();
-  }
-  const data = await Deno.readFile(resolve(fromFileUrl(url)));
-  return decoder.decode(data);
}

@vercel
Copy link

vercel bot commented Aug 19, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nestdotland/analyzer/ekecumnzs
✅ Preview: https://analyzer-git-feat-dependency-tree.nestdotland.vercel.app

deno/analyze.ts Outdated Show resolved Hide resolved
egg.json Outdated Show resolved Hide resolved
deno/dependencyTree.ts Outdated Show resolved Hide resolved
Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay

@littledivy littledivy merged commit f10c88e into master Aug 19, 2020
@littledivy littledivy deleted the feat/dependency-tree branch August 19, 2020 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants