tempo-sdk 0.0.8 → 0.0.10

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 { 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";
@@ -130,19 +130,98 @@ function annotateFile(source, filename, computeAnnotatedProps) {
130
130
  // index.ts
131
131
  import { createFilter } from "@rollup/pluginutils";
132
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
+
133
212
  // type-analyzer.ts
134
213
  import ts2 from "typescript";
135
214
  import path2 from "path";
136
- import { realpathSync as realpathSync2 } from "fs";
215
+ import { realpathSync as realpathSync3 } from "fs";
137
216
 
138
217
  // ../../modules/typescript/workspace-service.ts
139
- import { realpathSync, statSync } from "fs";
218
+ import { realpathSync as realpathSync2, statSync as statSync2 } from "fs";
140
219
  import path from "path";
141
220
  import ts from "typescript";
142
221
  function canonicalPath(input) {
143
222
  const resolved = path.resolve(input);
144
223
  try {
145
- return realpathSync.native(resolved);
224
+ return realpathSync2.native(resolved);
146
225
  } catch {
147
226
  return resolved;
148
227
  }
@@ -207,7 +286,7 @@ function loadProject(descriptor) {
207
286
  }
208
287
  function getFileMtimeVersion(filePath) {
209
288
  try {
210
- const stats = statSync(filePath);
289
+ const stats = statSync2(filePath);
211
290
  return String(stats.mtimeMs);
212
291
  } catch {
213
292
  return "0";
@@ -370,7 +449,7 @@ function isCustomComponent(node) {
370
449
  function canonicalPath2(value) {
371
450
  const resolved = path2.resolve(value);
372
451
  try {
373
- return realpathSync2.native(resolved);
452
+ return realpathSync3.native(resolved);
374
453
  } catch {
375
454
  return resolved;
376
455
  }
@@ -686,7 +765,7 @@ function cleanModuleId(id) {
686
765
  }
687
766
  function resolveCanonicalRoot(root) {
688
767
  try {
689
- return realpathSync3.native(root);
768
+ return realpathSync4.native(root);
690
769
  } catch {
691
770
  return root;
692
771
  }
@@ -694,32 +773,6 @@ function resolveCanonicalRoot(root) {
694
773
  function hasRootMetaTag(html) {
695
774
  return /<meta[^>]+name=["']tempo-project-root["'][^>]*>/i.test(html);
696
775
  }
697
- function isIntrinsicElement(tagName) {
698
- return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
699
- }
700
- var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
701
- "area",
702
- "base",
703
- "br",
704
- "col",
705
- "embed",
706
- "hr",
707
- "img",
708
- "input",
709
- "link",
710
- "meta",
711
- "param",
712
- "source",
713
- "track",
714
- "wbr"
715
- ]);
716
- function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs) {
717
- return {
718
- "data-tempo-filepath": filepath,
719
- "data-tempo-position": info.element.openingElement.start,
720
- "data-tempo-modifiedts": modifiedtsMs
721
- };
722
- }
723
776
  function createErrorServer() {
724
777
  const errorsByFile = /* @__PURE__ */ new Map();
725
778
  function getMostRecentError() {
@@ -827,7 +880,6 @@ function tempoVitePlugin(options = {}) {
827
880
  const include = options.include === void 0 ? DEFAULT_INCLUDE : options.include;
828
881
  const exclude = options.exclude === void 0 ? DEFAULT_EXCLUDE : options.exclude;
829
882
  const filter = createFilter(include, exclude);
830
- const computeAnnotatedProps = options.computeAnnotatedProps ?? defaultComputeAnnotatedProps;
831
883
  let canonicalRoot = process.cwd();
832
884
  let command = "serve";
833
885
  let typeAnalyzer = null;
@@ -912,25 +964,20 @@ function tempoVitePlugin(options = {}) {
912
964
  return null;
913
965
  }
914
966
  try {
915
- const filepath = relative(canonicalRoot, cleanId);
916
- const modifiedtsMs = Math.trunc(statSync2(cleanId).mtimeMs);
967
+ const filepath = relative2(canonicalRoot, cleanId);
968
+ const modifiedtsMs = Math.trunc(statSync3(cleanId).mtimeMs);
917
969
  const typeInfo = typeAnalyzer?.analyzeFileTypes(cleanId, source);
918
- const result = annotateFile(source, cleanId, (info) => {
919
- const userProps = computeAnnotatedProps(info, filepath, modifiedtsMs);
920
- if (isIntrinsicElement(info.tagName)) {
921
- return {
922
- ...userProps,
923
- "data-tempo-supports-children": !HTML_VOID_ELEMENTS.has(info.tagName)
924
- };
925
- }
926
- const support = typeInfo?.get(info.element.openingElement.start);
927
- return {
928
- ...userProps,
929
- "data-tempo-supports-style": support?.supportsStyle ?? false,
930
- "data-tempo-supports-classname": support?.supportsClassName ?? false,
931
- "data-tempo-supports-children": support?.supportsChildren ?? false
932
- };
933
- });
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
+ );
934
981
  if (result.elementsAnnotated === 0) {
935
982
  return null;
936
983
  }