diff --git a/Resources/Private/ViteConfigTemplates/glob.vite.config.js b/Resources/Private/ViteConfigTemplates/glob.vite.config.js index 6d3c9c1..0ac16a4 100644 --- a/Resources/Private/ViteConfigTemplates/glob.vite.config.js +++ b/Resources/Private/ViteConfigTemplates/glob.vite.config.js @@ -16,8 +16,8 @@ const VITE_OUTPUT_PATH = 'public/_assets/vite/'; // ------------------------------------------------------ // Base URL that will be prepended to all referenced assets in dev mode -// e. g// Set this to the URL of your vite dev server, -. https://myproject.ddev.site:5173 +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 const VITE_DEV_ORIGIN = ''; // Ignored patterns to speed up globbing diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/configForExtension.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/configForExtension.vite.config.js index c812d95..67e520b 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/configForExtension.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/configForExtension.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "Resources/Public/Vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointExtensionPath.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointExtensionPath.vite.config.js index 62f944e..d94184a 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointExtensionPath.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointExtensionPath.vite.config.js @@ -12,6 +12,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -23,4 +28,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointFileadmin.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointFileadmin.vite.config.js index 7e07c7c..81e7503 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointFileadmin.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointFileadmin.vite.config.js @@ -12,6 +12,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -23,4 +28,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/globEntrypoint.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/globEntrypoint.vite.config.js index b4007ca..c95401a 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/globEntrypoint.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/globEntrypoint.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + // Ignored patterns to speed up globbing const VITE_PATTERN_IGNORE = ['**/node_modules/**', '**/.git/**']; @@ -30,4 +35,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/multipleEntrypoints.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/multipleEntrypoints.vite.config.js index 96b5710..421cb1e 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/multipleEntrypoints.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/multipleEntrypoints.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/withoutEntrypoints.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/withoutEntrypoints.vite.config.js index 17708b3..ccf9adb 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/withoutEntrypoints.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/withoutEntrypoints.vite.config.js @@ -12,6 +12,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -23,4 +28,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/configForExtension.vite.config.js b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/configForExtension.vite.config.js index 3f022d1..3289c26 100644 --- a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/configForExtension.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/configForExtension.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "Resources/Public/Vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inExtensionRoot.vite.config.js b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inExtensionRoot.vite.config.js index dd152bf..1195afa 100644 --- a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inExtensionRoot.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inExtensionRoot.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inNonExistingSubfolder.vite.config.js b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inNonExistingSubfolder.vite.config.js index 7553a3c..81926ac 100644 --- a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inNonExistingSubfolder.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inNonExistingSubfolder.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRoot.vite.config.js b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRoot.vite.config.js index 4b2595b..848c1ff 100644 --- a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRoot.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRoot.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRootBeforeOverwrite.vite.config.js b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRootBeforeOverwrite.vite.config.js index 17708b3..ccf9adb 100644 --- a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRootBeforeOverwrite.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRootBeforeOverwrite.vite.config.js @@ -12,6 +12,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -23,4 +28,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Functional/Command/ViteConfigCommandTest.php b/Tests/Functional/Command/ViteConfigCommandTest.php index 161910c..5b25d9e 100644 --- a/Tests/Functional/Command/ViteConfigCommandTest.php +++ b/Tests/Functional/Command/ViteConfigCommandTest.php @@ -33,6 +33,15 @@ public function setUp(): void } } + public function tearDown(): void + { + // Delete config file from overwriteConfigFile() test + $overwriteConfigFile = self::getInstancePath() . '/vite.config.js'; + if (file_exists($overwriteConfigFile)) { + unlink($overwriteConfigFile); + } + } + public static function outputConfigDataProvider(): array { return [ @@ -255,7 +264,11 @@ public function overwriteConfigFile(): void $input = ['--outputfile' => './vite.config.js']; $output = new BufferedOutput(); $command->run(new ArrayInput($input, $command->getDefinition()), $output); - self::assertEquals(sprintf("Vite config has been written to %s.\n", $outputFile), $output->fetch()); + self::assertEquals( + sprintf("Vite config has been written to %s.\n", $outputFile), + $output->fetch(), + 'Initial file can be written' + ); self::assertEquals( $expectedFirstResult, file_get_contents($outputFile), @@ -268,7 +281,11 @@ public function overwriteConfigFile(): void ]; $output = new BufferedOutput(); $command->run(new ArrayInput($input, $command->getDefinition()), $output); - self::assertEquals(sprintf("Output file %s already exists. Use --force if you want to overwrite the existing file.\n", $outputFile), $output->fetch()); + self::assertEquals( + sprintf("Output file %s already exists. Use --force if you want to overwrite the existing file.\n", $outputFile), + $output->fetch(), + 'Overwrite attempt without force option' + ); self::assertEquals( $expectedFirstResult, file_get_contents($outputFile), @@ -278,7 +295,11 @@ public function overwriteConfigFile(): void $input['--force'] = null; $output = new BufferedOutput(); $command->run(new ArrayInput($input, $command->getDefinition()), $output); - self::assertEquals(sprintf("Vite config has been written to %s.\n", $outputFile), $output->fetch()); + self::assertEquals( + sprintf("Vite config has been written to %s.\n", $outputFile), + $output->fetch(), + 'Overwrite attempt with force option' + ); self::assertEquals( $expectedLaterResult, file_get_contents($outputFile),