-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
214 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
Rename `directory` to `projectRoot` and ensure it's relative to the `wrangler.toml`. This fixes a regression which meant that `.wrangler` temporary folders were inadvertently generated relative to `process.cwd()` rather than the location of the `wrangler.toml` file. It also renames `directory` to `projectRoot`, which affects the `unstable_startWorker() interface. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import path from "path"; | ||
import dedent from "ts-dedent"; | ||
import { defaultWranglerConfig } from "../config/config"; | ||
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 { Entry } from "../deployment-bundle/entry"; | ||
|
||
function normalize(entry: Entry): Entry { | ||
const tmpDir = process.cwd(); | ||
const tmpDirName = path.basename(tmpDir); | ||
|
||
return Object.fromEntries( | ||
Object.entries(entry).map(([k, v]) => [ | ||
k, | ||
typeof v === "string" | ||
? v | ||
.replaceAll("\\", "/") | ||
.replace(new RegExp(`(.*${tmpDirName})`), `/tmp/dir`) | ||
: v, | ||
]) | ||
) as Entry; | ||
} | ||
|
||
describe("getEntry()", () => { | ||
runInTempDir(); | ||
mockConsoleMethods(); | ||
|
||
it("--script index.ts", async () => { | ||
await seed({ | ||
"index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
} | ||
} | ||
`, | ||
}); | ||
const entry = await getEntry( | ||
{ script: "index.ts" }, | ||
defaultWranglerConfig, | ||
"deploy" | ||
); | ||
expect(normalize(entry)).toMatchObject({ | ||
projectRoot: "/tmp/dir", | ||
file: "/tmp/dir/index.ts", | ||
moduleRoot: "/tmp/dir", | ||
}); | ||
}); | ||
|
||
it("--script src/index.ts", async () => { | ||
await seed({ | ||
"src/index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
} | ||
} | ||
`, | ||
}); | ||
const entry = await getEntry( | ||
{ script: "src/index.ts" }, | ||
defaultWranglerConfig, | ||
"deploy" | ||
); | ||
expect(normalize(entry)).toMatchObject({ | ||
projectRoot: "/tmp/dir", | ||
file: "/tmp/dir/src/index.ts", | ||
moduleRoot: "/tmp/dir/src", | ||
}); | ||
}); | ||
|
||
it("main = index.ts", async () => { | ||
await seed({ | ||
"index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
} | ||
} | ||
`, | ||
}); | ||
const entry = await getEntry( | ||
{}, | ||
{ ...defaultWranglerConfig, main: "index.ts" }, | ||
"deploy" | ||
); | ||
expect(normalize(entry)).toMatchObject({ | ||
projectRoot: "/tmp/dir", | ||
file: "/tmp/dir/index.ts", | ||
moduleRoot: "/tmp/dir", | ||
}); | ||
}); | ||
|
||
it("main = src/index.ts", async () => { | ||
await seed({ | ||
"src/index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
} | ||
} | ||
`, | ||
}); | ||
const entry = await getEntry( | ||
{}, | ||
{ ...defaultWranglerConfig, main: "src/index.ts" }, | ||
"deploy" | ||
); | ||
expect(normalize(entry)).toMatchObject({ | ||
projectRoot: "/tmp/dir", | ||
file: "/tmp/dir/src/index.ts", | ||
moduleRoot: "/tmp/dir/src", | ||
}); | ||
}); | ||
|
||
it("main = src/index.ts w/ configPath", async () => { | ||
await seed({ | ||
"other-worker/src/index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
} | ||
} | ||
`, | ||
}); | ||
const entry = await getEntry( | ||
{}, | ||
{ | ||
...defaultWranglerConfig, | ||
main: "src/index.ts", | ||
configPath: "other-worker/wrangler.toml", | ||
}, | ||
"deploy" | ||
); | ||
expect(normalize(entry)).toMatchObject({ | ||
projectRoot: "/tmp/dir/other-worker", | ||
file: "/tmp/dir/other-worker/src/index.ts", | ||
moduleRoot: "/tmp/dir/other-worker/src", | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.