@inlang/paraglide-js 2.29.1 → 2.29.2

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.
@@ -108,7 +108,12 @@ export const compileProject = async (args) => {
108
108
  }
109
109
  }
110
110
  if (optionsWithDefaults.emitTsDeclarations) {
111
- const declarations = await emitTsDeclarations(output);
111
+ // Additional JavaScript can import project dependencies. Keep the
112
+ // compiler API's project-relative resolution: the native CLI stages
113
+ // files in an OS temporary directory, outside the project's packages.
114
+ const declarations = await emitTsDeclarations(output, {
115
+ allowNativeAlias: !Object.keys(optionsWithDefaults.additionalFiles ?? {}).some((fileName) => fileName.endsWith(".js")),
116
+ });
112
117
  Object.assign(output, declarations);
113
118
  }
114
119
  return output;
@@ -1 +1 @@
1
- {"version":3,"file":"compile-project.js","sourceRoot":"","sources":["../../src/compiler/compile-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAsB,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,aAAa,MAAM,sCAAsC,CAAC;AACtE,OAAO,KAAK,cAAc,MAAM,uCAAuC,CAAC;AACxE,OAAO,EACN,sBAAsB,GAEtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oCAAoC,EAAE,MAAM,uBAAuB,CAAC;AAE7E,MAAM,gBAAgB,GAAG;IACxB,gBAAgB,EAAE,aAAa;IAC/B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;YACnD,OAAO,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IACtC,CAAC,CAAC,CAC0B,CAAC;AAC/B,CAAC;AAED,MAAM,eAAe,GAAG;;;CAGvB,CAAC;AAEF,KAAK,UAAU,yBAAyB;IACvC,IAAI,CAAC;QACJ,IAAI,UAAU,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACR,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACrC,CAAC;AACF,CAAC;AAED,SAAS,6BAA6B,CACrC,eAAmD;IAEnD,IAAI,CAAC,eAAe,EAAE,MAAM,EAAE,CAAC;QAC9B,OAAO;IACR,CAAC;IAED,KAAK,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC;QAChE,IAAI,CAAC;YACJ,IAAI,UAAU,CAAC,aAAa,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,MAAM,IAAI,KAAK,CACd,2BAA2B,KAAK,YAAY,aAAa,CAAC,KAAK,iCAAiC,OAAO,EAAE,CACzG,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { compileBundle } from \"./compile-bundle.js\";\nimport { selectBundleNested, type InlangProject } from \"@inlang/sdk\";\nimport { lookup } from \"../services/lookup.js\";\nimport * as localeModules from \"./output-structure/locale-modules.js\";\nimport * as messageModules from \"./output-structure/message-modules.js\";\nimport {\n\tdefaultCompilerOptions,\n\ttype CompilerOptions,\n} from \"./compiler-options.js\";\nimport { createRuntimeFile } from \"./runtime/create-runtime.js\";\nimport { createServerFile } from \"./server/create-server-file.js\";\nimport { createRegistry } from \"./registry.js\";\nimport { emitTsDeclarations } from \"./emit-ts-declarations.js\";\nimport { createReadme } from \"./create-readme.js\";\nimport { perLocaleBuildStaticLocaleExpression } from \"./per-locale-build.js\";\n\nconst outputStructures = {\n\t\"locale-modules\": localeModules,\n\t\"message-modules\": messageModules,\n};\n\n/**\n * Takes an inlang project and compiles it into a set of files.\n *\n * Use this function for more programmatic control than `compile()`.\n * You can adjust the output structure and get the compiled files as a return value.\n *\n * @example\n * const output = await compileProject({ project, projectPath: \"./project.inlang\" });\n * await writeOutput('path', output, fs.promises);\n */\nexport const compileProject = async (args: {\n\tproject: InlangProject;\n\tprojectPath?: string;\n\tcompilerOptions?: Omit<CompilerOptions, \"fs\" | \"project\" | \"outdir\">;\n}): Promise<Record<string, string>> => {\n\tconst optionsWithDefaults = {\n\t\t...defaultCompilerOptions,\n\t\t...args.compilerOptions,\n\t};\n\tawait ensureURLPatternAvailable();\n\tvalidateRouteStrategyMatchers(optionsWithDefaults.routeStrategies);\n\n\tconst settings = await args.project.settings.get();\n\tconst bundles = await selectBundleNested(args.project.db).execute();\n\n\t//Maps each language to it's fallback\n\t//If there is no fallback, it will be undefined\n\tconst fallbackMap = getFallbackMap(settings.locales, settings.baseLocale);\n\n\tconst outputStructure = outputStructures[optionsWithDefaults.outputStructure];\n\n\tconst compiledBundles = bundles.map((bundle) =>\n\t\tcompileBundle({\n\t\t\tbundle,\n\t\t\tfallbackMap,\n\t\t\tinlineMessages: optionsWithDefaults.outputStructure === \"message-modules\",\n\t\t\tmessageReferenceExpression: outputStructure.messageReferenceExpression,\n\t\t\tsettings,\n\t\t\texperimentalMiddlewareLocaleSplitting:\n\t\t\t\toptionsWithDefaults.experimentalMiddlewareLocaleSplitting,\n\t\t\texperimentalStaticLocale: optionsWithDefaults.experimentalStaticLocale,\n\t\t})\n\t);\n\n\tconst output: Record<string, string> = {\n\t\t[\"runtime.js\"]: createRuntimeFile({\n\t\t\tbaseLocale: settings.baseLocale,\n\t\t\tlocales: settings.locales,\n\t\t\tcompilerOptions: optionsWithDefaults,\n\t\t}),\n\t\t[\"server.js\"]: createServerFile({\n\t\t\tcompiledBundles,\n\t\t\tcompilerOptions: optionsWithDefaults,\n\t\t}),\n\t\t[\"registry.js\"]: createRegistry(),\n\t\t[\"messages.js\"]: [\n\t\t\t\"export * from './messages/_index.js'\",\n\t\t\t\"// enabling auto-import by exposing all messages as m\",\n\t\t\t\"export * as m from './messages/_index.js'\",\n\t\t].join(\"\\n\"),\n\t};\n\n\t// generate the output modules\n\tObject.assign(\n\t\toutput,\n\t\toutputStructure.generateOutput(\n\t\t\tcompiledBundles,\n\t\t\tsettings,\n\t\t\tfallbackMap,\n\t\t\toptionsWithDefaults.experimentalMiddlewareLocaleSplitting\n\t\t)\n\t);\n\n\tif (optionsWithDefaults.emitGitIgnore) {\n\t\toutput[\".gitignore\"] = ignoreDirectory;\n\t}\n\n\tif (optionsWithDefaults.emitPrettierIgnore) {\n\t\toutput[\".prettierignore\"] = ignoreDirectory;\n\t}\n\n\tif (optionsWithDefaults.emitReadme) {\n\t\toutput[\"README.md\"] = createReadme({\n\t\t\tprojectPath: args.projectPath,\n\t\t\tgitignored: optionsWithDefaults.emitGitIgnore,\n\t\t});\n\t}\n\n\t// Declare the generated message modules side-effect-free so bundlers can drop\n\t// unused re-exports from the `m` barrel per entry, instead of bundling every\n\t// message used anywhere in the app into one shared chunk that every entry\n\t// downloads. Scoped to `messages/` so `runtime.js` (one level up, which has\n\t// real side effects) is unaffected. This also lets locale-specialized builds\n\t// discard the unselected locale modules before Rolldown creates source maps.\n\t//\n\t// `type: \"module\"` is required: this package.json creates a new module scope\n\t// for `messages/`, and a package.json without a `type` field defaults to\n\t// CommonJS in Node — even when the consuming project is `type: \"module\"`.\n\t// Without it, the generated ESM `.js` files in `messages/` would be treated\n\t// as CommonJS and fail to resolve.\n\t// See https://github.com/opral/paraglide-js/issues/668\n\tif (\n\t\toptionsWithDefaults.outputStructure === \"message-modules\" ||\n\t\toptionsWithDefaults.experimentalStaticLocale ===\n\t\t\tperLocaleBuildStaticLocaleExpression\n\t) {\n\t\toutput[\"messages/package.json\"] =\n\t\t\tJSON.stringify({ type: \"module\", sideEffects: false }, undefined, \"\\t\") +\n\t\t\t\"\\n\";\n\t}\n\n\tfor (const [filename, content] of Object.entries(\n\t\toptionsWithDefaults.additionalFiles ?? {}\n\t)) {\n\t\toutput[filename] = content;\n\t}\n\n\tfor (const [filename, content] of Object.entries(output)) {\n\t\tif (optionsWithDefaults.includeEslintDisableComment) {\n\t\t\tif (filename.endsWith(\".js\")) {\n\t\t\t\toutput[filename] = `/* eslint-disable */\\n${content}`;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (optionsWithDefaults.emitTsDeclarations) {\n\t\tconst declarations = await emitTsDeclarations(output);\n\t\tObject.assign(output, declarations);\n\t}\n\n\treturn output;\n};\n\nexport function getFallbackMap<T extends string>(\n\tlocales: T[],\n\tbaseLocale: NoInfer<T>\n): Record<T, T | undefined> {\n\treturn Object.fromEntries(\n\t\tlocales.map((lang) => {\n\t\t\tif (lang === baseLocale) return [lang, undefined];\n\t\t\tconst fallbackLanguage = lookup(lang, {\n\t\t\t\tlocales: locales.filter((l) => l !== lang),\n\t\t\t\tbaseLocale,\n\t\t\t});\n\n\t\t\tif (lang === fallbackLanguage) return [lang, undefined];\n\t\t\telse return [lang, fallbackLanguage];\n\t\t})\n\t) as Record<T, T | undefined>;\n}\n\nconst ignoreDirectory = `# ignore everything because the directory is auto-generated by inlang paraglide-js\n# for more info visit https://paraglidejs.com\n*\n`;\n\nasync function ensureURLPatternAvailable() {\n\ttry {\n\t\tnew URLPattern({ pathname: \"/:path(.*)?\" });\n\t} catch {\n\t\tawait import(\"urlpattern-polyfill\");\n\t}\n}\n\nfunction validateRouteStrategyMatchers(\n\trouteStrategies: CompilerOptions[\"routeStrategies\"]\n) {\n\tif (!routeStrategies?.length) {\n\t\treturn;\n\t}\n\n\tfor (const [index, routeStrategy] of routeStrategies.entries()) {\n\t\ttry {\n\t\t\tnew URLPattern(routeStrategy.match, \"https://example.com\");\n\t\t} catch (error) {\n\t\t\tconst details = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid routeStrategies[${index}].match \"${routeStrategy.match}\". URLPattern parsing failed: ${details}`\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"compile-project.js","sourceRoot":"","sources":["../../src/compiler/compile-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAsB,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,aAAa,MAAM,sCAAsC,CAAC;AACtE,OAAO,KAAK,cAAc,MAAM,uCAAuC,CAAC;AACxE,OAAO,EACN,sBAAsB,GAEtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oCAAoC,EAAE,MAAM,uBAAuB,CAAC;AAE7E,MAAM,gBAAgB,GAAG;IACxB,gBAAgB,EAAE,aAAa;IAC/B,iBAAiB,EAAE,cAAc;CACjC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,IAIpC,EAAmC,EAAE;IACrC,MAAM,mBAAmB,GAAG;QAC3B,GAAG,sBAAsB;QACzB,GAAG,IAAI,CAAC,eAAe;KACvB,CAAC;IACF,MAAM,yBAAyB,EAAE,CAAC;IAClC,6BAA6B,CAAC,mBA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AE,gBAAgB,CAAC,CAAC;IACtC,CAAC,CAAC,CAC0B,CAAC;AAC/B,CAAC;AAED,MAAM,eAAe,GAAG;;;CAGvB,CAAC;AAEF,KAAK,UAAU,yBAAyB;IACvC,IAAI,CAAC;QACJ,IAAI,UAAU,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACR,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACrC,CAAC;AACF,CAAC;AAED,SAAS,6BAA6B,CACrC,eAAmD;IAEnD,IAAI,CAAC,eAAe,EAAE,MAAM,EAAE,CAAC;QAC9B,OAAO;IACR,CAAC;IAED,KAAK,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC;QAChE,IAAI,CAAC;YACJ,IAAI,UAAU,CAAC,aAAa,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,MAAM,IAAI,KAAK,CACd,2BAA2B,KAAK,YAAY,aAAa,CAAC,KAAK,iCAAiC,OAAO,EAAE,CACzG,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { compileBundle } from \"./compile-bundle.js\";\nimport { selectBundleNested, type InlangProject } from \"@inlang/sdk\";\nimport { lookup } from \"../services/lookup.js\";\nimport * as localeModules from \"./output-structure/locale-modules.js\";\nimport * as messageModules from \"./output-structure/message-modules.js\";\nimport {\n\tdefaultCompilerOptions,\n\ttype CompilerOptions,\n} from \"./compiler-options.js\";\nimport { createRuntimeFile } from \"./runtime/create-runtime.js\";\nimport { createServerFile } from \"./server/create-server-file.js\";\nimport { createRegistry } from \"./registry.js\";\nimport { emitTsDeclarations } from \"./emit-ts-declarations.js\";\nimport { createReadme } from \"./create-readme.js\";\nimport { perLocaleBuildStaticLocaleExpression } from \"./per-locale-build.js\";\n\nconst outputStructures = {\n\t\"locale-modules\": localeModules,\n\t\"message-modules\": messageModules,\n};\n\n/**\n * Takes an inlang project and compiles it into a set of files.\n *\n * Use this function for more programmatic control than `compile()`.\n * You can adjust the output structure and get the compiled files as a return value.\n *\n * @example\n * const output = await compileProject({ project, projectPath: \"./project.inlang\" });\n * await writeOutput('path', output, fs.promises);\n */\nexport const compileProject = async (args: {\n\tproject: InlangProject;\n\tprojectPath?: string;\n\tcompilerOptions?: Omit<CompilerOptions, \"fs\" | \"project\" | \"outdir\">;\n}): Promise<Record<string, string>> => {\n\tconst optionsWithDefaults = {\n\t\t...defaultCompilerOptions,\n\t\t...args.compilerOptions,\n\t};\n\tawait ensureURLPatternAvailable();\n\tvalidateRouteStrategyMatchers(optionsWithDefaults.routeStrategies);\n\n\tconst settings = await args.project.settings.get();\n\tconst bundles = await selectBundleNested(args.project.db).execute();\n\n\t//Maps each language to it's fallback\n\t//If there is no fallback, it will be undefined\n\tconst fallbackMap = getFallbackMap(settings.locales, settings.baseLocale);\n\n\tconst outputStructure = outputStructures[optionsWithDefaults.outputStructure];\n\n\tconst compiledBundles = bundles.map((bundle) =>\n\t\tcompileBundle({\n\t\t\tbundle,\n\t\t\tfallbackMap,\n\t\t\tinlineMessages: optionsWithDefaults.outputStructure === \"message-modules\",\n\t\t\tmessageReferenceExpression: outputStructure.messageReferenceExpression,\n\t\t\tsettings,\n\t\t\texperimentalMiddlewareLocaleSplitting:\n\t\t\t\toptionsWithDefaults.experimentalMiddlewareLocaleSplitting,\n\t\t\texperimentalStaticLocale: optionsWithDefaults.experimentalStaticLocale,\n\t\t})\n\t);\n\n\tconst output: Record<string, string> = {\n\t\t[\"runtime.js\"]: createRuntimeFile({\n\t\t\tbaseLocale: settings.baseLocale,\n\t\t\tlocales: settings.locales,\n\t\t\tcompilerOptions: optionsWithDefaults,\n\t\t}),\n\t\t[\"server.js\"]: createServerFile({\n\t\t\tcompiledBundles,\n\t\t\tcompilerOptions: optionsWithDefaults,\n\t\t}),\n\t\t[\"registry.js\"]: createRegistry(),\n\t\t[\"messages.js\"]: [\n\t\t\t\"export * from './messages/_index.js'\",\n\t\t\t\"// enabling auto-import by exposing all messages as m\",\n\t\t\t\"export * as m from './messages/_index.js'\",\n\t\t].join(\"\\n\"),\n\t};\n\n\t// generate the output modules\n\tObject.assign(\n\t\toutput,\n\t\toutputStructure.generateOutput(\n\t\t\tcompiledBundles,\n\t\t\tsettings,\n\t\t\tfallbackMap,\n\t\t\toptionsWithDefaults.experimentalMiddlewareLocaleSplitting\n\t\t)\n\t);\n\n\tif (optionsWithDefaults.emitGitIgnore) {\n\t\toutput[\".gitignore\"] = ignoreDirectory;\n\t}\n\n\tif (optionsWithDefaults.emitPrettierIgnore) {\n\t\toutput[\".prettierignore\"] = ignoreDirectory;\n\t}\n\n\tif (optionsWithDefaults.emitReadme) {\n\t\toutput[\"README.md\"] = createReadme({\n\t\t\tprojectPath: args.projectPath,\n\t\t\tgitignored: optionsWithDefaults.emitGitIgnore,\n\t\t});\n\t}\n\n\t// Declare the generated message modules side-effect-free so bundlers can drop\n\t// unused re-exports from the `m` barrel per entry, instead of bundling every\n\t// message used anywhere in the app into one shared chunk that every entry\n\t// downloads. Scoped to `messages/` so `runtime.js` (one level up, which has\n\t// real side effects) is unaffected. This also lets locale-specialized builds\n\t// discard the unselected locale modules before Rolldown creates source maps.\n\t//\n\t// `type: \"module\"` is required: this package.json creates a new module scope\n\t// for `messages/`, and a package.json without a `type` field defaults to\n\t// CommonJS in Node — even when the consuming project is `type: \"module\"`.\n\t// Without it, the generated ESM `.js` files in `messages/` would be treated\n\t// as CommonJS and fail to resolve.\n\t// See https://github.com/opral/paraglide-js/issues/668\n\tif (\n\t\toptionsWithDefaults.outputStructure === \"message-modules\" ||\n\t\toptionsWithDefaults.experimentalStaticLocale ===\n\t\t\tperLocaleBuildStaticLocaleExpression\n\t) {\n\t\toutput[\"messages/package.json\"] =\n\t\t\tJSON.stringify({ type: \"module\", sideEffects: false }, undefined, \"\\t\") +\n\t\t\t\"\\n\";\n\t}\n\n\tfor (const [filename, content] of Object.entries(\n\t\toptionsWithDefaults.additionalFiles ?? {}\n\t)) {\n\t\toutput[filename] = content;\n\t}\n\n\tfor (const [filename, content] of Object.entries(output)) {\n\t\tif (optionsWithDefaults.includeEslintDisableComment) {\n\t\t\tif (filename.endsWith(\".js\")) {\n\t\t\t\toutput[filename] = `/* eslint-disable */\\n${content}`;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (optionsWithDefaults.emitTsDeclarations) {\n\t\t// Additional JavaScript can import project dependencies. Keep the\n\t\t// compiler API's project-relative resolution: the native CLI stages\n\t\t// files in an OS temporary directory, outside the project's packages.\n\t\tconst declarations = await emitTsDeclarations(output, {\n\t\t\tallowNativeAlias: !Object.keys(\n\t\t\t\toptionsWithDefaults.additionalFiles ?? {}\n\t\t\t).some((fileName) => fileName.endsWith(\".js\")),\n\t\t});\n\t\tObject.assign(output, declarations);\n\t}\n\n\treturn output;\n};\n\nexport function getFallbackMap<T extends string>(\n\tlocales: T[],\n\tbaseLocale: NoInfer<T>\n): Record<T, T | undefined> {\n\treturn Object.fromEntries(\n\t\tlocales.map((lang) => {\n\t\t\tif (lang === baseLocale) return [lang, undefined];\n\t\t\tconst fallbackLanguage = lookup(lang, {\n\t\t\t\tlocales: locales.filter((l) => l !== lang),\n\t\t\t\tbaseLocale,\n\t\t\t});\n\n\t\t\tif (lang === fallbackLanguage) return [lang, undefined];\n\t\t\telse return [lang, fallbackLanguage];\n\t\t})\n\t) as Record<T, T | undefined>;\n}\n\nconst ignoreDirectory = `# ignore everything because the directory is auto-generated by inlang paraglide-js\n# for more info visit https://paraglidejs.com\n*\n`;\n\nasync function ensureURLPatternAvailable() {\n\ttry {\n\t\tnew URLPattern({ pathname: \"/:path(.*)?\" });\n\t} catch {\n\t\tawait import(\"urlpattern-polyfill\");\n\t}\n}\n\nfunction validateRouteStrategyMatchers(\n\trouteStrategies: CompilerOptions[\"routeStrategies\"]\n) {\n\tif (!routeStrategies?.length) {\n\t\treturn;\n\t}\n\n\tfor (const [index, routeStrategy] of routeStrategies.entries()) {\n\t\ttry {\n\t\t\tnew URLPattern(routeStrategy.match, \"https://example.com\");\n\t\t} catch (error) {\n\t\t\tconst details = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid routeStrategies[${index}].match \"${routeStrategy.match}\". URLPattern parsing failed: ${details}`\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
@@ -317,8 +317,11 @@ export type CompilerOptions = {
317
317
  *
318
318
  * **Note:** With TypeScript 5/6 the declarations are generated in-process.
319
319
  * TypeScript 7+ no longer provides the compiler API, so its `tsc` CLI is
320
- * invoked in a child process instead; the emitted declarations are
321
- * semantically equivalent but differ cosmetically between the two.
320
+ * invoked in a child process instead, also when TypeScript 7 is installed
321
+ * beside TypeScript 5/6 as `@typescript/native`. The exported types are the
322
+ * same, but formatting, ordering and some JSDoc differ between the two.
323
+ * When `additionalFiles` contains JavaScript, TypeScript 5/6 keeps using
324
+ * the compiler API so imports resolve against the project's dependencies.
322
325
  *
323
326
  * @example
324
327
  * ```ts
@@ -1 +1 @@
1
- {"version":3,"file":"compiler-options.js","sourceRoot":"","sources":["../../src/compiler/compiler-options.ts"],"names":[],"mappings":"AAgCA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,eAAe,EAAE,iBAAiB;IAClC,aAAa,EAAE,IAAI;IACnB,2BAA2B,EAAE,IAAI;IACjC,kBAAkB,EAAE,IAAI;IACxB,UAAU,EAAE,IAAI;IAChB,kBAAkB,EAAE,KAAK;IACzB,WAAW,EAAE,IAAI;IACjB,wBAAwB,EAAE,KAAK;IAC/B,qCAAqC,EAAE,KAAK;IAC5C,eAAe,EAAE,kBAAkB;IACnC,QAAQ,EAAE,+BAA+B;IACzC,QAAQ,EAAE,CAAC,QAAQ,EAAE,gBAAgB,EAAE,YAAY,CAAC;IACpD,UAAU,EAAE,kBAAkB;IAC9B,YAAY,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG;IAChC,YAAY,EAAE,EAAE;CAC4B,CAAC","sourcesContent":["import type { Runtime } from \"./runtime/type.js\";\n\nexport type RouteStrategy =\n\t| {\n\t\t\t/**\n\t\t\t * URLPattern-compatible matcher.\n\t\t\t */\n\t\t\tmatch: string;\n\t\t\t/**\n\t\t\t * Strategy override for matching requests.\n\t\t\t */\n\t\t\tstrategy: Runtime[\"strategy\"];\n\t\t\t/**\n\t\t\t * Prevent mutually exclusive configuration (`exclude` + `strategy`).\n\t\t\t */\n\t\t\texclude?: never;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * URLPattern-compatible matcher.\n\t\t\t */\n\t\t\tmatch: string;\n\t\t\t/**\n\t\t\t * Exclude matching requests from i18n middleware behavior.\n\t\t\t */\n\t\t\texclude: true;\n\t\t\t/**\n\t\t\t * Prevent mutually exclusive configuration (`exclude` + `strategy`).\n\t\t\t */\n\t\t\tstrategy?: never;\n\t };\n\nexport const defaultCompilerOptions = {\n\toutputStructure: \"message-modules\",\n\temitGitIgnore: true,\n\tincludeEslintDisableComment: true,\n\temitPrettierIgnore: true,\n\temitReadme: true,\n\temitTsDeclarations: false,\n\tcleanOutdir: true,\n\tdisableAsyncLocalStorage: false,\n\texperimentalMiddlewareLocaleSplitting: false,\n\tlocalStorageKey: \"PARAGLIDE_LOCALE\",\n\tisServer: \"typeof window === 'undefined'\",\n\tstrategy: [\"cookie\", \"globalVariable\", \"baseLocale\"],\n\tcookieName: \"PARAGLIDE_LOCALE\",\n\tcookieMaxAge: 60 * 60 * 24 * 400,\n\tcookieDomain: \"\",\n} as const satisfies Partial<CompilerOptions>;\n\nexport type CompilerOptions = {\n\t/**\n\t * The path to the inlang project.\n\t *\n\t * @example\n\t * ```diff\n\t * await compile({\n\t * + project: \"./project.inlang\",\n\t * outdir: \"./src/paraglide\"\n\t * })\n\t * ```\n\t */\n\tproject: string;\n\t/**\n\t * The path to the output directory.\n\t *\n\t * @example\n\t * ```diff\n\t * await compile({\n\t * project: \"./project.inlang\",\n\t * + outdir: \"./src/paraglide\"\n\t * })\n\t * ```\n\t */\n\toutdir: string;\n\t/**\n\t * The strategy to use for getting the locale.\n\t *\n\t * The order of the strategy defines the precedence of matches.\n\t *\n\t * For example, in `['url', 'cookie', 'baseLocale']`, the locale will be\n\t * first tried to be detected in the url, then in a cookie, and finally\n\t * fallback to the base locale.\n\t *\n\t * The default ensures that the browser takes a cookie approach,\n\t * server-side takes the globalVariable (because cookie is unavailable),\n\t * whereas both fallback to the base locale if not available.\n\t *\n\t * Custom strategies with the pattern `custom-[A-Za-z0-9_-]+` are supported.\n\t *\n\t * @default [\"cookie\", \"globalVariable\", \"baseLocale\"]\n\t */\n\tstrategy?: Runtime[\"strategy\"];\n\t/**\n\t * Route-level strategy overrides.\n\t *\n\t * Routes are matched in declaration order. The first matching rule wins.\n\t * `match` uses URLPattern syntax.\n\t *\n\t * - `strategy`: Override locale resolution for the matched route.\n\t * - `exclude: true`: Skip i18n middleware behavior for the matched route.\n\t *\n\t * @example\n\t * ```ts\n\t * routeStrategies: [\n\t * { match: \"/dashboard/:path(.*)?\", strategy: [\"cookie\", \"baseLocale\"] },\n\t * { match: \"/api/:path(.*)?\", exclude: true }\n\t * ]\n\t * ```\n\t */\n\trouteStrategies?: RouteStrategy[];\n\t/**\n\t * Whether or not to use experimental middleware locale splitting.\n\t *\n\t * ⚠️ This feature is experimental and only works in SSR/SSG environment\n\t * without client-side routing. Do not rely on this feature for production.\n\t *\n\t * This feature is part of the exploration of per locale splitting. The\n\t * issue is ongoing and can be followed here [#88](https://github.com/opral/inlang-paraglide-js/issues/88).\n\t *\n\t * - The client bundle will tree-shake all messages (have close to 0kb JS).\n\t * - The server middleware will inject the used messages into the HTML.\n\t * - The client will re-trieve the messages from the injected HTML.\n\t *\n\t * @default false\n\t */\n\texperimentalMiddlewareLocaleSplitting?: boolean;\n\t/**\n\t * The name of the localStorage key to use for the localStorage strategy.\n\t *\n\t * @default 'PARAGLIDE_LOCALE'\n\t */\n\tlocalStorageKey?: string;\n\t/**\n\t * Tree-shaking flag if the code is running on the server.\n\t *\n\t * Dependent on the bundler, this flag must be adapted to\n\t * enable tree-shaking.\n\t *\n\t * @example\n\t * // vite\n\t * isServer: \"import.meta.env.SSR\"\n\t *\n\t * @default typeof window === \"undefined\"\n\t */\n\tisServer?: string;\n\t/**\n\t * Compile-time locale constant used for per-locale tree-shaking.\n\t *\n\t * This is experimental and opt-in. It should be a JavaScript expression\n\t * (not a quoted literal) that resolves to a locale or `undefined` at build time.\n\t * You can pass a string literal (e.g. `\"de\"`) for programmatic builds, or an\n\t * injected env/define expression for bundler-driven builds.\n\t *\n\t * High-level flow for per-locale builds:\n\t *\n\t * client request (/)\n\t * |\n\t * v\n\t * +----------------------+\n\t * | detect locale |\n\t * | (cookie/Accept-L) |\n\t * | pick build prefix |\n\t * +----------------------+\n\t * | if \"de\"\n\t * v\n\t * serve dist/de/... <----> serve dist/en/...\n\t * (HTML + assets) (HTML + assets)\n\t *\n\t * @see https://github.com/opral/paraglide-js/issues/88#issuecomment-3634754638\n\t *\n\t * @example\n\t * // Vite define\n\t * experimentalStaticLocale: \"typeof __PARAGLIDE_STATIC_LOCALE__ === 'undefined' ? undefined : __PARAGLIDE_STATIC_LOCALE__\"\n\t *\n\t * @example\n\t * // Programmatic compile (literal)\n\t * experimentalStaticLocale: '\"de\"'\n\t */\n\texperimentalStaticLocale?: string;\n\t/**\n\t * The name of the cookie to use for the cookie strategy.\n\t *\n\t * @default 'PARAGLIDE_LOCALE'\n\t */\n\tcookieName?: string;\n\t/**\n\t * The max-age in seconds of the cookie until it expires.\n\t *\n\t * @default 60 * 60 * 24 * 400\n\t */\n\tcookieMaxAge?: number;\n\t/**\n\t * The host to which the cookie will be sent.\n\t * If undefined or empty, the domain attribute is omitted from the cookie, scoping it to the exact current domain only (no subdomains).\n\t * If specified, the cookie will be available to the specified domain and all its subdomains.\n\t *\n\t * Use this when you need cookies to be shared across subdomains (e.g., between `app.example.com` and `api.example.com`).\n\t * The default behavior (no domain) ensures better compatibility with server-side cookies that don't specify a domain attribute.\n\t *\n\t * @example\n\t * ```ts\n\t * // Default: exact domain only (compatible with server-side cookies)\n\t * cookieDomain: undefined // Cookie: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000\"\n\t *\n\t * // Subdomain sharing: available across all subdomains\n\t * cookieDomain: \"example.com\" // Cookie: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000; domain=example.com\"\n\t * ```\n\t *\n\t * @default \"\" (no domain attribute, exact domain only)\n\t */\n\tcookieDomain?: string;\n\t/**\n\t * The `SameSite` attribute of the cookie.\n\t *\n\t * If undefined, the attribute is omitted and the browser applies its own default.\n\t * Set it when the cookie must match a policy, for example the one a server uses\n\t * when it writes the same cookie with `Set-Cookie`.\n\t *\n\t * `\"none\"` requires `cookieSecure` to be `true` or `\"auto\"` because browsers\n\t * reject `SameSite=None` cookies without the `Secure` attribute. With `\"auto\"`,\n\t * the cookie is still dropped on plain `http://` pages.\n\t *\n\t * @example\n\t * ```ts\n\t * cookieSameSite: \"lax\" // Cookie: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000; samesite=lax\"\n\t * ```\n\t *\n\t * @default undefined (no samesite attribute)\n\t */\n\tcookieSameSite?: \"lax\" | \"strict\" | \"none\";\n\t/**\n\t * Whether the cookie gets the `Secure` attribute.\n\t *\n\t * - `true` always adds it. Pages served over plain `http://` cannot set a\n\t * `Secure` cookie, except on `localhost`.\n\t * - `\"auto\"` adds it only when the page is served over `https:`, so the cookie\n\t * keeps working on plain `http://` hosts other than localhost, like a LAN IP\n\t * or an internal staging server. With `cookieSameSite: \"none\"`, the cookie\n\t * still needs `https:`.\n\t * - `false` never adds it.\n\t *\n\t * Server code that reads `cookieSecure` from the runtime has to resolve `\"auto\"`\n\t * itself, for example from the request protocol or `X-Forwarded-Proto`.\n\t *\n\t * @example\n\t * ```ts\n\t * cookieSecure: \"auto\" // on https: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000; secure\"\n\t * ```\n\t *\n\t * @default false\n\t */\n\tcookieSecure?: boolean | \"auto\";\n\t/**\n\t * The `additionalFiles` option is an array of paths to additional files that should be copied to the output directory.\n\t *\n\t * @example\n\t *\n\t * ```diff\n\t * await compile({\n\t * project: \"./project.inlang\",\n\t * outdir: \"./src/paraglide\",\n\t * additionalFiles: [\n\t * + \"my-file.js\": \"console.log('hello')\"\n\t * ]\n\t * })\n\t * ```\n\t *\n\t * The output will look like this:\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - my-file.js\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t */\n\tadditionalFiles?: Record<string, string>;\n\t/**\n\t * If `emitPrettierIgnore` is set to `true` a `.prettierignore` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - .prettierignore\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitPrettierIgnore?: boolean;\n\t/**\n\t * If `emitReadme` is set to `true` a `README.md` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * The README helps LLMs understand the compiled output.\n\t * See https://llmstxt.org/ for format guidelines.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - README.md\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitReadme?: boolean;\n\t/**\n\t * Emit `.d.ts` files for the generated output using the TypeScript compiler.\n\t *\n\t * Useful when `allowJs: true` cannot be set in your `tsconfig.json`\n\t * (e.g., due to project constraints or conflicting compiler options), or when\n\t * an editor language server caches stale JSDoc types for generated messages.\n\t *\n\t * Requires `typescript` to be resolvable in your toolchain.\n\t *\n\t * **Note:** Enabling this option reduces compiler speed because TypeScript\n\t * needs to generate declaration files for all output modules.\n\t *\n\t * **Note:** With TypeScript 5/6 the declarations are generated in-process.\n\t * TypeScript 7+ no longer provides the compiler API, so its `tsc` CLI is\n\t * invoked in a child process instead; the emitted declarations are\n\t * semantically equivalent but differ cosmetically between the two.\n\t *\n\t * @example\n\t * ```ts\n\t * await compile({\n\t * project: \"./project.inlang\",\n\t * outdir: \"./src/paraglide\",\n\t * emitTsDeclarations: true,\n\t * });\n\t * ```\n\t *\n\t * @default false\n\t */\n\temitTsDeclarations?: boolean;\n\t/**\n\t * https://paraglidejs.com/strategy#url\n\t */\n\turlPatterns?: Runtime[\"urlPatterns\"];\n\t/**\n\t * Controls trailing slash canonicalization for localized URLs.\n\t *\n\t * Canonicalization happens before URL pattern matching and after URL\n\t * localization. If omitted, Paraglide keeps its existing trailing slash\n\t * behavior.\n\t */\n\ttrailingSlash?: \"always\" | \"never\";\n\t/**\n\t * Whether to include an eslint-disable comment at the top of each .js file.\n\t *\n\t * @default true\n\t */\n\tincludeEslintDisableComment?: boolean;\n\t/**\n\t * Replaces AsyncLocalStorage with a synchronous implementation.\n\t *\n\t * Leave AsyncLocalStorage enabled by default. This option is a\n\t * compatibility fallback for runtimes that do not provide\n\t * AsyncLocalStorage or `node:async_hooks`.\n\t *\n\t * ⚠️ WARNING: Only use this option when your runtime also guarantees\n\t * request isolation. Disabling AsyncLocalStorage in multi-request\n\t * server environments risks cross-request pollution where state from\n\t * one request could leak into another concurrent request.\n\t */\n\tdisableAsyncLocalStorage?: boolean;\n\t/**\n\t * If `emitGitIgnore` is set to `true` a `.gitignore` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - .gitignore\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitGitIgnore?: boolean;\n\t/**\n\t * The `outputStructure` defines how modules are structured in the output.\n\t *\n\t * - `message-modules` - Each module is a message. This is the default.\n\t * - `locale-modules` - Each module is a locale.\n\t *\n\t * It is recommended to use `locale-modules` for development and `message-modules` for production.\n\t * Bundlers speed up the dev mode by bypassing bundling which can lead to many http requests\n\t * during the dev mode with `message-modules`. See https://github.com/opral/inlang-paraglide-js/issues/486.\n\t *\n\t * **`message-modules`**\n\t *\n\t * Messages have their own module which eases tree-shaking for bundlers.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - blue_elephant_tree/\n\t * + - index.js\n\t * + - en.js\n\t * + - fr.js\n\t * + - sky_phone_bottle/\n\t * + - index.js\n\t * + - en.js\n\t * + - fr.js\n\t * - ...\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * **`locale-modules`**\n\t *\n\t * Messages are bundled in a per locale module. Bundlers often struggle with tree-shaking this structure,\n\t * which can lead to more inefficient tree-shaking and larger bundle sizes compared to `message-modules`.\n\t *\n\t * The benefit are substantially fewer files which is needed in large projects.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - de.js\n\t * + - en.js\n\t * + - fr.js\n\t * - ...\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default \"message-modules\"\n\t */\n\toutputStructure?: \"locale-modules\" | \"message-modules\";\n\t/**\n\t * Whether to clean the output directory before writing the new files.\n\t *\n\t * @default true\n\t */\n\tcleanOutdir?: boolean;\n\n\t/**\n\t * The file system to use. Defaults to `await import('node:fs')`.\n\t *\n\t * Useful for testing the paraglide compiler by mocking the fs.\n\t */\n\tfs?: any;\n};\n"]}
1
+ {"version":3,"file":"compiler-options.js","sourceRoot":"","sources":["../../src/compiler/compiler-options.ts"],"names":[],"mappings":"AAgCA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,eAAe,EAAE,iBAAiB;IAClC,aAAa,EAAE,IAAI;IACnB,2BAA2B,EAAE,IAAI;IACjC,kBAAkB,EAAE,IAAI;IACxB,UAAU,EAAE,IAAI;IAChB,kBAAkB,EAAE,KAAK;IACzB,WAAW,EAAE,IAAI;IACjB,wBAAwB,EAAE,KAAK;IAC/B,qCAAqC,EAAE,KAAK;IAC5C,eAAe,EAAE,kBAAkB;IACnC,QAAQ,EAAE,+BAA+B;IACzC,QAAQ,EAAE,CAAC,QAAQ,EAAE,gBAAgB,EAAE,YAAY,CAAC;IACpD,UAAU,EAAE,kBAAkB;IAC9B,YAAY,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG;IAChC,YAAY,EAAE,EAAE;CAC4B,CAAC","sourcesContent":["import type { Runtime } from \"./runtime/type.js\";\n\nexport type RouteStrategy =\n\t| {\n\t\t\t/**\n\t\t\t * URLPattern-compatible matcher.\n\t\t\t */\n\t\t\tmatch: string;\n\t\t\t/**\n\t\t\t * Strategy override for matching requests.\n\t\t\t */\n\t\t\tstrategy: Runtime[\"strategy\"];\n\t\t\t/**\n\t\t\t * Prevent mutually exclusive configuration (`exclude` + `strategy`).\n\t\t\t */\n\t\t\texclude?: never;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * URLPattern-compatible matcher.\n\t\t\t */\n\t\t\tmatch: string;\n\t\t\t/**\n\t\t\t * Exclude matching requests from i18n middleware behavior.\n\t\t\t */\n\t\t\texclude: true;\n\t\t\t/**\n\t\t\t * Prevent mutually exclusive configuration (`exclude` + `strategy`).\n\t\t\t */\n\t\t\tstrategy?: never;\n\t };\n\nexport const defaultCompilerOptions = {\n\toutputStructure: \"message-modules\",\n\temitGitIgnore: true,\n\tincludeEslintDisableComment: true,\n\temitPrettierIgnore: true,\n\temitReadme: true,\n\temitTsDeclarations: false,\n\tcleanOutdir: true,\n\tdisableAsyncLocalStorage: false,\n\texperimentalMiddlewareLocaleSplitting: false,\n\tlocalStorageKey: \"PARAGLIDE_LOCALE\",\n\tisServer: \"typeof window === 'undefined'\",\n\tstrategy: [\"cookie\", \"globalVariable\", \"baseLocale\"],\n\tcookieName: \"PARAGLIDE_LOCALE\",\n\tcookieMaxAge: 60 * 60 * 24 * 400,\n\tcookieDomain: \"\",\n} as const satisfies Partial<CompilerOptions>;\n\nexport type CompilerOptions = {\n\t/**\n\t * The path to the inlang project.\n\t *\n\t * @example\n\t * ```diff\n\t * await compile({\n\t * + project: \"./project.inlang\",\n\t * outdir: \"./src/paraglide\"\n\t * })\n\t * ```\n\t */\n\tproject: string;\n\t/**\n\t * The path to the output directory.\n\t *\n\t * @example\n\t * ```diff\n\t * await compile({\n\t * project: \"./project.inlang\",\n\t * + outdir: \"./src/paraglide\"\n\t * })\n\t * ```\n\t */\n\toutdir: string;\n\t/**\n\t * The strategy to use for getting the locale.\n\t *\n\t * The order of the strategy defines the precedence of matches.\n\t *\n\t * For example, in `['url', 'cookie', 'baseLocale']`, the locale will be\n\t * first tried to be detected in the url, then in a cookie, and finally\n\t * fallback to the base locale.\n\t *\n\t * The default ensures that the browser takes a cookie approach,\n\t * server-side takes the globalVariable (because cookie is unavailable),\n\t * whereas both fallback to the base locale if not available.\n\t *\n\t * Custom strategies with the pattern `custom-[A-Za-z0-9_-]+` are supported.\n\t *\n\t * @default [\"cookie\", \"globalVariable\", \"baseLocale\"]\n\t */\n\tstrategy?: Runtime[\"strategy\"];\n\t/**\n\t * Route-level strategy overrides.\n\t *\n\t * Routes are matched in declaration order. The first matching rule wins.\n\t * `match` uses URLPattern syntax.\n\t *\n\t * - `strategy`: Override locale resolution for the matched route.\n\t * - `exclude: true`: Skip i18n middleware behavior for the matched route.\n\t *\n\t * @example\n\t * ```ts\n\t * routeStrategies: [\n\t * { match: \"/dashboard/:path(.*)?\", strategy: [\"cookie\", \"baseLocale\"] },\n\t * { match: \"/api/:path(.*)?\", exclude: true }\n\t * ]\n\t * ```\n\t */\n\trouteStrategies?: RouteStrategy[];\n\t/**\n\t * Whether or not to use experimental middleware locale splitting.\n\t *\n\t * ⚠️ This feature is experimental and only works in SSR/SSG environment\n\t * without client-side routing. Do not rely on this feature for production.\n\t *\n\t * This feature is part of the exploration of per locale splitting. The\n\t * issue is ongoing and can be followed here [#88](https://github.com/opral/inlang-paraglide-js/issues/88).\n\t *\n\t * - The client bundle will tree-shake all messages (have close to 0kb JS).\n\t * - The server middleware will inject the used messages into the HTML.\n\t * - The client will re-trieve the messages from the injected HTML.\n\t *\n\t * @default false\n\t */\n\texperimentalMiddlewareLocaleSplitting?: boolean;\n\t/**\n\t * The name of the localStorage key to use for the localStorage strategy.\n\t *\n\t * @default 'PARAGLIDE_LOCALE'\n\t */\n\tlocalStorageKey?: string;\n\t/**\n\t * Tree-shaking flag if the code is running on the server.\n\t *\n\t * Dependent on the bundler, this flag must be adapted to\n\t * enable tree-shaking.\n\t *\n\t * @example\n\t * // vite\n\t * isServer: \"import.meta.env.SSR\"\n\t *\n\t * @default typeof window === \"undefined\"\n\t */\n\tisServer?: string;\n\t/**\n\t * Compile-time locale constant used for per-locale tree-shaking.\n\t *\n\t * This is experimental and opt-in. It should be a JavaScript expression\n\t * (not a quoted literal) that resolves to a locale or `undefined` at build time.\n\t * You can pass a string literal (e.g. `\"de\"`) for programmatic builds, or an\n\t * injected env/define expression for bundler-driven builds.\n\t *\n\t * High-level flow for per-locale builds:\n\t *\n\t * client request (/)\n\t * |\n\t * v\n\t * +----------------------+\n\t * | detect locale |\n\t * | (cookie/Accept-L) |\n\t * | pick build prefix |\n\t * +----------------------+\n\t * | if \"de\"\n\t * v\n\t * serve dist/de/... <----> serve dist/en/...\n\t * (HTML + assets) (HTML + assets)\n\t *\n\t * @see https://github.com/opral/paraglide-js/issues/88#issuecomment-3634754638\n\t *\n\t * @example\n\t * // Vite define\n\t * experimentalStaticLocale: \"typeof __PARAGLIDE_STATIC_LOCALE__ === 'undefined' ? undefined : __PARAGLIDE_STATIC_LOCALE__\"\n\t *\n\t * @example\n\t * // Programmatic compile (literal)\n\t * experimentalStaticLocale: '\"de\"'\n\t */\n\texperimentalStaticLocale?: string;\n\t/**\n\t * The name of the cookie to use for the cookie strategy.\n\t *\n\t * @default 'PARAGLIDE_LOCALE'\n\t */\n\tcookieName?: string;\n\t/**\n\t * The max-age in seconds of the cookie until it expires.\n\t *\n\t * @default 60 * 60 * 24 * 400\n\t */\n\tcookieMaxAge?: number;\n\t/**\n\t * The host to which the cookie will be sent.\n\t * If undefined or empty, the domain attribute is omitted from the cookie, scoping it to the exact current domain only (no subdomains).\n\t * If specified, the cookie will be available to the specified domain and all its subdomains.\n\t *\n\t * Use this when you need cookies to be shared across subdomains (e.g., between `app.example.com` and `api.example.com`).\n\t * The default behavior (no domain) ensures better compatibility with server-side cookies that don't specify a domain attribute.\n\t *\n\t * @example\n\t * ```ts\n\t * // Default: exact domain only (compatible with server-side cookies)\n\t * cookieDomain: undefined // Cookie: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000\"\n\t *\n\t * // Subdomain sharing: available across all subdomains\n\t * cookieDomain: \"example.com\" // Cookie: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000; domain=example.com\"\n\t * ```\n\t *\n\t * @default \"\" (no domain attribute, exact domain only)\n\t */\n\tcookieDomain?: string;\n\t/**\n\t * The `SameSite` attribute of the cookie.\n\t *\n\t * If undefined, the attribute is omitted and the browser applies its own default.\n\t * Set it when the cookie must match a policy, for example the one a server uses\n\t * when it writes the same cookie with `Set-Cookie`.\n\t *\n\t * `\"none\"` requires `cookieSecure` to be `true` or `\"auto\"` because browsers\n\t * reject `SameSite=None` cookies without the `Secure` attribute. With `\"auto\"`,\n\t * the cookie is still dropped on plain `http://` pages.\n\t *\n\t * @example\n\t * ```ts\n\t * cookieSameSite: \"lax\" // Cookie: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000; samesite=lax\"\n\t * ```\n\t *\n\t * @default undefined (no samesite attribute)\n\t */\n\tcookieSameSite?: \"lax\" | \"strict\" | \"none\";\n\t/**\n\t * Whether the cookie gets the `Secure` attribute.\n\t *\n\t * - `true` always adds it. Pages served over plain `http://` cannot set a\n\t * `Secure` cookie, except on `localhost`.\n\t * - `\"auto\"` adds it only when the page is served over `https:`, so the cookie\n\t * keeps working on plain `http://` hosts other than localhost, like a LAN IP\n\t * or an internal staging server. With `cookieSameSite: \"none\"`, the cookie\n\t * still needs `https:`.\n\t * - `false` never adds it.\n\t *\n\t * Server code that reads `cookieSecure` from the runtime has to resolve `\"auto\"`\n\t * itself, for example from the request protocol or `X-Forwarded-Proto`.\n\t *\n\t * @example\n\t * ```ts\n\t * cookieSecure: \"auto\" // on https: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000; secure\"\n\t * ```\n\t *\n\t * @default false\n\t */\n\tcookieSecure?: boolean | \"auto\";\n\t/**\n\t * The `additionalFiles` option is an array of paths to additional files that should be copied to the output directory.\n\t *\n\t * @example\n\t *\n\t * ```diff\n\t * await compile({\n\t * project: \"./project.inlang\",\n\t * outdir: \"./src/paraglide\",\n\t * additionalFiles: [\n\t * + \"my-file.js\": \"console.log('hello')\"\n\t * ]\n\t * })\n\t * ```\n\t *\n\t * The output will look like this:\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - my-file.js\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t */\n\tadditionalFiles?: Record<string, string>;\n\t/**\n\t * If `emitPrettierIgnore` is set to `true` a `.prettierignore` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - .prettierignore\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitPrettierIgnore?: boolean;\n\t/**\n\t * If `emitReadme` is set to `true` a `README.md` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * The README helps LLMs understand the compiled output.\n\t * See https://llmstxt.org/ for format guidelines.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - README.md\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitReadme?: boolean;\n\t/**\n\t * Emit `.d.ts` files for the generated output using the TypeScript compiler.\n\t *\n\t * Useful when `allowJs: true` cannot be set in your `tsconfig.json`\n\t * (e.g., due to project constraints or conflicting compiler options), or when\n\t * an editor language server caches stale JSDoc types for generated messages.\n\t *\n\t * Requires `typescript` to be resolvable in your toolchain.\n\t *\n\t * **Note:** Enabling this option reduces compiler speed because TypeScript\n\t * needs to generate declaration files for all output modules.\n\t *\n\t * **Note:** With TypeScript 5/6 the declarations are generated in-process.\n\t * TypeScript 7+ no longer provides the compiler API, so its `tsc` CLI is\n\t * invoked in a child process instead, also when TypeScript 7 is installed\n\t * beside TypeScript 5/6 as `@typescript/native`. The exported types are the\n\t * same, but formatting, ordering and some JSDoc differ between the two.\n\t * When `additionalFiles` contains JavaScript, TypeScript 5/6 keeps using\n\t * the compiler API so imports resolve against the project's dependencies.\n\t *\n\t * @example\n\t * ```ts\n\t * await compile({\n\t * project: \"./project.inlang\",\n\t * outdir: \"./src/paraglide\",\n\t * emitTsDeclarations: true,\n\t * });\n\t * ```\n\t *\n\t * @default false\n\t */\n\temitTsDeclarations?: boolean;\n\t/**\n\t * https://paraglidejs.com/strategy#url\n\t */\n\turlPatterns?: Runtime[\"urlPatterns\"];\n\t/**\n\t * Controls trailing slash canonicalization for localized URLs.\n\t *\n\t * Canonicalization happens before URL pattern matching and after URL\n\t * localization. If omitted, Paraglide keeps its existing trailing slash\n\t * behavior.\n\t */\n\ttrailingSlash?: \"always\" | \"never\";\n\t/**\n\t * Whether to include an eslint-disable comment at the top of each .js file.\n\t *\n\t * @default true\n\t */\n\tincludeEslintDisableComment?: boolean;\n\t/**\n\t * Replaces AsyncLocalStorage with a synchronous implementation.\n\t *\n\t * Leave AsyncLocalStorage enabled by default. This option is a\n\t * compatibility fallback for runtimes that do not provide\n\t * AsyncLocalStorage or `node:async_hooks`.\n\t *\n\t * ⚠️ WARNING: Only use this option when your runtime also guarantees\n\t * request isolation. Disabling AsyncLocalStorage in multi-request\n\t * server environments risks cross-request pollution where state from\n\t * one request could leak into another concurrent request.\n\t */\n\tdisableAsyncLocalStorage?: boolean;\n\t/**\n\t * If `emitGitIgnore` is set to `true` a `.gitignore` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - .gitignore\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitGitIgnore?: boolean;\n\t/**\n\t * The `outputStructure` defines how modules are structured in the output.\n\t *\n\t * - `message-modules` - Each module is a message. This is the default.\n\t * - `locale-modules` - Each module is a locale.\n\t *\n\t * It is recommended to use `locale-modules` for development and `message-modules` for production.\n\t * Bundlers speed up the dev mode by bypassing bundling which can lead to many http requests\n\t * during the dev mode with `message-modules`. See https://github.com/opral/inlang-paraglide-js/issues/486.\n\t *\n\t * **`message-modules`**\n\t *\n\t * Messages have their own module which eases tree-shaking for bundlers.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - blue_elephant_tree/\n\t * + - index.js\n\t * + - en.js\n\t * + - fr.js\n\t * + - sky_phone_bottle/\n\t * + - index.js\n\t * + - en.js\n\t * + - fr.js\n\t * - ...\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * **`locale-modules`**\n\t *\n\t * Messages are bundled in a per locale module. Bundlers often struggle with tree-shaking this structure,\n\t * which can lead to more inefficient tree-shaking and larger bundle sizes compared to `message-modules`.\n\t *\n\t * The benefit are substantially fewer files which is needed in large projects.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - de.js\n\t * + - en.js\n\t * + - fr.js\n\t * - ...\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default \"message-modules\"\n\t */\n\toutputStructure?: \"locale-modules\" | \"message-modules\";\n\t/**\n\t * Whether to clean the output directory before writing the new files.\n\t *\n\t * @default true\n\t */\n\tcleanOutdir?: boolean;\n\n\t/**\n\t * The file system to use. Defaults to `await import('node:fs')`.\n\t *\n\t * Useful for testing the paraglide compiler by mocking the fs.\n\t */\n\tfs?: any;\n};\n"]}
@@ -2,10 +2,13 @@
2
2
  * Generates `.d.ts` files for the compiled Paraglide output using the TypeScript compiler.
3
3
  *
4
4
  * @param output - The generated compiler output keyed by relative file path.
5
+ * @param options - Whether the optional native alias may replace the compiler API.
5
6
  * @returns The generated declaration files keyed by relative path.
6
7
  *
7
8
  * @example
8
9
  * const declarations = await emitTsDeclarations(output);
9
10
  * // Merge them into the compiler output before writing to disk
10
11
  */
11
- export declare function emitTsDeclarations(output: Record<string, string>): Promise<Record<string, string>>;
12
+ export declare function emitTsDeclarations(output: Record<string, string>, options?: {
13
+ allowNativeAlias?: boolean;
14
+ }): Promise<Record<string, string>>;
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
3
3
  import os from "node:os";
4
4
  import { execFile } from "node:child_process";
5
5
  import { promisify } from "node:util";
6
- import { resolveTscJsPath } from "./resolve-tsc-js-path.js";
6
+ import { resolveNativeTscJsPath, resolveTscJsPath, } from "./resolve-tsc-js-path.js";
7
7
  const execFileAsync = promisify(execFile);
8
8
  const missingTypeScriptMessage = `Paraglide's "emitTsDeclarations" option requires the "typescript" package.
9
9
 
@@ -15,13 +15,14 @@ TypeScript appears to be installed, but failed to load. See the error cause for
15
15
  * Generates `.d.ts` files for the compiled Paraglide output using the TypeScript compiler.
16
16
  *
17
17
  * @param output - The generated compiler output keyed by relative file path.
18
+ * @param options - Whether the optional native alias may replace the compiler API.
18
19
  * @returns The generated declaration files keyed by relative path.
19
20
  *
20
21
  * @example
21
22
  * const declarations = await emitTsDeclarations(output);
22
23
  * // Merge them into the compiler output before writing to disk
23
24
  */
24
- export async function emitTsDeclarations(output) {
25
+ export async function emitTsDeclarations(output, options = {}) {
25
26
  const ts = await importTypeScript();
26
27
  const jsEntries = Object.entries(output).filter(([fileName]) => fileName.endsWith(".js"));
27
28
  if (jsEntries.length === 0) {
@@ -32,7 +33,17 @@ export async function emitTsDeclarations(output) {
32
33
  // https://github.com/opral/paraglide-js/issues/711
33
34
  const compilerApi = resolveCompilerApi(ts);
34
35
  if (compilerApi === undefined) {
35
- return emitWithTscCli(jsEntries);
36
+ // resolved before spawning so a missing tsc entry point surfaces its own
37
+ // pointed error instead of the generic "no declaration files" one
38
+ return emitWithTscCli(jsEntries, resolveTscJsPath());
39
+ }
40
+ // TypeScript 7 installed beside TypeScript 5/6, as svelte-check's `--tsgo`
41
+ // mode needs, emits declarations much faster than the compiler API.
42
+ if (options.allowNativeAlias !== false) {
43
+ const nativeTscJsPath = resolveNativeTscJsPath();
44
+ if (nativeTscJsPath !== undefined) {
45
+ return emitWithTscCli(jsEntries, nativeTscJsPath);
46
+ }
36
47
  }
37
48
  return emitWithCompilerApi(compilerApi, jsEntries);
38
49
  }
@@ -147,17 +158,16 @@ async function emitWithCompilerApi(ts, jsEntries) {
147
158
  });
148
159
  return declarations;
149
160
  }
150
- const failedToEmitWithTscMessage = `Paraglide's "emitTsDeclarations" option failed to generate declaration files with the installed TypeScript version.
161
+ const failedToEmitWithTscMessage = `Paraglide's "emitTsDeclarations" option failed to generate declaration files with TypeScript 7's "tsc" CLI, which did not produce a declaration file for every compiled file.
151
162
 
152
- TypeScript 7+ no longer provides the in-process compiler API, so Paraglide invokes its "tsc" CLI instead — which did not produce a declaration file for every compiled file. As a workaround, install TypeScript 5 or 6, or disable "emitTsDeclarations".`;
163
+ Paraglide uses that CLI when the "typescript" package is version 7+, or when TypeScript 7 is installed as "@typescript/native". As a workaround, use TypeScript 5 or 6 without "@typescript/native", or disable "emitTsDeclarations".`;
153
164
  /**
154
- * Emits declarations by invoking the `tsc` CLI of the installed TypeScript
155
- * package (TypeScript 7+, where the in-process compiler API is unavailable).
165
+ * Emits declarations by invoking the given TypeScript 7+ `tsc` CLI.
156
166
  *
157
167
  * The compiled output is written to a temporary directory because the
158
168
  * Go-based compiler cannot read from a virtual filesystem.
159
169
  */
160
- async function emitWithTscCli(jsEntries) {
170
+ async function emitWithTscCli(jsEntries, tscJsPath) {
161
171
  // entries escaping the output root cannot be declared safely; the
162
172
  // compiler-API path silently drops them too (see the writeFile hook).
163
173
  // Checked against both separator conventions because path.join interprets
@@ -167,9 +177,6 @@ async function emitWithTscCli(jsEntries) {
167
177
  return (normalized.startsWith("..") === false &&
168
178
  platformPath.isAbsolute(normalized) === false);
169
179
  }));
170
- // resolved before spawning so a missing tsc entry point surfaces its own
171
- // pointed error instead of the generic "no declaration files" one
172
- const tscJsPath = resolveTscJsPath();
173
180
  const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "paraglide-dts-"));
174
181
  try {
175
182
  const srcDir = path.join(tempDir, "src");
@@ -1 +1 @@
1
- {"version":3,"file":"emit-ts-declarations.js","sourceRoot":"","sources":["../../src/compiler/emit-ts-declarations.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAI1C,MAAM,wBAAwB,GAAG;;qEAEoC,CAAC;AAEtE,MAAM,6BAA6B,GAAG;;yFAEmD,CAAC;AAE1F;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,MAA8B;IAE9B,MAAM,EAAE,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAEpC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,CAC9D,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CACxB,CAAC;IAEF,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,uEAAuE;IACvE,qEAAqE;IACrE,mDAAmD;IACnD,MAAM,WAAW,GAAG,kBAA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c,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC,CAAC;QAEF,OAAO,CAAC,kBAAkB,EAAE,EAAE;YAC7B,IAAI,UAAU,IAAI,kBAAkB,EAAE,CAAC;gBACtC,OAAO,eAAe,CAAC,kBAAkB,CAAC,CAAC;YAC5C,CAAC;YACD,OAAO,kBAAkB,CAAC;QAC3B,CAAC,CAAC;IACH,CAAC,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,IAA2C;IACxE,OAAO,IAAI,CAAC,IAAI,CAAC;AAClB,CAAC;AAED,KAAK,UAAU,gBAAgB;IAC9B,IAAI,CAAC;QACJ,OAAO,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,+BAA+B,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC3C,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,CAAC;AACF,CAAC;AAED,SAAS,+BAA+B,CAAC,KAAc;IACtD,IAAI,KAAK,YAAY,KAAK,KAAK,KAAK,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACd,CAAC;IACD,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;QAC9D,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,kCAAkC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport { execFile } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport { resolveTscJsPath } from \"./resolve-tsc-js-path.js\";\n\nconst execFileAsync = promisify(execFile);\n\ntype TypeScript = typeof import(\"typescript\");\n\nconst missingTypeScriptMessage = `Paraglide's \"emitTsDeclarations\" option requires the \"typescript\" package.\n\nInstall TypeScript in your project, or disable \"emitTsDeclarations\".`;\n\nconst failedToLoadTypeScriptMessage = `Paraglide's \"emitTsDeclarations\" option requires the \"typescript\" package.\n\nTypeScript appears to be installed, but failed to load. See the error cause for details.`;\n\n/**\n * Generates `.d.ts` files for the compiled Paraglide output using the TypeScript compiler.\n *\n * @param output - The generated compiler output keyed by relative file path.\n * @returns The generated declaration files keyed by relative path.\n *\n * @example\n * const declarations = await emitTsDeclarations(output);\n * // Merge them into the compiler output before writing to disk\n */\nexport async function emitTsDeclarations(\n\toutput: Record<string, string>\n): Promise<Record<string, string>> {\n\tconst ts = await importTypeScript();\n\n\tconst jsEntries = Object.entries(output).filter(([fileName]) =>\n\t\tfileName.endsWith(\".js\")\n\t);\n\n\tif (jsEntries.length === 0) {\n\t\treturn {};\n\t}\n\n\t// TypeScript 7+ (the Go-based compiler) no longer ships the in-process\n\t// compiler API — its main entry point only exports version metadata.\n\t// https://github.com/opral/paraglide-js/issues/711\n\tconst compilerApi = resolveCompilerApi(ts);\n\tif (compilerApi === undefined) {\n\t\treturn emitWithTscCli(jsEntries);\n\t}\n\n\treturn emitWithCompilerApi(compilerApi, jsEntries);\n}\n\n/**\n * Returns the in-process compiler API (TypeScript 5/6), or `undefined` when\n * the installed TypeScript does not provide one (TypeScript 7+).\n *\n * Unwraps default-only interop shapes (`{ default: ts }`) that bundlers and\n * CJS interop can produce. Without the unwrap, TypeScript 5/6 would be\n * misrouted to the CLI path, whose TypeScript 5 declaration emitter produces\n * syntactically invalid quoted export aliases.\n */\nfunction resolveCompilerApi(ts: TypeScript): TypeScript | undefined {\n\tif (typeof ts.createProgram === \"function\") {\n\t\treturn ts;\n\t}\n\tconst defaultExport = (ts as { default?: TypeScript }).default;\n\tif (defaultExport && typeof defaultExport.createProgram === \"function\") {\n\t\treturn defaultExport;\n\t}\n\treturn undefined;\n}\n\n/**\n * Emits declarations with the in-process TypeScript compiler API (TypeScript 5/6).\n */\nasync function emitWithCompilerApi(\n\tts: TypeScript,\n\tjsEntries: [string, string][]\n): Promise<Record<string, string>> {\n\tconst virtualRoot = path.join(process.cwd(), \"__paraglide_virtual_output\");\n\tconst normalizeFileName = (fileName: string) =>\n\t\tpath.normalize(\n\t\t\tpath.isAbsolute(fileName) ? fileName : path.join(virtualRoot, fileName)\n\t\t);\n\n\tconst files = new Map(\n\t\tjsEntries.map(([fileName, content]) => [\n\t\t\tnormalizeFileName(fileName),\n\t\t\tcontent,\n\t\t])\n\t);\n\tconst quotedExportAliases = collectQuotedExportAliases(ts, files);\n\n\tconst virtualDirectories = new Set(\n\t\tArray.from(files.keys()).flatMap((filePath) => {\n\t\t\tconst directories: string[] = [];\n\t\t\tlet current = path.dirname(filePath);\n\t\t\twhile (current.startsWith(virtualRoot) && current !== virtualRoot) {\n\t\t\t\tdirectories.push(current);\n\t\t\t\tconst parent = path.dirname(current);\n\t\t\t\tif (parent === current) break;\n\t\t\t\tcurrent = parent;\n\t\t\t}\n\t\t\treturn directories;\n\t\t})\n\t);\n\t// Ensure the virtual root itself is treated as existing\n\tvirtualDirectories.add(virtualRoot);\n\n\tconst compilerOptions: import(\"typescript\").CompilerOptions = {\n\t\tallowJs: true,\n\t\tcheckJs: true,\n\t\tdeclaration: true,\n\t\temitDeclarationOnly: true,\n\t\tisolatedDeclarations: true,\n\t\tesModuleInterop: true,\n\t\tlib: [\"ESNext\", \"DOM\"],\n\t\tmodule: ts.ModuleKind.ESNext,\n\t\tmoduleResolution: ts.ModuleResolutionKind.Bundler,\n\t\tnoEmitOnError: false,\n\t\toutDir: virtualRoot,\n\t\trootDir: virtualRoot,\n\t\tskipLibCheck: true,\n\t\ttarget: ts.ScriptTarget.ESNext,\n\t};\n\n\tconst defaultHost = ts.createCompilerHost(compilerOptions, true);\n\tconst declarations: Record<string, string> = {};\n\n\tconst host: import(\"typescript\").CompilerHost = {\n\t\t...defaultHost,\n\t\tfileExists: (fileName) => {\n\t\t\tconst normalized = normalizeFileName(fileName);\n\t\t\treturn files.has(normalized) || defaultHost.fileExists(fileName);\n\t\t},\n\t\tdirectoryExists: (directoryName) => {\n\t\t\tconst normalized = normalizeFileName(directoryName);\n\t\t\treturn (\n\t\t\t\tvirtualDirectories.has(normalized) ||\n\t\t\t\tdefaultHost.directoryExists?.(directoryName) === true\n\t\t\t);\n\t\t},\n\t\tgetDirectories: (directoryName) => {\n\t\t\tconst normalized = normalizeFileName(directoryName);\n\t\t\tconst children = Array.from(virtualDirectories).filter(\n\t\t\t\t(dir) => path.dirname(dir) === normalized\n\t\t\t);\n\t\t\treturn [\n\t\t\t\t...(defaultHost.getDirectories?.(directoryName) ?? []),\n\t\t\t\t...children.map((dir) => path.basename(dir)),\n\t\t\t];\n\t\t},\n\t\treadFile: (fileName) => {\n\t\t\tconst normalized = normalizeFileName(fileName);\n\t\t\treturn files.get(normalized) ?? defaultHost.readFile(fileName);\n\t\t},\n\t\tgetSourceFile: (\n\t\t\tfileName,\n\t\t\tlanguageVersion,\n\t\t\tonError,\n\t\t\tshouldCreateNewFile\n\t\t) => {\n\t\t\tconst normalized = normalizeFileName(fileName);\n\t\t\tconst sourceText = files.get(normalized);\n\t\t\tif (sourceText !== undefined) {\n\t\t\t\treturn ts.createSourceFile(fileName, sourceText, languageVersion, true);\n\t\t\t}\n\t\t\treturn defaultHost.getSourceFile(\n\t\t\t\tfileName,\n\t\t\t\tlanguageVersion,\n\t\t\t\tonError,\n\t\t\t\tshouldCreateNewFile\n\t\t\t);\n\t\t},\n\t\twriteFile: (fileName, text) => {\n\t\t\tconst relativePath = path\n\t\t\t\t.relative(virtualRoot, fileName)\n\t\t\t\t.split(path.sep)\n\t\t\t\t.join(path.posix.sep);\n\n\t\t\tif (!relativePath.startsWith(\"..\")) {\n\t\t\t\tdeclarations[relativePath] = text;\n\t\t\t}\n\t\t},\n\t};\n\n\tconst program = ts.createProgram(\n\t\tArray.from(files.keys()),\n\t\tcompilerOptions,\n\t\thost\n\t);\n\n\tprogram.emit(undefined, undefined, undefined, true, {\n\t\tafterDeclarations: [\n\t\t\tcreateQuotedExportAliasTransformer(\n\t\t\t\tts,\n\t\t\t\tquotedExportAliases,\n\t\t\t\tnormalizeFileName\n\t\t\t),\n\t\t],\n\t});\n\n\treturn declarations;\n}\n\nconst failedToEmitWithTscMessage = `Paraglide's \"emitTsDeclarations\" option failed to generate declaration files with the installed TypeScript version.\n\nTypeScript 7+ no longer provides the in-process compiler API, so Paraglide invokes its \"tsc\" CLI instead — which did not produce a declaration file for every compiled file. As a workaround, install TypeScript 5 or 6, or disable \"emitTsDeclarations\".`;\n\n/**\n * Emits declarations by invoking the `tsc` CLI of the installed TypeScript\n * package (TypeScript 7+, where the in-process compiler API is unavailable).\n *\n * The compiled output is written to a temporary directory because the\n * Go-based compiler cannot read from a virtual filesystem.\n */\nasync function emitWithTscCli(\n\tjsEntries: [string, string][]\n): Promise<Record<string, string>> {\n\t// entries escaping the output root cannot be declared safely; the\n\t// compiler-API path silently drops them too (see the writeFile hook).\n\t// Checked against both separator conventions because path.join interprets\n\t// backslashes on Windows (`foo\\..\\..\\x.js` would escape the temp dir).\n\tconst safeEntries = jsEntries.filter(([fileName]) =>\n\t\t[path.posix, path.win32].every((platformPath) => {\n\t\t\tconst normalized = platformPath.normalize(fileName);\n\t\t\treturn (\n\t\t\t\tnormalized.startsWith(\"..\") === false &&\n\t\t\t\tplatformPath.isAbsolute(normalized) === false\n\t\t\t);\n\t\t})\n\t);\n\n\t// resolved before spawning so a missing tsc entry point surfaces its own\n\t// pointed error instead of the generic \"no declaration files\" one\n\tconst tscJsPath = resolveTscJsPath();\n\n\tconst tempDir = await fs.mkdtemp(path.join(os.tmpdir(), \"paraglide-dts-\"));\n\n\ttry {\n\t\tconst srcDir = path.join(tempDir, \"src\");\n\t\tconst outDir = path.join(tempDir, \"dist\");\n\t\tawait fs.mkdir(outDir, { recursive: true });\n\n\t\tfor (const [fileName, content] of safeEntries) {\n\t\t\tconst filePath = path.join(srcDir, fileName);\n\t\t\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\t\t\tawait fs.writeFile(filePath, content);\n\t\t}\n\n\t\tconst tsconfigPath = path.join(tempDir, \"tsconfig.json\");\n\t\tawait fs.writeFile(\n\t\t\ttsconfigPath,\n\t\t\tJSON.stringify({\n\t\t\t\tcompilerOptions: {\n\t\t\t\t\tallowJs: true,\n\t\t\t\t\tcheckJs: true,\n\t\t\t\t\tdeclaration: true,\n\t\t\t\t\temitDeclarationOnly: true,\n\t\t\t\t\tesModuleInterop: true,\n\t\t\t\t\tlib: [\"ESNext\", \"DOM\"],\n\t\t\t\t\tmodule: \"ESNext\",\n\t\t\t\t\tmoduleResolution: \"bundler\",\n\t\t\t\t\t// Declaration emit does not need a typecheck; skipping it also\n\t\t\t\t\t// suppresses diagnostics about the project's environment (e.g.\n\t\t\t\t\t// a missing @types/node) that are irrelevant to the output.\n\t\t\t\t\tnoCheck: true,\n\t\t\t\t\tnoEmitOnError: false,\n\t\t\t\t\toutDir: \"./dist\",\n\t\t\t\t\trootDir: \"./src\",\n\t\t\t\t\tskipLibCheck: true,\n\t\t\t\t\ttarget: \"ESNext\",\n\t\t\t\t},\n\t\t\t\tfiles: safeEntries.map(([fileName]) => `./src/${fileName}`),\n\t\t\t})\n\t\t);\n\n\t\tlet tscError: unknown;\n\t\ttry {\n\t\t\tawait execFileAsync(\n\t\t\t\tprocess.execPath,\n\t\t\t\t[tscJsPath, \"--project\", tsconfigPath],\n\t\t\t\t{\n\t\t\t\t\tmaxBuffer: 64 * 1024 * 1024,\n\t\t\t\t\t// Electron-based hosts must execute tsc with their embedded\n\t\t\t\t\t// Node instead of launching another instance of the host app.\n\t\t\t\t\t// Harmless under node and bun.\n\t\t\t\t\tenv: { ...process.env, ELECTRON_RUN_AS_NODE: \"1\" },\n\t\t\t\t}\n\t\t\t);\n\t\t} catch (error) {\n\t\t\t// tsc exits non-zero when the input has diagnostics even though the\n\t\t\t// declaration files are still emitted (noEmitOnError is false).\n\t\t\t// Success is judged by the presence of declaration files below.\n\t\t\ttscError = error;\n\t\t}\n\n\t\tconst declarations: Record<string, string> = {};\n\n\t\tfor (const entry of await fs.readdir(outDir, { recursive: true })) {\n\t\t\tif (entry.endsWith(\".d.ts\")) {\n\t\t\t\tdeclarations[entry.split(path.sep).join(path.posix.sep)] =\n\t\t\t\t\tawait fs.readFile(path.join(outDir, entry), \"utf-8\");\n\t\t\t}\n\t\t}\n\n\t\t// tsc emits exactly one .d.ts per input .js (even for inputs with\n\t\t// syntax errors), so a count mismatch means the compiler died mid-emit\n\t\t// and the result would be silently incomplete.\n\t\tif (Object.keys(declarations).length !== safeEntries.length) {\n\t\t\tthrow new Error(withTscOutput(failedToEmitWithTscMessage, tscError), {\n\t\t\t\tcause: tscError,\n\t\t\t});\n\t\t}\n\n\t\treturn declarations;\n\t} finally {\n\t\tawait fs.rm(tempDir, { recursive: true, force: true });\n\t}\n}\n\n/**\n * Appends the spawned compiler's output to the error message.\n *\n * tsc writes diagnostics to stdout, which `execFile` errors expose only as a\n * property — not in the message — so error reporters that print only\n * message/stack would otherwise hide the reason the emit failed.\n */\nfunction withTscOutput(message: string, tscError: unknown): string {\n\tconst { stdout, stderr } = (tscError ?? {}) as {\n\t\tstdout?: unknown;\n\t\tstderr?: unknown;\n\t};\n\tconst output = [stdout, stderr]\n\t\t.filter((value): value is string => typeof value === \"string\")\n\t\t.join(\"\\n\")\n\t\t.trim();\n\tif (output === \"\") {\n\t\treturn message;\n\t}\n\tconst truncated =\n\t\toutput.length > 4000 ? output.slice(0, 4000) + \"\\n… (truncated)\" : output;\n\treturn `${message}\\n\\nCompiler output:\\n${truncated}`;\n}\n\ntype QuotedExportAliases = Map<string, Map<string, Set<string>>>;\n\nfunction collectQuotedExportAliases(\n\tts: TypeScript,\n\tfiles: Map<string, string>\n): QuotedExportAliases {\n\tconst aliases: QuotedExportAliases = new Map();\n\n\tfor (const [fileName, content] of files) {\n\t\tconst sourceFile = ts.createSourceFile(\n\t\t\tfileName,\n\t\t\tcontent,\n\t\t\tts.ScriptTarget.ESNext,\n\t\t\ttrue,\n\t\t\tts.ScriptKind.JS\n\t\t);\n\t\tconst fileAliases = new Map<string, Set<string>>();\n\n\t\tconst visit = (node: import(\"typescript\").Node) => {\n\t\t\tif (\n\t\t\t\tts.isExportDeclaration(node) &&\n\t\t\t\tnode.exportClause &&\n\t\t\t\tts.isNamedExports(node.exportClause)\n\t\t\t) {\n\t\t\t\tfor (const specifier of node.exportClause.elements) {\n\t\t\t\t\tif (ts.isStringLiteral(specifier.name)) {\n\t\t\t\t\t\tconst localName = moduleExportNameText(\n\t\t\t\t\t\t\tspecifier.propertyName ?? specifier.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst exportedName = specifier.name.text;\n\t\t\t\t\t\tconst localAliases =\n\t\t\t\t\t\t\tfileAliases.get(localName) ?? new Set<string>();\n\t\t\t\t\t\tlocalAliases.add(exportedName);\n\t\t\t\t\t\tfileAliases.set(localName, localAliases);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tts.forEachChild(node, visit);\n\t\t};\n\n\t\tvisit(sourceFile);\n\n\t\tif (fileAliases.size > 0) {\n\t\t\taliases.set(fileName, fileAliases);\n\t\t}\n\t}\n\n\treturn aliases;\n}\n\nfunction createQuotedExportAliasTransformer(\n\tts: TypeScript,\n\tquotedExportAliases: QuotedExportAliases,\n\tnormalizeFileName: (fileName: string) => string\n): import(\"typescript\").TransformerFactory<\n\timport(\"typescript\").SourceFile | import(\"typescript\").Bundle\n> {\n\treturn (context) => {\n\t\tconst visitSourceFile = (sourceFile: import(\"typescript\").SourceFile) => {\n\t\t\tconst fileAliases = quotedExportAliases.get(\n\t\t\t\tnormalizeFileName(sourceFile.fileName)\n\t\t\t);\n\n\t\t\tif (!fileAliases) {\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst visit = (\n\t\t\t\tnode: import(\"typescript\").Node\n\t\t\t): import(\"typescript\").VisitResult<import(\"typescript\").Node> => {\n\t\t\t\tif (\n\t\t\t\t\tts.isExportDeclaration(node) &&\n\t\t\t\t\tnode.exportClause &&\n\t\t\t\t\tts.isNamedExports(node.exportClause)\n\t\t\t\t) {\n\t\t\t\t\tconst elements: import(\"typescript\").ExportSpecifier[] = [];\n\t\t\t\t\tconst emitted = new Set<string>();\n\n\t\t\t\t\tfor (const specifier of node.exportClause.elements) {\n\t\t\t\t\t\tconst localName = moduleExportNameText(\n\t\t\t\t\t\t\tspecifier.propertyName ?? specifier.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst exportedName = moduleExportNameText(specifier.name);\n\t\t\t\t\t\tconst shouldQuote = fileAliases.get(localName)?.has(exportedName);\n\t\t\t\t\t\tconst nextSpecifier = shouldQuote\n\t\t\t\t\t\t\t? ts.factory.updateExportSpecifier(\n\t\t\t\t\t\t\t\t\tspecifier,\n\t\t\t\t\t\t\t\t\tspecifier.isTypeOnly,\n\t\t\t\t\t\t\t\t\tspecifier.propertyName,\n\t\t\t\t\t\t\t\t\tts.factory.createStringLiteral(exportedName)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: specifier;\n\t\t\t\t\t\tconst emittedKey = `${moduleExportNameText(\n\t\t\t\t\t\t\tnextSpecifier.propertyName ?? nextSpecifier.name\n\t\t\t\t\t\t)}\\0${moduleExportNameText(nextSpecifier.name)}`;\n\n\t\t\t\t\t\tif (!emitted.has(emittedKey)) {\n\t\t\t\t\t\t\telements.push(nextSpecifier);\n\t\t\t\t\t\t\temitted.add(emittedKey);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ts.factory.updateExportDeclaration(\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\tnode.modifiers,\n\t\t\t\t\t\tnode.isTypeOnly,\n\t\t\t\t\t\tts.factory.updateNamedExports(node.exportClause, elements),\n\t\t\t\t\t\tnode.moduleSpecifier,\n\t\t\t\t\t\tnode.attributes\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn ts.visitEachChild(node, visit, context);\n\t\t\t};\n\n\t\t\treturn ts.visitEachChild(sourceFile, visit, context);\n\t\t};\n\n\t\treturn (sourceFileOrBundle) => {\n\t\t\tif (\"fileName\" in sourceFileOrBundle) {\n\t\t\t\treturn visitSourceFile(sourceFileOrBundle);\n\t\t\t}\n\t\t\treturn sourceFileOrBundle;\n\t\t};\n\t};\n}\n\nfunction moduleExportNameText(name: import(\"typescript\").ModuleExportName) {\n\treturn name.text;\n}\n\nasync function importTypeScript(): Promise<TypeScript> {\n\ttry {\n\t\treturn await import(\"typescript\");\n\t} catch (cause) {\n\t\tif (isMissingTypeScriptPackageError(cause)) {\n\t\t\tthrow new Error(missingTypeScriptMessage);\n\t\t}\n\t\tthrow new Error(failedToLoadTypeScriptMessage, { cause });\n\t}\n}\n\nfunction isMissingTypeScriptPackageError(cause: unknown): boolean {\n\tif (cause instanceof Error === false) {\n\t\treturn false;\n\t}\n\tif (\"code\" in cause && cause.code !== \"ERR_MODULE_NOT_FOUND\") {\n\t\treturn false;\n\t}\n\treturn cause.message.includes(\"Cannot find package 'typescript'\");\n}\n"]}
1
+ {"version":3,"file":"emit-ts-declarations.js","sourceRoot":"","sources":["../../src/compiler/emit-ts-declarations.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACN,sBAAsB,EACtB,gBAAgB,GAChB,MAAM,0BAA0B,CAAC;AAElC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAI1C,MAAM,wBAAwB,GAAG;;qEAEoC,CAAC;AAEtE,MAAM,6BAA6B,GAAG;;yFAEmD,CAAC;AAE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I,+BAA+B,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC3C,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,CAAC;AACF,CAAC;AAED,SAAS,+BAA+B,CAAC,KAAc;IACtD,IAAI,KAAK,YAAY,KAAK,KAAK,KAAK,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACd,CAAC;IACD,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;QAC9D,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,kCAAkC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport { execFile } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport {\n\tresolveNativeTscJsPath,\n\tresolveTscJsPath,\n} from \"./resolve-tsc-js-path.js\";\n\nconst execFileAsync = promisify(execFile);\n\ntype TypeScript = typeof import(\"typescript\");\n\nconst missingTypeScriptMessage = `Paraglide's \"emitTsDeclarations\" option requires the \"typescript\" package.\n\nInstall TypeScript in your project, or disable \"emitTsDeclarations\".`;\n\nconst failedToLoadTypeScriptMessage = `Paraglide's \"emitTsDeclarations\" option requires the \"typescript\" package.\n\nTypeScript appears to be installed, but failed to load. See the error cause for details.`;\n\n/**\n * Generates `.d.ts` files for the compiled Paraglide output using the TypeScript compiler.\n *\n * @param output - The generated compiler output keyed by relative file path.\n * @param options - Whether the optional native alias may replace the compiler API.\n * @returns The generated declaration files keyed by relative path.\n *\n * @example\n * const declarations = await emitTsDeclarations(output);\n * // Merge them into the compiler output before writing to disk\n */\nexport async function emitTsDeclarations(\n\toutput: Record<string, string>,\n\toptions: { allowNativeAlias?: boolean } = {}\n): Promise<Record<string, string>> {\n\tconst ts = await importTypeScript();\n\n\tconst jsEntries = Object.entries(output).filter(([fileName]) =>\n\t\tfileName.endsWith(\".js\")\n\t);\n\n\tif (jsEntries.length === 0) {\n\t\treturn {};\n\t}\n\n\t// TypeScript 7+ (the Go-based compiler) no longer ships the in-process\n\t// compiler API — its main entry point only exports version metadata.\n\t// https://github.com/opral/paraglide-js/issues/711\n\tconst compilerApi = resolveCompilerApi(ts);\n\tif (compilerApi === undefined) {\n\t\t// resolved before spawning so a missing tsc entry point surfaces its own\n\t\t// pointed error instead of the generic \"no declaration files\" one\n\t\treturn emitWithTscCli(jsEntries, resolveTscJsPath());\n\t}\n\n\t// TypeScript 7 installed beside TypeScript 5/6, as svelte-check's `--tsgo`\n\t// mode needs, emits declarations much faster than the compiler API.\n\tif (options.allowNativeAlias !== false) {\n\t\tconst nativeTscJsPath = resolveNativeTscJsPath();\n\t\tif (nativeTscJsPath !== undefined) {\n\t\t\treturn emitWithTscCli(jsEntries, nativeTscJsPath);\n\t\t}\n\t}\n\n\treturn emitWithCompilerApi(compilerApi, jsEntries);\n}\n\n/**\n * Returns the in-process compiler API (TypeScript 5/6), or `undefined` when\n * the installed TypeScript does not provide one (TypeScript 7+).\n *\n * Unwraps default-only interop shapes (`{ default: ts }`) that bundlers and\n * CJS interop can produce. Without the unwrap, TypeScript 5/6 would be\n * misrouted to the CLI path, whose TypeScript 5 declaration emitter produces\n * syntactically invalid quoted export aliases.\n */\nfunction resolveCompilerApi(ts: TypeScript): TypeScript | undefined {\n\tif (typeof ts.createProgram === \"function\") {\n\t\treturn ts;\n\t}\n\tconst defaultExport = (ts as { default?: TypeScript }).default;\n\tif (defaultExport && typeof defaultExport.createProgram === \"function\") {\n\t\treturn defaultExport;\n\t}\n\treturn undefined;\n}\n\n/**\n * Emits declarations with the in-process TypeScript compiler API (TypeScript 5/6).\n */\nasync function emitWithCompilerApi(\n\tts: TypeScript,\n\tjsEntries: [string, string][]\n): Promise<Record<string, string>> {\n\tconst virtualRoot = path.join(process.cwd(), \"__paraglide_virtual_output\");\n\tconst normalizeFileName = (fileName: string) =>\n\t\tpath.normalize(\n\t\t\tpath.isAbsolute(fileName) ? fileName : path.join(virtualRoot, fileName)\n\t\t);\n\n\tconst files = new Map(\n\t\tjsEntries.map(([fileName, content]) => [\n\t\t\tnormalizeFileName(fileName),\n\t\t\tcontent,\n\t\t])\n\t);\n\tconst quotedExportAliases = collectQuotedExportAliases(ts, files);\n\n\tconst virtualDirectories = new Set(\n\t\tArray.from(files.keys()).flatMap((filePath) => {\n\t\t\tconst directories: string[] = [];\n\t\t\tlet current = path.dirname(filePath);\n\t\t\twhile (current.startsWith(virtualRoot) && current !== virtualRoot) {\n\t\t\t\tdirectories.push(current);\n\t\t\t\tconst parent = path.dirname(current);\n\t\t\t\tif (parent === current) break;\n\t\t\t\tcurrent = parent;\n\t\t\t}\n\t\t\treturn directories;\n\t\t})\n\t);\n\t// Ensure the virtual root itself is treated as existing\n\tvirtualDirectories.add(virtualRoot);\n\n\tconst compilerOptions: import(\"typescript\").CompilerOptions = {\n\t\tallowJs: true,\n\t\tcheckJs: true,\n\t\tdeclaration: true,\n\t\temitDeclarationOnly: true,\n\t\tisolatedDeclarations: true,\n\t\tesModuleInterop: true,\n\t\tlib: [\"ESNext\", \"DOM\"],\n\t\tmodule: ts.ModuleKind.ESNext,\n\t\tmoduleResolution: ts.ModuleResolutionKind.Bundler,\n\t\tnoEmitOnError: false,\n\t\toutDir: virtualRoot,\n\t\trootDir: virtualRoot,\n\t\tskipLibCheck: true,\n\t\ttarget: ts.ScriptTarget.ESNext,\n\t};\n\n\tconst defaultHost = ts.createCompilerHost(compilerOptions, true);\n\tconst declarations: Record<string, string> = {};\n\n\tconst host: import(\"typescript\").CompilerHost = {\n\t\t...defaultHost,\n\t\tfileExists: (fileName) => {\n\t\t\tconst normalized = normalizeFileName(fileName);\n\t\t\treturn files.has(normalized) || defaultHost.fileExists(fileName);\n\t\t},\n\t\tdirectoryExists: (directoryName) => {\n\t\t\tconst normalized = normalizeFileName(directoryName);\n\t\t\treturn (\n\t\t\t\tvirtualDirectories.has(normalized) ||\n\t\t\t\tdefaultHost.directoryExists?.(directoryName) === true\n\t\t\t);\n\t\t},\n\t\tgetDirectories: (directoryName) => {\n\t\t\tconst normalized = normalizeFileName(directoryName);\n\t\t\tconst children = Array.from(virtualDirectories).filter(\n\t\t\t\t(dir) => path.dirname(dir) === normalized\n\t\t\t);\n\t\t\treturn [\n\t\t\t\t...(defaultHost.getDirectories?.(directoryName) ?? []),\n\t\t\t\t...children.map((dir) => path.basename(dir)),\n\t\t\t];\n\t\t},\n\t\treadFile: (fileName) => {\n\t\t\tconst normalized = normalizeFileName(fileName);\n\t\t\treturn files.get(normalized) ?? defaultHost.readFile(fileName);\n\t\t},\n\t\tgetSourceFile: (\n\t\t\tfileName,\n\t\t\tlanguageVersion,\n\t\t\tonError,\n\t\t\tshouldCreateNewFile\n\t\t) => {\n\t\t\tconst normalized = normalizeFileName(fileName);\n\t\t\tconst sourceText = files.get(normalized);\n\t\t\tif (sourceText !== undefined) {\n\t\t\t\treturn ts.createSourceFile(fileName, sourceText, languageVersion, true);\n\t\t\t}\n\t\t\treturn defaultHost.getSourceFile(\n\t\t\t\tfileName,\n\t\t\t\tlanguageVersion,\n\t\t\t\tonError,\n\t\t\t\tshouldCreateNewFile\n\t\t\t);\n\t\t},\n\t\twriteFile: (fileName, text) => {\n\t\t\tconst relativePath = path\n\t\t\t\t.relative(virtualRoot, fileName)\n\t\t\t\t.split(path.sep)\n\t\t\t\t.join(path.posix.sep);\n\n\t\t\tif (!relativePath.startsWith(\"..\")) {\n\t\t\t\tdeclarations[relativePath] = text;\n\t\t\t}\n\t\t},\n\t};\n\n\tconst program = ts.createProgram(\n\t\tArray.from(files.keys()),\n\t\tcompilerOptions,\n\t\thost\n\t);\n\n\tprogram.emit(undefined, undefined, undefined, true, {\n\t\tafterDeclarations: [\n\t\t\tcreateQuotedExportAliasTransformer(\n\t\t\t\tts,\n\t\t\t\tquotedExportAliases,\n\t\t\t\tnormalizeFileName\n\t\t\t),\n\t\t],\n\t});\n\n\treturn declarations;\n}\n\nconst failedToEmitWithTscMessage = `Paraglide's \"emitTsDeclarations\" option failed to generate declaration files with TypeScript 7's \"tsc\" CLI, which did not produce a declaration file for every compiled file.\n\nParaglide uses that CLI when the \"typescript\" package is version 7+, or when TypeScript 7 is installed as \"@typescript/native\". As a workaround, use TypeScript 5 or 6 without \"@typescript/native\", or disable \"emitTsDeclarations\".`;\n\n/**\n * Emits declarations by invoking the given TypeScript 7+ `tsc` CLI.\n *\n * The compiled output is written to a temporary directory because the\n * Go-based compiler cannot read from a virtual filesystem.\n */\nasync function emitWithTscCli(\n\tjsEntries: [string, string][],\n\ttscJsPath: string\n): Promise<Record<string, string>> {\n\t// entries escaping the output root cannot be declared safely; the\n\t// compiler-API path silently drops them too (see the writeFile hook).\n\t// Checked against both separator conventions because path.join interprets\n\t// backslashes on Windows (`foo\\..\\..\\x.js` would escape the temp dir).\n\tconst safeEntries = jsEntries.filter(([fileName]) =>\n\t\t[path.posix, path.win32].every((platformPath) => {\n\t\t\tconst normalized = platformPath.normalize(fileName);\n\t\t\treturn (\n\t\t\t\tnormalized.startsWith(\"..\") === false &&\n\t\t\t\tplatformPath.isAbsolute(normalized) === false\n\t\t\t);\n\t\t})\n\t);\n\n\tconst tempDir = await fs.mkdtemp(path.join(os.tmpdir(), \"paraglide-dts-\"));\n\n\ttry {\n\t\tconst srcDir = path.join(tempDir, \"src\");\n\t\tconst outDir = path.join(tempDir, \"dist\");\n\t\tawait fs.mkdir(outDir, { recursive: true });\n\n\t\tfor (const [fileName, content] of safeEntries) {\n\t\t\tconst filePath = path.join(srcDir, fileName);\n\t\t\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\t\t\tawait fs.writeFile(filePath, content);\n\t\t}\n\n\t\tconst tsconfigPath = path.join(tempDir, \"tsconfig.json\");\n\t\tawait fs.writeFile(\n\t\t\ttsconfigPath,\n\t\t\tJSON.stringify({\n\t\t\t\tcompilerOptions: {\n\t\t\t\t\tallowJs: true,\n\t\t\t\t\tcheckJs: true,\n\t\t\t\t\tdeclaration: true,\n\t\t\t\t\temitDeclarationOnly: true,\n\t\t\t\t\tesModuleInterop: true,\n\t\t\t\t\tlib: [\"ESNext\", \"DOM\"],\n\t\t\t\t\tmodule: \"ESNext\",\n\t\t\t\t\tmoduleResolution: \"bundler\",\n\t\t\t\t\t// Declaration emit does not need a typecheck; skipping it also\n\t\t\t\t\t// suppresses diagnostics about the project's environment (e.g.\n\t\t\t\t\t// a missing @types/node) that are irrelevant to the output.\n\t\t\t\t\tnoCheck: true,\n\t\t\t\t\tnoEmitOnError: false,\n\t\t\t\t\toutDir: \"./dist\",\n\t\t\t\t\trootDir: \"./src\",\n\t\t\t\t\tskipLibCheck: true,\n\t\t\t\t\ttarget: \"ESNext\",\n\t\t\t\t},\n\t\t\t\tfiles: safeEntries.map(([fileName]) => `./src/${fileName}`),\n\t\t\t})\n\t\t);\n\n\t\tlet tscError: unknown;\n\t\ttry {\n\t\t\tawait execFileAsync(\n\t\t\t\tprocess.execPath,\n\t\t\t\t[tscJsPath, \"--project\", tsconfigPath],\n\t\t\t\t{\n\t\t\t\t\tmaxBuffer: 64 * 1024 * 1024,\n\t\t\t\t\t// Electron-based hosts must execute tsc with their embedded\n\t\t\t\t\t// Node instead of launching another instance of the host app.\n\t\t\t\t\t// Harmless under node and bun.\n\t\t\t\t\tenv: { ...process.env, ELECTRON_RUN_AS_NODE: \"1\" },\n\t\t\t\t}\n\t\t\t);\n\t\t} catch (error) {\n\t\t\t// tsc exits non-zero when the input has diagnostics even though the\n\t\t\t// declaration files are still emitted (noEmitOnError is false).\n\t\t\t// Success is judged by the presence of declaration files below.\n\t\t\ttscError = error;\n\t\t}\n\n\t\tconst declarations: Record<string, string> = {};\n\n\t\tfor (const entry of await fs.readdir(outDir, { recursive: true })) {\n\t\t\tif (entry.endsWith(\".d.ts\")) {\n\t\t\t\tdeclarations[entry.split(path.sep).join(path.posix.sep)] =\n\t\t\t\t\tawait fs.readFile(path.join(outDir, entry), \"utf-8\");\n\t\t\t}\n\t\t}\n\n\t\t// tsc emits exactly one .d.ts per input .js (even for inputs with\n\t\t// syntax errors), so a count mismatch means the compiler died mid-emit\n\t\t// and the result would be silently incomplete.\n\t\tif (Object.keys(declarations).length !== safeEntries.length) {\n\t\t\tthrow new Error(withTscOutput(failedToEmitWithTscMessage, tscError), {\n\t\t\t\tcause: tscError,\n\t\t\t});\n\t\t}\n\n\t\treturn declarations;\n\t} finally {\n\t\tawait fs.rm(tempDir, { recursive: true, force: true });\n\t}\n}\n\n/**\n * Appends the spawned compiler's output to the error message.\n *\n * tsc writes diagnostics to stdout, which `execFile` errors expose only as a\n * property — not in the message — so error reporters that print only\n * message/stack would otherwise hide the reason the emit failed.\n */\nfunction withTscOutput(message: string, tscError: unknown): string {\n\tconst { stdout, stderr } = (tscError ?? {}) as {\n\t\tstdout?: unknown;\n\t\tstderr?: unknown;\n\t};\n\tconst output = [stdout, stderr]\n\t\t.filter((value): value is string => typeof value === \"string\")\n\t\t.join(\"\\n\")\n\t\t.trim();\n\tif (output === \"\") {\n\t\treturn message;\n\t}\n\tconst truncated =\n\t\toutput.length > 4000 ? output.slice(0, 4000) + \"\\n… (truncated)\" : output;\n\treturn `${message}\\n\\nCompiler output:\\n${truncated}`;\n}\n\ntype QuotedExportAliases = Map<string, Map<string, Set<string>>>;\n\nfunction collectQuotedExportAliases(\n\tts: TypeScript,\n\tfiles: Map<string, string>\n): QuotedExportAliases {\n\tconst aliases: QuotedExportAliases = new Map();\n\n\tfor (const [fileName, content] of files) {\n\t\tconst sourceFile = ts.createSourceFile(\n\t\t\tfileName,\n\t\t\tcontent,\n\t\t\tts.ScriptTarget.ESNext,\n\t\t\ttrue,\n\t\t\tts.ScriptKind.JS\n\t\t);\n\t\tconst fileAliases = new Map<string, Set<string>>();\n\n\t\tconst visit = (node: import(\"typescript\").Node) => {\n\t\t\tif (\n\t\t\t\tts.isExportDeclaration(node) &&\n\t\t\t\tnode.exportClause &&\n\t\t\t\tts.isNamedExports(node.exportClause)\n\t\t\t) {\n\t\t\t\tfor (const specifier of node.exportClause.elements) {\n\t\t\t\t\tif (ts.isStringLiteral(specifier.name)) {\n\t\t\t\t\t\tconst localName = moduleExportNameText(\n\t\t\t\t\t\t\tspecifier.propertyName ?? specifier.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst exportedName = specifier.name.text;\n\t\t\t\t\t\tconst localAliases =\n\t\t\t\t\t\t\tfileAliases.get(localName) ?? new Set<string>();\n\t\t\t\t\t\tlocalAliases.add(exportedName);\n\t\t\t\t\t\tfileAliases.set(localName, localAliases);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tts.forEachChild(node, visit);\n\t\t};\n\n\t\tvisit(sourceFile);\n\n\t\tif (fileAliases.size > 0) {\n\t\t\taliases.set(fileName, fileAliases);\n\t\t}\n\t}\n\n\treturn aliases;\n}\n\nfunction createQuotedExportAliasTransformer(\n\tts: TypeScript,\n\tquotedExportAliases: QuotedExportAliases,\n\tnormalizeFileName: (fileName: string) => string\n): import(\"typescript\").TransformerFactory<\n\timport(\"typescript\").SourceFile | import(\"typescript\").Bundle\n> {\n\treturn (context) => {\n\t\tconst visitSourceFile = (sourceFile: import(\"typescript\").SourceFile) => {\n\t\t\tconst fileAliases = quotedExportAliases.get(\n\t\t\t\tnormalizeFileName(sourceFile.fileName)\n\t\t\t);\n\n\t\t\tif (!fileAliases) {\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst visit = (\n\t\t\t\tnode: import(\"typescript\").Node\n\t\t\t): import(\"typescript\").VisitResult<import(\"typescript\").Node> => {\n\t\t\t\tif (\n\t\t\t\t\tts.isExportDeclaration(node) &&\n\t\t\t\t\tnode.exportClause &&\n\t\t\t\t\tts.isNamedExports(node.exportClause)\n\t\t\t\t) {\n\t\t\t\t\tconst elements: import(\"typescript\").ExportSpecifier[] = [];\n\t\t\t\t\tconst emitted = new Set<string>();\n\n\t\t\t\t\tfor (const specifier of node.exportClause.elements) {\n\t\t\t\t\t\tconst localName = moduleExportNameText(\n\t\t\t\t\t\t\tspecifier.propertyName ?? specifier.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst exportedName = moduleExportNameText(specifier.name);\n\t\t\t\t\t\tconst shouldQuote = fileAliases.get(localName)?.has(exportedName);\n\t\t\t\t\t\tconst nextSpecifier = shouldQuote\n\t\t\t\t\t\t\t? ts.factory.updateExportSpecifier(\n\t\t\t\t\t\t\t\t\tspecifier,\n\t\t\t\t\t\t\t\t\tspecifier.isTypeOnly,\n\t\t\t\t\t\t\t\t\tspecifier.propertyName,\n\t\t\t\t\t\t\t\t\tts.factory.createStringLiteral(exportedName)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: specifier;\n\t\t\t\t\t\tconst emittedKey = `${moduleExportNameText(\n\t\t\t\t\t\t\tnextSpecifier.propertyName ?? nextSpecifier.name\n\t\t\t\t\t\t)}\\0${moduleExportNameText(nextSpecifier.name)}`;\n\n\t\t\t\t\t\tif (!emitted.has(emittedKey)) {\n\t\t\t\t\t\t\telements.push(nextSpecifier);\n\t\t\t\t\t\t\temitted.add(emittedKey);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ts.factory.updateExportDeclaration(\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\tnode.modifiers,\n\t\t\t\t\t\tnode.isTypeOnly,\n\t\t\t\t\t\tts.factory.updateNamedExports(node.exportClause, elements),\n\t\t\t\t\t\tnode.moduleSpecifier,\n\t\t\t\t\t\tnode.attributes\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn ts.visitEachChild(node, visit, context);\n\t\t\t};\n\n\t\t\treturn ts.visitEachChild(sourceFile, visit, context);\n\t\t};\n\n\t\treturn (sourceFileOrBundle) => {\n\t\t\tif (\"fileName\" in sourceFileOrBundle) {\n\t\t\t\treturn visitSourceFile(sourceFileOrBundle);\n\t\t\t}\n\t\t\treturn sourceFileOrBundle;\n\t\t};\n\t};\n}\n\nfunction moduleExportNameText(name: import(\"typescript\").ModuleExportName) {\n\treturn name.text;\n}\n\nasync function importTypeScript(): Promise<TypeScript> {\n\ttry {\n\t\treturn await import(\"typescript\");\n\t} catch (cause) {\n\t\tif (isMissingTypeScriptPackageError(cause)) {\n\t\t\tthrow new Error(missingTypeScriptMessage);\n\t\t}\n\t\tthrow new Error(failedToLoadTypeScriptMessage, { cause });\n\t}\n}\n\nfunction isMissingTypeScriptPackageError(cause: unknown): boolean {\n\tif (cause instanceof Error === false) {\n\t\treturn false;\n\t}\n\tif (\"code\" in cause && cause.code !== \"ERR_MODULE_NOT_FOUND\") {\n\t\treturn false;\n\t}\n\treturn cause.message.includes(\"Cannot find package 'typescript'\");\n}\n"]}
@@ -0,0 +1,86 @@
1
+ import { beforeEach, expect, test, vi } from "vitest";
2
+ import { loadProjectInMemory, newProject } from "@inlang/sdk";
3
+ import { createRequire } from "node:module";
4
+ import fs from "node:fs/promises";
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+ import { compileProject } from "./compile-project.js";
8
+ // TypeScript 7 can be installed beside TypeScript 5/6 under the
9
+ // `@typescript/native` npm alias, the setup svelte-check documents for its
10
+ // `--tsgo` mode. Its `tsc` takes precedence over the in-process compiler API
11
+ // of the `typescript` package. The repo's TypeScript 7 alias stands in for it.
12
+ const nativeTsc = vi.hoisted(() => ({ tscJsPath: "" }));
13
+ vi.mock("./resolve-tsc-js-path.js", () => ({
14
+ resolveNativeTscJsPath: () => nativeTsc.tscJsPath,
15
+ resolveTscJsPath: () => {
16
+ throw new Error("the tsc of the typescript package must not be used");
17
+ },
18
+ }));
19
+ const createProgram = vi.hoisted(() => vi.fn());
20
+ vi.mock("typescript", async () => {
21
+ const actual = await vi.importActual("typescript");
22
+ createProgram.mockImplementation(actual.createProgram);
23
+ return { ...actual, createProgram };
24
+ });
25
+ nativeTsc.tscJsPath = path.join(path.dirname(createRequire(import.meta.url).resolve("typescript-go/package.json")), "lib", "tsc.js");
26
+ beforeEach(() => vi.clearAllMocks());
27
+ const nonJavaScriptAdditionalFiles = [
28
+ undefined,
29
+ {},
30
+ { "notes.txt": "Additional documentation" },
31
+ ];
32
+ test.each(nonJavaScriptAdditionalFiles)("emitTsDeclarations uses the tsc of @typescript/native with non-JavaScript additionalFiles: %j", async (additionalFiles) => {
33
+ const project = await loadProjectInMemory({
34
+ blob: await newProject({
35
+ settings: {
36
+ locales: ["en"],
37
+ baseLocale: "en",
38
+ },
39
+ }),
40
+ });
41
+ const output = await compileProject({
42
+ project,
43
+ compilerOptions: {
44
+ emitTsDeclarations: true,
45
+ additionalFiles,
46
+ },
47
+ });
48
+ expect(output["runtime.d.ts"]).toContain("getLocale");
49
+ expect(createProgram).not.toHaveBeenCalled();
50
+ });
51
+ test.each(["custom.js", "messages.js"])("additionalFiles preserves imported types with @typescript/native installed: %s", async (fileName) => {
52
+ const projectRoot = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), "paraglide-additional-types-")));
53
+ const dependency = path.join(projectRoot, "node_modules", "fixture-dependency");
54
+ await fs.mkdir(dependency, { recursive: true });
55
+ await fs.writeFile(path.join(dependency, "package.json"), JSON.stringify({
56
+ name: "fixture-dependency",
57
+ version: "1.0.0",
58
+ types: "index.d.ts",
59
+ }));
60
+ await fs.writeFile(path.join(dependency, "index.d.ts"), "export declare function value(): { id: number };");
61
+ const cwd = vi.spyOn(process, "cwd").mockReturnValue(projectRoot);
62
+ try {
63
+ const project = await loadProjectInMemory({
64
+ blob: await newProject({
65
+ settings: { locales: ["en"], baseLocale: "en" },
66
+ }),
67
+ });
68
+ const output = await compileProject({
69
+ project,
70
+ compilerOptions: {
71
+ emitTsDeclarations: true,
72
+ additionalFiles: {
73
+ [fileName]: 'import { value } from "fixture-dependency"; export const result = value();',
74
+ },
75
+ },
76
+ });
77
+ const declaration = output[fileName.replace(/\.js$/, ".d.ts")];
78
+ expect(declaration).toMatch(/result:\s*\{\s*id: number;\s*\}/);
79
+ expect(declaration).not.toMatch(/\bany\b/);
80
+ }
81
+ finally {
82
+ cwd.mockRestore();
83
+ await fs.rm(projectRoot, { recursive: true, force: true });
84
+ }
85
+ });
86
+ //# sourceMappingURL=emit-ts-declarations.native.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit-ts-declarations.native.test.js","sourceRoot":"","sources":["../../src/compiler/emit-ts-declarations.native.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,gEAAgE;AAChE,2EAA2E;AAC3E,6EAA6E;AAC7E,+EAA+E;AAC/E,MAAM,SAAS,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAExD,EAAE,CAAC,IAAI,CAAC,0BAA0B,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1C,sBAAsB,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,SAAS;IACjD,gBAAgB,EAAE,GAAG,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACvE,CAAC;CACD,CAAC,CAAC,CAAC;AAEJ,MAAM,aAAa,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAEhD,EAAE,CAAC,IAAI,CAA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C,EACT,4EAA4E;iBAC7E;aACD;SACD,CAAC,CAAC;QAEH,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QAC/D,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC;QAC/D,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;YAAS,CAAC;QACV,GAAG,CAAC,WAAW,EAAE,CAAC;QAClB,MAAM,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;AACF,CAAC,CACD,CAAC","sourcesContent":["import { beforeEach, expect, test, vi } from \"vitest\";\nimport { loadProjectInMemory, newProject } from \"@inlang/sdk\";\nimport { createRequire } from \"node:module\";\nimport fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { compileProject } from \"./compile-project.js\";\n\n// TypeScript 7 can be installed beside TypeScript 5/6 under the\n// `@typescript/native` npm alias, the setup svelte-check documents for its\n// `--tsgo` mode. Its `tsc` takes precedence over the in-process compiler API\n// of the `typescript` package. The repo's TypeScript 7 alias stands in for it.\nconst nativeTsc = vi.hoisted(() => ({ tscJsPath: \"\" }));\n\nvi.mock(\"./resolve-tsc-js-path.js\", () => ({\n\tresolveNativeTscJsPath: () => nativeTsc.tscJsPath,\n\tresolveTscJsPath: () => {\n\t\tthrow new Error(\"the tsc of the typescript package must not be used\");\n\t},\n}));\n\nconst createProgram = vi.hoisted(() => vi.fn());\n\nvi.mock(\"typescript\", async () => {\n\tconst actual =\n\t\tawait vi.importActual<typeof import(\"typescript\")>(\"typescript\");\n\tcreateProgram.mockImplementation(actual.createProgram);\n\treturn { ...actual, createProgram };\n});\n\nnativeTsc.tscJsPath = path.join(\n\tpath.dirname(\n\t\tcreateRequire(import.meta.url).resolve(\"typescript-go/package.json\")\n\t),\n\t\"lib\",\n\t\"tsc.js\"\n);\n\nbeforeEach(() => vi.clearAllMocks());\n\nconst nonJavaScriptAdditionalFiles: (Record<string, string> | undefined)[] = [\n\tundefined,\n\t{},\n\t{ \"notes.txt\": \"Additional documentation\" },\n];\n\ntest.each(nonJavaScriptAdditionalFiles)(\n\t\"emitTsDeclarations uses the tsc of @typescript/native with non-JavaScript additionalFiles: %j\",\n\tasync (additionalFiles) => {\n\t\tconst project = await loadProjectInMemory({\n\t\t\tblob: await newProject({\n\t\t\t\tsettings: {\n\t\t\t\t\tlocales: [\"en\"],\n\t\t\t\t\tbaseLocale: \"en\",\n\t\t\t\t},\n\t\t\t}),\n\t\t});\n\n\t\tconst output = await compileProject({\n\t\t\tproject,\n\t\t\tcompilerOptions: {\n\t\t\t\temitTsDeclarations: true,\n\t\t\t\tadditionalFiles,\n\t\t\t},\n\t\t});\n\n\t\texpect(output[\"runtime.d.ts\"]).toContain(\"getLocale\");\n\t\texpect(createProgram).not.toHaveBeenCalled();\n\t}\n);\n\ntest.each([\"custom.js\", \"messages.js\"])(\n\t\"additionalFiles preserves imported types with @typescript/native installed: %s\",\n\tasync (fileName) => {\n\t\tconst projectRoot = await fs.realpath(\n\t\t\tawait fs.mkdtemp(path.join(os.tmpdir(), \"paraglide-additional-types-\"))\n\t\t);\n\t\tconst dependency = path.join(\n\t\t\tprojectRoot,\n\t\t\t\"node_modules\",\n\t\t\t\"fixture-dependency\"\n\t\t);\n\t\tawait fs.mkdir(dependency, { recursive: true });\n\t\tawait fs.writeFile(\n\t\t\tpath.join(dependency, \"package.json\"),\n\t\t\tJSON.stringify({\n\t\t\t\tname: \"fixture-dependency\",\n\t\t\t\tversion: \"1.0.0\",\n\t\t\t\ttypes: \"index.d.ts\",\n\t\t\t})\n\t\t);\n\t\tawait fs.writeFile(\n\t\t\tpath.join(dependency, \"index.d.ts\"),\n\t\t\t\"export declare function value(): { id: number };\"\n\t\t);\n\t\tconst cwd = vi.spyOn(process, \"cwd\").mockReturnValue(projectRoot);\n\n\t\ttry {\n\t\t\tconst project = await loadProjectInMemory({\n\t\t\t\tblob: await newProject({\n\t\t\t\t\tsettings: { locales: [\"en\"], baseLocale: \"en\" },\n\t\t\t\t}),\n\t\t\t});\n\t\t\tconst output = await compileProject({\n\t\t\t\tproject,\n\t\t\t\tcompilerOptions: {\n\t\t\t\t\temitTsDeclarations: true,\n\t\t\t\t\tadditionalFiles: {\n\t\t\t\t\t\t[fileName]:\n\t\t\t\t\t\t\t'import { value } from \"fixture-dependency\"; export const result = value();',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst declaration = output[fileName.replace(/\\.js$/, \".d.ts\")];\n\t\t\texpect(declaration).toMatch(/result:\\s*\\{\\s*id: number;\\s*\\}/);\n\t\t\texpect(declaration).not.toMatch(/\\bany\\b/);\n\t\t} finally {\n\t\t\tcwd.mockRestore();\n\t\t\tawait fs.rm(projectRoot, { recursive: true, force: true });\n\t\t}\n\t}\n);\n"]}
@@ -37,6 +37,9 @@ vi.mock("typescript", async () => {
37
37
  // path can be tested with a broken resolution.
38
38
  const tscResolution = vi.hoisted(() => ({ tscJsPath: "" }));
39
39
  vi.mock("./resolve-tsc-js-path.js", () => ({
40
+ resolveNativeTscJsPath: () => {
41
+ throw new Error("@typescript/native must not replace TypeScript 7's tsc");
42
+ },
40
43
  resolveTscJsPath: () => tscResolution.tscJsPath,
41
44
  }));
42
45
  const typescriptGoTscJsPath = path.join(path.dirname(createRequire(import.meta.url).resolve("typescript-go/package.json")), "lib", "tsc.js");
@@ -1 +1 @@
1
- {"version":3,"file":"emit-ts-declarations.test.js","sourceRoot":"","sources":["../../src/compiler/emit-ts-declarations.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,aAAa,IAAI,iBA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AE,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;AACF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,yFAAyF,EAAE,KAAK,IAAI,EAAE;IAC1G,aAAa,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAClC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,EACnC,mBAAmB,CACnB,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,sBAAsB,EAAE,CAAC;IAE/C,MAAM,MAAM,CACX,cAAc,CAAC;QACd,OAAO;QACP,eAAe,EAAE;YAChB,kBAAkB,EAAE,IAAI;SACxB;KACD,CAAC,CACF,CAAC,OAAO,CAAC,OAAO,CAAC,uDAAuD,CAAC,CAAC;AAC5E,CAAC,CAAC,CAAC","sourcesContent":["import { beforeEach, expect, test, vi } from \"vitest\";\nimport { createProject as typescriptProject, ts } from \"@ts-morph/bootstrap\";\nimport {\n\ttype BundleNested,\n\tinsertBundleNested,\n\tloadProjectInMemory,\n\tnewProject,\n} from \"@inlang/sdk\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { compileProject } from \"./compile-project.js\";\n\n// TypeScript 7 (the Go-based compiler, npm `latest` since 7.0.2) no longer\n// ships the in-process compiler API. Its main entry point only exports\n// `version` and `versionMajorMinor` — no `createProgram`, no `ScriptTarget`,\n// no `ModuleKind`. Emitting declarations must go through the `tsc` CLI\n// instead. https://github.com/opral/paraglide-js/issues/711\n//\n// The repo's own `typescript` dev dependency stays on 5.x for the existing\n// tests; this file swaps in the aliased TypeScript 7 package to simulate a\n// user who upgraded.\n//\n// Note: vitest wraps factory mocks in a proxy that throws on missing exports.\n// The real TypeScript 7 module returns `undefined` for them instead, so the\n// classic compiler API surface is stubbed out explicitly to mirror that.\nvi.mock(\"typescript\", async () => {\n\tconst actual =\n\t\tawait vi.importActual<typeof import(\"typescript-go\")>(\"typescript-go\");\n\treturn {\n\t\t...actual,\n\t\tcreateProgram: undefined,\n\t\tcreateCompilerHost: undefined,\n\t\tcreateSourceFile: undefined,\n\t\tScriptTarget: undefined,\n\t\tScriptKind: undefined,\n\t\tModuleKind: undefined,\n\t\tModuleResolutionKind: undefined,\n\t};\n});\n\n// In production, the `typescript` module and the `tsc` CLI resolve to the\n// same package. In this test the module is mocked with the TypeScript 7\n// alias, so the CLI resolution must point at that alias too — otherwise it\n// would find the repo's TypeScript 5 dev dependency. Mutable so the error\n// path can be tested with a broken resolution.\nconst tscResolution = vi.hoisted(() => ({ tscJsPath: \"\" }));\n\nvi.mock(\"./resolve-tsc-js-path.js\", () => ({\n\tresolveTscJsPath: () => tscResolution.tscJsPath,\n}));\n\nconst typescriptGoTscJsPath = path.join(\n\tpath.dirname(\n\t\tcreateRequire(import.meta.url).resolve(\"typescript-go/package.json\")\n\t),\n\t\"lib\",\n\t\"tsc.js\"\n);\n\nbeforeEach(() => {\n\ttscResolution.tscJsPath = typescriptGoTscJsPath;\n});\n\nasync function newProjectWithMessages() {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tlocales: [\"en\"],\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t},\n\t\t}),\n\t});\n\n\t// a message id that is not a valid JS identifier -> quoted export alias\n\tconst quotedAliasBundle: BundleNested = {\n\t\tid: \"greeting.hello\",\n\t\tdeclarations: [],\n\t\tmessages: [\n\t\t\t{\n\t\t\t\tid: \"greeting.hello_en\",\n\t\t\t\tbundle_id: \"greeting.hello\",\n\t\t\t\tlocale: \"en\",\n\t\t\t\tselectors: [],\n\t\t\t\tvariants: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"greeting.hello_en_variant\",\n\t\t\t\t\t\tmessage_id: \"greeting.hello\",\n\t\t\t\t\t\tmatches: [],\n\t\t\t\t\t\tpattern: [{ type: \"text\", value: \"Hello\" }],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\t// a message with an input so the declarations carry a typed parameter\n\tconst parameterizedBundle: BundleNested = {\n\t\tid: \"balance\",\n\t\tdeclarations: [{ type: \"input-variable\", name: \"amount\" }],\n\t\tmessages: [\n\t\t\t{\n\t\t\t\tid: \"balance_en\",\n\t\t\t\tbundle_id: \"balance\",\n\t\t\t\tlocale: \"en\",\n\t\t\t\tselectors: [],\n\t\t\t\tvariants: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"balance_en_variant\",\n\t\t\t\t\t\tmessage_id: \"balance\",\n\t\t\t\t\t\tmatches: [],\n\t\t\t\t\t\tpattern: [\n\t\t\t\t\t\t\t{ type: \"text\", value: \"You have \" },\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\t\t\t\targ: { type: \"variable-reference\", name: \"amount\" },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ type: \"text\", value: \" coins.\" },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tawait insertBundleNested(project.db, quotedAliasBundle);\n\tawait insertBundleNested(project.db, parameterizedBundle);\n\treturn project;\n}\n\ntest(\"emitTsDeclarations works with TypeScript 7 (tsgo)\", async () => {\n\tconst project = await newProjectWithMessages();\n\n\tfor (const outputStructure of [\n\t\t\"message-modules\",\n\t\t\"locale-modules\",\n\t] as const) {\n\t\tconst output = await compileProject({\n\t\t\tproject,\n\t\t\tcompilerOptions: {\n\t\t\t\temitTsDeclarations: true,\n\t\t\t\toutputStructure,\n\t\t\t\t// path-traversing keys (incl. Windows separators) must be\n\t\t\t\t// silently skipped like on the compiler-API path — neither\n\t\t\t\t// escaping the temp dir nor failing the completeness check\n\t\t\t\tadditionalFiles: {\n\t\t\t\t\t\"../escape.js\": \"export const escape = 1;\",\n\t\t\t\t\t\"foo\\\\..\\\\..\\\\escape.js\": \"export const escape = 1;\",\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\texpect(output[\"../escape.d.ts\"]).toBeUndefined();\n\t\texpect(output[\"foo\\\\..\\\\..\\\\escape.d.ts\"]).toBeUndefined();\n\n\t\texpect(output).toHaveProperty(\"runtime.d.ts\");\n\t\texpect(output).toHaveProperty(\"messages.d.ts\");\n\t\texpect(output).toHaveProperty(\"registry.d.ts\");\n\t\texpect(output[\"runtime.d.ts\"]).toContain(\"getLocale\");\n\n\t\t// TypeScript 5's declaration emitter drops the quotes around export\n\t\t// aliases that are not valid identifiers (worked around by a custom\n\t\t// transformer on the compiler-API path); tsgo emits them correctly.\n\t\tconst declarationFile =\n\t\t\toutputStructure === \"message-modules\"\n\t\t\t\t? \"messages/greeting_hello.d.ts\"\n\t\t\t\t: \"messages/_index.d.ts\";\n\n\t\texpect(output[declarationFile]).toContain(`as \"greeting.hello\"`);\n\n\t\t// the emitted declarations must typecheck for a consumer\n\t\t// (@ts-morph/bootstrap bundles its own compiler and is unaffected\n\t\t// by the TypeScript 7 mock above)\n\t\tconst tsProject = await typescriptProject({\n\t\t\tuseInMemoryFileSystem: true,\n\t\t\tcompilerOptions: {\n\t\t\t\tmodule: ts.ModuleKind.Node16,\n\t\t\t\tmoduleResolution: ts.ModuleResolutionKind.Node16,\n\t\t\t\tstrict: true,\n\t\t\t},\n\t\t});\n\n\t\tfor (const [fileName, code] of Object.entries(output)) {\n\t\t\tif (fileName.endsWith(\".d.ts\")) {\n\t\t\t\ttsProject.createSourceFile(fileName, code);\n\t\t\t}\n\t\t}\n\n\t\ttsProject.createSourceFile(\n\t\t\t\"test.ts\",\n\t\t\t`\n\t\t\t\timport { \"greeting.hello\" as greetingHello, balance } from \"./messages.js\";\n\n\t\t\t\tgreetingHello() satisfies string;\n\t\t\t\tbalance({ amount: 5 }) satisfies string;\n\t\t\t`\n\t\t);\n\n\t\tconst program = tsProject.createProgram();\n\t\tconst diagnostics = ts.getPreEmitDiagnostics(program);\n\t\tfor (const diagnostic of diagnostics) {\n\t\t\tconsole.error(diagnostic.messageText, diagnostic.file?.fileName);\n\t\t}\n\t\texpect(diagnostics.length).toEqual(0);\n\t}\n});\n\ntest(\"emitTsDeclarations throws a descriptive error when the tsc CLI produces no declarations\", async () => {\n\ttscResolution.tscJsPath = path.join(\n\t\tpath.dirname(typescriptGoTscJsPath),\n\t\t\"does-not-exist.js\"\n\t);\n\n\tconst project = await newProjectWithMessages();\n\n\tawait expect(\n\t\tcompileProject({\n\t\t\tproject,\n\t\t\tcompilerOptions: {\n\t\t\t\temitTsDeclarations: true,\n\t\t\t},\n\t\t})\n\t).rejects.toThrow(/did not produce a declaration file for every compiled/);\n});\n"]}
1
+ {"version":3,"file":"emit-ts-declarations.test.js","sourceRoot":"","sources":["../../src/compiler/emit-ts-declarations.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAEN,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,2EAA2E;AAC3E,uEAAuE;AACvE,6EAA6E;AAC7E,uEAAuE;AACvE,4DAA4D;AAC5D,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,qBAAqB;AACrB,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,yEAAyE;AACzE,EAAE,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,IAAI,EAAE;IAChC,MAAM,MAAM,GACX,MAAM,EAAE,CAAC,YAAY,CAAiC,eAAe,CAAC,CAAC;I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xB;KACD,CAAC,CACF,CAAC,OAAO,CAAC,OAAO,CAAC,uDAAuD,CAAC,CAAC;AAC5E,CAAC,CAAC,CAAC","sourcesContent":["import { beforeEach, expect, test, vi } from \"vitest\";\nimport { createProject as typescriptProject, ts } from \"@ts-morph/bootstrap\";\nimport {\n\ttype BundleNested,\n\tinsertBundleNested,\n\tloadProjectInMemory,\n\tnewProject,\n} from \"@inlang/sdk\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { compileProject } from \"./compile-project.js\";\n\n// TypeScript 7 (the Go-based compiler, npm `latest` since 7.0.2) no longer\n// ships the in-process compiler API. Its main entry point only exports\n// `version` and `versionMajorMinor` — no `createProgram`, no `ScriptTarget`,\n// no `ModuleKind`. Emitting declarations must go through the `tsc` CLI\n// instead. https://github.com/opral/paraglide-js/issues/711\n//\n// The repo's own `typescript` dev dependency stays on 5.x for the existing\n// tests; this file swaps in the aliased TypeScript 7 package to simulate a\n// user who upgraded.\n//\n// Note: vitest wraps factory mocks in a proxy that throws on missing exports.\n// The real TypeScript 7 module returns `undefined` for them instead, so the\n// classic compiler API surface is stubbed out explicitly to mirror that.\nvi.mock(\"typescript\", async () => {\n\tconst actual =\n\t\tawait vi.importActual<typeof import(\"typescript-go\")>(\"typescript-go\");\n\treturn {\n\t\t...actual,\n\t\tcreateProgram: undefined,\n\t\tcreateCompilerHost: undefined,\n\t\tcreateSourceFile: undefined,\n\t\tScriptTarget: undefined,\n\t\tScriptKind: undefined,\n\t\tModuleKind: undefined,\n\t\tModuleResolutionKind: undefined,\n\t};\n});\n\n// In production, the `typescript` module and the `tsc` CLI resolve to the\n// same package. In this test the module is mocked with the TypeScript 7\n// alias, so the CLI resolution must point at that alias too — otherwise it\n// would find the repo's TypeScript 5 dev dependency. Mutable so the error\n// path can be tested with a broken resolution.\nconst tscResolution = vi.hoisted(() => ({ tscJsPath: \"\" }));\n\nvi.mock(\"./resolve-tsc-js-path.js\", () => ({\n\tresolveNativeTscJsPath: () => {\n\t\tthrow new Error(\"@typescript/native must not replace TypeScript 7's tsc\");\n\t},\n\tresolveTscJsPath: () => tscResolution.tscJsPath,\n}));\n\nconst typescriptGoTscJsPath = path.join(\n\tpath.dirname(\n\t\tcreateRequire(import.meta.url).resolve(\"typescript-go/package.json\")\n\t),\n\t\"lib\",\n\t\"tsc.js\"\n);\n\nbeforeEach(() => {\n\ttscResolution.tscJsPath = typescriptGoTscJsPath;\n});\n\nasync function newProjectWithMessages() {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tlocales: [\"en\"],\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t},\n\t\t}),\n\t});\n\n\t// a message id that is not a valid JS identifier -> quoted export alias\n\tconst quotedAliasBundle: BundleNested = {\n\t\tid: \"greeting.hello\",\n\t\tdeclarations: [],\n\t\tmessages: [\n\t\t\t{\n\t\t\t\tid: \"greeting.hello_en\",\n\t\t\t\tbundle_id: \"greeting.hello\",\n\t\t\t\tlocale: \"en\",\n\t\t\t\tselectors: [],\n\t\t\t\tvariants: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"greeting.hello_en_variant\",\n\t\t\t\t\t\tmessage_id: \"greeting.hello\",\n\t\t\t\t\t\tmatches: [],\n\t\t\t\t\t\tpattern: [{ type: \"text\", value: \"Hello\" }],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\t// a message with an input so the declarations carry a typed parameter\n\tconst parameterizedBundle: BundleNested = {\n\t\tid: \"balance\",\n\t\tdeclarations: [{ type: \"input-variable\", name: \"amount\" }],\n\t\tmessages: [\n\t\t\t{\n\t\t\t\tid: \"balance_en\",\n\t\t\t\tbundle_id: \"balance\",\n\t\t\t\tlocale: \"en\",\n\t\t\t\tselectors: [],\n\t\t\t\tvariants: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"balance_en_variant\",\n\t\t\t\t\t\tmessage_id: \"balance\",\n\t\t\t\t\t\tmatches: [],\n\t\t\t\t\t\tpattern: [\n\t\t\t\t\t\t\t{ type: \"text\", value: \"You have \" },\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\t\t\t\targ: { type: \"variable-reference\", name: \"amount\" },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ type: \"text\", value: \" coins.\" },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tawait insertBundleNested(project.db, quotedAliasBundle);\n\tawait insertBundleNested(project.db, parameterizedBundle);\n\treturn project;\n}\n\ntest(\"emitTsDeclarations works with TypeScript 7 (tsgo)\", async () => {\n\tconst project = await newProjectWithMessages();\n\n\tfor (const outputStructure of [\n\t\t\"message-modules\",\n\t\t\"locale-modules\",\n\t] as const) {\n\t\tconst output = await compileProject({\n\t\t\tproject,\n\t\t\tcompilerOptions: {\n\t\t\t\temitTsDeclarations: true,\n\t\t\t\toutputStructure,\n\t\t\t\t// path-traversing keys (incl. Windows separators) must be\n\t\t\t\t// silently skipped like on the compiler-API path — neither\n\t\t\t\t// escaping the temp dir nor failing the completeness check\n\t\t\t\tadditionalFiles: {\n\t\t\t\t\t\"../escape.js\": \"export const escape = 1;\",\n\t\t\t\t\t\"foo\\\\..\\\\..\\\\escape.js\": \"export const escape = 1;\",\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\texpect(output[\"../escape.d.ts\"]).toBeUndefined();\n\t\texpect(output[\"foo\\\\..\\\\..\\\\escape.d.ts\"]).toBeUndefined();\n\n\t\texpect(output).toHaveProperty(\"runtime.d.ts\");\n\t\texpect(output).toHaveProperty(\"messages.d.ts\");\n\t\texpect(output).toHaveProperty(\"registry.d.ts\");\n\t\texpect(output[\"runtime.d.ts\"]).toContain(\"getLocale\");\n\n\t\t// TypeScript 5's declaration emitter drops the quotes around export\n\t\t// aliases that are not valid identifiers (worked around by a custom\n\t\t// transformer on the compiler-API path); tsgo emits them correctly.\n\t\tconst declarationFile =\n\t\t\toutputStructure === \"message-modules\"\n\t\t\t\t? \"messages/greeting_hello.d.ts\"\n\t\t\t\t: \"messages/_index.d.ts\";\n\n\t\texpect(output[declarationFile]).toContain(`as \"greeting.hello\"`);\n\n\t\t// the emitted declarations must typecheck for a consumer\n\t\t// (@ts-morph/bootstrap bundles its own compiler and is unaffected\n\t\t// by the TypeScript 7 mock above)\n\t\tconst tsProject = await typescriptProject({\n\t\t\tuseInMemoryFileSystem: true,\n\t\t\tcompilerOptions: {\n\t\t\t\tmodule: ts.ModuleKind.Node16,\n\t\t\t\tmoduleResolution: ts.ModuleResolutionKind.Node16,\n\t\t\t\tstrict: true,\n\t\t\t},\n\t\t});\n\n\t\tfor (const [fileName, code] of Object.entries(output)) {\n\t\t\tif (fileName.endsWith(\".d.ts\")) {\n\t\t\t\ttsProject.createSourceFile(fileName, code);\n\t\t\t}\n\t\t}\n\n\t\ttsProject.createSourceFile(\n\t\t\t\"test.ts\",\n\t\t\t`\n\t\t\t\timport { \"greeting.hello\" as greetingHello, balance } from \"./messages.js\";\n\n\t\t\t\tgreetingHello() satisfies string;\n\t\t\t\tbalance({ amount: 5 }) satisfies string;\n\t\t\t`\n\t\t);\n\n\t\tconst program = tsProject.createProgram();\n\t\tconst diagnostics = ts.getPreEmitDiagnostics(program);\n\t\tfor (const diagnostic of diagnostics) {\n\t\t\tconsole.error(diagnostic.messageText, diagnostic.file?.fileName);\n\t\t}\n\t\texpect(diagnostics.length).toEqual(0);\n\t}\n});\n\ntest(\"emitTsDeclarations throws a descriptive error when the tsc CLI produces no declarations\", async () => {\n\ttscResolution.tscJsPath = path.join(\n\t\tpath.dirname(typescriptGoTscJsPath),\n\t\t\"does-not-exist.js\"\n\t);\n\n\tconst project = await newProjectWithMessages();\n\n\tawait expect(\n\t\tcompileProject({\n\t\t\tproject,\n\t\t\tcompilerOptions: {\n\t\t\t\temitTsDeclarations: true,\n\t\t\t},\n\t\t})\n\t).rejects.toThrow(/did not produce a declaration file for every compiled/);\n});\n"]}
@@ -7,3 +7,9 @@
7
7
  * itself depends on.
8
8
  */
9
9
  export declare function resolveTscJsPath(): string;
10
+ /**
11
+ * Resolves the `tsc` CLI of TypeScript 7+ installed beside TypeScript 5/6
12
+ * under the `@typescript/native` npm alias, as documented for
13
+ * `svelte-check --tsgo`, or returns `undefined` when there is none.
14
+ */
15
+ export declare function resolveNativeTscJsPath(): string | undefined;
@@ -1,6 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
- import { existsSync } from "node:fs";
2
+ import { existsSync, readFileSync } from "node:fs";
3
3
  import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
4
5
  /**
5
6
  * Resolves the path to the `tsc` CLI entry point of the installed
6
7
  * `typescript` package.
@@ -20,4 +21,36 @@ export function resolveTscJsPath() {
20
21
  }
21
22
  return tscJsPath;
22
23
  }
24
+ /**
25
+ * Resolves the `tsc` CLI of TypeScript 7+ installed beside TypeScript 5/6
26
+ * under the `@typescript/native` npm alias, as documented for
27
+ * `svelte-check --tsgo`, or returns `undefined` when there is none.
28
+ */
29
+ export function resolveNativeTscJsPath() {
30
+ const require = createRequire(import.meta.url);
31
+ try {
32
+ // the working directory first, so that an app's alias is found in a
33
+ // workspace without hoisting
34
+ const packageJsonPath = require.resolve("@typescript/native/package.json", {
35
+ paths: [process.cwd(), path.dirname(fileURLToPath(import.meta.url))],
36
+ });
37
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
38
+ const version = typeof packageJson === "object" &&
39
+ packageJson !== null &&
40
+ "version" in packageJson
41
+ ? packageJson.version
42
+ : undefined;
43
+ // the CLI of TypeScript 5/6 emits invalid quoted export aliases, which
44
+ // only the compiler-API path corrects
45
+ const isTypeScript7OrNewer = typeof version === "string" && Number.parseInt(version, 10) >= 7;
46
+ const tscJsPath = path.join(path.dirname(packageJsonPath), "lib", "tsc.js");
47
+ return isTypeScript7OrNewer && existsSync(tscJsPath)
48
+ ? tscJsPath
49
+ : undefined;
50
+ }
51
+ catch {
52
+ // an alias that can't be read leaves the other emit paths in place
53
+ return undefined;
54
+ }
55
+ }
23
56
  //# sourceMappingURL=resolve-tsc-js-path.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-tsc-js-path.js","sourceRoot":"","sources":["../../src/compiler/resolve-tsc-js-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB;IAC/B,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACnE,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5E,0EAA0E;IAC1E,qEAAqE;IACrE,IAAI,UAAU,CAAC,SAAS,CAAC,KAAK,KAAK,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACd,sFAAsF,SAAS,gFAAgF,CAC/K,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { createRequire } from \"node:module\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Resolves the path to the `tsc` CLI entry point of the installed\n * `typescript` package.\n *\n * Lives in its own module so tests can point the TypeScript 7 emit\n * path at a different TypeScript installation than the one the repo\n * itself depends on.\n */\nexport function resolveTscJsPath(): string {\n\tconst require = createRequire(import.meta.url);\n\tconst packageJsonPath = require.resolve(\"typescript/package.json\");\n\tconst tscJsPath = path.join(path.dirname(packageJsonPath), \"lib\", \"tsc.js\");\n\t// `lib/tsc.js` is internal package layout rather than a public export, so\n\t// fail with a pointed error if a future TypeScript version moves it.\n\tif (existsSync(tscJsPath) === false) {\n\t\tthrow new Error(\n\t\t\t`Paraglide's \"emitTsDeclarations\" option could not locate TypeScript's \"tsc\" CLI at ${tscJsPath}. As a workaround, install TypeScript 5 or 6, or disable \"emitTsDeclarations\".`\n\t\t);\n\t}\n\treturn tscJsPath;\n}\n"]}
1
+ {"version":3,"file":"resolve-tsc-js-path.js","sourceRoot":"","sources":["../../src/compiler/resolve-tsc-js-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB;IAC/B,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACnE,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5E,0EAA0E;IAC1E,qEAAqE;IACrE,IAAI,UAAU,CAAC,SAAS,CAAC,KAAK,KAAK,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACd,sFAAsF,SAAS,gFAAgF,CAC/K,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB;IACrC,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,IAAI,CAAC;QACJ,oEAAoE;QACpE,6BAA6B;QAC7B,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,iCAAiC,EAAE;YAC1E,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;SACpE,CAAC,CAAC;QACH,MAAM,WAAW,GAAY,IAAI,CAAC,KAAK,CACtC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CACtC,CAAC;QACF,MAAM,OAAO,GACZ,OAAO,WAAW,KAAK,QAAQ;YAC/B,WAAW,KAAK,IAAI;YACpB,SAAS,IAAI,WAAW;YACvB,CAAC,CAAC,WAAW,CAAC,OAAO;YACrB,CAAC,CAAC,SAAS,CAAC;QACd,uEAAuE;QACvE,sCAAsC;QACtC,MAAM,oBAAoB,GACzB,OAAO,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;QAClE,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC5E,OAAO,oBAAoB,IAAI,UAAU,CAAC,SAAS,CAAC;YACnD,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACR,mEAAmE;QACnE,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC","sourcesContent":["import { createRequire } from \"node:module\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n/**\n * Resolves the path to the `tsc` CLI entry point of the installed\n * `typescript` package.\n *\n * Lives in its own module so tests can point the TypeScript 7 emit\n * path at a different TypeScript installation than the one the repo\n * itself depends on.\n */\nexport function resolveTscJsPath(): string {\n\tconst require = createRequire(import.meta.url);\n\tconst packageJsonPath = require.resolve(\"typescript/package.json\");\n\tconst tscJsPath = path.join(path.dirname(packageJsonPath), \"lib\", \"tsc.js\");\n\t// `lib/tsc.js` is internal package layout rather than a public export, so\n\t// fail with a pointed error if a future TypeScript version moves it.\n\tif (existsSync(tscJsPath) === false) {\n\t\tthrow new Error(\n\t\t\t`Paraglide's \"emitTsDeclarations\" option could not locate TypeScript's \"tsc\" CLI at ${tscJsPath}. As a workaround, install TypeScript 5 or 6, or disable \"emitTsDeclarations\".`\n\t\t);\n\t}\n\treturn tscJsPath;\n}\n\n/**\n * Resolves the `tsc` CLI of TypeScript 7+ installed beside TypeScript 5/6\n * under the `@typescript/native` npm alias, as documented for\n * `svelte-check --tsgo`, or returns `undefined` when there is none.\n */\nexport function resolveNativeTscJsPath(): string | undefined {\n\tconst require = createRequire(import.meta.url);\n\ttry {\n\t\t// the working directory first, so that an app's alias is found in a\n\t\t// workspace without hoisting\n\t\tconst packageJsonPath = require.resolve(\"@typescript/native/package.json\", {\n\t\t\tpaths: [process.cwd(), path.dirname(fileURLToPath(import.meta.url))],\n\t\t});\n\t\tconst packageJson: unknown = JSON.parse(\n\t\t\treadFileSync(packageJsonPath, \"utf-8\")\n\t\t);\n\t\tconst version =\n\t\t\ttypeof packageJson === \"object\" &&\n\t\t\tpackageJson !== null &&\n\t\t\t\"version\" in packageJson\n\t\t\t\t? packageJson.version\n\t\t\t\t: undefined;\n\t\t// the CLI of TypeScript 5/6 emits invalid quoted export aliases, which\n\t\t// only the compiler-API path corrects\n\t\tconst isTypeScript7OrNewer =\n\t\t\ttypeof version === \"string\" && Number.parseInt(version, 10) >= 7;\n\t\tconst tscJsPath = path.join(path.dirname(packageJsonPath), \"lib\", \"tsc.js\");\n\t\treturn isTypeScript7OrNewer && existsSync(tscJsPath)\n\t\t\t? tscJsPath\n\t\t\t: undefined;\n\t} catch {\n\t\t// an alias that can't be read leaves the other emit paths in place\n\t\treturn undefined;\n\t}\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import { expect, test, vi } from "vitest";
2
+ import fs from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { resolveNativeTscJsPath } from "./resolve-tsc-js-path.js";
6
+ test("resolveNativeTscJsPath only accepts TypeScript 7+ under the @typescript/native alias", async () => {
7
+ const project = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), "paraglide-native-tsc-")));
8
+ const alias = path.join(project, "node_modules", "@typescript", "native");
9
+ const tscJsPath = path.join(alias, "lib", "tsc.js");
10
+ await fs.mkdir(path.dirname(tscJsPath), { recursive: true });
11
+ await fs.writeFile(tscJsPath, "");
12
+ vi.spyOn(process, "cwd").mockReturnValue(project);
13
+ try {
14
+ const cases = [
15
+ [{ name: "typescript", version: "7.0.2" }, tscJsPath],
16
+ // the CLI of TypeScript 5/6 would emit invalid quoted export aliases
17
+ [{ name: "typescript", version: "6.0.3" }, undefined],
18
+ [{ name: "typescript" }, undefined],
19
+ [null, undefined],
20
+ ];
21
+ for (const [packageJson, expected] of cases) {
22
+ await fs.writeFile(path.join(alias, "package.json"), JSON.stringify(packageJson));
23
+ expect(resolveNativeTscJsPath()).toBe(expected);
24
+ }
25
+ }
26
+ finally {
27
+ vi.restoreAllMocks();
28
+ await fs.rm(project, { recursive: true, force: true });
29
+ }
30
+ });
31
+ //# sourceMappingURL=resolve-tsc-js-path.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-tsc-js-path.test.js","sourceRoot":"","sources":["../../src/compiler/resolve-tsc-js-path.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,IAAI,CAAC,sFAAsF,EAAE,KAAK,IAAI,EAAE;IACvG,MAAM,OAAO,GA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Q,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;YAAS,CAAC;QACV,EAAE,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,CAAC;AACF,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test, vi } from \"vitest\";\nimport fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { resolveNativeTscJsPath } from \"./resolve-tsc-js-path.js\";\n\ntest(\"resolveNativeTscJsPath only accepts TypeScript 7+ under the @typescript/native alias\", async () => {\n\tconst project = await fs.realpath(\n\t\tawait fs.mkdtemp(path.join(os.tmpdir(), \"paraglide-native-tsc-\"))\n\t);\n\tconst alias = path.join(project, \"node_modules\", \"@typescript\", \"native\");\n\tconst tscJsPath = path.join(alias, \"lib\", \"tsc.js\");\n\tawait fs.mkdir(path.dirname(tscJsPath), { recursive: true });\n\tawait fs.writeFile(tscJsPath, \"\");\n\tvi.spyOn(process, \"cwd\").mockReturnValue(project);\n\n\ttry {\n\t\tconst cases: Array<[packageJson: unknown, expected: string | undefined]> = [\n\t\t\t[{ name: \"typescript\", version: \"7.0.2\" }, tscJsPath],\n\t\t\t// the CLI of TypeScript 5/6 would emit invalid quoted export aliases\n\t\t\t[{ name: \"typescript\", version: \"6.0.3\" }, undefined],\n\t\t\t[{ name: \"typescript\" }, undefined],\n\t\t\t[null, undefined],\n\t\t];\n\t\tfor (const [packageJson, expected] of cases) {\n\t\t\tawait fs.writeFile(\n\t\t\t\tpath.join(alias, \"package.json\"),\n\t\t\t\tJSON.stringify(packageJson)\n\t\t\t);\n\t\t\texpect(resolveNativeTscJsPath()).toBe(expected);\n\t\t}\n\t} finally {\n\t\tvi.restoreAllMocks();\n\t\tawait fs.rm(project, { recursive: true, force: true });\n\t}\n});\n"]}
@@ -1,4 +1,4 @@
1
1
  export const ENV_VARIABLES = {
2
- PARJS_PACKAGE_VERSION: "2.29.1",
2
+ PARJS_PACKAGE_VERSION: "2.29.2",
3
3
  };
4
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/env-variables/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,qBAAqB,EAAE,QAAQ;CAC/B,CAAA","sourcesContent":["\nexport const ENV_VARIABLES = {\n\tPARJS_PACKAGE_VERSION: \"2.29.1\",\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/env-variables/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,qBAAqB,EAAE,QAAQ;CAC/B,CAAA","sourcesContent":["\nexport const ENV_VARIABLES = {\n\tPARJS_PACKAGE_VERSION: \"2.29.2\",\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@inlang/paraglide-js",
3
3
  "type": "module",
4
- "version": "2.29.1",
4
+ "version": "2.29.2",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public",