-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dev): use Vite instead of esbuild, also Vitest (#416)
This is _yet another_ change in how we generate features/templates. The story have been to use esbuild, then ts-morph, back to esbuild and now Vite. We use the Vite devServer directly to handle compiling the code so we can import the template module to get the config off of it. This change also replaces Jest with Vitest, which allows the testing of esmodules much more easily. It was also required in order to actually run Vite in some tests. --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
Showing
46 changed files
with
572 additions
and
2,160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,38 @@ SOFTWARE. | |
|
||
----------- | ||
|
||
The following npm package may be included in this product: | ||
|
||
- [email protected] | ||
|
||
This package contains the following license and notice below: | ||
|
||
Copyright (c) 2015, Scott Motte | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
----------- | ||
|
||
The following npm package may be included in this product: | ||
|
||
- [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 1 addition & 19 deletions
20
packages/pages/src/common/src/function/internal/loader.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/pages/src/common/src/function/internal/validateFunctionModule.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { InlineConfig, createServer } from "vite"; | ||
import { ProjectStructure } from "../project/structure.js"; | ||
import { processEnvVariables } from "../../../util/processEnvVariables.js"; | ||
import { pathToFileURL } from "node:url"; | ||
import { loadViteModule } from "../../../dev/server/ssr/loadViteModule.js"; | ||
|
||
export const getViteServerConfig = ( | ||
projectStructure: ProjectStructure | ||
): InlineConfig => { | ||
return { | ||
server: { | ||
middlewareMode: true, | ||
}, | ||
appType: "custom", | ||
envDir: projectStructure.config.envVarConfig.envVarDir, | ||
envPrefix: projectStructure.config.envVarConfig.envVarPrefix, | ||
define: processEnvVariables( | ||
projectStructure.config.envVarConfig.envVarPrefix | ||
), | ||
optimizeDeps: { | ||
include: ["react-dom", "react-dom/client"], | ||
}, | ||
}; | ||
}; | ||
|
||
export type ImportedModule = { | ||
path: string; | ||
module: any; | ||
}; | ||
|
||
/** | ||
* Loads any files as modules. | ||
* | ||
* @param modulePaths the filepaths to load as modules | ||
* @param transpile set to true if the paths need to be transpiled (such as when they are in tsx format) | ||
* @returns Promise<{@link ImportedModule[]}> | ||
*/ | ||
export const loadModules = async ( | ||
modulePaths: string[], | ||
transpile: boolean, | ||
projectStructure: ProjectStructure | ||
): Promise<ImportedModule[]> => { | ||
const importedModules: ImportedModule[] = []; | ||
|
||
if (transpile) { | ||
// Note that this will log inconsequential errors | ||
// See https://github.com/vitejs/vite/issues/14328 | ||
const vite = await createServer(getViteServerConfig(projectStructure)); | ||
|
||
for (const modulePath of modulePaths) { | ||
const functionModule = await loadViteModule(vite, modulePath); | ||
|
||
importedModules.push({ | ||
path: modulePath, | ||
module: functionModule, | ||
}); | ||
} | ||
|
||
await vite.close(); | ||
} else { | ||
for (const modulePath of modulePaths) { | ||
importedModules.push({ | ||
path: modulePath, | ||
module: await import(pathToFileURL(modulePath).toString()), | ||
}); | ||
} | ||
} | ||
|
||
return importedModules; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.