@@ -4,6 +4,7 @@ import { Writable } from "node:stream";
44import { configFileName , UserError } from "@cloudflare/workers-utils" ;
55import chalk from "chalk" ;
66import { execaCommand } from "execa" ;
7+ import dedent from "ts-dedent" ;
78import { logger } from "../logger" ;
89import type { Config } from "@cloudflare/workers-utils" ;
910
@@ -69,15 +70,11 @@ export async function runCustomBuild(
6970 assertEntryPointExists (
7071 expectedEntryAbsolute ,
7172 expectedEntryRelative ,
72- `The expected output file at " ${ expectedEntryRelative } " was not found after running custom build: ${ build . command } .\n` +
73- `The \`main\` property in your ${ configFileName ( configPath ) } file should point to the file generated by the custom build.`
73+ build . command ,
74+ configPath
7475 ) ;
7576 } else {
76- assertEntryPointExists (
77- expectedEntryAbsolute ,
78- expectedEntryRelative ,
79- `The entry-point file at "${ expectedEntryRelative } " was not found.`
80- ) ;
77+ assertEntryPointExists ( expectedEntryAbsolute , expectedEntryRelative ) ;
8178 }
8279}
8380
@@ -87,14 +84,16 @@ export async function runCustomBuild(
8784function assertEntryPointExists (
8885 expectedEntryAbsolute : string ,
8986 expectedEntryRelative : string ,
90- errorMessage : string
87+ customBuildCommand ?: string ,
88+ configPath ?: string
9189) {
9290 if ( ! fileExists ( expectedEntryAbsolute ) ) {
9391 throw new UserError (
9492 getMissingEntryPointMessage (
95- errorMessage ,
9693 expectedEntryAbsolute ,
97- expectedEntryRelative
94+ expectedEntryRelative ,
95+ customBuildCommand ,
96+ configPath
9897 )
9998 ) ;
10099 }
@@ -107,16 +106,17 @@ function assertEntryPointExists(
107106 * nearby to the expected file path.
108107 */
109108function getMissingEntryPointMessage (
110- message : string ,
111109 absoluteEntryPointPath : string ,
112- relativeEntryPointPath : string
110+ relativeEntryPointPath : string ,
111+ customBuildCommand ?: string ,
112+ configPath ?: string
113113) : string {
114114 if (
115115 existsSync ( absoluteEntryPointPath ) &&
116116 statSync ( absoluteEntryPointPath ) . isDirectory ( )
117117 ) {
118118 // The expected entry-point is a directory, so offer further guidance.
119- message + = `\nThe provided entry-point path, "${ relativeEntryPointPath } ", points to a directory, rather than a file.\n` ;
119+ let message = `The provided entry-point path, "${ relativeEntryPointPath } ", points to a directory, rather than a file.\n` ;
120120
121121 // Perhaps we can even guess what the correct path should be...
122122 const possiblePaths : string [ ] = [ ] ;
@@ -147,8 +147,23 @@ function getMissingEntryPointMessage(
147147 `\n If you want to deploy a directory of static assets, you can do so by using the \`--assets\` flag. For example:\n\n` +
148148 `wrangler deploy --assets=./${ relativeEntryPointPath } \n` ;
149149 }
150+
151+ return message ;
150152 }
151- return message ;
153+
154+ if ( customBuildCommand ) {
155+ return dedent `
156+ The expected output file at "${ relativeEntryPointPath } " was not found after running custom build: ${ customBuildCommand } .
157+ The \`main\` property in your ${ configFileName ( configPath ) } file should point to the file generated by the custom build.
158+ ` ;
159+ }
160+
161+ return dedent `
162+ The entry-point file at "${ relativeEntryPointPath } " was not found.
163+
164+ This might mean that your entry-point file needs to be generated (which is the general case when a framework is being used).
165+ If that's the case please run your project's build command and try again.
166+ ` ;
152167}
153168
154169/**
0 commit comments