@alloy-js/core 0.19.0-dev.12 → 0.19.0-dev.3

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 (95) hide show
  1. package/dist/src/components/index.d.ts +0 -4
  2. package/dist/src/components/index.d.ts.map +1 -1
  3. package/dist/src/components/index.js +0 -4
  4. package/dist/src/components/stc/index.d.ts +0 -4
  5. package/dist/src/components/stc/index.d.ts.map +1 -1
  6. package/dist/src/components/stc/index.js +0 -4
  7. package/dist/src/context/source-directory.d.ts +3 -3
  8. package/dist/src/context/source-directory.d.ts.map +1 -1
  9. package/dist/src/context/source-file.d.ts +0 -4
  10. package/dist/src/context/source-file.d.ts.map +1 -1
  11. package/dist/src/debug.d.ts.map +1 -1
  12. package/dist/src/debug.js +1 -4
  13. package/dist/src/index.browser.d.ts +1 -1
  14. package/dist/src/index.browser.d.ts.map +1 -1
  15. package/dist/src/index.browser.js +2 -2
  16. package/dist/src/render.d.ts +2 -10
  17. package/dist/src/render.d.ts.map +1 -1
  18. package/dist/src/render.js +1 -20
  19. package/dist/src/scheduler.d.ts +0 -6
  20. package/dist/src/scheduler.d.ts.map +1 -1
  21. package/dist/src/scheduler.js +0 -36
  22. package/dist/src/write-output.browser.d.ts +2 -0
  23. package/dist/src/write-output.browser.d.ts.map +1 -0
  24. package/dist/src/write-output.browser.js +4 -0
  25. package/dist/src/write-output.d.ts +1 -1
  26. package/dist/src/write-output.d.ts.map +1 -1
  27. package/dist/src/write-output.js +21 -40
  28. package/dist/test/components/source-file.test.d.ts.map +1 -1
  29. package/dist/test/rendering/formatting.test.d.ts.map +1 -1
  30. package/dist/testing/extend-expect.js +54 -60
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +3 -3
  33. package/src/components/index.tsx +0 -4
  34. package/src/components/stc/index.ts +0 -4
  35. package/src/context/source-directory.ts +3 -5
  36. package/src/context/source-file.ts +0 -5
  37. package/src/debug.ts +1 -4
  38. package/src/index.browser.ts +1 -1
  39. package/src/render.ts +5 -44
  40. package/src/scheduler.ts +0 -39
  41. package/src/write-output.browser.ts +4 -0
  42. package/src/write-output.ts +19 -49
  43. package/temp/api.json +423 -1886
  44. package/test/components/source-file.test.tsx +2 -5
  45. package/test/rendering/formatting.test.tsx +3 -9
  46. package/testing/extend-expect.ts +58 -74
  47. package/testing/vitest.d.ts +0 -4
  48. package/dist/src/components/AppendFile.d.ts +0 -90
  49. package/dist/src/components/AppendFile.d.ts.map +0 -1
  50. package/dist/src/components/AppendFile.js +0 -226
  51. package/dist/src/components/CopyFile.d.ts +0 -12
  52. package/dist/src/components/CopyFile.d.ts.map +0 -1
  53. package/dist/src/components/CopyFile.js +0 -15
  54. package/dist/src/components/TemplateFile.d.ts +0 -84
  55. package/dist/src/components/TemplateFile.d.ts.map +0 -1
  56. package/dist/src/components/TemplateFile.js +0 -133
  57. package/dist/src/components/UpdateFile.d.ts +0 -34
  58. package/dist/src/components/UpdateFile.d.ts.map +0 -1
  59. package/dist/src/components/UpdateFile.js +0 -66
  60. package/dist/src/host/alloy-host.browser.d.ts +0 -11
  61. package/dist/src/host/alloy-host.browser.d.ts.map +0 -1
  62. package/dist/src/host/alloy-host.browser.js +0 -31
  63. package/dist/src/host/alloy-host.d.ts +0 -11
  64. package/dist/src/host/alloy-host.d.ts.map +0 -1
  65. package/dist/src/host/alloy-host.js +0 -143
  66. package/dist/src/host/interface.d.ts +0 -144
  67. package/dist/src/host/interface.d.ts.map +0 -1
  68. package/dist/src/host/interface.js +0 -1
  69. package/dist/src/resource.d.ts +0 -80
  70. package/dist/src/resource.d.ts.map +0 -1
  71. package/dist/src/resource.js +0 -118
  72. package/dist/test/components/append-file.test.d.ts +0 -2
  73. package/dist/test/components/append-file.test.d.ts.map +0 -1
  74. package/dist/test/components/append-file.test.js +0 -281
  75. package/dist/test/components/copy-file.test.d.ts +0 -2
  76. package/dist/test/components/copy-file.test.d.ts.map +0 -1
  77. package/dist/test/components/copy-file.test.js +0 -94
  78. package/dist/test/components/template-file.test.d.ts +0 -2
  79. package/dist/test/components/template-file.test.d.ts.map +0 -1
  80. package/dist/test/components/template-file.test.js +0 -133
  81. package/dist/test/components/update-file.test.d.ts +0 -2
  82. package/dist/test/components/update-file.test.d.ts.map +0 -1
  83. package/dist/test/components/update-file.test.js +0 -169
  84. package/src/components/AppendFile.tsx +0 -294
  85. package/src/components/CopyFile.tsx +0 -29
  86. package/src/components/TemplateFile.tsx +0 -193
  87. package/src/components/UpdateFile.tsx +0 -86
  88. package/src/host/alloy-host.browser.ts +0 -56
  89. package/src/host/alloy-host.ts +0 -160
  90. package/src/host/interface.ts +0 -153
  91. package/src/resource.ts +0 -152
  92. package/test/components/append-file.test.tsx +0 -275
  93. package/test/components/copy-file.test.tsx +0 -98
  94. package/test/components/template-file.test.tsx +0 -127
  95. package/test/components/update-file.test.tsx +0 -214
@@ -1,214 +0,0 @@
1
- import { existsSync, unlinkSync, writeFileSync } from "fs";
2
- import { tmpdir } from "os";
3
- import { join } from "pathe";
4
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
- import { UpdateFile } from "../../src/components/UpdateFile.jsx";
6
- import { render } from "../../src/render.js";
7
- import "../../testing/extend-expect.js";
8
- import { d } from "../../testing/render.js";
9
-
10
- describe("UpdateFile", () => {
11
- let testFilePath: string;
12
-
13
- beforeEach(() => {
14
- testFilePath = join(tmpdir(), "test-file.txt");
15
- });
16
-
17
- afterEach(() => {
18
- if (existsSync(testFilePath)) {
19
- unlinkSync(testFilePath);
20
- }
21
- });
22
-
23
- describe("when file exists", () => {
24
- it("should read existing file and transform content", async () => {
25
- const existingContent = "Hello World";
26
- writeFileSync(testFilePath, existingContent, "utf-8");
27
-
28
- const result = (
29
- <UpdateFile path={testFilePath}>
30
- {(currentContents) => {
31
- return `${currentContents?.toUpperCase()}`;
32
- }}
33
- </UpdateFile>
34
- );
35
-
36
- await expect(result).toRenderToAsync("HELLO WORLD");
37
- });
38
-
39
- it("should handle JSON file updates", async () => {
40
- const existingConfig = { version: "1.0.0", name: "test" };
41
- writeFileSync(testFilePath, JSON.stringify(existingConfig), "utf-8");
42
-
43
- const result = (
44
- <UpdateFile path={testFilePath}>
45
- {(currentContents) => {
46
- const config = JSON.parse(currentContents!);
47
- config.version = "2.0.0";
48
- config.newProperty = "added";
49
- return JSON.stringify(config, null, 2);
50
- }}
51
- </UpdateFile>
52
- );
53
-
54
- await expect(result).toRenderToAsync(d`
55
- {
56
- "version": "2.0.0",
57
- "name": "test",
58
- "newProperty": "added"
59
- }
60
- `);
61
- });
62
-
63
- it("should handle multiline content transformation", async () => {
64
- const existingContent = d`
65
- line 1
66
- line 2
67
- line 3
68
- `;
69
- writeFileSync(testFilePath, existingContent, "utf-8");
70
-
71
- const result = (
72
- <UpdateFile path={testFilePath}>
73
- {(currentContents) => {
74
- const lines = currentContents!.split("\n");
75
- const modifiedLines = lines.map((line) => `// ${line}`);
76
- return modifiedLines.join("\n");
77
- }}
78
- </UpdateFile>
79
- );
80
-
81
- await expect(result).toRenderToAsync(d`
82
- // line 1
83
- // line 2
84
- // line 3
85
- `);
86
- });
87
-
88
- it("should handle empty existing file", async () => {
89
- writeFileSync(testFilePath, "", "utf-8");
90
-
91
- const result = (
92
- <UpdateFile path={testFilePath}>
93
- {(currentContents) => {
94
- return `Content was: "${currentContents || "empty"}"`;
95
- }}
96
- </UpdateFile>
97
- );
98
-
99
- await expect(result).toRenderToAsync('Content was: "empty"');
100
- });
101
- });
102
-
103
- describe("when file does not exist", () => {
104
- it("should use defaultContent when file does not exist", async () => {
105
- const result = (
106
- <UpdateFile path="non-existent.txt" defaultContent="default content">
107
- {(currentContents) => {
108
- if (currentContents === null) {
109
- return `File did not exist`;
110
- }
111
- return `File existed with: ${currentContents}`;
112
- }}
113
- </UpdateFile>
114
- );
115
-
116
- await expect(result).toRenderToAsync("File did not exist");
117
- });
118
-
119
- it("should use defaultContentPath when file does not exist", async () => {
120
- const defaultFilePath = join(
121
- tmpdir(),
122
- `default-content-${Date.now()}.txt`,
123
- );
124
- const defaultContent = "This is default content from file";
125
- writeFileSync(defaultFilePath, defaultContent, "utf-8");
126
-
127
- try {
128
- const result = (
129
- <UpdateFile
130
- path="non-existent.txt"
131
- defaultContentPath={defaultFilePath}
132
- >
133
- {(currentContents) => {
134
- return `Default: ${currentContents}`;
135
- }}
136
- </UpdateFile>
137
- );
138
-
139
- await expect(result).toRenderToAsync(
140
- "Default: This is default content from file",
141
- );
142
- } finally {
143
- if (existsSync(defaultFilePath)) {
144
- unlinkSync(defaultFilePath);
145
- }
146
- }
147
- });
148
-
149
- it("should pass null to children when no default content provided", async () => {
150
- const result = (
151
- <UpdateFile path="non-existent.txt">
152
- {(currentContents) => {
153
- if (currentContents === null) {
154
- return `Creating new file`;
155
- }
156
- return `Updating existing file: ${currentContents}`;
157
- }}
158
- </UpdateFile>
159
- );
160
-
161
- await expect(result).toRenderToAsync("Creating new file");
162
- });
163
-
164
- it("should create JSON file from scratch when it doesn't exist", async () => {
165
- const result = (
166
- <UpdateFile path="new-config.json">
167
- {(currentContents) => {
168
- const config = currentContents ? JSON.parse(currentContents) : {};
169
- config.name = "new-project";
170
- config.version = "1.0.0";
171
- config.dependencies = {};
172
- return JSON.stringify(config, null, 2);
173
- }}
174
- </UpdateFile>
175
- );
176
-
177
- await expect(result).toRenderToAsync(d`
178
- {
179
- "name": "new-project",
180
- "version": "1.0.0",
181
- "dependencies": {}
182
- }
183
- `);
184
- });
185
- });
186
-
187
- describe("error handling", () => {
188
- it("should throw error when defaultContentPath file does not exist", async () => {
189
- expect(() =>
190
- render(
191
- <UpdateFile
192
- path="non-existent.txt"
193
- defaultContentPath="/path/that/does/not/exist.txt"
194
- >
195
- {(currentContents) => currentContents}
196
- </UpdateFile>,
197
- ),
198
- ).toThrow();
199
- });
200
-
201
- it("should handle file system errors gracefully", async () => {
202
- // Try to read a directory as a file (should cause an error)
203
- const dirPath = join(tmpdir(), `test-dir-${Date.now()}`);
204
-
205
- expect(() =>
206
- render(
207
- <UpdateFile path={dirPath}>
208
- {(currentContents) => currentContents}
209
- </UpdateFile>,
210
- ),
211
- ).toThrow();
212
- });
213
- });
214
- });