tempo-sdk 0.0.7 → 0.0.9

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.
Files changed (39) hide show
  1. package/README.md +96 -0
  2. package/dist/annotation-strategy-DCJHc--2.d.cts +13 -0
  3. package/dist/annotation-strategy-DCJHc--2.d.ts +13 -0
  4. package/dist/chunk-2LP5G6CD.js +748 -0
  5. package/dist/chunk-2LP5G6CD.js.map +1 -0
  6. package/dist/chunk-GHPL4LGE.js +205 -0
  7. package/dist/chunk-GHPL4LGE.js.map +1 -0
  8. package/dist/chunk-IG3JZVZI.js +846 -0
  9. package/dist/chunk-IG3JZVZI.js.map +1 -0
  10. package/dist/chunk-X3K7Z2BH.js +900 -0
  11. package/dist/chunk-X3K7Z2BH.js.map +1 -0
  12. package/dist/chunk-ZHORRCQG.js +756 -0
  13. package/dist/chunk-ZHORRCQG.js.map +1 -0
  14. package/dist/expo/plugin.cjs +883 -0
  15. package/dist/expo/plugin.cjs.map +1 -0
  16. package/dist/expo/plugin.d.cts +5 -0
  17. package/dist/expo/plugin.d.ts +5 -0
  18. package/dist/expo/plugin.js +8 -0
  19. package/dist/expo/plugin.js.map +1 -0
  20. package/dist/expo-babel-plugin.cjs +881 -0
  21. package/dist/expo-babel-plugin.cjs.map +1 -0
  22. package/dist/expo-babel-plugin.d.cts +71 -0
  23. package/dist/expo-babel-plugin.d.ts +71 -0
  24. package/dist/expo-babel-plugin.js +8 -0
  25. package/dist/expo-babel-plugin.js.map +1 -0
  26. package/dist/index.cjs +1170 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/index.d.cts +99 -0
  29. package/dist/index.js +117 -54
  30. package/dist/index.js.map +1 -1
  31. package/dist/nextjs-loader.cjs +157 -76
  32. package/dist/nextjs-loader.cjs.map +1 -1
  33. package/package.json +22 -5
  34. package/dist/chunk-FIAAEHXK.js +0 -171
  35. package/dist/chunk-FIAAEHXK.js.map +0 -1
  36. package/dist/chunk-G4OYWYQA.js +0 -168
  37. package/dist/chunk-G4OYWYQA.js.map +0 -1
  38. package/dist/chunk-UWWB27SE.js +0 -170
  39. package/dist/chunk-UWWB27SE.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // index.ts
2
- import { realpathSync as realpathSync3, statSync as statSync2 } from "fs";
3
- import { relative } from "path";
2
+ import { realpathSync as realpathSync4, statSync as statSync3 } from "fs";
3
+ import { relative as relative2 } 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;
@@ -114,19 +130,98 @@ function annotateFile(source, filename, computeAnnotatedProps) {
114
130
  // index.ts
115
131
  import { createFilter } from "@rollup/pluginutils";
116
132
 
133
+ // annotation-strategy.ts
134
+ import { realpathSync, statSync } from "fs";
135
+ import { relative } from "path";
136
+ var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
137
+ "area",
138
+ "base",
139
+ "br",
140
+ "col",
141
+ "embed",
142
+ "hr",
143
+ "img",
144
+ "input",
145
+ "link",
146
+ "meta",
147
+ "param",
148
+ "source",
149
+ "track",
150
+ "wbr"
151
+ ]);
152
+ function isIntrinsicElement(tagName) {
153
+ return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
154
+ }
155
+ function hasJsxAttribute(info, attrName) {
156
+ for (const attr of info.element.openingElement.attributes) {
157
+ const name = attr.name;
158
+ if (name?.name === attrName) return true;
159
+ }
160
+ return false;
161
+ }
162
+ function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs) {
163
+ return {
164
+ "data-tempo-filepath": filepath,
165
+ "data-tempo-position": info.element.openingElement.start,
166
+ "data-tempo-modifiedts": modifiedtsMs
167
+ };
168
+ }
169
+ function computeTempoAnnotatedProps(params) {
170
+ const {
171
+ info,
172
+ filepath,
173
+ modifiedtsMs,
174
+ computeAnnotatedProps,
175
+ typeInfo,
176
+ elementSupportOverrides
177
+ } = params;
178
+ const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs);
179
+ if (isIntrinsicElement(info.tagName)) {
180
+ return {
181
+ ...userProps,
182
+ "data-tempo-supports-children": hasJsxAttribute(
183
+ info,
184
+ "data-tempo-supports-children"
185
+ ) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
186
+ };
187
+ }
188
+ const override = elementSupportOverrides?.get(info.tagName);
189
+ if (override) {
190
+ return {
191
+ ...userProps,
192
+ "data-tempo-supports-style": override.supportsStyle,
193
+ "data-tempo-supports-classname": override.supportsClassName,
194
+ "data-tempo-supports-children": hasJsxAttribute(
195
+ info,
196
+ "data-tempo-supports-children"
197
+ ) ? void 0 : override.supportsChildren
198
+ };
199
+ }
200
+ const support = typeInfo?.get(info.element.openingElement.start);
201
+ return {
202
+ ...userProps,
203
+ "data-tempo-supports-style": support?.supportsStyle ?? false,
204
+ "data-tempo-supports-classname": support?.supportsClassName ?? false,
205
+ "data-tempo-supports-children": hasJsxAttribute(
206
+ info,
207
+ "data-tempo-supports-children"
208
+ ) ? void 0 : support?.supportsChildren ?? false
209
+ };
210
+ }
211
+
117
212
  // type-analyzer.ts
118
213
  import ts2 from "typescript";
119
214
  import path2 from "path";
120
- import { realpathSync as realpathSync2 } from "fs";
215
+ import { realpathSync as realpathSync3 } from "fs";
121
216
 
122
217
  // ../../modules/typescript/workspace-service.ts
123
- import { realpathSync, statSync } from "fs";
218
+ import { realpathSync as realpathSync2, statSync as statSync2 } from "fs";
124
219
  import path from "path";
125
220
  import ts from "typescript";
126
221
  function canonicalPath(input) {
127
222
  const resolved = path.resolve(input);
128
223
  try {
129
- return realpathSync.native(resolved);
224
+ return realpathSync2.native(resolved);
130
225
  } catch {
131
226
  return resolved;
132
227
  }
@@ -191,7 +286,7 @@ function loadProject(descriptor) {
191
286
  }
192
287
  function getFileMtimeVersion(filePath) {
193
288
  try {
194
- const stats = statSync(filePath);
289
+ const stats = statSync2(filePath);
195
290
  return String(stats.mtimeMs);
196
291
  } catch {
197
292
  return "0";
@@ -354,7 +449,7 @@ function isCustomComponent(node) {
354
449
  function canonicalPath2(value) {
355
450
  const resolved = path2.resolve(value);
356
451
  try {
357
- return realpathSync2.native(resolved);
452
+ return realpathSync3.native(resolved);
358
453
  } catch {
359
454
  return resolved;
360
455
  }
@@ -670,7 +765,7 @@ function cleanModuleId(id) {
670
765
  }
671
766
  function resolveCanonicalRoot(root) {
672
767
  try {
673
- return realpathSync3.native(root);
768
+ return realpathSync4.native(root);
674
769
  } catch {
675
770
  return root;
676
771
  }
@@ -678,32 +773,6 @@ function resolveCanonicalRoot(root) {
678
773
  function hasRootMetaTag(html) {
679
774
  return /<meta[^>]+name=["']tempo-project-root["'][^>]*>/i.test(html);
680
775
  }
681
- function isIntrinsicElement(tagName) {
682
- return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
683
- }
684
- var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
685
- "area",
686
- "base",
687
- "br",
688
- "col",
689
- "embed",
690
- "hr",
691
- "img",
692
- "input",
693
- "link",
694
- "meta",
695
- "param",
696
- "source",
697
- "track",
698
- "wbr"
699
- ]);
700
- function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs) {
701
- return {
702
- "data-tempo-filepath": filepath,
703
- "data-tempo-position": info.element.openingElement.start,
704
- "data-tempo-modifiedts": modifiedtsMs
705
- };
706
- }
707
776
  function createErrorServer() {
708
777
  const errorsByFile = /* @__PURE__ */ new Map();
709
778
  function getMostRecentError() {
@@ -811,7 +880,6 @@ function tempoVitePlugin(options = {}) {
811
880
  const include = options.include === void 0 ? DEFAULT_INCLUDE : options.include;
812
881
  const exclude = options.exclude === void 0 ? DEFAULT_EXCLUDE : options.exclude;
813
882
  const filter = createFilter(include, exclude);
814
- const computeAnnotatedProps = options.computeAnnotatedProps ?? defaultComputeAnnotatedProps;
815
883
  let canonicalRoot = process.cwd();
816
884
  let command = "serve";
817
885
  let typeAnalyzer = null;
@@ -896,25 +964,20 @@ function tempoVitePlugin(options = {}) {
896
964
  return null;
897
965
  }
898
966
  try {
899
- const filepath = relative(canonicalRoot, cleanId);
900
- const modifiedtsMs = Math.trunc(statSync2(cleanId).mtimeMs);
967
+ const filepath = relative2(canonicalRoot, cleanId);
968
+ const modifiedtsMs = Math.trunc(statSync3(cleanId).mtimeMs);
901
969
  const typeInfo = typeAnalyzer?.analyzeFileTypes(cleanId, source);
902
- const result = annotateFile(source, cleanId, (info) => {
903
- const userProps = computeAnnotatedProps(info, filepath, modifiedtsMs);
904
- if (isIntrinsicElement(info.tagName)) {
905
- return {
906
- ...userProps,
907
- "data-tempo-supports-children": !HTML_VOID_ELEMENTS.has(info.tagName)
908
- };
909
- }
910
- const support = typeInfo?.get(info.element.openingElement.start);
911
- return {
912
- ...userProps,
913
- "data-tempo-supports-style": support?.supportsStyle ?? false,
914
- "data-tempo-supports-classname": support?.supportsClassName ?? false,
915
- "data-tempo-supports-children": support?.supportsChildren ?? false
916
- };
917
- });
970
+ const result = annotateFile(
971
+ source,
972
+ cleanId,
973
+ (info) => computeTempoAnnotatedProps({
974
+ info,
975
+ filepath,
976
+ modifiedtsMs,
977
+ computeAnnotatedProps: options.computeAnnotatedProps,
978
+ typeInfo
979
+ })
980
+ );
918
981
  if (result.elementsAnnotated === 0) {
919
982
  return null;
920
983
  }