-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: add ModuleGraph
type
#528
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
|
||
export enum MediaType { | ||
JavaScript = "JavaScript", | ||
Mjs = "Mjs", | ||
Cjs = "Cjs", | ||
Jsx = "Jsx", | ||
TypeScript = "TypeScript", | ||
Mts = "Mts", | ||
Cts = "Cts", | ||
Dts = "Dts", | ||
Dmts = "Dmts", | ||
Dcts = "Dcts", | ||
Tsx = "Tsx", | ||
Json = "Json", | ||
Wasm = "Wasm", | ||
TsBuildInfo = "TsBuildInfo", | ||
SourceMap = "SourceMap", | ||
Unknown = "Unknown", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
|
||
import type { MediaType } from "./media_type.ts"; | ||
|
||
/** Additional meta data that is used to enrich the output of the module | ||
* graph. */ | ||
export interface CacheInfo { | ||
/** The string path to where the local version of the content is located. For | ||
* non `file:` URLs, this is the location of the cached content, otherwise it | ||
* is the absolute path to the local file. */ | ||
local?: string; | ||
/** The string path to where a transpiled version of the source content is | ||
* located, if any. */ | ||
emit?: string; | ||
/** The string path to where an external source map of the transpiled source | ||
* content is located, if any. */ | ||
map?: string; | ||
} | ||
|
||
export interface TypesDependency { | ||
/** The string URL to the type information for the module. */ | ||
types: string; | ||
/** An optional range which indicates the source of the dependency. */ | ||
source?: Range; | ||
} | ||
|
||
export interface LoadResponseModule { | ||
/** A module with code has been loaded. */ | ||
kind: "module"; | ||
/** The string URL of the resource. If there were redirects, the final | ||
* specifier should be set here, otherwise the requested specifier. */ | ||
specifier: string; | ||
/** For remote resources, a record of headers should be set, where the key's | ||
* have been normalized to be lower case values. */ | ||
headers?: Record<string, string>; | ||
/** The string value of the loaded resources. */ | ||
content: string; | ||
} | ||
|
||
export interface LoadResponseExternal { | ||
/** The loaded module is either _external_ or _built-in_ to the runtime. */ | ||
kind: "external"; | ||
/** The strung URL of the resource. If there were redirects, the final | ||
* specifier should be set here, otherwise the requested specifier. */ | ||
specifier: string; | ||
} | ||
|
||
export type LoadResponse = LoadResponseModule | LoadResponseExternal; | ||
|
||
export interface PositionJson { | ||
/** The line number of a position within a source file. The number is a zero | ||
* based index. */ | ||
line: number; | ||
/** The character number of a position within a source file. The number is a | ||
* zero based index. */ | ||
character: number; | ||
} | ||
|
||
export interface Range { | ||
/** A string URL representing a source of a dependency. */ | ||
specifier: string; | ||
/** The start location of a range of text in a source file. */ | ||
start?: PositionJson; | ||
/** The end location of a range of text in a source file. */ | ||
end?: PositionJson; | ||
} | ||
|
||
export interface RangeJson { | ||
/** The start location of a range of text in a source file. */ | ||
start: PositionJson; | ||
/** The end location of a range of text in a source file. */ | ||
end: PositionJson; | ||
} | ||
|
||
export interface ResolvedDependency { | ||
/** The fully resolved string URL of the dependency, which should be | ||
* resolvable in the module graph. If there was an error, `error` will be set | ||
* and this will be undefined. */ | ||
specifier?: string; | ||
/** Any error encountered when trying to resolved the specifier. If this is | ||
* defined, `specifier` will be undefined. */ | ||
error?: string; | ||
/** The range within the source code where the specifier was identified. */ | ||
span: RangeJson; | ||
} | ||
|
||
export interface TypesDependencyJson { | ||
/** The string specifier that was used for the dependency. */ | ||
specifier: string; | ||
/** An object pointing to the resolved dependency. */ | ||
dependency: ResolvedDependency; | ||
} | ||
|
||
/** The kind of module. | ||
* | ||
* For asserted modules, the value of the `asserted` property is set to the | ||
* `type` value of the import attribute. | ||
* | ||
* Dependency analysis is not performed for asserted or Script modules | ||
* currently. Synthetic modules were injected into the graph with their own | ||
* dependencies provided. */ | ||
export type ModuleKind = | ||
| "asserted" | ||
| "esm" | ||
| "npm" | ||
| "external"; | ||
|
||
export interface DependencyJson { | ||
/** The string specifier that was used for the dependency. */ | ||
specifier: string; | ||
/** An object pointing to the resolved _code_ dependency. */ | ||
code?: ResolvedDependency; | ||
/** An object pointing to the resolved _type_ dependency of a module. This is | ||
* populated when the `@deno-types` directive was used to supply a type | ||
* definition file for a dependency. */ | ||
type?: ResolvedDependency; | ||
/** A flag indicating if the dependency was dynamic. (e.g. | ||
* `await import("mod.ts")`) */ | ||
isDynamic?: true; | ||
assertionType?: string; | ||
} | ||
|
||
// todo(dsherret): split this up into separate types based on the "kind" | ||
|
||
export interface ModuleJson extends CacheInfo { | ||
/** The string URL of the module. */ | ||
specifier: string; | ||
/** Any error encountered when attempting to load the module. */ | ||
error?: string; | ||
/** The module kind that was determined when the module was resolved. This is | ||
* used by loaders to indicate how a module needs to be loaded at runtime. */ | ||
kind?: ModuleKind; | ||
/** An array of dependencies that were identified in the module. */ | ||
dependencies?: DependencyJson[]; | ||
/** If the module had a types dependency, the information about that | ||
* dependency. */ | ||
typesDependency?: TypesDependencyJson; | ||
/** The resolved media type of the module, which determines how Deno will | ||
* handle the module. */ | ||
mediaType?: MediaType; | ||
/** The size of the source content of the module in bytes. */ | ||
size?: number; | ||
} | ||
|
||
export interface GraphImportJson { | ||
/** The referrer (URL string) that was used as a base when resolving the | ||
* imports added to the graph. */ | ||
referrer: string; | ||
/** An array of resolved dependencies which were imported using the | ||
* referrer. */ | ||
dependencies?: DependencyJson[]; | ||
} | ||
|
||
/** The plain-object representation of a module graph that is suitable for | ||
* serialization to JSON. */ | ||
export interface ModuleGraphJson { | ||
/** The module specifiers (URL string) of the _roots_ of the module graph of | ||
* which the module graph was built for. */ | ||
roots: string[]; | ||
/** An array of modules that are part of the module graph. */ | ||
modules: ModuleJson[]; | ||
/** External imports that were added to the graph when it was being built. | ||
* The key is the referrer which was used as a base to resolve the | ||
* dependency. The value is the resolved dependency. */ | ||
imports?: GraphImportJson[]; | ||
/** A record/map of any redirects encountered when resolving modules. The | ||
* key was the requested module specifier and the value is the redirected | ||
* module specifier. */ | ||
redirects: Record<string, string>; | ||
} | ||
|
||
export interface Dependency { | ||
/** An object pointing to the resolved _code_ dependency. */ | ||
code?: ResolvedDependency; | ||
/** An object pointing to the resolved _type_ dependency of a module. This is | ||
* populated when the `@deno-types` directive was used to supply a type | ||
* definition file for a dependency. */ | ||
type?: ResolvedDependency; | ||
/** A flag indicating if the dependency was dynamic. (e.g. | ||
* `await import("mod.ts")`) */ | ||
isDynamic?: true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks for documenting this!