-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix entrypoint logic and refactor (#6971)
* chore: fix entrypoint logic and refactor * chore: remove spurious files * Add test case
- Loading branch information
1 parent
e4a8591
commit b5fa4a6
Showing
3 changed files
with
113 additions
and
32 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
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,48 @@ | ||
import path from "path"; | ||
import { getBasePath } from "../paths"; | ||
|
||
export function resolveEntryWithScript(script: string): { | ||
absolutePath: string; | ||
relativePath: string; | ||
} { | ||
const file = path.resolve(script); | ||
const relativePath = path.relative(process.cwd(), file) || "."; | ||
return { absolutePath: file, relativePath }; | ||
} | ||
|
||
export function resolveEntryWithMain( | ||
main: string, | ||
configPath?: string | ||
): { | ||
absolutePath: string; | ||
relativePath: string; | ||
} { | ||
const directory = path.resolve(path.dirname(configPath ?? ".")); | ||
const file = path.resolve(directory, main); | ||
const relativePath = path.relative(directory, file) || "."; | ||
return { absolutePath: file, relativePath }; | ||
} | ||
|
||
export function resolveEntryWithEntryPoint( | ||
entryPoint: string, | ||
configPath?: string | ||
): { | ||
absolutePath: string; | ||
relativePath: 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 }; | ||
} | ||
|
||
export function resolveEntryWithAssets(): { | ||
absolutePath: string; | ||
relativePath: string; | ||
} { | ||
const file = path.resolve(getBasePath(), "templates/no-op-worker.js"); | ||
const relativePath = path.relative(process.cwd(), file) || "."; | ||
return { absolutePath: file, relativePath }; | ||
} |