Update build step
This commit is contained in:
parent
61a9d8d612
commit
817beacc7a
12
dist/commands/build/index.js
vendored
12
dist/commands/build/index.js
vendored
@ -1,9 +1,8 @@
|
||||
import { Command } from "commander";
|
||||
import { log } from "../../utils/log";
|
||||
import init from "../../functions/init";
|
||||
import grabDirNames from "../../utils/grab-dir-names";
|
||||
import { rmSync } from "fs";
|
||||
import allPagesESBuildContextBundler from "../../functions/bundler/all-pages-esbuild-context-bundler";
|
||||
import bunextInit from "../../functions/bunext-init";
|
||||
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
|
||||
export default function () {
|
||||
return new Command("build")
|
||||
@ -15,13 +14,8 @@ export default function () {
|
||||
}
|
||||
catch (error) { }
|
||||
global.SKIPPED_BROWSER_MODULES = new Set();
|
||||
// await rewritePagesModule();
|
||||
await init();
|
||||
log.banner();
|
||||
log.build("Building Project ...");
|
||||
// await allPagesBunBundler();
|
||||
// await allPagesBundler();
|
||||
await allPagesESBuildContextBundler();
|
||||
await bunextInit({ build_only: true });
|
||||
log.success("Modules Built Successfully!");
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
|
||||
26
dist/commands/dev/index.js
vendored
26
dist/commands/dev/index.js
vendored
@ -35,13 +35,27 @@ async function dev() {
|
||||
NODE_ENV: "development",
|
||||
},
|
||||
};
|
||||
let dev_process = Bun.spawn(spawn_options);
|
||||
retries++;
|
||||
let dev_process;
|
||||
try {
|
||||
dev_process = Bun.spawn(spawn_options);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`Failed to start dev process:`, error);
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
return await dev();
|
||||
}
|
||||
const exited = await dev_process.exited;
|
||||
if (exited) {
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
return await dev();
|
||||
}
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
const exited = await dev_process.exited;
|
||||
if (exited) {
|
||||
return await dev();
|
||||
}
|
||||
}
|
||||
|
||||
26
dist/commands/start/index.js
vendored
26
dist/commands/start/index.js
vendored
@ -34,13 +34,27 @@ async function start() {
|
||||
NODE_ENV: "production",
|
||||
},
|
||||
};
|
||||
let dev_process = Bun.spawn(spawn_options);
|
||||
retries++;
|
||||
let dev_process;
|
||||
try {
|
||||
dev_process = Bun.spawn(spawn_options);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`Failed to start production process:`, error);
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
return await start();
|
||||
}
|
||||
const exited = await dev_process.exited;
|
||||
if (exited) {
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
return await start();
|
||||
}
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
const exited = await dev_process.exited;
|
||||
if (exited) {
|
||||
return await start();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ type Params = {
|
||||
post_build_fn?: (params: {
|
||||
artifacts: BundlerCTXMap[];
|
||||
}) => Promise<void> | void;
|
||||
build_only?: boolean;
|
||||
};
|
||||
export default function allPagesESBuildContextBundler(params?: Params): Promise<void>;
|
||||
export {};
|
||||
|
||||
@ -50,6 +50,7 @@ export default async function allPagesESBuildContextBundler(params) {
|
||||
esbuildCTXArtifactTracker({
|
||||
entryToPage,
|
||||
post_build_fn: params?.post_build_fn,
|
||||
build_only: params?.build_only,
|
||||
}),
|
||||
],
|
||||
jsx: "automatic",
|
||||
|
||||
@ -7,6 +7,7 @@ type Params = {
|
||||
post_build_fn?: (params: {
|
||||
artifacts: any[];
|
||||
}) => Promise<void> | void;
|
||||
build_only?: boolean;
|
||||
};
|
||||
export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn, }: Params): Plugin;
|
||||
export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn, build_only, }: Params): Plugin;
|
||||
export {};
|
||||
|
||||
@ -12,7 +12,7 @@ import cleanupLogsDirs from "../../cleanup-logs-dir";
|
||||
const { BUNX_BUNDLER_ERROR_EXIT_FILE, BUNX_ERROR_LOGS_DIR } = grabDirNames();
|
||||
let build_start = 0;
|
||||
const MAX_BUILD_STARTS = 2;
|
||||
export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn, }) {
|
||||
export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn, build_only, }) {
|
||||
const artifactTracker = {
|
||||
name: "artifact-tracker",
|
||||
setup(build) {
|
||||
@ -25,7 +25,7 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
|
||||
await buildOnstartErrorHandler();
|
||||
}
|
||||
});
|
||||
build.onEnd((result) => {
|
||||
build.onEnd(async (result) => {
|
||||
if (result.errors.length > 0) {
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
@ -65,12 +65,20 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
|
||||
global.MAIN_CTX_BUILD_STARTS = 0;
|
||||
global.BUNDLER_CTX_DISPOSED = false;
|
||||
const does_error_file_exist = existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE);
|
||||
if (does_error_file_exist) {
|
||||
if (build_only) {
|
||||
try {
|
||||
await pagesSSRBundler();
|
||||
}
|
||||
catch (error) {
|
||||
log.error(`SSR Bundler Error: ${error}`);
|
||||
}
|
||||
}
|
||||
else if (does_error_file_exist) {
|
||||
mkdirSync(BUNX_ERROR_LOGS_DIR, { recursive: true });
|
||||
cpSync(BUNX_BUNDLER_ERROR_EXIT_FILE, path.join(BUNX_ERROR_LOGS_DIR, `${Date.now()}.log`));
|
||||
rmSync(BUNX_BUNDLER_ERROR_EXIT_FILE, { force: true });
|
||||
cleanupLogsDirs();
|
||||
fullRebuild();
|
||||
await fullRebuild();
|
||||
}
|
||||
else {
|
||||
try {
|
||||
|
||||
6
dist/functions/bunext-init.d.ts
vendored
6
dist/functions/bunext-init.d.ts
vendored
@ -47,4 +47,8 @@ declare global {
|
||||
var CONSTANTS: ReturnType<typeof grabConstants>;
|
||||
var MAIN_CTX_BUILD_STARTS: number;
|
||||
}
|
||||
export default function bunextInit(): Promise<void>;
|
||||
type Params = {
|
||||
build_only?: boolean;
|
||||
};
|
||||
export default function bunextInit(params?: Params): Promise<void>;
|
||||
export {};
|
||||
|
||||
8
dist/functions/bunext-init.js
vendored
8
dist/functions/bunext-init.js
vendored
@ -10,7 +10,7 @@ import grabConstants from "../utils/grab-constants";
|
||||
import watcherEsbuildCTX from "./server/watcher-esbuild-ctx";
|
||||
const dirNames = grabDirNames();
|
||||
const { PAGES_DIR } = dirNames;
|
||||
export default async function bunextInit() {
|
||||
export default async function bunextInit(params) {
|
||||
global.HMR_CONTROLLERS = [];
|
||||
global.BUNDLER_CTX_MAP = {};
|
||||
global.SSR_BUNDLER_CTX_MAP = {};
|
||||
@ -33,7 +33,11 @@ export default async function bunextInit() {
|
||||
});
|
||||
global.ROUTER = router;
|
||||
const is_dev = isDevelopment();
|
||||
if (is_dev) {
|
||||
if (params?.build_only) {
|
||||
log.build(`Building Modules ...`);
|
||||
await allPagesESBuildContextBundler();
|
||||
}
|
||||
else if (is_dev) {
|
||||
log.build(`Building Modules ...`);
|
||||
await allPagesESBuildContextBundler({
|
||||
post_build_fn: () => {
|
||||
|
||||
2
dist/functions/server/full-rebuild.js
vendored
2
dist/functions/server/full-rebuild.js
vendored
@ -18,7 +18,7 @@ export default async function fullRebuild(params) {
|
||||
}
|
||||
catch (error) { }
|
||||
// await pagesSSRBundler();
|
||||
allPagesESBuildContextBundler({
|
||||
await allPagesESBuildContextBundler({
|
||||
post_build_fn: () => {
|
||||
serverPostBuildFn();
|
||||
},
|
||||
|
||||
1
dist/functions/server/watcher-esbuild-ctx.js
vendored
1
dist/functions/server/watcher-esbuild-ctx.js
vendored
@ -22,6 +22,7 @@ export default async function watcherEsbuildCTX() {
|
||||
}
|
||||
if (global.BUNDLER_CTX_DISPOSED) {
|
||||
await fullRebuild({ msg: `Restarting Bundler ...` });
|
||||
return;
|
||||
}
|
||||
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
||||
pagesSSRBundler();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/bunext",
|
||||
"version": "1.0.94",
|
||||
"version": "1.0.95",
|
||||
"main": "dist/index.js",
|
||||
"module": "index.ts",
|
||||
"dependencies": {
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import { Command } from "commander";
|
||||
import { log } from "../../utils/log";
|
||||
import init from "../../functions/init";
|
||||
import grabDirNames from "../../utils/grab-dir-names";
|
||||
import { rmSync } from "fs";
|
||||
import allPagesESBuildContextBundler from "../../functions/bundler/all-pages-esbuild-context-bundler";
|
||||
import bunextInit from "../../functions/bunext-init";
|
||||
|
||||
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
|
||||
|
||||
@ -18,16 +17,9 @@ export default function () {
|
||||
|
||||
global.SKIPPED_BROWSER_MODULES = new Set<string>();
|
||||
|
||||
// await rewritePagesModule();
|
||||
await init();
|
||||
await bunextInit({ build_only: true });
|
||||
|
||||
log.banner();
|
||||
log.build("Building Project ...");
|
||||
|
||||
// await allPagesBunBundler();
|
||||
|
||||
// await allPagesBundler();
|
||||
await allPagesESBuildContextBundler();
|
||||
log.success("Modules Built Successfully!");
|
||||
|
||||
process.exit();
|
||||
});
|
||||
|
||||
@ -44,16 +44,29 @@ async function dev() {
|
||||
},
|
||||
};
|
||||
|
||||
let dev_process = Bun.spawn(spawn_options);
|
||||
let dev_process;
|
||||
try {
|
||||
dev_process = Bun.spawn(spawn_options);
|
||||
} catch (error) {
|
||||
console.error(`Failed to start dev process:`, error);
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
return await dev();
|
||||
}
|
||||
|
||||
retries++;
|
||||
const exited = await dev_process.exited;
|
||||
|
||||
if (exited) {
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
return await dev();
|
||||
}
|
||||
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
|
||||
const exited = await dev_process.exited;
|
||||
if (exited) {
|
||||
return await dev();
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,17 +45,29 @@ async function start() {
|
||||
},
|
||||
};
|
||||
|
||||
let dev_process = Bun.spawn(spawn_options);
|
||||
|
||||
retries++;
|
||||
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
let dev_process;
|
||||
try {
|
||||
dev_process = Bun.spawn(spawn_options);
|
||||
} catch (error) {
|
||||
console.error(`Failed to start production process:`, error);
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
return await start();
|
||||
}
|
||||
|
||||
const exited = await dev_process.exited;
|
||||
|
||||
if (exited) {
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
return await start();
|
||||
}
|
||||
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ type Params = {
|
||||
post_build_fn?: (params: {
|
||||
artifacts: BundlerCTXMap[];
|
||||
}) => Promise<void> | void;
|
||||
build_only?: boolean;
|
||||
};
|
||||
|
||||
export default async function allPagesESBuildContextBundler(params?: Params) {
|
||||
@ -82,6 +83,7 @@ export default async function allPagesESBuildContextBundler(params?: Params) {
|
||||
esbuildCTXArtifactTracker({
|
||||
entryToPage,
|
||||
post_build_fn: params?.post_build_fn,
|
||||
build_only: params?.build_only,
|
||||
}),
|
||||
],
|
||||
jsx: "automatic",
|
||||
|
||||
@ -24,11 +24,13 @@ type Params = {
|
||||
}
|
||||
>;
|
||||
post_build_fn?: (params: { artifacts: any[] }) => Promise<void> | void;
|
||||
build_only?: boolean;
|
||||
};
|
||||
|
||||
export default function esbuildCTXArtifactTracker({
|
||||
entryToPage,
|
||||
post_build_fn,
|
||||
build_only,
|
||||
}: Params) {
|
||||
const artifactTracker: Plugin = {
|
||||
name: "artifact-tracker",
|
||||
@ -49,7 +51,7 @@ export default function esbuildCTXArtifactTracker({
|
||||
}
|
||||
});
|
||||
|
||||
build.onEnd((result) => {
|
||||
build.onEnd(async (result) => {
|
||||
if (result.errors.length > 0) {
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
@ -112,7 +114,13 @@ export default function esbuildCTXArtifactTracker({
|
||||
BUNX_BUNDLER_ERROR_EXIT_FILE,
|
||||
);
|
||||
|
||||
if (does_error_file_exist) {
|
||||
if (build_only) {
|
||||
try {
|
||||
await pagesSSRBundler();
|
||||
} catch (error) {
|
||||
log.error(`SSR Bundler Error: ${error}`);
|
||||
}
|
||||
} else if (does_error_file_exist) {
|
||||
mkdirSync(BUNX_ERROR_LOGS_DIR, { recursive: true });
|
||||
cpSync(
|
||||
BUNX_BUNDLER_ERROR_EXIT_FILE,
|
||||
@ -120,7 +128,7 @@ export default function esbuildCTXArtifactTracker({
|
||||
);
|
||||
rmSync(BUNX_BUNDLER_ERROR_EXIT_FILE, { force: true });
|
||||
cleanupLogsDirs();
|
||||
fullRebuild();
|
||||
await fullRebuild();
|
||||
} else {
|
||||
try {
|
||||
pagesSSRBundler();
|
||||
|
||||
@ -58,7 +58,11 @@ declare global {
|
||||
const dirNames = grabDirNames();
|
||||
const { PAGES_DIR } = dirNames;
|
||||
|
||||
export default async function bunextInit() {
|
||||
type Params = {
|
||||
build_only?: boolean;
|
||||
};
|
||||
|
||||
export default async function bunextInit(params?: Params) {
|
||||
global.HMR_CONTROLLERS = [];
|
||||
global.BUNDLER_CTX_MAP = {};
|
||||
global.SSR_BUNDLER_CTX_MAP = {};
|
||||
@ -88,7 +92,10 @@ export default async function bunextInit() {
|
||||
|
||||
const is_dev = isDevelopment();
|
||||
|
||||
if (is_dev) {
|
||||
if (params?.build_only) {
|
||||
log.build(`Building Modules ...`);
|
||||
await allPagesESBuildContextBundler();
|
||||
} else if (is_dev) {
|
||||
log.build(`Building Modules ...`);
|
||||
await allPagesESBuildContextBundler({
|
||||
post_build_fn: () => {
|
||||
|
||||
@ -25,7 +25,7 @@ export default async function fullRebuild(params?: { msg?: string }) {
|
||||
|
||||
// await pagesSSRBundler();
|
||||
|
||||
allPagesESBuildContextBundler({
|
||||
await allPagesESBuildContextBundler({
|
||||
post_build_fn: () => {
|
||||
serverPostBuildFn();
|
||||
},
|
||||
|
||||
@ -29,6 +29,7 @@ export default async function watcherEsbuildCTX() {
|
||||
|
||||
if (global.BUNDLER_CTX_DISPOSED) {
|
||||
await fullRebuild({ msg: `Restarting Bundler ...` });
|
||||
return;
|
||||
}
|
||||
|
||||
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user