Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make wrangler an optional peer dependency #12452

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
link-workspace-packages = true
auto-install-peers = false
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default [
'**/.svelte-kit',
'packages/adapter-static/test/apps/*/build',
'packages/adapter-cloudflare/files',
'packages/adapter-cloudflare-workers/files',
'packages/adapter-netlify/files',
'packages/adapter-node/files',
]
Expand All @@ -29,6 +30,8 @@ export default [
'@typescript-eslint/require-await': 'error',
},
ignores: [
'packages/adapter-cloudflare/index.js',
'packages/adapter-cloudflare-workers/index.js',
'packages/adapter-node/rollup.config.js',
'packages/adapter-node/tests/smoke.spec.js',
'packages/adapter-static/test/apps/**/*',
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@
},
"devDependencies": {
"@changesets/cli": "^2.27.6",
"@stylistic/eslint-plugin-js": "^2.3.0",
"@sveltejs/eslint-config": "^8.0.1",
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
"eslint": "^9.6.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-n": "^17.9.0",
"eslint-plugin-svelte": "^2.41.0",
"playwright": "^1.44.1",
"typescript-eslint": "^8.0.0-alpha.20"
"typescript-eslint": "^8.0.0-alpha.41"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
3 changes: 1 addition & 2 deletions packages/adapter-cloudflare-workers/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.DS_Store
node_modules
/files
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare-workers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["**/*.js", "placeholders.d.ts"]
"include": ["*.js", "*.d.ts"]
}
116 changes: 116 additions & 0 deletions packages/adapter-cloudflare-workers/wrangler.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import type { IncomingRequestCfProperties } from '@cloudflare/workers-types/experimental';

declare class ExecutionContext {
waitUntil(promise: Promise<any>): void;
passThroughOnException(): void;
}

declare type CacheQueryOptions_2 = {
ignoreMethod?: boolean;
};

declare type CacheRequest = any;

declare type CacheResponse = any;

/**
* No-op implementation of Cache
*/
declare class Cache_2 {
delete(request: CacheRequest, options?: CacheQueryOptions_2): Promise<boolean>;
match(request: CacheRequest, options?: CacheQueryOptions_2): Promise<CacheResponse | undefined>;
put(request: CacheRequest, response: CacheResponse): Promise<void>;
}

/**
* No-op implementation of CacheStorage
*/
declare class CacheStorage_2 {
constructor();
open(cacheName: string): Promise<Cache_2>;
get default(): Cache_2;
}

/**
* Result of the `getPlatformProxy` utility
*/
export declare type PlatformProxy<
Env = Record<string, unknown>,
CfProperties extends Record<string, unknown> = IncomingRequestCfProperties
> = {
/**
* Environment object containing the various Cloudflare bindings
*/
env: Env;
/**
* Mock of the context object that Workers received in their request handler, all the object's methods are no-op
*/
cf: CfProperties;
/**
* Mock of the context object that Workers received in their request handler, all the object's methods are no-op
*/
ctx: ExecutionContext;
/**
* Caches object emulating the Workers Cache runtime API
*/
caches: CacheStorage_2;
/**
* Function used to dispose of the child process providing the bindings implementation
*/
dispose: () => Promise<void>;
};

/**
* By reading from a `wrangler.toml` file this function generates proxy objects that can be
* used to simulate the interaction with the Cloudflare platform during local development
* in a Node.js environment
*
* @param options The various options that can tweak this function's behavior
* @returns An Object containing the generated proxies alongside other related utilities
*/
export declare function getPlatformProxy<
Env = Record<string, unknown>,
CfProperties extends Record<string, unknown> = IncomingRequestCfProperties
>(options?: GetPlatformProxyOptions): Promise<PlatformProxy<Env, CfProperties>>;

/**
* Options for the `getPlatformProxy` utility
*/
export declare type GetPlatformProxyOptions = {
/**
* The name of the environment to use
*/
environment?: string;
/**
* The path to the config file to use.
* If no path is specified the default behavior is to search from the
* current directory up the filesystem for a `wrangler.toml` to use.
*
* Note: this field is optional but if a path is specified it must
* point to a valid file on the filesystem
*/
configPath?: string;
/**
* Flag to indicate the utility to read a json config file (`wrangler.json`)
* instead of the toml one (`wrangler.toml`)
*
* Note: this feature is experimental
*/
experimentalJsonConfig?: boolean;
/**
* Indicates if and where to persist the bindings data, if not present or `true` it defaults to the same location
* used by wrangler v3: `.wrangler/state/v3` (so that the same data can be easily used by the caller and wrangler).
* If `false` is specified no data is persisted on the filesystem.
*/
persist?:
| boolean
| {
path: string;
};
/**
* Use the experimental file-based dev registry for service discovery
*
* Note: this feature is experimental
*/
experimentalRegistry?: boolean;
};
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["index.js", "placeholders.d.ts", "src/worker.js"]
"include": ["*.js", "src/*.js", "*.d.ts"]
}
116 changes: 116 additions & 0 deletions packages/adapter-cloudflare/wrangler.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import type { IncomingRequestCfProperties } from '@cloudflare/workers-types/experimental';

declare class ExecutionContext {
waitUntil(promise: Promise<any>): void;
passThroughOnException(): void;
}

declare type CacheQueryOptions_2 = {
ignoreMethod?: boolean;
};

declare type CacheRequest = any;

declare type CacheResponse = any;

/**
* No-op implementation of Cache
*/
declare class Cache_2 {
delete(request: CacheRequest, options?: CacheQueryOptions_2): Promise<boolean>;
match(request: CacheRequest, options?: CacheQueryOptions_2): Promise<CacheResponse | undefined>;
put(request: CacheRequest, response: CacheResponse): Promise<void>;
}

/**
* No-op implementation of CacheStorage
*/
declare class CacheStorage_2 {
constructor();
open(cacheName: string): Promise<Cache_2>;
get default(): Cache_2;
}

/**
* Result of the `getPlatformProxy` utility
*/
export declare type PlatformProxy<
Env = Record<string, unknown>,
CfProperties extends Record<string, unknown> = IncomingRequestCfProperties
> = {
/**
* Environment object containing the various Cloudflare bindings
*/
env: Env;
/**
* Mock of the context object that Workers received in their request handler, all the object's methods are no-op
*/
cf: CfProperties;
/**
* Mock of the context object that Workers received in their request handler, all the object's methods are no-op
*/
ctx: ExecutionContext;
/**
* Caches object emulating the Workers Cache runtime API
*/
caches: CacheStorage_2;
/**
* Function used to dispose of the child process providing the bindings implementation
*/
dispose: () => Promise<void>;
};

/**
* By reading from a `wrangler.toml` file this function generates proxy objects that can be
* used to simulate the interaction with the Cloudflare platform during local development
* in a Node.js environment
*
* @param options The various options that can tweak this function's behavior
* @returns An Object containing the generated proxies alongside other related utilities
*/
export declare function getPlatformProxy<
Env = Record<string, unknown>,
CfProperties extends Record<string, unknown> = IncomingRequestCfProperties
>(options?: GetPlatformProxyOptions): Promise<PlatformProxy<Env, CfProperties>>;

/**
* Options for the `getPlatformProxy` utility
*/
export declare type GetPlatformProxyOptions = {
/**
* The name of the environment to use
*/
environment?: string;
/**
* The path to the config file to use.
* If no path is specified the default behavior is to search from the
* current directory up the filesystem for a `wrangler.toml` to use.
*
* Note: this field is optional but if a path is specified it must
* point to a valid file on the filesystem
*/
configPath?: string;
/**
* Flag to indicate the utility to read a json config file (`wrangler.json`)
* instead of the toml one (`wrangler.toml`)
*
* Note: this feature is experimental
*/
experimentalJsonConfig?: boolean;
/**
* Indicates if and where to persist the bindings data, if not present or `true` it defaults to the same location
* used by wrangler v3: `.wrangler/state/v3` (so that the same data can be easily used by the caller and wrangler).
* If `false` is specified no data is persisted on the filesystem.
*/
persist?:
| boolean
| {
path: string;
};
/**
* Use the experimental file-based dev registry for service discovery
*
* Note: this feature is experimental
*/
experimentalRegistry?: boolean;
};
Loading
Loading