@cedarjs/vite 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/bins/rw-vite-build.mjs +61 -0
- package/bins/rw-vite-dev.mjs +57 -0
- package/bins/vite.mjs +12 -0
- package/dist/build/build.d.ts +21 -0
- package/dist/build/build.d.ts.map +1 -0
- package/dist/build/build.js +78 -0
- package/dist/buildFeServer.d.ts +6 -0
- package/dist/buildFeServer.d.ts.map +1 -0
- package/dist/buildFeServer.js +39 -0
- package/dist/buildRouteHooks.d.ts +3 -0
- package/dist/buildRouteHooks.d.ts.map +1 -0
- package/dist/buildRouteHooks.js +45 -0
- package/dist/buildRouteManifest.d.ts +6 -0
- package/dist/buildRouteManifest.d.ts.map +1 -0
- package/dist/buildRouteManifest.js +58 -0
- package/dist/buildRscClientAndServer.d.ts +4 -0
- package/dist/buildRscClientAndServer.d.ts.map +1 -0
- package/dist/buildRscClientAndServer.js +30 -0
- package/dist/bundled/react-server-dom-webpack.server.d.ts +2 -0
- package/dist/bundled/react-server-dom-webpack.server.d.ts.map +1 -0
- package/dist/bundled/react-server-dom-webpack.server.js +33529 -0
- package/dist/cjs/ClientRouter.d.ts +1 -0
- package/dist/cjs/build/build.d.ts +1 -0
- package/dist/cjs/build/build.js +116 -0
- package/dist/cjs/buildFeServer.d.ts +1 -0
- package/dist/cjs/buildFeServer.js +63 -0
- package/dist/cjs/buildRouteHooks.js +66 -0
- package/dist/cjs/buildRouteManifest.js +92 -0
- package/dist/cjs/buildRscClientAndServer.js +54 -0
- package/dist/cjs/client.d.ts +1 -0
- package/dist/cjs/clientSsr.d.ts +1 -0
- package/dist/cjs/devFeServer.js +153 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +184 -0
- package/dist/cjs/lib/StatusError.js +36 -0
- package/dist/cjs/lib/entries.js +53 -0
- package/dist/cjs/lib/envVarDefinitions.js +87 -0
- package/dist/cjs/lib/getMergedConfig.js +187 -0
- package/dist/cjs/lib/onWarn.js +36 -0
- package/dist/cjs/lib/registerFwGlobalsAndShims.js +117 -0
- package/dist/cjs/middleware/index.js +22 -0
- package/dist/cjs/middleware/invokeMiddleware.js +52 -0
- package/dist/cjs/middleware/register.js +106 -0
- package/dist/cjs/middleware/types.js +16 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/plugins/vite-plugin-jsx-loader.js +42 -0
- package/dist/cjs/plugins/vite-plugin-remove-from-bundle.js +56 -0
- package/dist/cjs/plugins/vite-plugin-rsc-analyze.js +104 -0
- package/dist/cjs/plugins/vite-plugin-rsc-reload.js +75 -0
- package/dist/cjs/plugins/vite-plugin-rsc-routes-auto-loader.js +159 -0
- package/dist/cjs/plugins/vite-plugin-rsc-routes-imports.js +125 -0
- package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +75 -0
- package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +229 -0
- package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +398 -0
- package/dist/cjs/plugins/vite-plugin-swap-apollo-provider.js +41 -0
- package/dist/cjs/rsc/rscBuildAnalyze.js +116 -0
- package/dist/cjs/rsc/rscBuildClient.js +91 -0
- package/dist/cjs/rsc/rscBuildCopyCssAssets.js +56 -0
- package/dist/cjs/rsc/rscBuildEntriesFile.js +115 -0
- package/dist/cjs/rsc/rscBuildForServer.js +157 -0
- package/dist/cjs/rsc/rscBuildForSsr.js +172 -0
- package/dist/cjs/rsc/rscBuildRwEnvVars.js +56 -0
- package/dist/cjs/rsc/rscRenderer.js +165 -0
- package/dist/cjs/rsc/rscRequestHandler.js +162 -0
- package/dist/cjs/rsc/rscStudioHandlers.js +154 -0
- package/dist/cjs/runFeServer.js +166 -0
- package/dist/cjs/streaming/buildForStreamingServer.js +65 -0
- package/dist/cjs/streaming/collectCss.js +52 -0
- package/dist/cjs/streaming/createReactStreamingHandler.js +173 -0
- package/dist/cjs/streaming/streamHelpers.js +228 -0
- package/dist/cjs/streaming/transforms/bufferedTransform.js +61 -0
- package/dist/cjs/streaming/transforms/cancelTimeoutTransform.js +34 -0
- package/dist/cjs/streaming/transforms/encode-decode.js +36 -0
- package/dist/cjs/streaming/transforms/serverInjectionTransform.js +84 -0
- package/dist/cjs/streaming/triggerRouteHooks.js +96 -0
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/utils.js +91 -0
- package/dist/devFeServer.d.ts +2 -0
- package/dist/devFeServer.d.ts.map +1 -0
- package/dist/devFeServer.js +134 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +154 -0
- package/dist/lib/StatusError.d.ts +8 -0
- package/dist/lib/StatusError.d.ts.map +1 -0
- package/dist/lib/StatusError.js +11 -0
- package/dist/lib/entries.d.ts +3 -0
- package/dist/lib/entries.d.ts.map +1 -0
- package/dist/lib/entries.js +32 -0
- package/dist/lib/envVarDefinitions.d.ts +14 -0
- package/dist/lib/envVarDefinitions.d.ts.map +1 -0
- package/dist/lib/envVarDefinitions.js +53 -0
- package/dist/lib/getMergedConfig.d.ts +11 -0
- package/dist/lib/getMergedConfig.d.ts.map +1 -0
- package/dist/lib/getMergedConfig.js +153 -0
- package/dist/lib/onWarn.d.ts +3 -0
- package/dist/lib/onWarn.d.ts.map +1 -0
- package/dist/lib/onWarn.js +12 -0
- package/dist/lib/registerFwGlobalsAndShims.d.ts +12 -0
- package/dist/lib/registerFwGlobalsAndShims.d.ts.map +1 -0
- package/dist/lib/registerFwGlobalsAndShims.js +83 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +1 -0
- package/dist/middleware/invokeMiddleware.d.ts +14 -0
- package/dist/middleware/invokeMiddleware.d.ts.map +1 -0
- package/dist/middleware/invokeMiddleware.js +32 -0
- package/dist/middleware/register.d.ts +23 -0
- package/dist/middleware/register.d.ts.map +1 -0
- package/dist/middleware/register.js +69 -0
- package/dist/middleware/types.d.ts +3 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/middleware/types.js +0 -0
- package/dist/package.json +1 -0
- package/dist/plugins/vite-plugin-jsx-loader.d.ts +8 -0
- package/dist/plugins/vite-plugin-jsx-loader.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-jsx-loader.js +18 -0
- package/dist/plugins/vite-plugin-remove-from-bundle.d.ts +17 -0
- package/dist/plugins/vite-plugin-remove-from-bundle.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-remove-from-bundle.js +31 -0
- package/dist/plugins/vite-plugin-rsc-analyze.d.ts +3 -0
- package/dist/plugins/vite-plugin-rsc-analyze.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-rsc-analyze.js +70 -0
- package/dist/plugins/vite-plugin-rsc-reload.d.ts +3 -0
- package/dist/plugins/vite-plugin-rsc-reload.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-rsc-reload.js +41 -0
- package/dist/plugins/vite-plugin-rsc-routes-auto-loader.d.ts +3 -0
- package/dist/plugins/vite-plugin-rsc-routes-auto-loader.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-rsc-routes-auto-loader.js +130 -0
- package/dist/plugins/vite-plugin-rsc-routes-imports.d.ts +3 -0
- package/dist/plugins/vite-plugin-rsc-routes-imports.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-rsc-routes-imports.js +96 -0
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts +7 -0
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.js +41 -0
- package/dist/plugins/vite-plugin-rsc-transform-client.d.ts +3 -0
- package/dist/plugins/vite-plugin-rsc-transform-client.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-rsc-transform-client.js +195 -0
- package/dist/plugins/vite-plugin-rsc-transform-server.d.ts +3 -0
- package/dist/plugins/vite-plugin-rsc-transform-server.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-rsc-transform-server.js +364 -0
- package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts +12 -0
- package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-swap-apollo-provider.js +17 -0
- package/dist/rsc/rscBuildAnalyze.d.ts +16 -0
- package/dist/rsc/rscBuildAnalyze.d.ts.map +1 -0
- package/dist/rsc/rscBuildAnalyze.js +92 -0
- package/dist/rsc/rscBuildClient.d.ts +7 -0
- package/dist/rsc/rscBuildClient.d.ts.map +1 -0
- package/dist/rsc/rscBuildClient.js +67 -0
- package/dist/rsc/rscBuildCopyCssAssets.d.ts +7 -0
- package/dist/rsc/rscBuildCopyCssAssets.d.ts.map +1 -0
- package/dist/rsc/rscBuildCopyCssAssets.js +22 -0
- package/dist/rsc/rscBuildEntriesFile.d.ts +10 -0
- package/dist/rsc/rscBuildEntriesFile.d.ts.map +1 -0
- package/dist/rsc/rscBuildEntriesFile.js +81 -0
- package/dist/rsc/rscBuildForServer.d.ts +7 -0
- package/dist/rsc/rscBuildForServer.d.ts.map +1 -0
- package/dist/rsc/rscBuildForServer.js +133 -0
- package/dist/rsc/rscBuildForSsr.d.ts +9 -0
- package/dist/rsc/rscBuildForSsr.d.ts.map +1 -0
- package/dist/rsc/rscBuildForSsr.js +138 -0
- package/dist/rsc/rscBuildRwEnvVars.d.ts +10 -0
- package/dist/rsc/rscBuildRwEnvVars.d.ts.map +1 -0
- package/dist/rsc/rscBuildRwEnvVars.js +22 -0
- package/dist/rsc/rscRenderer.d.ts +9 -0
- package/dist/rsc/rscRenderer.d.ts.map +1 -0
- package/dist/rsc/rscRenderer.js +130 -0
- package/dist/rsc/rscRequestHandler.d.ts +10 -0
- package/dist/rsc/rscRequestHandler.d.ts.map +1 -0
- package/dist/rsc/rscRequestHandler.js +131 -0
- package/dist/rsc/rscStudioHandlers.d.ts +10 -0
- package/dist/rsc/rscStudioHandlers.d.ts.map +1 -0
- package/dist/rsc/rscStudioHandlers.js +120 -0
- package/dist/runFeServer.d.ts +2 -0
- package/dist/runFeServer.d.ts.map +1 -0
- package/dist/runFeServer.js +132 -0
- package/dist/streaming/buildForStreamingServer.d.ts +4 -0
- package/dist/streaming/buildForStreamingServer.d.ts.map +1 -0
- package/dist/streaming/buildForStreamingServer.js +41 -0
- package/dist/streaming/collectCss.d.ts +7 -0
- package/dist/streaming/collectCss.d.ts.map +1 -0
- package/dist/streaming/collectCss.js +27 -0
- package/dist/streaming/createReactStreamingHandler.d.ts +12 -0
- package/dist/streaming/createReactStreamingHandler.d.ts.map +1 -0
- package/dist/streaming/createReactStreamingHandler.js +139 -0
- package/dist/streaming/streamHelpers.d.ts +23 -0
- package/dist/streaming/streamHelpers.d.ts.map +1 -0
- package/dist/streaming/streamHelpers.js +192 -0
- package/dist/streaming/transforms/bufferedTransform.d.ts +2 -0
- package/dist/streaming/transforms/bufferedTransform.d.ts.map +1 -0
- package/dist/streaming/transforms/bufferedTransform.js +37 -0
- package/dist/streaming/transforms/cancelTimeoutTransform.d.ts +2 -0
- package/dist/streaming/transforms/cancelTimeoutTransform.d.ts.map +1 -0
- package/dist/streaming/transforms/cancelTimeoutTransform.js +10 -0
- package/dist/streaming/transforms/encode-decode.d.ts +3 -0
- package/dist/streaming/transforms/encode-decode.d.ts.map +1 -0
- package/dist/streaming/transforms/encode-decode.js +11 -0
- package/dist/streaming/transforms/serverInjectionTransform.d.ts +16 -0
- package/dist/streaming/transforms/serverInjectionTransform.d.ts.map +1 -0
- package/dist/streaming/transforms/serverInjectionTransform.js +60 -0
- package/dist/streaming/triggerRouteHooks.d.ts +26 -0
- package/dist/streaming/triggerRouteHooks.d.ts.map +1 -0
- package/dist/streaming/triggerRouteHooks.js +71 -0
- package/dist/types.d.ts +31 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +0 -0
- package/dist/utils.d.ts +14 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +62 -0
- package/inject/reactRefresh.js +7 -0
- package/package.json +116 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Cedar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
|
|
4
|
+
import yargsParser from 'yargs-parser'
|
|
5
|
+
|
|
6
|
+
import { getConfig, getPaths } from '@cedarjs/project-config'
|
|
7
|
+
import { buildWeb } from '@cedarjs/vite/build'
|
|
8
|
+
import { buildFeServer } from '@cedarjs/vite/buildFeServer'
|
|
9
|
+
|
|
10
|
+
const rwPaths = getPaths()
|
|
11
|
+
|
|
12
|
+
const { webDir, verbose } = yargsParser(process.argv.slice(2), {
|
|
13
|
+
string: ['webDir'],
|
|
14
|
+
boolean: ['verbose'],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
if (!webDir) {
|
|
18
|
+
console.error(
|
|
19
|
+
'Please pass the full path to the web side using the --webDir argument',
|
|
20
|
+
)
|
|
21
|
+
process.exit(1)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!fs.existsSync(webDir)) {
|
|
25
|
+
console.error(`Could not find web directory at ${webDir}`)
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!fs.existsSync(`${webDir}/package.json`)) {
|
|
30
|
+
console.error(`${webDir} does not appear to be a Redwood web directory`)
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Build the web side of a Redwood project using Vite
|
|
36
|
+
* @param {string} webDir - The path to the web side of the project
|
|
37
|
+
*/
|
|
38
|
+
const buildWebSide = async (webDir) => {
|
|
39
|
+
const configFile = rwPaths.web.viteConfig
|
|
40
|
+
|
|
41
|
+
if (!configFile) {
|
|
42
|
+
throw new Error('Could not locate your web/vite.config.{js,ts} file')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!process.env.NODE_ENV) {
|
|
46
|
+
process.env.NODE_ENV = 'production'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (getConfig().experimental?.streamingSsr?.enabled) {
|
|
50
|
+
// Webdir checks handled in the rwjs/vite package in new build system
|
|
51
|
+
await buildFeServer({ verbose, webDir })
|
|
52
|
+
} else {
|
|
53
|
+
// Ensure cwd to be web: required for postcss/tailwind to work correctly
|
|
54
|
+
process.chdir(webDir)
|
|
55
|
+
// Right now, the buildWeb function looks up the config file from project-config
|
|
56
|
+
// In the future, if we have multiple web spaces we could pass in the cwd here
|
|
57
|
+
buildWeb({ verbose })
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
buildWebSide(webDir)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createServer } from 'vite'
|
|
3
|
+
import yargsParser from 'yargs-parser'
|
|
4
|
+
|
|
5
|
+
import { getPaths } from '@cedarjs/project-config'
|
|
6
|
+
|
|
7
|
+
const rwPaths = getPaths()
|
|
8
|
+
|
|
9
|
+
const startDevServer = async () => {
|
|
10
|
+
const configFile = rwPaths.web.viteConfig
|
|
11
|
+
|
|
12
|
+
if (!configFile) {
|
|
13
|
+
throw new Error('Could not locate your web/vite.config.{js,ts} file')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Tries to maintain the same options as vite's dev cli
|
|
17
|
+
// See here: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/cli.ts#L103
|
|
18
|
+
// e.g. yarn rw dev web --fwd="--force"
|
|
19
|
+
const {
|
|
20
|
+
force: forceOptimize,
|
|
21
|
+
forwardedServerArgs,
|
|
22
|
+
debug,
|
|
23
|
+
} = yargsParser(process.argv.slice(2), {
|
|
24
|
+
boolean: ['https', 'open', 'strictPort', 'force', 'cors', 'debug'],
|
|
25
|
+
number: ['port'],
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const devServer = await createServer({
|
|
29
|
+
configFile,
|
|
30
|
+
envFile: false, // env file is handled by plugins in the redwood-vite plugin
|
|
31
|
+
optimizeDeps: {
|
|
32
|
+
// This is the only value that isn't a server option
|
|
33
|
+
force: forceOptimize,
|
|
34
|
+
},
|
|
35
|
+
server: forwardedServerArgs,
|
|
36
|
+
logLevel: debug ? 'info' : undefined,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
await devServer.listen()
|
|
40
|
+
|
|
41
|
+
process.stdin.on('data', async (data) => {
|
|
42
|
+
const str = data.toString().trim().toLowerCase()
|
|
43
|
+
if (str === 'rs' || str === 'restart') {
|
|
44
|
+
await devServer.restart(true)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
devServer.printUrls()
|
|
49
|
+
|
|
50
|
+
if (debug) {
|
|
51
|
+
console.log('~~~ Vite Server Config ~~~')
|
|
52
|
+
console.log(JSON.stringify(devServer.config, ' ', 2))
|
|
53
|
+
console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~')
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
startDevServer()
|
package/bins/vite.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'module'
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url)
|
|
5
|
+
const vitePath = require.resolve('vite/package.json')
|
|
6
|
+
const requireFromVite = createRequire(vitePath)
|
|
7
|
+
|
|
8
|
+
const bins = requireFromVite('./package.json')['bin']
|
|
9
|
+
|
|
10
|
+
// @MARK: This is temporary hack, speak to Dom about this...
|
|
11
|
+
// What is the correct way to proxy a bin with yarn 3 when its a ES module?
|
|
12
|
+
import(`${vitePath.replace('package.json', '')}/${bins['vite']}`)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as babel from '@babel/core';
|
|
2
|
+
import type { Flags } from '@cedarjs/babel-config';
|
|
3
|
+
export declare const cleanWebBuild: () => void;
|
|
4
|
+
export declare function prebuildWebFile(srcPath: string, flags?: Flags): Promise<babel.BabelFileResult | null>;
|
|
5
|
+
export declare function transform(srcPath: string): Promise<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Remove RedwoodJS "magic" from a user's code leaving JavaScript behind.
|
|
8
|
+
*
|
|
9
|
+
* Currently only used for debugging purposes
|
|
10
|
+
*/
|
|
11
|
+
export declare const prebuildWebFiles: (srcFiles: string[], flags?: Flags) => Promise<(string | undefined)[]>;
|
|
12
|
+
interface BuildOptions {
|
|
13
|
+
verbose?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Builds the web side with Vite, but not used in the buildHandler currently
|
|
17
|
+
* because we want to set the process.cwd to web.base
|
|
18
|
+
*/
|
|
19
|
+
export declare const buildWeb: ({ verbose }: BuildOptions) => Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build/build.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,aAAa,CAAA;AAIpC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAIlD,eAAO,MAAM,aAAa,YAIzB,CAAA;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,KAAU,yCAUvE;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,MAAM,mBAS9C;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,aAAoB,MAAM,EAAE,UAAU,KAAK,oCA8BvE,CAAA;AAED,UAAU,YAAY;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,gBAAuB,YAAY,8GAoBvD,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import * as babel from "@babel/core";
|
|
4
|
+
import fse from "fs-extra";
|
|
5
|
+
import { transformWithEsbuild } from "vite";
|
|
6
|
+
import { getWebSideDefaultBabelConfig } from "@cedarjs/babel-config";
|
|
7
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
8
|
+
const cleanWebBuild = () => {
|
|
9
|
+
const rwjsPaths = getPaths();
|
|
10
|
+
fse.removeSync(rwjsPaths.web.dist);
|
|
11
|
+
fse.removeSync(path.join(rwjsPaths.generated.prebuild, "web"));
|
|
12
|
+
};
|
|
13
|
+
async function prebuildWebFile(srcPath, flags = {}) {
|
|
14
|
+
const code = fs.readFileSync(srcPath, "utf-8");
|
|
15
|
+
const config = getWebSideDefaultBabelConfig(flags);
|
|
16
|
+
const result = babel.transform(code, {
|
|
17
|
+
...config,
|
|
18
|
+
cwd: getPaths().web.base,
|
|
19
|
+
filename: srcPath
|
|
20
|
+
});
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
async function transform(srcPath) {
|
|
24
|
+
const code = fs.readFileSync(srcPath, "utf-8");
|
|
25
|
+
const loader = path.extname(srcPath).match(/^\.m?ts/) ? "tsx" : "jsx";
|
|
26
|
+
const transformed = await transformWithEsbuild(code, srcPath, {
|
|
27
|
+
loader
|
|
28
|
+
});
|
|
29
|
+
return transformed.code;
|
|
30
|
+
}
|
|
31
|
+
const prebuildWebFiles = async (srcFiles, flags) => {
|
|
32
|
+
const rwjsPaths = getPaths();
|
|
33
|
+
const processFile = async (srcPath) => {
|
|
34
|
+
const relativePathFromSrc = path.relative(rwjsPaths.base, srcPath);
|
|
35
|
+
const dstPath = path.join(rwjsPaths.generated.prebuild, relativePathFromSrc).replace(/\.(ts)$/, ".js");
|
|
36
|
+
try {
|
|
37
|
+
const result = await prebuildWebFile(srcPath, flags);
|
|
38
|
+
if (!result?.code) {
|
|
39
|
+
throw new Error("No code returned from prebuildWebFile");
|
|
40
|
+
}
|
|
41
|
+
fs.mkdirSync(path.dirname(dstPath), { recursive: true });
|
|
42
|
+
fs.writeFileSync(dstPath, result.code);
|
|
43
|
+
} catch {
|
|
44
|
+
console.warn("Error:", srcPath, "could not prebuilt.");
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
return dstPath;
|
|
48
|
+
};
|
|
49
|
+
const promises = [];
|
|
50
|
+
for (const srcPath of srcFiles) {
|
|
51
|
+
promises.push(processFile(srcPath));
|
|
52
|
+
}
|
|
53
|
+
return await Promise.all(promises);
|
|
54
|
+
};
|
|
55
|
+
const buildWeb = async ({ verbose }) => {
|
|
56
|
+
const { build } = await import("vite");
|
|
57
|
+
const viteConfig = getPaths().web.viteConfig;
|
|
58
|
+
if (process.cwd() !== getPaths().web.base) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
"Looks like you are running the command from the wrong dir, this can lead to unintended consequences on CSS processing"
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (!viteConfig) {
|
|
64
|
+
throw new Error("Could not locate your web/vite.config.{js,ts} file");
|
|
65
|
+
}
|
|
66
|
+
return build({
|
|
67
|
+
configFile: viteConfig,
|
|
68
|
+
envFile: false,
|
|
69
|
+
logLevel: verbose ? "info" : "warn"
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
export {
|
|
73
|
+
buildWeb,
|
|
74
|
+
cleanWebBuild,
|
|
75
|
+
prebuildWebFile,
|
|
76
|
+
prebuildWebFiles,
|
|
77
|
+
transform
|
|
78
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildFeServer.d.ts","sourceRoot":"","sources":["../src/buildFeServer.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,aAAa,yBAA+B,YAAY,kBA0CpE,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
2
|
+
import { buildWeb } from "./build/build.js";
|
|
3
|
+
import { buildRouteHooks } from "./buildRouteHooks.js";
|
|
4
|
+
import { buildRouteManifest } from "./buildRouteManifest.js";
|
|
5
|
+
import { buildRscClientAndServer } from "./buildRscClientAndServer.js";
|
|
6
|
+
import { buildForStreamingServer } from "./streaming/buildForStreamingServer.js";
|
|
7
|
+
import { ensureProcessDirWeb } from "./utils.js";
|
|
8
|
+
const buildFeServer = async ({ verbose, webDir } = {}) => {
|
|
9
|
+
ensureProcessDirWeb(webDir);
|
|
10
|
+
const rwPaths = getPaths();
|
|
11
|
+
const rwConfig = getConfig();
|
|
12
|
+
const viteConfigPath = rwPaths.web.viteConfig;
|
|
13
|
+
const rscEnabled = rwConfig.experimental?.rsc?.enabled;
|
|
14
|
+
const streamingSsrEnabled = rwConfig.experimental?.streamingSsr?.enabled;
|
|
15
|
+
if (!viteConfigPath) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
"Vite config not found. You need to setup your project with Vite using `yarn rw setup vite`"
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
if (!rwPaths.web.entryServer || !rwPaths.web.entryClient) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
"Vite entry points not found. Please check that your project has an entry.client.{jsx,tsx} and entry.server.{jsx,tsx} file in the web/src directory."
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
if (rscEnabled) {
|
|
26
|
+
await buildRscClientAndServer({ verbose });
|
|
27
|
+
} else {
|
|
28
|
+
await buildForStreamingServer({ verbose });
|
|
29
|
+
}
|
|
30
|
+
if (streamingSsrEnabled && !rscEnabled) {
|
|
31
|
+
console.log("Building client for streaming SSR...\n");
|
|
32
|
+
await buildWeb({ verbose });
|
|
33
|
+
}
|
|
34
|
+
await buildRouteHooks(verbose, rwPaths);
|
|
35
|
+
await buildRouteManifest();
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
buildFeServer
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRouteHooks.d.ts","sourceRoot":"","sources":["../src/buildRouteHooks.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAGpD,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,OAAO,EAAE,KAAK,iBAuCf"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { build as esbuildBuild } from "esbuild";
|
|
2
|
+
import {
|
|
3
|
+
getRouteHookBabelPlugins,
|
|
4
|
+
transformWithBabel
|
|
5
|
+
} from "@cedarjs/babel-config";
|
|
6
|
+
import { findRouteHooksSrc } from "@cedarjs/internal/dist/files.js";
|
|
7
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
8
|
+
async function buildRouteHooks(verbose, rwPaths) {
|
|
9
|
+
const allRouteHooks = findRouteHooksSrc();
|
|
10
|
+
const runRwBabelTransformsPlugin = {
|
|
11
|
+
name: "rw-esbuild-babel-transform",
|
|
12
|
+
setup(build) {
|
|
13
|
+
build.onLoad({ filter: /\.(js|ts|tsx|jsx)$/ }, async (args) => {
|
|
14
|
+
const transformedCode = await transformWithBabel(args.path, [
|
|
15
|
+
...getRouteHookBabelPlugins()
|
|
16
|
+
]);
|
|
17
|
+
if (transformedCode?.code) {
|
|
18
|
+
return {
|
|
19
|
+
contents: transformedCode.code,
|
|
20
|
+
loader: "js"
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
throw new Error(`Could not transform file: ${args.path}`);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
await esbuildBuild({
|
|
28
|
+
absWorkingDir: getPaths().web.base,
|
|
29
|
+
entryPoints: allRouteHooks,
|
|
30
|
+
platform: "node",
|
|
31
|
+
target: "node16",
|
|
32
|
+
// @MARK Disable splitting and esm, because Redwood web modules don't support esm yet
|
|
33
|
+
// outExtension: { '.js': '.mjs' },
|
|
34
|
+
// format: 'esm',
|
|
35
|
+
// splitting: true,
|
|
36
|
+
bundle: true,
|
|
37
|
+
plugins: [runRwBabelTransformsPlugin],
|
|
38
|
+
packages: "external",
|
|
39
|
+
logLevel: verbose ? "info" : "error",
|
|
40
|
+
outdir: rwPaths.web.distRouteHooks
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
buildRouteHooks
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRouteManifest.d.ts","sourceRoot":"","sources":["../src/buildRouteManifest.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,wBAAsB,kBAAkB,kBAgDvC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import url from "node:url";
|
|
4
|
+
import { getProjectRoutes } from "@cedarjs/internal/dist/routes.js";
|
|
5
|
+
import { getAppRouteHook, getPaths } from "@cedarjs/project-config";
|
|
6
|
+
async function buildRouteManifest() {
|
|
7
|
+
const rwPaths = getPaths();
|
|
8
|
+
const buildManifestUrl = url.pathToFileURL(
|
|
9
|
+
path.join(getPaths().web.distBrowser, "client-build-manifest.json")
|
|
10
|
+
).href;
|
|
11
|
+
const clientBuildManifest = (await import(buildManifestUrl, { with: { type: "json" } })).default;
|
|
12
|
+
const routesList = getProjectRoutes();
|
|
13
|
+
const routeManifest = routesList.reduce((acc, route) => {
|
|
14
|
+
acc[route.pathDefinition] = {
|
|
15
|
+
name: route.name,
|
|
16
|
+
bundle: route.relativeFilePath ? (
|
|
17
|
+
// @TODO(RSC_DC): this no longer resolves to anything i.e. its always null
|
|
18
|
+
// Because the clientBuildManifest has no pages, because all pages are Server-components?
|
|
19
|
+
// This may be a non-issue, because RSC pages don't need a client bundle per page (or atleast not the same bundle)
|
|
20
|
+
clientBuildManifest[route.relativeFilePath]?.file ?? null
|
|
21
|
+
) : null,
|
|
22
|
+
matchRegexString: route.matchRegexString,
|
|
23
|
+
// NOTE this is the path definition, not the actual path
|
|
24
|
+
// E.g. /blog/post/{id:Int}
|
|
25
|
+
pathDefinition: route.pathDefinition,
|
|
26
|
+
hasParams: route.hasParams,
|
|
27
|
+
routeHooks: FIXME_constructRouteHookPath(route.routeHooks),
|
|
28
|
+
redirect: route.redirect ? {
|
|
29
|
+
to: route.redirect?.to,
|
|
30
|
+
permanent: false
|
|
31
|
+
} : null,
|
|
32
|
+
relativeFilePath: route.relativeFilePath,
|
|
33
|
+
isPrivate: route.isPrivate,
|
|
34
|
+
unauthenticated: route.unauthenticated,
|
|
35
|
+
roles: route.roles,
|
|
36
|
+
pageIdentifier: route.pageIdentifier
|
|
37
|
+
};
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
console.log("routeManifest", JSON.stringify(routeManifest, null, 2));
|
|
41
|
+
const webRouteManifest = rwPaths.web.routeManifest;
|
|
42
|
+
await fs.mkdir(rwPaths.web.distSsr, { recursive: true });
|
|
43
|
+
return fs.writeFile(webRouteManifest, JSON.stringify(routeManifest, null, 2));
|
|
44
|
+
}
|
|
45
|
+
const FIXME_constructRouteHookPath = (routeHookSrcPath) => {
|
|
46
|
+
const rwPaths = getPaths();
|
|
47
|
+
if (!routeHookSrcPath) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (getAppRouteHook()) {
|
|
51
|
+
return path.relative(rwPaths.web.src, routeHookSrcPath).replace(".ts", ".js");
|
|
52
|
+
} else {
|
|
53
|
+
return path.relative(path.join(rwPaths.web.src, "pages"), routeHookSrcPath).replace(".ts", ".js");
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
buildRouteManifest
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRscClientAndServer.d.ts","sourceRoot":"","sources":["../src/buildRscClientAndServer.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,uBAAuB,iBAEjC;IACD,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,kBAkCA,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { rscBuildAnalyze } from "./rsc/rscBuildAnalyze.js";
|
|
2
|
+
import { rscBuildClient } from "./rsc/rscBuildClient.js";
|
|
3
|
+
import { rscBuildCopyCssAssets } from "./rsc/rscBuildCopyCssAssets.js";
|
|
4
|
+
import { rscBuildEntriesMappings } from "./rsc/rscBuildEntriesFile.js";
|
|
5
|
+
import { rscBuildForServer } from "./rsc/rscBuildForServer.js";
|
|
6
|
+
import { rscBuildForSsr } from "./rsc/rscBuildForSsr.js";
|
|
7
|
+
import { rscBuildRwEnvVars } from "./rsc/rscBuildRwEnvVars.js";
|
|
8
|
+
const buildRscClientAndServer = async ({
|
|
9
|
+
verbose = false
|
|
10
|
+
}) => {
|
|
11
|
+
const { clientEntryFiles, serverEntryFiles } = await rscBuildAnalyze();
|
|
12
|
+
const clientBuildOutput = await rscBuildClient(clientEntryFiles);
|
|
13
|
+
const ssrBuildOutput = await rscBuildForSsr({ clientEntryFiles, verbose });
|
|
14
|
+
const serverBuildOutput = await rscBuildForServer(
|
|
15
|
+
clientEntryFiles,
|
|
16
|
+
serverEntryFiles,
|
|
17
|
+
{}
|
|
18
|
+
);
|
|
19
|
+
await rscBuildCopyCssAssets(serverBuildOutput);
|
|
20
|
+
await rscBuildEntriesMappings(
|
|
21
|
+
clientBuildOutput,
|
|
22
|
+
ssrBuildOutput,
|
|
23
|
+
serverBuildOutput,
|
|
24
|
+
clientEntryFiles
|
|
25
|
+
);
|
|
26
|
+
await rscBuildRwEnvVars();
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
buildRscClientAndServer
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-server-dom-webpack.server.d.ts","sourceRoot":"","sources":["../../src/bundled/react-server-dom-webpack.server.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,WAAW,EACX,qBAAqB,GACtB,MAAM,iCAAiC,CAAA"}
|