@useavalon/avalon 0.1.3 → 0.1.5
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/package.json +1 -1
- package/src/vite-plugin/plugin.ts +48 -8
package/package.json
CHANGED
|
@@ -256,16 +256,26 @@ export async function avalon(config?: AvalonPluginConfig): Promise<PluginOption[
|
|
|
256
256
|
verbose: preResolvedConfig.verbose,
|
|
257
257
|
});
|
|
258
258
|
|
|
259
|
-
//
|
|
260
|
-
// In the monorepo www/ project
|
|
261
|
-
|
|
259
|
+
// Pre-resolve paths for standalone projects.
|
|
260
|
+
// In the monorepo www/ project these are handled by manual resolve.alias.
|
|
261
|
+
const require = createRequire(import.meta.url);
|
|
262
|
+
|
|
262
263
|
let clientMainResolved: string | null = null;
|
|
263
264
|
try {
|
|
264
|
-
const require = createRequire(import.meta.url);
|
|
265
265
|
const clientEntry = require.resolve("@useavalon/avalon/client");
|
|
266
266
|
clientMainResolved = join(dirname(clientEntry), "main.js");
|
|
267
267
|
} catch {
|
|
268
|
-
//
|
|
268
|
+
// Monorepo — www/ sets its own alias
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Resolve /@useavalon/*/client virtual imports used by main.js
|
|
272
|
+
const integrationClientMap: Record<string, string | null> = {};
|
|
273
|
+
for (const name of ['preact', 'react', 'vue', 'svelte', 'solid', 'lit', 'qwik']) {
|
|
274
|
+
try {
|
|
275
|
+
integrationClientMap[`/@useavalon/${name}/client`] = require.resolve(`@useavalon/${name}/client`);
|
|
276
|
+
} catch {
|
|
277
|
+
integrationClientMap[`/@useavalon/${name}/client`] = null;
|
|
278
|
+
}
|
|
269
279
|
}
|
|
270
280
|
|
|
271
281
|
// The main Avalon plugin
|
|
@@ -273,6 +283,22 @@ export async function avalon(config?: AvalonPluginConfig): Promise<PluginOption[
|
|
|
273
283
|
name: "avalon",
|
|
274
284
|
enforce: "pre",
|
|
275
285
|
|
|
286
|
+
config() {
|
|
287
|
+
// @useavalon packages ship raw .ts source. Mark them as noExternal so
|
|
288
|
+
// Vite processes them through the transform pipeline. Also exclude them
|
|
289
|
+
// from Vite's built-in OXC transform (which applies the project's jsx
|
|
290
|
+
// config and fails on plain .ts files). Our own transform hook below
|
|
291
|
+
// handles TS stripping for these files instead.
|
|
292
|
+
return {
|
|
293
|
+
ssr: {
|
|
294
|
+
noExternal: [/^@useavalon\//],
|
|
295
|
+
},
|
|
296
|
+
oxc: {
|
|
297
|
+
exclude: [/node_modules\/@useavalon\//],
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
},
|
|
301
|
+
|
|
276
302
|
configResolved(resolvedViteConfig: ResolvedConfig) {
|
|
277
303
|
viteConfig = resolvedViteConfig;
|
|
278
304
|
const isDev = resolvedViteConfig.command === "serve";
|
|
@@ -284,15 +310,29 @@ export async function avalon(config?: AvalonPluginConfig): Promise<PluginOption[
|
|
|
284
310
|
},
|
|
285
311
|
|
|
286
312
|
resolveId(id: string) {
|
|
287
|
-
// Resolve /src/client/main.js to the actual file inside @useavalon/avalon.
|
|
288
|
-
// The SSR renderer injects <script src="/src/client/main.js"> into HTML.
|
|
289
|
-
// Without this alias, standalone projects get a 404.
|
|
290
313
|
if (id === "/src/client/main.js" && clientMainResolved) {
|
|
291
314
|
return clientMainResolved;
|
|
292
315
|
}
|
|
316
|
+
if (id in integrationClientMap && integrationClientMap[id]) {
|
|
317
|
+
return integrationClientMap[id];
|
|
318
|
+
}
|
|
293
319
|
return null;
|
|
294
320
|
},
|
|
295
321
|
|
|
322
|
+
async transform(code: string, id: string) {
|
|
323
|
+
// Vite 8's OXC transform applies the project's jsx config to ALL .ts files,
|
|
324
|
+
// including those in node_modules/@useavalon. OXC rejects jsx options for
|
|
325
|
+
// plain .ts files. Strip TypeScript ourselves for @useavalon packages so
|
|
326
|
+
// Vite's built-in OXC doesn't need to touch them.
|
|
327
|
+
if (id.includes('node_modules/@useavalon/') && /\.tsx?$/.test(id)) {
|
|
328
|
+
const { transform: oxcTransform } = await import('oxc-transform');
|
|
329
|
+
const result = await oxcTransform(id, code, {
|
|
330
|
+
typescript: { onlyRemoveTypeImports: false },
|
|
331
|
+
});
|
|
332
|
+
return { code: result.code, map: result.map };
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
|
|
296
336
|
async buildStart() {
|
|
297
337
|
await runAutoDiscovery(resolvedConfig, viteConfig?.root, activeIntegrations);
|
|
298
338
|
runValidation(resolvedConfig, activeIntegrations);
|