svelte-adapter-uws 0.2.2 → 0.2.4
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/index.js +43 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -87,24 +87,49 @@ export default function (opts = {}) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
if (handlerFile) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
90
|
+
// Bundle through esbuild to resolve SvelteKit aliases ($lib, $env, $app)
|
|
91
|
+
// and handle TypeScript. Without this, these imports survive into
|
|
92
|
+
// the Rollup step which doesn't know about SvelteKit virtual modules.
|
|
93
|
+
const esbuild = await import('esbuild');
|
|
94
|
+
const { loadEnv } = await import('vite');
|
|
95
|
+
const libDir = path.resolve(builder.config.kit.files?.lib || 'src/lib');
|
|
96
|
+
const publicPrefix = builder.config.kit.env?.publicPrefix ?? 'PUBLIC_';
|
|
97
|
+
const allEnv = loadEnv('production', process.cwd(), '');
|
|
98
|
+
const version = builder.config.kit.version?.name ?? '';
|
|
99
|
+
|
|
100
|
+
await esbuild.build({
|
|
101
|
+
entryPoints: [path.resolve(handlerFile)],
|
|
102
|
+
bundle: true,
|
|
103
|
+
format: 'esm',
|
|
104
|
+
platform: 'node',
|
|
105
|
+
outfile: `${tmp}/ws-handler.js`,
|
|
106
|
+
alias: { '$lib': libDir },
|
|
107
|
+
packages: 'external',
|
|
108
|
+
plugins: [{
|
|
109
|
+
name: 'sveltekit-virtual-modules',
|
|
110
|
+
setup(build) {
|
|
111
|
+
build.onResolve({ filter: /^\$(env|app)\// }, (args) => ({
|
|
112
|
+
path: args.path,
|
|
113
|
+
namespace: 'sveltekit'
|
|
114
|
+
}));
|
|
115
|
+
build.onLoad({ filter: /.*/, namespace: 'sveltekit' }, (args) => {
|
|
116
|
+
if (args.path === '$app/environment') {
|
|
117
|
+
return { contents: `export const dev = false;\nexport const building = false;\nexport const version = ${JSON.stringify(version)};` };
|
|
118
|
+
}
|
|
119
|
+
const isPublic = args.path.includes('/public');
|
|
120
|
+
const isStatic = args.path.includes('/static');
|
|
121
|
+
const entries = Object.entries(allEnv).filter(([k]) =>
|
|
122
|
+
isPublic ? k.startsWith(publicPrefix) : !k.startsWith(publicPrefix)
|
|
123
|
+
);
|
|
124
|
+
if (isStatic) {
|
|
125
|
+
return { contents: entries.map(([k, v]) => `export const ${k} = ${JSON.stringify(v)};`).join('\n') || 'export {};' };
|
|
126
|
+
}
|
|
127
|
+
// dynamic: read from process.env at runtime
|
|
128
|
+
return { contents: entries.map(([k]) => `export const ${k} = process.env[${JSON.stringify(k)}];`).join('\n') || 'export {};' };
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}]
|
|
132
|
+
});
|
|
108
133
|
builder.log.minor(`WebSocket handler: ${handlerFile}`);
|
|
109
134
|
} else {
|
|
110
135
|
// No handler found - use built-in default (subscribe/unsubscribe only)
|
package/package.json
CHANGED