unframer 2.25.5 → 2.26.0

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 (117) hide show
  1. package/dist/babel-jsx.d.ts +15 -0
  2. package/dist/babel-jsx.d.ts.map +1 -0
  3. package/dist/babel-jsx.js +223 -0
  4. package/dist/babel-jsx.js.map +1 -0
  5. package/dist/babel-plugin-imports.d.ts +0 -6
  6. package/dist/babel-plugin-imports.d.ts.map +1 -1
  7. package/dist/babel-plugin-imports.js +2 -135
  8. package/dist/babel-plugin-imports.js.map +1 -1
  9. package/dist/cli.d.ts +1 -0
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +31 -6
  12. package/dist/cli.js.map +1 -1
  13. package/dist/css.js +13 -13
  14. package/dist/esbuild.d.ts.map +1 -1
  15. package/dist/esbuild.js +5 -5
  16. package/dist/esbuild.js.map +1 -1
  17. package/dist/example-code.test.js +39 -39
  18. package/dist/example-code.test.js.map +1 -1
  19. package/dist/exporter.d.ts.map +1 -1
  20. package/dist/exporter.js +137 -87
  21. package/dist/exporter.js.map +1 -1
  22. package/dist/flat-cache-interceptor.d.ts +27 -0
  23. package/dist/flat-cache-interceptor.d.ts.map +1 -0
  24. package/dist/flat-cache-interceptor.js +99 -0
  25. package/dist/flat-cache-interceptor.js.map +1 -0
  26. package/dist/framer.d.ts.map +1 -1
  27. package/dist/framer.js +837 -684
  28. package/dist/framer.js.map +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/react.d.ts.map +1 -1
  32. package/dist/react.js +15 -3
  33. package/dist/react.js.map +1 -1
  34. package/dist/sentry.d.ts.map +1 -1
  35. package/dist/sentry.js +1 -16
  36. package/dist/sentry.js.map +1 -1
  37. package/dist/undici-dispatcher.d.ts +2 -0
  38. package/dist/undici-dispatcher.d.ts.map +1 -0
  39. package/dist/undici-dispatcher.js +13 -0
  40. package/dist/undici-dispatcher.js.map +1 -0
  41. package/dist/utils.d.ts +3 -3
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +4 -10
  44. package/dist/utils.js.map +1 -1
  45. package/dist/utils.test.d.ts +2 -0
  46. package/dist/utils.test.d.ts.map +1 -0
  47. package/dist/utils.test.js +143 -0
  48. package/dist/utils.test.js.map +1 -0
  49. package/dist/version.d.ts +1 -1
  50. package/dist/version.js +1 -1
  51. package/esm/babel-jsx.d.ts +15 -0
  52. package/esm/babel-jsx.d.ts.map +1 -0
  53. package/esm/babel-jsx.js +219 -0
  54. package/esm/babel-jsx.js.map +1 -0
  55. package/esm/babel-plugin-imports.d.ts +0 -6
  56. package/esm/babel-plugin-imports.d.ts.map +1 -1
  57. package/esm/babel-plugin-imports.js +2 -134
  58. package/esm/babel-plugin-imports.js.map +1 -1
  59. package/esm/cli.d.ts +1 -0
  60. package/esm/cli.d.ts.map +1 -1
  61. package/esm/cli.js +31 -6
  62. package/esm/cli.js.map +1 -1
  63. package/esm/css.js +13 -13
  64. package/esm/esbuild.d.ts.map +1 -1
  65. package/esm/esbuild.js +4 -4
  66. package/esm/esbuild.js.map +1 -1
  67. package/esm/example-code.test.js +40 -40
  68. package/esm/example-code.test.js.map +1 -1
  69. package/esm/exporter.d.ts.map +1 -1
  70. package/esm/exporter.js +100 -50
  71. package/esm/exporter.js.map +1 -1
  72. package/esm/flat-cache-interceptor.d.ts +27 -0
  73. package/esm/flat-cache-interceptor.d.ts.map +1 -0
  74. package/esm/flat-cache-interceptor.js +95 -0
  75. package/esm/flat-cache-interceptor.js.map +1 -0
  76. package/esm/framer.d.ts.map +1 -1
  77. package/esm/framer.js +813 -672
  78. package/esm/framer.js.map +1 -1
  79. package/esm/index.d.ts +1 -1
  80. package/esm/index.d.ts.map +1 -1
  81. package/esm/react.d.ts.map +1 -1
  82. package/esm/react.js +15 -3
  83. package/esm/react.js.map +1 -1
  84. package/esm/sentry.d.ts.map +1 -1
  85. package/esm/sentry.js +1 -16
  86. package/esm/sentry.js.map +1 -1
  87. package/esm/undici-dispatcher.d.ts +2 -0
  88. package/esm/undici-dispatcher.d.ts.map +1 -0
  89. package/esm/undici-dispatcher.js +10 -0
  90. package/esm/undici-dispatcher.js.map +1 -0
  91. package/esm/utils.d.ts +3 -3
  92. package/esm/utils.d.ts.map +1 -1
  93. package/esm/utils.js +3 -9
  94. package/esm/utils.js.map +1 -1
  95. package/esm/utils.test.d.ts +2 -0
  96. package/esm/utils.test.d.ts.map +1 -0
  97. package/esm/utils.test.js +141 -0
  98. package/esm/utils.test.js.map +1 -0
  99. package/esm/version.d.ts +1 -1
  100. package/esm/version.js +1 -1
  101. package/package.json +8 -10
  102. package/src/babel-jsx.ts +277 -0
  103. package/src/babel-plugin-imports.ts +6 -169
  104. package/src/cli.ts +45 -6
  105. package/src/css.ts +13 -13
  106. package/src/esbuild.ts +5 -4
  107. package/src/example-code.test.ts +40 -41
  108. package/src/exporter.ts +124 -54
  109. package/src/flat-cache-interceptor.ts +114 -0
  110. package/src/framer.js +902 -739
  111. package/src/index.ts +1 -1
  112. package/src/react.tsx +15 -1
  113. package/src/sentry.ts +1 -20
  114. package/src/undici-dispatcher.ts +13 -0
  115. package/src/utils.test.ts +148 -0
  116. package/src/utils.ts +4 -17
  117. package/src/version.ts +1 -1
@@ -0,0 +1,114 @@
1
+ // FlatCacheStore.ts
2
+ import { Writable } from 'node:stream'
3
+ import { promises as fs } from 'node:fs'
4
+ import { join } from 'node:path'
5
+ import { tmpdir } from 'node:os'
6
+ import { createHash } from 'node:crypto'
7
+
8
+ import type CacheHandler from 'undici/types/cache-interceptor.js'
9
+ import { logger } from './utils'
10
+
11
+ /* Narrow the names we need from the .d.ts so we stay 1-to-1 with the built-ins */
12
+ type CacheKey = CacheHandler.CacheKey
13
+ type CacheValue = CacheHandler.CacheValue
14
+ type GetResult = CacheHandler.GetResult
15
+ type CacheStore = CacheHandler.CacheStore
16
+
17
+ /**
18
+ * A CacheStore that persists each entry as separate files in os.tmpdir()/.unframer.
19
+ * Each cache entry creates a .json file for metadata and a .bin file for the body.
20
+ * It satisfies the exact same interface that `MemoryCacheStore` and
21
+ * `SqliteCacheStore` implement inside Undici (see cache-interceptor.d.ts).
22
+ */
23
+ export class FlatCacheStore implements CacheStore {
24
+ private readonly cacheDir: string
25
+
26
+ constructor() {
27
+ this.cacheDir = join(tmpdir(), '.unframer')
28
+ logger.log(`using cache dir`, this.cacheDir)
29
+ this.ensureCacheDir()
30
+ }
31
+
32
+ private async ensureCacheDir(): Promise<void> {
33
+ try {
34
+ await fs.mkdir(this.cacheDir, { recursive: true })
35
+ } catch (error) {
36
+ // Directory might already exist, ignore error
37
+ }
38
+ }
39
+
40
+ private getFileHash(key: CacheKey): string {
41
+ return createHash('sha256').update(JSON.stringify(key)).digest('hex')
42
+ }
43
+
44
+ private getFilePaths(key: CacheKey): {
45
+ metaPath: string
46
+ bodyPath: string
47
+ } {
48
+ const hash = this.getFileHash(key)
49
+ return {
50
+ metaPath: join(this.cacheDir, `${hash}.json`),
51
+ bodyPath: join(this.cacheDir, `${hash}.bin`),
52
+ }
53
+ }
54
+
55
+ /** Read a cached response (metadata + body) */
56
+ async get(key: CacheKey): Promise<GetResult | undefined> {
57
+ try {
58
+ const { metaPath, bodyPath } = this.getFilePaths(key)
59
+
60
+ const [metaData, bodyData] = await Promise.all([
61
+ fs.readFile(metaPath, 'utf-8'),
62
+ fs.readFile(bodyPath),
63
+ ])
64
+
65
+ const meta = JSON.parse(metaData)
66
+ return {
67
+ ...meta,
68
+ body: bodyData,
69
+ }
70
+ } catch (error) {
71
+ return undefined
72
+ }
73
+ }
74
+
75
+ /** Return a writable stream so the interceptor can pipe the body into us */
76
+ createWriteStream(key: CacheKey, meta: CacheValue): Writable {
77
+ const chunks: Buffer[] = []
78
+
79
+ return new Writable({
80
+ write(chunk, _enc, cb) {
81
+ chunks.push(chunk as Buffer)
82
+ cb()
83
+ },
84
+ final: async (cb) => {
85
+ try {
86
+ await this.ensureCacheDir()
87
+ const { metaPath, bodyPath } = this.getFilePaths(key)
88
+
89
+ await Promise.all([
90
+ fs.writeFile(metaPath, JSON.stringify(meta, null, 2)),
91
+ fs.writeFile(bodyPath, Buffer.concat(chunks)),
92
+ ])
93
+
94
+ cb()
95
+ } catch (error) {
96
+ cb(error as Error)
97
+ }
98
+ },
99
+ })
100
+ }
101
+
102
+ /** Delete one entry */
103
+ async delete(key: CacheKey): Promise<void> {
104
+ try {
105
+ const { metaPath, bodyPath } = this.getFilePaths(key)
106
+ await Promise.all([
107
+ fs.unlink(metaPath).catch(() => {}),
108
+ fs.unlink(bodyPath).catch(() => {}),
109
+ ])
110
+ } catch (error) {
111
+ // Ignore errors when deleting non-existent files
112
+ }
113
+ }
114
+ }