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
@@ -37,9 +37,9 @@ __export(nextjs_loader_exports, {
37
37
  nextjsLoader: () => nextjsLoader
38
38
  });
39
39
  module.exports = __toCommonJS(nextjs_loader_exports);
40
- var import_node_fs3 = require("fs");
40
+ var import_node_fs4 = require("fs");
41
41
  var import_node_module = require("module");
42
- var import_node_path3 = require("path");
42
+ var import_node_path4 = require("path");
43
43
 
44
44
  // ../../modules/annotation/annotate-file.ts
45
45
  var import_oxc_parser2 = require("oxc-parser");
@@ -116,6 +116,19 @@ function formatProps(props) {
116
116
  return ` ${key}={${formatted}}`;
117
117
  }).filter((s) => s !== null).join("");
118
118
  }
119
+ function getExistingAttributeNames(element) {
120
+ const names = /* @__PURE__ */ new Set();
121
+ for (const attr of element.openingElement.attributes ?? []) {
122
+ if (attr.type !== "JSXAttribute") continue;
123
+ names.add(getTagName(attr.name));
124
+ }
125
+ return names;
126
+ }
127
+ function removeExistingProps(props, existingNames) {
128
+ return Object.fromEntries(
129
+ Object.entries(props).filter(([key]) => !existingNames.has(key))
130
+ );
131
+ }
119
132
  var FRAGMENT_TAG_NAMES = /* @__PURE__ */ new Set(["Fragment", "React.Fragment"]);
120
133
  function annotateFile(source, filename, computeAnnotatedProps) {
121
134
  const parseResult = (0, import_oxc_parser2.parseSync)(filename, source);
@@ -125,7 +138,10 @@ function annotateFile(source, filename, computeAnnotatedProps) {
125
138
  const element = node;
126
139
  const tagName = getTagName(element.openingElement.name);
127
140
  if (FRAGMENT_TAG_NAMES.has(tagName)) return;
128
- const props = computeAnnotatedProps({ element, tagName });
141
+ const props = removeExistingProps(
142
+ computeAnnotatedProps({ element, tagName }),
143
+ getExistingAttributeNames(element)
144
+ );
129
145
  if (Object.keys(props).length === 0) return;
130
146
  const openingElement = element.openingElement;
131
147
  let insertPos = openingElement.end - 1;
@@ -153,19 +169,98 @@ function annotateFile(source, filename, computeAnnotatedProps) {
153
169
  // nextjs-loader.ts
154
170
  var import_oxc_parser3 = require("oxc-parser");
155
171
 
172
+ // annotation-strategy.ts
173
+ var import_node_fs = require("fs");
174
+ var import_node_path = require("path");
175
+ var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
176
+ "area",
177
+ "base",
178
+ "br",
179
+ "col",
180
+ "embed",
181
+ "hr",
182
+ "img",
183
+ "input",
184
+ "link",
185
+ "meta",
186
+ "param",
187
+ "source",
188
+ "track",
189
+ "wbr"
190
+ ]);
191
+ function isIntrinsicElement(tagName) {
192
+ return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
193
+ }
194
+ function hasJsxAttribute(info, attrName) {
195
+ for (const attr of info.element.openingElement.attributes) {
196
+ const name = attr.name;
197
+ if (name?.name === attrName) return true;
198
+ }
199
+ return false;
200
+ }
201
+ function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs) {
202
+ return {
203
+ "data-tempo-filepath": filepath,
204
+ "data-tempo-position": info.element.openingElement.start,
205
+ "data-tempo-modifiedts": modifiedtsMs
206
+ };
207
+ }
208
+ function computeTempoAnnotatedProps(params) {
209
+ const {
210
+ info,
211
+ filepath,
212
+ modifiedtsMs,
213
+ computeAnnotatedProps,
214
+ typeInfo,
215
+ elementSupportOverrides
216
+ } = params;
217
+ const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs);
218
+ if (isIntrinsicElement(info.tagName)) {
219
+ return {
220
+ ...userProps,
221
+ "data-tempo-supports-children": hasJsxAttribute(
222
+ info,
223
+ "data-tempo-supports-children"
224
+ ) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
225
+ };
226
+ }
227
+ const override = elementSupportOverrides?.get(info.tagName);
228
+ if (override) {
229
+ return {
230
+ ...userProps,
231
+ "data-tempo-supports-style": override.supportsStyle,
232
+ "data-tempo-supports-classname": override.supportsClassName,
233
+ "data-tempo-supports-children": hasJsxAttribute(
234
+ info,
235
+ "data-tempo-supports-children"
236
+ ) ? void 0 : override.supportsChildren
237
+ };
238
+ }
239
+ const support = typeInfo?.get(info.element.openingElement.start);
240
+ return {
241
+ ...userProps,
242
+ "data-tempo-supports-style": support?.supportsStyle ?? false,
243
+ "data-tempo-supports-classname": support?.supportsClassName ?? false,
244
+ "data-tempo-supports-children": hasJsxAttribute(
245
+ info,
246
+ "data-tempo-supports-children"
247
+ ) ? void 0 : support?.supportsChildren ?? false
248
+ };
249
+ }
250
+
156
251
  // type-analyzer.ts
157
252
  var import_typescript2 = __toESM(require("typescript"), 1);
158
- var import_node_path2 = __toESM(require("path"), 1);
159
- var import_node_fs2 = require("fs");
253
+ var import_node_path3 = __toESM(require("path"), 1);
254
+ var import_node_fs3 = require("fs");
160
255
 
161
256
  // ../../modules/typescript/workspace-service.ts
162
- var import_node_fs = require("fs");
163
- var import_node_path = __toESM(require("path"), 1);
257
+ var import_node_fs2 = require("fs");
258
+ var import_node_path2 = __toESM(require("path"), 1);
164
259
  var import_typescript = __toESM(require("typescript"), 1);
165
260
  function canonicalPath(input) {
166
- const resolved = import_node_path.default.resolve(input);
261
+ const resolved = import_node_path2.default.resolve(input);
167
262
  try {
168
- return import_node_fs.realpathSync.native(resolved);
263
+ return import_node_fs2.realpathSync.native(resolved);
169
264
  } catch {
170
265
  return resolved;
171
266
  }
@@ -182,7 +277,7 @@ function compareProjectPriority(left, right) {
182
277
  return left.id.localeCompare(right.id);
183
278
  }
184
279
  function isWithinRoot(filePath, rootDir) {
185
- return filePath === rootDir || filePath.startsWith(`${rootDir}${import_node_path.default.sep}`);
280
+ return filePath === rootDir || filePath.startsWith(`${rootDir}${import_node_path2.default.sep}`);
186
281
  }
187
282
  function loadProject(descriptor) {
188
283
  const id = descriptor.id.trim();
@@ -203,7 +298,7 @@ function loadProject(descriptor) {
203
298
  const parsed = import_typescript.default.parseJsonConfigFileContent(
204
299
  readResult.config,
205
300
  import_typescript.default.sys,
206
- import_node_path.default.dirname(tsconfigPath)
301
+ import_node_path2.default.dirname(tsconfigPath)
207
302
  );
208
303
  if (parsed.errors.length > 0) {
209
304
  const message = parsed.errors.map(
@@ -230,7 +325,7 @@ function loadProject(descriptor) {
230
325
  }
231
326
  function getFileMtimeVersion(filePath) {
232
327
  try {
233
- const stats = (0, import_node_fs.statSync)(filePath);
328
+ const stats = (0, import_node_fs2.statSync)(filePath);
234
329
  return String(stats.mtimeMs);
235
330
  } catch {
236
331
  return "0";
@@ -391,9 +486,9 @@ function isCustomComponent(node) {
391
486
  return text.length > 0 && text[0] !== text[0].toLowerCase();
392
487
  }
393
488
  function canonicalPath2(value) {
394
- const resolved = import_node_path2.default.resolve(value);
489
+ const resolved = import_node_path3.default.resolve(value);
395
490
  try {
396
- return import_node_fs2.realpathSync.native(resolved);
491
+ return import_node_fs3.realpathSync.native(resolved);
397
492
  } catch {
398
493
  return resolved;
399
494
  }
@@ -424,14 +519,14 @@ function parseProjectReferenceTsconfigPaths(references, configDir) {
424
519
  if (!referencePath) {
425
520
  continue;
426
521
  }
427
- const resolvedPath = import_node_path2.default.resolve(configDir, referencePath);
428
- const tsconfigPath = resolvedPath.endsWith(".json") ? resolvedPath : import_node_path2.default.join(resolvedPath, "tsconfig.json");
522
+ const resolvedPath = import_node_path3.default.resolve(configDir, referencePath);
523
+ const tsconfigPath = resolvedPath.endsWith(".json") ? resolvedPath : import_node_path3.default.join(resolvedPath, "tsconfig.json");
429
524
  entries.push(tsconfigPath);
430
525
  }
431
526
  return entries;
432
527
  }
433
528
  function buildWorkspaceProjects(root, configPath, parsedConfig, rawConfig) {
434
- const configDir = import_node_path2.default.dirname(configPath);
529
+ const configDir = import_node_path3.default.dirname(configPath);
435
530
  const projects = [
436
531
  {
437
532
  id: "root",
@@ -446,7 +541,7 @@ function buildWorkspaceProjects(root, configPath, parsedConfig, rawConfig) {
446
541
  configDir
447
542
  );
448
543
  const managedTsconfigPaths = parseManagedTsconfigPaths(rawConfig).map(
449
- (entry) => import_node_path2.default.resolve(configDir, entry)
544
+ (entry) => import_node_path3.default.resolve(configDir, entry)
450
545
  );
451
546
  const candidateTsconfigPaths = [
452
547
  ...managedTsconfigPaths,
@@ -463,7 +558,7 @@ function buildWorkspaceProjects(root, configPath, parsedConfig, rawConfig) {
463
558
  seenTsconfigPaths.add(normalizedPath);
464
559
  projects.push({
465
560
  id: `external-${projects.length}`,
466
- rootDir: import_node_path2.default.dirname(normalizedPath),
561
+ rootDir: import_node_path3.default.dirname(normalizedPath),
467
562
  tsconfigPath: normalizedPath,
468
563
  priority: 0
469
564
  });
@@ -634,7 +729,7 @@ function createTypeAnalyzer(root) {
634
729
  analyzeFileTypes(filePath, source) {
635
730
  const canonicalFilePath = canonicalPath2(filePath);
636
731
  const belongsToWorkspace = workspaceProjectRoots.some(
637
- (projectRoot) => canonicalFilePath === projectRoot || canonicalFilePath.startsWith(`${projectRoot}${import_node_path2.default.sep}`)
732
+ (projectRoot) => canonicalFilePath === projectRoot || canonicalFilePath.startsWith(`${projectRoot}${import_node_path3.default.sep}`)
638
733
  );
639
734
  if (!belongsToWorkspace) {
640
735
  return null;
@@ -702,22 +797,6 @@ function createTypeAnalyzer(root) {
702
797
 
703
798
  // nextjs-loader.ts
704
799
  var ROOT_META_NAME = "tempo-project-root";
705
- var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
706
- "area",
707
- "base",
708
- "br",
709
- "col",
710
- "embed",
711
- "hr",
712
- "img",
713
- "input",
714
- "link",
715
- "meta",
716
- "param",
717
- "source",
718
- "track",
719
- "wbr"
720
- ]);
721
800
  var cachedCanonicalRoot = null;
722
801
  var cachedTypeAnalyzer = null;
723
802
  var cachedUserComputeProps;
@@ -728,16 +807,6 @@ function _resetLoaderState() {
728
807
  cachedUserComputeProps = void 0;
729
808
  cachedComputeModulePath = null;
730
809
  }
731
- function isIntrinsicElement(tagName) {
732
- return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
733
- }
734
- function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs) {
735
- return {
736
- "data-tempo-filepath": filepath,
737
- "data-tempo-position": info.element.openingElement.start,
738
- "data-tempo-modifiedts": modifiedtsMs
739
- };
740
- }
741
810
  function stripQueryAndHash(path3) {
742
811
  const queryIdx = path3.indexOf("?");
743
812
  const hashIdx = path3.indexOf("#");
@@ -748,22 +817,21 @@ function stripQueryAndHash(path3) {
748
817
  }
749
818
  function resolveCanonicalRoot(rootContext) {
750
819
  try {
751
- return import_node_fs3.realpathSync.native(rootContext);
820
+ return import_node_fs4.realpathSync.native(rootContext);
752
821
  } catch {
753
822
  return rootContext;
754
823
  }
755
824
  }
756
825
  function isInNodeModules(path3) {
757
- return path3.includes(`${import_node_path3.sep}node_modules${import_node_path3.sep}`);
826
+ return path3.includes(`${import_node_path4.sep}node_modules${import_node_path4.sep}`);
758
827
  }
759
- function findFirstJSXHead(program) {
828
+ function findFirstJSXElement(program, tagName) {
760
829
  let result = null;
761
830
  walk(program, {
762
831
  JSXElement(node) {
763
832
  if (result) return;
764
833
  const element = node;
765
- const tagName = getTagName(element.openingElement.name);
766
- if (tagName === "head") {
834
+ if (getTagName(element.openingElement.name) === tagName) {
767
835
  result = element;
768
836
  }
769
837
  }
@@ -786,6 +854,16 @@ function hasRootMetaChild(headElement) {
786
854
  }
787
855
  return false;
788
856
  }
857
+ function injectFirstChildMarkup(source, element, childMarkup) {
858
+ const opening = element.openingElement;
859
+ if (!opening.selfClosing) {
860
+ const insertPos = opening.end;
861
+ return source.slice(0, insertPos) + childMarkup + source.slice(insertPos);
862
+ }
863
+ const tagName = getTagName(opening.name);
864
+ const reopened = source.slice(opening.start, opening.end).replace(/\s*\/>$/, ">");
865
+ return source.slice(0, opening.start) + `${reopened}${childMarkup}</${tagName}>` + source.slice(opening.end);
866
+ }
789
867
  function injectRootMetaIntoSource(source, filename, root) {
790
868
  let parseResult;
791
869
  try {
@@ -793,18 +871,27 @@ function injectRootMetaIntoSource(source, filename, root) {
793
871
  } catch {
794
872
  return source;
795
873
  }
796
- const headElement = findFirstJSXHead(parseResult.program);
797
- if (!headElement) return source;
798
- if (hasRootMetaChild(headElement)) return source;
799
- const insertPos = headElement.openingElement.end;
800
874
  const metaTag = `<meta name="${ROOT_META_NAME}" content={${JSON.stringify(root)}} />`;
801
- return source.slice(0, insertPos) + metaTag + source.slice(insertPos);
875
+ const headElement = findFirstJSXElement(parseResult.program, "head");
876
+ if (headElement) {
877
+ if (hasRootMetaChild(headElement)) return source;
878
+ return injectFirstChildMarkup(source, headElement, metaTag);
879
+ }
880
+ const htmlElement = findFirstJSXElement(parseResult.program, "html");
881
+ if (htmlElement) {
882
+ return injectFirstChildMarkup(
883
+ source,
884
+ htmlElement,
885
+ `<head>${metaTag}</head>`
886
+ );
887
+ }
888
+ return source;
802
889
  }
803
890
  function injectRootMetaIntoAnnotatedSource(annotatedSource, filename, root) {
804
891
  return injectRootMetaIntoSource(annotatedSource, filename, root);
805
892
  }
806
893
  function loadUserComputeProps(modulePath, canonicalRoot) {
807
- const resolved = (0, import_node_path3.resolve)(canonicalRoot, modulePath);
894
+ const resolved = (0, import_node_path4.resolve)(canonicalRoot, modulePath);
808
895
  const requireFromRoot = (0, import_node_module.createRequire)(`${canonicalRoot}/__tempo_loader__.js`);
809
896
  const mod = requireFromRoot(resolved);
810
897
  const fn = mod && (mod.default ?? mod);
@@ -853,29 +940,23 @@ function nextjsLoader(source) {
853
940
  cachedUserComputeProps = null;
854
941
  }
855
942
  const userComputeProps = cachedUserComputeProps;
856
- const filepath = (0, import_node_path3.relative)(canonicalRoot, cleanPath);
857
- const modifiedtsMs = Math.trunc((0, import_node_fs3.statSync)(cleanPath).mtimeMs);
943
+ const filepath = (0, import_node_path4.relative)(canonicalRoot, cleanPath);
944
+ const modifiedtsMs = Math.trunc((0, import_node_fs4.statSync)(cleanPath).mtimeMs);
858
945
  const typeInfo = cachedTypeAnalyzer?.analyzeFileTypes(
859
946
  cleanPath,
860
947
  source
861
948
  ) ?? null;
862
- const annotated = annotateFile(source, cleanPath, (info) => {
863
- const compute = userComputeProps ?? defaultComputeAnnotatedProps;
864
- const userProps = compute(info, filepath, modifiedtsMs);
865
- if (isIntrinsicElement(info.tagName)) {
866
- return {
867
- ...userProps,
868
- "data-tempo-supports-children": !HTML_VOID_ELEMENTS.has(info.tagName)
869
- };
870
- }
871
- const support = typeInfo?.get(info.element.openingElement.start);
872
- return {
873
- ...userProps,
874
- "data-tempo-supports-style": support?.supportsStyle ?? false,
875
- "data-tempo-supports-classname": support?.supportsClassName ?? false,
876
- "data-tempo-supports-children": support?.supportsChildren ?? false
877
- };
878
- });
949
+ const annotated = annotateFile(
950
+ source,
951
+ cleanPath,
952
+ (info) => computeTempoAnnotatedProps({
953
+ info,
954
+ filepath,
955
+ modifiedtsMs,
956
+ computeAnnotatedProps: userComputeProps ?? void 0,
957
+ typeInfo
958
+ })
959
+ );
879
960
  let finalSource = annotated.annotatedSource;
880
961
  if (options.autoInjectRootMeta !== false) {
881
962
  finalSource = injectRootMetaIntoAnnotatedSource(