@astrojs/cloudflare 9.2.0 → 10.0.0
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/dist/entrypoints/image-endpoint.js +2 -0
- package/dist/entrypoints/image-service.js +2 -1
- package/dist/entrypoints/server.advanced.d.ts +7 -6
- package/dist/entrypoints/server.advanced.js +13 -8
- package/dist/index.d.ts +37 -49
- package/dist/index.js +123 -374
- package/dist/utils/assets.d.ts +0 -5
- package/dist/utils/assets.js +1 -26
- package/dist/utils/generate-routes-json.d.ts +9 -0
- package/dist/utils/generate-routes-json.js +205 -0
- package/dist/utils/image-config.d.ts +1 -1
- package/dist/utils/image-config.js +1 -1
- package/dist/utils/wasm-module-loader.d.ts +1 -2
- package/dist/utils/wasm-module-loader.js +33 -19
- package/package.json +8 -12
- package/dist/entrypoints/server.directory.d.ts +0 -14
- package/dist/entrypoints/server.directory.js +0 -40
- package/dist/getAdapter.d.ts +0 -5
- package/dist/getAdapter.js +0 -30
- package/dist/util.d.ts +0 -2
- package/dist/util.js +0 -10
- package/dist/utils/deduplicatePatterns.d.ts +0 -8
- package/dist/utils/deduplicatePatterns.js +0 -25
- package/dist/utils/local-runtime.d.ts +0 -11744
- package/dist/utils/local-runtime.js +0 -250
- package/dist/utils/parser.d.ts +0 -27
- package/dist/utils/parser.js +0 -149
- package/dist/utils/prependForwardSlash.d.ts +0 -1
- package/dist/utils/prependForwardSlash.js +0 -3
- package/dist/utils/rewriteWasmImportPath.d.ts +0 -8
- package/dist/utils/rewriteWasmImportPath.js +0 -22
- package/dist/utils/sharpBundlePatch.d.ts +0 -2
- package/dist/utils/sharpBundlePatch.js +0 -17
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import TOML from '@iarna/toml';
|
|
5
|
-
import { AstroError } from 'astro/errors';
|
|
6
|
-
import dotenv from 'dotenv';
|
|
7
|
-
import { Miniflare } from 'miniflare';
|
|
8
|
-
class LocalRuntime {
|
|
9
|
-
_astroConfig;
|
|
10
|
-
_logger;
|
|
11
|
-
_miniflare;
|
|
12
|
-
miniflareBindings;
|
|
13
|
-
secrets;
|
|
14
|
-
cfObject;
|
|
15
|
-
constructor(astroConfig, runtimeConfig, logger) {
|
|
16
|
-
this._astroConfig = astroConfig;
|
|
17
|
-
this._logger = logger;
|
|
18
|
-
const varBindings = {};
|
|
19
|
-
const kvBindings = [];
|
|
20
|
-
const d1Bindings = [];
|
|
21
|
-
const r2Bindings = [];
|
|
22
|
-
const durableObjectBindings = {};
|
|
23
|
-
const serviceBindings = {};
|
|
24
|
-
for (const bindingName in runtimeConfig.bindings) {
|
|
25
|
-
const bindingData = runtimeConfig.bindings[bindingName];
|
|
26
|
-
switch (bindingData.type) {
|
|
27
|
-
case 'var':
|
|
28
|
-
varBindings[bindingName] = bindingData.value;
|
|
29
|
-
break;
|
|
30
|
-
case 'kv':
|
|
31
|
-
kvBindings.push(bindingName);
|
|
32
|
-
break;
|
|
33
|
-
case 'd1':
|
|
34
|
-
d1Bindings.push(bindingName);
|
|
35
|
-
break;
|
|
36
|
-
case 'r2':
|
|
37
|
-
r2Bindings.push(bindingName);
|
|
38
|
-
break;
|
|
39
|
-
case 'durable-object':
|
|
40
|
-
durableObjectBindings[bindingName] = {
|
|
41
|
-
className: bindingData.className,
|
|
42
|
-
scriptName: bindingData.service?.name,
|
|
43
|
-
};
|
|
44
|
-
break;
|
|
45
|
-
case 'service':
|
|
46
|
-
if ('address' in bindingData) {
|
|
47
|
-
// Pages mode
|
|
48
|
-
const isHttps = bindingData.protocol === 'https';
|
|
49
|
-
const serviceBindingConfig = isHttps
|
|
50
|
-
? { address: bindingData.address, https: {} }
|
|
51
|
-
: { address: bindingData.address, http: {} };
|
|
52
|
-
serviceBindings[bindingName] = {
|
|
53
|
-
external: serviceBindingConfig,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
else if ('service' in bindingData) {
|
|
57
|
-
// Worker mode
|
|
58
|
-
serviceBindings[bindingName] = bindingData.service;
|
|
59
|
-
}
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
this._miniflare = new Miniflare({
|
|
64
|
-
cachePersist: `${runtimeConfig.persistTo}/cache`,
|
|
65
|
-
d1Persist: `${runtimeConfig.persistTo}/d1`,
|
|
66
|
-
r2Persist: `${runtimeConfig.persistTo}/r2`,
|
|
67
|
-
kvPersist: `${runtimeConfig.persistTo}/kv`,
|
|
68
|
-
durableObjectsPersist: `${runtimeConfig.persistTo}/do`,
|
|
69
|
-
workers: [
|
|
70
|
-
{
|
|
71
|
-
name: 'worker',
|
|
72
|
-
script: '',
|
|
73
|
-
modules: true,
|
|
74
|
-
cacheWarnUsage: true,
|
|
75
|
-
cache: true,
|
|
76
|
-
bindings: varBindings,
|
|
77
|
-
d1Databases: d1Bindings,
|
|
78
|
-
r2Buckets: r2Bindings,
|
|
79
|
-
kvNamespaces: kvBindings,
|
|
80
|
-
durableObjects: durableObjectBindings,
|
|
81
|
-
serviceBindings: serviceBindings,
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
async getBindings() {
|
|
87
|
-
await this._miniflare.ready;
|
|
88
|
-
if (!this.miniflareBindings) {
|
|
89
|
-
this.miniflareBindings = await this._miniflare.getBindings();
|
|
90
|
-
}
|
|
91
|
-
return this.miniflareBindings;
|
|
92
|
-
}
|
|
93
|
-
async getSecrets() {
|
|
94
|
-
await this._miniflare.ready;
|
|
95
|
-
if (!this.secrets) {
|
|
96
|
-
try {
|
|
97
|
-
this.secrets = dotenv.parse(readFileSync(fileURLToPath(new URL('./.dev.vars', this._astroConfig.root))));
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
const e = error;
|
|
101
|
-
if (e.code === 'ENOENT') {
|
|
102
|
-
this._logger.info('There is no `.dev.vars` file in the root directory, if you have encrypted secrets or environmental variables you Cloudflare recommends to put them in this file');
|
|
103
|
-
this.secrets = {};
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
throw new AstroError('Failed to load secrets file', e.message);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return this.secrets;
|
|
111
|
-
}
|
|
112
|
-
async getCaches() {
|
|
113
|
-
await this._miniflare.ready;
|
|
114
|
-
return this._miniflare.getCaches();
|
|
115
|
-
}
|
|
116
|
-
async getCF() {
|
|
117
|
-
await this._miniflare.ready;
|
|
118
|
-
const MAX_CACHE_AGE = 1000 * 60 * 60 * 24 * 7; // 7 days;
|
|
119
|
-
// Try load cached cfObject, if this fails, we'll catch the error and refetch.
|
|
120
|
-
// If this succeeds, and the file is stale, that's fine: it's very likely
|
|
121
|
-
// we'll be fetching the same data anyways.
|
|
122
|
-
try {
|
|
123
|
-
const cachedCFObject = JSON.parse(readFileSync(fileURLToPath(new URL('cf.json', this._astroConfig.cacheDir)), 'utf8'));
|
|
124
|
-
const cfObjectStats = statSync(fileURLToPath(new URL('cf.json', this._astroConfig.cacheDir)));
|
|
125
|
-
assert(Date.now() - cfObjectStats.mtimeMs <= MAX_CACHE_AGE);
|
|
126
|
-
this.cfObject = cachedCFObject;
|
|
127
|
-
}
|
|
128
|
-
catch { }
|
|
129
|
-
const CF_ENDPOINT = 'https://workers.cloudflare.com/cf.json';
|
|
130
|
-
if (!this.cfObject) {
|
|
131
|
-
this.cfObject = await fetch(CF_ENDPOINT).then((res) => res.json());
|
|
132
|
-
if (!existsSync(this._astroConfig.cacheDir)) {
|
|
133
|
-
mkdirSync(this._astroConfig.cacheDir);
|
|
134
|
-
}
|
|
135
|
-
writeFileSync(fileURLToPath(new URL('cf.json', this._astroConfig.cacheDir)), JSON.stringify(this.cfObject), 'utf8');
|
|
136
|
-
}
|
|
137
|
-
return this.cfObject;
|
|
138
|
-
}
|
|
139
|
-
async dispose() {
|
|
140
|
-
await this._miniflare.dispose();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
export class LocalWorkersRuntime extends LocalRuntime {
|
|
144
|
-
constructor(astroConfig, runtimeConfig, logger) {
|
|
145
|
-
let _wranglerConfig;
|
|
146
|
-
try {
|
|
147
|
-
_wranglerConfig = TOML.parse(readFileSync(fileURLToPath(new URL('./wrangler.toml', astroConfig.root)), 'utf-8').replace(/\r\n/g, '\n'));
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
const e = error;
|
|
151
|
-
if (e.code === 'ENOENT') {
|
|
152
|
-
logger.error('Missing file `wrangler.toml in root directory`');
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
throw new AstroError('Failed to load wrangler config', e.message);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const runtimeConfigWithWrangler = {
|
|
159
|
-
...runtimeConfig,
|
|
160
|
-
bindings: {},
|
|
161
|
-
};
|
|
162
|
-
if (_wranglerConfig?.vars) {
|
|
163
|
-
for (const key in _wranglerConfig.vars) {
|
|
164
|
-
runtimeConfigWithWrangler.bindings[key] = {
|
|
165
|
-
type: 'var',
|
|
166
|
-
value: _wranglerConfig.vars[key],
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (_wranglerConfig?.kv_namespaces) {
|
|
171
|
-
for (const ns of _wranglerConfig.kv_namespaces) {
|
|
172
|
-
runtimeConfigWithWrangler.bindings[ns.binding] = {
|
|
173
|
-
type: 'kv',
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (_wranglerConfig?.d1_databases) {
|
|
178
|
-
for (const db of _wranglerConfig.d1_databases) {
|
|
179
|
-
runtimeConfigWithWrangler.bindings[db.binding] = {
|
|
180
|
-
type: 'd1',
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (_wranglerConfig?.r2_buckets) {
|
|
185
|
-
for (const bucket of _wranglerConfig.r2_buckets) {
|
|
186
|
-
runtimeConfigWithWrangler.bindings[bucket.binding] = {
|
|
187
|
-
type: 'r2',
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if (_wranglerConfig?.durable_objects) {
|
|
192
|
-
for (const durableObject of _wranglerConfig.durable_objects.bindings) {
|
|
193
|
-
runtimeConfigWithWrangler.bindings[durableObject.name] = {
|
|
194
|
-
type: 'durable-object',
|
|
195
|
-
className: durableObject.class_name,
|
|
196
|
-
service: durableObject.script_name
|
|
197
|
-
? {
|
|
198
|
-
name: durableObject.script_name,
|
|
199
|
-
}
|
|
200
|
-
: undefined,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (_wranglerConfig?.services) {
|
|
205
|
-
for (const service of _wranglerConfig.services) {
|
|
206
|
-
runtimeConfigWithWrangler.bindings[service.binding] = {
|
|
207
|
-
type: 'service',
|
|
208
|
-
service: service.service,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
super(astroConfig, runtimeConfigWithWrangler, logger);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
export class LocalPagesRuntime extends LocalRuntime {
|
|
216
|
-
// biome-ignore lint/complexity/noUselessConstructor: not types information yet, so we need to disable the rule for the time being
|
|
217
|
-
constructor(astroConfig, runtimeConfig, logger) {
|
|
218
|
-
super(astroConfig, runtimeConfig, logger);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
let localRuntime;
|
|
222
|
-
export function getLocalRuntime(astroConfig, runtimeConfig, logger) {
|
|
223
|
-
if (localRuntime)
|
|
224
|
-
return localRuntime;
|
|
225
|
-
if (runtimeConfig.type === 'pages') {
|
|
226
|
-
localRuntime = new LocalPagesRuntime(astroConfig, runtimeConfig, logger);
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
localRuntime = new LocalWorkersRuntime(astroConfig, runtimeConfig, logger);
|
|
230
|
-
}
|
|
231
|
-
return localRuntime;
|
|
232
|
-
}
|
|
233
|
-
export function getRuntimeConfig(userConfig) {
|
|
234
|
-
if (!userConfig || userConfig.mode === 'off')
|
|
235
|
-
return { mode: 'off' };
|
|
236
|
-
// we know that we have `mode: local` below
|
|
237
|
-
if (userConfig.type === 'pages')
|
|
238
|
-
return {
|
|
239
|
-
mode: 'local',
|
|
240
|
-
type: 'pages',
|
|
241
|
-
persistTo: userConfig.persistTo ?? '.wrangler/state/v3',
|
|
242
|
-
bindings: userConfig.bindings ?? {},
|
|
243
|
-
};
|
|
244
|
-
// we know that we have `type: workers` below
|
|
245
|
-
return {
|
|
246
|
-
mode: 'local',
|
|
247
|
-
type: 'workers',
|
|
248
|
-
persistTo: userConfig.persistTo ?? '.wrangler/state/v3',
|
|
249
|
-
};
|
|
250
|
-
}
|
package/dist/utils/parser.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is a derivative work of wrangler by Cloudflare
|
|
3
|
-
* An upstream request for exposing this API was made here:
|
|
4
|
-
* https://github.com/cloudflare/workers-sdk/issues/3897
|
|
5
|
-
*
|
|
6
|
-
* Until further notice, we will be using this file as a workaround
|
|
7
|
-
* TODO: Tackle this file, once their is an decision on the upstream request
|
|
8
|
-
*/
|
|
9
|
-
import dotenv from 'dotenv';
|
|
10
|
-
export interface DotEnv {
|
|
11
|
-
path: string;
|
|
12
|
-
parsed: dotenv.DotenvParseOutput;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Loads a dotenv file from <path>, preferring to read <path>.<environment> if
|
|
16
|
-
* <environment> is defined and that file exists.
|
|
17
|
-
*/
|
|
18
|
-
export declare function loadDotEnv(path: string): DotEnv | undefined;
|
|
19
|
-
export declare function getEnvVars(): Promise<any>;
|
|
20
|
-
export declare function getD1Bindings(): Promise<string[]>;
|
|
21
|
-
export declare function getR2Bindings(): Promise<string[]>;
|
|
22
|
-
export declare function getKVBindings(): Promise<string[]>;
|
|
23
|
-
export declare function getDOBindings(): Record<string, {
|
|
24
|
-
scriptName?: string | undefined;
|
|
25
|
-
unsafeUniqueKey?: string | undefined;
|
|
26
|
-
className: string;
|
|
27
|
-
}>;
|
package/dist/utils/parser.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is a derivative work of wrangler by Cloudflare
|
|
3
|
-
* An upstream request for exposing this API was made here:
|
|
4
|
-
* https://github.com/cloudflare/workers-sdk/issues/3897
|
|
5
|
-
*
|
|
6
|
-
* Until further notice, we will be using this file as a workaround
|
|
7
|
-
* TODO: Tackle this file, once their is an decision on the upstream request
|
|
8
|
-
*/
|
|
9
|
-
import * as fs from 'node:fs';
|
|
10
|
-
import { dirname, resolve } from 'node:path';
|
|
11
|
-
import TOML from '@iarna/toml';
|
|
12
|
-
import dotenv from 'dotenv';
|
|
13
|
-
import { findUpSync } from 'find-up';
|
|
14
|
-
let _wrangler;
|
|
15
|
-
function findWranglerToml(referencePath = process.cwd(), preferJson = false) {
|
|
16
|
-
if (preferJson) {
|
|
17
|
-
return (findUpSync('wrangler.json', { cwd: referencePath }) ??
|
|
18
|
-
findUpSync('wrangler.toml', { cwd: referencePath }));
|
|
19
|
-
}
|
|
20
|
-
return findUpSync('wrangler.toml', { cwd: referencePath });
|
|
21
|
-
}
|
|
22
|
-
class ParseError extends Error {
|
|
23
|
-
text;
|
|
24
|
-
notes;
|
|
25
|
-
location;
|
|
26
|
-
kind;
|
|
27
|
-
constructor({ text, notes, location, kind }) {
|
|
28
|
-
super(text);
|
|
29
|
-
this.name = this.constructor.name;
|
|
30
|
-
this.text = text;
|
|
31
|
-
this.notes = notes ?? [];
|
|
32
|
-
this.location = location;
|
|
33
|
-
this.kind = kind ?? 'error';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const TOML_ERROR_NAME = 'TomlError';
|
|
37
|
-
const TOML_ERROR_SUFFIX = ' at row ';
|
|
38
|
-
function parseTOML(input, file) {
|
|
39
|
-
try {
|
|
40
|
-
// Normalize CRLF to LF to avoid hitting https://github.com/iarna/iarna-toml/issues/33.
|
|
41
|
-
const normalizedInput = input.replace(/\r\n/g, '\n');
|
|
42
|
-
return TOML.parse(normalizedInput);
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
const { name, message, line, col } = err;
|
|
46
|
-
if (name !== TOML_ERROR_NAME) {
|
|
47
|
-
throw err;
|
|
48
|
-
}
|
|
49
|
-
const text = message.substring(0, message.lastIndexOf(TOML_ERROR_SUFFIX));
|
|
50
|
-
const lineText = input.split('\n')[line];
|
|
51
|
-
const location = {
|
|
52
|
-
lineText,
|
|
53
|
-
line: line + 1,
|
|
54
|
-
column: col - 1,
|
|
55
|
-
file,
|
|
56
|
-
fileText: input,
|
|
57
|
-
};
|
|
58
|
-
throw new ParseError({ text, location });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function tryLoadDotEnv(path) {
|
|
62
|
-
try {
|
|
63
|
-
const parsed = dotenv.parse(fs.readFileSync(path));
|
|
64
|
-
return { path, parsed };
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
// logger.debug(`Failed to load .env file "${path}":`, e);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Loads a dotenv file from <path>, preferring to read <path>.<environment> if
|
|
72
|
-
* <environment> is defined and that file exists.
|
|
73
|
-
*/
|
|
74
|
-
export function loadDotEnv(path) {
|
|
75
|
-
return tryLoadDotEnv(path);
|
|
76
|
-
}
|
|
77
|
-
function getVarsForDev(config, configPath) {
|
|
78
|
-
const configDir = resolve(dirname(configPath ?? '.'));
|
|
79
|
-
const devVarsPath = resolve(configDir, '.dev.vars');
|
|
80
|
-
const loaded = loadDotEnv(devVarsPath);
|
|
81
|
-
if (loaded !== undefined) {
|
|
82
|
-
return {
|
|
83
|
-
...config.vars,
|
|
84
|
-
...loaded.parsed,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
return config.vars;
|
|
88
|
-
}
|
|
89
|
-
function parseConfig() {
|
|
90
|
-
if (_wrangler)
|
|
91
|
-
return _wrangler;
|
|
92
|
-
// biome-ignore lint/suspicious/noImplicitAnyLet: correct usage
|
|
93
|
-
let rawConfig;
|
|
94
|
-
const configPath = findWranglerToml(process.cwd(), false); // false = args.experimentalJsonConfig
|
|
95
|
-
if (!configPath) {
|
|
96
|
-
throw new Error('Could not find wrangler.toml');
|
|
97
|
-
}
|
|
98
|
-
// Load the configuration from disk if available
|
|
99
|
-
if (configPath?.endsWith('toml')) {
|
|
100
|
-
rawConfig = parseTOML(fs.readFileSync(configPath).toString(), configPath);
|
|
101
|
-
}
|
|
102
|
-
_wrangler = { rawConfig, configPath };
|
|
103
|
-
return { rawConfig, configPath };
|
|
104
|
-
}
|
|
105
|
-
export async function getEnvVars() {
|
|
106
|
-
const { rawConfig, configPath } = parseConfig();
|
|
107
|
-
const vars = getVarsForDev(rawConfig, configPath);
|
|
108
|
-
return vars;
|
|
109
|
-
}
|
|
110
|
-
export async function getD1Bindings() {
|
|
111
|
-
const { rawConfig } = parseConfig();
|
|
112
|
-
if (!rawConfig)
|
|
113
|
-
return [];
|
|
114
|
-
if (!rawConfig?.d1_databases)
|
|
115
|
-
return [];
|
|
116
|
-
const bindings = (rawConfig?.d1_databases).map((binding) => binding.binding);
|
|
117
|
-
return bindings;
|
|
118
|
-
}
|
|
119
|
-
export async function getR2Bindings() {
|
|
120
|
-
const { rawConfig } = parseConfig();
|
|
121
|
-
if (!rawConfig)
|
|
122
|
-
return [];
|
|
123
|
-
if (!rawConfig?.r2_buckets)
|
|
124
|
-
return [];
|
|
125
|
-
const bindings = (rawConfig?.r2_buckets).map((binding) => binding.binding);
|
|
126
|
-
return bindings;
|
|
127
|
-
}
|
|
128
|
-
export async function getKVBindings() {
|
|
129
|
-
const { rawConfig } = parseConfig();
|
|
130
|
-
if (!rawConfig)
|
|
131
|
-
return [];
|
|
132
|
-
if (!rawConfig?.kv_namespaces)
|
|
133
|
-
return [];
|
|
134
|
-
const bindings = (rawConfig?.kv_namespaces).map((binding) => binding.binding);
|
|
135
|
-
return bindings;
|
|
136
|
-
}
|
|
137
|
-
export function getDOBindings() {
|
|
138
|
-
const { rawConfig } = parseConfig();
|
|
139
|
-
if (!rawConfig)
|
|
140
|
-
return {};
|
|
141
|
-
if (!rawConfig.durable_objects)
|
|
142
|
-
return {};
|
|
143
|
-
const output = new Object({});
|
|
144
|
-
const bindings = rawConfig.durable_objects.bindings;
|
|
145
|
-
for (const binding of bindings) {
|
|
146
|
-
Reflect.set(output, binding.name, { className: binding.class_name });
|
|
147
|
-
}
|
|
148
|
-
return output;
|
|
149
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function prependForwardSlash(path: string): string;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type esbuild from 'esbuild';
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param relativePathToAssets - relative path from the final location for the current esbuild output bundle, to the assets directory.
|
|
5
|
-
*/
|
|
6
|
-
export declare function rewriteWasmImportPath({ relativePathToAssets, }: {
|
|
7
|
-
relativePathToAssets: string;
|
|
8
|
-
}): esbuild.Plugin;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { basename } from 'node:path';
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param relativePathToAssets - relative path from the final location for the current esbuild output bundle, to the assets directory.
|
|
5
|
-
*/
|
|
6
|
-
export function rewriteWasmImportPath({ relativePathToAssets, }) {
|
|
7
|
-
return {
|
|
8
|
-
name: 'wasm-loader',
|
|
9
|
-
setup(build) {
|
|
10
|
-
build.onResolve({ filter: /.*\.wasm.mjs$/ }, (args) => {
|
|
11
|
-
const updatedPath = [
|
|
12
|
-
relativePathToAssets.replaceAll('\\', '/'),
|
|
13
|
-
basename(args.path).replace(/\.mjs$/, ''),
|
|
14
|
-
].join('/');
|
|
15
|
-
return {
|
|
16
|
-
path: updatedPath,
|
|
17
|
-
external: true, // mark it as external in the bundle
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function patchSharpBundle() {
|
|
2
|
-
return {
|
|
3
|
-
name: 'sharp-patch',
|
|
4
|
-
setup(build) {
|
|
5
|
-
build.onResolve({ filter: /^sharp/ }, (args) => ({
|
|
6
|
-
path: args.path,
|
|
7
|
-
namespace: 'sharp-ns',
|
|
8
|
-
}));
|
|
9
|
-
build.onLoad({ filter: /.*/, namespace: 'sharp-ns' }, (a) => {
|
|
10
|
-
return {
|
|
11
|
-
contents: JSON.stringify(''),
|
|
12
|
-
loader: 'json',
|
|
13
|
-
};
|
|
14
|
-
});
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|