-
Notifications
You must be signed in to change notification settings - Fork 734
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
Fix relative project root #7285
Changes from 1 commit
577f4b9
d94a80a
1f0d1ae
d875dc0
c1ceac2
61353fe
17af36f
512b9a9
79d10d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { writeFile } from "fs/promises"; | ||
Check failure on line 1 in packages/wrangler/src/__tests__/get-entry.test.ts GitHub Actions / Checks
|
||
import path from "path"; | ||
Check failure on line 2 in packages/wrangler/src/__tests__/get-entry.test.ts GitHub Actions / Checks
|
||
import dedent from "ts-dedent"; | ||
import { Config } from "../config"; | ||
Check failure on line 4 in packages/wrangler/src/__tests__/get-entry.test.ts GitHub Actions / Checks
|
||
import { defaultWranglerConfig } from "../config/config"; | ||
import { Entry, getEntry } from "../deployment-bundle/entry"; | ||
import guessWorkerFormat from "../deployment-bundle/guess-worker-format"; | ||
Check failure on line 7 in packages/wrangler/src/__tests__/get-entry.test.ts GitHub Actions / Checks
|
||
import { mockConsoleMethods } from "./helpers/mock-console"; | ||
import { runInTempDir } from "./helpers/run-in-tmp"; | ||
import { seed } from "./helpers/seed"; | ||
|
||
function normalize(entry: Entry): Entry { | ||
return JSON.parse( | ||
JSON.stringify(entry).replaceAll(process.cwd(), "/tmp/dir") | ||
); | ||
} | ||
describe("getEntry()", () => { | ||
runInTempDir(); | ||
mockConsoleMethods(); | ||
it.each([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love that you added these tests, but if I am honest, using |
||
[ | ||
"--script index.ts", | ||
{ | ||
"index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
|
||
} | ||
} | ||
`, | ||
}, | ||
{ script: "index.ts" }, | ||
{}, | ||
{ | ||
directory: "/tmp/dir", | ||
file: "/tmp/dir/index.ts", | ||
moduleRoot: "/tmp/dir", | ||
}, | ||
], | ||
[ | ||
"--script src/index.ts", | ||
{ | ||
"src/index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
|
||
} | ||
} | ||
`, | ||
}, | ||
{ script: "src/index.ts" }, | ||
{}, | ||
{ | ||
directory: "/tmp/dir", | ||
file: "/tmp/dir/src/index.ts", | ||
moduleRoot: "/tmp/dir/src", | ||
}, | ||
], | ||
[ | ||
"main = index.ts", | ||
{ | ||
"index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
|
||
} | ||
} | ||
`, | ||
}, | ||
{}, | ||
{ main: "index.ts" }, | ||
{ | ||
directory: "/tmp/dir", | ||
file: "/tmp/dir/index.ts", | ||
moduleRoot: "/tmp/dir", | ||
}, | ||
], | ||
[ | ||
"main = src/index.ts", | ||
{ | ||
"src/index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
|
||
} | ||
} | ||
`, | ||
}, | ||
{}, | ||
{ main: "src/index.ts" }, | ||
{ | ||
directory: "/tmp/dir", | ||
file: "/tmp/dir/src/index.ts", | ||
moduleRoot: "/tmp/dir/src", | ||
}, | ||
], | ||
[ | ||
"main = src/index.ts w/ configPath", | ||
{ | ||
"other-worker/src/index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
|
||
} | ||
} | ||
`, | ||
}, | ||
{}, | ||
{ | ||
main: "src/index.ts", | ||
configPath: "other-worker/wrangler.toml", | ||
}, | ||
{ | ||
directory: "/tmp/dir/other-worker", | ||
file: "/tmp/dir/other-worker/src/index.ts", | ||
moduleRoot: "/tmp/dir/other-worker/src", | ||
}, | ||
], | ||
])("%s", async (_name, files, args, config, result) => { | ||
await seed(files); | ||
const entry = await getEntry( | ||
args, | ||
{ ...defaultWranglerConfig, ...config }, | ||
"deploy" | ||
); | ||
expect(normalize(entry)).toMatchObject(result); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -53,7 +53,9 @@ export async function getEntry( | |||||
const directory = process.cwd(); | ||||||
const entryPoint = config.site?.["entry-point"]; | ||||||
|
||||||
let paths: { absolutePath: string; relativePath: string } | undefined; | ||||||
let paths: | ||||||
| { absolutePath: string; relativePath: string; directory?: string } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| undefined; | ||||||
|
||||||
if (args.script) { | ||||||
paths = resolveEntryWithScript(args.script); | ||||||
|
@@ -81,9 +83,10 @@ export async function getEntry( | |||||
} | ||||||
await runCustomBuild(paths.absolutePath, paths.relativePath, config.build); | ||||||
|
||||||
const projectRoot = paths.directory ?? directory; | ||||||
const { format, exports } = await guessWorkerFormat( | ||||||
paths.absolutePath, | ||||||
directory, | ||||||
projectRoot, | ||||||
args.format ?? config.build?.upload?.format, | ||||||
config.tsconfig | ||||||
); | ||||||
|
@@ -117,7 +120,7 @@ export async function getEntry( | |||||
|
||||||
return { | ||||||
file: paths.absolutePath, | ||||||
directory, | ||||||
directory: projectRoot, | ||||||
format, | ||||||
moduleRoot: | ||||||
args.moduleRoot ?? config.base_dir ?? path.dirname(paths.absolutePath), | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,12 @@ export function resolveEntryWithMain( | |
): { | ||
absolutePath: string; | ||
relativePath: string; | ||
directory: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we call this |
||
} { | ||
const directory = path.resolve(path.dirname(configPath ?? ".")); | ||
const file = path.resolve(directory, main); | ||
const relativePath = path.relative(directory, file) || "."; | ||
return { absolutePath: file, relativePath }; | ||
return { absolutePath: file, relativePath, directory }; | ||
} | ||
|
||
export function resolveEntryWithEntryPoint( | ||
|
@@ -29,13 +30,14 @@ export function resolveEntryWithEntryPoint( | |
): { | ||
absolutePath: string; | ||
relativePath: string; | ||
directory: string; | ||
} { | ||
const directory = path.resolve(path.dirname(configPath ?? ".")); | ||
const file = path.extname(entryPoint) | ||
? path.resolve(entryPoint) | ||
: path.resolve(entryPoint, "index.js"); | ||
const relativePath = path.relative(directory, file) || "."; | ||
return { absolutePath: file, relativePath }; | ||
return { absolutePath: file, relativePath, directory }; | ||
} | ||
|
||
export function resolveEntryWithAssets(): { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏 🙇♥️