1313 */
1414
1515import { createUnplugin } from "unplugin" ;
16- import path from "path" ;
1716import { transformComponent } from "./transform" ;
1817import type { LoaderConfig } from "../types" ;
1918import {
2019 startTranslationServer ,
2120 type TranslationServer ,
2221} from "../translation-server" ;
23- import { loadMetadata , saveMetadataWithEntries } from "../metadata/manager" ;
22+ import { saveMetadataWithEntries } from "../metadata/manager" ;
2423import { createLoaderConfig } from "../utils/config-factory" ;
2524import { logger } from "../utils/logger" ;
25+ import { getCacheDir } from "../utils/path-helpers" ;
2626
2727export interface LingoPluginOptions extends LoaderConfig {
2828 /**
@@ -77,6 +77,26 @@ export const lingoUnplugin = createUnplugin<LingoPluginOptions>(
7777 }
7878 } ,
7979
80+ resolveId ( id ) {
81+ if ( id === "@lingo.dev/_compiler/dev-config" ) {
82+ // Return a virtual module ID (prefix with \0 to mark it as virtual)
83+ return "\0virtual:lingo-dev-config" ;
84+ }
85+ return null ;
86+ } ,
87+
88+ load ( id ) {
89+ if ( id === "\0virtual:lingo-dev-config" ) {
90+ const serverUrl = globalServer ?. getUrl ( ) || "http://127.0.0.1:60000" ;
91+ const cacheDir = getCacheDir ( config ) ;
92+
93+ return `export const serverUrl = ${ JSON . stringify ( serverUrl ) } ;
94+ export const cacheDir = ${ JSON . stringify ( cacheDir ) } ;
95+ export const sourceLocale = ${ JSON . stringify ( config . sourceLocale ) } ;` ;
96+ }
97+ return null ;
98+ } ,
99+
80100 transform : {
81101 filter : {
82102 id : {
@@ -86,25 +106,15 @@ export const lingoUnplugin = createUnplugin<LingoPluginOptions>(
86106 } ,
87107 handler : async ( code , id ) => {
88108 try {
89- // Load current metadata
90- const metadata = await loadMetadata ( {
91- sourceRoot : config . sourceRoot ,
92- lingoDir : config . lingoDir ,
93- } ) ;
94-
95- logger . debug (
96- `Metadata loaded, entries:` ,
97- Object . keys ( metadata . entries ) . length ,
98- ) ;
99-
100109 // Transform the component
101110 const result = transformComponent ( {
102111 code,
103112 filePath : id ,
104113 config,
105- metadata,
106114 } ) ;
107115
116+ logger . debug ( `Transforming ${ result . code } ` ) ;
117+
108118 // If no transformation occurred, return original code
109119 if ( ! result . transformed ) {
110120 logger . debug ( `No transformation needed for ${ id } ` ) ;
0 commit comments