elit 3.6.0 → 3.6.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/build.cjs CHANGED
@@ -418,7 +418,11 @@ function findInstalledPackageRoot(startDir, packageName) {
418
418
  }
419
419
  function getWorkspacePackageImportCandidates(packageRoot, specifier, options = {}) {
420
420
  const subpath = specifier === "elit" ? "index" : specifier.slice("elit/".length);
421
- const builtCandidates = [
421
+ const builtCandidates = options.preferredBuiltFormat === "cjs" ? [
422
+ resolve(packageRoot, "dist", `${subpath}.cjs`),
423
+ resolve(packageRoot, "dist", `${subpath}.js`),
424
+ resolve(packageRoot, "dist", `${subpath}.mjs`)
425
+ ] : [
422
426
  resolve(packageRoot, "dist", `${subpath}.mjs`),
423
427
  resolve(packageRoot, "dist", `${subpath}.js`),
424
428
  resolve(packageRoot, "dist", `${subpath}.cjs`)
@@ -463,12 +467,12 @@ function readFileAsString(filePath) {
463
467
  const contentBuffer = readFileSync(filePath, "utf-8");
464
468
  return typeof contentBuffer === "string" ? contentBuffer : contentBuffer.toString("utf-8");
465
469
  }
466
- function createWorkspacePackagePlugin(entryDir) {
470
+ function createWorkspacePackagePlugin(entryDir, options = {}) {
467
471
  return {
468
472
  name: "workspace-package-self-reference",
469
473
  setup(build2) {
470
474
  build2.onResolve({ filter: /^elit(?:\/.*)?$/ }, (args) => {
471
- const resolved = resolveWorkspacePackageImport(args.path, args.resolveDir || entryDir);
475
+ const resolved = resolveWorkspacePackageImport(args.path, args.resolveDir || entryDir, options);
472
476
  return resolved ? { path: resolved } : void 0;
473
477
  });
474
478
  }
@@ -542,7 +546,10 @@ async function build(options) {
542
546
  };
543
547
  try {
544
548
  const platform = config.platform || (config.format === "cjs" ? "node" : "browser");
545
- const workspacePackagePlugin = createWorkspacePackagePlugin(dirname(entryPath));
549
+ const workspacePackagePlugin = createWorkspacePackagePlugin(dirname(entryPath), {
550
+ preferBuilt: platform === "browser",
551
+ preferredBuiltFormat: platform === "browser" ? "esm" : void 0
552
+ });
546
553
  const plugins = platform === "browser" ? [workspacePackagePlugin, browserOnlyPlugin] : [workspacePackagePlugin];
547
554
  const define = {};
548
555
  if (config.env) {
package/dist/build.js CHANGED
@@ -2917,7 +2917,11 @@ error: ${text}`);
2917
2917
  }
2918
2918
  function getWorkspacePackageImportCandidates(packageRoot, specifier, options = {}) {
2919
2919
  const subpath = specifier === "elit" ? "index" : specifier.slice("elit/".length);
2920
- const builtCandidates = [
2920
+ const builtCandidates = options.preferredBuiltFormat === "cjs" ? [
2921
+ resolve(packageRoot, "dist", `${subpath}.cjs`),
2922
+ resolve(packageRoot, "dist", `${subpath}.js`),
2923
+ resolve(packageRoot, "dist", `${subpath}.mjs`)
2924
+ ] : [
2921
2925
  resolve(packageRoot, "dist", `${subpath}.mjs`),
2922
2926
  resolve(packageRoot, "dist", `${subpath}.js`),
2923
2927
  resolve(packageRoot, "dist", `${subpath}.cjs`)
@@ -2962,12 +2966,12 @@ error: ${text}`);
2962
2966
  const contentBuffer = readFileSync(filePath, "utf-8");
2963
2967
  return typeof contentBuffer === "string" ? contentBuffer : contentBuffer.toString("utf-8");
2964
2968
  }
2965
- function createWorkspacePackagePlugin(entryDir) {
2969
+ function createWorkspacePackagePlugin(entryDir, options = {}) {
2966
2970
  return {
2967
2971
  name: "workspace-package-self-reference",
2968
2972
  setup(build2) {
2969
2973
  build2.onResolve({ filter: /^elit(?:\/.*)?$/ }, (args) => {
2970
- const resolved = resolveWorkspacePackageImport(args.path, args.resolveDir || entryDir);
2974
+ const resolved = resolveWorkspacePackageImport(args.path, args.resolveDir || entryDir, options);
2971
2975
  return resolved ? { path: resolved } : void 0;
2972
2976
  });
2973
2977
  }
@@ -3041,7 +3045,10 @@ error: ${text}`);
3041
3045
  };
3042
3046
  try {
3043
3047
  const platform = config.platform || (config.format === "cjs" ? "node" : "browser");
3044
- const workspacePackagePlugin = createWorkspacePackagePlugin(dirname(entryPath));
3048
+ const workspacePackagePlugin = createWorkspacePackagePlugin(dirname(entryPath), {
3049
+ preferBuilt: platform === "browser",
3050
+ preferredBuiltFormat: platform === "browser" ? "esm" : void 0
3051
+ });
3045
3052
  const plugins = platform === "browser" ? [workspacePackagePlugin, browserOnlyPlugin] : [workspacePackagePlugin];
3046
3053
  const define = {};
3047
3054
  if (config.env) {
package/dist/build.mjs CHANGED
@@ -390,7 +390,11 @@ function findInstalledPackageRoot(startDir, packageName) {
390
390
  }
391
391
  function getWorkspacePackageImportCandidates(packageRoot, specifier, options = {}) {
392
392
  const subpath = specifier === "elit" ? "index" : specifier.slice("elit/".length);
393
- const builtCandidates = [
393
+ const builtCandidates = options.preferredBuiltFormat === "cjs" ? [
394
+ resolve(packageRoot, "dist", `${subpath}.cjs`),
395
+ resolve(packageRoot, "dist", `${subpath}.js`),
396
+ resolve(packageRoot, "dist", `${subpath}.mjs`)
397
+ ] : [
394
398
  resolve(packageRoot, "dist", `${subpath}.mjs`),
395
399
  resolve(packageRoot, "dist", `${subpath}.js`),
396
400
  resolve(packageRoot, "dist", `${subpath}.cjs`)
@@ -435,12 +439,12 @@ function readFileAsString(filePath) {
435
439
  const contentBuffer = readFileSync(filePath, "utf-8");
436
440
  return typeof contentBuffer === "string" ? contentBuffer : contentBuffer.toString("utf-8");
437
441
  }
438
- function createWorkspacePackagePlugin(entryDir) {
442
+ function createWorkspacePackagePlugin(entryDir, options = {}) {
439
443
  return {
440
444
  name: "workspace-package-self-reference",
441
445
  setup(build2) {
442
446
  build2.onResolve({ filter: /^elit(?:\/.*)?$/ }, (args) => {
443
- const resolved = resolveWorkspacePackageImport(args.path, args.resolveDir || entryDir);
447
+ const resolved = resolveWorkspacePackageImport(args.path, args.resolveDir || entryDir, options);
444
448
  return resolved ? { path: resolved } : void 0;
445
449
  });
446
450
  }
@@ -514,7 +518,10 @@ async function build(options) {
514
518
  };
515
519
  try {
516
520
  const platform = config.platform || (config.format === "cjs" ? "node" : "browser");
517
- const workspacePackagePlugin = createWorkspacePackagePlugin(dirname(entryPath));
521
+ const workspacePackagePlugin = createWorkspacePackagePlugin(dirname(entryPath), {
522
+ preferBuilt: platform === "browser",
523
+ preferredBuiltFormat: platform === "browser" ? "esm" : void 0
524
+ });
518
525
  const plugins = platform === "browser" ? [workspacePackagePlugin, browserOnlyPlugin] : [workspacePackagePlugin];
519
526
  const define = {};
520
527
  if (config.env) {
package/dist/cli.cjs CHANGED
@@ -59462,7 +59462,11 @@ function findInstalledPackageRoot(startDir, packageName) {
59462
59462
  }
59463
59463
  function getWorkspacePackageImportCandidates(packageRoot, specifier, options = {}) {
59464
59464
  const subpath = specifier === "elit" ? "index" : specifier.slice("elit/".length);
59465
- const builtCandidates = [
59465
+ const builtCandidates = options.preferredBuiltFormat === "cjs" ? [
59466
+ resolve(packageRoot, "dist", `${subpath}.cjs`),
59467
+ resolve(packageRoot, "dist", `${subpath}.js`),
59468
+ resolve(packageRoot, "dist", `${subpath}.mjs`)
59469
+ ] : [
59466
59470
  resolve(packageRoot, "dist", `${subpath}.mjs`),
59467
59471
  resolve(packageRoot, "dist", `${subpath}.js`),
59468
59472
  resolve(packageRoot, "dist", `${subpath}.cjs`)
@@ -59594,7 +59598,8 @@ async function loadConfigFile(configPath) {
59594
59598
  setup(build3) {
59595
59599
  build3.onResolve({ filter: /.*/ }, (args) => {
59596
59600
  const workspacePackageImport = resolveWorkspacePackageImport(args.path, args.resolveDir || configDir, {
59597
- preferBuilt: true
59601
+ preferBuilt: true,
59602
+ preferredBuiltFormat: "esm"
59598
59603
  });
59599
59604
  if (workspacePackageImport) {
59600
59605
  return {
@@ -61337,22 +61342,30 @@ async function resolveWorkspaceElitImportBasePath(rootDir, basePath, _mode) {
61337
61342
  }
61338
61343
  return void 0;
61339
61344
  }
61345
+ var BROWSER_SAFE_ELIT_IMPORTS = {
61346
+ "elit": "index",
61347
+ "elit/dom": "dom",
61348
+ "elit/el": "el",
61349
+ "elit/native": "native",
61350
+ "elit/universal": "universal",
61351
+ "elit/router": "router",
61352
+ "elit/state": "state",
61353
+ "elit/style": "style",
61354
+ "elit/hmr": "hmr",
61355
+ "elit/types": "types"
61356
+ };
61357
+ function createBrowserSafeElitImports(basePath, fileExt) {
61358
+ return Object.fromEntries(
61359
+ Object.entries(BROWSER_SAFE_ELIT_IMPORTS).map(([specifier, outputName]) => [
61360
+ specifier,
61361
+ `${basePath}/${outputName}${fileExt}`
61362
+ ])
61363
+ );
61364
+ }
61340
61365
  var createElitImportMap = async (rootDir, basePath = "", mode = "dev") => {
61341
61366
  const workspaceImportBasePath = await resolveWorkspaceElitImportBasePath(rootDir, basePath, mode);
61342
- const fileExt = ".js";
61343
- const elitImports = workspaceImportBasePath ? {
61344
- "elit": `${workspaceImportBasePath}/index${fileExt}`,
61345
- "elit/": `${workspaceImportBasePath}/`,
61346
- "elit/dom": `${workspaceImportBasePath}/dom${fileExt}`,
61347
- "elit/state": `${workspaceImportBasePath}/state${fileExt}`,
61348
- "elit/style": `${workspaceImportBasePath}/style${fileExt}`,
61349
- "elit/el": `${workspaceImportBasePath}/el${fileExt}`,
61350
- "elit/universal": `${workspaceImportBasePath}/universal${fileExt}`,
61351
- "elit/router": `${workspaceImportBasePath}/router${fileExt}`,
61352
- "elit/hmr": `${workspaceImportBasePath}/hmr${fileExt}`,
61353
- "elit/types": `${workspaceImportBasePath}/types${fileExt}`,
61354
- "elit/native": `${workspaceImportBasePath}/native${fileExt}`
61355
- } : {};
61367
+ const fileExt = ".mjs";
61368
+ const elitImports = workspaceImportBasePath ? createBrowserSafeElitImports(workspaceImportBasePath, fileExt) : {};
61356
61369
  const externalImports = await generateExternalImportMaps(rootDir, basePath);
61357
61370
  const allImports = { ...externalImports, ...elitImports };
61358
61371
  return `<script type="importmap">${JSON.stringify({ imports: allImports }, null, 2)}</script>`;
@@ -61623,6 +61636,29 @@ async function processPackage(nodeModulesPath, pkgName, importMap, basePath) {
61623
61636
  }
61624
61637
  }
61625
61638
  function processExportsField(pkgName, exports2, baseUrl, importMap) {
61639
+ if (pkgName === "elit") {
61640
+ if (typeof exports2 !== "object" || exports2 === null) {
61641
+ return;
61642
+ }
61643
+ const elitExports = exports2;
61644
+ const browserSafeImports = {};
61645
+ const rootResolved = "." in elitExports ? resolveExport(elitExports["."]) : "import" in elitExports ? resolveExport(elitExports) : null;
61646
+ if (rootResolved) {
61647
+ browserSafeImports.elit = `${baseUrl}/${rootResolved}`;
61648
+ }
61649
+ const allowedSubpaths = Object.keys(BROWSER_SAFE_ELIT_IMPORTS).filter((specifier) => specifier !== "elit").map((specifier) => ({
61650
+ exportKey: `./${specifier.slice("elit/".length)}`,
61651
+ importName: specifier
61652
+ }));
61653
+ for (const { exportKey, importName } of allowedSubpaths) {
61654
+ const resolved = resolveExport(elitExports[exportKey]);
61655
+ if (resolved) {
61656
+ browserSafeImports[importName] = `${baseUrl}/${resolved}`;
61657
+ }
61658
+ }
61659
+ Object.assign(importMap, browserSafeImports);
61660
+ return;
61661
+ }
61626
61662
  if (typeof exports2 === "string") {
61627
61663
  importMap[pkgName] = `${baseUrl}/${exports2}`;
61628
61664
  importMap[`${pkgName}/`] = `${baseUrl}/`;
@@ -61866,6 +61902,85 @@ function shouldUseClientFallbackRoot(primaryRoot, fallbackRoot, indexPath) {
61866
61902
  const primaryHasRuntimeSources = existsSync(join(resolvedPrimaryRoot, "src")) || existsSync(join(resolvedPrimaryRoot, "public")) || existsSync(join(resolvedPrimaryRoot, normalizedIndexPath));
61867
61903
  return !primaryHasRuntimeSources;
61868
61904
  }
61905
+ function isPathWithinRoot(filePath, rootDir) {
61906
+ return filePath === rootDir || filePath.startsWith(rootDir.endsWith(sep) ? rootDir : `${rootDir}${sep}`);
61907
+ }
61908
+ async function getAllowedClientRoots(client) {
61909
+ const allowedRoots = [];
61910
+ for (const candidateRoot of [client.root, client.fallbackRoot]) {
61911
+ if (!candidateRoot) {
61912
+ continue;
61913
+ }
61914
+ try {
61915
+ const resolvedRoot = await realpath(resolve(candidateRoot));
61916
+ if (!allowedRoots.includes(resolvedRoot)) {
61917
+ allowedRoots.push(resolvedRoot);
61918
+ }
61919
+ } catch {
61920
+ }
61921
+ }
61922
+ return allowedRoots;
61923
+ }
61924
+ async function getClientBaseDirs(client, isDistRequest, isNodeModulesRequest) {
61925
+ const baseDirs = [];
61926
+ for (const candidateRoot of [client.root, client.fallbackRoot]) {
61927
+ if (!candidateRoot) {
61928
+ continue;
61929
+ }
61930
+ try {
61931
+ const resolvedRoot = await realpath(resolve(candidateRoot));
61932
+ let baseDir = resolvedRoot;
61933
+ if (isDistRequest || isNodeModulesRequest) {
61934
+ const targetDir = isDistRequest ? "dist" : "node_modules";
61935
+ const foundDir = await findSpecialDir(candidateRoot, targetDir);
61936
+ baseDir = foundDir ? await realpath(foundDir) : resolvedRoot;
61937
+ }
61938
+ if (!baseDirs.includes(baseDir)) {
61939
+ baseDirs.push(baseDir);
61940
+ }
61941
+ } catch {
61942
+ }
61943
+ }
61944
+ return baseDirs;
61945
+ }
61946
+ async function resolveClientPathFromBaseDir(baseDir, normalizedPath) {
61947
+ const tryRealpathWithinBaseDir = async (relativePath2) => {
61948
+ const unresolvedPath = resolve(join(baseDir, relativePath2));
61949
+ if (!isPathWithinRoot(unresolvedPath, baseDir)) {
61950
+ return void 0;
61951
+ }
61952
+ try {
61953
+ return await realpath(unresolvedPath);
61954
+ } catch {
61955
+ return void 0;
61956
+ }
61957
+ };
61958
+ const exactPath = await tryRealpathWithinBaseDir(normalizedPath);
61959
+ if (exactPath) {
61960
+ return exactPath;
61961
+ }
61962
+ if (normalizedPath.endsWith(".js")) {
61963
+ const tsPath = await tryRealpathWithinBaseDir(normalizedPath.replace(/\.js$/, ".ts"));
61964
+ if (tsPath) {
61965
+ return tsPath;
61966
+ }
61967
+ }
61968
+ if (normalizedPath.includes(".")) {
61969
+ return void 0;
61970
+ }
61971
+ for (const candidatePath of [
61972
+ `${normalizedPath}.ts`,
61973
+ `${normalizedPath}.js`,
61974
+ join(normalizedPath, "index.ts"),
61975
+ join(normalizedPath, "index.js")
61976
+ ]) {
61977
+ const resolvedPath = await tryRealpathWithinBaseDir(candidatePath);
61978
+ if (resolvedPath) {
61979
+ return resolvedPath;
61980
+ }
61981
+ }
61982
+ return void 0;
61983
+ }
61869
61984
  function createDevServer(options) {
61870
61985
  const config = { ...defaultOptions, ...options };
61871
61986
  const wsClients = /* @__PURE__ */ new Set();
@@ -61895,6 +62010,7 @@ function createDevServer(options) {
61895
62010
  const activeRoot = useFallbackRoot ? client.fallbackRoot || client.root : client.root;
61896
62011
  return {
61897
62012
  root: activeRoot,
62013
+ fallbackRoot: useFallbackRoot ? void 0 : client.fallbackRoot,
61898
62014
  basePath,
61899
62015
  index: useFallbackRoot ? void 0 : indexPath,
61900
62016
  ssr: useFallbackRoot ? void 0 : client.ssr,
@@ -61996,75 +62112,26 @@ function createDevServer(options) {
61996
62112
  return send403(res, "403 Forbidden");
61997
62113
  }
61998
62114
  normalizedPath = tempPath;
61999
- const rootDir = await realpath(resolve(matchedClient.root));
62000
- let baseDir = rootDir;
62001
- if (isDistRequest || isNodeModulesRequest) {
62002
- const targetDir = isDistRequest ? "dist" : "node_modules";
62003
- const foundDir = await findSpecialDir(matchedClient.root, targetDir);
62004
- baseDir = foundDir ? await realpath(foundDir) : rootDir;
62005
- }
62006
62115
  let fullPath;
62007
- try {
62008
- const unresolvedPath = resolve(join(baseDir, normalizedPath));
62009
- if (!unresolvedPath.startsWith(baseDir.endsWith(sep) ? baseDir : baseDir + sep)) {
62010
- if (config.logging) console.log(`[403] File access outside of root (before symlink): ${unresolvedPath}`);
62011
- return send403(res, "403 Forbidden");
62012
- }
62013
- fullPath = await realpath(unresolvedPath);
62014
- if (config.logging && filePath === "/src/pages") {
62015
- console.log(`[DEBUG] Initial resolve succeeded: ${fullPath}`);
62016
- }
62017
- } catch (firstError) {
62018
- let resolvedPath;
62019
- if (config.logging && !normalizedPath.includes(".")) {
62020
- console.log(`[DEBUG] File not found: ${normalizedPath}, trying extensions...`);
62021
- }
62022
- if (normalizedPath.endsWith(".js")) {
62023
- const tsPath = normalizedPath.replace(/\.js$/, ".ts");
62024
- try {
62025
- const tsFullPath = await realpath(resolve(join(baseDir, tsPath)));
62026
- if (!tsFullPath.startsWith(baseDir.endsWith(sep) ? baseDir : baseDir + sep)) {
62027
- if (config.logging) console.log(`[403] Fallback TS path outside of root: ${tsFullPath}`);
62028
- return send403(res, "403 Forbidden");
62029
- }
62030
- resolvedPath = tsFullPath;
62031
- } catch {
62032
- }
62033
- }
62034
- if (!resolvedPath && !normalizedPath.includes(".")) {
62035
- try {
62036
- resolvedPath = await realpath(resolve(join(baseDir, normalizedPath + ".ts")));
62037
- if (config.logging) console.log(`[DEBUG] Found: ${normalizedPath}.ts`);
62038
- } catch {
62039
- try {
62040
- resolvedPath = await realpath(resolve(join(baseDir, normalizedPath + ".js")));
62041
- if (config.logging) console.log(`[DEBUG] Found: ${normalizedPath}.js`);
62042
- } catch {
62043
- try {
62044
- resolvedPath = await realpath(resolve(join(baseDir, normalizedPath, "index.ts")));
62045
- if (config.logging) console.log(`[DEBUG] Found: ${normalizedPath}/index.ts`);
62046
- } catch {
62047
- try {
62048
- resolvedPath = await realpath(resolve(join(baseDir, normalizedPath, "index.js")));
62049
- if (config.logging) console.log(`[DEBUG] Found: ${normalizedPath}/index.js`);
62050
- } catch {
62051
- if (config.logging) console.log(`[DEBUG] Not found: all attempts failed for ${normalizedPath}`);
62052
- }
62053
- }
62054
- }
62116
+ const baseDirs = await getClientBaseDirs(matchedClient, isDistRequest, isNodeModulesRequest);
62117
+ for (const baseDir of baseDirs) {
62118
+ fullPath = await resolveClientPathFromBaseDir(baseDir, normalizedPath);
62119
+ if (fullPath) {
62120
+ if (config.logging && filePath === "/src/pages") {
62121
+ console.log(`[DEBUG] Initial resolve succeeded: ${fullPath}`);
62055
62122
  }
62123
+ break;
62056
62124
  }
62057
- if (!resolvedPath) {
62058
- if (!res.headersSent) {
62059
- if (filePath === "/index.html" && matchedClient.ssr) {
62060
- return await serveSSR(res, matchedClient);
62061
- }
62062
- if (config.logging) console.log(`[404] ${filePath}`);
62063
- return send404(res, "404 Not Found");
62125
+ }
62126
+ if (!fullPath) {
62127
+ if (!res.headersSent) {
62128
+ if (filePath === "/index.html" && matchedClient.ssr) {
62129
+ return await serveSSR(res, matchedClient);
62064
62130
  }
62065
- return;
62131
+ if (config.logging) console.log(`[404] ${filePath}`);
62132
+ return send404(res, "404 Not Found");
62066
62133
  }
62067
- fullPath = resolvedPath;
62134
+ return;
62068
62135
  }
62069
62136
  try {
62070
62137
  const stats = await stat(fullPath);
@@ -62093,11 +62160,12 @@ function createDevServer(options) {
62093
62160
  return send404(res, "404 Not Found");
62094
62161
  }
62095
62162
  try {
62163
+ const allowedRoots = await getAllowedClientRoots(matchedClient);
62096
62164
  const stats = await stat(fullPath);
62097
62165
  if (stats.isDirectory()) {
62098
62166
  try {
62099
62167
  const indexPath = await realpath(resolve(join(fullPath, "index.html")));
62100
- if (!indexPath.startsWith(rootDir + sep) && indexPath !== rootDir) {
62168
+ if (!isPathWithinRoot(indexPath, fullPath) && !allowedRoots.some((rootDir) => isPathWithinRoot(indexPath, rootDir))) {
62101
62169
  return send403(res, "403 Forbidden");
62102
62170
  }
62103
62171
  await stat(indexPath);
@@ -62119,10 +62187,11 @@ function createDevServer(options) {
62119
62187
  return input.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
62120
62188
  }
62121
62189
  try {
62122
- const rootDir = await realpath(resolve(client.root));
62190
+ const allowedRoots = await getAllowedClientRoots(client);
62191
+ const rootDir = allowedRoots[0] || await realpath(resolve(client.root));
62123
62192
  const unresolvedPath = resolve(filePath);
62124
62193
  if (!isNodeModulesOrDist) {
62125
- if (!unresolvedPath.startsWith(rootDir + sep) && unresolvedPath !== rootDir) {
62194
+ if (!allowedRoots.some((allowedRoot) => isPathWithinRoot(unresolvedPath, allowedRoot))) {
62126
62195
  if (config.logging) console.log(`[403] Attempted to serve file outside allowed directories: ${filePath}`);
62127
62196
  return send403(res, "403 Forbidden");
62128
62197
  }
@@ -62544,12 +62613,12 @@ function readFileAsString2(filePath) {
62544
62613
  const contentBuffer = readFileSync(filePath, "utf-8");
62545
62614
  return typeof contentBuffer === "string" ? contentBuffer : contentBuffer.toString("utf-8");
62546
62615
  }
62547
- function createWorkspacePackagePlugin(entryDir) {
62616
+ function createWorkspacePackagePlugin(entryDir, options = {}) {
62548
62617
  return {
62549
62618
  name: "workspace-package-self-reference",
62550
62619
  setup(build2) {
62551
62620
  build2.onResolve({ filter: /^elit(?:\/.*)?$/ }, (args) => {
62552
- const resolved = resolveWorkspacePackageImport(args.path, args.resolveDir || entryDir);
62621
+ const resolved = resolveWorkspacePackageImport(args.path, args.resolveDir || entryDir, options);
62553
62622
  return resolved ? { path: resolved } : void 0;
62554
62623
  });
62555
62624
  }
@@ -62623,7 +62692,10 @@ async function build(options) {
62623
62692
  };
62624
62693
  try {
62625
62694
  const platform = config.platform || (config.format === "cjs" ? "node" : "browser");
62626
- const workspacePackagePlugin = createWorkspacePackagePlugin(dirname(entryPath));
62695
+ const workspacePackagePlugin = createWorkspacePackagePlugin(dirname(entryPath), {
62696
+ preferBuilt: platform === "browser",
62697
+ preferredBuiltFormat: platform === "browser" ? "esm" : void 0
62698
+ });
62627
62699
  const plugins = platform === "browser" ? [workspacePackagePlugin, browserOnlyPlugin] : [workspacePackagePlugin];
62628
62700
  const define2 = {};
62629
62701
  if (config.env) {
@@ -81837,12 +81909,12 @@ init_path();
81837
81909
  // src/preview-build.ts
81838
81910
  init_fs();
81839
81911
  init_path();
81840
- function createWorkspacePackagePlugin3(resolveDir) {
81912
+ function createWorkspacePackagePlugin3(resolveDir, options = {}) {
81841
81913
  return {
81842
81914
  name: "workspace-package-self-reference",
81843
81915
  setup(build2) {
81844
81916
  build2.onResolve({ filter: /^elit(?:\/.*)?$/ }, (args) => {
81845
- const resolved = resolveWorkspacePackageImport(args.path, args.resolveDir || resolveDir);
81917
+ const resolved = resolveWorkspacePackageImport(args.path, args.resolveDir || resolveDir, options);
81846
81918
  return resolved ? { path: resolved } : void 0;
81847
81919
  });
81848
81920
  }
@@ -82024,7 +82096,10 @@ async function buildStandalonePreviewServer(options) {
82024
82096
  const outputDir = dirname(plan.outputPath);
82025
82097
  mkdirSync(outputDir, { recursive: true });
82026
82098
  const { build: build2 } = await import("esbuild");
82027
- const workspacePackagePlugin = createWorkspacePackagePlugin3(cwd);
82099
+ const workspacePackagePlugin = createWorkspacePackagePlugin3(cwd, {
82100
+ preferBuilt: true,
82101
+ preferredBuiltFormat: "cjs"
82102
+ });
82028
82103
  const entrySource = createStandalonePreviewEntrySource(options.configPath, plan, options.previewConfig);
82029
82104
  await build2({
82030
82105
  stdin: {
@@ -82252,7 +82327,10 @@ async function buildStandaloneDevServer(options) {
82252
82327
  const outputDir = dirname(plan.outputPath);
82253
82328
  mkdirSync(outputDir, { recursive: true });
82254
82329
  const { build: build2, version } = await import("esbuild");
82255
- const workspacePackagePlugin = createWorkspacePackagePlugin3(cwd);
82330
+ const workspacePackagePlugin = createWorkspacePackagePlugin3(cwd, {
82331
+ preferBuilt: true,
82332
+ preferredBuiltFormat: "cjs"
82333
+ });
82256
82334
  const entrySource = createStandaloneDevEntrySource(options.configPath, plan, options.devConfig, {
82257
82335
  cwd,
82258
82336
  buildConfig: options.buildConfig,