diff --git a/dist/commands/start/prod-spawn.js b/dist/commands/start/prod-spawn.js index afef0d1..aa49658 100644 --- a/dist/commands/start/prod-spawn.js +++ b/dist/commands/start/prod-spawn.js @@ -1,25 +1,6 @@ -import { readFileSync } from "fs"; import bunextInit from "../../functions/bunext-init"; import startServer from "../../functions/server/start-server"; -import grabDirNames from "../../utils/grab-dir-names"; import { log } from "../../utils/log"; -const { BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON } = grabDirNames(); log.info("Starting production server ..."); -try { - const bundler_ctx_json = JSON.parse(readFileSync(BUNDLER_CTX_MAP_JSON, "utf-8")); - if (bundler_ctx_json) { - global.BUNEXT_BUNDLER_CTX_MAP = bundler_ctx_json; - } -} -catch (error) { - // log.error(`Couldn't set global bundler CTX map: ${error.message}`); -} -try { - const ssr_bundler_ctx_json = JSON.parse(readFileSync(SSR_BUNDLER_CTX_MAP_JSON, "utf-8")); - if (ssr_bundler_ctx_json) { - global.BUNEXT_SSR_BUNDLER_CTX_MAP = ssr_bundler_ctx_json; - } -} -catch (error) { } await bunextInit(); await startServer(); diff --git a/dist/functions/bunext-init.d.ts b/dist/functions/bunext-init.d.ts index 04f9c6b..d1f0208 100644 --- a/dist/functions/bunext-init.d.ts +++ b/dist/functions/bunext-init.d.ts @@ -3,7 +3,7 @@ import type { FileSystemRouter, Server } from "bun"; import { type DirNames } from "../utils/grab-dir-names"; import type { BuildContext } from "esbuild"; import grabConstants from "../utils/grab-constants"; -import type { FSWatcher } from "fs"; +import { type FSWatcher } from "fs"; /** * # Declare Global Variables */ @@ -49,6 +49,7 @@ declare global { } type Params = { build_only?: boolean; + start?: boolean; }; export default function bunextInit(params?: Params): Promise; export {}; diff --git a/dist/functions/bunext-init.js b/dist/functions/bunext-init.js index 29b9286..ad2c0a0 100644 --- a/dist/functions/bunext-init.js +++ b/dist/functions/bunext-init.js @@ -8,9 +8,27 @@ import serverPostBuildFn from "./server/server-post-build-fn"; import reactModulesBundler from "./bundler/react-modules-bundler"; import grabConstants from "../utils/grab-constants"; import watcherEsbuildCTX from "./server/watcher-esbuild-ctx"; +import { readFileSync } from "fs"; const dirNames = grabDirNames(); -const { PAGES_DIR } = dirNames; +const { PAGES_DIR, BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON } = dirNames; export default async function bunextInit(params) { + const is_dev = isDevelopment(); + if (!is_dev || params?.start) { + try { + const bundler_ctx_json = JSON.parse(readFileSync(BUNDLER_CTX_MAP_JSON, "utf-8")); + if (bundler_ctx_json) { + global.BUNEXT_BUNDLER_CTX_MAP = bundler_ctx_json; + } + } + catch (error) { } + try { + const ssr_bundler_ctx_json = JSON.parse(readFileSync(SSR_BUNDLER_CTX_MAP_JSON, "utf-8")); + if (ssr_bundler_ctx_json) { + global.BUNEXT_SSR_BUNDLER_CTX_MAP = ssr_bundler_ctx_json; + } + } + catch (error) { } + } const are_modules_aready_built = global.BUNEXT_BUNDLER_CTX_MAP && global.BUNEXT_SSR_BUNDLER_CTX_MAP; global.BUNEXT_HMR_CONTROLLERS = []; if (!global.BUNEXT_BUNDLER_CTX_MAP) { @@ -37,7 +55,6 @@ export default async function bunextInit(params) { dir: PAGES_DIR, }); global.BUNEXT_ROUTER = router; - const is_dev = isDevelopment(); if (params?.build_only) { log.build(`Building Modules ...`); await allPagesESBuildContextBundler({ build_only: params.build_only }); diff --git a/package.json b/package.json index 4ec64cd..14c8af0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/bunext", - "version": "1.1.8", + "version": "1.1.9", "main": "dist/index.js", "module": "index.ts", "dependencies": { diff --git a/src/commands/start/prod-spawn.ts b/src/commands/start/prod-spawn.ts index 3649fae..fa9dd35 100644 --- a/src/commands/start/prod-spawn.ts +++ b/src/commands/start/prod-spawn.ts @@ -1,36 +1,9 @@ -import { readFileSync } from "fs"; import bunextInit from "../../functions/bunext-init"; import startServer from "../../functions/server/start-server"; -import grabDirNames from "../../utils/grab-dir-names"; import { log } from "../../utils/log"; -import type { BundlerCTXMap } from "../../types"; - -const { BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON } = grabDirNames(); log.info("Starting production server ..."); -try { - const bundler_ctx_json = JSON.parse( - readFileSync(BUNDLER_CTX_MAP_JSON, "utf-8"), - ) as { [k: string]: BundlerCTXMap } | undefined; - - if (bundler_ctx_json) { - global.BUNEXT_BUNDLER_CTX_MAP = bundler_ctx_json; - } -} catch (error: any) { - // log.error(`Couldn't set global bundler CTX map: ${error.message}`); -} - -try { - const ssr_bundler_ctx_json = JSON.parse( - readFileSync(SSR_BUNDLER_CTX_MAP_JSON, "utf-8"), - ) as { [k: string]: BundlerCTXMap } | undefined; - - if (ssr_bundler_ctx_json) { - global.BUNEXT_SSR_BUNDLER_CTX_MAP = ssr_bundler_ctx_json; - } -} catch (error) {} - await bunextInit(); await startServer(); diff --git a/src/functions/bunext-init.ts b/src/functions/bunext-init.ts index 8052b96..f848ac5 100644 --- a/src/functions/bunext-init.ts +++ b/src/functions/bunext-init.ts @@ -16,7 +16,7 @@ import serverPostBuildFn from "./server/server-post-build-fn"; import reactModulesBundler from "./bundler/react-modules-bundler"; import grabConstants from "../utils/grab-constants"; import watcherEsbuildCTX from "./server/watcher-esbuild-ctx"; -import type { FSWatcher } from "fs"; +import { readFileSync, type FSWatcher } from "fs"; /** * # Declare Global Variables @@ -56,13 +56,38 @@ declare global { } const dirNames = grabDirNames(); -const { PAGES_DIR } = dirNames; +const { PAGES_DIR, BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON } = dirNames; type Params = { build_only?: boolean; + start?: boolean; }; export default async function bunextInit(params?: Params) { + const is_dev = isDevelopment(); + + if (!is_dev || params?.start) { + try { + const bundler_ctx_json = JSON.parse( + readFileSync(BUNDLER_CTX_MAP_JSON, "utf-8"), + ) as { [k: string]: BundlerCTXMap } | undefined; + + if (bundler_ctx_json) { + global.BUNEXT_BUNDLER_CTX_MAP = bundler_ctx_json; + } + } catch (error: any) {} + + try { + const ssr_bundler_ctx_json = JSON.parse( + readFileSync(SSR_BUNDLER_CTX_MAP_JSON, "utf-8"), + ) as { [k: string]: BundlerCTXMap } | undefined; + + if (ssr_bundler_ctx_json) { + global.BUNEXT_SSR_BUNDLER_CTX_MAP = ssr_bundler_ctx_json; + } + } catch (error) {} + } + const are_modules_aready_built = global.BUNEXT_BUNDLER_CTX_MAP && global.BUNEXT_SSR_BUNDLER_CTX_MAP; @@ -97,8 +122,6 @@ export default async function bunextInit(params?: Params) { global.BUNEXT_ROUTER = router; - const is_dev = isDevelopment(); - if (params?.build_only) { log.build(`Building Modules ...`); await allPagesESBuildContextBundler({ build_only: params.build_only });