UNPKG

10 kBTypeScriptView Raw
1import { Loader, LoaderPlugin as AureliaLoaderPlugin, TemplateRegistryEntry } from 'aurelia-loader';
2export declare type LoaderPlugin = {
3 fetch: (address: string) => Promise<TemplateRegistryEntry> | TemplateRegistryEntry;
4};
5/**
6* An implementation of the TemplateLoader interface implemented with text-based loading.
7*/
8export declare class TextTemplateLoader {
9 /**
10 * Loads a template.
11 * @param loader The loader that is requesting the template load.
12 * @param entry The TemplateRegistryEntry to load and populate with a template.
13 * @return A promise which resolves when the TemplateRegistryEntry is loaded with a template.
14 */
15 loadTemplate(loader: Loader, entry: TemplateRegistryEntry): Promise<void>;
16}
17export declare function ensureOriginOnExports(moduleExports: any, moduleId: string): any;
18/**
19* A default implementation of the Loader abstraction which works with webpack (extended common-js style).
20*/
21export declare class WebpackLoader extends Loader {
22 moduleRegistry: any;
23 loaderPlugins: {
24 [name: string]: AureliaLoaderPlugin & {
25 hot?: (moduleId: string) => void;
26 };
27 };
28 modulesBeingLoaded: Map<string, Promise<any>>;
29 templateLoader: TextTemplateLoader;
30 hmrContext: {
31 handleModuleChange(moduleId: string, hot: WebpackHotModule): Promise<void>;
32 handleViewChange(moduleId: string): Promise<void>;
33 };
34 constructor();
35 _import(address: string, defaultHMR?: boolean): Promise<any>;
36 /**
37 * Maps a module id to a source.
38 * @param id The module id.
39 * @param source The source to map the module to.
40 */
41 map(id: string, source: any): void;
42 /**
43 * Normalizes a module id.
44 * @param moduleId The module id to normalize.
45 * @param relativeTo What the module id should be normalized relative to.
46 * @return The normalized module id.
47 */
48 normalizeSync(moduleId: string, relativeTo: string): string;
49 /**
50 * Normalizes a module id.
51 * @param moduleId The module id to normalize.
52 * @param relativeTo What the module id should be normalized relative to.
53 * @return The normalized module id.
54 */
55 normalize(moduleId: string, relativeTo: string): Promise<string>;
56 /**
57 * Instructs the loader to use a specific TemplateLoader instance for loading templates
58 * @param templateLoader The instance of TemplateLoader to use for loading templates.
59 */
60 useTemplateLoader(templateLoader: TextTemplateLoader): void;
61 /**
62 * Loads a collection of modules.
63 * @param ids The set of module ids to load.
64 * @return A Promise for an array of loaded modules.
65 */
66 loadAllModules(ids: Array<string>): Promise<any[]>;
67 /**
68 * Loads a module.
69 * @param moduleId The module ID to load.
70 * @return A Promise for the loaded module.
71 */
72 loadModule(moduleId: string, defaultHMR?: boolean): Promise<any>;
73 /**
74 * Loads a template.
75 * @param url The url of the template to load.
76 * @return A Promise for a TemplateRegistryEntry containing the template.
77 */
78 loadTemplate(url: string): Promise<any>;
79 /**
80 * Loads a text-based resource.
81 * @param url The url of the text file to load.
82 * @return A Promise for text content.
83 */
84 loadText(url: string): Promise<any>;
85 /**
86 * Alters a module id so that it includes a plugin loader.
87 * @param url The url of the module to load.
88 * @param pluginName The plugin to apply to the module id.
89 * @return The plugin-based module id.
90 */
91 applyPluginToUrl(url: string, pluginName: string): string;
92 /**
93 * Registers a plugin with the loader.
94 * @param pluginName The name of the plugin.
95 * @param implementation The plugin implementation.
96 */
97 addPlugin(pluginName: string, implementation: AureliaLoaderPlugin): void;
98}
99export declare type HotModuleStatus = 'idle' | 'check' | 'watch' | 'watch-delay' | 'prepare' | 'ready' | 'dispose' | 'apply' | 'abort' | 'fail';
100export interface WebpackHotModule {
101 /**
102 * Accept code updates for the specified dependencies. The callback is called when dependencies were replaced.
103 */
104 accept(dependencies: string[], callback: (updatedDependencies: Array<string>) => void): void;
105 /**
106 * Accept code updates for the specified dependencies. The callback is called when dependencies were replaced.
107 */
108 accept(dependency: string, callback: () => void): void;
109 /**
110 * Accept code updates for this module without notification of parents. This should only be used if the module doesn’t export anything. The errHandler can be used to handle errors that occur while loading the updated module.
111 */
112 accept(errHandler?: (e: Error) => void): void;
113 /**
114 * Do not accept updates for the specified dependencies. If any dependencies is updated, the code update fails with code "decline".
115 */
116 decline(dependencies: string[]): void;
117 /**
118 * Do not accept updates for the specified dependencies. If any dependencies is updated, the code update fails with code "decline".
119 */
120 decline(dependency: string): void;
121 /**
122 * Flag the current module as not update-able. If updated the update code would fail with code "decline".
123 */
124 decline(): void;
125 /**
126 * Add a one time handler, which is executed when the current module code is replaced. Here you should destroy/remove any persistent resource you have claimed/created. If you want to transfer state to the new module, add it to data object. The data will be available at module.hot.data on the new module.
127 */
128 dispose(callback: (data: any) => void): void;
129 /**
130 * Add a one time handler, which is executed when the current module code is replaced. Here you should destroy/remove any persistent resource you have claimed/created. If you want to transfer state to the new module, add it to data object. The data will be available at module.hot.data on the new module.
131 */
132 addDisposeHandler(callback: (data: any) => void): void;
133 /**
134 * Remove a dispose handler.
135 * This can useful to add a temporary dispose handler. You could i. e. replace code while in the middle of a multi-step async function.
136 */
137 removeDisposeHandler(callback: (data: any) => void): void;
138 /**
139 * Throws an exceptions if status() is not idle.
140 * Check all currently loaded modules for updates and apply updates if found.
141 * If no update was found, the callback is called with null.
142 * If autoApply is truthy the callback will be called with all modules that were disposed. apply() is automatically called with autoApply as options parameter.
143 * If autoApply is not set the callback will be called with all modules that will be disposed on apply().
144 */
145 check(autoApply: boolean, callback: (err: Error, outdatedModules: any[]) => void): void;
146 /**
147 * Throws an exceptions if status() is not idle.
148 * Check all currently loaded modules for updates and apply updates if found.
149 * If no update was found, the callback is called with null.
150 * If autoApply is not set the callback will be called with all modules that will be disposed on apply().
151 */
152 check(callback: (err: Error, outdatedModules: NodeModule[]) => void): void;
153 /**
154 * Continue the update process.
155 * If status() != "ready" it throws an error.
156 */
157 apply(options: HotOptions, callback: (err: Error, outdatedModules: any[]) => void): void;
158 apply(callback: (err: Error, outdatedModules: any[]) => void): void;
159 /**
160 * Return one of idle, check, watch, watch-delay, prepare, ready, dispose, apply, abort or fail.
161 *
162 * - `idle`
163 * The HMR is waiting for your call the check(). When you call it the status will change to check.
164 *
165 * - `check`
166 * The HMR is checking for updates. If it doesn’t find updates it will change back to idle. If updates were found it will go through the steps prepare, dispose and apply. Than back to idle.
167 *
168 * - `watch`
169 * The HMR is in watch mode and will automatically be notified about changes. After the first change it will change to watch-delay and wait for a specified time to start the update process. Any change will reset the timeout, to accumulate more changes. When the update process is started it will go through the steps prepare, dispose and apply. Than back to watch or watch-delay if changes were detected while updating.
170 *
171 * - `prepare`
172 * The HMR is prepare stuff for the update. This may means that it’s downloading something.
173 *
174 * - `ready`
175 * An update is available and prepared. Call apply() to continue.
176 *
177 * - `dispose`
178 * The HMR is calling the dispose handlers of modules that will be replaced.
179 *
180 * - `apply`
181 * The HMR is calling the accept handlers of the parents of replaced modules, than it requires the self accepted modules.
182 *
183 * - `abort`
184 * A update cannot apply, but the system is still in a (old) consistent state.
185 *
186 * - `fail`
187 * A update has thrown an exception in the middle of the process, and the system is (maybe) in a inconsistent state. The system should be restarted.
188 */
189 status(): HotModuleStatus;
190 /**
191 * Register a callback on status change.
192 */
193 status(callback: (status: HotModuleStatus) => void): void;
194 /**
195 * Register a callback on status change.
196 */
197 addStatusHandler(callback: (status: HotModuleStatus) => void): void;
198 /**
199 * Data from the previous version of this module, if set and disposed using the dispose() handler.
200 */
201 data?: any;
202}
203export interface HotOptions {
204 /**
205 * If true the update process continues even if some modules are not accepted (and would bubble to the entry point).
206 */
207 ignoreUnaccepted?: boolean;
208}