Update Package.json.
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { resolve } from "path";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
const shimPath = resolve(import.meta.dir, "lightningcss-wasm-shim.ts");
|
||||
const wasmBytes = readFileSync(
|
||||
resolve(
|
||||
import.meta.dir,
|
||||
"node_modules/lightningcss-wasm/lightningcss_node.wasm",
|
||||
),
|
||||
);
|
||||
const wasmBase64 = wasmBytes.toString("base64");
|
||||
|
||||
const result = await Bun.build({
|
||||
entrypoints: ["./src/commands/index.ts"],
|
||||
outdir: "./build",
|
||||
target: "bun",
|
||||
plugins: [
|
||||
{
|
||||
name: "alias-lightningcss-to-wasm",
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^lightningcss$/ }, () => {
|
||||
return {
|
||||
path: "lightningcss",
|
||||
namespace: "lcss-wasm-shim",
|
||||
};
|
||||
});
|
||||
build.onResolve({ filter: /^lightningcss\// }, () => {
|
||||
return {
|
||||
path: "lightningcss",
|
||||
namespace: "lcss-wasm-shim",
|
||||
};
|
||||
});
|
||||
|
||||
build.onLoad(
|
||||
{ filter: /.*/, namespace: "lcss-wasm-shim" },
|
||||
() => {
|
||||
return {
|
||||
contents: `
|
||||
import init, {
|
||||
transform as wasmTransform,
|
||||
transformStyleAttribute as wasmTransformStyleAttribute,
|
||||
bundle as wasmBundle,
|
||||
bundleAsync as wasmBundleAsync,
|
||||
Features,
|
||||
browserslistToTargets,
|
||||
composeVisitors,
|
||||
} from "lightningcss-wasm";
|
||||
|
||||
const wasmBytes = Uint8Array.from(atob("${wasmBase64}"), c => c.charCodeAt(0));
|
||||
await init(wasmBytes);
|
||||
|
||||
export {
|
||||
wasmTransform as transform,
|
||||
wasmTransformStyleAttribute as transformStyleAttribute,
|
||||
wasmBundle as bundle,
|
||||
wasmBundleAsync as bundleAsync,
|
||||
Features,
|
||||
browserslistToTargets,
|
||||
composeVisitors,
|
||||
};
|
||||
`,
|
||||
loader: "ts",
|
||||
};
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
if (!result.success) {
|
||||
console.error("Build failed:", result.logs);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Bun.spawnSync({
|
||||
cmd: [
|
||||
"bun",
|
||||
"build",
|
||||
"./build/index.js",
|
||||
"--compile",
|
||||
"--outfile",
|
||||
"bin/bunext",
|
||||
],
|
||||
stdout: "inherit",
|
||||
stderr: "inherit",
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { readFileSync } from "fs";
|
||||
import { resolve, dirname } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import init, {
|
||||
transform as wasmTransform,
|
||||
transformStyleAttribute as wasmTransformStyleAttribute,
|
||||
bundle as wasmBundle,
|
||||
bundleAsync as wasmBundleAsync,
|
||||
Features,
|
||||
browserslistToTargets,
|
||||
composeVisitors,
|
||||
} from "lightningcss-wasm";
|
||||
|
||||
// Resolve the .wasm file at build time — Bun's bundler will inline this
|
||||
// as a static path that gets embedded into the bundle.
|
||||
const wasmBytes = readFileSync(
|
||||
require.resolve("lightningcss-wasm/lightningcss_node.wasm"),
|
||||
);
|
||||
|
||||
await init(wasmBytes.toString());
|
||||
|
||||
export {
|
||||
wasmTransform as transform,
|
||||
wasmTransformStyleAttribute as transformStyleAttribute,
|
||||
wasmBundle as bundle,
|
||||
wasmBundleAsync as bundleAsync,
|
||||
Features,
|
||||
browserslistToTargets,
|
||||
composeVisitors,
|
||||
};
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
import { program } from "commander";
|
||||
import start from "./start";
|
||||
import dev from "./dev";
|
||||
import ora, { type Ora } from "ora";
|
||||
import type {
|
||||
BundlerCTXMap,
|
||||
BunextConfig,
|
||||
GlobalHMRControllerObject,
|
||||
PageFiles,
|
||||
} from "../types";
|
||||
import type { FileSystemRouter, Server } from "bun";
|
||||
import init from "../functions/init";
|
||||
import grabDirNames from "../utils/grab-dir-names";
|
||||
import build from "./build";
|
||||
import type { BuildContext } from "esbuild";
|
||||
import type { FSWatcher } from "fs";
|
||||
|
||||
/**
|
||||
* # Declare Global Variables
|
||||
*/
|
||||
declare global {
|
||||
var ORA_SPINNER: Ora;
|
||||
var CONFIG: BunextConfig;
|
||||
var SERVER: Server | undefined;
|
||||
var RECOMPILING: boolean;
|
||||
var WATCHER_TIMEOUT: any;
|
||||
var ROUTER: FileSystemRouter;
|
||||
var HMR_CONTROLLERS: GlobalHMRControllerObject[];
|
||||
var LAST_BUILD_TIME: number;
|
||||
var BUNDLER_CTX: BuildContext | undefined;
|
||||
var BUNDLER_CTX_MAP: BundlerCTXMap[] | undefined;
|
||||
var IS_FIRST_BUNDLE_READY: boolean;
|
||||
var BUNDLER_REBUILDS: 0;
|
||||
var PAGES_SRC_WATCHER: FSWatcher | undefined;
|
||||
var CURRENT_VERSION: string | undefined;
|
||||
var PAGE_FILES: PageFiles[];
|
||||
}
|
||||
|
||||
global.ORA_SPINNER = ora();
|
||||
global.ORA_SPINNER.clear();
|
||||
global.HMR_CONTROLLERS = [];
|
||||
global.IS_FIRST_BUNDLE_READY = false;
|
||||
global.BUNDLER_REBUILDS = 0;
|
||||
global.PAGE_FILES = [];
|
||||
|
||||
await init();
|
||||
|
||||
const { PAGES_DIR } = grabDirNames();
|
||||
|
||||
const router = new Bun.FileSystemRouter({
|
||||
style: "nextjs",
|
||||
dir: PAGES_DIR,
|
||||
});
|
||||
|
||||
global.ROUTER = router;
|
||||
|
||||
/**
|
||||
* # Describe Program
|
||||
*/
|
||||
program
|
||||
.name(`bunext`)
|
||||
.description(`A React Next JS replacement built with bun JS`)
|
||||
.version(`1.0.0`);
|
||||
|
||||
/**
|
||||
* # Declare Commands
|
||||
*/
|
||||
program.addCommand(dev());
|
||||
program.addCommand(start());
|
||||
program.addCommand(build());
|
||||
|
||||
/**
|
||||
* # Handle Unavailable Commands
|
||||
*/
|
||||
program.on("command:*", () => {
|
||||
console.error(
|
||||
"Invalid command: %s\nSee --help for a list of available commands.",
|
||||
program.args.join(" "),
|
||||
);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
/**
|
||||
* # Parse Arguments
|
||||
*/
|
||||
program.parse(Bun.argv);
|
||||
@@ -1,8 +1,5 @@
|
||||
import isDevelopment from "../../../utils/is-development";
|
||||
import * as esbuild from "esbuild";
|
||||
import postcss from "postcss";
|
||||
import tailwindcss from "@tailwindcss/postcss";
|
||||
import { readFile } from "fs/promises";
|
||||
import grabDirNames from "../../../utils/grab-dir-names";
|
||||
import path from "path";
|
||||
import tailwindEsbuildPlugin from "./tailwind-esbuild-plugin";
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import isDevelopment from "../../../utils/is-development";
|
||||
import * as esbuild from "esbuild";
|
||||
import postcss from "postcss";
|
||||
import tailwindcss from "@tailwindcss/postcss";
|
||||
import { readFile } from "fs/promises";
|
||||
import grabDirNames from "../../../utils/grab-dir-names";
|
||||
import path from "path";
|
||||
import { execSync } from "child_process";
|
||||
import tailwindEsbuildPlugin from "./tailwind-esbuild-plugin";
|
||||
|
||||
type Params = {
|
||||
|
||||
Executable → Regular
+2
-88
@@ -1,88 +1,2 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
import { program } from "commander";
|
||||
import start from "./commands/start";
|
||||
import dev from "./commands/dev";
|
||||
import ora, { type Ora } from "ora";
|
||||
import type {
|
||||
BundlerCTXMap,
|
||||
BunextConfig,
|
||||
GlobalHMRControllerObject,
|
||||
PageFiles,
|
||||
} from "./types";
|
||||
import type { FileSystemRouter, Server } from "bun";
|
||||
import init from "./functions/init";
|
||||
import grabDirNames from "./utils/grab-dir-names";
|
||||
import build from "./commands/build";
|
||||
import type { BuildContext } from "esbuild";
|
||||
import type { FSWatcher } from "fs";
|
||||
|
||||
/**
|
||||
* # Declare Global Variables
|
||||
*/
|
||||
declare global {
|
||||
var ORA_SPINNER: Ora;
|
||||
var CONFIG: BunextConfig;
|
||||
var SERVER: Server | undefined;
|
||||
var RECOMPILING: boolean;
|
||||
var WATCHER_TIMEOUT: any;
|
||||
var ROUTER: FileSystemRouter;
|
||||
var HMR_CONTROLLERS: GlobalHMRControllerObject[];
|
||||
var LAST_BUILD_TIME: number;
|
||||
var BUNDLER_CTX: BuildContext | undefined;
|
||||
var BUNDLER_CTX_MAP: BundlerCTXMap[] | undefined;
|
||||
var IS_FIRST_BUNDLE_READY: boolean;
|
||||
var BUNDLER_REBUILDS: 0;
|
||||
var PAGES_SRC_WATCHER: FSWatcher | undefined;
|
||||
var CURRENT_VERSION: string | undefined;
|
||||
var PAGE_FILES: PageFiles[];
|
||||
}
|
||||
|
||||
global.ORA_SPINNER = ora();
|
||||
global.ORA_SPINNER.clear();
|
||||
global.HMR_CONTROLLERS = [];
|
||||
global.IS_FIRST_BUNDLE_READY = false;
|
||||
global.BUNDLER_REBUILDS = 0;
|
||||
global.PAGE_FILES = [];
|
||||
|
||||
await init();
|
||||
|
||||
const { PAGES_DIR } = grabDirNames();
|
||||
|
||||
const router = new Bun.FileSystemRouter({
|
||||
style: "nextjs",
|
||||
dir: PAGES_DIR,
|
||||
});
|
||||
|
||||
global.ROUTER = router;
|
||||
|
||||
/**
|
||||
* # Describe Program
|
||||
*/
|
||||
program
|
||||
.name(`bunext`)
|
||||
.description(`A React Next JS replacement built with bun JS`)
|
||||
.version(`1.0.0`);
|
||||
|
||||
/**
|
||||
* # Declare Commands
|
||||
*/
|
||||
program.addCommand(dev());
|
||||
program.addCommand(start());
|
||||
program.addCommand(build());
|
||||
|
||||
/**
|
||||
* # Handle Unavailable Commands
|
||||
*/
|
||||
program.on("command:*", () => {
|
||||
console.error(
|
||||
"Invalid command: %s\nSee --help for a list of available commands.",
|
||||
program.args.join(" "),
|
||||
);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
/**
|
||||
* # Parse Arguments
|
||||
*/
|
||||
program.parse(Bun.argv);
|
||||
const bunext = {};
|
||||
export default bunext;
|
||||
|
||||
Reference in New Issue
Block a user