@blinkk/root 1.0.0-beta.0 → 1.0.0-beta.1

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/dist/cli.js CHANGED
@@ -1,88 +1,42 @@
1
- import {
2
- configureServerPlugins,
3
- getVitePlugins
4
- } from "./chunk-DTEQ2AIW.js";
5
1
  import {
6
2
  htmlMinify,
7
3
  htmlPretty,
8
4
  isValidTagName,
9
5
  parseTagNames
10
6
  } from "./chunk-GGQGZ7ZE.js";
7
+ import {
8
+ copyGlob,
9
+ createViteServer,
10
+ directoryContains,
11
+ fileExists,
12
+ isDirectory,
13
+ isJsFile,
14
+ loadJson,
15
+ loadRootConfig,
16
+ makeDir,
17
+ rmDir,
18
+ writeFile
19
+ } from "./chunk-LTSJAEBG.js";
20
+ import {
21
+ configureServerPlugins,
22
+ getVitePlugins
23
+ } from "./chunk-DTEQ2AIW.js";
11
24
 
12
25
  // src/cli/commands/dev.ts
13
- import path4 from "node:path";
26
+ import path3 from "node:path";
14
27
  import { fileURLToPath } from "node:url";
15
28
  import { default as express } from "express";
16
- import { createServer as createViteServer } from "vite";
17
29
 
18
30
  // src/render/asset-map/dev-asset-map.ts
19
- import path2 from "node:path";
20
- import { searchForWorkspaceRoot } from "vite";
21
-
22
- // src/utils/fsutils.ts
23
- import { promises as fs } from "node:fs";
24
31
  import path from "node:path";
25
- import fsExtra from "fs-extra";
26
- import glob from "tiny-glob";
27
- function isJsFile(filename) {
28
- return !!filename.match(/\.(j|t)sx?$/);
29
- }
30
- async function writeFile(filepath, content) {
31
- const dirPath = path.dirname(filepath);
32
- await makeDir(dirPath);
33
- await fs.writeFile(filepath, content);
34
- }
35
- async function makeDir(dirpath) {
36
- try {
37
- await fs.access(dirpath);
38
- } catch (e) {
39
- await fs.mkdir(dirpath, { recursive: true });
40
- }
41
- }
42
- async function copyGlob(pattern, srcdir, dstdir) {
43
- const files = await glob(pattern, { cwd: srcdir });
44
- if (files.length > 0) {
45
- await makeDir(dstdir);
46
- }
47
- files.forEach((file) => {
48
- fsExtra.copySync(path.resolve(srcdir, file), path.resolve(dstdir, file));
49
- });
50
- }
51
- async function rmDir(dirpath) {
52
- await fs.rm(dirpath, { recursive: true, force: true });
53
- }
54
- async function loadJson(filepath) {
55
- const content = await fs.readFile(filepath, "utf-8");
56
- return JSON.parse(content);
57
- }
58
- async function isDirectory(dirpath) {
59
- return fs.stat(dirpath).then((fsStat) => {
60
- return fsStat.isDirectory();
61
- }).catch((err) => {
62
- if (err.code === "ENOENT") {
63
- return false;
64
- }
65
- throw err;
66
- });
67
- }
68
- function fileExists(filepath) {
69
- return fs.access(filepath).then(() => true).catch(() => false);
70
- }
71
- async function directoryContains(dirpath, subpath) {
72
- const outer = await fs.realpath(dirpath);
73
- const inner = await fs.realpath(subpath);
74
- const rel = path.relative(outer, inner);
75
- return !rel.startsWith("..");
76
- }
77
-
78
- // src/render/asset-map/dev-asset-map.ts
32
+ import { searchForWorkspaceRoot } from "vite";
79
33
  var DevServerAssetMap = class {
80
34
  constructor(rootConfig, moduleGraph) {
81
35
  this.rootConfig = rootConfig;
82
36
  this.moduleGraph = moduleGraph;
83
37
  }
84
38
  async get(src) {
85
- const file = path2.resolve(this.rootConfig.rootDir, src);
39
+ const file = path.resolve(this.rootConfig.rootDir, src);
86
40
  const viteModules = this.moduleGraph.getModulesByFile(file);
87
41
  if (viteModules && viteModules.size > 0) {
88
42
  const [viteModule] = viteModules;
@@ -114,7 +68,7 @@ var DevServerAssetMap = class {
114
68
  return null;
115
69
  }
116
70
  filePathToSrc(file) {
117
- return path2.relative(this.rootConfig.rootDir, file);
71
+ return path.relative(this.rootConfig.rootDir, file);
118
72
  }
119
73
  };
120
74
  var DevServerAsset = class {
@@ -151,7 +105,7 @@ var DevServerAsset = class {
151
105
  return;
152
106
  }
153
107
  visited.add(asset.moduleId);
154
- const parts = path2.parse(asset.assetUrl);
108
+ const parts = path.parse(asset.assetUrl);
155
109
  if ([".js", ".jsx", ".ts", ".tsx"].includes(parts.ext) && asset.moduleId.includes("/elements/")) {
156
110
  urls.add(asset.assetUrl);
157
111
  }
@@ -178,7 +132,7 @@ var DevServerAsset = class {
178
132
  }
179
133
  visited.add(asset.assetUrl);
180
134
  if (asset.src.endsWith(".scss")) {
181
- const parts = path2.parse(asset.src);
135
+ const parts = path.parse(asset.src);
182
136
  if (!parts.name.startsWith("_")) {
183
137
  urls.add(asset.assetUrl);
184
138
  }
@@ -196,39 +150,18 @@ var DevServerAsset = class {
196
150
  }
197
151
  };
198
152
 
199
- // src/cli/load-config.ts
200
- import { bundleRequire } from "bundle-require";
201
- import JoyCon from "joycon";
202
- async function loadRootConfig(rootDir) {
203
- const joycon = new JoyCon();
204
- const configPath = await joycon.resolve({
205
- cwd: rootDir,
206
- files: ["root.config.ts"]
207
- });
208
- if (configPath) {
209
- const configBundle = await bundleRequire({
210
- filepath: configPath
211
- });
212
- return Object.assign({}, configBundle.mod.default || {}, { rootDir });
213
- }
214
- return { rootDir };
215
- }
216
-
217
153
  // src/cli/commands/dev.ts
218
- import glob3 from "tiny-glob";
219
154
  import { dim } from "kleur/colors";
220
155
 
221
156
  // src/core/middleware.ts
222
157
  function rootProjectMiddleware(options) {
223
158
  return (req, _, next) => {
224
- req.rootConfig = Object.assign({}, options.rootConfig, {
225
- rootDir: options.rootDir
226
- });
159
+ req.rootConfig = options.rootConfig;
227
160
  next();
228
161
  };
229
162
  }
230
163
 
231
- // src/cli/ports.ts
164
+ // src/utils/ports.ts
232
165
  import { createServer } from "node:net";
233
166
  function isPortOpen(port) {
234
167
  return new Promise((resolve, reject) => {
@@ -265,11 +198,11 @@ async function findOpenPort(min, max) {
265
198
  throw new Error(`no ports open between ${min} and ${max}`);
266
199
  }
267
200
 
268
- // src/core/element-graph.ts
269
- import fs2 from "node:fs";
270
- import path3 from "node:path";
201
+ // src/node/element-graph.ts
202
+ import fs from "node:fs";
203
+ import path2 from "node:path";
271
204
  import { searchForWorkspaceRoot as searchForWorkspaceRoot2 } from "vite";
272
- import glob2 from "tiny-glob";
205
+ import glob from "tiny-glob";
273
206
  var ElementGraph = class {
274
207
  constructor(sourceFiles) {
275
208
  this.sourceFiles = {};
@@ -296,7 +229,7 @@ var ElementGraph = class {
296
229
  if (!srcFile) {
297
230
  throw new Error(`could not find file path for tagName <${tagName}>`);
298
231
  }
299
- const src = fs2.readFileSync(srcFile.filePath, "utf-8");
232
+ const src = fs.readFileSync(srcFile.filePath, "utf-8");
300
233
  const tagNames = parseTagNames(src);
301
234
  const deps = /* @__PURE__ */ new Set();
302
235
  for (const depTagName of tagNames) {
@@ -311,14 +244,14 @@ async function getElements(rootConfig) {
311
244
  var _a, _b;
312
245
  const rootDir = rootConfig.rootDir;
313
246
  const workspaceRoot = searchForWorkspaceRoot2(rootDir);
314
- const elementsDirs = [path3.join(rootDir, "elements")];
247
+ const elementsDirs = [path2.join(rootDir, "elements")];
315
248
  const elementsInclude = ((_a = rootConfig.elements) == null ? void 0 : _a.include) || [];
316
249
  const excludePatterns = ((_b = rootConfig.elements) == null ? void 0 : _b.exclude) || [];
317
250
  const excludeElement = (moduleId) => {
318
251
  return excludePatterns.some((pattern) => Boolean(moduleId.match(pattern)));
319
252
  };
320
253
  for (const dirPath of elementsInclude) {
321
- const elementsDir = path3.resolve(rootDir, dirPath);
254
+ const elementsDir = path2.resolve(rootDir, dirPath);
322
255
  if (!directoryContains(rootDir, elementsDir)) {
323
256
  throw new Error(
324
257
  `the elements dir (${dirPath}) should be within the project's workspace (${workspaceRoot})`
@@ -329,13 +262,13 @@ async function getElements(rootConfig) {
329
262
  const elementFilePaths = {};
330
263
  for (const dirPath of elementsDirs) {
331
264
  if (await isDirectory(dirPath)) {
332
- const files = await glob2("**/*", { cwd: dirPath });
265
+ const files = await glob("**/*", { cwd: dirPath });
333
266
  files.forEach((file) => {
334
- const parts = path3.parse(file);
267
+ const parts = path2.parse(file);
335
268
  if (isJsFile(parts.base) && isValidTagName(parts.name)) {
336
269
  const tagName = parts.name;
337
- const filePath = path3.join(dirPath, file);
338
- const relPath = path3.relative(rootDir, filePath);
270
+ const filePath = path2.join(dirPath, file);
271
+ const relPath = path2.relative(rootDir, filePath);
339
272
  if (!excludeElement(relPath)) {
340
273
  elementFilePaths[tagName] = { filePath, relPath };
341
274
  }
@@ -348,10 +281,11 @@ async function getElements(rootConfig) {
348
281
  }
349
282
 
350
283
  // src/cli/commands/dev.ts
351
- var __dirname = path4.dirname(fileURLToPath(import.meta.url));
284
+ import glob2 from "tiny-glob";
285
+ var __dirname = path3.dirname(fileURLToPath(import.meta.url));
352
286
  async function dev(rootProjectDir) {
353
287
  process.env.NODE_ENV = "development";
354
- const rootDir = path4.resolve(rootProjectDir || process.cwd());
288
+ const rootDir = path3.resolve(rootProjectDir || process.cwd());
355
289
  const defaultPort = parseInt(process.env.PORT || "4007");
356
290
  const port = await findOpenPort(defaultPort, defaultPort + 10);
357
291
  console.log();
@@ -363,13 +297,13 @@ async function dev(rootProjectDir) {
363
297
  server.listen(port);
364
298
  }
365
299
  async function createServer2(options) {
366
- const rootDir = path4.resolve((options == null ? void 0 : options.rootDir) || process.cwd());
367
- const rootConfig = await loadRootConfig(rootDir);
300
+ const rootDir = path3.resolve((options == null ? void 0 : options.rootDir) || process.cwd());
301
+ const rootConfig = await loadRootConfig(rootDir, { command: "dev" });
368
302
  const port = options == null ? void 0 : options.port;
369
303
  const server = express();
370
304
  server.disable("x-powered-by");
371
- server.use(rootProjectMiddleware({ rootDir, rootConfig }));
372
- server.use(await viteServerMiddleware({ rootDir, rootConfig, port }));
305
+ server.use(rootProjectMiddleware({ rootConfig }));
306
+ server.use(await viteServerMiddleware({ rootConfig, port }));
373
307
  const plugins = rootConfig.plugins || [];
374
308
  await configureServerPlugins(
375
309
  server,
@@ -389,76 +323,34 @@ async function createServer2(options) {
389
323
  return server;
390
324
  }
391
325
  async function viteServerMiddleware(options) {
392
- var _a, _b;
393
- const rootDir = options.rootDir;
394
326
  const rootConfig = options.rootConfig;
395
- const viteConfig = rootConfig.vite || {};
396
- let hmrOptions = (_a = viteConfig.server) == null ? void 0 : _a.hmr;
397
- if (typeof hmrOptions === "undefined" && options.port) {
398
- hmrOptions = { port: options.port + 10 };
399
- }
400
- const routeFiles = [];
401
- if (await isDirectory(path4.join(rootDir, "routes"))) {
402
- const pageFiles = await glob3("routes/**/*", { cwd: rootDir });
403
- pageFiles.forEach((file) => {
404
- const parts = path4.parse(file);
405
- if (!parts.name.startsWith("_") && isJsFile(parts.base)) {
406
- routeFiles.push(file);
407
- }
408
- });
409
- }
327
+ const rootDir = rootConfig.rootDir;
410
328
  const elementGraph = await getElements(rootConfig);
411
329
  const elements = Object.values(elementGraph.sourceFiles).map((sourceFile) => {
412
330
  return sourceFile.relPath;
413
331
  });
414
332
  const bundleScripts = [];
415
- if (await isDirectory(path4.join(rootDir, "bundles"))) {
416
- const bundleFiles = await glob3("bundles/*", { cwd: rootDir });
333
+ if (await isDirectory(path3.join(rootDir, "bundles"))) {
334
+ const bundleFiles = await glob2("bundles/*", { cwd: rootDir });
417
335
  bundleFiles.forEach((file) => {
418
- const parts = path4.parse(file);
336
+ const parts = path3.parse(file);
419
337
  if (isJsFile(parts.base)) {
420
338
  bundleScripts.push(file);
421
339
  }
422
340
  });
423
341
  }
424
- const viteServer = await createViteServer({
425
- ...viteConfig,
426
- mode: "development",
427
- root: rootDir,
428
- publicDir: path4.join(rootDir, "public"),
429
- server: {
430
- ...viteConfig.server || {},
431
- middlewareMode: true,
432
- hmr: hmrOptions
433
- },
434
- appType: "custom",
435
- optimizeDeps: {
436
- ...viteConfig.optimizeDeps || {},
437
- include: [
438
- ...elements,
439
- ...bundleScripts,
440
- ...((_b = viteConfig.optimizeDeps) == null ? void 0 : _b.include) || []
441
- ]
442
- },
443
- ssr: {
444
- ...viteConfig.ssr || {},
445
- noExternal: ["@blinkk/root"]
446
- },
447
- esbuild: {
448
- ...viteConfig.esbuild || {},
449
- jsx: "automatic",
450
- jsxImportSource: "preact"
451
- },
452
- plugins: [
453
- ...viteConfig.plugins || [],
454
- ...getVitePlugins(rootConfig.plugins || [])
455
- ]
342
+ const optimizeDeps = [...elements, ...bundleScripts];
343
+ const viteServer = await createViteServer(rootConfig, {
344
+ port: options.port,
345
+ optimizeDeps
456
346
  });
457
347
  return async (req, res, next) => {
458
348
  try {
459
349
  req.viteServer = viteServer;
460
- const renderModulePath = path4.resolve(__dirname, "./render.js");
461
- const render = await viteServer.ssrLoadModule(renderModulePath);
350
+ const renderModulePath = path3.resolve(__dirname, "./render.js");
351
+ const render = await viteServer.ssrLoadModule(
352
+ renderModulePath
353
+ );
462
354
  const assetMap = new DevServerAssetMap(
463
355
  rootConfig,
464
356
  viteServer.moduleGraph
@@ -487,7 +379,7 @@ function rootDevServer404Middleware() {
487
379
  console.error(`\u2753 404 ${req.originalUrl}`);
488
380
  if (req.renderer) {
489
381
  const url = req.path;
490
- const ext = path4.extname(url);
382
+ const ext = path3.extname(url);
491
383
  if (!ext) {
492
384
  const renderer = req.renderer;
493
385
  const data = await renderer.renderDevServer404(req);
@@ -505,7 +397,7 @@ function rootDevServer500Middleware() {
505
397
  console.error(String(err.stack || err));
506
398
  if (req.renderer) {
507
399
  const url = req.path;
508
- const ext = path4.extname(url);
400
+ const ext = path3.extname(url);
509
401
  if (!ext) {
510
402
  const renderer = req.renderer;
511
403
  const data = await renderer.renderDevServer500(req, err);
@@ -519,15 +411,15 @@ function rootDevServer500Middleware() {
519
411
  }
520
412
 
521
413
  // src/cli/commands/build.ts
522
- import path6 from "node:path";
414
+ import path5 from "node:path";
523
415
  import { fileURLToPath as fileURLToPath2 } from "node:url";
524
- import fsExtra2 from "fs-extra";
525
- import glob4 from "tiny-glob";
416
+ import fsExtra from "fs-extra";
417
+ import glob3 from "tiny-glob";
526
418
  import { build as viteBuild } from "vite";
527
419
 
528
420
  // src/render/asset-map/build-asset-map.ts
529
- import fs3 from "node:fs";
530
- import path5 from "node:path";
421
+ import fs2 from "node:fs";
422
+ import path4 from "node:path";
531
423
  var BuildAssetMap = class {
532
424
  constructor(rootConfig) {
533
425
  this.rootConfig = rootConfig;
@@ -597,12 +489,12 @@ var BuildAssetMap = class {
597
489
  }
598
490
  };
599
491
  function realPathRelativeTo(rootDir, src) {
600
- const fullPath = path5.resolve(rootDir, src);
601
- if (!fs3.existsSync(fullPath)) {
492
+ const fullPath = path4.resolve(rootDir, src);
493
+ if (!fs2.existsSync(fullPath)) {
602
494
  return src;
603
495
  }
604
- const realpath = fs3.realpathSync(path5.resolve(rootDir, src));
605
- return path5.relative(rootDir, realpath);
496
+ const realpath = fs2.realpathSync(path4.resolve(rootDir, src));
497
+ return path4.relative(rootDir, realpath);
606
498
  }
607
499
  var BuildAsset = class {
608
500
  constructor(assetMap, assetData) {
@@ -680,14 +572,14 @@ var BuildAsset = class {
680
572
 
681
573
  // src/cli/commands/build.ts
682
574
  import { dim as dim2, cyan } from "kleur/colors";
683
- var __dirname2 = path6.dirname(fileURLToPath2(import.meta.url));
575
+ var __dirname2 = path5.dirname(fileURLToPath2(import.meta.url));
684
576
  async function build(rootProjectDir, options) {
685
577
  var _a, _b, _c, _d, _e, _f, _g, _h;
686
578
  const mode = (options == null ? void 0 : options.mode) || "production";
687
579
  process.env.NODE_ENV = mode;
688
- const rootDir = path6.resolve(rootProjectDir || process.cwd());
689
- const rootConfig = await loadRootConfig(rootDir);
690
- const distDir = path6.join(rootDir, "dist");
580
+ const rootDir = path5.resolve(rootProjectDir || process.cwd());
581
+ const rootConfig = await loadRootConfig(rootDir, { command: "build" });
582
+ const distDir = path5.join(rootDir, "dist");
691
583
  const ssrOnly = (options == null ? void 0 : options.ssrOnly) || false;
692
584
  console.log();
693
585
  console.log(`${dim2("\u2503")} project: ${rootDir}`);
@@ -697,12 +589,12 @@ async function build(rootProjectDir, options) {
697
589
  await rmDir(distDir);
698
590
  await makeDir(distDir);
699
591
  const routeFiles = [];
700
- if (await isDirectory(path6.join(rootDir, "routes"))) {
701
- const pageFiles = await glob4("routes/**/*", { cwd: rootDir });
592
+ if (await isDirectory(path5.join(rootDir, "routes"))) {
593
+ const pageFiles = await glob3("routes/**/*", { cwd: rootDir });
702
594
  pageFiles.forEach((file) => {
703
- const parts = path6.parse(file);
595
+ const parts = path5.parse(file);
704
596
  if (!parts.name.startsWith("_") && isJsFile(parts.base)) {
705
- routeFiles.push(path6.resolve(rootDir, file));
597
+ routeFiles.push(path5.resolve(rootDir, file));
706
598
  }
707
599
  });
708
600
  }
@@ -711,12 +603,12 @@ async function build(rootProjectDir, options) {
711
603
  return sourceFile.filePath;
712
604
  });
713
605
  const bundleScripts = [];
714
- if (await isDirectory(path6.join(rootDir, "bundles"))) {
715
- const bundleFiles = await glob4("bundles/*", { cwd: rootDir });
606
+ if (await isDirectory(path5.join(rootDir, "bundles"))) {
607
+ const bundleFiles = await glob3("bundles/*", { cwd: rootDir });
716
608
  bundleFiles.forEach((file) => {
717
- const parts = path6.parse(file);
609
+ const parts = path5.parse(file);
718
610
  if (isJsFile(parts.base)) {
719
- bundleScripts.push(path6.resolve(rootDir, file));
611
+ bundleScripts.push(path5.resolve(rootDir, file));
720
612
  }
721
613
  });
722
614
  }
@@ -739,7 +631,7 @@ async function build(rootProjectDir, options) {
739
631
  plugins: vitePlugins
740
632
  };
741
633
  const ssrInput = {
742
- render: path6.resolve(__dirname2, "./render.js")
634
+ render: path5.resolve(__dirname2, "./render.js")
743
635
  };
744
636
  rootPlugins.forEach((plugin) => {
745
637
  if (plugin.ssrInput) {
@@ -769,7 +661,7 @@ async function build(rootProjectDir, options) {
769
661
  assetFileNames: "assets/[name].[hash][extname]"
770
662
  }
771
663
  },
772
- outDir: path6.join(distDir, "server"),
664
+ outDir: path5.join(distDir, "server"),
773
665
  ssr: true,
774
666
  ssrManifest: false,
775
667
  cssCodeSplit: true,
@@ -800,7 +692,7 @@ async function build(rootProjectDir, options) {
800
692
  ...(_e = (_d = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _d.rollupOptions) == null ? void 0 : _e.output
801
693
  }
802
694
  },
803
- outDir: path6.join(distDir, "routes"),
695
+ outDir: path5.join(distDir, "routes"),
804
696
  ssr: false,
805
697
  ssrManifest: false,
806
698
  manifest: true,
@@ -829,7 +721,7 @@ async function build(rootProjectDir, options) {
829
721
  ...(_h = (_g = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _g.rollupOptions) == null ? void 0 : _h.output
830
722
  }
831
723
  },
832
- outDir: path6.join(distDir, "client"),
724
+ outDir: path5.join(distDir, "client"),
833
725
  ssr: false,
834
726
  ssrManifest: false,
835
727
  manifest: true,
@@ -841,18 +733,18 @@ async function build(rootProjectDir, options) {
841
733
  }
842
734
  });
843
735
  } else {
844
- await writeFile(path6.join(distDir, "client/manifest.json"), "{}");
736
+ await writeFile(path5.join(distDir, "client/manifest.json"), "{}");
845
737
  }
846
738
  await copyGlob(
847
739
  "*.css",
848
- path6.join(distDir, "routes/assets"),
849
- path6.join(distDir, "client/assets")
740
+ path5.join(distDir, "routes/assets"),
741
+ path5.join(distDir, "client/assets")
850
742
  );
851
743
  const routesManifest = await loadJson(
852
- path6.join(distDir, "routes/manifest.json")
744
+ path5.join(distDir, "routes/manifest.json")
853
745
  );
854
746
  const clientManifest = await loadJson(
855
- path6.join(distDir, "client/manifest.json")
747
+ path5.join(distDir, "client/manifest.json")
856
748
  );
857
749
  function collectRouteCss(asset, cssDeps, visited) {
858
750
  if (!asset || !asset.file || visited.has(asset.file)) {
@@ -888,19 +780,19 @@ async function build(rootProjectDir, options) {
888
780
  );
889
781
  const rootManifest = assetMap.toJson();
890
782
  await writeFile(
891
- path6.join(distDir, "client/root-manifest.json"),
783
+ path5.join(distDir, "client/root-manifest.json"),
892
784
  JSON.stringify(rootManifest, null, 2)
893
785
  );
894
- const buildDir = path6.join(distDir, "html");
895
- const publicDir = path6.join(rootDir, "public");
896
- if (fsExtra2.existsSync(path6.join(rootDir, "public"))) {
897
- fsExtra2.copySync(publicDir, buildDir, { dereference: true });
786
+ const buildDir = path5.join(distDir, "html");
787
+ const publicDir = path5.join(rootDir, "public");
788
+ if (fsExtra.existsSync(path5.join(rootDir, "public"))) {
789
+ fsExtra.copySync(publicDir, buildDir, { dereference: true });
898
790
  } else {
899
791
  makeDir(buildDir);
900
792
  }
901
793
  console.log("\njs/css output:");
902
- makeDir(path6.join(buildDir, "assets"));
903
- makeDir(path6.join(buildDir, "chunks"));
794
+ makeDir(path5.join(buildDir, "assets"));
795
+ makeDir(path5.join(buildDir, "chunks"));
904
796
  await Promise.all(
905
797
  Object.keys(rootManifest).map(async (src) => {
906
798
  if (isRouteFile(src)) {
@@ -908,18 +800,18 @@ async function build(rootProjectDir, options) {
908
800
  }
909
801
  const assetData = rootManifest[src];
910
802
  const assetRelPath = assetData.assetUrl.slice(1);
911
- const assetFrom = path6.join(distDir, "client", assetRelPath);
912
- const assetTo = path6.join(buildDir, assetRelPath);
803
+ const assetFrom = path5.join(distDir, "client", assetRelPath);
804
+ const assetTo = path5.join(buildDir, assetRelPath);
913
805
  if (!await fileExists(assetFrom)) {
914
806
  console.log(`${assetFrom} does not exist`);
915
807
  return;
916
808
  }
917
- await fsExtra2.copy(assetFrom, assetTo);
809
+ await fsExtra.copy(assetFrom, assetTo);
918
810
  printFileOutput(fileSize(assetTo), "dist/html/", assetRelPath);
919
811
  })
920
812
  );
921
813
  if (!ssrOnly) {
922
- const render = await import(path6.join(distDir, "server/render.js"));
814
+ const render = await import(path5.join(distDir, "server/render.js"));
923
815
  const renderer = new render.Renderer(rootConfig, { assetMap, elementGraph });
924
816
  const sitemap = await renderer.getSitemap();
925
817
  console.log("\nhtml output:");
@@ -932,11 +824,11 @@ async function build(rootProjectDir, options) {
932
824
  if (data.notFound) {
933
825
  return;
934
826
  }
935
- let outFilePath = path6.join(urlPath.slice(1), "index.html");
827
+ let outFilePath = path5.join(urlPath.slice(1), "index.html");
936
828
  if (outFilePath.endsWith("404/index.html")) {
937
829
  outFilePath = outFilePath.replace("404/index.html", "404.html");
938
830
  }
939
- const outPath = path6.join(buildDir, outFilePath);
831
+ const outPath = path5.join(buildDir, outFilePath);
940
832
  let html = data.html || "";
941
833
  if (rootConfig.prettyHtml !== false) {
942
834
  html = await htmlPretty(html, rootConfig.prettyHtmlOptions);
@@ -954,7 +846,7 @@ function isRouteFile(filepath) {
954
846
  return filepath.startsWith("routes") && isJsFile(filepath);
955
847
  }
956
848
  function fileSize(filepath) {
957
- const stats = fsExtra2.statSync(filepath);
849
+ const stats = fsExtra.statSync(filepath);
958
850
  const bytes = stats.size;
959
851
  const k = 1024;
960
852
  if (bytes < k) {
@@ -973,14 +865,14 @@ function printFileOutput(fileSize2, outputDir, outputFile) {
973
865
  }
974
866
 
975
867
  // src/cli/commands/preview.ts
976
- import path7 from "node:path";
868
+ import path6 from "node:path";
977
869
  import { default as express2 } from "express";
978
870
  import { dim as dim3 } from "kleur/colors";
979
871
  import sirv from "sirv";
980
872
  import compression from "compression";
981
873
  async function preview(rootProjectDir) {
982
874
  process.env.NODE_ENV = "development";
983
- const rootDir = path7.resolve(rootProjectDir || process.cwd());
875
+ const rootDir = path6.resolve(rootProjectDir || process.cwd());
984
876
  const server = await createServer3({ rootDir });
985
877
  const port = parseInt(process.env.PORT || "4007");
986
878
  console.log();
@@ -992,12 +884,12 @@ async function preview(rootProjectDir) {
992
884
  }
993
885
  async function createServer3(options) {
994
886
  const rootDir = options.rootDir;
995
- const rootConfig = await loadRootConfig(rootDir);
996
- const distDir = path7.join(rootDir, "dist");
887
+ const rootConfig = await loadRootConfig(rootDir, { command: "preview" });
888
+ const distDir = path6.join(rootDir, "dist");
997
889
  const server = express2();
998
890
  server.disable("x-powered-by");
999
891
  server.use(compression());
1000
- server.use(rootProjectMiddleware({ rootDir, rootConfig }));
892
+ server.use(rootProjectMiddleware({ rootConfig }));
1001
893
  server.use(await rootPreviewRendererMiddleware({ rootConfig, distDir }));
1002
894
  const plugins = rootConfig.plugins || [];
1003
895
  configureServerPlugins(
@@ -1008,7 +900,7 @@ async function createServer3(options) {
1008
900
  userMiddlewares.forEach((middleware) => {
1009
901
  server.use(middleware);
1010
902
  });
1011
- const publicDir = path7.join(distDir, "html");
903
+ const publicDir = path6.join(distDir, "html");
1012
904
  server.use(sirv(publicDir, { dev: false }));
1013
905
  server.use(rootPreviewServerMiddleware());
1014
906
  server.use(rootPreviewServer404Middleware());
@@ -1021,8 +913,8 @@ async function createServer3(options) {
1021
913
  }
1022
914
  async function rootPreviewRendererMiddleware(options) {
1023
915
  const { distDir, rootConfig } = options;
1024
- const render = await import(path7.join(distDir, "server/render.js"));
1025
- const manifestPath = path7.join(distDir, "client/root-manifest.json");
916
+ const render = await import(path6.join(distDir, "server/render.js"));
917
+ const manifestPath = path6.join(distDir, "client/root-manifest.json");
1026
918
  if (!await fileExists(manifestPath)) {
1027
919
  throw new Error(
1028
920
  `could not find ${manifestPath}. run \`root build\` before \`root preview\`.`
@@ -1058,7 +950,7 @@ function rootPreviewServer404Middleware() {
1058
950
  return async (req, res) => {
1059
951
  console.error(`\u2753 404 ${req.originalUrl}`);
1060
952
  const url = req.path;
1061
- const ext = path7.extname(url);
953
+ const ext = path6.extname(url);
1062
954
  const renderer = req.renderer;
1063
955
  if (!ext) {
1064
956
  const data = await renderer.render404();
@@ -1074,7 +966,7 @@ function rootPreviewServer500Middleware() {
1074
966
  console.error(`\u2757 500 ${req.originalUrl}`);
1075
967
  console.error(String(err.stack || err));
1076
968
  const url = req.path;
1077
- const ext = path7.extname(url);
969
+ const ext = path6.extname(url);
1078
970
  const renderer = req.renderer;
1079
971
  if (!ext) {
1080
972
  const data = await renderer.renderError(err);
@@ -1087,14 +979,14 @@ function rootPreviewServer500Middleware() {
1087
979
  }
1088
980
 
1089
981
  // src/cli/commands/start.ts
1090
- import path8 from "node:path";
982
+ import path7 from "node:path";
1091
983
  import { default as express3 } from "express";
1092
984
  import { dim as dim4 } from "kleur/colors";
1093
985
  import sirv2 from "sirv";
1094
986
  import compression2 from "compression";
1095
987
  async function start(rootProjectDir) {
1096
988
  process.env.NODE_ENV = "production";
1097
- const rootDir = path8.resolve(rootProjectDir || process.cwd());
989
+ const rootDir = path7.resolve(rootProjectDir || process.cwd());
1098
990
  const server = await createServer4({ rootDir });
1099
991
  const port = parseInt(process.env.PORT || "4007");
1100
992
  console.log();
@@ -1106,12 +998,12 @@ async function start(rootProjectDir) {
1106
998
  }
1107
999
  async function createServer4(options) {
1108
1000
  const rootDir = options.rootDir;
1109
- const rootConfig = await loadRootConfig(rootDir);
1110
- const distDir = path8.join(rootDir, "dist");
1001
+ const rootConfig = await loadRootConfig(rootDir, { command: "start" });
1002
+ const distDir = path7.join(rootDir, "dist");
1111
1003
  const server = express3();
1112
1004
  server.disable("x-powered-by");
1113
1005
  server.use(compression2());
1114
- server.use(rootProjectMiddleware({ rootDir, rootConfig }));
1006
+ server.use(rootProjectMiddleware({ rootConfig }));
1115
1007
  server.use(await rootProdRendererMiddleware({ rootConfig, distDir }));
1116
1008
  const plugins = rootConfig.plugins || [];
1117
1009
  configureServerPlugins(
@@ -1122,7 +1014,7 @@ async function createServer4(options) {
1122
1014
  userMiddlewares.forEach((middleware) => {
1123
1015
  server.use(middleware);
1124
1016
  });
1125
- const publicDir = path8.join(distDir, "html");
1017
+ const publicDir = path7.join(distDir, "html");
1126
1018
  server.use(sirv2(publicDir, { dev: false }));
1127
1019
  server.use(rootProdServerMiddleware());
1128
1020
  server.use(rootProdServer404Middleware());
@@ -1135,8 +1027,8 @@ async function createServer4(options) {
1135
1027
  }
1136
1028
  async function rootProdRendererMiddleware(options) {
1137
1029
  const { distDir, rootConfig } = options;
1138
- const render = await import(path8.join(distDir, "server/render.js"));
1139
- const manifestPath = path8.join(distDir, "client/root-manifest.json");
1030
+ const render = await import(path7.join(distDir, "server/render.js"));
1031
+ const manifestPath = path7.join(distDir, "client/root-manifest.json");
1140
1032
  if (!await fileExists(manifestPath)) {
1141
1033
  throw new Error(
1142
1034
  `could not find ${manifestPath}. run \`root build\` before \`root start\`.`
@@ -1173,7 +1065,7 @@ function rootProdServer404Middleware() {
1173
1065
  console.error(`\u2753 404 ${req.originalUrl}`);
1174
1066
  if (req.renderer) {
1175
1067
  const url = req.path;
1176
- const ext = path8.extname(url);
1068
+ const ext = path7.extname(url);
1177
1069
  if (!ext) {
1178
1070
  const renderer = req.renderer;
1179
1071
  const data = await renderer.render404();
@@ -1191,7 +1083,7 @@ function rootProdServer500Middleware() {
1191
1083
  console.error(String(err.stack || err));
1192
1084
  if (req.renderer) {
1193
1085
  const url = req.path;
1194
- const ext = path8.extname(url);
1086
+ const ext = path7.extname(url);
1195
1087
  if (!ext) {
1196
1088
  const renderer = req.renderer;
1197
1089
  const data = await renderer.renderError(err);