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.
- package/README.md +311 -2
- package/compiler/win-x64/Microsoft.CSharp.dll +0 -0
- package/compiler/win-x64/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/compiler/win-x64/Microsoft.CodeAnalysis.dll +0 -0
- package/compiler/win-x64/Microsoft.DiaSymReader.Native.amd64.dll +0 -0
- package/compiler/win-x64/Microsoft.VisualBasic.Core.dll +0 -0
- package/compiler/win-x64/Microsoft.VisualBasic.dll +0 -0
- package/compiler/win-x64/Microsoft.Win32.Primitives.dll +0 -0
- package/compiler/win-x64/Microsoft.Win32.Registry.dll +0 -0
- package/compiler/win-x64/SvelteSharp.Compiler.deps.json +882 -0
- package/compiler/win-x64/SvelteSharp.Compiler.dll +0 -0
- package/compiler/win-x64/SvelteSharp.Compiler.exe +0 -0
- package/compiler/win-x64/SvelteSharp.Compiler.runtimeconfig.json +15 -0
- package/compiler/win-x64/System.AppContext.dll +0 -0
- package/compiler/win-x64/System.Buffers.dll +0 -0
- package/compiler/win-x64/System.Collections.Concurrent.dll +0 -0
- package/compiler/win-x64/System.Collections.Immutable.dll +0 -0
- package/compiler/win-x64/System.Collections.NonGeneric.dll +0 -0
- package/compiler/win-x64/System.Collections.Specialized.dll +0 -0
- package/compiler/win-x64/System.Collections.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.Annotations.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.DataAnnotations.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.EventBasedAsync.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.Primitives.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.TypeConverter.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.dll +0 -0
- package/compiler/win-x64/System.Configuration.dll +0 -0
- package/compiler/win-x64/System.Console.dll +0 -0
- package/compiler/win-x64/System.Core.dll +0 -0
- package/compiler/win-x64/System.Data.Common.dll +0 -0
- package/compiler/win-x64/System.Data.DataSetExtensions.dll +0 -0
- package/compiler/win-x64/System.Data.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.Contracts.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.Debug.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.DiagnosticSource.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.FileVersionInfo.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.Process.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.StackTrace.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.TextWriterTraceListener.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.Tools.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.TraceSource.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.Tracing.dll +0 -0
- package/compiler/win-x64/System.Drawing.Primitives.dll +0 -0
- package/compiler/win-x64/System.Drawing.dll +0 -0
- package/compiler/win-x64/System.Dynamic.Runtime.dll +0 -0
- package/compiler/win-x64/System.Formats.Asn1.dll +0 -0
- package/compiler/win-x64/System.Formats.Tar.dll +0 -0
- package/compiler/win-x64/System.Globalization.Calendars.dll +0 -0
- package/compiler/win-x64/System.Globalization.Extensions.dll +0 -0
- package/compiler/win-x64/System.Globalization.dll +0 -0
- package/compiler/win-x64/System.IO.Compression.Brotli.dll +0 -0
- package/compiler/win-x64/System.IO.Compression.FileSystem.dll +0 -0
- package/compiler/win-x64/System.IO.Compression.Native.dll +0 -0
- package/compiler/win-x64/System.IO.Compression.ZipFile.dll +0 -0
- package/compiler/win-x64/System.IO.Compression.dll +0 -0
- package/compiler/win-x64/System.IO.FileSystem.AccessControl.dll +0 -0
- package/compiler/win-x64/System.IO.FileSystem.DriveInfo.dll +0 -0
- package/compiler/win-x64/System.IO.FileSystem.Primitives.dll +0 -0
- package/compiler/win-x64/System.IO.FileSystem.Watcher.dll +0 -0
- package/compiler/win-x64/System.IO.FileSystem.dll +0 -0
- package/compiler/win-x64/System.IO.IsolatedStorage.dll +0 -0
- package/compiler/win-x64/System.IO.MemoryMappedFiles.dll +0 -0
- package/compiler/win-x64/System.IO.Pipelines.dll +0 -0
- package/compiler/win-x64/System.IO.Pipes.AccessControl.dll +0 -0
- package/compiler/win-x64/System.IO.Pipes.dll +0 -0
- package/compiler/win-x64/System.IO.UnmanagedMemoryStream.dll +0 -0
- package/compiler/win-x64/System.IO.dll +0 -0
- package/compiler/win-x64/System.Linq.Expressions.dll +0 -0
- package/compiler/win-x64/System.Linq.Parallel.dll +0 -0
- package/compiler/win-x64/System.Linq.Queryable.dll +0 -0
- package/compiler/win-x64/System.Linq.dll +0 -0
- package/compiler/win-x64/System.Memory.dll +0 -0
- package/compiler/win-x64/System.Net.Http.Json.dll +0 -0
- package/compiler/win-x64/System.Net.Http.dll +0 -0
- package/compiler/win-x64/System.Net.HttpListener.dll +0 -0
- package/compiler/win-x64/System.Net.Mail.dll +0 -0
- package/compiler/win-x64/System.Net.NameResolution.dll +0 -0
- package/compiler/win-x64/System.Net.NetworkInformation.dll +0 -0
- package/compiler/win-x64/System.Net.Ping.dll +0 -0
- package/compiler/win-x64/System.Net.Primitives.dll +0 -0
- package/compiler/win-x64/System.Net.Quic.dll +0 -0
- package/compiler/win-x64/System.Net.Requests.dll +0 -0
- package/compiler/win-x64/System.Net.Security.dll +0 -0
- package/compiler/win-x64/System.Net.ServicePoint.dll +0 -0
- package/compiler/win-x64/System.Net.Sockets.dll +0 -0
- package/compiler/win-x64/System.Net.WebClient.dll +0 -0
- package/compiler/win-x64/System.Net.WebHeaderCollection.dll +0 -0
- package/compiler/win-x64/System.Net.WebProxy.dll +0 -0
- package/compiler/win-x64/System.Net.WebSockets.Client.dll +0 -0
- package/compiler/win-x64/System.Net.WebSockets.dll +0 -0
- package/compiler/win-x64/System.Net.dll +0 -0
- package/compiler/win-x64/System.Numerics.Vectors.dll +0 -0
- package/compiler/win-x64/System.Numerics.dll +0 -0
- package/compiler/win-x64/System.ObjectModel.dll +0 -0
- package/compiler/win-x64/System.Private.CoreLib.dll +0 -0
- package/compiler/win-x64/System.Private.DataContractSerialization.dll +0 -0
- package/compiler/win-x64/System.Private.Uri.dll +0 -0
- package/compiler/win-x64/System.Private.Xml.Linq.dll +0 -0
- package/compiler/win-x64/System.Private.Xml.dll +0 -0
- package/compiler/win-x64/System.Reflection.DispatchProxy.dll +0 -0
- package/compiler/win-x64/System.Reflection.Emit.ILGeneration.dll +0 -0
- package/compiler/win-x64/System.Reflection.Emit.Lightweight.dll +0 -0
- package/compiler/win-x64/System.Reflection.Emit.dll +0 -0
- package/compiler/win-x64/System.Reflection.Extensions.dll +0 -0
- package/compiler/win-x64/System.Reflection.Metadata.dll +0 -0
- package/compiler/win-x64/System.Reflection.Primitives.dll +0 -0
- package/compiler/win-x64/System.Reflection.TypeExtensions.dll +0 -0
- package/compiler/win-x64/System.Reflection.dll +0 -0
- package/compiler/win-x64/System.Resources.Reader.dll +0 -0
- package/compiler/win-x64/System.Resources.ResourceManager.dll +0 -0
- package/compiler/win-x64/System.Resources.Writer.dll +0 -0
- package/compiler/win-x64/System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/compiler/win-x64/System.Runtime.CompilerServices.VisualC.dll +0 -0
- package/compiler/win-x64/System.Runtime.Extensions.dll +0 -0
- package/compiler/win-x64/System.Runtime.Handles.dll +0 -0
- package/compiler/win-x64/System.Runtime.InteropServices.JavaScript.dll +0 -0
- package/compiler/win-x64/System.Runtime.InteropServices.RuntimeInformation.dll +0 -0
- package/compiler/win-x64/System.Runtime.InteropServices.dll +0 -0
- package/compiler/win-x64/System.Runtime.Intrinsics.dll +0 -0
- package/compiler/win-x64/System.Runtime.Loader.dll +0 -0
- package/compiler/win-x64/System.Runtime.Numerics.dll +0 -0
- package/compiler/win-x64/System.Runtime.Serialization.Formatters.dll +0 -0
- package/compiler/win-x64/System.Runtime.Serialization.Json.dll +0 -0
- package/compiler/win-x64/System.Runtime.Serialization.Primitives.dll +0 -0
- package/compiler/win-x64/System.Runtime.Serialization.Xml.dll +0 -0
- package/compiler/win-x64/System.Runtime.Serialization.dll +0 -0
- package/compiler/win-x64/System.Runtime.dll +0 -0
- package/compiler/win-x64/System.Security.AccessControl.dll +0 -0
- package/compiler/win-x64/System.Security.Claims.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.Algorithms.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.Cng.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.Csp.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.Encoding.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.OpenSsl.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.Primitives.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.X509Certificates.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.dll +0 -0
- package/compiler/win-x64/System.Security.Principal.Windows.dll +0 -0
- package/compiler/win-x64/System.Security.Principal.dll +0 -0
- package/compiler/win-x64/System.Security.SecureString.dll +0 -0
- package/compiler/win-x64/System.Security.dll +0 -0
- package/compiler/win-x64/System.ServiceModel.Web.dll +0 -0
- package/compiler/win-x64/System.ServiceProcess.dll +0 -0
- package/compiler/win-x64/System.Text.Encoding.CodePages.dll +0 -0
- package/compiler/win-x64/System.Text.Encoding.Extensions.dll +0 -0
- package/compiler/win-x64/System.Text.Encoding.dll +0 -0
- package/compiler/win-x64/System.Text.Encodings.Web.dll +0 -0
- package/compiler/win-x64/System.Text.Json.dll +0 -0
- package/compiler/win-x64/System.Text.RegularExpressions.dll +0 -0
- package/compiler/win-x64/System.Threading.Channels.dll +0 -0
- package/compiler/win-x64/System.Threading.Overlapped.dll +0 -0
- package/compiler/win-x64/System.Threading.Tasks.Dataflow.dll +0 -0
- package/compiler/win-x64/System.Threading.Tasks.Extensions.dll +0 -0
- package/compiler/win-x64/System.Threading.Tasks.Parallel.dll +0 -0
- package/compiler/win-x64/System.Threading.Tasks.dll +0 -0
- package/compiler/win-x64/System.Threading.Thread.dll +0 -0
- package/compiler/win-x64/System.Threading.ThreadPool.dll +0 -0
- package/compiler/win-x64/System.Threading.Timer.dll +0 -0
- package/compiler/win-x64/System.Threading.dll +0 -0
- package/compiler/win-x64/System.Transactions.Local.dll +0 -0
- package/compiler/win-x64/System.Transactions.dll +0 -0
- package/compiler/win-x64/System.ValueTuple.dll +0 -0
- package/compiler/win-x64/System.Web.HttpUtility.dll +0 -0
- package/compiler/win-x64/System.Web.dll +0 -0
- package/compiler/win-x64/System.Windows.dll +0 -0
- package/compiler/win-x64/System.Xml.Linq.dll +0 -0
- package/compiler/win-x64/System.Xml.ReaderWriter.dll +0 -0
- package/compiler/win-x64/System.Xml.Serialization.dll +0 -0
- package/compiler/win-x64/System.Xml.XDocument.dll +0 -0
- package/compiler/win-x64/System.Xml.XPath.XDocument.dll +0 -0
- package/compiler/win-x64/System.Xml.XPath.dll +0 -0
- package/compiler/win-x64/System.Xml.XmlDocument.dll +0 -0
- package/compiler/win-x64/System.Xml.XmlSerializer.dll +0 -0
- package/compiler/win-x64/System.Xml.dll +0 -0
- package/compiler/win-x64/System.dll +0 -0
- package/compiler/win-x64/WindowsBase.dll +0 -0
- package/compiler/win-x64/clretwrc.dll +0 -0
- package/compiler/win-x64/clrgc.dll +0 -0
- package/compiler/win-x64/clrgcexp.dll +0 -0
- package/compiler/win-x64/clrjit.dll +0 -0
- package/compiler/win-x64/coreclr.dll +0 -0
- package/compiler/win-x64/createdump.exe +0 -0
- package/compiler/win-x64/cs/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/cs/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/de/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/de/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/es/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/es/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/fr/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/fr/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/hostfxr.dll +0 -0
- package/compiler/win-x64/hostpolicy.dll +0 -0
- package/compiler/win-x64/it/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/it/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/ja/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/ja/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/ko/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/ko/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/mscordaccore.dll +0 -0
- package/compiler/win-x64/mscordaccore_amd64_amd64_9.0.2026.41315.dll +0 -0
- package/compiler/win-x64/mscordbi.dll +0 -0
- package/compiler/win-x64/mscorlib.dll +0 -0
- package/compiler/win-x64/mscorrc.dll +0 -0
- package/compiler/win-x64/msquic.dll +0 -0
- package/compiler/win-x64/netstandard.dll +0 -0
- package/compiler/win-x64/pl/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/pl/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/pt-BR/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/pt-BR/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/ru/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/ru/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/tr/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/tr/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/zh-Hans/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/zh-Hans/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/zh-Hant/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/zh-Hant/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/compiler-runner.d.ts +2 -0
- package/dist/compiler-runner.js +95 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/preprocessor.d.ts +3 -0
- package/dist/preprocessor.js +45 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/dist/vite-plugin.d.ts +3 -0
- package/dist/vite-plugin.js +26 -0
- package/dist/watcher.d.ts +3 -0
- package/dist/watcher.js +12 -0
- 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
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -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
|
+
}
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
}
|
package/dist/watcher.js
ADDED
|
@@ -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.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
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
|
+
}
|