@expo/cli 1.0.0-canary-20250131-5c4e588 → 1.0.0-canary-20250219-4a5dade
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/build/bin/cli +1 -1
- package/build/src/api/getNativeModuleVersions.js +1 -1
- package/build/src/api/getNativeModuleVersions.js.map +1 -1
- package/build/src/api/graphql/types/App.js +1 -0
- package/build/src/api/graphql/types/App.js.map +1 -1
- package/build/src/api/rest/cache/FileSystemResponseCache.js +129 -50
- package/build/src/api/rest/cache/FileSystemResponseCache.js.map +1 -1
- package/build/src/graphql/generated.js +494 -23
- package/build/src/graphql/generated.js.map +1 -1
- package/build/src/prebuild/configureProjectAsync.js +2 -2
- package/build/src/prebuild/configureProjectAsync.js.map +1 -1
- package/build/src/prebuild/ensureConfigAsync.js +2 -2
- package/build/src/prebuild/ensureConfigAsync.js.map +1 -1
- package/build/src/start/resolveOptions.js +5 -0
- package/build/src/start/resolveOptions.js.map +1 -1
- package/build/src/start/server/AsyncWsTunnel.js +159 -0
- package/build/src/start/server/AsyncWsTunnel.js.map +1 -0
- package/build/src/start/server/BundlerDevServer.js +17 -10
- package/build/src/start/server/BundlerDevServer.js.map +1 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js +1 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
- package/build/src/start/server/middleware/DomComponentsMiddleware.js +1 -1
- package/build/src/start/server/middleware/DomComponentsMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/metroOptions.js +1 -1
- package/build/src/start/server/middleware/metroOptions.js.map +1 -1
- package/build/src/utils/env.js +30 -5
- package/build/src/utils/env.js.map +1 -1
- package/build/src/utils/getOrPromptApplicationId.js +53 -20
- package/build/src/utils/getOrPromptApplicationId.js.map +1 -1
- package/build/src/utils/telemetry/clients/FetchClient.js +1 -1
- package/build/src/utils/telemetry/utils/context.js +1 -1
- package/package.json +16 -16
- package/build/src/utils/getAccountUsername.js +0 -22
- package/build/src/utils/getAccountUsername.js.map +0 -1
package/build/bin/cli
CHANGED
|
@@ -121,7 +121,7 @@ const args = (0, _arg().default)({
|
|
|
121
121
|
});
|
|
122
122
|
if (args["--version"]) {
|
|
123
123
|
// Version is added in the build script.
|
|
124
|
-
console.log("1.0.0-canary-
|
|
124
|
+
console.log("1.0.0-canary-20250219-4a5dade");
|
|
125
125
|
process.exit(0);
|
|
126
126
|
}
|
|
127
127
|
if (args["--non-interactive"]) {
|
|
@@ -12,7 +12,7 @@ async function getNativeModuleVersionsAsync(sdkVersion) {
|
|
|
12
12
|
const fetchAsync = (0, _client.createCachedFetch)({
|
|
13
13
|
cacheDirectory: "native-modules-cache",
|
|
14
14
|
// 1 minute cache
|
|
15
|
-
ttl: 1000 * 60
|
|
15
|
+
ttl: 1000 * 60
|
|
16
16
|
});
|
|
17
17
|
const response = await fetchAsync(`sdks/${sdkVersion}/native-modules`);
|
|
18
18
|
if (!response.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/getNativeModuleVersions.ts"],"sourcesContent":["import { createCachedFetch, getResponseDataOrThrow } from './rest/client';\nimport { CommandError } from '../utils/errors';\n\ninterface NativeModule {\n npmPackage: string;\n versionRange: string;\n}\ntype BundledNativeModuleList = NativeModule[];\n\nexport type BundledNativeModules = Record<string, string>;\n\n/**\n * The endpoint returns the list of bundled native modules for a given SDK version.\n * The data is populated by the `et sync-bundled-native-modules` script from expo/expo repo.\n * See the code for more details:\n * https://github.com/expo/expo/blob/main/tools/src/commands/SyncBundledNativeModules.ts\n *\n * Example result:\n * [\n * {\n * id: \"79285187-e5c4-47f7-b6a9-664f5d16f0db\",\n * sdkVersion: \"41.0.0\",\n * npmPackage: \"expo-camera\",\n * versionRange: \"~10.1.0\",\n * createdAt: \"2021-04-29T09:34:32.825Z\",\n * updatedAt: \"2021-04-29T09:34:32.825Z\"\n * },\n * ...\n * ]\n */\nexport async function getNativeModuleVersionsAsync(\n sdkVersion: string\n): Promise<BundledNativeModules> {\n const fetchAsync = createCachedFetch({\n cacheDirectory: 'native-modules-cache',\n // 1 minute cache\n ttl: 1000 * 60
|
|
1
|
+
{"version":3,"sources":["../../../src/api/getNativeModuleVersions.ts"],"sourcesContent":["import { createCachedFetch, getResponseDataOrThrow } from './rest/client';\nimport { CommandError } from '../utils/errors';\n\ninterface NativeModule {\n npmPackage: string;\n versionRange: string;\n}\ntype BundledNativeModuleList = NativeModule[];\n\nexport type BundledNativeModules = Record<string, string>;\n\n/**\n * The endpoint returns the list of bundled native modules for a given SDK version.\n * The data is populated by the `et sync-bundled-native-modules` script from expo/expo repo.\n * See the code for more details:\n * https://github.com/expo/expo/blob/main/tools/src/commands/SyncBundledNativeModules.ts\n *\n * Example result:\n * [\n * {\n * id: \"79285187-e5c4-47f7-b6a9-664f5d16f0db\",\n * sdkVersion: \"41.0.0\",\n * npmPackage: \"expo-camera\",\n * versionRange: \"~10.1.0\",\n * createdAt: \"2021-04-29T09:34:32.825Z\",\n * updatedAt: \"2021-04-29T09:34:32.825Z\"\n * },\n * ...\n * ]\n */\nexport async function getNativeModuleVersionsAsync(\n sdkVersion: string\n): Promise<BundledNativeModules> {\n const fetchAsync = createCachedFetch({\n cacheDirectory: 'native-modules-cache',\n // 1 minute cache\n ttl: 1000 * 60,\n });\n const response = await fetchAsync(`sdks/${sdkVersion}/native-modules`);\n if (!response.ok) {\n throw new CommandError(\n 'API',\n `Unexpected response when fetching version info from Expo servers: ${response.statusText}.`\n );\n }\n\n const json = await response.json();\n const data = getResponseDataOrThrow<BundledNativeModuleList>(json);\n if (!data.length) {\n throw new CommandError('VERSIONS', 'The bundled native module list from the Expo API is empty');\n }\n return fromBundledNativeModuleList(data);\n}\n\nfunction fromBundledNativeModuleList(list: BundledNativeModuleList): BundledNativeModules {\n return list.reduce((acc, i) => {\n acc[i.npmPackage] = i.versionRange;\n return acc;\n }, {} as BundledNativeModules);\n}\n"],"names":["getNativeModuleVersionsAsync","sdkVersion","fetchAsync","createCachedFetch","cacheDirectory","ttl","response","ok","CommandError","statusText","json","data","getResponseDataOrThrow","length","fromBundledNativeModuleList","list","reduce","acc","i","npmPackage","versionRange"],"mappings":"AAAA;;;;+BA8BsBA,8BAA4B;;aAA5BA,4BAA4B;;wBA9BQ,eAAe;wBAC5C,iBAAiB;AA6BvC,eAAeA,4BAA4B,CAChDC,UAAkB,EACa;IAC/B,MAAMC,UAAU,GAAGC,IAAAA,OAAiB,kBAAA,EAAC;QACnCC,cAAc,EAAE,sBAAsB;QACtC,iBAAiB;QACjBC,GAAG,EAAE,IAAI,GAAG,EAAE;KACf,CAAC,AAAC;IACH,MAAMC,QAAQ,GAAG,MAAMJ,UAAU,CAAC,CAAC,KAAK,EAAED,UAAU,CAAC,eAAe,CAAC,CAAC,AAAC;IACvE,IAAI,CAACK,QAAQ,CAACC,EAAE,EAAE;QAChB,MAAM,IAAIC,OAAY,aAAA,CACpB,KAAK,EACL,CAAC,kEAAkE,EAAEF,QAAQ,CAACG,UAAU,CAAC,CAAC,CAAC,CAC5F,CAAC;IACJ,CAAC;IAED,MAAMC,IAAI,GAAG,MAAMJ,QAAQ,CAACI,IAAI,EAAE,AAAC;IACnC,MAAMC,IAAI,GAAGC,IAAAA,OAAsB,uBAAA,EAA0BF,IAAI,CAAC,AAAC;IACnE,IAAI,CAACC,IAAI,CAACE,MAAM,EAAE;QAChB,MAAM,IAAIL,OAAY,aAAA,CAAC,UAAU,EAAE,2DAA2D,CAAC,CAAC;IAClG,CAAC;IACD,OAAOM,2BAA2B,CAACH,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED,SAASG,2BAA2B,CAACC,IAA6B,EAAwB;IACxF,OAAOA,IAAI,CAACC,MAAM,CAAC,CAACC,GAAG,EAAEC,CAAC,GAAK;QAC7BD,GAAG,CAACC,CAAC,CAACC,UAAU,CAAC,GAAGD,CAAC,CAACE,YAAY,CAAC;QACnC,OAAOH,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAyB,CAAC;AACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/api/graphql/types/App.ts"],"sourcesContent":["import { TypedDocumentNode, gql } from '@urql/core';\n\nexport const AppFragmentNode: TypedDocumentNode = gql`\n fragment AppFragment on App {\n id\n scopeKey\n ownerAccount {\n id\n }\n }\n`;\n"],"names":["AppFragmentNode","gql"],"mappings":"AAAA;;;;+BAEaA,iBAAe;;aAAfA,eAAe;;;yBAFW,YAAY;;;;;;AAE5C,MAAMA,eAAe,GAAsBC,IAAAA,KAAG,EAAA,IAAA,CAAA,CAAC
|
|
1
|
+
{"version":3,"sources":["../../../../../src/api/graphql/types/App.ts"],"sourcesContent":["import { TypedDocumentNode, gql } from '@urql/core';\n\nexport const AppFragmentNode: TypedDocumentNode = gql`\n fragment AppFragment on App {\n id\n scopeKey\n ownerAccount {\n id\n name\n }\n }\n`;\n"],"names":["AppFragmentNode","gql"],"mappings":"AAAA;;;;+BAEaA,iBAAe;;aAAfA,eAAe;;;yBAFW,YAAY;;;;;;AAE5C,MAAMA,eAAe,GAAsBC,IAAAA,KAAG,EAAA,IAAA,CAAA,CAAC;;;;;;;;;AAStD,CAAC,AAAC"}
|
|
@@ -6,58 +6,130 @@ Object.defineProperty(exports, "FileSystemResponseCache", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>FileSystemResponseCache
|
|
8
8
|
});
|
|
9
|
-
function
|
|
10
|
-
const data = /*#__PURE__*/ _interopRequireDefault(require("
|
|
11
|
-
|
|
9
|
+
function _nodeCrypto() {
|
|
10
|
+
const data = /*#__PURE__*/ _interopRequireDefault(require("node:crypto"));
|
|
11
|
+
_nodeCrypto = function() {
|
|
12
12
|
return data;
|
|
13
13
|
};
|
|
14
14
|
return data;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
const data = require("
|
|
18
|
-
|
|
16
|
+
function _nodeFs() {
|
|
17
|
+
const data = /*#__PURE__*/ _interopRequireDefault(require("node:fs"));
|
|
18
|
+
_nodeFs = function() {
|
|
19
19
|
return data;
|
|
20
20
|
};
|
|
21
21
|
return data;
|
|
22
22
|
}
|
|
23
|
+
function _nodePath() {
|
|
24
|
+
const data = /*#__PURE__*/ _interopRequireDefault(require("node:path"));
|
|
25
|
+
_nodePath = function() {
|
|
26
|
+
return data;
|
|
27
|
+
};
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
function _nodeStream() {
|
|
31
|
+
const data = /*#__PURE__*/ _interopRequireWildcard(require("node:stream"));
|
|
32
|
+
_nodeStream = function() {
|
|
33
|
+
return data;
|
|
34
|
+
};
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
const _dir = require("../../../utils/dir");
|
|
23
38
|
function _interopRequireDefault(obj) {
|
|
24
39
|
return obj && obj.__esModule ? obj : {
|
|
25
40
|
default: obj
|
|
26
41
|
};
|
|
27
42
|
}
|
|
43
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
44
|
+
if (typeof WeakMap !== "function") return null;
|
|
45
|
+
var cacheBabelInterop = new WeakMap();
|
|
46
|
+
var cacheNodeInterop = new WeakMap();
|
|
47
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
48
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
49
|
+
})(nodeInterop);
|
|
50
|
+
}
|
|
51
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
52
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
53
|
+
return obj;
|
|
54
|
+
}
|
|
55
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
56
|
+
return {
|
|
57
|
+
default: obj
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
61
|
+
if (cache && cache.has(obj)) {
|
|
62
|
+
return cache.get(obj);
|
|
63
|
+
}
|
|
64
|
+
var newObj = {};
|
|
65
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
66
|
+
for(var key in obj){
|
|
67
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
68
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
69
|
+
if (desc && (desc.get || desc.set)) {
|
|
70
|
+
Object.defineProperty(newObj, key, desc);
|
|
71
|
+
} else {
|
|
72
|
+
newObj[key] = obj[key];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
newObj.default = obj;
|
|
77
|
+
if (cache) {
|
|
78
|
+
cache.set(obj, newObj);
|
|
79
|
+
}
|
|
80
|
+
return newObj;
|
|
81
|
+
}
|
|
28
82
|
class FileSystemResponseCache {
|
|
29
83
|
constructor(options){
|
|
30
84
|
this.cacheDirectory = options.cacheDirectory;
|
|
31
85
|
this.timeToLive = options.ttl;
|
|
32
86
|
}
|
|
87
|
+
getFilePaths(cacheKey) {
|
|
88
|
+
// Create a hash of the cache key to use as filename
|
|
89
|
+
const hash = _nodeCrypto().default.createHash("sha256").update(cacheKey).digest("hex");
|
|
90
|
+
return {
|
|
91
|
+
info: _nodePath().default.join(this.cacheDirectory, `${hash}-info.json`),
|
|
92
|
+
body: _nodePath().default.join(this.cacheDirectory, `${hash}-body.bin`)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
33
95
|
/** Retrieve the cache response, if any */ async get(cacheKey) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
// Abort if the response info is not found
|
|
37
|
-
if (!responseInfoMeta) {
|
|
96
|
+
const paths = this.getFilePaths(cacheKey);
|
|
97
|
+
if (!await (0, _dir.fileExistsAsync)(paths.info)) {
|
|
38
98
|
return undefined;
|
|
39
99
|
}
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
100
|
+
// Read and parse the info file
|
|
101
|
+
const infoBuffer = await _nodeFs().default.promises.readFile(paths.info);
|
|
102
|
+
try {
|
|
103
|
+
const responseInfo = JSON.parse(infoBuffer.toString());
|
|
104
|
+
// Check if the response has expired
|
|
105
|
+
if (responseInfo.expiration && responseInfo.expiration < Date.now()) {
|
|
106
|
+
await this.remove(cacheKey);
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
// Remove cache-specific data from the response info
|
|
110
|
+
const { empty , expiration , bodyPath , ...cleanInfo } = responseInfo;
|
|
111
|
+
// Create response body stream
|
|
112
|
+
let responseBody;
|
|
113
|
+
if (empty) {
|
|
114
|
+
responseBody = _nodeStream().Readable.toWeb(_nodeStream().Readable.from(Buffer.alloc(0)));
|
|
115
|
+
} else {
|
|
116
|
+
const bodyBuffer = await _nodeFs().default.promises.readFile(paths.body);
|
|
117
|
+
responseBody = _nodeStream().Readable.toWeb(_nodeStream().Readable.from(bodyBuffer));
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
body: responseBody,
|
|
121
|
+
info: cleanInfo
|
|
122
|
+
};
|
|
123
|
+
} catch {
|
|
124
|
+
// If file doesn't exist or other errors, return undefined
|
|
49
125
|
return undefined;
|
|
50
126
|
}
|
|
51
|
-
// Create a read-stream for the response body
|
|
52
|
-
const responseBody = empty ? _stream().Readable.from(Buffer.alloc(0)) : _stream().Readable.from(_cacache().default.get.stream.byDigest(this.cacheDirectory, bodyIntegrity));
|
|
53
|
-
return {
|
|
54
|
-
body: _stream().Readable.toWeb(responseBody),
|
|
55
|
-
info: responseInfo
|
|
56
|
-
};
|
|
57
127
|
}
|
|
58
128
|
/** Store the response for caching */ async set(cacheKey, response) {
|
|
59
|
-
|
|
60
|
-
|
|
129
|
+
await _nodeFs().default.promises.mkdir(this.cacheDirectory, {
|
|
130
|
+
recursive: true
|
|
131
|
+
});
|
|
132
|
+
const paths = this.getFilePaths(cacheKey);
|
|
61
133
|
// Create a copy of the response info, to add cache-specific data
|
|
62
134
|
const responseInfo = {
|
|
63
135
|
...response.info
|
|
@@ -67,35 +139,42 @@ class FileSystemResponseCache {
|
|
|
67
139
|
responseInfo.expiration = Date.now() + this.timeToLive;
|
|
68
140
|
}
|
|
69
141
|
try {
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
142
|
+
// Clone the response body stream since we need to read it twice
|
|
143
|
+
const [forSize, forWrite] = response.body.tee();
|
|
144
|
+
// Check if the body is empty by reading the first stream
|
|
145
|
+
const reader = forSize.getReader();
|
|
146
|
+
const { value } = await reader.read();
|
|
147
|
+
reader.releaseLock();
|
|
148
|
+
if (!value || value.length === 0) {
|
|
149
|
+
responseInfo.empty = true;
|
|
150
|
+
} else {
|
|
151
|
+
// Create write stream and pipe response body to file
|
|
152
|
+
const writeStream = _nodeFs().default.createWriteStream(paths.body);
|
|
153
|
+
const nodeStream = _nodeStream().Readable.fromWeb(forWrite);
|
|
154
|
+
nodeStream.pipe(writeStream);
|
|
155
|
+
// Wait for the stream to finish
|
|
156
|
+
await _nodeStream().default.promises.finished(writeStream);
|
|
157
|
+
responseInfo.bodyPath = paths.body;
|
|
77
158
|
}
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
159
|
+
// Write info to file
|
|
160
|
+
await _nodeFs().default.promises.writeFile(paths.info, JSON.stringify(responseInfo));
|
|
161
|
+
return await this.get(cacheKey);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
// Clean up any partially written files
|
|
164
|
+
await this.remove(cacheKey);
|
|
165
|
+
throw error;
|
|
81
166
|
}
|
|
82
|
-
// Store the response info
|
|
83
|
-
const responseInfoBuffer = Buffer.from(JSON.stringify(responseInfo));
|
|
84
|
-
await _cacache().default.put(this.cacheDirectory, responseInfoKey, responseInfoBuffer);
|
|
85
|
-
return await this.get(cacheKey);
|
|
86
167
|
}
|
|
87
168
|
/** Remove the response from caching */ async remove(cacheKey) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
_cacache().default.rm.entry(this.cacheDirectory, getResponseBodyKey(cacheKey)),
|
|
91
|
-
]);
|
|
169
|
+
const paths = this.getFilePaths(cacheKey);
|
|
170
|
+
await removeAllAsync(paths.info, paths.body);
|
|
92
171
|
}
|
|
93
172
|
}
|
|
94
|
-
function
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
173
|
+
function removeAllAsync(...paths) {
|
|
174
|
+
return Promise.all(paths.map((path)=>_nodeFs().default.promises.rm(path, {
|
|
175
|
+
recursive: true,
|
|
176
|
+
force: true
|
|
177
|
+
}).catch(()=>{})));
|
|
99
178
|
}
|
|
100
179
|
|
|
101
180
|
//# sourceMappingURL=FileSystemResponseCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/api/rest/cache/FileSystemResponseCache.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../../src/api/rest/cache/FileSystemResponseCache.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport stream, { Readable } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\n\nimport type { ResponseCache, ResponseCacheEntry } from './ResponseCache';\nimport { fileExistsAsync } from '../../../utils/dir';\n\ntype FileSystemResponseCacheInfo = ResponseCacheEntry['info'] & {\n /** The path to the cached body file */\n bodyPath?: string;\n /** If there is no response body */\n empty?: boolean;\n /** The expiration time, in milliseconds, when the response should be invalidated */\n expiration?: number;\n};\n\nexport class FileSystemResponseCache implements ResponseCache {\n /** The absolute path to the directory used to store responses */\n private cacheDirectory: string;\n /** Optional auto-expiration for all stored responses */\n private timeToLive?: number;\n\n constructor(options: { cacheDirectory: string; ttl?: number }) {\n this.cacheDirectory = options.cacheDirectory;\n this.timeToLive = options.ttl;\n }\n\n private getFilePaths(cacheKey: string) {\n // Create a hash of the cache key to use as filename\n const hash = crypto.createHash('sha256').update(cacheKey).digest('hex');\n return {\n info: path.join(this.cacheDirectory, `${hash}-info.json`),\n body: path.join(this.cacheDirectory, `${hash}-body.bin`),\n };\n }\n\n /** Retrieve the cache response, if any */\n async get(cacheKey: string): Promise<ResponseCacheEntry | undefined> {\n const paths = this.getFilePaths(cacheKey);\n\n if (!(await fileExistsAsync(paths.info))) {\n return undefined;\n }\n\n // Read and parse the info file\n const infoBuffer = await fs.promises.readFile(paths.info);\n\n try {\n const responseInfo: FileSystemResponseCacheInfo = JSON.parse(infoBuffer.toString());\n\n // Check if the response has expired\n if (responseInfo.expiration && responseInfo.expiration < Date.now()) {\n await this.remove(cacheKey);\n return undefined;\n }\n\n // Remove cache-specific data from the response info\n const { empty, expiration, bodyPath, ...cleanInfo } = responseInfo;\n\n // Create response body stream\n let responseBody: ReadableStream;\n if (empty) {\n responseBody = Readable.toWeb(Readable.from(Buffer.alloc(0)));\n } else {\n const bodyBuffer = await fs.promises.readFile(paths.body);\n responseBody = Readable.toWeb(Readable.from(bodyBuffer));\n }\n\n return {\n body: responseBody,\n info: cleanInfo,\n };\n } catch {\n // If file doesn't exist or other errors, return undefined\n return undefined;\n }\n }\n\n /** Store the response for caching */\n async set(\n cacheKey: string,\n response: ResponseCacheEntry\n ): Promise<ResponseCacheEntry | undefined> {\n await fs.promises.mkdir(this.cacheDirectory, { recursive: true });\n const paths = this.getFilePaths(cacheKey);\n\n // Create a copy of the response info, to add cache-specific data\n const responseInfo: FileSystemResponseCacheInfo = { ...response.info };\n\n // Add expiration time if the \"time to live\" is set\n if (typeof this.timeToLive === 'number') {\n responseInfo.expiration = Date.now() + this.timeToLive;\n }\n\n try {\n // Clone the response body stream since we need to read it twice\n const [forSize, forWrite] = response.body.tee();\n\n // Check if the body is empty by reading the first stream\n const reader = forSize.getReader();\n const { value } = await reader.read();\n reader.releaseLock();\n\n if (!value || value.length === 0) {\n responseInfo.empty = true;\n } else {\n // Create write stream and pipe response body to file\n const writeStream = fs.createWriteStream(paths.body);\n const nodeStream = Readable.fromWeb(forWrite);\n nodeStream.pipe(writeStream);\n\n // Wait for the stream to finish\n await stream.promises.finished(writeStream);\n\n responseInfo.bodyPath = paths.body;\n }\n\n // Write info to file\n await fs.promises.writeFile(paths.info, JSON.stringify(responseInfo));\n\n return await this.get(cacheKey);\n } catch (error) {\n // Clean up any partially written files\n await this.remove(cacheKey);\n throw error;\n }\n }\n\n /** Remove the response from caching */\n async remove(cacheKey: string): Promise<void> {\n const paths = this.getFilePaths(cacheKey);\n await removeAllAsync(paths.info, paths.body);\n }\n}\n\nfunction removeAllAsync(...paths: string[]) {\n return Promise.all(\n paths.map((path) => fs.promises.rm(path, { recursive: true, force: true }).catch(() => {}))\n );\n}\n"],"names":["FileSystemResponseCache","constructor","options","cacheDirectory","timeToLive","ttl","getFilePaths","cacheKey","hash","crypto","createHash","update","digest","info","path","join","body","get","paths","fileExistsAsync","undefined","infoBuffer","fs","promises","readFile","responseInfo","JSON","parse","toString","expiration","Date","now","remove","empty","bodyPath","cleanInfo","responseBody","Readable","toWeb","from","Buffer","alloc","bodyBuffer","set","response","mkdir","recursive","forSize","forWrite","tee","reader","getReader","value","read","releaseLock","length","writeStream","createWriteStream","nodeStream","fromWeb","pipe","stream","finished","writeFile","stringify","error","removeAllAsync","Promise","all","map","rm","force","catch"],"mappings":"AAAA;;;;+BAkBaA,yBAAuB;;aAAvBA,uBAAuB;;;8DAlBjB,aAAa;;;;;;;8DACjB,SAAS;;;;;;;8DACP,WAAW;;;;;;;+DACK,aAAa;;;;;;qBAId,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAW7C,MAAMA,uBAAuB;IAMlCC,YAAYC,OAAiD,CAAE;QAC7D,IAAI,CAACC,cAAc,GAAGD,OAAO,CAACC,cAAc,CAAC;QAC7C,IAAI,CAACC,UAAU,GAAGF,OAAO,CAACG,GAAG,CAAC;IAChC;IAEQC,YAAY,CAACC,QAAgB,EAAE;QACrC,oDAAoD;QACpD,MAAMC,IAAI,GAAGC,WAAM,EAAA,QAAA,CAAC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