Skip to content

Commit 7ec7c0a

Browse files
authored
[0.6.x] Fail running HMR in known environments (#128)
* fail in known environments * Allow bypassing env validation * update the Forge env * bypass env check for tests * naming * rename vapor env * fail on envoyer
1 parent 8afffba commit 7ec7c0a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
schedule:
77
- cron: '0 0 * * *'
88

9+
env:
10+
LARAVEL_BYPASS_ENV_CHECK: 1
11+
912
jobs:
1013
tests:
1114
runs-on: ubuntu-latest

src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
105105
const env = loadEnv(mode, userConfig.envDir || process.cwd(), '')
106106
const assetUrl = env.ASSET_URL ?? ''
107107

108+
ensureCommandShouldRunInEnvironment(command, env)
109+
108110
return {
109111
base: command === 'build' ? resolveBase(pluginConfig, assetUrl) : '',
110112
publicDir: false,
@@ -202,6 +204,31 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
202204
}
203205
}
204206

207+
/**
208+
* Validate the command can run in the given environment.
209+
*/
210+
function ensureCommandShouldRunInEnvironment(command: 'build'|'serve', env: Record<string, string>): void {
211+
if (command === 'build' || env.LARAVEL_BYPASS_ENV_CHECK === '1') {
212+
return;
213+
}
214+
215+
if (typeof env.LARAVEL_VAPOR !== 'undefined') {
216+
throw Error('You should not run the Vite HMR server on Vapor. You should build your assets for production instead.');
217+
}
218+
219+
if (typeof env.LARAVEL_FORGE !== 'undefined') {
220+
throw Error('You should not run the Vite HMR server in your Forge deployment script. You should build your assets for production instead.');
221+
}
222+
223+
if (typeof env.LARAVEL_ENVOYER !== 'undefined') {
224+
throw Error('You should not run the Vite HMR server in your Envoyer hook. You should build your assets for production instead.');
225+
}
226+
227+
if (typeof env.CI !== 'undefined') {
228+
throw Error('You should not run the Vite HMR server in CI environments. You should build your assets for production instead.');
229+
}
230+
}
231+
205232
/**
206233
* The version of Laravel being run.
207234
*/

0 commit comments

Comments
 (0)