From c01431e456dff0ce6ebdf3fedee66fe0d57fcee8 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 25 Aug 2022 15:44:43 +1000 Subject: [PATCH 1/7] fail in known environments --- src/index.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/index.ts b/src/index.ts index b890d99..74ac3c4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -98,6 +98,8 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug const env = loadEnv(mode, userConfig.envDir || process.cwd(), '') const assetUrl = env.ASSET_URL ?? '' + validateCommandOnEnvironment(command, env) + return { base: command === 'build' ? resolveBase(pluginConfig, assetUrl) : '', publicDir: false, @@ -197,6 +199,27 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug } } +/** + * Validate the command can run in the given environment. + */ +function validateCommandOnEnvironment(command: 'build'|'serve', env: Record): void { + if (command === 'build') { + return; + } + + if (typeof env.VAPOR_SSM_PATH !== 'undefined') { + throw Error('You should not run the Vite HMR server (`npm run dev`) on Vapor. Instead you should run `npm run build`.'); + } + + if (typeof env.FORGE_PHP !== 'undefined') { + throw Error('You should not run the Vite HMR server (`npm run dev`) in your Forge deployment script. Instead you should run `npm run build`.'); + } + + if (typeof env.CI !== 'undefined') { + throw Error('You should not run the Vite HMR server (`npm run dev`) in CI. Instead you should run `npm run build`.'); + } +} + /** * The version of Laravel being run. */ From 3a908fd80d0f9f219e522b5dd9d5ae2d394d9ea1 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 25 Aug 2022 15:46:21 +1000 Subject: [PATCH 2/7] Allow bypassing env validation --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 74ac3c4..5bcef2b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -203,7 +203,7 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug * Validate the command can run in the given environment. */ function validateCommandOnEnvironment(command: 'build'|'serve', env: Record): void { - if (command === 'build') { + if (command === 'build' || env.LARAVEL_BYPASS_ENV_CHECK === '1') { return; } From 1d7db575336750194c1f9ef97da469b2d48ff26e Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 25 Aug 2022 16:28:36 +1000 Subject: [PATCH 3/7] update the Forge env --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 5bcef2b..3f38216 100644 --- a/src/index.ts +++ b/src/index.ts @@ -211,7 +211,7 @@ function validateCommandOnEnvironment(command: 'build'|'serve', env: Record Date: Thu, 25 Aug 2022 16:44:25 +1000 Subject: [PATCH 4/7] bypass env check for tests --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8eddf00..a1a358e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,6 +6,9 @@ on: schedule: - cron: '0 0 * * *' +env: + LARAVEL_BYPASS_ENV_CHECK: 1 + jobs: tests: runs-on: ubuntu-latest From 9c0574a87c673309c334b9a7adc3c67d158ac1af Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Fri, 26 Aug 2022 10:17:55 +1000 Subject: [PATCH 5/7] naming --- src/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3f38216..1457c48 100644 --- a/src/index.ts +++ b/src/index.ts @@ -98,7 +98,7 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug const env = loadEnv(mode, userConfig.envDir || process.cwd(), '') const assetUrl = env.ASSET_URL ?? '' - validateCommandOnEnvironment(command, env) + ensureCommandShouldRunInEnvironment(command, env) return { base: command === 'build' ? resolveBase(pluginConfig, assetUrl) : '', @@ -202,21 +202,21 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug /** * Validate the command can run in the given environment. */ -function validateCommandOnEnvironment(command: 'build'|'serve', env: Record): void { +function ensureCommandShouldRunInEnvironment(command: 'build'|'serve', env: Record): void { if (command === 'build' || env.LARAVEL_BYPASS_ENV_CHECK === '1') { return; } if (typeof env.VAPOR_SSM_PATH !== 'undefined') { - throw Error('You should not run the Vite HMR server (`npm run dev`) on Vapor. Instead you should run `npm run build`.'); + 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 (`npm run dev`) in your Forge deployment script. Instead you should run `npm run build`.'); + 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.CI !== 'undefined') { - throw Error('You should not run the Vite HMR server (`npm run dev`) in CI. Instead you should run `npm run build`.'); + throw Error('You should not run the Vite HMR server in CI environments. You should build your assets for production instead.'); } } From 963140930130126c8b17bd403109be14562a7f14 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 7 Sep 2022 18:17:11 +1000 Subject: [PATCH 6/7] rename vapor env --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 1457c48..074a71a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -207,7 +207,7 @@ function ensureCommandShouldRunInEnvironment(command: 'build'|'serve', env: Reco return; } - if (typeof env.VAPOR_SSM_PATH !== 'undefined') { + 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.'); } From 2be1b56ce49be0e3a2d6b980db047ab7480cbfd2 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Tue, 13 Sep 2022 11:58:05 +1000 Subject: [PATCH 7/7] fail on envoyer --- src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.ts b/src/index.ts index 074a71a..1200794 100644 --- a/src/index.ts +++ b/src/index.ts @@ -215,6 +215,10 @@ function ensureCommandShouldRunInEnvironment(command: 'build'|'serve', env: Reco 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.'); }