expo-asset 8.3.1 → 8.4.1
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 +20 -0
- package/build/Asset.fx.js +1 -1
- package/build/Asset.fx.js.map +1 -1
- package/build/Asset.js +16 -13
- package/build/Asset.js.map +1 -1
- package/build/AssetHooks.js +1 -3
- package/build/AssetHooks.js.map +1 -1
- package/build/AssetSourceResolver.web.js +6 -1
- package/build/AssetSourceResolver.web.js.map +1 -1
- package/build/AssetSources.js +2 -2
- package/build/AssetSources.js.map +1 -1
- package/build/LocalAssets.d.ts +4 -0
- package/build/LocalAssets.js +35 -0
- package/build/LocalAssets.js.map +1 -0
- package/build/LocalAssets.web.d.ts +1 -0
- package/build/LocalAssets.web.js +5 -0
- package/build/LocalAssets.web.js.map +1 -0
- package/build/PlatformUtils.js +1 -1
- package/build/PlatformUtils.js.map +1 -1
- package/package.json +4 -4
- package/src/Asset.fx.ts +1 -1
- package/src/Asset.ts +5 -5
- package/src/AssetHooks.ts +1 -3
- package/src/AssetSourceResolver.web.ts +1 -1
- package/src/AssetSources.ts +2 -2
- package/src/LocalAssets.ts +39 -0
- package/src/LocalAssets.web.ts +4 -0
- package/src/PlatformUtils.ts +1 -1
- package/build/EmbeddedAssets.d.ts +0 -5
- package/build/EmbeddedAssets.js +0 -25
- package/build/EmbeddedAssets.js.map +0 -1
- package/build/EmbeddedAssets.web.d.ts +0 -1
- package/build/EmbeddedAssets.web.js +0 -5
- package/build/EmbeddedAssets.web.js.map +0 -1
- package/src/EmbeddedAssets.ts +0 -28
- package/src/EmbeddedAssets.web.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,26 @@
|
|
|
8
8
|
|
|
9
9
|
### 🐛 Bug fixes
|
|
10
10
|
|
|
11
|
+
### 💡 Others
|
|
12
|
+
|
|
13
|
+
## 8.4.1 — 2021-10-01
|
|
14
|
+
|
|
15
|
+
### 💡 Others
|
|
16
|
+
|
|
17
|
+
- Updated `@testing-library/react-hooks` to version `7.0.1`. ([#14552](https://github.com/expo/expo/pull/14552)) by [@Simek](https://github.com/Simek))
|
|
18
|
+
|
|
19
|
+
## 8.4.0 — 2021-09-08
|
|
20
|
+
|
|
21
|
+
### 🎉 New features
|
|
22
|
+
|
|
23
|
+
- Reapply [#12624](https://github.com/expo/expo/pull/12624) ([#13789](https://github.com/expo/expo/pull/13789) by [@jkhales](https://github.com/jkhales))
|
|
24
|
+
|
|
25
|
+
## 8.3.2 — 2021-04-21
|
|
26
|
+
|
|
27
|
+
### 🎉 New features
|
|
28
|
+
|
|
29
|
+
- Find local assets without extensions. ([#12624](https://github.com/expo/expo/pull/12624) by [@jkhales](https://github.com/jkhales))
|
|
30
|
+
|
|
11
31
|
## 8.3.1 — 2021-03-23
|
|
12
32
|
|
|
13
33
|
### 🐛 Bug fixes
|
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) {
|
package/build/Asset.fx.js.map
CHANGED
|
@@ -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,
|
|
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 '
|
|
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 =
|
|
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
|
package/build/Asset.js.map
CHANGED
|
@@ -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,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAkBtD,MAAM,OAAO,KAAK;IAehB,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAmB;QAT5E,SAAI,GAAkB,IAAI,CAAC;QAE3B,aAAQ,GAAkB,IAAI,CAAC;QAC/B,UAAK,GAAkB,IAAI,CAAC;QAC5B,WAAM,GAAkB,IAAI,C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AAI,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;AACj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I,CAAC,EAAE;oBACtC,MAAM,EAAE,KAAK,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","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"]}
|
package/build/AssetHooks.js
CHANGED
|
@@ -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
|
}
|
package/build/AssetHooks.js.map
CHANGED
|
@@ -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
|
|
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 '
|
|
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 }) {
|
|
@@ -17,6 +17,11 @@ function getScaledAssetPath(asset) {
|
|
|
17
17
|
return assetDir + '/' + asset.name + scaleSuffix + '.' + 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;
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"AssetSourceResolver.web.js","sourceRoot":"","sources":["../src/AssetSourceResolver.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAClE,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,C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I,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,CAAC;IACD,8BAA8B;QAC5B,MAAM,IAAI,mBAAmB,CAAC,cAAc,EAAE,kCAAkC,CAAC,CAAC;IACpF,CAAC;IACD,sBAAsB;QACpB,MAAM,IAAI,mBAAmB,CAAC,cAAc,EAAE,0BAA0B,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 '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"]}
|
package/build/AssetSources.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Platform } from '
|
|
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,
|
|
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,OAA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AC;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 } 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,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 @@
|
|
|
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"]}
|
package/build/PlatformUtils.js
CHANGED
|
@@ -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,
|
|
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,MAAM,CAAC,MAAM,wBAAwB,GACnC,CAAC,cAAc;IACf,CAAC,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS;IAC3C,kGAAkG;IAClG,sCAAsC;IACtC,CAAC,kBAAkB,CAAC,WAAW,EAAE,qBAAqB,CAAC;AAEzD,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,IAAI,wBAAwB,CAAC;AAEtF,4EAA4E;AAC5E,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,cAAc,IAAI,CAAC,wBAAwB,CAAC;AAExF,gFAAgF;AAChF,iEAAiE;AACjE,MAAM,UAAU,cAAc;IAC5B,OAAO,kBAAkB,CAAC,WAAW,EAAE,WAAW,IAAI,EAAE,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,SAAS,CAAC,sBAAsB,IAAI,EAAE,CAAC;AAChD,CAAC;AAED,yCAAyC;AACzC,MAAM,CAA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AClB,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-asset",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.1",
|
|
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.
|
|
35
|
+
"homepage": "https://docs.expo.dev/versions/latest/sdk/asset/",
|
|
36
36
|
"jest": {
|
|
37
37
|
"preset": "expo-module-scripts/ios"
|
|
38
38
|
},
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"url-parse": "^1.4.4"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@testing-library/react-hooks": "^
|
|
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": "
|
|
51
|
+
"gitHead": "2718b696f4a6919905b0f47ebb24ff65b42d8ff9"
|
|
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 '
|
|
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 =
|
|
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];
|
package/src/AssetSources.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Platform } from '
|
|
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
|
+
}
|
package/src/PlatformUtils.ts
CHANGED
|
@@ -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
|
|
package/build/EmbeddedAssets.js
DELETED
|
@@ -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 +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"]}
|
package/src/EmbeddedAssets.ts
DELETED
|
@@ -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
|
-
}
|