Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.6.x] Fail running HMR in known environments #128

Merged
merged 7 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -98,6 +98,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 @@ -197,6 +199,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