tempo-sdk 0.0.6 → 0.0.8

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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // index.ts
2
- import { existsSync, realpathSync as realpathSync3, statSync as statSync2 } from "fs";
3
- import { dirname, relative, resolve } from "path";
2
+ import { realpathSync as realpathSync3, statSync as statSync2 } from "fs";
3
+ import { relative } from "path";
4
4
 
5
5
  // ../../modules/annotation/annotate-file.ts
6
6
  import { parseSync as parseSync2 } from "oxc-parser";
@@ -77,6 +77,19 @@ function formatProps(props) {
77
77
  return ` ${key}={${formatted}}`;
78
78
  }).filter((s) => s !== null).join("");
79
79
  }
80
+ function getExistingAttributeNames(element) {
81
+ const names = /* @__PURE__ */ new Set();
82
+ for (const attr of element.openingElement.attributes ?? []) {
83
+ if (attr.type !== "JSXAttribute") continue;
84
+ names.add(getTagName(attr.name));
85
+ }
86
+ return names;
87
+ }
88
+ function removeExistingProps(props, existingNames) {
89
+ return Object.fromEntries(
90
+ Object.entries(props).filter(([key]) => !existingNames.has(key))
91
+ );
92
+ }
80
93
  var FRAGMENT_TAG_NAMES = /* @__PURE__ */ new Set(["Fragment", "React.Fragment"]);
81
94
  function annotateFile(source, filename, computeAnnotatedProps) {
82
95
  const parseResult = parseSync2(filename, source);
@@ -86,7 +99,10 @@ function annotateFile(source, filename, computeAnnotatedProps) {
86
99
  const element = node;
87
100
  const tagName = getTagName(element.openingElement.name);
88
101
  if (FRAGMENT_TAG_NAMES.has(tagName)) return;
89
- const props = computeAnnotatedProps({ element, tagName });
102
+ const props = removeExistingProps(
103
+ computeAnnotatedProps({ element, tagName }),
104
+ getExistingAttributeNames(element)
105
+ );
90
106
  if (Object.keys(props).length === 0) return;
91
107
  const openingElement = element.openingElement;
92
108
  let insertPos = openingElement.end - 1;
@@ -111,17 +127,6 @@ function annotateFile(source, filename, computeAnnotatedProps) {
111
127
  return { annotatedSource: chunks.join(""), elementsAnnotated: insertions.length, parseResult };
112
128
  }
113
129
 
114
- // ../../modules/annotation/has-expression-children.ts
115
- function hasJsxExpressionChild(element) {
116
- for (const child of element.children) {
117
- if (child.type !== "JSXExpressionContainer") continue;
118
- const expression = child.expression;
119
- if (!expression || expression.type === "JSXEmptyExpression") continue;
120
- return true;
121
- }
122
- return false;
123
- }
124
-
125
130
  // index.ts
126
131
  import { createFilter } from "@rollup/pluginutils";
127
132
 
@@ -692,47 +697,6 @@ function hasRootMetaTag(html) {
692
697
  function isIntrinsicElement(tagName) {
693
698
  return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
694
699
  }
695
- var IMPORT_RESOLUTION_EXTENSIONS = [
696
- "",
697
- ".tsx",
698
- ".ts",
699
- ".jsx",
700
- ".js",
701
- ".mjs",
702
- ".cjs",
703
- ".json"
704
- ];
705
- function hasJsxAttribute(info, attrName) {
706
- for (const attr of info.element.openingElement.attributes) {
707
- const name = attr.name;
708
- if (name?.name === attrName) return true;
709
- }
710
- return false;
711
- }
712
- function pathExistsWithCommonExtensions(basePath) {
713
- for (const ext of IMPORT_RESOLUTION_EXTENSIONS) {
714
- const candidate = `${basePath}${ext}`;
715
- if (existsSync(candidate)) return true;
716
- }
717
- for (const ext of IMPORT_RESOLUTION_EXTENSIONS) {
718
- const candidate = resolve(basePath, `index${ext}`);
719
- if (existsSync(candidate)) return true;
720
- }
721
- return false;
722
- }
723
- function findMissingRelativeImport(source, importerPath) {
724
- const importPattern = /(?:import|export)\s+(?:[\s\S]*?\s+from\s+)?["'](\.{1,2}\/[^"']+)["']/g;
725
- let match;
726
- while (match = importPattern.exec(source)) {
727
- const specifier = match[1];
728
- if (!specifier) continue;
729
- const resolved = resolve(dirname(importerPath), specifier);
730
- if (!pathExistsWithCommonExtensions(resolved)) {
731
- return specifier;
732
- }
733
- }
734
- return null;
735
- }
736
700
  var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
737
701
  "area",
738
702
  "base",
@@ -804,10 +768,10 @@ function createErrorServer() {
804
768
  return server;
805
769
  }
806
770
  function readBody(req) {
807
- return new Promise((resolve2, reject) => {
771
+ return new Promise((resolve, reject) => {
808
772
  const chunks = [];
809
773
  req.on("data", (chunk) => chunks.push(chunk));
810
- req.on("end", () => resolve2(Buffer.concat(chunks).toString()));
774
+ req.on("end", () => resolve(Buffer.concat(chunks).toString()));
811
775
  req.on("error", reject);
812
776
  });
813
777
  }
@@ -858,29 +822,6 @@ function handleErrorMiddleware(errorServer, req, res, next) {
858
822
  }
859
823
  next();
860
824
  }
861
- function parseViteInternalServerError(message) {
862
- if (!message.includes("Internal server error:")) return null;
863
- const lines = message.split(/\r?\n/);
864
- const firstLine = lines.find(
865
- (line) => line.includes("Internal server error:")
866
- );
867
- if (!firstLine) return null;
868
- const fileLine = lines.find((line) => line.trim().startsWith("File:"));
869
- const pluginLine = lines.find((line) => line.trim().startsWith("Plugin:"));
870
- const locMatch = fileLine?.match(/File:\s*(.+?)(?::(\d+):(\d+))?\s*$/);
871
- return {
872
- type: "compile",
873
- message: firstLine.replace(/^.*Internal server error:\s*/, "").trim(),
874
- stack: message,
875
- file: locMatch?.[1]?.trim(),
876
- plugin: pluginLine?.replace(/^.*Plugin:\s*/, "").trim(),
877
- loc: locMatch?.[2] && locMatch?.[3] ? {
878
- file: locMatch[1]?.trim(),
879
- line: Number(locMatch[2]),
880
- column: Number(locMatch[3])
881
- } : void 0
882
- };
883
- }
884
825
  function tempoVitePlugin(options = {}) {
885
826
  const enabled = !!process.env.TEMPO;
886
827
  const include = options.include === void 0 ? DEFAULT_INCLUDE : options.include;
@@ -940,18 +881,6 @@ function tempoVitePlugin(options = {}) {
940
881
  if (clientHot && clientHot !== server.ws) {
941
882
  interceptHmrSend(clientHot);
942
883
  }
943
- if (server.config?.logger?.error) {
944
- const originalLoggerError = server.config.logger.error.bind(
945
- server.config.logger
946
- );
947
- server.config.logger.error = ((message, options2) => {
948
- const error = parseViteInternalServerError(String(message));
949
- if (error) {
950
- errorServer.setError(error);
951
- }
952
- return originalLoggerError(message, options2);
953
- });
954
- }
955
884
  },
956
885
  transformIndexHtml(html) {
957
886
  if (!enabled || command !== "serve") {
@@ -984,43 +913,22 @@ function tempoVitePlugin(options = {}) {
984
913
  }
985
914
  try {
986
915
  const filepath = relative(canonicalRoot, cleanId);
987
- const missingImport = findMissingRelativeImport(source, cleanId);
988
- if (missingImport) {
989
- const message = `Failed to resolve import "${missingImport}" from "${filepath}". Does the file exist?`;
990
- errorServer.setError({
991
- type: "compile",
992
- message,
993
- file: cleanId,
994
- plugin: "vite:import-analysis"
995
- });
996
- } else {
997
- errorServer.clearErrorForModules([cleanId, filepath]);
998
- }
999
916
  const modifiedtsMs = Math.trunc(statSync2(cleanId).mtimeMs);
1000
917
  const typeInfo = typeAnalyzer?.analyzeFileTypes(cleanId, source);
1001
918
  const result = annotateFile(source, cleanId, (info) => {
1002
919
  const userProps = computeAnnotatedProps(info, filepath, modifiedtsMs);
1003
- const dynamicChildrenProp = hasJsxExpressionChild(info.element) ? { "data-tempo-dynamic-children": true } : {};
1004
920
  if (isIntrinsicElement(info.tagName)) {
1005
921
  return {
1006
922
  ...userProps,
1007
- ...dynamicChildrenProp,
1008
- "data-tempo-supports-children": hasJsxAttribute(
1009
- info,
1010
- "data-tempo-supports-children"
1011
- ) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
923
+ "data-tempo-supports-children": !HTML_VOID_ELEMENTS.has(info.tagName)
1012
924
  };
1013
925
  }
1014
926
  const support = typeInfo?.get(info.element.openingElement.start);
1015
927
  return {
1016
928
  ...userProps,
1017
- ...dynamicChildrenProp,
1018
929
  "data-tempo-supports-style": support?.supportsStyle ?? false,
1019
930
  "data-tempo-supports-classname": support?.supportsClassName ?? false,
1020
- "data-tempo-supports-children": hasJsxAttribute(
1021
- info,
1022
- "data-tempo-supports-children"
1023
- ) ? void 0 : support?.supportsChildren ?? false
931
+ "data-tempo-supports-children": support?.supportsChildren ?? false
1024
932
  };
1025
933
  });
1026
934
  if (result.elementsAnnotated === 0) {