@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/core",
3
- "version": "0.19.0-dev.12",
3
+ "version": "0.19.0-dev.3",
4
4
  "description": "",
5
5
  "main": "./dist/src/index.js",
6
6
  "exports": {
@@ -26,8 +26,8 @@
26
26
  }
27
27
  },
28
28
  "browser": {
29
- "./dist/src/host/alloy-host.js": "./dist/src/host/alloy-host.browser.js",
30
- "./src/host/alloy-host.ts": "./src/host/alloy-host.browser.ts"
29
+ "./dist/src/write-output.js": "./dist/src/write-output.browser.js",
30
+ "./src/write-output.ts": "./src/write-output.browser.ts"
31
31
  },
32
32
  "keywords": [],
33
33
  "author": "brian.terlson@microsoft.com",
@@ -1,6 +1,4 @@
1
- export * from "./AppendFile.jsx";
2
1
  export * from "./Block.js";
3
- export * from "./CopyFile.jsx";
4
2
  export * from "./Declaration.js";
5
3
  export * from "./For.js";
6
4
  export * from "./Indent.jsx";
@@ -18,6 +16,4 @@ export * from "./SourceDirectory.js";
18
16
  export * from "./SourceFile.js";
19
17
  export * from "./StatementList.jsx";
20
18
  export * from "./Switch.jsx";
21
- export * from "./TemplateFile.jsx";
22
- export * from "./UpdateFile.jsx";
23
19
  export * from "./Wrap.jsx";
@@ -1,9 +1,7 @@
1
1
  import { stc } from "../../stc.js";
2
2
  import * as base from "../index.js";
3
3
 
4
- export const AppendFile = stc(base.AppendFile);
5
4
  export const Block = stc(base.Block);
6
- export const CopyFile = stc(base.CopyFile);
7
5
  export const Declaration = stc(base.Declaration);
8
6
  export const For = stc(base.For);
9
7
  export const Indent = stc(base.Indent);
@@ -20,8 +18,6 @@ export const StatementList = stc(base.StatementList);
20
18
  export const SourceDirectory = stc(base.SourceDirectory);
21
19
  export const SourceFile = stc(base.SourceFile);
22
20
  export const Switch = stc(base.Switch);
23
- export const TemplateFile = stc(base.TemplateFile);
24
- export const UpdateFile = stc(base.UpdateFile);
25
21
  export const Wrap = stc(base.Wrap);
26
22
  export const ReferenceOrContent = stc(base.ReferenceOrContent);
27
23
 
@@ -1,11 +1,9 @@
1
1
  import { ComponentContext, createNamedContext } from "../context.js";
2
- import type { CopyFileContext, SourceFileContext } from "./source-file.js";
2
+ import type { SourceFileContext } from "./source-file.js";
3
3
 
4
4
  export interface SourceDirectoryContext {
5
- contents: (SourceDirectoryContext | SourceFileContext | CopyFileContext)[];
6
- addContent(
7
- content: SourceDirectoryContext | SourceFileContext | CopyFileContext,
8
- ): void;
5
+ contents: (SourceDirectoryContext | SourceFileContext)[];
6
+ addContent(content: SourceDirectoryContext | SourceFileContext): void;
9
7
  path: string;
10
8
  }
11
9
 
@@ -2,11 +2,6 @@ import { ComponentContext, createNamedContext } from "../context.js";
2
2
  import type { Refkey } from "../refkey.js";
3
3
  import { ComponentDefinition } from "../runtime/component.js";
4
4
 
5
- export interface CopyFileContext {
6
- path: string;
7
- sourcePath: string;
8
- }
9
-
10
5
  export interface SourceFileContext {
11
6
  path: string;
12
7
  filetype: string;
package/src/debug.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  import { isReactive } from "@vue/reactivity";
2
3
  import Table from "cli-table3";
3
4
  import pc from "picocolors";
@@ -18,15 +19,12 @@ const debug: DebugInterface = {
18
19
  component: {
19
20
  stack: debugStack,
20
21
  tree() {
21
- //eslint-disable-next-line no-console
22
22
  console.log("tree");
23
23
  },
24
24
  watch() {
25
- //eslint-disable-next-line no-console
26
25
  console.log("watch");
27
26
  },
28
27
  render() {
29
- //eslint-disable-next-line no-console
30
28
  console.log("render");
31
29
  },
32
30
  context: debugContext,
@@ -80,7 +78,6 @@ function debugStack() {
80
78
  function debugContext() {
81
79
  let currentContext = getContext();
82
80
  while (currentContext !== null) {
83
- //eslint-disable-next-line no-console
84
81
  console.log(printContext(currentContext));
85
82
  currentContext = currentContext.owner;
86
83
  }
@@ -1,2 +1,2 @@
1
- export * from "./host/alloy-host.browser.js"; // Override writeOutput for browsers
2
1
  export * from "./index.js"; // Re-export everything
2
+ export { writeOutput } from "./write-output.browser.js"; // Override writeOutput for browsers
package/src/render.ts CHANGED
@@ -23,7 +23,7 @@ import {
23
23
  Props,
24
24
  } from "./runtime/component.js";
25
25
  import { IntrinsicElement, isIntrinsicElement } from "./runtime/intrinsic.js";
26
- import { flushJobs, flushJobsAsync } from "./scheduler.js";
26
+ import { flushJobs } from "./scheduler.js";
27
27
  import { trace, TracePhase } from "./tracer.js";
28
28
 
29
29
  const {
@@ -133,22 +133,13 @@ export interface OutputDirectory {
133
133
  contents: (OutputDirectory | OutputFile)[];
134
134
  }
135
135
 
136
- export interface OutputFileBase {
136
+ export interface OutputFile {
137
137
  kind: "file";
138
- path: string;
139
- }
140
-
141
- export interface CopyOutputFile extends OutputFileBase {
142
- sourcePath: string;
143
- }
144
-
145
- export interface ContentOutputFile extends OutputFileBase {
146
138
  contents: string;
139
+ path: string;
147
140
  filetype: string;
148
141
  }
149
142
 
150
- export type OutputFile = ContentOutputFile | CopyOutputFile;
151
-
152
143
  const nodesToContext = new WeakMap<RenderedTextTree, Context>();
153
144
 
154
145
  export function getContextForRenderNode(node: RenderedTextTree) {
@@ -190,22 +181,6 @@ export function render(
190
181
  ): OutputDirectory {
191
182
  const tree = renderTree(children);
192
183
  flushJobs();
193
- return sourceFilesForTree(tree, options);
194
- }
195
-
196
- export async function renderAsync(
197
- children: Children,
198
- options?: PrintTreeOptions,
199
- ): Promise<OutputDirectory> {
200
- const tree = renderTree(children);
201
- await flushJobsAsync();
202
- return sourceFilesForTree(tree, options);
203
- }
204
-
205
- export function sourceFilesForTree(
206
- tree: RenderedTextTree,
207
- options?: PrintTreeOptions,
208
- ): OutputDirectory {
209
184
  let rootDirectory: OutputDirectory | undefined = undefined;
210
185
 
211
186
  // when passing Output, the first render tree child is the Output component.
@@ -259,7 +234,7 @@ export function sourceFilesForTree(
259
234
  );
260
235
  }
261
236
 
262
- const sourceFile: ContentOutputFile = {
237
+ const sourceFile: OutputFile = {
263
238
  kind: "file",
264
239
  path: context.meta?.sourceFile.path,
265
240
  filetype: context.meta?.sourceFile.filetype,
@@ -279,21 +254,6 @@ export function sourceFilesForTree(
279
254
  }),
280
255
  };
281
256
 
282
- currentDirectory.contents.push(sourceFile);
283
- } else if (context.meta?.copyFile) {
284
- if (!currentDirectory) {
285
- // This shouldn't happen if you're using the Output component.
286
- throw new Error(
287
- "Copy file doesn't have parent directory. Make sure you have used the Output component.",
288
- );
289
- }
290
-
291
- const sourceFile: CopyOutputFile = {
292
- kind: "file",
293
- path: context.meta?.copyFile.path,
294
- sourcePath: context.meta?.copyFile.sourcePath,
295
- };
296
-
297
257
  currentDirectory.contents.push(sourceFile);
298
258
  } else {
299
259
  recurse(currentDirectory);
@@ -306,6 +266,7 @@ export function sourceFilesForTree(
306
266
  }
307
267
  }
308
268
  }
269
+
309
270
  export function renderTree(children: Children) {
310
271
  const rootElem: RenderedTextTree = [];
311
272
  try {
package/src/scheduler.ts CHANGED
@@ -5,7 +5,6 @@ export interface QueueJob {
5
5
  }
6
6
  const immediateQueue = new Set<QueueJob>();
7
7
  const queue = new Set<QueueJob>();
8
- const pendingPromises = new Set<Promise<any>>();
9
8
 
10
9
  export function scheduler(
11
10
  jobGetter: () => ReactiveEffectRunner,
@@ -26,49 +25,11 @@ export function queueJob(job: QueueJob, immediate = false) {
26
25
  }
27
26
  }
28
27
 
29
- /**
30
- * Register a promise that the scheduler should wait for during flushJobs.
31
- * This is used by async resources to ensure the scheduler waits for their completion.
32
- */
33
- export function trackPromise(promise: Promise<any>) {
34
- pendingPromises.add(promise);
35
- void promise.finally(() => {
36
- pendingPromises.delete(promise);
37
- });
38
- }
39
-
40
28
  export function flushJobs() {
41
- // First, run all synchronous jobs
42
29
  let job;
43
30
  while ((job = takeJob()) !== null) {
44
31
  job();
45
32
  }
46
-
47
- // If there are no pending promises, we're done
48
- if (pendingPromises.size > 0) {
49
- throw new Error(
50
- "Asynchronous jobs were found but render was called synchronously. Use `asyncRender` instead.",
51
- );
52
- }
53
- }
54
-
55
- export async function flushJobsAsync() {
56
- // Keep running jobs until both the queues are empty and all promises are resolved
57
- while (true) {
58
- // First, run all synchronous jobs
59
- let job;
60
- while ((job = takeJob()) !== null) {
61
- job();
62
- }
63
-
64
- // If there are no pending promises, we're done
65
- if (pendingPromises.size === 0) {
66
- break;
67
- }
68
-
69
- // Wait for all current promises to complete
70
- await Promise.allSettled(Array.from(pendingPromises));
71
- }
72
33
  }
73
34
 
74
35
  function takeJob() {
@@ -0,0 +1,4 @@
1
+ export function writeOutput(output: any, basePath: string = "") {
2
+ // eslint-disable-next-line no-console
3
+ console.warn("writeOutput is not supported in a browser environment.");
4
+ }
@@ -1,63 +1,33 @@
1
- import { dirname, relative, resolve } from "pathe";
2
- import { AlloyHost } from "./host/alloy-host.js";
1
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
+ import { relative, resolve } from "pathe";
3
3
  import { OutputDirectory } from "./render.js";
4
4
  import { traverseOutput } from "./utils.js";
5
5
  /**
6
6
  * Write the output from {@link render} to the file system.
7
7
  *
8
8
  */
9
- export async function writeOutput(
10
- output: OutputDirectory,
11
- basePath: string = "",
12
- ) {
13
- const ops: Promise<void>[] = [];
14
-
9
+ export function writeOutput(output: OutputDirectory, basePath: string = "") {
15
10
  traverseOutput(output, {
16
11
  visitDirectory(directory) {
17
- ops.push(
18
- (async () => {
19
- const path = resolve(basePath, directory.path);
20
- if (await AlloyHost.exists(path)) {
21
- return;
22
- }
23
- // eslint-disable-next-line no-console
24
- console.log("create", relative(process.cwd(), path));
25
- await AlloyHost.mkdir(path);
26
- })(),
27
- );
12
+ const path = resolve(basePath, directory.path);
13
+ if (existsSync(path)) {
14
+ return;
15
+ }
16
+ // eslint-disable-next-line no-console
17
+ console.log("create", relative(process.cwd(), path));
18
+ mkdirSync(path, { recursive: true });
28
19
  },
29
20
  visitFile(file) {
30
- ops.push(
31
- (async () => {
32
- if ("contents" in file) {
33
- const path = resolve(basePath, file.path);
34
- if (await AlloyHost.exists(path)) {
35
- // eslint-disable-next-line no-console
36
- console.log("overwrite", relative(process.cwd(), path));
37
- } else {
38
- // eslint-disable-next-line no-console
39
- console.log("create", relative(process.cwd(), path));
40
- }
21
+ const path = resolve(basePath, file.path);
22
+ if (existsSync(path)) {
23
+ // eslint-disable-next-line no-console
24
+ console.log("overwrite", relative(process.cwd(), path));
25
+ } else {
26
+ // eslint-disable-next-line no-console
27
+ console.log("create", relative(process.cwd(), path));
28
+ }
41
29
 
42
- await AlloyHost.write(path, file.contents);
43
- } else {
44
- // copy file
45
- const source = resolve(basePath, file.sourcePath);
46
- const target = resolve(basePath, file.path);
47
- if (await AlloyHost.exists(target)) {
48
- // eslint-disable-next-line no-console
49
- console.log("copy over", relative(process.cwd(), target));
50
- } else {
51
- // eslint-disable-next-line no-console
52
- console.log("copy", relative(process.cwd(), target));
53
- }
54
- await AlloyHost.mkdir(dirname(target));
55
- await AlloyHost.write(target, AlloyHost.read(source).stream());
56
- }
57
- })(),
58
- );
30
+ writeFileSync(path, file.contents);
59
31
  },
60
32
  });
61
-
62
- return Promise.all(ops);
63
33
  }