Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion fixtures/workflow-multiple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"deploy": "wrangler deploy",
"start": "wrangler dev",
"test:ci": "vitest"
"test:ci": "vitest run"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20241106.0",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/workflow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"deploy": "wrangler deploy",
"start": "wrangler dev",
"test:ci": "vitest"
"test:ci": "vitest run"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20241106.0",
Expand Down
31 changes: 12 additions & 19 deletions packages/wrangler/src/__tests__/get-entry.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import path from "path";
import dedent from "ts-dedent";
import { defaultWranglerConfig } from "../config/config";
import { normalizeAndValidateConfig } from "../config/validation";
import { getEntry } from "../deployment-bundle/entry";
import { mockConsoleMethods } from "./helpers/mock-console";
import { runInTempDir } from "./helpers/run-in-tmp";
import { seed } from "./helpers/seed";
import type { Config } from "../config/config";
import type { Config, RawConfig } from "../config";
import type { Entry } from "../deployment-bundle/entry";

function getConfig(): Config {
return {
...defaultWranglerConfig,
projectRoot: process.cwd(),
};
function getConfig(raw: RawConfig = {}, configPath?: string): Config {
return normalizeAndValidateConfig(raw, configPath, {}).config;
}

function normalize(entry: Entry): Entry {
Expand Down Expand Up @@ -83,11 +80,7 @@ describe("getEntry()", () => {
}
`,
});
const entry = await getEntry(
{},
{ ...getConfig(), main: "index.ts" },
"deploy"
);
const entry = await getEntry({}, getConfig({ main: "index.ts" }), "deploy");
expect(normalize(entry)).toMatchObject({
file: "/tmp/dir/index.ts",
moduleRoot: "/tmp/dir",
Expand All @@ -106,7 +99,7 @@ describe("getEntry()", () => {
});
const entry = await getEntry(
{},
{ ...getConfig(), main: "src/index.ts" },
getConfig({ main: "src/index.ts" }),
"deploy"
);
expect(normalize(entry)).toMatchObject({
Expand All @@ -127,12 +120,12 @@ describe("getEntry()", () => {
});
const entry = await getEntry(
{},
{
...getConfig(),
main: "src/index.ts",
configPath: "other-worker/wrangler.toml",
projectRoot: "other-worker",
},
getConfig(
{
main: "src/index.ts",
},
"other-worker/wrangler.toml"
),
"deploy"
);
expect(normalize(entry)).toMatchObject({
Expand Down
11 changes: 9 additions & 2 deletions packages/wrangler/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ export type RawConfig = Partial<ConfigFields<RawDevConfig>> &
EnvironmentMap & { $schema?: string };

export interface ComputedConfigFields {
/** Path to the configuration file (e.g. wrangler.toml/json), if one was provided. */
/**
* Path (relative to current working directory) of the configuration file (e.g. wrangler.toml/json), if one was provided.
*/
configPath: string | undefined;

/** A worker's directory. Usually where the Wrangler configuration file is located */
/**
* Absolute path to the Worker's directory.
*
* Will be the directory containing the Wrangler configuration file,
* or the current working directory otherwise.
*/
projectRoot: string;
}
export interface ConfigFields<Dev extends RawDevConfig> {
Expand Down
7 changes: 2 additions & 5 deletions packages/wrangler/src/deployment-bundle/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export async function getEntry(
): Promise<Entry> {
const entryPoint = config.site?.["entry-point"];

let paths:
| { absolutePath: string; relativePath: string; projectRoot?: string }
| undefined;
let paths: { absolutePath: string; relativePath: string } | undefined;

if (args.script) {
paths = resolveEntryWithScript(args.script);
Expand Down Expand Up @@ -86,10 +84,9 @@ export async function getEntry(
config.configPath
);

const projectRoot = paths.projectRoot ?? process.cwd();
const { format, exports } = await guessWorkerFormat(
paths.absolutePath,
projectRoot,
config.projectRoot,
args.format ?? config.build?.upload?.format,
config.tsconfig
);
Expand Down