@vite-hub/queue 0.0.0 → 0.0.2
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/README.md +89 -1
- package/dist/_app-D29AwUdD.d.ts +11 -0
- package/dist/app-BZpq2cwC.js +10 -0
- package/dist/client-CBDT9GL9.js +93 -0
- package/dist/cloudflare-GosJefIK.js +26 -0
- package/dist/cloudflare-client-w5vphoNn.js +99 -0
- package/dist/cloudflare-resource-name-R8zYQiZb.js +34 -0
- package/dist/cloudflare-vite-BNBVtEwG.js +92 -0
- package/dist/cloudflare-vite-krY8T3zM.d.ts +24 -0
- package/dist/config-B7xkD1v0.js +47 -0
- package/dist/delivery-error-glgYWC9g.js +45 -0
- package/dist/errors-CjuG_qr-.js +108 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +28 -0
- package/dist/internal/runtime/cloudflare-client.d.ts +6 -0
- package/dist/internal/runtime/cloudflare-client.js +2 -0
- package/dist/internal/runtime/vercel-client.d.ts +6 -0
- package/dist/internal/runtime/vercel-client.js +114 -0
- package/dist/nuxt.d.ts +19 -0
- package/dist/nuxt.js +29 -0
- package/dist/runtime/cloudflare-vite.d.ts +2 -0
- package/dist/runtime/cloudflare-vite.js +2 -0
- package/dist/runtime/hosted.d.ts +11 -0
- package/dist/runtime/hosted.js +53 -0
- package/dist/runtime/state.d.ts +16 -0
- package/dist/runtime/state.js +2 -0
- package/dist/runtime/vercel-vite.d.ts +20 -0
- package/dist/runtime/vercel-vite.js +49 -0
- package/dist/state-BfUFGeC2.js +105 -0
- package/dist/types-CwvoMATy.d.ts +169 -0
- package/dist/vercel-C_4vqxcl.js +8 -0
- package/dist/vercel-runtime-package-copy-B8AEFWXT.js +66 -0
- package/dist/virtual.d.ts +4 -0
- package/dist/vite-C6yK76Sw.js +1823 -0
- package/dist/vite.d.ts +129 -0
- package/dist/vite.js +2 -0
- package/package.json +73 -5
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
//#region ../internal/src/runtime/cloudflare-env.ts
|
|
3
|
+
let activeEnv;
|
|
4
|
+
const activeEnvStorage = new AsyncLocalStorage();
|
|
5
|
+
function setActiveCloudflareEnv(env) {
|
|
6
|
+
activeEnv = env;
|
|
7
|
+
globalThis.__env__ = env;
|
|
8
|
+
try {
|
|
9
|
+
activeEnvStorage.enterWith({ env });
|
|
10
|
+
} catch {}
|
|
11
|
+
}
|
|
12
|
+
function runWithActiveCloudflareEnv(env, callback) {
|
|
13
|
+
return activeEnvStorage.run({ env }, callback);
|
|
14
|
+
}
|
|
15
|
+
function getActiveCloudflareEnv() {
|
|
16
|
+
const scoped = activeEnvStorage.getStore();
|
|
17
|
+
return scoped ? scoped.env : activeEnv ?? globalThis.__env__;
|
|
18
|
+
}
|
|
19
|
+
function getCloudflareEnv(event) {
|
|
20
|
+
const target = event;
|
|
21
|
+
return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
|
|
22
|
+
}
|
|
23
|
+
function resolveWaitUntil(event) {
|
|
24
|
+
const target = event;
|
|
25
|
+
const owners = [
|
|
26
|
+
target,
|
|
27
|
+
target?.context,
|
|
28
|
+
target?.context?.cloudflare,
|
|
29
|
+
target?.context?.cloudflare?.context,
|
|
30
|
+
target?.context?._platform?.cloudflare,
|
|
31
|
+
target?.context?._platform?.cloudflare?.context,
|
|
32
|
+
target?.req,
|
|
33
|
+
target?.req?.runtime?.cloudflare,
|
|
34
|
+
target?.req?.runtime?.cloudflare?.context
|
|
35
|
+
];
|
|
36
|
+
for (const owner of owners) if (typeof owner?.waitUntil === "function") return owner.waitUntil.bind(owner);
|
|
37
|
+
}
|
|
38
|
+
function createCloudflareRuntimeEvent(env, context) {
|
|
39
|
+
const waitUntil = typeof context?.waitUntil === "function" ? context.waitUntil.bind(context) : void 0;
|
|
40
|
+
return {
|
|
41
|
+
context: {
|
|
42
|
+
cloudflare: {
|
|
43
|
+
env,
|
|
44
|
+
context
|
|
45
|
+
},
|
|
46
|
+
waitUntil
|
|
47
|
+
},
|
|
48
|
+
env,
|
|
49
|
+
waitUntil
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/runtime/state.ts
|
|
54
|
+
let runtimeConfig;
|
|
55
|
+
let runtimeClientFactory;
|
|
56
|
+
let registryOverride;
|
|
57
|
+
const queueEventStorage = new AsyncLocalStorage();
|
|
58
|
+
let queueEventDefaults;
|
|
59
|
+
const queueClientCache = /* @__PURE__ */ new Map();
|
|
60
|
+
function setQueueRuntimeConfig(config, createClient) {
|
|
61
|
+
runtimeConfig = config;
|
|
62
|
+
runtimeClientFactory = createClient;
|
|
63
|
+
if (typeof config === "undefined") queueEventDefaults = void 0;
|
|
64
|
+
queueClientCache.clear();
|
|
65
|
+
}
|
|
66
|
+
function getQueueRuntimeConfig() {
|
|
67
|
+
return runtimeConfig;
|
|
68
|
+
}
|
|
69
|
+
function getQueueRuntimeClientFactory() {
|
|
70
|
+
return runtimeClientFactory;
|
|
71
|
+
}
|
|
72
|
+
function runWithQueueRuntimeEvent(event, callback) {
|
|
73
|
+
return queueEventStorage.run(event, callback);
|
|
74
|
+
}
|
|
75
|
+
function enterQueueRuntimeEvent(event) {
|
|
76
|
+
try {
|
|
77
|
+
queueEventStorage.enterWith(event);
|
|
78
|
+
} catch {}
|
|
79
|
+
setActiveCloudflareEnv(getCloudflareEnv(event));
|
|
80
|
+
}
|
|
81
|
+
function getQueueRuntimeEvent() {
|
|
82
|
+
return queueEventStorage.getStore() ?? queueEventDefaults;
|
|
83
|
+
}
|
|
84
|
+
function setQueueRuntimeEventDefaults(event) {
|
|
85
|
+
queueEventDefaults = event;
|
|
86
|
+
}
|
|
87
|
+
function setQueueRuntimeRegistry(registry) {
|
|
88
|
+
registryOverride = registry;
|
|
89
|
+
queueClientCache.clear();
|
|
90
|
+
}
|
|
91
|
+
function getQueueClientCache() {
|
|
92
|
+
return queueClientCache;
|
|
93
|
+
}
|
|
94
|
+
function isQueueDefinition(value) {
|
|
95
|
+
return Boolean(value) && typeof value === "object" && typeof value.handler === "function";
|
|
96
|
+
}
|
|
97
|
+
async function loadQueueDefinition(name) {
|
|
98
|
+
const entry = registryOverride?.[name];
|
|
99
|
+
if (!entry) return;
|
|
100
|
+
const loaded = await entry();
|
|
101
|
+
if (isQueueDefinition(loaded)) return loaded;
|
|
102
|
+
if (loaded && typeof loaded === "object" && "default" in loaded && isQueueDefinition(loaded.default)) return loaded.default;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { getQueueRuntimeEvent as a, setQueueRuntimeConfig as c, createCloudflareRuntimeEvent as d, getCloudflareEnv as f, getQueueRuntimeConfig as i, setQueueRuntimeEventDefaults as l, runWithActiveCloudflareEnv as m, getQueueClientCache as n, loadQueueDefinition as o, resolveWaitUntil as p, getQueueRuntimeClientFactory as r, runWithQueueRuntimeEvent as s, enterQueueRuntimeEvent as t, setQueueRuntimeRegistry as u };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type QueueProvider = "cloudflare" | "vercel";
|
|
3
|
+
type CloudflareQueueContentType = "bytes" | "json" | "text" | "v8";
|
|
4
|
+
interface CloudflareQueueSendOptions {
|
|
5
|
+
contentType?: CloudflareQueueContentType;
|
|
6
|
+
delaySeconds?: number;
|
|
7
|
+
}
|
|
8
|
+
interface CloudflareQueueSendBatchOptions {
|
|
9
|
+
delaySeconds?: number;
|
|
10
|
+
}
|
|
11
|
+
interface CloudflareQueueSendBatchMessage<T = unknown> extends CloudflareQueueSendOptions {
|
|
12
|
+
body: T;
|
|
13
|
+
}
|
|
14
|
+
interface CloudflareQueueRetryOptions {
|
|
15
|
+
delaySeconds?: number;
|
|
16
|
+
}
|
|
17
|
+
interface CloudflareQueueBinding {
|
|
18
|
+
send: <T = unknown>(body: T, options?: CloudflareQueueSendOptions) => Promise<unknown>;
|
|
19
|
+
sendBatch: <T = unknown>(messages: Iterable<CloudflareQueueSendBatchMessage<T>>, options?: CloudflareQueueSendBatchOptions) => Promise<unknown>;
|
|
20
|
+
}
|
|
21
|
+
interface CloudflareQueueMessage<T = unknown> {
|
|
22
|
+
ack: () => void;
|
|
23
|
+
attempts: number;
|
|
24
|
+
body: T;
|
|
25
|
+
id: string;
|
|
26
|
+
retry: (options?: CloudflareQueueRetryOptions) => void;
|
|
27
|
+
timestamp?: Date;
|
|
28
|
+
}
|
|
29
|
+
interface CloudflareQueueMessageBatch<T = unknown> {
|
|
30
|
+
ackAll: () => void;
|
|
31
|
+
messages: CloudflareQueueMessage<T>[];
|
|
32
|
+
queue: string;
|
|
33
|
+
retryAll: (options?: CloudflareQueueRetryOptions) => void;
|
|
34
|
+
}
|
|
35
|
+
type CloudflareQueueBatchErrorAction = "ack" | "retry" | {
|
|
36
|
+
retry: CloudflareQueueRetryOptions;
|
|
37
|
+
};
|
|
38
|
+
interface CloudflareQueueBatchHandlerOptions<T = unknown> {
|
|
39
|
+
concurrency?: number;
|
|
40
|
+
onError?: (error: unknown, message: CloudflareQueueMessage<T>, batch: CloudflareQueueMessageBatch<T>) => CloudflareQueueBatchErrorAction | void | Promise<CloudflareQueueBatchErrorAction | void>;
|
|
41
|
+
onMessage: (message: CloudflareQueueMessage<T>, batch: CloudflareQueueMessageBatch<T>) => unknown | Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
type VercelQueueRetryDirective = {
|
|
44
|
+
acknowledge: true;
|
|
45
|
+
} | {
|
|
46
|
+
afterSeconds: number;
|
|
47
|
+
};
|
|
48
|
+
type VercelQueueRetryHandler = (error: unknown, metadata: unknown) => VercelQueueRetryDirective | void;
|
|
49
|
+
interface VercelQueueCallbackOptions {
|
|
50
|
+
retry?: VercelQueueRetryHandler;
|
|
51
|
+
visibilityTimeoutSeconds?: number;
|
|
52
|
+
}
|
|
53
|
+
interface VercelQueueSendOptions {
|
|
54
|
+
delaySeconds?: number;
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
idempotencyKey?: string;
|
|
57
|
+
region?: string;
|
|
58
|
+
retentionSeconds?: number;
|
|
59
|
+
}
|
|
60
|
+
interface VercelQueueSendResult {
|
|
61
|
+
messageId?: string | null;
|
|
62
|
+
}
|
|
63
|
+
type VercelQueueMessageHandler<T = unknown> = (payload: T, metadata?: unknown) => unknown | Promise<unknown>;
|
|
64
|
+
type VercelQueueCallbackReturn = (request: Request) => Promise<unknown> | unknown;
|
|
65
|
+
interface VercelQueueSDK {
|
|
66
|
+
handleCallback: <TPayload = unknown>(handler: VercelQueueMessageHandler<TPayload>, options?: VercelQueueCallbackOptions) => VercelQueueCallbackReturn;
|
|
67
|
+
send: (topic: string, payload: unknown, options?: VercelQueueSendOptions) => Promise<VercelQueueSendResult>;
|
|
68
|
+
}
|
|
69
|
+
interface QueueSharedOptions {
|
|
70
|
+
cache?: boolean;
|
|
71
|
+
}
|
|
72
|
+
interface CloudflareQueueProviderOptions extends QueueSharedOptions {
|
|
73
|
+
binding?: string | CloudflareQueueBinding;
|
|
74
|
+
provider: "cloudflare";
|
|
75
|
+
}
|
|
76
|
+
interface CloudflareQueueModuleProviderOptions extends QueueSharedOptions {
|
|
77
|
+
binding?: string;
|
|
78
|
+
namePrefix?: string;
|
|
79
|
+
provider: "cloudflare";
|
|
80
|
+
}
|
|
81
|
+
interface VercelQueueProviderOptions extends QueueSharedOptions {
|
|
82
|
+
client?: VercelQueueSDK;
|
|
83
|
+
provider: "vercel";
|
|
84
|
+
region?: string;
|
|
85
|
+
topic?: string;
|
|
86
|
+
}
|
|
87
|
+
interface VercelQueueModuleProviderOptions extends QueueSharedOptions {
|
|
88
|
+
provider: "vercel";
|
|
89
|
+
region?: string;
|
|
90
|
+
}
|
|
91
|
+
type QueueProviderOptions = CloudflareQueueProviderOptions | VercelQueueProviderOptions;
|
|
92
|
+
type QueueModuleProviderOptions = CloudflareQueueModuleProviderOptions | VercelQueueModuleProviderOptions;
|
|
93
|
+
type QueueModuleOptions = false | (QueueSharedOptions & {
|
|
94
|
+
namePrefix?: string;
|
|
95
|
+
provider?: undefined;
|
|
96
|
+
}) | QueueModuleProviderOptions;
|
|
97
|
+
type ResolvedQueueOptions = QueueModuleProviderOptions;
|
|
98
|
+
interface QueueJob<TPayload = unknown> {
|
|
99
|
+
attempts: number;
|
|
100
|
+
id: string;
|
|
101
|
+
metadata?: unknown;
|
|
102
|
+
payload: TPayload;
|
|
103
|
+
}
|
|
104
|
+
type QueueHandler<TPayload = unknown, TResult = unknown> = (job: QueueJob<TPayload>) => TResult;
|
|
105
|
+
interface QueueDefinitionOptions {
|
|
106
|
+
cache?: boolean;
|
|
107
|
+
callbackOptions?: VercelQueueCallbackOptions;
|
|
108
|
+
concurrency?: number;
|
|
109
|
+
onDispatchError?: (error: unknown, context: {
|
|
110
|
+
name: string;
|
|
111
|
+
}) => unknown | Promise<unknown>;
|
|
112
|
+
onError?: CloudflareQueueBatchHandlerOptions["onError"];
|
|
113
|
+
}
|
|
114
|
+
interface QueueDefinition<TPayload = unknown, TResult = unknown> {
|
|
115
|
+
handler: QueueHandler<TPayload, TResult>;
|
|
116
|
+
options?: QueueDefinitionOptions;
|
|
117
|
+
}
|
|
118
|
+
interface QueueEnqueueOptions {
|
|
119
|
+
contentType?: CloudflareQueueContentType;
|
|
120
|
+
delaySeconds?: number;
|
|
121
|
+
idempotencyKey?: string;
|
|
122
|
+
region?: string;
|
|
123
|
+
retentionSeconds?: number;
|
|
124
|
+
}
|
|
125
|
+
type QueueEnqueueEnvelope<TPayload = unknown> = {
|
|
126
|
+
payload: TPayload;
|
|
127
|
+
contentType?: CloudflareQueueContentType;
|
|
128
|
+
delaySeconds?: number;
|
|
129
|
+
id?: string;
|
|
130
|
+
idempotencyKey?: string;
|
|
131
|
+
region?: string;
|
|
132
|
+
retentionSeconds?: number;
|
|
133
|
+
};
|
|
134
|
+
type QueueEnqueueInput<TPayload = unknown> = TPayload | QueueEnqueueEnvelope<TPayload>;
|
|
135
|
+
type QueueSendResult = {
|
|
136
|
+
messageId?: string;
|
|
137
|
+
status: "queued";
|
|
138
|
+
};
|
|
139
|
+
interface QueueClientBase<P extends QueueProvider = QueueProvider> {
|
|
140
|
+
readonly native: unknown;
|
|
141
|
+
readonly provider: P;
|
|
142
|
+
send: <TPayload = unknown>(input: QueueEnqueueInput<TPayload>) => Promise<QueueSendResult>;
|
|
143
|
+
}
|
|
144
|
+
interface CloudflareQueueClient extends QueueClientBase<"cloudflare"> {
|
|
145
|
+
readonly binding: CloudflareQueueBinding;
|
|
146
|
+
createBatchHandler: <TPayload = unknown>(options: CloudflareQueueBatchHandlerOptions<TPayload>) => (batch: CloudflareQueueMessageBatch<TPayload>) => Promise<void>;
|
|
147
|
+
sendBatch: (items: CloudflareQueueSendBatchMessage[], options?: QueueEnqueueOptions) => Promise<QueueSendResult[]>;
|
|
148
|
+
}
|
|
149
|
+
interface VercelQueueClient extends QueueClientBase<"vercel"> {
|
|
150
|
+
readonly topic: string;
|
|
151
|
+
callback: <TPayload = unknown>(handler: VercelQueueMessageHandler<TPayload>, options?: VercelQueueCallbackOptions) => VercelQueueCallbackReturn;
|
|
152
|
+
}
|
|
153
|
+
interface QueueClientMap {
|
|
154
|
+
cloudflare: CloudflareQueueClient;
|
|
155
|
+
vercel: VercelQueueClient;
|
|
156
|
+
}
|
|
157
|
+
type QueueClient<P extends QueueProvider = QueueProvider> = QueueClientMap[P];
|
|
158
|
+
interface QueueDefinitionRegistry {
|
|
159
|
+
[name: string]: () => Promise<{
|
|
160
|
+
default?: QueueDefinition;
|
|
161
|
+
} | QueueDefinition>;
|
|
162
|
+
}
|
|
163
|
+
interface DiscoveredQueueDefinition {
|
|
164
|
+
handler: string;
|
|
165
|
+
name: string;
|
|
166
|
+
source?: "server-queues" | "vite-suffix";
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
export { VercelQueueRetryHandler as C, VercelQueueRetryDirective as S, QueueProviderOptions as _, DiscoveredQueueDefinition as a, VercelQueueCallbackOptions as b, QueueDefinitionOptions as c, QueueEnqueueOptions as d, QueueHandler as f, QueueProvider as g, QueueModuleProviderOptions as h, CloudflareQueueMessageBatch as i, QueueDefinitionRegistry as l, QueueModuleOptions as m, CloudflareQueueClient as n, QueueClient as o, QueueJob as p, CloudflareQueueMessage as r, QueueDefinition as s, CloudflareQueueBatchHandlerOptions as t, QueueEnqueueInput as u, QueueSendResult as v, VercelQueueSendResult as w, VercelQueueClient as x, ResolvedQueueOptions as y };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { r as encodeNameHex } from "./cloudflare-GosJefIK.js";
|
|
2
|
+
//#region src/integrations/vercel.ts
|
|
3
|
+
const vercelQueueTopicPrefix = "topic--";
|
|
4
|
+
function getVercelQueueTopicName(name) {
|
|
5
|
+
return `${vercelQueueTopicPrefix}${encodeNameHex(name)}`;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getVercelQueueTopicName as t };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { i as createDefaultVercelOutputRoot } from "./vite-C6yK76Sw.js";
|
|
2
|
+
import { access, cp, mkdir, readFile, realpath, rm } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
//#region ../internal/src/build/vercel-runtime-package-copy.ts
|
|
5
|
+
async function copyVercelFunctionRuntimePackageDirectories(options) {
|
|
6
|
+
if (!options.packages.length) return;
|
|
7
|
+
const outputNodeModules = resolve(resolve(options.outputRoot ?? createDefaultVercelOutputRoot(options.rootDir), "functions", options.serverFunctionName ?? "__server.func"), "node_modules");
|
|
8
|
+
const copied = /* @__PURE__ */ new Map();
|
|
9
|
+
const selected = /* @__PURE__ */ new Map();
|
|
10
|
+
for (const runtimePackage of options.packages) try {
|
|
11
|
+
selected.set(runtimePackage.name, await realpath(await resolvePackageJson(runtimePackage.name, dirname(runtimePackage.resolveFrom ?? join(options.rootDir, "package.json")))));
|
|
12
|
+
} catch (error) {
|
|
13
|
+
if (!runtimePackage.optional || error.code !== "ENOENT") throw error;
|
|
14
|
+
}
|
|
15
|
+
for (const runtimePackage of options.packages) await copyPackageDirectory(runtimePackage.name, runtimePackage.resolveFrom ?? join(options.rootDir, "package.json"), outputNodeModules, copied, selected, runtimePackage.optional);
|
|
16
|
+
}
|
|
17
|
+
async function copyPackageDirectory(name, resolveFrom, outputNodeModules, copied, selected, optional = false, conflictNodeModules) {
|
|
18
|
+
let resolvedPackageJsonPath;
|
|
19
|
+
try {
|
|
20
|
+
resolvedPackageJsonPath = await resolvePackageJson(name, dirname(resolveFrom));
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (optional && error.code === "ENOENT") return;
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
const packageJsonPath = await realpath(resolvedPackageJsonPath);
|
|
26
|
+
const packageDir = dirname(packageJsonPath);
|
|
27
|
+
let targetDir = join(outputNodeModules, ...name.split("/"));
|
|
28
|
+
const selectedPackage = selected.get(name);
|
|
29
|
+
const existingPackage = copied.get(targetDir);
|
|
30
|
+
if (selectedPackage && selectedPackage !== packageJsonPath || existingPackage && existingPackage !== packageJsonPath) {
|
|
31
|
+
if (!conflictNodeModules) return;
|
|
32
|
+
targetDir = join(conflictNodeModules, ...name.split("/"));
|
|
33
|
+
}
|
|
34
|
+
if (copied.get(targetDir) === packageJsonPath) return;
|
|
35
|
+
copied.set(targetDir, packageJsonPath);
|
|
36
|
+
await rm(targetDir, {
|
|
37
|
+
force: true,
|
|
38
|
+
recursive: true
|
|
39
|
+
});
|
|
40
|
+
await mkdir(dirname(targetDir), { recursive: true });
|
|
41
|
+
await cp(packageDir, targetDir, {
|
|
42
|
+
dereference: true,
|
|
43
|
+
filter: (source) => !relative(packageDir, source).split(sep).includes("node_modules"),
|
|
44
|
+
recursive: true
|
|
45
|
+
});
|
|
46
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
|
|
47
|
+
for (const dependency of Object.keys(packageJson.dependencies ?? {})) await copyPackageDirectory(dependency, packageJsonPath, outputNodeModules, copied, selected, false, join(targetDir, "node_modules"));
|
|
48
|
+
}
|
|
49
|
+
async function resolvePackageJson(name, fromDir) {
|
|
50
|
+
let current = await realpath(fromDir).catch(() => fromDir);
|
|
51
|
+
while (current !== dirname(current)) {
|
|
52
|
+
const candidate = join(current, "node_modules", ...name.split("/"), "package.json");
|
|
53
|
+
try {
|
|
54
|
+
await access(candidate);
|
|
55
|
+
return candidate;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error.code !== "ENOENT") throw error;
|
|
58
|
+
}
|
|
59
|
+
current = dirname(current);
|
|
60
|
+
}
|
|
61
|
+
const error = /* @__PURE__ */ new Error(`Could not resolve package.json for ${name}.`);
|
|
62
|
+
error.code = "ENOENT";
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { copyVercelFunctionRuntimePackageDirectories };
|