|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @flow |
| 8 | + */ |
| 9 | + |
| 10 | +type ResolveContext = { |
| 11 | + conditions: Array<string>, |
| 12 | + parentURL: string | void, |
| 13 | +}; |
| 14 | + |
| 15 | +type ResolveFunction = ( |
| 16 | + string, |
| 17 | + ResolveContext, |
| 18 | + ResolveFunction, |
| 19 | +) => Promise<string>; |
| 20 | + |
| 21 | +type GetSourceContext = { |
| 22 | + format: string, |
| 23 | + url: string, |
| 24 | +}; |
| 25 | + |
| 26 | +type GetSourceFunction = ( |
| 27 | + string, |
| 28 | + GetSourceContext, |
| 29 | + GetSourceFunction, |
| 30 | +) => Promise<{source: Source}>; |
| 31 | + |
| 32 | +type Source = string | ArrayBuffer | Uint8Array; |
| 33 | + |
| 34 | +export async function resolve( |
| 35 | + specifier: string, |
| 36 | + context: ResolveContext, |
| 37 | + defaultResolve: ResolveFunction, |
| 38 | +): Promise<string> { |
| 39 | + // TODO: Resolve server-only files. |
| 40 | + return defaultResolve(specifier, context, defaultResolve); |
| 41 | +} |
| 42 | + |
| 43 | +export async function getSource( |
| 44 | + url: string, |
| 45 | + context: GetSourceContext, |
| 46 | + defaultGetSource: GetSourceFunction, |
| 47 | +): Promise<{source: Source}> { |
| 48 | + if (url.endsWith('.client.js')) { |
| 49 | + // TODO: Named exports. |
| 50 | + const src = |
| 51 | + "export default { $$typeof: Symbol.for('react.module.reference'), name: " + |
| 52 | + JSON.stringify(url) + |
| 53 | + '}'; |
| 54 | + return {source: src}; |
| 55 | + } |
| 56 | + return defaultGetSource(url, context, defaultGetSource); |
| 57 | +} |
0 commit comments