New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wrangler

Package Overview
Dependencies
Maintainers
4
Versions
4005
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wrangler - npm Package Compare versions

Comparing version 0.0.0-00e51cd to 0.0.0-014a731

4

package.json
{
"name": "wrangler",
"version": "0.0.0-00e51cd",
"version": "0.0.0-014a731",
"author": "wrangler@cloudflare.com",

@@ -40,3 +40,3 @@ "description": "Command-line interface for all things Cloudflare Workers",

"esbuild": "0.14.1",
"miniflare": "2.1.0",
"miniflare": "2.2.0",
"path-to-regexp": "^6.2.0",

@@ -43,0 +43,0 @@ "semiver": "^1.1.0"

@@ -55,3 +55,3 @@ import path from "path";

// `export async function onRequest() {...}`
if (declaration.type === "FunctionDeclaration") {
if (declaration.type === "FunctionDeclaration" && declaration.id) {
exportNames.push(declaration.id.name);

@@ -159,8 +159,6 @@ }

export function compareRoutes(a: string, b: string) {
function parseRoutePath(routePath: string) {
let [method, segmentedPath] = routePath.split(" ");
if (!segmentedPath) {
segmentedPath = method;
method = null;
}
function parseRoutePath(routePath: string): [string | null, string[]] {
const parts = routePath.split(" ", 2);
const segmentedPath = parts.pop();
const method = parts.pop() ?? null;

@@ -209,3 +207,3 @@ const segments = segmentedPath.slice(1).split("/").filter(Boolean);

while (searchPaths.length) {
while (isNotEmpty(searchPaths)) {
const cwd = searchPaths.shift();

@@ -225,1 +223,8 @@ const dir = await fs.readdir(cwd, { withFileTypes: true });

}
interface NonEmptyArray<T> extends Array<T> {
shift(): T;
}
function isNotEmpty<T>(array: T[]): array is NonEmptyArray<T> {
return array.length > 0;
}

@@ -117,3 +117,3 @@ import path from "path";

for (const [route, props] of Object.entries(config.routes)) {
for (const [route, props] of Object.entries(config.routes ?? {})) {
let [_methods, routePath] = route.split(" ");

@@ -120,0 +120,0 @@ if (!routePath) {

@@ -36,5 +36,5 @@ import { match } from "path-to-regexp";

// expect an ASSETS fetcher binding pointing to the asset-server stage
type Env = {
[name: string]: unknown;
ASSETS: { fetch(url: string, init: RequestInit): Promise<Response> };
type FetchEnv = {
[name: string]: { fetch: typeof fetch };
ASSETS: { fetch: typeof fetch };
};

@@ -46,4 +46,3 @@

// eslint-disable-next-line @typescript-eslint/no-unused-vars -- `env` can be used by __FALLBACK_SERVICE_FETCH__
function* executeRequest(request: Request, env: Env) {
function* executeRequest(request: Request, _env: FetchEnv) {
const requestPath = new URL(request.url).pathname;

@@ -93,16 +92,6 @@

}
// Finally, yield to the fallback service (`env.ASSETS.fetch` in Pages' case)
return {
handler: () =>
__FALLBACK_SERVICE__
? // @ts-expect-error expecting __FALLBACK_SERVICE__ to be the name of a service binding, so fetch should be defined
env[__FALLBACK_SERVICE__].fetch(request)
: fetch(request),
params: {} as Params,
};
}
export default {
async fetch(request: Request, env: Env, workerContext: WorkerContext) {
async fetch(request: Request, env: FetchEnv, workerContext: WorkerContext) {
const handlerIterator = executeRequest(request, env);

@@ -115,10 +104,7 @@ const data = {}; // arbitrary data the user can set between functions

const { value } = handlerIterator.next();
if (value) {
const { handler, params } = value;
const context: EventContext<
unknown,
string,
Record<string, unknown>
> = {
const result = handlerIterator.next();
// Note we can't use `!result.done` because this doesn't narrow to the correct type
if (result.done == false) {
const { handler, params } = result.value;
const context = {
request: new Request(request.clone()),

@@ -139,2 +125,8 @@ next,

);
} else if (__FALLBACK_SERVICE__) {
// There are no more handlers so finish with the fallback service (`env.ASSETS.fetch` in Pages' case)
return env[__FALLBACK_SERVICE__].fetch(request);
} else {
// There was not fallback service so actually make the request to the origin.
return fetch(request);
}

@@ -141,0 +133,0 @@ };

@@ -1,3 +0,3 @@

import fetch, { Headers } from "node-fetch";
import type { RequestInit } from "node-fetch";
import fetch from "node-fetch";
import type { RequestInit, HeadersInit } from "node-fetch";
import { getAPIToken, loginOrRefreshIfRequired } from "../user";

@@ -24,3 +24,3 @@

const apiToken = requireApiToken();
const headers = new Headers(init.headers);
const headers = cloneHeaders(init.headers);
addAuthorizationHeader(headers, apiToken);

@@ -44,2 +44,6 @@

function cloneHeaders(headers: HeadersInit): HeadersInit {
return { ...headers };
}
async function requireLoggedIn(): Promise<void> {

@@ -60,3 +64,3 @@ const loggedIn = await loginOrRefreshIfRequired();

function addAuthorizationHeader(headers: Headers, apiToken: string): void {
function addAuthorizationHeader(headers: HeadersInit, apiToken: string): void {
if (headers["Authorization"]) {

@@ -63,0 +67,0 @@ throw new Error(

@@ -53,9 +53,14 @@ import assert from "node:assert";

const envRootObj = props.env ? config.env[props.env] || {} : config;
const envRootObj =
props.env && config.env ? config.env[props.env] || {} : config;
assert(
envRootObj.compatibility_date || props["compatibility-date"],
envRootObj.compatibility_date || props.compatibilityDate,
"A compatibility_date is required when publishing. Add one to your wrangler.toml file, or pass it in your terminal as --compatibility_date. See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information."
);
if (accountId === undefined) {
throw new Error("No account_id provided.");
}
const triggers = props.triggers || config.triggers?.crons;

@@ -133,14 +138,20 @@ const routes = props.routes || config.routes;

const chunks = Object.entries(result.metafile.outputs).find(
([_path, { entryPoint }]) =>
entryPoint ===
(props.public
? path.join(path.dirname(file), "static-asset-facade.js")
: Object.keys(result.metafile.inputs)[0])
// result.metafile is defined because of the `metafile: true` option above.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const metafile = result.metafile!;
const expectedEntryPoint = props.public
? path.join(path.dirname(file), "static-asset-facade.js")
: file;
const outputEntry = Object.entries(metafile.outputs).find(
([, { entryPoint }]) => entryPoint === expectedEntryPoint
);
if (outputEntry === undefined) {
throw new Error(
`Cannot find entry-point "${expectedEntryPoint}" in generated bundle.`
);
}
const { format } = props;
const bundle = {
type: chunks[1].exports.length > 0 ? "esm" : "commonjs",
exports: chunks[1].exports,
type: outputEntry[1].exports.length > 0 ? "esm" : "commonjs",
exports: outputEntry[1].exports,
};

@@ -162,3 +173,3 @@

const content = await readFile(chunks[0], { encoding: "utf-8" });
const content = await readFile(outputEntry[0], { encoding: "utf-8" });
await destination.cleanup();

@@ -169,3 +180,3 @@

let migrations;
if ("migrations" in config) {
if (config.migrations !== undefined) {
const scripts = await fetchResult<{ id: string; migration_tag: string }[]>(

@@ -206,11 +217,6 @@ `/accounts/${accountId}/workers/scripts`

const assets =
props.public || props.site || props.config.site?.bucket // TODO: allow both
? await syncAssets(
accountId,
scriptName,
props.public || props.site || props.config.site?.bucket,
false
)
: { manifest: undefined, namespace: undefined };
const assetPath = props.public || props.site || props.config.site?.bucket; // TODO: allow both
const assets = assetPath
? await syncAssets(accountId, scriptName, assetPath, false)
: { manifest: undefined, namespace: undefined };

@@ -231,3 +237,3 @@ const bindings: CfWorkerInit["bindings"] = {

main: {
name: path.basename(chunks[0]),
name: path.basename(outputEntry[0]),
content: content,

@@ -234,0 +240,0 @@ type: bundle.type === "esm" ? "esm" : "commonjs",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc