-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Vite projects in debug:cpu command (#2124)
* Improve deferPromise utility for debugging * Implement --watch in build command * Support --codegen with --watch in build command * Add --build to preview command * Fix codegen flag relationship * Use new flag in skeleton * Pass --entry from preview to build * Extract resource cleanup logic * Setup resource cleanup for build watch * Add --watch to preview command * Replace command in examples * Consider classic compiler in preview * Support --diff in preview to test in examples * Changesets * Silence non-actionable build logs during preview * Typo * Support --diff in debug:cpu to test in examples * Fix output filepath resolution * Extract classic project logic * Setup resource cleanup * Rename hook * Extract profiler logic * Support Vite in debug:cpu * Changesets * Enable sourcemaps in debug:cpu * Add more info to top-level script * Try to fix mini-oxygen tests
- Loading branch information
Showing
8 changed files
with
226 additions
and
101 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 @@ | ||
--- | ||
'@shopify/cli-hydrogen': minor | ||
--- | ||
|
||
Support Vite projects in `h2 debug cpu` command. |
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,72 @@ | ||
import {outputWarn} from '@shopify/cli-kit/node/output'; | ||
import {createRemixLogger} from '../log.js'; | ||
import {importLocal} from '../import-utils.js'; | ||
import { | ||
getRemixConfig, | ||
handleRemixImportFail, | ||
type RemixConfig, | ||
type ServerMode, | ||
} from '../remix-config.js'; | ||
|
||
type DebugOptions = { | ||
directory: string; | ||
output: string; | ||
buildPathWorkerFile: string; | ||
hooks: { | ||
onServerBuildStart: () => void | Promise<void>; | ||
onServerBuildFinish: () => void | Promise<void>; | ||
}; | ||
}; | ||
|
||
export async function runClassicCompilerDebugCpu({ | ||
directory, | ||
hooks, | ||
}: DebugOptions) { | ||
type RemixWatch = typeof import('@remix-run/dev/dist/compiler/watch.js'); | ||
type RemixFileWatchCache = | ||
typeof import('@remix-run/dev/dist/compiler/fileWatchCache.js'); | ||
|
||
const [{watch}, {createFileWatchCache}] = await Promise.all([ | ||
importLocal<RemixWatch>('@remix-run/dev/dist/compiler/watch.js', directory), | ||
importLocal<RemixFileWatchCache>( | ||
'@remix-run/dev/dist/compiler/fileWatchCache.js', | ||
directory, | ||
), | ||
]).catch(handleRemixImportFail); | ||
|
||
const fileWatchCache = createFileWatchCache(); | ||
|
||
const closeWatcher = await watch( | ||
{ | ||
config: (await getRemixConfig(directory)) as RemixConfig, | ||
options: { | ||
mode: process.env.NODE_ENV as ServerMode, | ||
sourcemap: true, | ||
}, | ||
fileWatchCache, | ||
logger: createRemixLogger(), | ||
}, | ||
{ | ||
onBuildStart: hooks.onServerBuildStart, | ||
async onBuildFinish(context, duration, succeeded) { | ||
if (succeeded) { | ||
await hooks.onServerBuildFinish(); | ||
} else { | ||
outputWarn('\nBuild failed, waiting for changes to restart...'); | ||
} | ||
}, | ||
async onFileChanged(file) { | ||
fileWatchCache.invalidateFile(file); | ||
}, | ||
async onFileDeleted(file) { | ||
fileWatchCache.invalidateFile(file); | ||
}, | ||
}, | ||
); | ||
|
||
return { | ||
async close() { | ||
await closeWatcher(); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.