expo-asset 8.4.2 → 8.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,9 +10,23 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 8.4.22021-10-15
13
+ ## 8.4.62022-01-13
14
14
 
15
- _This version does not introduce any user-facing changes._
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fix missing `getManifest2()` function on web. ([#15891](https://github.com/expo/expo/pull/15891)) by [@jonsamp](https://github.com/jonsamp)
18
+
19
+ ## 8.4.5 — 2021-12-21
20
+
21
+ ### 🐛 Bug fixes
22
+
23
+ - Fix an issue preventing the loading of assets using expo-updates manifests during local development. ([#15667](https://github.com/expo/expo/pull/15667)) by [@jonsamp](https://github.com/jonsamp)
24
+
25
+ ## 8.4.4 — 2021-11-17
26
+
27
+ ### 🐛 Bug fixes
28
+
29
+ - Fix `fromModule` on restrictive (Snack) web environments. ([#14435](https://github.com/expo/expo/pull/14435) by [@IjzerenHein](https://github.com/IjzerenHein))
16
30
 
17
31
  ## 8.4.1 — 2021-10-01
18
32
 
@@ -24,13 +38,13 @@ _This version does not introduce any user-facing changes._
24
38
 
25
39
  ### 🎉 New features
26
40
 
27
- - Reapply [#12624](https://github.com/expo/expo/pull/12624) ([#13789](https://github.com/expo/expo/pull/13789) by [@jkhales](https://github.com/jkhales))
41
+ - Reapply [#12624](https://github.com/expo/expo/pull/12624) ([#13789](https://github.com/expo/expo/pull/13789) by [@jkhales](https://github.com/jkhales))
28
42
 
29
43
  ## 8.3.2 — 2021-04-21
30
44
 
31
45
  ### 🎉 New features
32
46
 
33
- - Find local assets without extensions. ([#12624](https://github.com/expo/expo/pull/12624) by [@jkhales](https://github.com/jkhales))
47
+ - Find local assets without extensions. ([#12624](https://github.com/expo/expo/pull/12624) by [@jkhales](https://github.com/jkhales))
34
48
 
35
49
  ## 8.3.1 — 2021-03-23
36
50
 
@@ -64,11 +78,11 @@ _This version does not introduce any user-facing changes._
64
78
 
65
79
  ## 8.1.7 — 2020-05-29
66
80
 
67
- *This version does not introduce any user-facing changes.*
81
+ _This version does not introduce any user-facing changes._
68
82
 
69
83
  ## 8.1.6 — 2020-05-27
70
84
 
71
- *This version does not introduce any user-facing changes.*
85
+ _This version does not introduce any user-facing changes._
72
86
 
73
87
  ## 8.1.5
74
88
 
package/README.md CHANGED
@@ -13,7 +13,7 @@ For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-
13
13
 
14
14
  # Installation in bare React Native projects
15
15
 
16
- For bare React Native projects, you must ensure that you have [installed and configured the `react-native-unimodules` package](https://github.com/expo/expo/tree/master/packages/react-native-unimodules) before continuing.
16
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
17
17
 
18
18
  ### Add the package to your npm dependencies
19
19
 
package/build/Asset.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import * as AssetSources from './AssetSources';
2
- declare type AssetDescriptor = {
1
+ import { AssetMetadata } from './AssetSources';
2
+ export declare type AssetDescriptor = {
3
3
  name: string;
4
4
  type: string;
5
5
  hash?: string | null;
@@ -11,25 +11,89 @@ declare type DownloadPromiseCallbacks = {
11
11
  resolve: () => void;
12
12
  reject: (error: Error) => void;
13
13
  };
14
- export declare type AssetMetadata = AssetSources.AssetMetadata;
14
+ export { AssetMetadata };
15
+ /**
16
+ * The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its
17
+ * name and type) and provides facilities to load the asset data.
18
+ */
15
19
  export declare class Asset {
20
+ /**
21
+ * @private
22
+ */
16
23
  static byHash: {};
24
+ /**
25
+ * @private
26
+ */
17
27
  static byUri: {};
28
+ /**
29
+ * The name of the asset file without the extension. Also without the part from `@` onward in the
30
+ * filename (used to specify scale factor for images).
31
+ */
18
32
  name: string;
33
+ /**
34
+ * The extension of the asset filename.
35
+ */
19
36
  type: string;
37
+ /**
38
+ * The MD5 hash of the asset's data.
39
+ */
20
40
  hash: string | null;
41
+ /**
42
+ * A URI that points to the asset's data on the remote server. When running the published version
43
+ * of your app, this refers to the location on Expo's asset server where Expo has stored your
44
+ * asset. When running the app from Expo CLI during development, this URI points to Expo CLI's
45
+ * server running on your computer and the asset is served directly from your computer.
46
+ */
21
47
  uri: string;
48
+ /**
49
+ * If the asset has been downloaded (by calling [`downloadAsync()`](#downloadasync)), the
50
+ * `file://` URI pointing to the local file on the device that contains the asset data.
51
+ */
22
52
  localUri: string | null;
53
+ /**
54
+ * If the asset is an image, the width of the image data divided by the scale factor. The scale
55
+ * factor is the number after `@` in the filename, or `1` if not present.
56
+ */
23
57
  width: number | null;
58
+ /**
59
+ * If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.
60
+ */
24
61
  height: number | null;
25
62
  downloading: boolean;
26
63
  downloaded: boolean;
64
+ /**
65
+ * @private
66
+ */
27
67
  _downloadCallbacks: DownloadPromiseCallbacks[];
28
68
  constructor({ name, type, hash, uri, width, height }: AssetDescriptor);
69
+ /**
70
+ * A helper that wraps `Asset.fromModule(module).downloadAsync` for convenience.
71
+ * @param moduleId An array of `require('path/to/file')` or external network URLs. Can also be
72
+ * just one module or URL without an Array.
73
+ * @return Returns a Promise that fulfills with an array of `Asset`s when the asset(s) has been
74
+ * saved to disk.
75
+ * @example
76
+ * ```ts
77
+ * const [{ localUri }] = await Asset.loadAsync(require('./assets/snack-icon.png'));
78
+ * ```
79
+ */
29
80
  static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]>;
81
+ /**
82
+ * Returns the [`Asset`](#asset) instance representing an asset given its module or URL.
83
+ * @param virtualAssetModule The value of `require('path/to/file')` for the asset or external
84
+ * network URL
85
+ * @return The [`Asset`](#asset) instance for the asset.
86
+ */
30
87
  static fromModule(virtualAssetModule: number | string): Asset;
31
88
  static fromMetadata(meta: AssetMetadata): Asset;
32
89
  static fromURI(uri: string): Asset;
90
+ /**
91
+ * Downloads the asset data to a local file in the device's cache directory. Once the returned
92
+ * promise is fulfilled without error, the [`localUri`](#assetlocaluri) field of this asset points
93
+ * to a local file containing the asset data. The asset is only downloaded if an up-to-date local
94
+ * file for the asset isn't already present due to an earlier download. The downloaded `Asset`
95
+ * will be returned when the promise is resolved.
96
+ * @return Returns a Promise which fulfills with an `Asset` instance.
97
+ */
33
98
  downloadAsync(): Promise<this>;
34
99
  }
35
- export {};
package/build/Asset.js CHANGED
@@ -1,23 +1,66 @@
1
1
  import { Platform } from 'expo-modules-core';
2
2
  import { getAssetByID } from './AssetRegistry';
3
- import * as AssetSources from './AssetSources';
3
+ import { selectAssetSource } from './AssetSources';
4
4
  import * as AssetUris from './AssetUris';
5
5
  import * as ImageAssets from './ImageAssets';
6
6
  import { getLocalAssetUri } from './LocalAssets';
7
7
  import { downloadAsync, IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';
8
8
  import resolveAssetSource from './resolveAssetSource';
9
+ // @needsAudit
10
+ /**
11
+ * The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its
12
+ * name and type) and provides facilities to load the asset data.
13
+ */
9
14
  export class Asset {
15
+ /**
16
+ * @private
17
+ */
10
18
  static byHash = {};
19
+ /**
20
+ * @private
21
+ */
11
22
  static byUri = {};
23
+ /**
24
+ * The name of the asset file without the extension. Also without the part from `@` onward in the
25
+ * filename (used to specify scale factor for images).
26
+ */
12
27
  name;
28
+ /**
29
+ * The extension of the asset filename.
30
+ */
13
31
  type;
32
+ /**
33
+ * The MD5 hash of the asset's data.
34
+ */
14
35
  hash = null;
36
+ /**
37
+ * A URI that points to the asset's data on the remote server. When running the published version
38
+ * of your app, this refers to the location on Expo's asset server where Expo has stored your
39
+ * asset. When running the app from Expo CLI during development, this URI points to Expo CLI's
40
+ * server running on your computer and the asset is served directly from your computer.
41
+ */
15
42
  uri;
43
+ /**
44
+ * If the asset has been downloaded (by calling [`downloadAsync()`](#downloadasync)), the
45
+ * `file://` URI pointing to the local file on the device that contains the asset data.
46
+ */
16
47
  localUri = null;
48
+ /**
49
+ * If the asset is an image, the width of the image data divided by the scale factor. The scale
50
+ * factor is the number after `@` in the filename, or `1` if not present.
51
+ */
17
52
  width = null;
53
+ /**
54
+ * If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.
55
+ */
18
56
  height = null;
57
+ // @docsMissing
19
58
  downloading = false;
59
+ // @docsMissing
20
60
  downloaded = false;
61
+ /**
62
+ * @private
63
+ */
21
64
  _downloadCallbacks = [];
22
65
  constructor({ name, type, hash = null, uri, width, height }) {
23
66
  this.name = name;
@@ -45,10 +88,29 @@ export class Asset {
45
88
  }
46
89
  }
47
90
  }
91
+ // @needsAudit
92
+ /**
93
+ * A helper that wraps `Asset.fromModule(module).downloadAsync` for convenience.
94
+ * @param moduleId An array of `require('path/to/file')` or external network URLs. Can also be
95
+ * just one module or URL without an Array.
96
+ * @return Returns a Promise that fulfills with an array of `Asset`s when the asset(s) has been
97
+ * saved to disk.
98
+ * @example
99
+ * ```ts
100
+ * const [{ localUri }] = await Asset.loadAsync(require('./assets/snack-icon.png'));
101
+ * ```
102
+ */
48
103
  static loadAsync(moduleId) {
49
104
  const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];
50
105
  return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));
51
106
  }
107
+ // @needsAudit
108
+ /**
109
+ * Returns the [`Asset`](#asset) instance representing an asset given its module or URL.
110
+ * @param virtualAssetModule The value of `require('path/to/file')` for the asset or external
111
+ * network URL
112
+ * @return The [`Asset`](#asset) instance for the asset.
113
+ */
52
114
  static fromModule(virtualAssetModule) {
53
115
  if (typeof virtualAssetModule === 'string') {
54
116
  return Asset.fromURI(virtualAssetModule);
@@ -82,6 +144,7 @@ export class Asset {
82
144
  }
83
145
  return Asset.fromMetadata(meta);
84
146
  }
147
+ // @docsMissing
85
148
  static fromMetadata(meta) {
86
149
  // The hash of the whole asset, not to be confused with the hash of a specific file returned
87
150
  // from `selectAssetSource`
@@ -89,7 +152,7 @@ export class Asset {
89
152
  if (Asset.byHash[metaHash]) {
90
153
  return Asset.byHash[metaHash];
91
154
  }
92
- const { uri, hash } = AssetSources.selectAssetSource(meta);
155
+ const { uri, hash } = selectAssetSource(meta);
93
156
  const asset = new Asset({
94
157
  name: meta.name,
95
158
  type: meta.type,
@@ -101,6 +164,7 @@ export class Asset {
101
164
  Asset.byHash[metaHash] = asset;
102
165
  return asset;
103
166
  }
167
+ // @docsMissing
104
168
  static fromURI(uri) {
105
169
  if (Asset.byUri[uri]) {
106
170
  return Asset.byUri[uri];
@@ -123,6 +187,15 @@ export class Asset {
123
187
  Asset.byUri[uri] = asset;
124
188
  return asset;
125
189
  }
190
+ // @needsAudit
191
+ /**
192
+ * Downloads the asset data to a local file in the device's cache directory. Once the returned
193
+ * promise is fulfilled without error, the [`localUri`](#assetlocaluri) field of this asset points
194
+ * to a local file containing the asset data. The asset is only downloaded if an up-to-date local
195
+ * file for the asset isn't already present due to an earlier download. The downloaded `Asset`
196
+ * will be returned when the promise is resolved.
197
+ * @return Returns a Promise which fulfills with an `Asset` instance.
198
+ */
126
199
  async downloadAsync() {
127
200
  if (this.downloaded) {
128
201
  return this;
@@ -1 +1 @@
1
- {"version":3,"file":"Asset.js","sourceRoot":"","sources":["../src/Asset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAkBtD,M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,CAAC,GAAG,CAAC,CAAC;oBAC9E,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;oBACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;oBACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;iBAClB;qBAAM;oBACL,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;iBAC7C;aACF;YACD,IAAI,CAAC,QAAQ,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAE/E,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;SAC7D;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,MAAM,CAAC,CAAC;SACT;gBAAS;YACR,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;SAC9B;QACD,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\n\nimport { getAssetByID } from './AssetRegistry';\nimport * as AssetSources from './AssetSources';\nimport * as AssetUris from './AssetUris';\nimport * as ImageAssets from './ImageAssets';\nimport { getLocalAssetUri } from './LocalAssets';\nimport { downloadAsync, IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';\nimport resolveAssetSource from './resolveAssetSource';\n\ntype AssetDescriptor = {\n name: string;\n type: string;\n hash?: string | null;\n uri: string;\n width?: number | null;\n height?: number | null;\n};\n\ntype DownloadPromiseCallbacks = {\n resolve: () => void;\n reject: (error: Error) => void;\n};\n\nexport type AssetMetadata = AssetSources.AssetMetadata;\n\nexport class Asset {\n static byHash = {};\n static byUri = {};\n\n name: string;\n type: string;\n hash: string | null = null;\n uri: string;\n localUri: string | null = null;\n width: number | null = null;\n height: number | null = null;\n downloading: boolean = false;\n downloaded: boolean = false;\n _downloadCallbacks: DownloadPromiseCallbacks[] = [];\n\n constructor({ name, type, hash = null, uri, width, height }: AssetDescriptor) {\n this.name = name;\n this.type = type;\n this.hash = hash;\n this.uri = uri;\n\n if (typeof width === 'number') {\n this.width = width;\n }\n if (typeof height === 'number') {\n this.height = height;\n }\n\n if (hash) {\n this.localUri = getLocalAssetUri(hash, type);\n if (this.localUri) {\n this.downloaded = true;\n }\n }\n\n if (Platform.OS === 'web') {\n if (!name) {\n this.name = AssetUris.getFilename(uri);\n }\n if (!type) {\n this.type = AssetUris.getFileExtension(uri);\n }\n }\n }\n\n static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {\n const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];\n return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));\n }\n\n static fromModule(virtualAssetModule: number | string): Asset {\n if (typeof virtualAssetModule === 'string') {\n return Asset.fromURI(virtualAssetModule);\n }\n\n const meta = getAssetByID(virtualAssetModule);\n if (!meta) {\n throw new Error(`Module \"${virtualAssetModule}\" is missing from the asset registry`);\n }\n\n // Outside of the managed env we need the moduleId to initialize the asset\n // because resolveAssetSource depends on it\n if (!IS_ENV_WITH_UPDATES_ENABLED) {\n const { uri } = resolveAssetSource(virtualAssetModule);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash: meta.hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n\n // TODO: FileSystem should probably support 'downloading' from drawable\n // resources But for now it doesn't (it only supports raw resources) and\n // React Native's Image works fine with drawable resource names for\n // images.\n if (Platform.OS === 'android' && !uri.includes(':') && (meta.width || meta.height)) {\n asset.localUri = asset.uri;\n asset.downloaded = true;\n }\n\n Asset.byHash[meta.hash] = asset;\n return asset;\n }\n\n return Asset.fromMetadata(meta);\n }\n\n static fromMetadata(meta: AssetMetadata): Asset {\n // The hash of the whole asset, not to be confused with the hash of a specific file returned\n // from `selectAssetSource`\n const metaHash = meta.hash;\n if (Asset.byHash[metaHash]) {\n return Asset.byHash[metaHash];\n }\n\n const { uri, hash } = AssetSources.selectAssetSource(meta);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n Asset.byHash[metaHash] = asset;\n return asset;\n }\n\n static fromURI(uri: string): Asset {\n if (Asset.byUri[uri]) {\n return Asset.byUri[uri];\n }\n\n // Possibly a Base64-encoded URI\n let type = '';\n if (uri.indexOf(';base64') > -1) {\n type = uri.split(';')[0].split('/')[1];\n } else {\n const extension = AssetUris.getFileExtension(uri);\n type = extension.startsWith('.') ? extension.substring(1) : extension;\n }\n\n const asset = new Asset({\n name: '',\n type,\n hash: null,\n uri,\n });\n\n Asset.byUri[uri] = asset;\n\n return asset;\n }\n\n async downloadAsync(): Promise<this> {\n if (this.downloaded) {\n return this;\n }\n if (this.downloading) {\n await new Promise<void>((resolve, reject) => {\n this._downloadCallbacks.push({ resolve, reject });\n });\n return this;\n }\n this.downloading = true;\n\n try {\n if (Platform.OS === 'web') {\n if (ImageAssets.isImageType(this.type)) {\n const { width, height, name } = await ImageAssets.getImageInfoAsync(this.uri);\n this.width = width;\n this.height = height;\n this.name = name;\n } else {\n this.name = AssetUris.getFilename(this.uri);\n }\n }\n this.localUri = await downloadAsync(this.uri, this.hash, this.type, this.name);\n\n this.downloaded = true;\n this._downloadCallbacks.forEach(({ resolve }) => resolve());\n } catch (e) {\n this._downloadCallbacks.forEach(({ reject }) => reject(e));\n throw e;\n } finally {\n this.downloading = false;\n this._downloadCallbacks = [];\n }\n return this;\n }\n}\n"]}
1
+ {"version":3,"file":"Asset.js","sourceRoot":"","sources":["../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EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;SAC7D;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,MAAM,CAAC,CAAC;SACT;gBAAS;YACR,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;SAC9B;QACD,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\n\nimport { getAssetByID } from './AssetRegistry';\nimport { AssetMetadata, selectAssetSource } from './AssetSources';\nimport * as AssetUris from './AssetUris';\nimport * as ImageAssets from './ImageAssets';\nimport { getLocalAssetUri } from './LocalAssets';\nimport { downloadAsync, IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';\nimport resolveAssetSource from './resolveAssetSource';\n\n// @docsMissing\nexport type AssetDescriptor = {\n name: string;\n type: string;\n hash?: string | null;\n uri: string;\n width?: number | null;\n height?: number | null;\n};\n\ntype DownloadPromiseCallbacks = {\n resolve: () => void;\n reject: (error: Error) => void;\n};\n\nexport { AssetMetadata };\n\n// @needsAudit\n/**\n * The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its\n * name and type) and provides facilities to load the asset data.\n */\nexport class Asset {\n /**\n * @private\n */\n static byHash = {};\n /**\n * @private\n */\n static byUri = {};\n\n /**\n * The name of the asset file without the extension. Also without the part from `@` onward in the\n * filename (used to specify scale factor for images).\n */\n name: string;\n /**\n * The extension of the asset filename.\n */\n type: string;\n /**\n * The MD5 hash of the asset's data.\n */\n hash: string | null = null;\n /**\n * A URI that points to the asset's data on the remote server. When running the published version\n * of your app, this refers to the location on Expo's asset server where Expo has stored your\n * asset. When running the app from Expo CLI during development, this URI points to Expo CLI's\n * server running on your computer and the asset is served directly from your computer.\n */\n uri: string;\n /**\n * If the asset has been downloaded (by calling [`downloadAsync()`](#downloadasync)), the\n * `file://` URI pointing to the local file on the device that contains the asset data.\n */\n localUri: string | null = null;\n /**\n * If the asset is an image, the width of the image data divided by the scale factor. The scale\n * factor is the number after `@` in the filename, or `1` if not present.\n */\n width: number | null = null;\n /**\n * If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.\n */\n height: number | null = null;\n // @docsMissing\n downloading: boolean = false;\n // @docsMissing\n downloaded: boolean = false;\n\n /**\n * @private\n */\n _downloadCallbacks: DownloadPromiseCallbacks[] = [];\n\n constructor({ name, type, hash = null, uri, width, height }: AssetDescriptor) {\n this.name = name;\n this.type = type;\n this.hash = hash;\n this.uri = uri;\n\n if (typeof width === 'number') {\n this.width = width;\n }\n if (typeof height === 'number') {\n this.height = height;\n }\n\n if (hash) {\n this.localUri = getLocalAssetUri(hash, type);\n if (this.localUri) {\n this.downloaded = true;\n }\n }\n\n if (Platform.OS === 'web') {\n if (!name) {\n this.name = AssetUris.getFilename(uri);\n }\n if (!type) {\n this.type = AssetUris.getFileExtension(uri);\n }\n }\n }\n\n // @needsAudit\n /**\n * A helper that wraps `Asset.fromModule(module).downloadAsync` for convenience.\n * @param moduleId An array of `require('path/to/file')` or external network URLs. Can also be\n * just one module or URL without an Array.\n * @return Returns a Promise that fulfills with an array of `Asset`s when the asset(s) has been\n * saved to disk.\n * @example\n * ```ts\n * const [{ localUri }] = await Asset.loadAsync(require('./assets/snack-icon.png'));\n * ```\n */\n static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {\n const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];\n return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));\n }\n\n // @needsAudit\n /**\n * Returns the [`Asset`](#asset) instance representing an asset given its module or URL.\n * @param virtualAssetModule The value of `require('path/to/file')` for the asset or external\n * network URL\n * @return The [`Asset`](#asset) instance for the asset.\n */\n static fromModule(virtualAssetModule: number | string): Asset {\n if (typeof virtualAssetModule === 'string') {\n return Asset.fromURI(virtualAssetModule);\n }\n\n const meta = getAssetByID(virtualAssetModule);\n if (!meta) {\n throw new Error(`Module \"${virtualAssetModule}\" is missing from the asset registry`);\n }\n\n // Outside of the managed env we need the moduleId to initialize the asset\n // because resolveAssetSource depends on it\n if (!IS_ENV_WITH_UPDATES_ENABLED) {\n const { uri } = resolveAssetSource(virtualAssetModule);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash: meta.hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n\n // TODO: FileSystem should probably support 'downloading' from drawable\n // resources But for now it doesn't (it only supports raw resources) and\n // React Native's Image works fine with drawable resource names for\n // images.\n if (Platform.OS === 'android' && !uri.includes(':') && (meta.width || meta.height)) {\n asset.localUri = asset.uri;\n asset.downloaded = true;\n }\n\n Asset.byHash[meta.hash] = asset;\n return asset;\n }\n\n return Asset.fromMetadata(meta);\n }\n\n // @docsMissing\n static fromMetadata(meta: AssetMetadata): Asset {\n // The hash of the whole asset, not to be confused with the hash of a specific file returned\n // from `selectAssetSource`\n const metaHash = meta.hash;\n if (Asset.byHash[metaHash]) {\n return Asset.byHash[metaHash];\n }\n\n const { uri, hash } = selectAssetSource(meta);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n Asset.byHash[metaHash] = asset;\n return asset;\n }\n\n // @docsMissing\n static fromURI(uri: string): Asset {\n if (Asset.byUri[uri]) {\n return Asset.byUri[uri];\n }\n\n // Possibly a Base64-encoded URI\n let type = '';\n if (uri.indexOf(';base64') > -1) {\n type = uri.split(';')[0].split('/')[1];\n } else {\n const extension = AssetUris.getFileExtension(uri);\n type = extension.startsWith('.') ? extension.substring(1) : extension;\n }\n\n const asset = new Asset({\n name: '',\n type,\n hash: null,\n uri,\n });\n\n Asset.byUri[uri] = asset;\n\n return asset;\n }\n\n // @needsAudit\n /**\n * Downloads the asset data to a local file in the device's cache directory. Once the returned\n * promise is fulfilled without error, the [`localUri`](#assetlocaluri) field of this asset points\n * to a local file containing the asset data. The asset is only downloaded if an up-to-date local\n * file for the asset isn't already present due to an earlier download. The downloaded `Asset`\n * will be returned when the promise is resolved.\n * @return Returns a Promise which fulfills with an `Asset` instance.\n */\n async downloadAsync(): Promise<this> {\n if (this.downloaded) {\n return this;\n }\n if (this.downloading) {\n await new Promise<void>((resolve, reject) => {\n this._downloadCallbacks.push({ resolve, reject });\n });\n return this;\n }\n this.downloading = true;\n\n try {\n if (Platform.OS === 'web') {\n if (ImageAssets.isImageType(this.type)) {\n const { width, height, name } = await ImageAssets.getImageInfoAsync(this.uri);\n this.width = width;\n this.height = height;\n this.name = name;\n } else {\n this.name = AssetUris.getFilename(this.uri);\n }\n }\n this.localUri = await downloadAsync(this.uri, this.hash, this.type, this.name);\n\n this.downloaded = true;\n this._downloadCallbacks.forEach(({ resolve }) => resolve());\n } catch (e) {\n this._downloadCallbacks.forEach(({ reject }) => reject(e));\n throw e;\n } finally {\n this.downloading = false;\n this._downloadCallbacks = [];\n }\n return this;\n }\n}\n"]}
@@ -4,14 +4,19 @@ import { Asset } from './Asset';
4
4
  * After the assets are loaded, this hook returns a list of asset instances.
5
5
  * If something went wrong when loading the assets, an error is returned.
6
6
  *
7
- * Note, the assets are not "reloaded" when you dynamically change the asset list.
7
+ * > Note, the assets are not "reloaded" when you dynamically change the asset list.
8
+ *
9
+ * @return Returns an array containing:
10
+ * - on the first position, a list of all loaded assets. If they aren't loaded yet, this value is
11
+ * `undefined`.
12
+ * - on the second position, an error which encountered when loading the assets. If there was no
13
+ * error, this value is `undefined`.
8
14
  *
9
- * @see https://docs.expo.io/versions/latest/sdk/asset/
10
15
  * @example
11
16
  * ```tsx
12
- * const [assets, error] = useAssets(require('path/to/asset.jpg'));
17
+ * const [assets, error] = useAssets([require('path/to/asset.jpg'), require('path/to/other.png')]);
13
18
  *
14
- * return !assets ? null : <Image source={assets[0]} />;
19
+ * return assets ? <Image source={assets[0]} /> : null;
15
20
  * ```
16
21
  */
17
22
  export declare function useAssets(moduleIds: number | number[]): [Asset[] | undefined, Error | undefined];
@@ -1,18 +1,24 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { Asset } from './Asset';
3
+ // @needsAudit
3
4
  /**
4
5
  * Downloads and stores one or more assets locally.
5
6
  * After the assets are loaded, this hook returns a list of asset instances.
6
7
  * If something went wrong when loading the assets, an error is returned.
7
8
  *
8
- * Note, the assets are not "reloaded" when you dynamically change the asset list.
9
+ * > Note, the assets are not "reloaded" when you dynamically change the asset list.
10
+ *
11
+ * @return Returns an array containing:
12
+ * - on the first position, a list of all loaded assets. If they aren't loaded yet, this value is
13
+ * `undefined`.
14
+ * - on the second position, an error which encountered when loading the assets. If there was no
15
+ * error, this value is `undefined`.
9
16
  *
10
- * @see https://docs.expo.io/versions/latest/sdk/asset/
11
17
  * @example
12
18
  * ```tsx
13
- * const [assets, error] = useAssets(require('path/to/asset.jpg'));
19
+ * const [assets, error] = useAssets([require('path/to/asset.jpg'), require('path/to/other.png')]);
14
20
  *
15
- * return !assets ? null : <Image source={assets[0]} />;
21
+ * return assets ? <Image source={assets[0]} /> : null;
16
22
  * ```
17
23
  */
18
24
  export function useAssets(moduleIds) {
@@ -1 +1 @@
1
- {"version":3,"file":"AssetHooks.js","sourceRoot":"","sources":["../src/AssetHooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,SAAS,CAAC,SAA4B;IACpD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAW,CAAC;IAChD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAS,CAAC;IAE5C,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7D,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { Asset } from './Asset';\n\n/**\n * Downloads and stores one or more assets locally.\n * After the assets are loaded, this hook returns a list of asset instances.\n * If something went wrong when loading the assets, an error is returned.\n *\n * Note, the assets are not \"reloaded\" when you dynamically change the asset list.\n *\n * @see https://docs.expo.io/versions/latest/sdk/asset/\n * @example\n * ```tsx\n * const [assets, error] = useAssets(require('path/to/asset.jpg'));\n *\n * return !assets ? null : <Image source={assets[0]} />;\n * ```\n */\nexport function useAssets(moduleIds: number | number[]): [Asset[] | undefined, Error | undefined] {\n const [assets, setAssets] = useState<Asset[]>();\n const [error, setError] = useState<Error>();\n\n useEffect(() => {\n Asset.loadAsync(moduleIds).then(setAssets).catch(setError);\n }, []);\n\n return [assets, error];\n}\n"]}
1
+ {"version":3,"file":"AssetHooks.js","sourceRoot":"","sources":["../src/AssetHooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,cAAc;AACd;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,SAAS,CAAC,SAA4B;IACpD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAW,CAAC;IAChD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAS,CAAC;IAE5C,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7D,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { Asset } from './Asset';\n\n// @needsAudit\n/**\n * Downloads and stores one or more assets locally.\n * After the assets are loaded, this hook returns a list of asset instances.\n * If something went wrong when loading the assets, an error is returned.\n *\n * > Note, the assets are not \"reloaded\" when you dynamically change the asset list.\n *\n * @return Returns an array containing:\n * - on the first position, a list of all loaded assets. If they aren't loaded yet, this value is\n * `undefined`.\n * - on the second position, an error which encountered when loading the assets. If there was no\n * error, this value is `undefined`.\n *\n * @example\n * ```tsx\n * const [assets, error] = useAssets([require('path/to/asset.jpg'), require('path/to/other.png')]);\n *\n * return assets ? <Image source={assets[0]} /> : null;\n * ```\n */\nexport function useAssets(moduleIds: number | number[]): [Asset[] | undefined, Error | undefined] {\n const [assets, setAssets] = useState<Asset[]>();\n const [error, setError] = useState<Error>();\n\n useEffect(() => {\n Asset.loadAsync(moduleIds).then(setAssets).catch(setError);\n }, []);\n\n return [assets, error];\n}\n"]}
@@ -14,7 +14,7 @@ function getScaledAssetPath(asset) {
14
14
  const scale = AssetSourceResolver.pickScale(asset.scales, getScale());
15
15
  const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';
16
16
  const assetDir = getBasePath(asset);
17
- return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;
17
+ return assetDir + '/' + asset.name + scaleSuffix + (asset.type ? `.${asset.type}` : '');
18
18
  }
19
19
  export default class AssetSourceResolver {
20
20
  serverUrl;
@@ -52,7 +52,7 @@ export default class AssetSourceResolver {
52
52
  return this.fromSource(getScaledAssetPath(this.asset));
53
53
  }
54
54
  scaledAssetURLNearBundle() {
55
- const path = this.jsbundleUrl || 'file://';
55
+ const path = this.jsbundleUrl || '';
56
56
  return this.fromSource(path + getScaledAssetPath(this.asset));
57
57
  }
58
58
  resourceIdentifierWithoutScale() {
@@ -1 +1 @@
1
- {"version":3,"file":"AssetSourceResol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KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK;YACvB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;YACzB,GAAG,EAAE,MAAM;YACX,KAAK,EAAE,mBAAmB,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;SACpE,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAgB,EAAE,WAAmB;QACpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACtC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE;gBAC5B,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;aAClB;SACF;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import { Platform, UnavailabilityError } from 'expo-modules-core';\nimport invariant from 'invariant';\nimport { Dimensions } from 'react-native';\n\ntype PackagerAsset = {\n __packager_asset: boolean;\n fileSystemLocation: string;\n httpServerLocation: string;\n width?: number;\n height?: number;\n scales: number[];\n hash: string;\n name: string;\n type: string;\n};\n\nfunction getBasePath({ httpServerLocation }: PackagerAsset): string {\n if (httpServerLocation[0] === '/') {\n return httpServerLocation.substr(1);\n }\n return httpServerLocation;\n}\n\nexport type ResolvedAssetSource = {\n __packager_asset: boolean;\n width?: number;\n height?: number;\n uri: string;\n scale: number;\n};\n\nfunction getScale(): number {\n return Dimensions.get('window').scale;\n}\n\nfunction getScaledAssetPath(asset): string {\n const scale = AssetSourceResolver.pickScale(asset.scales, getScale());\n const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';\n const assetDir = getBasePath(asset);\n return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;\n}\n\nexport default class AssetSourceResolver {\n serverUrl?: string | null;\n // where the jsbundle is being run from\n jsbundleUrl?: string | null;\n // the asset to resolve\n asset: PackagerAsset;\n\n constructor(\n serverUrl: string | undefined | null,\n jsbundleUrl: string | undefined | null,\n asset: PackagerAsset\n ) {\n this.serverUrl = serverUrl;\n this.jsbundleUrl = jsbundleUrl;\n this.asset = asset;\n }\n isLoadedFromServer(): boolean {\n return !!this.serverUrl;\n }\n isLoadedFromFileSystem(): boolean {\n return !!(this.jsbundleUrl && this.jsbundleUrl.startsWith('file://'));\n }\n defaultAsset(): ResolvedAssetSource {\n if (this.isLoadedFromServer()) {\n return this.assetServerURL();\n }\n\n return this.scaledAssetURLNearBundle();\n }\n assetServerURL(): ResolvedAssetSource {\n invariant(!!this.serverUrl, 'need server to load from');\n return this.fromSource(\n this.serverUrl +\n getScaledAssetPath(this.asset) +\n '?platform=' +\n Platform.OS +\n '&hash=' +\n this.asset.hash\n );\n }\n scaledAssetPath(): ResolvedAssetSource {\n return this.fromSource(getScaledAssetPath(this.asset));\n }\n scaledAssetURLNearBundle(): ResolvedAssetSource {\n const path = this.jsbundleUrl || 'file://';\n return this.fromSource(path + getScaledAssetPath(this.asset));\n }\n resourceIdentifierWithoutScale(): ResolvedAssetSource {\n throw new UnavailabilityError('react-native', 'resourceIdentifierWithoutScale()');\n }\n drawableFolderInBundle(): ResolvedAssetSource {\n throw new UnavailabilityError('react-native', 'drawableFolderInBundle()');\n }\n fromSource(source: string): ResolvedAssetSource {\n return {\n __packager_asset: true,\n width: this.asset.width,\n height: this.asset.height,\n uri: source,\n scale: AssetSourceResolver.pickScale(this.asset.scales, getScale()),\n };\n }\n\n static pickScale(scales: number[], deviceScale: number): number {\n for (let i = 0; i < scales.length; i++) {\n if (scales[i] >= deviceScale) {\n return scales[i];\n }\n }\n return scales[scales.length - 1] || 1;\n }\n}\n"]}
1
+ {"version":3,"file":"AssetSourceResolver.web.js","sourceRoot":"","sources":["../src/AssetSourceResolver.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,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AK;YACvB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;YACzB,GAAG,EAAE,MAAM;YACX,KAAK,EAAE,mBAAmB,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;SACpE,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAgB,EAAE,WAAmB;QACpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACtC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE;gBAC5B,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;aAClB;SACF;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import { Platform, UnavailabilityError } from 'expo-modules-core';\nimport invariant from 'invariant';\nimport { Dimensions } from 'react-native';\n\ntype PackagerAsset = {\n __packager_asset: boolean;\n fileSystemLocation: string;\n httpServerLocation: string;\n width?: number;\n height?: number;\n scales: number[];\n hash: string;\n name: string;\n type: string;\n};\n\nfunction getBasePath({ httpServerLocation }: PackagerAsset): string {\n if (httpServerLocation[0] === '/') {\n return httpServerLocation.substr(1);\n }\n return httpServerLocation;\n}\n\nexport type ResolvedAssetSource = {\n __packager_asset: boolean;\n width?: number;\n height?: number;\n uri: string;\n scale: number;\n};\n\nfunction getScale(): number {\n return Dimensions.get('window').scale;\n}\n\nfunction getScaledAssetPath(asset): string {\n const scale = AssetSourceResolver.pickScale(asset.scales, getScale());\n const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';\n const assetDir = getBasePath(asset);\n return assetDir + '/' + asset.name + scaleSuffix + (asset.type ? `.${asset.type}` : '');\n}\n\nexport default class AssetSourceResolver {\n serverUrl?: string | null;\n // where the jsbundle is being run from\n jsbundleUrl?: string | null;\n // the asset to resolve\n asset: PackagerAsset;\n\n constructor(\n serverUrl: string | undefined | null,\n jsbundleUrl: string | undefined | null,\n asset: PackagerAsset\n ) {\n this.serverUrl = serverUrl;\n this.jsbundleUrl = jsbundleUrl;\n this.asset = asset;\n }\n isLoadedFromServer(): boolean {\n return !!this.serverUrl;\n }\n isLoadedFromFileSystem(): boolean {\n return !!(this.jsbundleUrl && this.jsbundleUrl.startsWith('file://'));\n }\n defaultAsset(): ResolvedAssetSource {\n if (this.isLoadedFromServer()) {\n return this.assetServerURL();\n }\n\n return this.scaledAssetURLNearBundle();\n }\n assetServerURL(): ResolvedAssetSource {\n invariant(!!this.serverUrl, 'need server to load from');\n return this.fromSource(\n this.serverUrl +\n getScaledAssetPath(this.asset) +\n '?platform=' +\n Platform.OS +\n '&hash=' +\n this.asset.hash\n );\n }\n scaledAssetPath(): ResolvedAssetSource {\n return this.fromSource(getScaledAssetPath(this.asset));\n }\n scaledAssetURLNearBundle(): ResolvedAssetSource {\n const path = this.jsbundleUrl || '';\n return this.fromSource(path + getScaledAssetPath(this.asset));\n }\n resourceIdentifierWithoutScale(): ResolvedAssetSource {\n throw new UnavailabilityError('react-native', 'resourceIdentifierWithoutScale()');\n }\n drawableFolderInBundle(): ResolvedAssetSource {\n throw new UnavailabilityError('react-native', 'drawableFolderInBundle()');\n }\n fromSource(source: string): ResolvedAssetSource {\n return {\n __packager_asset: true,\n width: this.asset.width,\n height: this.asset.height,\n uri: source,\n scale: AssetSourceResolver.pickScale(this.asset.scales, getScale()),\n };\n }\n\n static pickScale(scales: number[], deviceScale: number): number {\n for (let i = 0; i < scales.length; i++) {\n if (scales[i] >= deviceScale) {\n return scales[i];\n }\n }\n return scales[scales.length - 1] || 1;\n }\n}\n"]}
@@ -3,7 +3,7 @@ import path from 'path-browserify';
3
3
  import { PixelRatio } from 'react-native';
4
4
  import URL from 'url-parse';
5
5
  import AssetSourceResolver from './AssetSourceResolver';
6
- import { manifestBaseUrl, getManifest } from './PlatformUtils';
6
+ import { manifestBaseUrl, getManifest, getManifest2 } from './PlatformUtils';
7
7
  // Fast lookup check if asset map has any overrides in the manifest
8
8
  const assetMapOverride = getManifest().assetMapOverride;
9
9
  /**
@@ -42,6 +42,16 @@ export function selectAssetSource(meta) {
42
42
  const uri = meta.httpServerLocation + suffix;
43
43
  return { uri, hash };
44
44
  }
45
+ // For assets during development using manifest2, we use the development server's URL origin
46
+ const manifest2 = getManifest2();
47
+ if (manifest2?.extra?.expoGo?.developer) {
48
+ const baseUrl = new URL(`http://${manifest2.extra.expoGo.debuggerHost}`);
49
+ baseUrl.set('pathname', meta.httpServerLocation + suffix);
50
+ return {
51
+ uri: baseUrl.href,
52
+ hash,
53
+ };
54
+ }
45
55
  // For assets during development, we use the development server's URL origin
46
56
  if (getManifest().developer) {
47
57
  const baseUrl = new URL(getManifest().bundleUrl);
@@ -1 +1 @@
1
- {"version":3,"file":"AssetSources.js","sourceRoot":"","sources":["../src/AssetSources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,GAAG,MAAM,WAAW,CAAC;AAE5B,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAoB/D,mEAAmE;AACnE,MAAM,gBAAgB,GAAG,WAAW,EAAE,CAAC,gBAAgB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAmB;IACnD,uDAAuD;IACvD,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAClE,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;KACpD;IAED,kGAAkG;IAClG,2B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CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IACtC,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\nimport path from 'path-browserify';\nimport { PixelRatio } from 'react-native';\nimport URL from 'url-parse';\n\nimport AssetSourceResolver from './AssetSourceResolver';\nimport { manifestBaseUrl, getManifest } from './PlatformUtils';\n\nexport type AssetMetadata = {\n hash: string;\n name: string;\n type: string;\n width?: number;\n height?: number;\n scales: number[];\n httpServerLocation: string;\n uri?: string;\n fileHashes?: string[];\n fileUris?: string[];\n};\n\nexport type AssetSource = {\n uri: string;\n hash: string;\n};\n\n// Fast lookup check if asset map has any overrides in the manifest\nconst assetMapOverride = getManifest().assetMapOverride;\n\n/**\n * Selects the best file for the given asset (ex: choosing the best scale for images) and returns\n * a { uri, hash } pair for the specific asset file.\n *\n * If the asset isn't an image with multiple scales, the first file is selected.\n */\nexport function selectAssetSource(meta: AssetMetadata): AssetSource {\n // Override with the asset map in manifest if available\n if (assetMapOverride && assetMapOverride.hasOwnProperty(meta.hash)) {\n meta = { ...meta, ...assetMapOverride[meta.hash] };\n }\n\n // This logic is based on that of AssetSourceResolver, with additional support for file hashes and\n // explicitly provided URIs\n const scale = AssetSourceResolver.pickScale(meta.scales, PixelRatio.get());\n const index = meta.scales.findIndex((s) => s === scale);\n const hash = meta.fileHashes ? meta.fileHashes[index] || meta.fileHashes[0] : meta.hash;\n\n // Allow asset processors to directly provide the URL to load\n const uri = meta.fileUris ? meta.fileUris[index] || meta.fileUris[0] : meta.uri;\n if (uri) {\n return { uri: resolveUri(uri), hash };\n }\n\n // Check if the assetUrl was overridden in the manifest\n const assetUrlOverride = getManifest().assetUrlOverride;\n if (assetUrlOverride) {\n const uri = path.join(assetUrlOverride, hash);\n return { uri: resolveUri(uri), hash };\n }\n\n const fileScale = scale === 1 ? '' : `@${scale}x`;\n const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';\n const suffix = `/${encodeURIComponent(\n meta.name\n )}${fileScale}${fileExtension}?platform=${encodeURIComponent(\n Platform.OS\n )}&hash=${encodeURIComponent(meta.hash)}`;\n\n // For assets with a specified absolute URL, we use the existing origin instead of prepending the\n // development server or production CDN URL origin\n if (/^https?:\\/\\//.test(meta.httpServerLocation)) {\n const uri = meta.httpServerLocation + suffix;\n return { uri, hash };\n }\n\n // For assets during development, we use the development server's URL origin\n if (getManifest().developer) {\n const baseUrl = new URL(getManifest().bundleUrl);\n baseUrl.set('pathname', meta.httpServerLocation + suffix);\n return { uri: baseUrl.href, hash };\n }\n\n // Production CDN URIs are based on each asset file hash\n return {\n uri: `https://d1wp6m56sqw74a.cloudfront.net/~assets/${encodeURIComponent(hash)}`,\n hash,\n };\n}\n\n/**\n * Resolves the given URI to an absolute URI. If the given URI is already an absolute URI, it is\n * simply returned. Otherwise, if it is a relative URI, it is resolved relative to the manifest's\n * base URI.\n */\nexport function resolveUri(uri: string): string {\n if (!manifestBaseUrl) {\n return uri;\n }\n\n const { protocol } = new URL(uri);\n if (protocol !== '') {\n return uri;\n }\n\n const baseUrl = new URL(manifestBaseUrl);\n const resolvedPath = uri.startsWith('/') ? uri : path.join(baseUrl.pathname, uri);\n baseUrl.set('pathname', resolvedPath);\n return baseUrl.href;\n}\n"]}
1
+ {"version":3,"file":"AssetSources.js","sourceRoot":"","sources":["../src/AssetSources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,GAAG,MAAM,WAAW,CAAC;AAE5B,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE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AE,CAAC,SAAS,EAAE;QAC3B,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,CAAC;QAC1D,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;KACpC;IAED,wDAAwD;IACxD,OAAO;QACL,GAAG,EAAE,iDAAiD,kBAAkB,CAAC,IAAI,CAAC,EAAE;QAChF,IAAI;KACL,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,CAAC,eAAe,EAAE;QACpB,OAAO,GAAG,CAAC;KACZ;IAED,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,QAAQ,KAAK,EAAE,EAAE;QACnB,OAAO,GAAG,CAAC;KACZ;IAED,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;IACzC,MAAM,YAAY,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IACtC,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\nimport path from 'path-browserify';\nimport { PixelRatio } from 'react-native';\nimport URL from 'url-parse';\n\nimport AssetSourceResolver from './AssetSourceResolver';\nimport { manifestBaseUrl, getManifest, getManifest2 } from './PlatformUtils';\n\n// @docsMissing\nexport type AssetMetadata = {\n hash: string;\n name: string;\n type: string;\n width?: number;\n height?: number;\n scales: number[];\n httpServerLocation: string;\n uri?: string;\n fileHashes?: string[];\n fileUris?: string[];\n};\n\nexport type AssetSource = {\n uri: string;\n hash: string;\n};\n\n// Fast lookup check if asset map has any overrides in the manifest\nconst assetMapOverride = getManifest().assetMapOverride;\n\n/**\n * Selects the best file for the given asset (ex: choosing the best scale for images) and returns\n * a { uri, hash } pair for the specific asset file.\n *\n * If the asset isn't an image with multiple scales, the first file is selected.\n */\nexport function selectAssetSource(meta: AssetMetadata): AssetSource {\n // Override with the asset map in manifest if available\n if (assetMapOverride && assetMapOverride.hasOwnProperty(meta.hash)) {\n meta = { ...meta, ...assetMapOverride[meta.hash] };\n }\n\n // This logic is based on that of AssetSourceResolver, with additional support for file hashes and\n // explicitly provided URIs\n const scale = AssetSourceResolver.pickScale(meta.scales, PixelRatio.get());\n const index = meta.scales.findIndex((s) => s === scale);\n const hash = meta.fileHashes ? meta.fileHashes[index] || meta.fileHashes[0] : meta.hash;\n\n // Allow asset processors to directly provide the URL to load\n const uri = meta.fileUris ? meta.fileUris[index] || meta.fileUris[0] : meta.uri;\n if (uri) {\n return { uri: resolveUri(uri), hash };\n }\n\n // Check if the assetUrl was overridden in the manifest\n const assetUrlOverride = getManifest().assetUrlOverride;\n if (assetUrlOverride) {\n const uri = path.join(assetUrlOverride, hash);\n return { uri: resolveUri(uri), hash };\n }\n\n const fileScale = scale === 1 ? '' : `@${scale}x`;\n const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';\n const suffix = `/${encodeURIComponent(\n meta.name\n )}${fileScale}${fileExtension}?platform=${encodeURIComponent(\n Platform.OS\n )}&hash=${encodeURIComponent(meta.hash)}`;\n\n // For assets with a specified absolute URL, we use the existing origin instead of prepending the\n // development server or production CDN URL origin\n if (/^https?:\\/\\//.test(meta.httpServerLocation)) {\n const uri = meta.httpServerLocation + suffix;\n return { uri, hash };\n }\n\n // For assets during development using manifest2, we use the development server's URL origin\n const manifest2 = getManifest2();\n\n if (manifest2?.extra?.expoGo?.developer) {\n const baseUrl = new URL(`http://${manifest2.extra.expoGo.debuggerHost}`);\n baseUrl.set('pathname', meta.httpServerLocation + suffix);\n\n return {\n uri: baseUrl.href,\n hash,\n };\n }\n\n // For assets during development, we use the development server's URL origin\n if (getManifest().developer) {\n const baseUrl = new URL(getManifest().bundleUrl);\n baseUrl.set('pathname', meta.httpServerLocation + suffix);\n return { uri: baseUrl.href, hash };\n }\n\n // Production CDN URIs are based on each asset file hash\n return {\n uri: `https://d1wp6m56sqw74a.cloudfront.net/~assets/${encodeURIComponent(hash)}`,\n hash,\n };\n}\n\n/**\n * Resolves the given URI to an absolute URI. If the given URI is already an absolute URI, it is\n * simply returned. Otherwise, if it is a relative URI, it is resolved relative to the manifest's\n * base URI.\n */\nexport function resolveUri(uri: string): string {\n if (!manifestBaseUrl) {\n return uri;\n }\n\n const { protocol } = new URL(uri);\n if (protocol !== '') {\n return uri;\n }\n\n const baseUrl = new URL(manifestBaseUrl);\n const resolvedPath = uri.startsWith('/') ? uri : path.join(baseUrl.pathname, uri);\n baseUrl.set('pathname', resolvedPath);\n return baseUrl.href;\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { Manifest } from 'expo-constants/build/Constants.types';
1
2
  export declare const IS_MANAGED_ENV: boolean;
2
3
  export declare const IS_BARE_ENV_WITH_UPDATES: boolean;
3
4
  export declare const IS_ENV_WITH_UPDATES_ENABLED: boolean;
@@ -6,5 +7,6 @@ export declare function getLocalAssets(): any;
6
7
  export declare function getManifest(): {
7
8
  [key: string]: any;
8
9
  };
10
+ export declare function getManifest2(): Manifest | undefined;
9
11
  export declare const manifestBaseUrl: string | null;
10
12
  export declare function downloadAsync(uri: any, hash: any, type: any, name: any): Promise<string>;
@@ -24,6 +24,9 @@ export function getLocalAssets() {
24
24
  export function getManifest() {
25
25
  return Constants.__unsafeNoWarnManifest ?? {};
26
26
  }
27
+ export function getManifest2() {
28
+ return Constants.__unsafeNoWarnManifest2;
29
+ }
27
30
  // Compute manifest base URL if available
28
31
  export const manifestBaseUrl = Constants.experienceUr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CAAC,EAAE;QAC7B,OAAO,GAAG,CAAC;KACZ;IAED,MAAM,WAAW,GAAG,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,GAAG,UAAU,CAAC,cAAc,iBAAiB,WAAW,IAAI,IAAI,EAAE,CAAC;IAEpF,4EAA4E;IAC5E,yCAAyC;IACzC,MAAM,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC9C,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import computeMd5 from 'blueimp-md5';\nimport Constants from 'expo-constants';\nimport * as FileSystem from 'expo-file-system';\nimport { NativeModulesProxy } from 'expo-modules-core';\n\nimport { getManifestBaseUrl } from './AssetUris';\n\n// Constants.appOwnership is only available in managed apps (Expo client and standalone)\nexport const IS_MANAGED_ENV = !!Constants.appOwnership;\n\n// In the future (SDK38+) expo-updates is likely to be used in managed apps, so we decide\n// that you are in a bare app with updates if you're not in a managed app and you have\n// local assets available.\nexport const IS_BARE_ENV_WITH_UPDATES =\n !IS_MANAGED_ENV &&\n !!NativeModulesProxy.ExpoUpdates?.isEnabled &&\n // if expo-updates is installed but we're running directly from the embedded bundle, we don't want\n // to override the AssetSourceResolver\n !NativeModulesProxy.ExpoUpdates?.isUsingEmbeddedAssets;\n\nexport const IS_ENV_WITH_UPDATES_ENABLED = IS_MANAGED_ENV || IS_BARE_ENV_WITH_UPDATES;\n\n// If it's not managed or bare w/ updates, then it must be bare w/o updates!\nexport const IS_BARE_ENV_WITHOUT_UPDATES = !IS_MANAGED_ENV && !IS_BARE_ENV_WITH_UPDATES;\n\n// Get the localAssets property from the ExpoUpdates native module so that we do\n// not need to include expo-updates as a dependency of expo-asset\nexport function getLocalAssets() {\n return NativeModulesProxy.ExpoUpdates?.localAssets ?? {};\n}\n\nexport function getManifest(): { [key: string]: any } {\n return Constants.__unsafeNoWarnManifest ?? {};\n}\n\n// Compute manifest base URL if available\nexport const manifestBaseUrl = Constants.experienceUrl\n ? getManifestBaseUrl(Constants.experienceUrl)\n : null;\n\n// TODO: how should this behave in bare app with updates? re: hashAssetFiles\nexport async function downloadAsync(uri, hash, type, name): Promise<string> {\n if (IS_MANAGED_ENV) {\n return _downloadAsyncManagedEnv(uri, hash, type, name);\n }\n\n return _downloadAsyncUnmanagedEnv(uri, hash, type);\n}\n\n/**\n * Check if the file exists on disk already, perform integrity check if so.\n * Otherwise, download it.\n */\nasync function _downloadAsyncManagedEnv(uri, hash, type, name): Promise<string> {\n const cacheFileId = hash || computeMd5(uri);\n const localUri = `${FileSystem.cacheDirectory}ExponentAsset-${cacheFileId}.${type}`;\n let { exists, md5 } = await FileSystem.getInfoAsync(localUri, {\n md5: true,\n });\n if (!exists || (hash !== null && md5 !== hash)) {\n ({ md5 } = await FileSystem.downloadAsync(uri, localUri, {\n md5: true,\n }));\n if (hash !== null && md5 !== hash) {\n throw new Error(\n `Downloaded file for asset '${name}.${type}' ` +\n `Located at ${uri} ` +\n `failed MD5 integrity check`\n );\n }\n }\n return localUri;\n}\n\n/**\n * Just download the asset, don't perform integrity check because we don't have\n * the hash to compare it with (we don't have hashAssetFiles plugin). Hash is\n * only used for the file name.\n */\nasync function _downloadAsyncUnmanagedEnv(uri, hash, type): Promise<string> {\n // TODO: does this make sense to bail out if it's already at a file URL\n // because it's already available locally?\n if (uri.startsWith('file://')) {\n return uri;\n }\n\n const cacheFileId = hash || computeMd5(uri);\n const localUri = `${FileSystem.cacheDirectory}ExponentAsset-${cacheFileId}.${type}`;\n\n // We don't check the FileSystem for an existing version of the asset and we\n // also don't perform an integrity check!\n await FileSystem.downloadAsync(uri, localUri);\n return localUri;\n}\n"]}
1
+ {"version":3,"file":"PlatformUtils.js","sourceRoot":"","sources":["../src/PlatformUtils.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,OAAO,KAAK,UAAU,MAAM,kBAAkB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iB,WAAW,IAAI,IAAI,EAAE,CAAC;IAEpF,4EAA4E;IAC5E,yCAAyC;IACzC,MAAM,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC9C,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import computeMd5 from 'blueimp-md5';\nimport Constants from 'expo-constants';\nimport { Manifest } from 'expo-constants/build/Constants.types';\nimport * as FileSystem from 'expo-file-system';\nimport { NativeModulesProxy } from 'expo-modules-core';\n\nimport { getManifestBaseUrl } from './AssetUris';\n\n// Constants.appOwnership is only available in managed apps (Expo client and standalone)\nexport const IS_MANAGED_ENV = !!Constants.appOwnership;\n\n// In the future (SDK38+) expo-updates is likely to be used in managed apps, so we decide\n// that you are in a bare app with updates if you're not in a managed app and you have\n// local assets available.\nexport const IS_BARE_ENV_WITH_UPDATES =\n !IS_MANAGED_ENV &&\n !!NativeModulesProxy.ExpoUpdates?.isEnabled &&\n // if expo-updates is installed but we're running directly from the embedded bundle, we don't want\n // to override the AssetSourceResolver\n !NativeModulesProxy.ExpoUpdates?.isUsingEmbeddedAssets;\n\nexport const IS_ENV_WITH_UPDATES_ENABLED = IS_MANAGED_ENV || IS_BARE_ENV_WITH_UPDATES;\n\n// If it's not managed or bare w/ updates, then it must be bare w/o updates!\nexport const IS_BARE_ENV_WITHOUT_UPDATES = !IS_MANAGED_ENV && !IS_BARE_ENV_WITH_UPDATES;\n\n// Get the localAssets property from the ExpoUpdates native module so that we do\n// not need to include expo-updates as a dependency of expo-asset\nexport function getLocalAssets() {\n return NativeModulesProxy.ExpoUpdates?.localAssets ?? {};\n}\n\nexport function getManifest(): { [key: string]: any } {\n return Constants.__unsafeNoWarnManifest ?? {};\n}\n\nexport function getManifest2(): Manifest | undefined {\n return Constants.__unsafeNoWarnManifest2;\n}\n\n// Compute manifest base URL if available\nexport const manifestBaseUrl = Constants.experienceUrl\n ? getManifestBaseUrl(Constants.experienceUrl)\n : null;\n\n// TODO: how should this behave in bare app with updates? re: hashAssetFiles\nexport async function downloadAsync(uri, hash, type, name): Promise<string> {\n if (IS_MANAGED_ENV) {\n return _downloadAsyncManagedEnv(uri, hash, type, name);\n }\n\n return _downloadAsyncUnmanagedEnv(uri, hash, type);\n}\n\n/**\n * Check if the file exists on disk already, perform integrity check if so.\n * Otherwise, download it.\n */\nasync function _downloadAsyncManagedEnv(uri, hash, type, name): Promise<string> {\n const cacheFileId = hash || computeMd5(uri);\n const localUri = `${FileSystem.cacheDirectory}ExponentAsset-${cacheFileId}.${type}`;\n let { exists, md5 } = await FileSystem.getInfoAsync(localUri, {\n md5: true,\n });\n if (!exists || (hash !== null && md5 !== hash)) {\n ({ md5 } = await FileSystem.downloadAsync(uri, localUri, {\n md5: true,\n }));\n if (hash !== null && md5 !== hash) {\n throw new Error(\n `Downloaded file for asset '${name}.${type}' ` +\n `Located at ${uri} ` +\n `failed MD5 integrity check`\n );\n }\n }\n return localUri;\n}\n\n/**\n * Just download the asset, don't perform integrity check because we don't have\n * the hash to compare it with (we don't have hashAssetFiles plugin). Hash is\n * only used for the file name.\n */\nasync function _downloadAsyncUnmanagedEnv(uri, hash, type): Promise<string> {\n // TODO: does this make sense to bail out if it's already at a file URL\n // because it's already available locally?\n if (uri.startsWith('file://')) {\n return uri;\n }\n\n const cacheFileId = hash || computeMd5(uri);\n const localUri = `${FileSystem.cacheDirectory}ExponentAsset-${cacheFileId}.${type}`;\n\n // We don't check the FileSystem for an existing version of the asset and we\n // also don't perform an integrity check!\n await FileSystem.downloadAsync(uri, localUri);\n return localUri;\n}\n"]}
@@ -4,3 +4,4 @@ export declare const IS_ENV_WITHOUT_UPDATES_ENABLED = false;
4
4
  export declare const manifestBaseUrl: null;
5
5
  export declare function downloadAsync(uri: any, hash: any, type: any, name: any): Promise<string>;
6
6
  export declare function getManifest(): {};
7
+ export declare function getManifest2(): {};
@@ -9,4 +9,7 @@ export async function downloadAsync(uri, hash, type, name) {
9
9
  export function getManifest() {
10
10
  return {};
11
11
  }
12
+ export function getManifest2() {
13
+ return {};
14
+ }
12
15
  //# sourceMappingURL=PlatformUtils.web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformUtils.web.js","sourceRoot":"","sources":["../src/PlatformUtils.web.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC;AACpC,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAC;AACjD,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAEpD,yCAAyC;AACzC,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC;AAEpC,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACvD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["export const IS_MANAGED_ENV = false;\nexport const IS_ENV_WITH_UPDATES_ENABLED = false;\nexport const IS_ENV_WITHOUT_UPDATES_ENABLED = false;\n\n// Compute manifest base URL if available\nexport const manifestBaseUrl = null;\n\nexport async function downloadAsync(uri, hash, type, name): Promise<string> {\n return uri;\n}\n\nexport function getManifest() {\n return {};\n}\n"]}
1
+ {"version":3,"file":"PlatformUtils.web.js","sourceRoot":"","sources":["../src/PlatformUtils.web.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC;AACpC,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAC;AACjD,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAEpD,yCAAyC;AACzC,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC;AAEpC,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACvD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["export const IS_MANAGED_ENV = false;\nexport const IS_ENV_WITH_UPDATES_ENABLED = false;\nexport const IS_ENV_WITHOUT_UPDATES_ENABLED = false;\n\n// Compute manifest base URL if available\nexport const manifestBaseUrl = null;\n\nexport async function downloadAsync(uri, hash, type, name): Promise<string> {\n return uri;\n}\n\nexport function getManifest() {\n return {};\n}\n\nexport function getManifest2() {\n return {};\n}\n"]}
@@ -3,17 +3,16 @@ import { getAssetByID } from './AssetRegistry';
3
3
  import AssetSourceResolver from './AssetSourceResolver';
4
4
  let _customSourceTransformer;
5
5
  let _serverURL;
6
- let _scriptURL;
7
6
  let _sourceCodeScriptURL;
8
7
  function getSourceCodeScriptURL() {
9
8
  if (_sourceCodeScriptURL) {
10
9
  return _sourceCodeScriptURL;
11
10
  }
12
- let sourceCode = nativeExtensions && nativeExtensions.SourceCode;
11
+ let sourceCode = typeof nativeExtensions !== 'undefined' ? nativeExtensions.SourceCode : null;
13
12
  if (!sourceCode) {
14
- sourceCode = NativeModules && NativeModules.SourceCode;
13
+ sourceCode = NativeModules?.SourceCode;
15
14
  }
16
- _sourceCodeScriptURL = sourceCode.scriptURL;
15
+ _sourceCodeScriptURL = sourceCode?.scriptURL;
17
16
  return _sourceCodeScriptURL;
18
17
  }
19
18
  function getDevServerURL() {
@@ -31,27 +30,6 @@ function getDevServerURL() {
31
30
  }
32
31
  return _serverURL;
33
32
  }
34
- function _coerceLocalScriptURL(scriptURL) {
35
- if (scriptURL) {
36
- if (scriptURL.startsWith('assets://')) {
37
- // android: running from within assets, no offline path to use
38
- return null;
39
- }
40
- scriptURL = scriptURL.substring(0, scriptURL.lastIndexOf('/') + 1);
41
- if (!scriptURL.includes('://')) {
42
- // Add file protocol in case we have an absolute file path and not a URL.
43
- // This shouldn't really be necessary. scriptURL should be a URL.
44
- scriptURL = 'file://' + scriptURL;
45
- }
46
- }
47
- return null;
48
- }
49
- function getScriptURL() {
50
- if (_scriptURL === undefined) {
51
- _scriptURL = _coerceLocalScriptURL(getSourceCodeScriptURL());
52
- }
53
- return _scriptURL;
54
- }
55
33
  export function setCustomSourceTransformer(transformer) {
56
34
  _customSourceTransformer = transformer;
57
35
  }
@@ -67,7 +45,7 @@ export default function resolveAssetSource(source) {
67
45
  if (!asset) {
68
46
  return undefined;
69
47
  }
70
- const resolver = new AssetSourceResolver(getDevServerURL(), getScriptURL(), asset);
48
+ const resolver = new AssetSourceResolver(getDevServerURL(), null, asset);
71
49
  if (_customSourceTransformer) {
72
50
  return _customSourceTransformer(resolver);
73
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolveAssetSource.web.js","sourceRoot":"","sources":["../src/resolveAssetSource.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,mBAA4C,MAAM,uBAAuB,CAAC;AAIjF,IAAI,wBAAwB,CAAC;AAC7B,IAAI,UAAqC,CAAC;AAC1C,IAAI,UAAqC,CAAC;AAC1C,IAAI,oBAA+C,CAAC;AAEpD,SAAS,sBAAsB;IAC7B,IAAI,oBAAoB,EAAE;QACxB,OAAO,oBAAoB,CAAC;KAC7B;IAED,IAAI,UAAU,GAAG,gBAAgB,IAAI,gBAAgB,CAAC,UAAU,CAAC;IACjE,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,aAAa,IAAI,aAAa,CAAC,UAAU,CAAC;KACxD;IACD,oBAAoB,GAAG,UAAU,CAAC,SAAS,CAAC;IAC5C,OAAO,oBAAoB,CAAC;AAC9B,CAAC;AAED,SAAS,eAAe;IACtB,IAAI,UAAU,KAAK,SAAS,EAAE;QAC5B,MAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAC;QACrD,MAAM,KAAK,GAAG,mBAAmB,IAAI,mBAAmB,CAA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E,KAAK,CAAC,CAAC;IACnF,IAAI,wBAAwB,EAAE;QAC5B,OAAO,wBAAwB,CAAC,QAAQ,CAAC,CAAC;KAC3C;IACD,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;AACjC,CAAC;AAED,MAAM,CAAC,cAAc,CAAC,kBAAkB,EAAE,4BAA4B,EAAE;IACtE,GAAG;QACD,OAAO,0BAA0B,CAAC;IACpC,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,mBAAmB,CAAC","sourcesContent":["import { NativeModules } from 'react-native';\n\nimport { getAssetByID } from './AssetRegistry';\nimport AssetSourceResolver, { ResolvedAssetSource } from './AssetSourceResolver';\n\ndeclare let nativeExtensions: any;\n\nlet _customSourceTransformer;\nlet _serverURL: string | undefined | null;\nlet _scriptURL: string | undefined | null;\nlet _sourceCodeScriptURL: string | undefined | null;\n\nfunction getSourceCodeScriptURL(): string | undefined | null {\n if (_sourceCodeScriptURL) {\n return _sourceCodeScriptURL;\n }\n\n let sourceCode = nativeExtensions && nativeExtensions.SourceCode;\n if (!sourceCode) {\n sourceCode = NativeModules && NativeModules.SourceCode;\n }\n _sourceCodeScriptURL = sourceCode.scriptURL;\n return _sourceCodeScriptURL;\n}\n\nfunction getDevServerURL(): string | null {\n if (_serverURL === undefined) {\n const sourceCodeScriptURL = getSourceCodeScriptURL();\n const match = sourceCodeScriptURL && sourceCodeScriptURL.match(/^https?:\\/\\/.*?\\//);\n if (match) {\n // jsBundle was loaded from network\n _serverURL = match[0];\n } else {\n // jsBundle was loaded from file\n _serverURL = null;\n }\n }\n return _serverURL;\n}\n\nfunction _coerceLocalScriptURL(scriptURL: string | undefined | null): string | null {\n if (scriptURL) {\n if (scriptURL.startsWith('assets://')) {\n // android: running from within assets, no offline path to use\n return null;\n }\n scriptURL = scriptURL.substring(0, scriptURL.lastIndexOf('/') + 1);\n if (!scriptURL.includes('://')) {\n // Add file protocol in case we have an absolute file path and not a URL.\n // This shouldn't really be necessary. scriptURL should be a URL.\n scriptURL = 'file://' + scriptURL;\n }\n }\n return null;\n}\n\nfunction getScriptURL(): string | null {\n if (_scriptURL === undefined) {\n _scriptURL = _coerceLocalScriptURL(getSourceCodeScriptURL());\n }\n return _scriptURL;\n}\n\nexport function setCustomSourceTransformer(\n transformer: (resolver: AssetSourceResolver) => ResolvedAssetSource\n): void {\n _customSourceTransformer = transformer;\n}\n\n/**\n * `source` is either a number (opaque type returned by require('./foo.png'))\n * or an `ImageSource` like { uri: '<http location || file path>' }\n */\nexport default function resolveAssetSource(source: any): ResolvedAssetSource | undefined {\n if (typeof source === 'object') {\n return source;\n }\n\n const asset = getAssetByID(source);\n if (!asset) {\n return undefined;\n }\n\n const resolver = new AssetSourceResolver(getDevServerURL(), getScriptURL(), asset);\n if (_customSourceTransformer) {\n return _customSourceTransformer(resolver);\n }\n return resolver.defaultAsset();\n}\n\nObject.defineProperty(resolveAssetSource, 'setCustomSourceTransformer', {\n get() {\n return setCustomSourceTransformer;\n },\n});\n\nexport const { pickScale } = AssetSourceResolver;\n"]}
1
+ {"version":3,"file":"resolveAssetSource.web.js","sourceRoot":"","sources":["../src/resolveAssetSource.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,mBAA4C,MAAM,uBAAuB,CAAC;AAIjF,IAAI,wBAAwB,CAAC;AAC7B,IAAI,UAAqC,CAAC;AAC1C,IAAI,oBAA+C,CAAC;AAEpD,SAAS,sBAAsB;IAC7B,IAAI,oBAAoB,EAAE;QACxB,OAAO,oBAAoB,CAAC;KAC7B;IAED,IAAI,UAAU,GAAG,OAAO,gBAAgB,KAAK,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9F,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,aAAa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esContent":["import { NativeModules } from 'react-native';\n\nimport { getAssetByID } from './AssetRegistry';\nimport AssetSourceResolver, { ResolvedAssetSource } from './AssetSourceResolver';\n\ndeclare let nativeExtensions: { SourceCode?: { scriptURL: string } } | undefined;\n\nlet _customSourceTransformer;\nlet _serverURL: string | undefined | null;\nlet _sourceCodeScriptURL: string | undefined | null;\n\nfunction getSourceCodeScriptURL(): string | undefined | null {\n if (_sourceCodeScriptURL) {\n return _sourceCodeScriptURL;\n }\n\n let sourceCode = typeof nativeExtensions !== 'undefined' ? nativeExtensions.SourceCode : null;\n if (!sourceCode) {\n sourceCode = NativeModules?.SourceCode;\n }\n _sourceCodeScriptURL = sourceCode?.scriptURL;\n return _sourceCodeScriptURL;\n}\n\nfunction getDevServerURL(): string | null {\n if (_serverURL === undefined) {\n const sourceCodeScriptURL = getSourceCodeScriptURL();\n const match = sourceCodeScriptURL && sourceCodeScriptURL.match(/^https?:\\/\\/.*?\\//);\n if (match) {\n // jsBundle was loaded from network\n _serverURL = match[0];\n } else {\n // jsBundle was loaded from file\n _serverURL = null;\n }\n }\n return _serverURL;\n}\n\nexport function setCustomSourceTransformer(\n transformer: (resolver: AssetSourceResolver) => ResolvedAssetSource\n): void {\n _customSourceTransformer = transformer;\n}\n\n/**\n * `source` is either a number (opaque type returned by require('./foo.png'))\n * or an `ImageSource` like { uri: '<http location || file path>' }\n */\nexport default function resolveAssetSource(source: any): ResolvedAssetSource | undefined {\n if (typeof source === 'object') {\n return source;\n }\n\n const asset = getAssetByID(source);\n if (!asset) {\n return undefined;\n }\n\n const resolver = new AssetSourceResolver(getDevServerURL(), null, asset);\n if (_customSourceTransformer) {\n return _customSourceTransformer(resolver);\n }\n return resolver.defaultAsset();\n}\n\nObject.defineProperty(resolveAssetSource, 'setCustomSourceTransformer', {\n get() {\n return setCustomSourceTransformer;\n },\n});\n\nexport const { pickScale } = AssetSourceResolver;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-asset",
3
- "version": "8.4.2",
3
+ "version": "8.4.6",
4
4
  "description": "An Expo universal module to download assets and pass them into other APIs",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -44,9 +44,9 @@
44
44
  "url-parse": "^1.4.4"
45
45
  },
46
46
  "devDependencies": {
47
- "@testing-library/react-hooks": "^3.3.0",
47
+ "@testing-library/react-hooks": "^7.0.1",
48
48
  "@types/url-parse": "^1.4.1",
49
49
  "expo-module-scripts": "^2.0.0"
50
50
  },
51
- "gitHead": "d23e1ac491da96b51c25eb2533efcd56499ee287"
51
+ "gitHead": "a21848f3ed4b04a23aee5d3b78a9f60b3c6f59e0"
52
52
  }
package/src/Asset.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import { Platform } from 'expo-modules-core';
2
2
 
3
3
  import { getAssetByID } from './AssetRegistry';
4
- import * as AssetSources from './AssetSources';
4
+ import { AssetMetadata, selectAssetSource } from './AssetSources';
5
5
  import * as AssetUris from './AssetUris';
6
6
  import * as ImageAssets from './ImageAssets';
7
7
  import { getLocalAssetUri } from './LocalAssets';
8
8
  import { downloadAsync, IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';
9
9
  import resolveAssetSource from './resolveAssetSource';
10
10
 
11
- type AssetDescriptor = {
11
+ // @docsMissing
12
+ export type AssetDescriptor = {
12
13
  name: string;
13
14
  type: string;
14
15
  hash?: string | null;
@@ -22,21 +23,65 @@ type DownloadPromiseCallbacks = {
22
23
  reject: (error: Error) => void;
23
24
  };
24
25
 
25
- export type AssetMetadata = AssetSources.AssetMetadata;
26
+ export { AssetMetadata };
26
27
 
28
+ // @needsAudit
29
+ /**
30
+ * The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its
31
+ * name and type) and provides facilities to load the asset data.
32
+ */
27
33
  export class Asset {
34
+ /**
35
+ * @private
36
+ */
28
37
  static byHash = {};
38
+ /**
39
+ * @private
40
+ */
29
41
  static byUri = {};
30
42
 
43
+ /**
44
+ * The name of the asset file without the extension. Also without the part from `@` onward in the
45
+ * filename (used to specify scale factor for images).
46
+ */
31
47
  name: string;
48
+ /**
49
+ * The extension of the asset filename.
50
+ */
32
51
  type: string;
52
+ /**
53
+ * The MD5 hash of the asset's data.
54
+ */
33
55
  hash: string | null = null;
56
+ /**
57
+ * A URI that points to the asset's data on the remote server. When running the published version
58
+ * of your app, this refers to the location on Expo's asset server where Expo has stored your
59
+ * asset. When running the app from Expo CLI during development, this URI points to Expo CLI's
60
+ * server running on your computer and the asset is served directly from your computer.
61
+ */
34
62
  uri: string;
63
+ /**
64
+ * If the asset has been downloaded (by calling [`downloadAsync()`](#downloadasync)), the
65
+ * `file://` URI pointing to the local file on the device that contains the asset data.
66
+ */
35
67
  localUri: string | null = null;
68
+ /**
69
+ * If the asset is an image, the width of the image data divided by the scale factor. The scale
70
+ * factor is the number after `@` in the filename, or `1` if not present.
71
+ */
36
72
  width: number | null = null;
73
+ /**
74
+ * If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.
75
+ */
37
76
  height: number | null = null;
77
+ // @docsMissing
38
78
  downloading: boolean = false;
79
+ // @docsMissing
39
80
  downloaded: boolean = false;
81
+
82
+ /**
83
+ * @private
84
+ */
40
85
  _downloadCallbacks: DownloadPromiseCallbacks[] = [];
41
86
 
42
87
  constructor({ name, type, hash = null, uri, width, height }: AssetDescriptor) {
@@ -69,11 +114,30 @@ export class Asset {
69
114
  }
70
115
  }
71
116
 
117
+ // @needsAudit
118
+ /**
119
+ * A helper that wraps `Asset.fromModule(module).downloadAsync` for convenience.
120
+ * @param moduleId An array of `require('path/to/file')` or external network URLs. Can also be
121
+ * just one module or URL without an Array.
122
+ * @return Returns a Promise that fulfills with an array of `Asset`s when the asset(s) has been
123
+ * saved to disk.
124
+ * @example
125
+ * ```ts
126
+ * const [{ localUri }] = await Asset.loadAsync(require('./assets/snack-icon.png'));
127
+ * ```
128
+ */
72
129
  static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {
73
130
  const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];
74
131
  return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));
75
132
  }
76
133
 
134
+ // @needsAudit
135
+ /**
136
+ * Returns the [`Asset`](#asset) instance representing an asset given its module or URL.
137
+ * @param virtualAssetModule The value of `require('path/to/file')` for the asset or external
138
+ * network URL
139
+ * @return The [`Asset`](#asset) instance for the asset.
140
+ */
77
141
  static fromModule(virtualAssetModule: number | string): Asset {
78
142
  if (typeof virtualAssetModule === 'string') {
79
143
  return Asset.fromURI(virtualAssetModule);
@@ -113,6 +177,7 @@ export class Asset {
113
177
  return Asset.fromMetadata(meta);
114
178
  }
115
179
 
180
+ // @docsMissing
116
181
  static fromMetadata(meta: AssetMetadata): Asset {
117
182
  // The hash of the whole asset, not to be confused with the hash of a specific file returned
118
183
  // from `selectAssetSource`
@@ -121,7 +186,7 @@ export class Asset {
121
186
  return Asset.byHash[metaHash];
122
187
  }
123
188
 
124
- const { uri, hash } = AssetSources.selectAssetSource(meta);
189
+ const { uri, hash } = selectAssetSource(meta);
125
190
  const asset = new Asset({
126
191
  name: meta.name,
127
192
  type: meta.type,
@@ -134,6 +199,7 @@ export class Asset {
134
199
  return asset;
135
200
  }
136
201
 
202
+ // @docsMissing
137
203
  static fromURI(uri: string): Asset {
138
204
  if (Asset.byUri[uri]) {
139
205
  return Asset.byUri[uri];
@@ -160,6 +226,15 @@ export class Asset {
160
226
  return asset;
161
227
  }
162
228
 
229
+ // @needsAudit
230
+ /**
231
+ * Downloads the asset data to a local file in the device's cache directory. Once the returned
232
+ * promise is fulfilled without error, the [`localUri`](#assetlocaluri) field of this asset points
233
+ * to a local file containing the asset data. The asset is only downloaded if an up-to-date local
234
+ * file for the asset isn't already present due to an earlier download. The downloaded `Asset`
235
+ * will be returned when the promise is resolved.
236
+ * @return Returns a Promise which fulfills with an `Asset` instance.
237
+ */
163
238
  async downloadAsync(): Promise<this> {
164
239
  if (this.downloaded) {
165
240
  return this;
package/src/AssetHooks.ts CHANGED
@@ -2,19 +2,25 @@ import { useEffect, useState } from 'react';
2
2
 
3
3
  import { Asset } from './Asset';
4
4
 
5
+ // @needsAudit
5
6
  /**
6
7
  * Downloads and stores one or more assets locally.
7
8
  * After the assets are loaded, this hook returns a list of asset instances.
8
9
  * If something went wrong when loading the assets, an error is returned.
9
10
  *
10
- * Note, the assets are not "reloaded" when you dynamically change the asset list.
11
+ * > Note, the assets are not "reloaded" when you dynamically change the asset list.
12
+ *
13
+ * @return Returns an array containing:
14
+ * - on the first position, a list of all loaded assets. If they aren't loaded yet, this value is
15
+ * `undefined`.
16
+ * - on the second position, an error which encountered when loading the assets. If there was no
17
+ * error, this value is `undefined`.
11
18
  *
12
- * @see https://docs.expo.io/versions/latest/sdk/asset/
13
19
  * @example
14
20
  * ```tsx
15
- * const [assets, error] = useAssets(require('path/to/asset.jpg'));
21
+ * const [assets, error] = useAssets([require('path/to/asset.jpg'), require('path/to/other.png')]);
16
22
  *
17
- * return !assets ? null : <Image source={assets[0]} />;
23
+ * return assets ? <Image source={assets[0]} /> : null;
18
24
  * ```
19
25
  */
20
26
  export function useAssets(moduleIds: number | number[]): [Asset[] | undefined, Error | undefined] {
@@ -37,7 +37,7 @@ function getScaledAssetPath(asset): string {
37
37
  const scale = AssetSourceResolver.pickScale(asset.scales, getScale());
38
38
  const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';
39
39
  const assetDir = getBasePath(asset);
40
- return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;
40
+ return assetDir + '/' + asset.name + scaleSuffix + (asset.type ? `.${asset.type}` : '');
41
41
  }
42
42
 
43
43
  export default class AssetSourceResolver {
@@ -84,7 +84,7 @@ export default class AssetSourceResolver {
84
84
  return this.fromSource(getScaledAssetPath(this.asset));
85
85
  }
86
86
  scaledAssetURLNearBundle(): ResolvedAssetSource {
87
- const path = this.jsbundleUrl || 'file://';
87
+ const path = this.jsbundleUrl || '';
88
88
  return this.fromSource(path + getScaledAssetPath(this.asset));
89
89
  }
90
90
  resourceIdentifierWithoutScale(): ResolvedAssetSource {
@@ -4,8 +4,9 @@ import { PixelRatio } from 'react-native';
4
4
  import URL from 'url-parse';
5
5
 
6
6
  import AssetSourceResolver from './AssetSourceResolver';
7
- import { manifestBaseUrl, getManifest } from './PlatformUtils';
7
+ import { manifestBaseUrl, getManifest, getManifest2 } from './PlatformUtils';
8
8
 
9
+ // @docsMissing
9
10
  export type AssetMetadata = {
10
11
  hash: string;
11
12
  name: string;
@@ -73,6 +74,19 @@ export function selectAssetSource(meta: AssetMetadata): AssetSource {
73
74
  return { uri, hash };
74
75
  }
75
76
 
77
+ // For assets during development using manifest2, we use the development server's URL origin
78
+ const manifest2 = getManifest2();
79
+
80
+ if (manifest2?.extra?.expoGo?.developer) {
81
+ const baseUrl = new URL(`http://${manifest2.extra.expoGo.debuggerHost}`);
82
+ baseUrl.set('pathname', meta.httpServerLocation + suffix);
83
+
84
+ return {
85
+ uri: baseUrl.href,
86
+ hash,
87
+ };
88
+ }
89
+
76
90
  // For assets during development, we use the development server's URL origin
77
91
  if (getManifest().developer) {
78
92
  const baseUrl = new URL(getManifest().bundleUrl);
@@ -1,5 +1,6 @@
1
1
  import computeMd5 from 'blueimp-md5';
2
2
  import Constants from 'expo-constants';
3
+ import { Manifest } from 'expo-constants/build/Constants.types';
3
4
  import * as FileSystem from 'expo-file-system';
4
5
  import { NativeModulesProxy } from 'expo-modules-core';
5
6
 
@@ -33,6 +34,10 @@ export function getManifest(): { [key: string]: any } {
33
34
  return Constants.__unsafeNoWarnManifest ?? {};
34
35
  }
35
36
 
37
+ export function getManifest2(): Manifest | undefined {
38
+ return Constants.__unsafeNoWarnManifest2;
39
+ }
40
+
36
41
  // Compute manifest base URL if available
37
42
  export const manifestBaseUrl = Constants.experienceUrl
38
43
  ? getManifestBaseUrl(Constants.experienceUrl)
@@ -12,3 +12,7 @@ export async function downloadAsync(uri, hash, type, name): Promise<string> {
12
12
  export function getManifest() {
13
13
  return {};
14
14
  }
15
+
16
+ export function getManifest2() {
17
+ return {};
18
+ }
@@ -3,11 +3,10 @@ import { NativeModules } from 'react-native';
3
3
  import { getAssetByID } from './AssetRegistry';
4
4
  import AssetSourceResolver, { ResolvedAssetSource } from './AssetSourceResolver';
5
5
 
6
- declare let nativeExtensions: any;
6
+ declare let nativeExtensions: { SourceCode?: { scriptURL: string } } | undefined;
7
7
 
8
8
  let _customSourceTransformer;
9
9
  let _serverURL: string | undefined | null;
10
- let _scriptURL: string | undefined | null;
11
10
  let _sourceCodeScriptURL: string | undefined | null;
12
11
 
13
12
  function getSourceCodeScriptURL(): string | undefined | null {
@@ -15,11 +14,11 @@ function getSourceCodeScriptURL(): string | undefined | null {
15
14
  return _sourceCodeScriptURL;
16
15
  }
17
16
 
18
- let sourceCode = nativeExtensions && nativeExtensions.SourceCode;
17
+ let sourceCode = typeof nativeExtensions !== 'undefined' ? nativeExtensions.SourceCode : null;
19
18
  if (!sourceCode) {
20
- sourceCode = NativeModules && NativeModules.SourceCode;
19
+ sourceCode = NativeModules?.SourceCode;
21
20
  }
22
- _sourceCodeScriptURL = sourceCode.scriptURL;
21
+ _sourceCodeScriptURL = sourceCode?.scriptURL;
23
22
  return _sourceCodeScriptURL;
24
23
  }
25
24
 
@@ -38,29 +37,6 @@ function getDevServerURL(): string | null {
38
37
  return _serverURL;
39
38
  }
40
39
 
41
- function _coerceLocalScriptURL(scriptURL: string | undefined | null): string | null {
42
- if (scriptURL) {
43
- if (scriptURL.startsWith('assets://')) {
44
- // android: running from within assets, no offline path to use
45
- return null;
46
- }
47
- scriptURL = scriptURL.substring(0, scriptURL.lastIndexOf('/') + 1);
48
- if (!scriptURL.includes('://')) {
49
- // Add file protocol in case we have an absolute file path and not a URL.
50
- // This shouldn't really be necessary. scriptURL should be a URL.
51
- scriptURL = 'file://' + scriptURL;
52
- }
53
- }
54
- return null;
55
- }
56
-
57
- function getScriptURL(): string | null {
58
- if (_scriptURL === undefined) {
59
- _scriptURL = _coerceLocalScriptURL(getSourceCodeScriptURL());
60
- }
61
- return _scriptURL;
62
- }
63
-
64
40
  export function setCustomSourceTransformer(
65
41
  transformer: (resolver: AssetSourceResolver) => ResolvedAssetSource
66
42
  ): void {
@@ -81,7 +57,7 @@ export default function resolveAssetSource(source: any): ResolvedAssetSource | u
81
57
  return undefined;
82
58
  }
83
59
 
84
- const resolver = new AssetSourceResolver(getDevServerURL(), getScriptURL(), asset);
60
+ const resolver = new AssetSourceResolver(getDevServerURL(), null, asset);
85
61
  if (_customSourceTransformer) {
86
62
  return _customSourceTransformer(resolver);
87
63
  }