expo-asset 8.3.3 → 8.4.3

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/build/Asset.fx.js +1 -1
  3. package/build/Asset.fx.js.map +1 -1
  4. package/build/Asset.js +16 -13
  5. package/build/Asset.js.map +1 -1
  6. package/build/AssetHooks.js +1 -3
  7. package/build/AssetHooks.js.map +1 -1
  8. package/build/AssetSourceResolver.web.js +8 -3
  9. package/build/AssetSourceResolver.web.js.map +1 -1
  10. package/build/AssetSources.js +2 -2
  11. package/build/AssetSources.js.map +1 -1
  12. package/build/LocalAssets.d.ts +4 -0
  13. package/build/LocalAssets.js +35 -0
  14. package/build/LocalAssets.js.map +1 -0
  15. package/build/LocalAssets.web.d.ts +1 -0
  16. package/build/LocalAssets.web.js +5 -0
  17. package/build/LocalAssets.web.js.map +1 -0
  18. package/build/PlatformUtils.js +1 -1
  19. package/build/PlatformUtils.js.map +1 -1
  20. package/build/resolveAssetSource.web.js +4 -26
  21. package/build/resolveAssetSource.web.js.map +1 -1
  22. package/package.json +3 -3
  23. package/src/Asset.fx.ts +1 -1
  24. package/src/Asset.ts +5 -5
  25. package/src/AssetHooks.ts +1 -3
  26. package/src/AssetSourceResolver.web.ts +3 -3
  27. package/src/AssetSources.ts +2 -2
  28. package/src/LocalAssets.ts +39 -0
  29. package/src/LocalAssets.web.ts +4 -0
  30. package/src/PlatformUtils.ts +1 -1
  31. package/src/resolveAssetSource.web.ts +5 -29
  32. package/build/EmbeddedAssets.d.ts +0 -5
  33. package/build/EmbeddedAssets.js +0 -25
  34. package/build/EmbeddedAssets.js.map +0 -1
  35. package/build/EmbeddedAssets.web.d.ts +0 -1
  36. package/build/EmbeddedAssets.web.js +0 -5
  37. package/build/EmbeddedAssets.web.js.map +0 -1
  38. package/src/EmbeddedAssets.ts +0 -28
  39. package/src/EmbeddedAssets.web.ts +0 -4
package/CHANGELOG.md CHANGED
@@ -10,10 +10,28 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 8.3.3 — 2021-07-20
13
+ ## 8.4.3 — 2021-10-21
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fix `fromModule` on restrictive (Snack) web environments. ([#14435](https://github.com/expo/expo/pull/14435) by [@IjzerenHein](https://github.com/IjzerenHein))
18
+
19
+ ## 8.4.2 — 2021-10-15
14
20
 
15
21
  _This version does not introduce any user-facing changes._
16
22
 
23
+ ## 8.4.1 — 2021-10-01
24
+
25
+ ### 💡 Others
26
+
27
+ - Updated `@testing-library/react-hooks` to version `7.0.1`. ([#14552](https://github.com/expo/expo/pull/14552)) by [@Simek](https://github.com/Simek))
28
+
29
+ ## 8.4.0 — 2021-09-08
30
+
31
+ ### 🎉 New features
32
+
33
+ - Reapply [#12624](https://github.com/expo/expo/pull/12624) ([#13789](https://github.com/expo/expo/pull/13789) by [@jkhales](https://github.com/jkhales))
34
+
17
35
  ## 8.3.2 — 2021-04-21
18
36
 
19
37
  ### 🎉 New features
package/build/Asset.fx.js CHANGED
@@ -3,7 +3,7 @@ import { IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';
3
3
  import { setCustomSourceTransformer } from './resolveAssetSource';
4
4
  // Override React Native's asset resolution for `Image` components in contexts where it matters
5
5
  if (IS_ENV_WITH_UPDATES_ENABLED) {
6
- setCustomSourceTransformer(resolver => {
6
+ setCustomSourceTransformer((resolver) => {
7
7
  try {
8
8
  // Bundler is using the hashAssetFiles plugin if and only if the fileHashes property exists
9
9
  if (resolver.asset.fileHashes) {
@@ -1 +1 @@
1
- {"version":3,"file":"Asset.fx.js","sourceRoot":"","sources":["../src/Asset.fx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAElE,+FAA+F;AAC/F,IAAI,2BAA2B,EAAE;IAC/B,0BAA0B,CAAC,QAAQ,CAAC,EAAE;QACpC,IAAI;YACF,2FAA2F;YAC3F,IAAI,QAAQ,CAAC,KAAK,CAAC,UAAU,EAAE;gBAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACjD,OAAO,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aAC5E;iBAAM;gBACL,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;aAChC;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;SAChC;IACH,CAAC,CAAC,CAAC;CACJ","sourcesContent":["import { Asset } from './Asset';\nimport { IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';\nimport { setCustomSourceTransformer } from './resolveAssetSource';\n\n// Override React Native's asset resolution for `Image` components in contexts where it matters\nif (IS_ENV_WITH_UPDATES_ENABLED) {\n setCustomSourceTransformer(resolver => {\n try {\n // Bundler is using the hashAssetFiles plugin if and only if the fileHashes property exists\n if (resolver.asset.fileHashes) {\n const asset = Asset.fromMetadata(resolver.asset);\n return resolver.fromSource(asset.downloaded ? asset.localUri! : asset.uri);\n } else {\n return resolver.defaultAsset();\n }\n } catch (e) {\n return resolver.defaultAsset();\n }\n });\n}\n"]}
1
+ {"version":3,"file":"Asset.fx.js","sourceRoot":"","sources":["../src/Asset.fx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAElE,+FAA+F;AAC/F,IAAI,2BAA2B,EAAE;IAC/B,0BAA0B,CAAC,CAAC,QAAQ,EAAE,EAAE;QACtC,IAAI;YACF,2FAA2F;YAC3F,IAAI,QAAQ,CAAC,KAAK,CAAC,UAAU,EAAE;gBAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACjD,OAAO,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aAC5E;iBAAM;gBACL,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;aAChC;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;SAChC;IACH,CAAC,CAAC,CAAC;CACJ","sourcesContent":["import { Asset } from './Asset';\nimport { IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';\nimport { setCustomSourceTransformer } from './resolveAssetSource';\n\n// Override React Native's asset resolution for `Image` components in contexts where it matters\nif (IS_ENV_WITH_UPDATES_ENABLED) {\n setCustomSourceTransformer((resolver) => {\n try {\n // Bundler is using the hashAssetFiles plugin if and only if the fileHashes property exists\n if (resolver.asset.fileHashes) {\n const asset = Asset.fromMetadata(resolver.asset);\n return resolver.fromSource(asset.downloaded ? asset.localUri! : asset.uri);\n } else {\n return resolver.defaultAsset();\n }\n } catch (e) {\n return resolver.defaultAsset();\n }\n });\n}\n"]}
package/build/Asset.js CHANGED
@@ -1,20 +1,25 @@
1
- import { Platform } from '@unimodules/core';
1
+ import { Platform } from 'expo-modules-core';
2
2
  import { getAssetByID } from './AssetRegistry';
3
3
  import * as AssetSources from './AssetSources';
4
4
  import * as AssetUris from './AssetUris';
5
- import { getEmbeddedAssetUri } from './EmbeddedAssets';
6
5
  import * as ImageAssets from './ImageAssets';
6
+ import { getLocalAssetUri } from './LocalAssets';
7
7
  import { downloadAsync, IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';
8
8
  import resolveAssetSource from './resolveAssetSource';
9
9
  export class Asset {
10
+ static byHash = {};
11
+ static byUri = {};
12
+ name;
13
+ type;
14
+ hash = null;
15
+ uri;
16
+ localUri = null;
17
+ width = null;
18
+ height = null;
19
+ downloading = false;
20
+ downloaded = false;
21
+ _downloadCallbacks = [];
10
22
  constructor({ name, type, hash = null, uri, width, height }) {
11
- this.hash = null;
12
- this.localUri = null;
13
- this.width = null;
14
- this.height = null;
15
- this.downloading = false;
16
- this.downloaded = false;
17
- this._downloadCallbacks = [];
18
23
  this.name = name;
19
24
  this.type = type;
20
25
  this.hash = hash;
@@ -26,7 +31,7 @@ export class Asset {
26
31
  this.height = height;
27
32
  }
28
33
  if (hash) {
29
- this.localUri = getEmbeddedAssetUri(hash, type);
34
+ this.localUri = getLocalAssetUri(hash, type);
30
35
  if (this.localUri) {
31
36
  this.downloaded = true;
32
37
  }
@@ -42,7 +47,7 @@ export class Asset {
42
47
  }
43
48
  static loadAsync(moduleId) {
44
49
  const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];
45
- return Promise.all(moduleIds.map(moduleId => Asset.fromModule(moduleId).downloadAsync()));
50
+ return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));
46
51
  }
47
52
  static fromModule(virtualAssetModule) {
48
53
  if (typeof virtualAssetModule === 'string') {
@@ -156,6 +161,4 @@ export class Asset {
156
161
  return this;
157
162
  }
158
163
  }
159
- Asset.byHash = {};
160
- Asset.byUri = {};
161
164
  //# sourceMappingURL=Asset.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Asset.js","sourceRoot":"","sources":["../src/Asset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,SAAS,MAAM,aAAa,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K,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,WAAW,CAAC,iBAAiB,CAAC,IAAI,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;;AA1KM,YAAM,GAAG,EAAE,CAAC;AACZ,WAAK,GAAG,EAAE,CAAC","sourcesContent":["import { Platform } from '@unimodules/core';\n\nimport { getAssetByID } from './AssetRegistry';\nimport * as AssetSources from './AssetSources';\nimport * as AssetUris from './AssetUris';\nimport { getEmbeddedAssetUri } from './EmbeddedAssets';\nimport * as ImageAssets from './ImageAssets';\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 = getEmbeddedAssetUri(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((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":["../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,MAAM,OAAO,KAAK;IAChB,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;IAElB,IAAI,CAAS;IACb,IAAI,CAAS;IACb,IAAI,GAAkB,IAAI,CAAC;IAC3B,GAAG,CAAS;IACZ,QAAQ,GAAkB,IAAI,CAAC;IAC/B,KAAK,GAAkB,IAAI,CAAC;IAC5B,MAAM,GAAkB,IAAI,CAAC;IAC7B,WAAW,GAAY,KAAK,CAAC;IAC7B,UAAU,GAAY,KAAK,CAAC;IAC5B,kBAAkB,GAA+B,EAAE,CAAC;IAEpD,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAmB;QAC1E,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAEf,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AAM,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"]}
@@ -19,9 +19,7 @@ export function useAssets(moduleIds) {
19
19
  const [assets, setAssets] = useState();
20
20
  const [error, setError] = useState();
21
21
  useEffect(() => {
22
- Asset.loadAsync(moduleIds)
23
- .then(setAssets)
24
- .catch(setError);
22
+ Asset.loadAsync(moduleIds).then(setAssets).catch(setError);
25
23
  }, []);
26
24
  return [assets, error];
27
25
  }
@@ -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;aACvB,IAAI,CAAC,SAAS,CAAC;aACf,KAAK,CAAC,QAAQ,CAAC,CAAC;IACrB,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)\n .then(setAssets)\n .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;;;;;;;;;;;;;;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,4 +1,4 @@
1
- import { Platform, UnavailabilityError } from '@unimodules/core';
1
+ import { Platform, UnavailabilityError } from 'expo-modules-core';
2
2
  import invariant from 'invariant';
3
3
  import { Dimensions } from 'react-native';
4
4
  function getBasePath({ httpServerLocation }) {
@@ -14,9 +14,14 @@ 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
+ serverUrl;
21
+ // where the jsbundle is being run from
22
+ jsbundleUrl;
23
+ // the asset to resolve
24
+ asset;
20
25
  constructor(serverUrl, jsbundleUrl, asset) {
21
26
  this.serverUrl = serverUrl;
22
27
  this.jsbundleUrl = jsbundleUrl;
@@ -47,7 +52,7 @@ export default class AssetSourceResolver {
47
52
  return this.fromSource(getScaledAssetPath(this.asset));
48
53
  }
49
54
  scaledAssetURLNearBundle() {
50
- const path = this.jsbundleUrl || 'file://';
55
+ const path = this.jsbundleUrl || '';
51
56
  return this.fromSource(path + getScaledAssetPath(this.asset));
52
57
  }
53
58
  resourceIdentifierWithoutScale() {
@@ -1 +1 @@
1
- {"version":3,"file":"AssetSourceResolver.web.js","sourceRoot":"","sources":["../src/AssetSourceResolver.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAc1C,SAAS,WAAW,CAAC,EAAE,kBAAkB,EAAiB;IACxD,IAAI,kBAAkB,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QACjC,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KACrC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAUD,SAAS,QAAQ;IACf,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;AACxC,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAK;IAC/B,MAAM,KAAK,GAAG,mBAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IACtE,MAAM,WAAW,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;IACzD,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,QAAQ,GAAG,GAAG,GAAG,KAAK,CAAC,IAAI,GAAG,WAAW,GAAG,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC;AACtE,CAAC;AAED,MAAM,CAAC,OAAO,OAAO,mBAAmB;IAOtC,YACE,SAAoC,EACpC,WAAsC,EACtC,KAAoB;QAEpB,IAAI,CAAC,SAAS,GAA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CAAC,CAAC;IAC5E,CAAC;IACD,UAAU,CAAC,MAAc;QACvB,OAAO;YACL,gBAAgB,EAAE,IAAI;YACtB,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 '@unimodules/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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C,MAAc;QACvB,OAAO;YACL,gBAAgB,EAAE,IAAI;YACtB,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 ? `.${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"]}
@@ -1,4 +1,4 @@
1
- import { Platform } from '@unimodules/core';
1
+ import { Platform } from 'expo-modules-core';
2
2
  import path from 'path-browserify';
3
3
  import { PixelRatio } from 'react-native';
4
4
  import URL from 'url-parse';
@@ -20,7 +20,7 @@ export function selectAssetSource(meta) {
20
20
  // This logic is based on that of AssetSourceResolver, with additional support for file hashes and
21
21
  // explicitly provided URIs
22
22
  const scale = AssetSourceResolver.pickScale(meta.scales, PixelRatio.get());
23
- const index = meta.scales.findIndex(s => s === scale);
23
+ const index = meta.scales.findIndex((s) => s === scale);
24
24
  const hash = meta.fileHashes ? meta.fileHashes[index] || meta.fileHashes[0] : meta.hash;
25
25
  // Allow asset processors to directly provide the URL to load
26
26
  const uri = meta.fileUris ? meta.fileUris[index] || meta.fileUris[0] : meta.uri;
@@ -1 +1 @@
1
- {"version":3,"file":"AssetSources.js","sourceRoot":"","sources":["../src/AssetSources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,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,2BAA2B;IAC3B,MAAM,KAAK,GAAG,mBAAmB,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,GA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,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IACtC,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC","sourcesContent":["import { Platform } from '@unimodules/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,MAAM,iBAAiB,CAAC;AAoB/D,mEAAmE;AACnE,MAAM,gBAAgB,GAAG,WAAW,EAAE,CAAC,gBAAgB,CAAC;AAExD;;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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 } 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"]}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns the URI of a local asset from its hash, or null if the asset is not available locally
3
+ */
4
+ export declare function getLocalAssetUri(hash: string, type: string | null): string | null;
@@ -0,0 +1,35 @@
1
+ import Constants from 'expo-constants';
2
+ import * as FileSystem from 'expo-file-system';
3
+ import { getLocalAssets } from './PlatformUtils';
4
+ // Fast lookup check if assets are available in the local bundle in managed apps
5
+ const bundledAssets = new Set(FileSystem.bundledAssets || []);
6
+ // localAssets are provided by the expo-updates module
7
+ const localAssets = getLocalAssets();
8
+ /**
9
+ * Returns the URI of a local asset from its hash, or null if the asset is not available locally
10
+ */
11
+ export function getLocalAssetUri(hash, type) {
12
+ const localAssetsKey = hash;
13
+ const legacyLocalAssetsKey = `${hash}.${type ?? ''}`;
14
+ switch (true) {
15
+ case localAssetsKey in localAssets: {
16
+ return localAssets[localAssetsKey];
17
+ }
18
+ case legacyLocalAssetsKey in localAssets: {
19
+ // legacy updates store assets with an extension
20
+ return localAssets[legacyLocalAssetsKey];
21
+ }
22
+ case !__DEV__: {
23
+ // check legacy location in case we're in Expo client/managed workflow
24
+ // TODO(eric): remove this once bundledAssets is no longer exported from FileSystem
25
+ const assetName = `asset_${hash}${type ? `.${type}` : ''}`;
26
+ if (Constants.appOwnership !== 'standalone' || !bundledAssets.has(assetName)) {
27
+ return null;
28
+ }
29
+ return `${FileSystem.bundleDirectory}${assetName}`;
30
+ }
31
+ default:
32
+ return null;
33
+ }
34
+ }
35
+ //# sourceMappingURL=LocalAssets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalAssets.js","sourceRoot":"","sources":["../src/LocalAssets.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,gFAAgF;AAChF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;AAE9D,sDAAsD;AACtD,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;AAErC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,IAAmB;IAChE,MAAM,cAAc,GAAG,IAAI,CAAC;IAC5B,MAAM,oBAAoB,GAAG,GAAG,IAAI,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC;IAErD,QAAQ,IAAI,EAAE;QACZ,KAAK,cAAc,IAAI,WAAW,CAAC,CAAC;YAClC,OAAO,WAAW,CAAC,cAAc,CAAC,CAAC;SACpC;QACD,KAAK,oBAAoB,IAAI,WAAW,CAAC,CAAC;YACxC,gDAAgD;YAChD,OAAO,WAAW,CAAC,oBAAoB,CAAC,CAAC;SAC1C;QACD,KAAK,CAAC,OAAO,CAAC,CAAC;YACb,sEAAsE;YACtE,mFAAmF;YACnF,MAAM,SAAS,GAAG,SAAS,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;YAC3D,IAAI,SAAS,CAAC,YAAY,KAAK,YAAY,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;gBAC5E,OAAO,IAAI,CAAC;aACb;YACD,OAAO,GAAG,UAAU,CAAC,eAAe,GAAG,SAAS,EAAE,CAAC;SACpD;QACD;YACE,OAAO,IAAI,CAAC;KACf;AACH,CAAC","sourcesContent":["import Constants from 'expo-constants';\nimport * as FileSystem from 'expo-file-system';\n\nimport { getLocalAssets } from './PlatformUtils';\n\n// Fast lookup check if assets are available in the local bundle in managed apps\nconst bundledAssets = new Set(FileSystem.bundledAssets || []);\n\n// localAssets are provided by the expo-updates module\nconst localAssets = getLocalAssets();\n\n/**\n * Returns the URI of a local asset from its hash, or null if the asset is not available locally\n */\nexport function getLocalAssetUri(hash: string, type: string | null): string | null {\n const localAssetsKey = hash;\n const legacyLocalAssetsKey = `${hash}.${type ?? ''}`;\n\n switch (true) {\n case localAssetsKey in localAssets: {\n return localAssets[localAssetsKey];\n }\n case legacyLocalAssetsKey in localAssets: {\n // legacy updates store assets with an extension\n return localAssets[legacyLocalAssetsKey];\n }\n case !__DEV__: {\n // check legacy location in case we're in Expo client/managed workflow\n // TODO(eric): remove this once bundledAssets is no longer exported from FileSystem\n const assetName = `asset_${hash}${type ? `.${type}` : ''}`;\n if (Constants.appOwnership !== 'standalone' || !bundledAssets.has(assetName)) {\n return null;\n }\n return `${FileSystem.bundleDirectory}${assetName}`;\n }\n default:\n return null;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function getLocalAssetUri(hash: string, type: string | null): string | null;
@@ -0,0 +1,5 @@
1
+ export function getLocalAssetUri(hash, type) {
2
+ // noop on web
3
+ return null;
4
+ }
5
+ //# sourceMappingURL=LocalAssets.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalAssets.web.js","sourceRoot":"","sources":["../src/LocalAssets.web.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,IAAmB;IAChE,cAAc;IACd,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["export function getLocalAssetUri(hash: string, type: string | null): string | null {\n // noop on web\n return null;\n}\n"]}
@@ -1,7 +1,7 @@
1
- import { NativeModulesProxy } from '@unimodules/core';
2
1
  import computeMd5 from 'blueimp-md5';
3
2
  import Constants from 'expo-constants';
4
3
  import * as FileSystem from 'expo-file-system';
4
+ import { NativeModulesProxy } from 'expo-modules-core';
5
5
  import { getManifestBaseUrl } from './AssetUris';
6
6
  // Constants.appOwnership is only available in managed apps (Expo client and standalone)
7
7
  export const IS_MANAGED_ENV = !!Constants.appOwnership;
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformUtils.js","sourceRoot":"","sources":["../src/PlatformUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,SAAS,MAAM,gBAAgB,CA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aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC9C,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { NativeModulesProxy } from '@unimodules/core';\nimport computeMd5 from 'blueimp-md5';\nimport Constants from 'expo-constants';\nimport * as FileSystem from 'expo-file-system';\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;AACvC,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,wFAAwF;AACxF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC;AAEvD,yFAAyF;AACzF,sFAAsF;AACtF,0BAA0B;AAC1B,MA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AAC;IACpF,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,QAAQ,EAAE;QAC5D,GAAG,EAAE,IAAI;KACV,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,CAAC,EAAE;QAC9C,CAAC,EAAE,GAAG,EAAE,GAAG,MAAM,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE;YACvD,GAAG,EAAE,IAAI;SACV,CAAC,CAAC,CAAC;QACJ,IAAI,IAAI,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,EAAE;YACjC,MAAM,IAAI,KAAK,CACb,8BAA8B,IAAI,IAAI,IAAI,IAAI;gBAC5C,cAAc,GAAG,GAAG;gBACpB,4BAA4B,CAC/B,CAAC;SACH;KACF;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,0BAA0B,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI;IACvD,uEAAuE;IACvE,0CAA0C;IAC1C,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,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"]}
@@ -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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AAO,MAAM,CAAC;KACf;IAED,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,QAAQ,GAAG,IAAI,mBAAmB,CAAC,eAAe,EAAE,EAAE,YAAY,EAAE,EAAE,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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AE,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: { 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.3.3",
3
+ "version": "8.4.3",
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",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "author": "650 Industries, Inc.",
34
34
  "license": "MIT",
35
- "homepage": "https://docs.expo.io/versions/latest/sdk/asset/",
35
+ "homepage": "https://docs.expo.dev/versions/latest/sdk/asset/",
36
36
  "jest": {
37
37
  "preset": "expo-module-scripts/ios"
38
38
  },
@@ -48,5 +48,5 @@
48
48
  "@types/url-parse": "^1.4.1",
49
49
  "expo-module-scripts": "^2.0.0"
50
50
  },
51
- "gitHead": "7344b938b05ffd138a4ed1e102890248961eb2c5"
51
+ "gitHead": "4fa0497a180ae707fa860cb03858630ab7af19f4"
52
52
  }
package/src/Asset.fx.ts CHANGED
@@ -4,7 +4,7 @@ import { setCustomSourceTransformer } from './resolveAssetSource';
4
4
 
5
5
  // Override React Native's asset resolution for `Image` components in contexts where it matters
6
6
  if (IS_ENV_WITH_UPDATES_ENABLED) {
7
- setCustomSourceTransformer(resolver => {
7
+ setCustomSourceTransformer((resolver) => {
8
8
  try {
9
9
  // Bundler is using the hashAssetFiles plugin if and only if the fileHashes property exists
10
10
  if (resolver.asset.fileHashes) {
package/src/Asset.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { Platform } from '@unimodules/core';
1
+ import { Platform } from 'expo-modules-core';
2
2
 
3
3
  import { getAssetByID } from './AssetRegistry';
4
4
  import * as AssetSources from './AssetSources';
5
5
  import * as AssetUris from './AssetUris';
6
- import { getEmbeddedAssetUri } from './EmbeddedAssets';
7
6
  import * as ImageAssets from './ImageAssets';
7
+ import { getLocalAssetUri } from './LocalAssets';
8
8
  import { downloadAsync, IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';
9
9
  import resolveAssetSource from './resolveAssetSource';
10
10
 
@@ -53,7 +53,7 @@ export class Asset {
53
53
  }
54
54
 
55
55
  if (hash) {
56
- this.localUri = getEmbeddedAssetUri(hash, type);
56
+ this.localUri = getLocalAssetUri(hash, type);
57
57
  if (this.localUri) {
58
58
  this.downloaded = true;
59
59
  }
@@ -71,7 +71,7 @@ export class Asset {
71
71
 
72
72
  static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {
73
73
  const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];
74
- return Promise.all(moduleIds.map(moduleId => Asset.fromModule(moduleId).downloadAsync()));
74
+ return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));
75
75
  }
76
76
 
77
77
  static fromModule(virtualAssetModule: number | string): Asset {
@@ -165,7 +165,7 @@ export class Asset {
165
165
  return this;
166
166
  }
167
167
  if (this.downloading) {
168
- await new Promise((resolve, reject) => {
168
+ await new Promise<void>((resolve, reject) => {
169
169
  this._downloadCallbacks.push({ resolve, reject });
170
170
  });
171
171
  return this;
package/src/AssetHooks.ts CHANGED
@@ -22,9 +22,7 @@ export function useAssets(moduleIds: number | number[]): [Asset[] | undefined, E
22
22
  const [error, setError] = useState<Error>();
23
23
 
24
24
  useEffect(() => {
25
- Asset.loadAsync(moduleIds)
26
- .then(setAssets)
27
- .catch(setError);
25
+ Asset.loadAsync(moduleIds).then(setAssets).catch(setError);
28
26
  }, []);
29
27
 
30
28
  return [assets, error];
@@ -1,4 +1,4 @@
1
- import { Platform, UnavailabilityError } from '@unimodules/core';
1
+ import { Platform, UnavailabilityError } from 'expo-modules-core';
2
2
  import invariant from 'invariant';
3
3
  import { Dimensions } from 'react-native';
4
4
 
@@ -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 {
@@ -1,4 +1,4 @@
1
- import { Platform } from '@unimodules/core';
1
+ import { Platform } from 'expo-modules-core';
2
2
  import path from 'path-browserify';
3
3
  import { PixelRatio } from 'react-native';
4
4
  import URL from 'url-parse';
@@ -42,7 +42,7 @@ export function selectAssetSource(meta: AssetMetadata): AssetSource {
42
42
  // This logic is based on that of AssetSourceResolver, with additional support for file hashes and
43
43
  // explicitly provided URIs
44
44
  const scale = AssetSourceResolver.pickScale(meta.scales, PixelRatio.get());
45
- const index = meta.scales.findIndex(s => s === scale);
45
+ const index = meta.scales.findIndex((s) => s === scale);
46
46
  const hash = meta.fileHashes ? meta.fileHashes[index] || meta.fileHashes[0] : meta.hash;
47
47
 
48
48
  // Allow asset processors to directly provide the URL to load
@@ -0,0 +1,39 @@
1
+ import Constants from 'expo-constants';
2
+ import * as FileSystem from 'expo-file-system';
3
+
4
+ import { getLocalAssets } from './PlatformUtils';
5
+
6
+ // Fast lookup check if assets are available in the local bundle in managed apps
7
+ const bundledAssets = new Set(FileSystem.bundledAssets || []);
8
+
9
+ // localAssets are provided by the expo-updates module
10
+ const localAssets = getLocalAssets();
11
+
12
+ /**
13
+ * Returns the URI of a local asset from its hash, or null if the asset is not available locally
14
+ */
15
+ export function getLocalAssetUri(hash: string, type: string | null): string | null {
16
+ const localAssetsKey = hash;
17
+ const legacyLocalAssetsKey = `${hash}.${type ?? ''}`;
18
+
19
+ switch (true) {
20
+ case localAssetsKey in localAssets: {
21
+ return localAssets[localAssetsKey];
22
+ }
23
+ case legacyLocalAssetsKey in localAssets: {
24
+ // legacy updates store assets with an extension
25
+ return localAssets[legacyLocalAssetsKey];
26
+ }
27
+ case !__DEV__: {
28
+ // check legacy location in case we're in Expo client/managed workflow
29
+ // TODO(eric): remove this once bundledAssets is no longer exported from FileSystem
30
+ const assetName = `asset_${hash}${type ? `.${type}` : ''}`;
31
+ if (Constants.appOwnership !== 'standalone' || !bundledAssets.has(assetName)) {
32
+ return null;
33
+ }
34
+ return `${FileSystem.bundleDirectory}${assetName}`;
35
+ }
36
+ default:
37
+ return null;
38
+ }
39
+ }
@@ -0,0 +1,4 @@
1
+ export function getLocalAssetUri(hash: string, type: string | null): string | null {
2
+ // noop on web
3
+ return null;
4
+ }
@@ -1,7 +1,7 @@
1
- import { NativeModulesProxy } from '@unimodules/core';
2
1
  import computeMd5 from 'blueimp-md5';
3
2
  import Constants from 'expo-constants';
4
3
  import * as FileSystem from 'expo-file-system';
4
+ import { NativeModulesProxy } from 'expo-modules-core';
5
5
 
6
6
  import { getManifestBaseUrl } from './AssetUris';
7
7
 
@@ -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
  }
@@ -1,5 +0,0 @@
1
- /**
2
- * Returns the local URI of an embedded asset from its hash and type, or null if the asset is not
3
- * included in the app bundle.
4
- */
5
- export declare function getEmbeddedAssetUri(hash: string, type: string | null): string | null;
@@ -1,25 +0,0 @@
1
- import Constants from 'expo-constants';
2
- import * as FileSystem from 'expo-file-system';
3
- import { getLocalAssets } from './PlatformUtils';
4
- // Fast lookup check if assets are available in the local bundle in managed apps
5
- const bundledAssets = new Set(FileSystem.bundledAssets || []);
6
- // localAssets are provided by the expo-updates module
7
- const localAssets = getLocalAssets();
8
- /**
9
- * Returns the local URI of an embedded asset from its hash and type, or null if the asset is not
10
- * included in the app bundle.
11
- */
12
- export function getEmbeddedAssetUri(hash, type) {
13
- const localAssetsKey = `${hash}.${type ?? ''}`;
14
- if (!localAssets.hasOwnProperty(localAssetsKey) && !__DEV__) {
15
- // check legacy location in case we're in Expo client/managed workflow
16
- // TODO(eric): remove this once bundledAssets is no longer exported from FileSystem
17
- const assetName = `asset_${hash}${type ? `.${type}` : ''}`;
18
- if (Constants.appOwnership !== 'standalone' || !bundledAssets.has(assetName)) {
19
- return null;
20
- }
21
- return `${FileSystem.bundleDirectory}${assetName}`;
22
- }
23
- return localAssets[localAssetsKey] ?? null;
24
- }
25
- //# sourceMappingURL=EmbeddedAssets.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EmbeddedAssets.js","sourceRoot":"","sources":["../src/EmbeddedAssets.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,gFAAgF;AAChF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;AAE9D,sDAAsD;AACtD,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,IAAmB;IACnE,MAAM,cAAc,GAAG,GAAG,IAAI,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC;IAC/C,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE;QAC3D,sEAAsE;QACtE,mFAAmF;QACnF,MAAM,SAAS,GAAG,SAAS,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAC3D,IAAI,SAAS,CAAC,YAAY,KAAK,YAAY,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;YAC5E,OAAO,IAAI,CAAC;SACb;QACD,OAAO,GAAG,UAAU,CAAC,eAAe,GAAG,SAAS,EAAE,CAAC;KACpD;IACD,OAAO,WAAW,CAAC,cAAc,CAAC,IAAI,IAAI,CAAC;AAC7C,CAAC","sourcesContent":["import Constants from 'expo-constants';\nimport * as FileSystem from 'expo-file-system';\n\nimport { getLocalAssets } from './PlatformUtils';\n\n// Fast lookup check if assets are available in the local bundle in managed apps\nconst bundledAssets = new Set(FileSystem.bundledAssets || []);\n\n// localAssets are provided by the expo-updates module\nconst localAssets = getLocalAssets();\n\n/**\n * Returns the local URI of an embedded asset from its hash and type, or null if the asset is not\n * included in the app bundle.\n */\nexport function getEmbeddedAssetUri(hash: string, type: string | null): string | null {\n const localAssetsKey = `${hash}.${type ?? ''}`;\n if (!localAssets.hasOwnProperty(localAssetsKey) && !__DEV__) {\n // check legacy location in case we're in Expo client/managed workflow\n // TODO(eric): remove this once bundledAssets is no longer exported from FileSystem\n const assetName = `asset_${hash}${type ? `.${type}` : ''}`;\n if (Constants.appOwnership !== 'standalone' || !bundledAssets.has(assetName)) {\n return null;\n }\n return `${FileSystem.bundleDirectory}${assetName}`;\n }\n return localAssets[localAssetsKey] ?? null;\n}\n"]}
@@ -1 +0,0 @@
1
- export declare function getEmbeddedAssetUri(hash: string, type: string | null): string | null;
@@ -1,5 +0,0 @@
1
- export function getEmbeddedAssetUri(hash, type) {
2
- // noop on web
3
- return null;
4
- }
5
- //# sourceMappingURL=EmbeddedAssets.web.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EmbeddedAssets.web.js","sourceRoot":"","sources":["../src/EmbeddedAssets.web.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,IAAmB;IACnE,cAAc;IACd,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["export function getEmbeddedAssetUri(hash: string, type: string | null): string | null {\n // noop on web\n return null;\n}\n"]}
@@ -1,28 +0,0 @@
1
- import Constants from 'expo-constants';
2
- import * as FileSystem from 'expo-file-system';
3
-
4
- import { getLocalAssets } from './PlatformUtils';
5
-
6
- // Fast lookup check if assets are available in the local bundle in managed apps
7
- const bundledAssets = new Set(FileSystem.bundledAssets || []);
8
-
9
- // localAssets are provided by the expo-updates module
10
- const localAssets = getLocalAssets();
11
-
12
- /**
13
- * Returns the local URI of an embedded asset from its hash and type, or null if the asset is not
14
- * included in the app bundle.
15
- */
16
- export function getEmbeddedAssetUri(hash: string, type: string | null): string | null {
17
- const localAssetsKey = `${hash}.${type ?? ''}`;
18
- if (!localAssets.hasOwnProperty(localAssetsKey) && !__DEV__) {
19
- // check legacy location in case we're in Expo client/managed workflow
20
- // TODO(eric): remove this once bundledAssets is no longer exported from FileSystem
21
- const assetName = `asset_${hash}${type ? `.${type}` : ''}`;
22
- if (Constants.appOwnership !== 'standalone' || !bundledAssets.has(assetName)) {
23
- return null;
24
- }
25
- return `${FileSystem.bundleDirectory}${assetName}`;
26
- }
27
- return localAssets[localAssetsKey] ?? null;
28
- }
@@ -1,4 +0,0 @@
1
- export function getEmbeddedAssetUri(hash: string, type: string | null): string | null {
2
- // noop on web
3
- return null;
4
- }