svelte-sharp 0.0.0-stage → 0.1.1

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 (230) hide show
  1. package/README.md +311 -2
  2. package/compiler/win-x64/Microsoft.CSharp.dll +0 -0
  3. package/compiler/win-x64/Microsoft.CodeAnalysis.CSharp.dll +0 -0
  4. package/compiler/win-x64/Microsoft.CodeAnalysis.dll +0 -0
  5. package/compiler/win-x64/Microsoft.DiaSymReader.Native.amd64.dll +0 -0
  6. package/compiler/win-x64/Microsoft.VisualBasic.Core.dll +0 -0
  7. package/compiler/win-x64/Microsoft.VisualBasic.dll +0 -0
  8. package/compiler/win-x64/Microsoft.Win32.Primitives.dll +0 -0
  9. package/compiler/win-x64/Microsoft.Win32.Registry.dll +0 -0
  10. package/compiler/win-x64/SvelteSharp.Compiler.deps.json +882 -0
  11. package/compiler/win-x64/SvelteSharp.Compiler.dll +0 -0
  12. package/compiler/win-x64/SvelteSharp.Compiler.exe +0 -0
  13. package/compiler/win-x64/SvelteSharp.Compiler.runtimeconfig.json +15 -0
  14. package/compiler/win-x64/System.AppContext.dll +0 -0
  15. package/compiler/win-x64/System.Buffers.dll +0 -0
  16. package/compiler/win-x64/System.Collections.Concurrent.dll +0 -0
  17. package/compiler/win-x64/System.Collections.Immutable.dll +0 -0
  18. package/compiler/win-x64/System.Collections.NonGeneric.dll +0 -0
  19. package/compiler/win-x64/System.Collections.Specialized.dll +0 -0
  20. package/compiler/win-x64/System.Collections.dll +0 -0
  21. package/compiler/win-x64/System.ComponentModel.Annotations.dll +0 -0
  22. package/compiler/win-x64/System.ComponentModel.DataAnnotations.dll +0 -0
  23. package/compiler/win-x64/System.ComponentModel.EventBasedAsync.dll +0 -0
  24. package/compiler/win-x64/System.ComponentModel.Primitives.dll +0 -0
  25. package/compiler/win-x64/System.ComponentModel.TypeConverter.dll +0 -0
  26. package/compiler/win-x64/System.ComponentModel.dll +0 -0
  27. package/compiler/win-x64/System.Configuration.dll +0 -0
  28. package/compiler/win-x64/System.Console.dll +0 -0
  29. package/compiler/win-x64/System.Core.dll +0 -0
  30. package/compiler/win-x64/System.Data.Common.dll +0 -0
  31. package/compiler/win-x64/System.Data.DataSetExtensions.dll +0 -0
  32. package/compiler/win-x64/System.Data.dll +0 -0
  33. package/compiler/win-x64/System.Diagnostics.Contracts.dll +0 -0
  34. package/compiler/win-x64/System.Diagnostics.Debug.dll +0 -0
  35. package/compiler/win-x64/System.Diagnostics.DiagnosticSource.dll +0 -0
  36. package/compiler/win-x64/System.Diagnostics.FileVersionInfo.dll +0 -0
  37. package/compiler/win-x64/System.Diagnostics.Process.dll +0 -0
  38. package/compiler/win-x64/System.Diagnostics.StackTrace.dll +0 -0
  39. package/compiler/win-x64/System.Diagnostics.TextWriterTraceListener.dll +0 -0
  40. package/compiler/win-x64/System.Diagnostics.Tools.dll +0 -0
  41. package/compiler/win-x64/System.Diagnostics.TraceSource.dll +0 -0
  42. package/compiler/win-x64/System.Diagnostics.Tracing.dll +0 -0
  43. package/compiler/win-x64/System.Drawing.Primitives.dll +0 -0
  44. package/compiler/win-x64/System.Drawing.dll +0 -0
  45. package/compiler/win-x64/System.Dynamic.Runtime.dll +0 -0
  46. package/compiler/win-x64/System.Formats.Asn1.dll +0 -0
  47. package/compiler/win-x64/System.Formats.Tar.dll +0 -0
  48. package/compiler/win-x64/System.Globalization.Calendars.dll +0 -0
  49. package/compiler/win-x64/System.Globalization.Extensions.dll +0 -0
  50. package/compiler/win-x64/System.Globalization.dll +0 -0
  51. package/compiler/win-x64/System.IO.Compression.Brotli.dll +0 -0
  52. package/compiler/win-x64/System.IO.Compression.FileSystem.dll +0 -0
  53. package/compiler/win-x64/System.IO.Compression.Native.dll +0 -0
  54. package/compiler/win-x64/System.IO.Compression.ZipFile.dll +0 -0
  55. package/compiler/win-x64/System.IO.Compression.dll +0 -0
  56. package/compiler/win-x64/System.IO.FileSystem.AccessControl.dll +0 -0
  57. package/compiler/win-x64/System.IO.FileSystem.DriveInfo.dll +0 -0
  58. package/compiler/win-x64/System.IO.FileSystem.Primitives.dll +0 -0
  59. package/compiler/win-x64/System.IO.FileSystem.Watcher.dll +0 -0
  60. package/compiler/win-x64/System.IO.FileSystem.dll +0 -0
  61. package/compiler/win-x64/System.IO.IsolatedStorage.dll +0 -0
  62. package/compiler/win-x64/System.IO.MemoryMappedFiles.dll +0 -0
  63. package/compiler/win-x64/System.IO.Pipelines.dll +0 -0
  64. package/compiler/win-x64/System.IO.Pipes.AccessControl.dll +0 -0
  65. package/compiler/win-x64/System.IO.Pipes.dll +0 -0
  66. package/compiler/win-x64/System.IO.UnmanagedMemoryStream.dll +0 -0
  67. package/compiler/win-x64/System.IO.dll +0 -0
  68. package/compiler/win-x64/System.Linq.Expressions.dll +0 -0
  69. package/compiler/win-x64/System.Linq.Parallel.dll +0 -0
  70. package/compiler/win-x64/System.Linq.Queryable.dll +0 -0
  71. package/compiler/win-x64/System.Linq.dll +0 -0
  72. package/compiler/win-x64/System.Memory.dll +0 -0
  73. package/compiler/win-x64/System.Net.Http.Json.dll +0 -0
  74. package/compiler/win-x64/System.Net.Http.dll +0 -0
  75. package/compiler/win-x64/System.Net.HttpListener.dll +0 -0
  76. package/compiler/win-x64/System.Net.Mail.dll +0 -0
  77. package/compiler/win-x64/System.Net.NameResolution.dll +0 -0
  78. package/compiler/win-x64/System.Net.NetworkInformation.dll +0 -0
  79. package/compiler/win-x64/System.Net.Ping.dll +0 -0
  80. package/compiler/win-x64/System.Net.Primitives.dll +0 -0
  81. package/compiler/win-x64/System.Net.Quic.dll +0 -0
  82. package/compiler/win-x64/System.Net.Requests.dll +0 -0
  83. package/compiler/win-x64/System.Net.Security.dll +0 -0
  84. package/compiler/win-x64/System.Net.ServicePoint.dll +0 -0
  85. package/compiler/win-x64/System.Net.Sockets.dll +0 -0
  86. package/compiler/win-x64/System.Net.WebClient.dll +0 -0
  87. package/compiler/win-x64/System.Net.WebHeaderCollection.dll +0 -0
  88. package/compiler/win-x64/System.Net.WebProxy.dll +0 -0
  89. package/compiler/win-x64/System.Net.WebSockets.Client.dll +0 -0
  90. package/compiler/win-x64/System.Net.WebSockets.dll +0 -0
  91. package/compiler/win-x64/System.Net.dll +0 -0
  92. package/compiler/win-x64/System.Numerics.Vectors.dll +0 -0
  93. package/compiler/win-x64/System.Numerics.dll +0 -0
  94. package/compiler/win-x64/System.ObjectModel.dll +0 -0
  95. package/compiler/win-x64/System.Private.CoreLib.dll +0 -0
  96. package/compiler/win-x64/System.Private.DataContractSerialization.dll +0 -0
  97. package/compiler/win-x64/System.Private.Uri.dll +0 -0
  98. package/compiler/win-x64/System.Private.Xml.Linq.dll +0 -0
  99. package/compiler/win-x64/System.Private.Xml.dll +0 -0
  100. package/compiler/win-x64/System.Reflection.DispatchProxy.dll +0 -0
  101. package/compiler/win-x64/System.Reflection.Emit.ILGeneration.dll +0 -0
  102. package/compiler/win-x64/System.Reflection.Emit.Lightweight.dll +0 -0
  103. package/compiler/win-x64/System.Reflection.Emit.dll +0 -0
  104. package/compiler/win-x64/System.Reflection.Extensions.dll +0 -0
  105. package/compiler/win-x64/System.Reflection.Metadata.dll +0 -0
  106. package/compiler/win-x64/System.Reflection.Primitives.dll +0 -0
  107. package/compiler/win-x64/System.Reflection.TypeExtensions.dll +0 -0
  108. package/compiler/win-x64/System.Reflection.dll +0 -0
  109. package/compiler/win-x64/System.Resources.Reader.dll +0 -0
  110. package/compiler/win-x64/System.Resources.ResourceManager.dll +0 -0
  111. package/compiler/win-x64/System.Resources.Writer.dll +0 -0
  112. package/compiler/win-x64/System.Runtime.CompilerServices.Unsafe.dll +0 -0
  113. package/compiler/win-x64/System.Runtime.CompilerServices.VisualC.dll +0 -0
  114. package/compiler/win-x64/System.Runtime.Extensions.dll +0 -0
  115. package/compiler/win-x64/System.Runtime.Handles.dll +0 -0
  116. package/compiler/win-x64/System.Runtime.InteropServices.JavaScript.dll +0 -0
  117. package/compiler/win-x64/System.Runtime.InteropServices.RuntimeInformation.dll +0 -0
  118. package/compiler/win-x64/System.Runtime.InteropServices.dll +0 -0
  119. package/compiler/win-x64/System.Runtime.Intrinsics.dll +0 -0
  120. package/compiler/win-x64/System.Runtime.Loader.dll +0 -0
  121. package/compiler/win-x64/System.Runtime.Numerics.dll +0 -0
  122. package/compiler/win-x64/System.Runtime.Serialization.Formatters.dll +0 -0
  123. package/compiler/win-x64/System.Runtime.Serialization.Json.dll +0 -0
  124. package/compiler/win-x64/System.Runtime.Serialization.Primitives.dll +0 -0
  125. package/compiler/win-x64/System.Runtime.Serialization.Xml.dll +0 -0
  126. package/compiler/win-x64/System.Runtime.Serialization.dll +0 -0
  127. package/compiler/win-x64/System.Runtime.dll +0 -0
  128. package/compiler/win-x64/System.Security.AccessControl.dll +0 -0
  129. package/compiler/win-x64/System.Security.Claims.dll +0 -0
  130. package/compiler/win-x64/System.Security.Cryptography.Algorithms.dll +0 -0
  131. package/compiler/win-x64/System.Security.Cryptography.Cng.dll +0 -0
  132. package/compiler/win-x64/System.Security.Cryptography.Csp.dll +0 -0
  133. package/compiler/win-x64/System.Security.Cryptography.Encoding.dll +0 -0
  134. package/compiler/win-x64/System.Security.Cryptography.OpenSsl.dll +0 -0
  135. package/compiler/win-x64/System.Security.Cryptography.Primitives.dll +0 -0
  136. package/compiler/win-x64/System.Security.Cryptography.X509Certificates.dll +0 -0
  137. package/compiler/win-x64/System.Security.Cryptography.dll +0 -0
  138. package/compiler/win-x64/System.Security.Principal.Windows.dll +0 -0
  139. package/compiler/win-x64/System.Security.Principal.dll +0 -0
  140. package/compiler/win-x64/System.Security.SecureString.dll +0 -0
  141. package/compiler/win-x64/System.Security.dll +0 -0
  142. package/compiler/win-x64/System.ServiceModel.Web.dll +0 -0
  143. package/compiler/win-x64/System.ServiceProcess.dll +0 -0
  144. package/compiler/win-x64/System.Text.Encoding.CodePages.dll +0 -0
  145. package/compiler/win-x64/System.Text.Encoding.Extensions.dll +0 -0
  146. package/compiler/win-x64/System.Text.Encoding.dll +0 -0
  147. package/compiler/win-x64/System.Text.Encodings.Web.dll +0 -0
  148. package/compiler/win-x64/System.Text.Json.dll +0 -0
  149. package/compiler/win-x64/System.Text.RegularExpressions.dll +0 -0
  150. package/compiler/win-x64/System.Threading.Channels.dll +0 -0
  151. package/compiler/win-x64/System.Threading.Overlapped.dll +0 -0
  152. package/compiler/win-x64/System.Threading.Tasks.Dataflow.dll +0 -0
  153. package/compiler/win-x64/System.Threading.Tasks.Extensions.dll +0 -0
  154. package/compiler/win-x64/System.Threading.Tasks.Parallel.dll +0 -0
  155. package/compiler/win-x64/System.Threading.Tasks.dll +0 -0
  156. package/compiler/win-x64/System.Threading.Thread.dll +0 -0
  157. package/compiler/win-x64/System.Threading.ThreadPool.dll +0 -0
  158. package/compiler/win-x64/System.Threading.Timer.dll +0 -0
  159. package/compiler/win-x64/System.Threading.dll +0 -0
  160. package/compiler/win-x64/System.Transactions.Local.dll +0 -0
  161. package/compiler/win-x64/System.Transactions.dll +0 -0
  162. package/compiler/win-x64/System.ValueTuple.dll +0 -0
  163. package/compiler/win-x64/System.Web.HttpUtility.dll +0 -0
  164. package/compiler/win-x64/System.Web.dll +0 -0
  165. package/compiler/win-x64/System.Windows.dll +0 -0
  166. package/compiler/win-x64/System.Xml.Linq.dll +0 -0
  167. package/compiler/win-x64/System.Xml.ReaderWriter.dll +0 -0
  168. package/compiler/win-x64/System.Xml.Serialization.dll +0 -0
  169. package/compiler/win-x64/System.Xml.XDocument.dll +0 -0
  170. package/compiler/win-x64/System.Xml.XPath.XDocument.dll +0 -0
  171. package/compiler/win-x64/System.Xml.XPath.dll +0 -0
  172. package/compiler/win-x64/System.Xml.XmlDocument.dll +0 -0
  173. package/compiler/win-x64/System.Xml.XmlSerializer.dll +0 -0
  174. package/compiler/win-x64/System.Xml.dll +0 -0
  175. package/compiler/win-x64/System.dll +0 -0
  176. package/compiler/win-x64/WindowsBase.dll +0 -0
  177. package/compiler/win-x64/clretwrc.dll +0 -0
  178. package/compiler/win-x64/clrgc.dll +0 -0
  179. package/compiler/win-x64/clrgcexp.dll +0 -0
  180. package/compiler/win-x64/clrjit.dll +0 -0
  181. package/compiler/win-x64/coreclr.dll +0 -0
  182. package/compiler/win-x64/createdump.exe +0 -0
  183. package/compiler/win-x64/cs/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  184. package/compiler/win-x64/cs/Microsoft.CodeAnalysis.resources.dll +0 -0
  185. package/compiler/win-x64/de/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  186. package/compiler/win-x64/de/Microsoft.CodeAnalysis.resources.dll +0 -0
  187. package/compiler/win-x64/es/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  188. package/compiler/win-x64/es/Microsoft.CodeAnalysis.resources.dll +0 -0
  189. package/compiler/win-x64/fr/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  190. package/compiler/win-x64/fr/Microsoft.CodeAnalysis.resources.dll +0 -0
  191. package/compiler/win-x64/hostfxr.dll +0 -0
  192. package/compiler/win-x64/hostpolicy.dll +0 -0
  193. package/compiler/win-x64/it/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  194. package/compiler/win-x64/it/Microsoft.CodeAnalysis.resources.dll +0 -0
  195. package/compiler/win-x64/ja/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  196. package/compiler/win-x64/ja/Microsoft.CodeAnalysis.resources.dll +0 -0
  197. package/compiler/win-x64/ko/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  198. package/compiler/win-x64/ko/Microsoft.CodeAnalysis.resources.dll +0 -0
  199. package/compiler/win-x64/mscordaccore.dll +0 -0
  200. package/compiler/win-x64/mscordaccore_amd64_amd64_9.0.2026.41315.dll +0 -0
  201. package/compiler/win-x64/mscordbi.dll +0 -0
  202. package/compiler/win-x64/mscorlib.dll +0 -0
  203. package/compiler/win-x64/mscorrc.dll +0 -0
  204. package/compiler/win-x64/msquic.dll +0 -0
  205. package/compiler/win-x64/netstandard.dll +0 -0
  206. package/compiler/win-x64/pl/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  207. package/compiler/win-x64/pl/Microsoft.CodeAnalysis.resources.dll +0 -0
  208. package/compiler/win-x64/pt-BR/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  209. package/compiler/win-x64/pt-BR/Microsoft.CodeAnalysis.resources.dll +0 -0
  210. package/compiler/win-x64/ru/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  211. package/compiler/win-x64/ru/Microsoft.CodeAnalysis.resources.dll +0 -0
  212. package/compiler/win-x64/tr/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  213. package/compiler/win-x64/tr/Microsoft.CodeAnalysis.resources.dll +0 -0
  214. package/compiler/win-x64/zh-Hans/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  215. package/compiler/win-x64/zh-Hans/Microsoft.CodeAnalysis.resources.dll +0 -0
  216. package/compiler/win-x64/zh-Hant/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
  217. package/compiler/win-x64/zh-Hant/Microsoft.CodeAnalysis.resources.dll +0 -0
  218. package/dist/compiler-runner.d.ts +2 -0
  219. package/dist/compiler-runner.js +95 -0
  220. package/dist/index.d.ts +3 -0
  221. package/dist/index.js +2 -0
  222. package/dist/preprocessor.d.ts +3 -0
  223. package/dist/preprocessor.js +45 -0
  224. package/dist/types.d.ts +4 -0
  225. package/dist/types.js +1 -0
  226. package/dist/vite-plugin.d.ts +3 -0
  227. package/dist/vite-plugin.js +26 -0
  228. package/dist/watcher.d.ts +3 -0
  229. package/dist/watcher.js +12 -0
  230. package/package.json +31 -4
@@ -0,0 +1,95 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import { existsSync } from 'node:fs';
4
+ import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
5
+ import { dirname, resolve } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ const packageDirectory = resolve(dirname(fileURLToPath(import.meta.url)), '..');
8
+ function getCompilerPath(options) {
9
+ if (options.compilerPath) {
10
+ return resolve(options.compilerPath);
11
+ }
12
+ if (process.platform !== 'win32' || process.arch !== 'x64') {
13
+ throw new Error(`SvelteSharp currently supports Windows x64 only. ` +
14
+ `Your platform is ${process.platform}-${process.arch}.`);
15
+ }
16
+ return resolve(packageDirectory, 'compiler', 'win-x64', 'SvelteSharp.Compiler.exe');
17
+ }
18
+ function createCacheKey(filename, componentCode, csharpCode, compilerModified, compilerSize) {
19
+ return createHash('sha256')
20
+ .update(filename)
21
+ .update(componentCode)
22
+ .update(csharpCode)
23
+ .update(String(compilerModified))
24
+ .update(String(compilerSize))
25
+ .digest('hex');
26
+ }
27
+ export async function compileComponent(filename, options = {}, suppliedContent) {
28
+ const absoluteFilename = resolve(filename);
29
+ const csharpFilename = `${absoluteFilename}.cs`;
30
+ const compilerPath = getCompilerPath(options);
31
+ // Read Svelte component content.
32
+ const componentCode = suppliedContent ??
33
+ await readFile(absoluteFilename, 'utf8');
34
+ // Read companion C# file if it exists.
35
+ const csharpCode = existsSync(csharpFilename)
36
+ ? await readFile(csharpFilename, 'utf8')
37
+ : '';
38
+ // Check compiler information.
39
+ let compilerInfo;
40
+ try {
41
+ compilerInfo = await stat(compilerPath);
42
+ }
43
+ catch {
44
+ throw new Error(`SvelteSharp compiler was not found: ${compilerPath}\n` +
45
+ `Build the compiler using: npm run compiler:build`);
46
+ }
47
+ // Generate cache key.
48
+ const cacheKey = createCacheKey(absoluteFilename, componentCode, csharpCode, compilerInfo.mtimeMs, compilerInfo.size);
49
+ // Store cache inside the consuming project's node_modules.
50
+ const cacheDirectory = resolve(process.cwd(), 'node_modules', '.cache', 'svelte-sharp');
51
+ const cacheFile = resolve(cacheDirectory, `${cacheKey}.svelte`);
52
+ // Return cached output if it exists.
53
+ try {
54
+ return await readFile(cacheFile, 'utf8');
55
+ }
56
+ catch {
57
+ // Cache does not exist.
58
+ }
59
+ // Execute compiler.
60
+ const generatedCode = await new Promise((resolvePromise, reject) => {
61
+ const useDotnet = Boolean(options.dotnetCommand);
62
+ const child = spawn(useDotnet ? options.dotnetCommand : compilerPath, useDotnet
63
+ ? [compilerPath, absoluteFilename]
64
+ : [absoluteFilename], {
65
+ cwd: process.cwd(),
66
+ stdio: ['ignore', 'pipe', 'pipe']
67
+ });
68
+ let stdout = '';
69
+ let stderr = '';
70
+ child.stdout.setEncoding('utf8');
71
+ child.stderr.setEncoding('utf8');
72
+ child.stdout.on('data', chunk => {
73
+ stdout += chunk;
74
+ });
75
+ child.stderr.on('data', chunk => {
76
+ stderr += chunk;
77
+ });
78
+ child.on('error', error => {
79
+ reject(new Error(`Could not start SvelteSharp compiler: ${error.message}`));
80
+ });
81
+ child.on('close', code => {
82
+ if (code === 0) {
83
+ resolvePromise(stdout);
84
+ }
85
+ else {
86
+ reject(new Error(stderr.trim() ||
87
+ `SvelteSharp compiler exited with code ${code}`));
88
+ }
89
+ });
90
+ });
91
+ // Save successful output in cache.
92
+ await mkdir(cacheDirectory, { recursive: true });
93
+ await writeFile(cacheFile, generatedCode, 'utf8');
94
+ return generatedCode;
95
+ }
@@ -0,0 +1,3 @@
1
+ export { svelteSharp } from './vite-plugin.js';
2
+ export { svelteSharpPreprocessor } from './preprocessor.js';
3
+ export type { SvelteSharpOptions } from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { svelteSharp } from './vite-plugin.js';
2
+ export { svelteSharpPreprocessor } from './preprocessor.js';
@@ -0,0 +1,3 @@
1
+ import type { PreprocessorGroup } from 'svelte/compiler';
2
+ import type { SvelteSharpOptions } from './types.js';
3
+ export declare function svelteSharpPreprocessor(options?: SvelteSharpOptions): PreprocessorGroup;
@@ -0,0 +1,45 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { compileComponent } from './compiler-runner.js';
3
+ import { registerCsharpDependency } from './watcher.js';
4
+ export function svelteSharpPreprocessor(options = {}) {
5
+ return {
6
+ name: 'svelte-sharp-preprocessor',
7
+ async markup({ content, filename }) {
8
+ if (!filename?.endsWith('.svelte')) {
9
+ return;
10
+ }
11
+ if (filename.includes('/.svelte-kit/') ||
12
+ filename.includes('\\.svelte-kit\\')) {
13
+ return;
14
+ }
15
+ const csharpFile = `${filename}.cs`;
16
+ const hasCsharpFile = existsSync(csharpFile);
17
+ const hasInlineCode = /@code\s*\{/.test(content);
18
+ if (!hasCsharpFile && !hasInlineCode) {
19
+ return;
20
+ }
21
+ if (hasCsharpFile) {
22
+ registerCsharpDependency(csharpFile);
23
+ }
24
+ try {
25
+ const code = await compileComponent(filename, options, content);
26
+ return {
27
+ code,
28
+ dependencies: hasCsharpFile
29
+ ? [csharpFile]
30
+ : []
31
+ };
32
+ }
33
+ catch (error) {
34
+ const message = error instanceof Error
35
+ ? error.message
36
+ : String(error);
37
+ if (process.env.NODE_ENV === 'production') {
38
+ console.error(`[SvelteSharp] Compilation failed in ${filename}:\n${message}`);
39
+ return;
40
+ }
41
+ throw new Error(`SvelteSharp failed in ${filename}:\n${message}`);
42
+ }
43
+ }
44
+ };
45
+ }
@@ -0,0 +1,4 @@
1
+ export interface SvelteSharpOptions {
2
+ compilerPath?: string;
3
+ dotnetCommand?: string;
4
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { SvelteSharpOptions } from './types.js';
3
+ export declare function svelteSharp(_options?: SvelteSharpOptions): Plugin;
@@ -0,0 +1,26 @@
1
+ import { resolve } from 'node:path';
2
+ import { normalizePath } from 'vite';
3
+ import { setViteServer } from './watcher.js';
4
+ export function svelteSharp(_options = {}) {
5
+ return {
6
+ name: 'svelte-sharp',
7
+ enforce: 'pre',
8
+ configureServer(server) {
9
+ setViteServer(server);
10
+ },
11
+ handleHotUpdate({ file, server }) {
12
+ if (!file.endsWith('.svelte.cs')) {
13
+ return;
14
+ }
15
+ const svelteFile = normalizePath(resolve(file.slice(0, -3)));
16
+ const modules = server.moduleGraph.getModulesByFile(svelteFile);
17
+ if (!modules || modules.size === 0) {
18
+ return;
19
+ }
20
+ for (const module of modules) {
21
+ server.moduleGraph.invalidateModule(module);
22
+ }
23
+ return [...modules];
24
+ }
25
+ };
26
+ }
@@ -0,0 +1,3 @@
1
+ import type { ViteDevServer } from 'vite';
2
+ export declare function setViteServer(server: ViteDevServer): void;
3
+ export declare function registerCsharpDependency(filename: string): void;
@@ -0,0 +1,12 @@
1
+ let viteServer;
2
+ const dependencies = new Set();
3
+ export function setViteServer(server) {
4
+ viteServer = server;
5
+ for (const file of dependencies) {
6
+ viteServer.watcher.add(file);
7
+ }
8
+ }
9
+ export function registerCsharpDependency(filename) {
10
+ dependencies.add(filename);
11
+ viteServer?.watcher.add(filename);
12
+ }
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
+
1
2
  {
2
3
  "name": "svelte-sharp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
4
+ "version": "0.1.1",
5
+ "description": "C# component authoring for SvelteKit",
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "files": [
9
+ "dist",
10
+ "compiler",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "tsc -p tsconfig.json"
22
+ },
23
+ "peerDependencies": {
24
+ "svelte": "^5.0.0",
25
+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^22.0.0",
29
+ "svelte": "^5.0.0",
30
+ "typescript": "^5.0.0",
31
+ "vite": "^6.0.0"
32
+ }
33
+ }