Skip to content

Commit

Permalink
fix(wrangler): Rename more legacy-assets things (#6336)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmenPopoviciu authored Jul 26, 2024
1 parent bdf1749 commit 6e14865
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 107 deletions.
4 changes: 2 additions & 2 deletions packages/wrangler/src/__tests__/navigator-user-agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe("defineNavigatorUserAgent is respected", () => {
bundle: true,
additionalModules: [],
moduleCollector: noopModuleCollector,
serveAssetsFromWorker: false,
serveLegacyAssetsFromWorker: false,
doBindings: [],
define: {},
alias: {},
Expand Down Expand Up @@ -172,7 +172,7 @@ describe("defineNavigatorUserAgent is respected", () => {
bundle: true,
additionalModules: [],
moduleCollector: noopModuleCollector,
serveAssetsFromWorker: false,
serveLegacyAssetsFromWorker: false,
doBindings: [],
define: {},
alias: {},
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/__tests__/validate-dev-props.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("validateDevProps", () => {
it("should throw if the user tries to use the service-worker format with an `assets` directory", () => {
const props = {
isWorkersSite: false,
assetPaths: ["assets"],
legacyAssetPaths: ["assets"],
entry: { format: "service-worker" },
bindings: {},
};
Expand All @@ -18,7 +18,7 @@ describe("validateDevProps", () => {
it("should throw if the user tries to configure [wasm_modules] with an ES module worker", () => {
const props = {
isWorkersSite: false,
assetPaths: [],
legacyAssetPaths: [],
entry: { format: "modules" },
bindings: { wasm_modules: true },
};
Expand All @@ -31,7 +31,7 @@ describe("validateDevProps", () => {
it("should throw if the user tries to configure [text_blobs] with an ES module worker", () => {
const props = {
isWorkersSite: false,
assetPaths: [],
legacyAssetPaths: [],
entry: { format: "modules" },
bindings: { text_blobs: true },
};
Expand All @@ -44,7 +44,7 @@ describe("validateDevProps", () => {
it("should throw if the user tries to configure [data_blobs] with an ES module worker", () => {
const props = {
isWorkersSite: false,
assetPaths: [],
legacyAssetPaths: [],
entry: { format: "modules" },
bindings: { data_blobs: true },
};
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/api/integrations/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
buildSitesOptions,
} from "../../../dev/miniflare";
import { run } from "../../../experimental-flags";
import { getAssetPaths, getSiteAssetPaths } from "../../../sites";
import { getLegacyAssetPaths, getSiteAssetPaths } from "../../../sites";
import { CacheStorage } from "./caches";
import { ExecutionContext } from "./executionContext";
import { getServiceBindings } from "./services";
Expand Down Expand Up @@ -290,10 +290,10 @@ export function unstable_getMiniflareWorkerOptions(
);
}

const assetPaths = config.legacy_assets
? getAssetPaths(config, undefined)
const legacyAssetPaths = config.legacy_assets
? getLegacyAssetPaths(config, undefined)
: getSiteAssetPaths(config);
const sitesOptions = buildSitesOptions({ assetPaths });
const sitesOptions = buildSitesOptions({ legacyAssetPaths });

const workerOptions: SourcelessWorkerOptions = {
compatibilityDate: config.compatibility_date,
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/api/startDevWorker/BundlerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
bundle: true,
additionalModules: [],
moduleCollector,
serveAssetsFromWorker: Boolean(
serveLegacyAssetsFromWorker: Boolean(
config.legacy?.legacyAssets && !config.dev?.remote
),
doBindings: bindings?.durable_objects?.bindings ?? [],
Expand Down Expand Up @@ -216,7 +216,7 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
additionalModules: config.build?.additionalModules ?? [],
rules: config.build.moduleRules,
legacyAssets: config.legacy?.legacyAssets,
serveAssetsFromWorker: Boolean(
serveLegacyAssetsFromWorker: Boolean(
config.legacy?.legacyAssets && !config.dev?.remote
),
tsconfig: config.build?.tsconfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async function convertToConfigBundle(
compatibilityFlags: event.config.compatibilityFlags,
bindings,
workerDefinitions: event.config.dev?.registry,
assetPaths: event.config.legacy?.site?.bucket
legacyAssetPaths: event.config.legacy?.site?.bucket
? {
baseDirectory: event.config.legacy?.site?.bucket,
assetDirectory: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class RemoteRuntimeController extends RuntimeController {
legacyEnv: props.legacyEnv,
env: props.env,
isWorkersSite: props.isWorkersSite,
assetPaths: props.assetPaths,
legacyAssetPaths: props.legacyAssetPaths,
format: props.format,
bindings: props.bindings,
compatibilityDate: props.compatibilityDate,
Expand Down Expand Up @@ -169,7 +169,7 @@ export class RemoteRuntimeController extends RuntimeController {
legacyEnv: !config.legacy?.enableServiceEnvironments,
env: config.env,
isWorkersSite: config.legacy?.site !== undefined,
assetPaths: config.legacy?.site?.bucket
legacyAssetPaths: config.legacy?.site?.bucket
? {
baseDirectory: config.legacy?.site?.bucket,
assetDirectory: "",
Expand Down
12 changes: 6 additions & 6 deletions packages/wrangler/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import type {
CfWorkerInit,
} from "../deployment-bundle/worker";
import type { PostQueueBody, PostTypedConsumerBody } from "../queues/client";
import type { AssetPaths } from "../sites";
import type { LegacyAssetPaths } from "../sites";
import type { RetrieveSourceMapFunction } from "../sourcemap";

type Props = {
Expand All @@ -75,7 +75,7 @@ type Props = {
env: string | undefined;
compatibilityDate: string | undefined;
compatibilityFlags: string[] | undefined;
assetPaths: AssetPaths | undefined;
legacyAssetPaths: LegacyAssetPaths | undefined;
experimentalAssets: string | undefined;
vars: Record<string, string> | undefined;
defines: Record<string, string> | undefined;
Expand Down Expand Up @@ -450,7 +450,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m

if (
!props.isWorkersSite &&
Boolean(props.assetPaths) &&
Boolean(props.legacyAssetPaths) &&
format === "service-worker"
) {
throw new UserError(
Expand Down Expand Up @@ -521,8 +521,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
bundle: true,
additionalModules: [],
moduleCollector,
serveAssetsFromWorker:
!props.isWorkersSite && Boolean(props.assetPaths),
serveLegacyAssetsFromWorker:
!props.isWorkersSite && Boolean(props.legacyAssetPaths),
doBindings: config.durable_objects.bindings,
jsxFactory,
jsxFragment,
Expand Down Expand Up @@ -595,7 +595,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
// include it in the kv namespace name regardless (since there's no
// concept of service environments for kv namespaces yet).
scriptName + (!props.legacyEnv && props.env ? `-${props.env}` : ""),
props.assetPaths,
props.legacyAssetPaths,
false,
props.dryRun,
props.oldAssetTtl
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "../index";
import { logger } from "../logger";
import * as metrics from "../metrics";
import { getAssetPaths, getSiteAssetPaths } from "../sites";
import { getLegacyAssetPaths, getSiteAssetPaths } from "../sites";
import { requireAuth } from "../user";
import { collectKeyValues } from "../utils/collectKeyValues";
import deploy from "./deploy";
Expand Down Expand Up @@ -335,9 +335,9 @@ export async function deployHandler(

const accountId = args.dryRun ? undefined : await requireAuth(config);

const assetPaths =
const legacyAssetPaths =
args.legacyAssets || config.legacy_assets
? getAssetPaths(config, args.legacyAssets)
? getLegacyAssetPaths(config, args.legacyAssets)
: getSiteAssetPaths(
config,
args.site,
Expand Down Expand Up @@ -370,7 +370,7 @@ export async function deployHandler(
tsconfig: args.tsconfig,
routes: args.routes,
experimentalAssets: experimentalAssets?.directory,
assetPaths,
legacyAssetPaths,
legacyEnv: isLegacyEnv(config),
minify: args.minify,
nodeCompat: args.nodeCompat,
Expand Down
6 changes: 3 additions & 3 deletions packages/wrangler/src/deployment-bundle/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type BundleOptions = {
additionalModules: CfModule[];
// A module collector enables you to observe what modules are in the Worker.
moduleCollector: ModuleCollector;
serveAssetsFromWorker: boolean;
serveLegacyAssetsFromWorker: boolean;
legacyAssets?: Config["legacy_assets"];
bypassAssetCache?: boolean;
doBindings: DurableObjectBindings;
Expand Down Expand Up @@ -100,7 +100,7 @@ export async function bundleWorker(
bundle,
moduleCollector = noopModuleCollector,
additionalModules = [],
serveAssetsFromWorker,
serveLegacyAssetsFromWorker,
doBindings,
jsxFactory,
jsxFragment,
Expand Down Expand Up @@ -180,7 +180,7 @@ export async function bundleWorker(
});
}

if (serveAssetsFromWorker) {
if (serveLegacyAssetsFromWorker) {
middlewareToLoad.push({
name: "serve-static-assets",
path: "templates/middleware/middleware-serve-static-assets.ts",
Expand Down
43 changes: 24 additions & 19 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { run } from "./experimental-flags";
import isInteractive from "./is-interactive";
import { logger } from "./logger";
import * as metrics from "./metrics";
import { getAssetPaths, getSiteAssetPaths } from "./sites";
import { getLegacyAssetPaths, getSiteAssetPaths } from "./sites";
import {
getAccountFromCache,
loginOrRefreshIfRequired,
Expand Down Expand Up @@ -723,16 +723,19 @@ export async function startDev(args: StartDevOptions) {
},
legacy: {
site: (configParam) => {
const assetPaths = getResolvedAssetPaths(args, configParam);
const legacyAssetPaths = getResolvedLegacyAssetPaths(
args,
configParam
);

return Boolean(args.site || configParam.site) && assetPaths
return Boolean(args.site || configParam.site) && legacyAssetPaths
? {
bucket: path.join(
assetPaths.baseDirectory,
assetPaths?.assetDirectory
legacyAssetPaths.baseDirectory,
legacyAssetPaths?.assetDirectory
),
include: assetPaths.includePatterns,
exclude: assetPaths.excludePatterns,
include: legacyAssetPaths.includePatterns,
exclude: legacyAssetPaths.excludePatterns,
}
: undefined;
},
Expand Down Expand Up @@ -821,6 +824,7 @@ export async function startDev(args: StartDevOptions) {
args.compatibilityFlags ?? config.compatibility_flags ?? [],
noBundle: args.noBundle ?? config.no_bundle ?? false,
});

void metrics.sendMetricsEvent(
"run dev",
{
Expand All @@ -832,7 +836,7 @@ export async function startDev(args: StartDevOptions) {

// eslint-disable-next-line no-inner-declarations
async function getDevReactElement(configParam: Config) {
const { assetPaths, bindings } = getBindingsAndAssetPaths(
const { legacyAssetPaths, bindings } = getBindingsAndLegacyAssetPaths(
args,
configParam
);
Expand Down Expand Up @@ -871,8 +875,8 @@ export async function startDev(args: StartDevOptions) {
configParam.account_id ??
getAccountFromCache()?.id
}
assetPaths={assetPaths}
assetsConfig={configParam.legacy_assets}
legacyAssetPaths={legacyAssetPaths}
legacyAssetsConfig={configParam.legacy_assets}
initialPort={
args.port ?? configParam.dev.port ?? (await getLocalPort())
}
Expand Down Expand Up @@ -910,6 +914,7 @@ export async function startDev(args: StartDevOptions) {
/>
);
}

const devReactElement = render(await getDevReactElement(config));

rerender = devReactElement.rerender;
Expand Down Expand Up @@ -992,7 +997,7 @@ export async function startApiDev(args: StartDevOptions) {

// eslint-disable-next-line no-inner-declarations
async function getDevServer(configParam: Config) {
const { assetPaths, bindings } = getBindingsAndAssetPaths(
const { legacyAssetPaths, bindings } = getBindingsAndLegacyAssetPaths(
args,
configParam
);
Expand Down Expand Up @@ -1032,8 +1037,8 @@ export async function startApiDev(args: StartDevOptions) {
liveReload: args.liveReload ?? false,
accountId:
args.accountId ?? configParam.account_id ?? getAccountFromCache()?.id,
assetPaths: assetPaths,
assetsConfig: configParam.legacy_assets,
legacyAssetPaths: legacyAssetPaths,
legacyAssetsConfig: configParam.legacy_assets,
//port can be 0, which means to use a random port
initialPort: args.port ?? configParam.dev.port ?? (await getLocalPort()),
initialIp: args.ip ?? configParam.dev.ip,
Expand Down Expand Up @@ -1295,29 +1300,29 @@ export function getResolvedBindings(
return bindings;
}

export function getResolvedAssetPaths(
export function getResolvedLegacyAssetPaths(
args: StartDevOptions,
configParam: Config
) {
const assetPaths =
const legacyAssetPaths =
args.legacyAssets || configParam.legacy_assets
? getAssetPaths(configParam, args.legacyAssets)
? getLegacyAssetPaths(configParam, args.legacyAssets)
: getSiteAssetPaths(
configParam,
args.site,
args.siteInclude,
args.siteExclude
);
return assetPaths;
return legacyAssetPaths;
}

export function getBindingsAndAssetPaths(
export function getBindingsAndLegacyAssetPaths(
args: StartDevOptions,
configParam: Config
) {
return {
bindings: getResolvedBindings(args, configParam),
assetPaths: getResolvedAssetPaths(args, configParam),
legacyAssetPaths: getResolvedLegacyAssetPaths(args, configParam),
};
}

Expand Down
Loading

0 comments on commit 6e14865

Please sign in to comment.