evolit 0.1.0-alpha.10 → 0.1.0-alpha.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evolit",
3
- "version": "0.1.0-alpha.10",
3
+ "version": "0.1.0-alpha.12",
4
4
  "description": "A convention-driven application framework for LitSX and web components.",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@4.10.3",
@@ -57,6 +57,18 @@ function isRelativeSpecifier(specifier) {
57
57
  );
58
58
  }
59
59
 
60
+ function stripImportSearchAndHash(specifier) {
61
+ return String(specifier).split("?")[0].split("#")[0];
62
+ }
63
+
64
+ function resolveRelativeClientImportPath(fromClientModule, specifier) {
65
+ const normalizedSpecifier = stripImportSearchAndHash(specifier);
66
+ return path
67
+ .normalize(path.join(path.dirname(fromClientModule), normalizedSpecifier))
68
+ .split(path.sep)
69
+ .join("/");
70
+ }
71
+
60
72
  function parsePackageSpecifier(specifier) {
61
73
  if (!isBareSpecifier(specifier)) {
62
74
  return null;
@@ -561,7 +573,10 @@ async function resolveRelativeImportFilePath(fromFilePath, specifier) {
561
573
  return null;
562
574
  }
563
575
 
564
- const candidatePath = path.resolve(path.dirname(fromFilePath), specifier);
576
+ const candidatePath = path.resolve(
577
+ path.dirname(stripImportSearchAndHash(fromFilePath)),
578
+ stripImportSearchAndHash(specifier),
579
+ );
565
580
  const candidatePaths = [
566
581
  candidatePath,
567
582
  `${candidatePath}.js`,
@@ -1191,9 +1206,7 @@ function collectRelativeClientImportPaths(source, fileRelativePath, publicPathBy
1191
1206
  continue;
1192
1207
  }
1193
1208
 
1194
- const resolvedRelativePath = path.normalize(
1195
- path.join(path.dirname(fileRelativePath), specifier),
1196
- );
1209
+ const resolvedRelativePath = resolveRelativeClientImportPath(fileRelativePath, specifier);
1197
1210
  if (!publicPathByRelativePath.has(resolvedRelativePath)) {
1198
1211
  continue;
1199
1212
  }
@@ -1217,9 +1230,7 @@ function rewriteRelativeClientImports(source, fileRelativePath, publicPathByRela
1217
1230
  continue;
1218
1231
  }
1219
1232
 
1220
- const resolvedRelativePath = path.normalize(
1221
- path.join(path.dirname(fileRelativePath), specifier),
1222
- );
1233
+ const resolvedRelativePath = resolveRelativeClientImportPath(fileRelativePath, specifier);
1223
1234
  const rewrittenTarget = publicPathByRelativePath.get(resolvedRelativePath);
1224
1235
  if (!rewrittenTarget) {
1225
1236
  continue;
@@ -1528,17 +1539,36 @@ async function bundleClientAssets(projectRoot, options = {}) {
1528
1539
  return isBareSpecifier(id);
1529
1540
  },
1530
1541
  plugins: [
1542
+ {
1543
+ name: "evolit-client-relative-imports",
1544
+ resolveId(source, importer) {
1545
+ if (!importer || !isRelativeSpecifier(source)) {
1546
+ return null;
1547
+ }
1548
+
1549
+ const cleanSource = stripImportSearchAndHash(source);
1550
+ if (cleanSource === source) {
1551
+ return null;
1552
+ }
1553
+
1554
+ return path.resolve(
1555
+ path.dirname(stripImportSearchAndHash(importer)),
1556
+ cleanSource,
1557
+ );
1558
+ },
1559
+ },
1531
1560
  {
1532
1561
  name: "evolit-client-input-sourcemaps",
1533
1562
  async load(id) {
1534
- if (!id.startsWith(clientRoot) || !id.endsWith(".mjs")) {
1563
+ const filePath = stripImportSearchAndHash(id);
1564
+ if (!filePath.startsWith(clientRoot) || !filePath.endsWith(".mjs")) {
1535
1565
  return null;
1536
1566
  }
1537
1567
 
1538
1568
  try {
1539
1569
  const [code, map] = await Promise.all([
1540
- fs.readFile(id, "utf8"),
1541
- fs.readFile(`${id}.map`, "utf8"),
1570
+ fs.readFile(filePath, "utf8"),
1571
+ fs.readFile(`${filePath}.map`, "utf8"),
1542
1572
  ]);
1543
1573
  return { code, map: JSON.parse(map) };
1544
1574
  } catch {