Skip to content

Commit

Permalink
[0.6.x] Fail running HMR in known environments (#128)
Browse files Browse the repository at this point in the history
* fail in known environments

* Allow bypassing env validation

* update the Forge env

* bypass env check for tests

* naming

* rename vapor env

* fail on envoyer
  • Loading branch information
timacdonald authored Sep 15, 2022
1 parent 8afffba commit 7ec7c0a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
schedule:
- cron: '0 0 * * *'

env:
LARAVEL_BYPASS_ENV_CHECK: 1

jobs:
tests:
runs-on: ubuntu-latest
Expand Down
27 changes: 27 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
const env = loadEnv(mode, userConfig.envDir || process.cwd(), '')
const assetUrl = env.ASSET_URL ?? ''

ensureCommandShouldRunInEnvironment(command, env)

return {
base: command === 'build' ? resolveBase(pluginConfig, assetUrl) : '',
publicDir: false,
Expand Down Expand Up @@ -202,6 +204,31 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
}
}

/**
* Validate the command can run in the given environment.
*/
function ensureCommandShouldRunInEnvironment(command: 'build'|'serve', env: Record<string, string>): void {
if (command === 'build' || env.LARAVEL_BYPASS_ENV_CHECK === '1') {
return;
}

if (typeof env.LARAVEL_VAPOR !== 'undefined') {
throw Error('You should not run the Vite HMR server on Vapor. You should build your assets for production instead.');
}

if (typeof env.LARAVEL_FORGE !== 'undefined') {
throw Error('You should not run the Vite HMR server in your Forge deployment script. You should build your assets for production instead.');
}

if (typeof env.LARAVEL_ENVOYER !== 'undefined') {
throw Error('You should not run the Vite HMR server in your Envoyer hook. You should build your assets for production instead.');
}

if (typeof env.CI !== 'undefined') {
throw Error('You should not run the Vite HMR server in CI environments. You should build your assets for production instead.');
}
}

/**
* The version of Laravel being run.
*/
Expand Down

0 comments on commit 7ec7c0a

Please sign in to comment.