UNPKG

5.16 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at
5 * http://polymer.github.io/LICENSE.txt
6 * The complete set of authors may be found at
7 * http://polymer.github.io/AUTHORS.txt
8 * The complete set of contributors may be found at
9 * http://polymer.github.io/CONTRIBUTORS.txt
10 * Code distributed by Google as part of the polymer project is also
11 * subject to an additional IP rights grant found at
12 * http://polymer.github.io/PATENTS.txt
13 */
14/// <reference path="../../custom_typings/main.d.ts" />
15import { ParsedDocument } from '..';
16import { Analysis } from '../model/model';
17import { PackageRelativeUrl, ResolvedUrl } from '../model/url';
18import { Parser } from '../parser/parser';
19import { Scanner } from '../scanning/scanner';
20import { UrlLoader } from '../url-loader/url-loader';
21import { UrlResolver } from '../url-loader/url-resolver';
22import { AnalysisContext } from './analysis-context';
23import { MinimalCancelToken } from './cancel-token';
24export interface Options {
25 urlLoader: UrlLoader;
26 urlResolver?: UrlResolver;
27 parsers?: Map<string, Parser<ParsedDocument>>;
28 scanners?: ScannerTable;
29 /**
30 * Map from url of an HTML Document to another HTML document it lazily depends
31 * on.
32 */
33 lazyEdges?: LazyEdgeMap;
34 /**
35 * Algorithm to use for resolving module specifiers in import
36 * and export statements when rewriting them to be web-compatible.
37 * A value of 'node' uses Node.js resolution to find modules.
38 */
39 moduleResolution?: 'node';
40 __contextPromise?: Promise<AnalysisContext>;
41}
42export interface AnalyzeOptions {
43 /**
44 * Used to indicate that the caller no longer cares about the result
45 * of the analysis, to save on effort.
46 */
47 readonly cancelToken?: MinimalCancelToken;
48}
49/**
50 * These are the options available to the `_fork` method. Currently, only the
51 * `urlLoader` override is implemented.
52 */
53export interface ForkOptions {
54 urlLoader?: UrlLoader;
55}
56export declare class NoKnownParserError extends Error {
57}
58export declare type ScannerTable = Map<string, Scanner<ParsedDocument, {} | null | undefined, {}>[]>;
59export declare type LazyEdgeMap = Map<ResolvedUrl, PackageRelativeUrl[]>;
60/**
61 * A static analyzer for web projects.
62 *
63 * An Analyzer can load and parse documents of various types, and extract
64 * arbitrary information from the documents, and transitively load
65 * dependencies. An Analyzer instance is configured with parsers, and scanners
66 * which do the actual work of understanding different file types.
67 */
68export declare class Analyzer {
69 private _analysisComplete;
70 readonly urlResolver: UrlResolver;
71 private readonly _urlLoader;
72 constructor(options: Options);
73 /**
74 * Loads, parses and analyzes the root document of a dependency graph and its
75 * transitive dependencies.
76 */
77 analyze(urls: string[], options?: AnalyzeOptions): Promise<Analysis>;
78 analyzePackage(options?: AnalyzeOptions): Promise<Analysis>;
79 private _filterFilesByParsableExtension;
80 private _constructAnalysis;
81 /**
82 * Clears all information about the given files from our caches, such that
83 * future calls to analyze() will reload these files if they're needed.
84 *
85 * The analyzer assumes that if this method isn't called with a file's url,
86 * then that file has not changed and does not need to be reloaded.
87 *
88 * @param urls The urls of files which may have changed.
89 */
90 filesChanged(urls: string[]): Promise<void>;
91 /**
92 * Clear all cached information from this analyzer instance.
93 *
94 * Note: if at all possible, instead tell the analyzer about the specific
95 * files that changed rather than clearing caches like this. Caching provides
96 * large performance gains.
97 */
98 clearCaches(): Promise<void>;
99 /**
100 * Returns a copy of the analyzer. If options are given, the AnalysisContext
101 * is also forked and individual properties are overridden by the options.
102 * is forked with the given options.
103 *
104 * When the analysis context is forked, its cache is preserved, so you will
105 * see a mixture of pre-fork and post-fork contents when you analyze with a
106 * forked analyzer.
107 *
108 * Note: this feature is experimental. It may be removed without being
109 * considered a breaking change, so check for its existence before calling
110 * it.
111 */
112 _fork(options?: ForkOptions): Analyzer;
113 /**
114 * Returns `true` if the provided resolved URL can be loaded. Obeys the
115 * semantics defined by `UrlLoader` and should only be used to check
116 * resolved URLs.
117 */
118 canLoad(resolvedUrl: ResolvedUrl): boolean;
119 /**
120 * Loads the content at the provided resolved URL. Obeys the semantics
121 * defined by `UrlLoader` and should only be used to attempt to load resolved
122 * URLs.
123 */
124 load(resolvedUrl: ResolvedUrl): Promise<string>;
125 /**
126 * Resoves `url` to a new location.
127 */
128 resolveUrl(url: string): ResolvedUrl | undefined;
129 private brandUserInputUrls;
130}