@gimloader/external-svelte-plugin 1.0.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.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @gimloader/external-svelte-plugin
2
+
3
+ A plugin for the Gimloader [build tools](https://github.com/Gimloader/build) which makes scripts automatically use Gimloader's exposed Svelte exports, cutting down script size by 1-2k lines.
4
+
5
+ This plugin requires Svelte v5.43.0 exactly. Should Gimloader update its svelte version in the future, there will be a short grace period before the old version is removed.
6
+
7
+ ## Usage
8
+
9
+ Import the plugin and add it to the plugins array of your `gimloader.config.ts/js` file. This should be used alongside the [esbuild-svelte](https://github.com/EMH333/esbuild-svelte) plugin.
10
+
11
+ ```js
12
+ import svelte from "esbuild-svelte";
13
+ import { externalSvelte } from "@gimloader/external-svelte-plugin";
14
+
15
+ export default {
16
+ // ...
17
+ plugins: [
18
+ svelte({
19
+ compilerOptions: {
20
+ css: "injected"
21
+ }
22
+ }),
23
+ externalSvelte()
24
+ ]
25
+ }
26
+ ```
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@gimloader/external-svelte-plugin",
3
+ "description": "Allows bundled Gimloader plugins to use Gimloader's exposed svelte exports",
4
+ "version": "1.0.0",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc"
9
+ },
10
+ "peerDependencies": {
11
+ "esbuild": ">=0.17.0",
12
+ "svelte": "5.43.0",
13
+ "typescript": "^5"
14
+ },
15
+ "type": "module"
16
+ }
package/src/index.ts ADDED
@@ -0,0 +1,66 @@
1
+ import type { Plugin } from "esbuild";
2
+
3
+ const keysCache = new Map<string, string[]>();
4
+ const imports: Record<string, string> = {
5
+ "svelte": "Index",
6
+ "svelte/internal/client": "Client",
7
+ "svelte/animate": "Animate",
8
+ "svelte/attachments": "Attachments",
9
+ "svelte/easing": "Easing",
10
+ "svelte/events": "Events",
11
+ "svelte/motion": "Motion",
12
+ "svelte/reactivity/window": "WindowReactivity",
13
+ "svelte/reactivity": "Reactivity",
14
+ "svelte/store": "Store",
15
+ "svelte/transition": "Transition"
16
+ }
17
+
18
+ const reserved = ["if", "await"];
19
+ const svelteVersion = "5_43_0";
20
+
21
+ export function externalSvelte(): Plugin {
22
+ return {
23
+ name: "external-svelte",
24
+ setup(build) {
25
+ build.onResolve({ filter: /^svelte/ }, async (args) => {
26
+ if(imports[args.path]) {
27
+ return { path: args.path, namespace: "external-svelte" };
28
+ }
29
+
30
+ return { path: args.path, namespace: "external-svelte-ignore" }
31
+ });
32
+
33
+ build.onLoad({ filter: /.*/, namespace: "external-svelte" }, async (args) => {
34
+ const contents = await createContents(args.path);
35
+ return { contents, loader: "js" }
36
+ });
37
+
38
+ build.onLoad({ filter: /.*/, namespace: "external-svelte-ignore" }, () => {
39
+ return { contents: "", loader: "js" }
40
+ });
41
+ }
42
+ }
43
+ }
44
+
45
+ async function createContents(path: string){
46
+ const type = imports[path];
47
+ let keys = keysCache.get(path);
48
+ if(!keys) {
49
+ keys = Object.keys(await import(path));
50
+ keysCache.set(path, keys);
51
+ }
52
+
53
+ const normalKeys = keys.filter(k => !reserved.includes(k));
54
+ const reservedKeys = keys.filter(k => reserved.includes(k));
55
+
56
+ // Add normal exports
57
+ let contents = normalKeys.map(k => `const ${k} = /** @__PURE__ */ (() => GL.svelte_${svelteVersion}.${type}.${k})();`).join("\n")
58
+ + `export { ${normalKeys.join(", ")} };\n`;
59
+
60
+ // Add exports with a reserved keyword, if applicable
61
+ if(reservedKeys.length === 0) return contents;
62
+ contents += reservedKeys.map(k => `const ${k}_export = /** @__PURE__ */ (() => GL.svelte_${svelteVersion}.${type}.${k})();`).join("\n")
63
+ + `export { ${reservedKeys.map(k => `${k}_export as ${k}`)} };\n`;
64
+
65
+ return contents;
66
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": ["ESNext"],
5
+ "target": "ESNext",
6
+ "module": "Preserve",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+ "outDir": "dist",
11
+ "declaration": true,
12
+
13
+ // Bundler mode
14
+ "moduleResolution": "bundler",
15
+ "verbatimModuleSyntax": true,
16
+
17
+ // Best practices
18
+ "strict": true,
19
+ "skipLibCheck": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedIndexedAccess": true,
22
+ "noImplicitOverride": true,
23
+
24
+ // Some stricter flags (disabled by default)
25
+ "noUnusedLocals": false,
26
+ "noUnusedParameters": false,
27
+ "noPropertyAccessFromIndexSignature": false
28
+ }
29
+ }