@generaltranslation/vue-extractor 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE.md +105 -0
  2. package/dist/config.d.ts +2 -0
  3. package/dist/config.js +2 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +2 -0
  6. package/dist/internal/compilerAst.d.ts +43 -0
  7. package/dist/internal/compilerAst.js +77 -0
  8. package/dist/internal/compilerAst.js.map +1 -0
  9. package/dist/internal/config/resolveVueCompilerOptions.d.ts +23 -0
  10. package/dist/internal/config/resolveVueCompilerOptions.js +987 -0
  11. package/dist/internal/config/resolveVueCompilerOptions.js.map +1 -0
  12. package/dist/internal/extractFromVueSource.d.ts +9 -0
  13. package/dist/internal/extractFromVueSource.js +332 -0
  14. package/dist/internal/extractFromVueSource.js.map +1 -0
  15. package/dist/internal/script/analyze.d.ts +13 -0
  16. package/dist/internal/script/analyze.js +4761 -0
  17. package/dist/internal/script/analyze.js.map +1 -0
  18. package/dist/internal/script/jsx.d.ts +36 -0
  19. package/dist/internal/script/jsx.js +667 -0
  20. package/dist/internal/script/jsx.js.map +1 -0
  21. package/dist/internal/script/knownValues.d.ts +14 -0
  22. package/dist/internal/script/knownValues.js +148 -0
  23. package/dist/internal/script/knownValues.js.map +1 -0
  24. package/dist/internal/script/localModules.d.ts +80 -0
  25. package/dist/internal/script/localModules.js +364 -0
  26. package/dist/internal/script/localModules.js.map +1 -0
  27. package/dist/internal/script/model.d.ts +317 -0
  28. package/dist/internal/script/model.js +1 -0
  29. package/dist/internal/script/parser.d.ts +3 -0
  30. package/dist/internal/script/parser.js +21 -0
  31. package/dist/internal/script/parser.js.map +1 -0
  32. package/dist/internal/script/replay.d.ts +53 -0
  33. package/dist/internal/script/replay.js +1611 -0
  34. package/dist/internal/script/replay.js.map +1 -0
  35. package/dist/internal/script/snapshot.d.ts +25 -0
  36. package/dist/internal/script/snapshot.js +293 -0
  37. package/dist/internal/script/snapshot.js.map +1 -0
  38. package/dist/internal/script/syntax.d.ts +21 -0
  39. package/dist/internal/script/syntax.js +46 -0
  40. package/dist/internal/script/syntax.js.map +1 -0
  41. package/dist/internal/script.d.ts +2 -0
  42. package/dist/internal/script.js +2 -0
  43. package/dist/internal/stringCalls.d.ts +7 -0
  44. package/dist/internal/stringCalls.js +82 -0
  45. package/dist/internal/stringCalls.js.map +1 -0
  46. package/dist/internal/template.d.ts +4 -0
  47. package/dist/internal/template.js +2198 -0
  48. package/dist/internal/template.js.map +1 -0
  49. package/dist/internal/templatePath.d.ts +12 -0
  50. package/dist/internal/templatePath.js +23 -0
  51. package/dist/internal/templatePath.js.map +1 -0
  52. package/dist/internal/types.d.ts +69 -0
  53. package/dist/internal/types.js +1 -0
  54. package/dist/internal/utils.d.ts +19 -0
  55. package/dist/internal/utils.js +149 -0
  56. package/dist/internal/utils.js.map +1 -0
  57. package/dist/internal/vueCompiler.d.ts +35 -0
  58. package/dist/internal/vueCompiler.js +320 -0
  59. package/dist/internal/vueCompiler.js.map +1 -0
  60. package/dist/types.d.ts +80 -0
  61. package/dist/types.js +1 -0
  62. package/package.json +78 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vueCompiler.js","names":[],"sources":["../../src/internal/vueCompiler.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport type { parse as parseVueTemplate } from '@vue/compiler-dom';\nimport type * as VueCompilerModule from '@vue/compiler-sfc';\nimport type { TemplateCompiler } from '@vue/compiler-sfc';\nimport type { VueCompiler } from '../types.js';\n\n/** Whitespace test used by Vue when it constructs an implicit default slot. */\nexport type ImplicitSlotWhitespace = 'ecmascript' | 'html';\n\nexport type ResolvedVueCompiler = {\n compiler: ExactVueCompiler;\n implicitSlotWhitespace: ImplicitSlotWhitespace;\n parseTemplate?: typeof parseVueTemplate;\n templateCompiler?: TemplateCompiler;\n templateParseOptionsSupported: boolean;\n version: string;\n};\n\ntype CompilerResolution =\n | { ok: true; value: ResolvedVueCompiler }\n | { ok: false; details: string };\n\nconst resolvedCompilers = new Map<string, CompilerResolution>();\nconst inspectedCompilers = new WeakMap<object, CompilerResolution>();\n\ntype ExactVueCompiler = Pick<\n typeof VueCompilerModule,\n 'compileTemplate' | 'parse' | 'version'\n> & {\n parseTemplate?: typeof parseVueTemplate;\n};\n\n/**\n * Resolves the exact Vue compiler selected by the consuming source file.\n *\n * The `vue/compiler-sfc` export is version-locked to that installation's Vue\n * runtime. Resolving from the SFC first is important in workspaces where apps\n * intentionally use different Vue versions.\n */\nexport function resolveVueCompiler(\n file: string,\n projectRoot: string\n): CompilerResolution {\n const absoluteFile = path.isAbsolute(file)\n ? file\n : path.resolve(projectRoot, file);\n const anchors = [absoluteFile, path.join(projectRoot, 'package.json')];\n\n for (const anchor of anchors) {\n const requireFromConsumer = createRequire(anchor);\n let vueManifestPath: string;\n try {\n vueManifestPath = requireFromConsumer.resolve('vue/package.json');\n } catch (error) {\n if (isMissingModule(error)) continue;\n return {\n ok: false,\n details: formatResolutionError(error),\n };\n }\n\n let compilerPath: string;\n try {\n compilerPath = requireFromConsumer.resolve('vue/compiler-sfc');\n } catch (error) {\n return {\n ok: false,\n details: `Resolved the app's Vue package at ${vueManifestPath}, but its compiler-sfc export could not be loaded: ${formatResolutionError(error)}`,\n };\n }\n\n const cached = resolvedCompilers.get(compilerPath);\n if (cached) return cached;\n\n const resolution = loadCompiler(\n requireFromConsumer,\n compilerPath,\n vueManifestPath,\n readVueVersion(requireFromConsumer, vueManifestPath)\n );\n resolvedCompilers.set(compilerPath, resolution);\n return resolution;\n }\n\n const declaredVersion = findDeclaredVueVersion(absoluteFile, projectRoot);\n if (declaredVersion) {\n return {\n ok: false,\n details: `The project declares Vue ${JSON.stringify(declaredVersion)} but vue/compiler-sfc could not be resolved from ${absoluteFile}.`,\n };\n }\n\n return {\n ok: false,\n details: `Could not resolve vue/compiler-sfc from ${absoluteFile}.`,\n };\n}\n\n/** Validates an explicitly supplied compiler before extraction uses it. */\nexport function inspectVueCompiler(compiler: VueCompiler): CompilerResolution {\n if (!compiler || typeof compiler !== 'object') {\n return {\n ok: false,\n details: 'The supplied Vue compiler is not an object.',\n };\n }\n const cached = inspectedCompilers.get(compiler);\n if (cached) return cached;\n const exactCompiler = compiler as ExactVueCompiler;\n const resolution = isVueCompiler(compiler)\n ? inspectCompiler(exactCompiler, exactCompiler.parseTemplate)\n : {\n ok: false as const,\n details:\n 'The supplied object does not expose the Vue compiler-sfc API.',\n };\n inspectedCompilers.set(compiler, resolution);\n return resolution;\n}\n\nfunction loadCompiler(\n requireFromConsumer: NodeRequire,\n compilerPath: string,\n vueManifestPath: string,\n vueVersion: string | undefined\n): CompilerResolution {\n try {\n const loaded = requireFromConsumer(compilerPath) as unknown;\n const defaultExport = readDefaultExport(loaded);\n const compiler = isVueCompiler(loaded)\n ? (loaded as ExactVueCompiler)\n : isVueCompiler(defaultExport)\n ? (defaultExport as ExactVueCompiler)\n : undefined;\n if (!compiler) {\n return {\n ok: false,\n details: `The module at ${compilerPath} does not expose the Vue compiler-sfc API.`,\n };\n }\n if (vueVersion && compiler.version !== vueVersion) {\n return {\n ok: false,\n details: `The app resolves Vue ${vueVersion} but vue/compiler-sfc ${compiler.version}. Install one matching Vue package version.`,\n };\n }\n if (!isSupportedVueVersion(compiler.version)) {\n return {\n ok: false,\n details: `Resolved Vue compiler version ${JSON.stringify(compiler.version)}; gt-vue supports Vue 3.3 through Vue 3.x.`,\n };\n }\n const requireFromCompiler = createRequire(compilerPath);\n const compilerDomPath = requireFromCompiler.resolve('@vue/compiler-dom');\n const compilerDom = requireFromCompiler(compilerDomPath) as {\n compile?: TemplateCompiler['compile'];\n parse?: typeof parseVueTemplate;\n };\n const compilerDomVersion = readVueVersion(\n requireFromCompiler,\n requireFromCompiler.resolve('@vue/compiler-dom/package.json')\n );\n if (compilerDomVersion !== compiler.version) {\n return {\n ok: false,\n details: `vue/compiler-sfc ${compiler.version} resolves @vue/compiler-dom ${String(compilerDomVersion)}. Install matching Vue compiler packages.`,\n };\n }\n if (typeof compilerDom.parse !== 'function') {\n return {\n ok: false,\n details: `The template compiler at ${compilerDomPath} does not expose parse().`,\n };\n }\n if (typeof compilerDom.compile !== 'function') {\n return {\n ok: false,\n details: `The template compiler at ${compilerDomPath} does not expose compile().`,\n };\n }\n return inspectCompiler(compiler, compilerDom.parse, {\n compile: compilerDom.compile,\n parse: compilerDom.parse,\n });\n } catch (error) {\n const bunResolution = loadBunCompiler(\n requireFromConsumer,\n vueManifestPath,\n vueVersion\n );\n if (bunResolution) return bunResolution;\n return { ok: false, details: formatResolutionError(error) };\n }\n}\n\n/** Loads exact, self-contained Vue browser compilers in a compiled Bun CLI. */\nfunction loadBunCompiler(\n requireFromConsumer: NodeRequire,\n vueManifestPath: string,\n vueVersion: string | undefined\n): CompilerResolution | undefined {\n if (typeof process.versions.bun !== 'string') return undefined;\n\n try {\n const compilerSfcRoot = findInstalledPackageRoot(\n vueManifestPath,\n '@vue/compiler-sfc'\n );\n const compilerDomRoot = findInstalledPackageRoot(\n vueManifestPath,\n '@vue/compiler-dom'\n );\n if (!compilerSfcRoot || !compilerDomRoot) {\n return {\n ok: false,\n details:\n 'The Vue installation does not contain its compiler-sfc and compiler-dom dependencies.',\n };\n }\n\n const compilerPath = path.join(\n compilerSfcRoot,\n 'dist/compiler-sfc.esm-browser.js'\n );\n const compilerDomPath = path.join(\n compilerDomRoot,\n 'dist/compiler-dom.esm-browser.js'\n );\n const loaded = requireFromConsumer(compilerPath) as unknown;\n const defaultExport = readDefaultExport(loaded);\n const compiler = isVueCompiler(loaded)\n ? (loaded as ExactVueCompiler)\n : isVueCompiler(defaultExport)\n ? (defaultExport as ExactVueCompiler)\n : undefined;\n if (!compiler) {\n return {\n ok: false,\n details: `The module at ${compilerPath} does not expose the Vue compiler-sfc API.`,\n };\n }\n if (vueVersion && compiler.version !== vueVersion) {\n return {\n ok: false,\n details: `The app resolves Vue ${vueVersion} but vue/compiler-sfc ${compiler.version}. Install one matching Vue package version.`,\n };\n }\n if (!isSupportedVueVersion(compiler.version)) {\n return {\n ok: false,\n details: `Resolved Vue compiler version ${JSON.stringify(compiler.version)}; gt-vue supports Vue 3.3 through Vue 3.x.`,\n };\n }\n\n const compilerDom = requireFromConsumer(compilerDomPath) as {\n compile?: TemplateCompiler['compile'];\n parse?: typeof parseVueTemplate;\n };\n const compilerDomVersion = readPackageVersion(compilerDomRoot);\n if (compilerDomVersion !== compiler.version) {\n return {\n ok: false,\n details: `vue/compiler-sfc ${compiler.version} resolves @vue/compiler-dom ${String(compilerDomVersion)}. Install matching Vue compiler packages.`,\n };\n }\n if (typeof compilerDom.parse !== 'function') {\n return {\n ok: false,\n details: `The template compiler at ${compilerDomPath} does not expose parse().`,\n };\n }\n if (typeof compilerDom.compile !== 'function') {\n return {\n ok: false,\n details: `The template compiler at ${compilerDomPath} does not expose compile().`,\n };\n }\n return inspectCompiler(compiler, compilerDom.parse, {\n compile: compilerDom.compile,\n parse: compilerDom.parse,\n });\n } catch (error) {\n return { ok: false, details: formatResolutionError(error) };\n }\n}\n\n/** Finds one dependency relative to the physical Vue installation on disk. */\nfunction findInstalledPackageRoot(\n vueManifestPath: string,\n packageName: string\n): string | undefined {\n const packageSegments = packageName.split('/');\n let directory = path.dirname(vueManifestPath);\n while (true) {\n const candidate =\n path.basename(directory) === 'node_modules'\n ? path.join(directory, ...packageSegments)\n : path.join(directory, 'node_modules', ...packageSegments);\n if (fs.existsSync(path.join(candidate, 'package.json'))) return candidate;\n const parent = path.dirname(directory);\n if (parent === directory) return undefined;\n directory = parent;\n }\n}\n\nfunction readPackageVersion(packageRoot: string): string | undefined {\n try {\n const manifest = JSON.parse(\n fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8')\n ) as { version?: unknown };\n return typeof manifest.version === 'string' ? manifest.version : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction readVueVersion(\n requireFromConsumer: NodeRequire,\n manifestPath: string\n): string | undefined {\n try {\n const manifest = requireFromConsumer(manifestPath) as { version?: unknown };\n return typeof manifest.version === 'string' ? manifest.version : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** Finds an installed-but-missing declaration that bundled fallback could hide. */\nfunction findDeclaredVueVersion(\n absoluteFile: string,\n projectRoot: string\n): string | undefined {\n const stop = path.resolve(projectRoot);\n let directory = path.dirname(absoluteFile);\n while (true) {\n const version = readDeclaredVueVersion(\n path.join(directory, 'package.json')\n );\n if (version) return version;\n if (directory === stop || directory === path.dirname(directory)) break;\n directory = path.dirname(directory);\n }\n return readDeclaredVueVersion(path.join(stop, 'package.json'));\n}\n\nfunction readDeclaredVueVersion(manifestPath: string): string | undefined {\n try {\n const manifest = JSON.parse(\n fs.readFileSync(manifestPath, 'utf8')\n ) as Record<string, unknown>;\n for (const section of [\n 'dependencies',\n 'devDependencies',\n 'peerDependencies',\n 'optionalDependencies',\n ]) {\n const dependencies = manifest[section];\n if (\n dependencies &&\n typeof dependencies === 'object' &&\n 'vue' in dependencies\n ) {\n const version = (dependencies as Record<string, unknown>).vue;\n return typeof version === 'string' ? version : 'an unknown version';\n }\n }\n } catch (error) {\n if (\n !error ||\n typeof error !== 'object' ||\n !('code' in error) ||\n error.code !== 'ENOENT'\n ) {\n throw error;\n }\n }\n return undefined;\n}\n\nfunction inspectCompiler(\n compiler: ExactVueCompiler,\n parseTemplate?: typeof parseVueTemplate,\n templateCompiler?: TemplateCompiler\n): CompilerResolution {\n const version = compiler.version;\n if (!isSupportedVueVersion(version)) {\n return {\n ok: false,\n details: `Resolved Vue compiler version ${JSON.stringify(version)}; gt-vue supports Vue 3.3 through Vue 3.x.`,\n };\n }\n\n try {\n const templateParseOptionsSupported =\n supportsTemplateParseOptions(compiler);\n if (!parseTemplate && !templateParseOptionsSupported) {\n return {\n ok: false,\n details:\n 'The supplied compiler does not expose exact template parser options. Let the extractor resolve vue/compiler-sfc from the consuming app instead.',\n };\n }\n return {\n ok: true,\n value: {\n compiler,\n implicitSlotWhitespace: detectImplicitSlotWhitespace(compiler),\n parseTemplate,\n templateCompiler,\n templateParseOptionsSupported,\n version,\n },\n };\n } catch (error) {\n return { ok: false, details: formatResolutionError(error) };\n }\n}\n\n/** Detects the SFC parser option added after Vue 3.4. */\nfunction supportsTemplateParseOptions(compiler: ExactVueCompiler): boolean {\n const source = '<template><Probe>First\\n second</Probe></template>';\n const parseText = (whitespace: 'condense' | 'preserve') => {\n const result = compiler.parse(source, {\n templateParseOptions: { whitespace },\n });\n return collectText(result.descriptor.template?.ast);\n };\n return parseText('condense') !== parseText('preserve');\n}\n\nfunction collectText(value: unknown): string {\n if (!value || typeof value !== 'object') return '';\n let output = '';\n if ('type' in value && value.type === 2 && 'content' in value) {\n output += String(value.content);\n }\n if ('children' in value && Array.isArray(value.children)) {\n for (const child of value.children) output += collectText(child);\n }\n return output;\n}\n\n/**\n * Detects the compiler's slot-whitespace semantics instead of inferring them\n * from a semver range. Vue 3.3/3.4 use ECMAScript `trim()`, while Vue 3.5 uses\n * the HTML parser's ASCII whitespace set. A behavior probe remains exact if a\n * later Vue 3.x release backports or revises that implementation.\n */\nfunction detectImplicitSlotWhitespace(\n compiler: ExactVueCompiler\n): ImplicitSlotWhitespace {\n const result = compiler.compileTemplate({\n filename: 'gt-vue-compiler-probe.vue',\n id: 'gt-vue-compiler-probe',\n source: '<Probe><template #named>x</template>&nbsp;</Probe>',\n });\n if (result.errors.length > 0) {\n throw new Error(\n `The Vue compiler compatibility probe failed: ${result.errors.map(String).join('; ')}`\n );\n }\n\n const component = result.ast?.children.find(\n (node) =>\n typeof node === 'object' &&\n node !== null &&\n 'tag' in node &&\n node.tag === 'Probe'\n );\n const codegen =\n component && 'codegenNode' in component ? component.codegenNode : undefined;\n const children =\n codegen &&\n typeof codegen === 'object' &&\n 'children' in codegen &&\n codegen.children &&\n typeof codegen.children === 'object'\n ? codegen.children\n : undefined;\n const properties =\n children && 'properties' in children && Array.isArray(children.properties)\n ? children.properties\n : undefined;\n if (!properties) {\n throw new Error(\n 'The Vue compiler compatibility probe returned an unknown slot AST.'\n );\n }\n\n const hasImplicitDefault = properties.some((property) => {\n if (!property || typeof property !== 'object' || !('key' in property)) {\n return false;\n }\n const key = property.key;\n return (\n key != null &&\n typeof key === 'object' &&\n 'content' in key &&\n key.content === 'default'\n );\n });\n return hasImplicitDefault ? 'html' : 'ecmascript';\n}\n\nfunction isVueCompiler(value: unknown): value is VueCompiler {\n if (!value || typeof value !== 'object') return false;\n return (\n 'compileTemplate' in value &&\n typeof value.compileTemplate === 'function' &&\n 'parse' in value &&\n typeof value.parse === 'function' &&\n 'version' in value &&\n typeof value.version === 'string'\n );\n}\n\n/** Reads a possible CommonJS-interoperability default export. */\nfunction readDefaultExport(value: unknown): unknown {\n return value && typeof value === 'object' && 'default' in value\n ? value.default\n : undefined;\n}\n\nfunction isSupportedVueVersion(version: string): boolean {\n const match = /^(\\d+)\\.(\\d+)(?:\\.|$)/.exec(version);\n if (!match) return false;\n const major = Number(match[1]);\n const minor = Number(match[2]);\n return major === 3 && minor >= 3;\n}\n\nfunction isMissingModule(error: unknown): boolean {\n return (\n !!error &&\n typeof error === 'object' &&\n 'code' in error &&\n error.code === 'MODULE_NOT_FOUND'\n );\n}\n\nfunction formatResolutionError(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],"mappings":";;;;AAwBA,MAAM,oCAAoB,IAAI,KAAiC;AAC/D,MAAM,qCAAqB,IAAI,SAAqC;;;;;;;;AAgBpE,SAAgB,mBACd,MACA,aACoB;CACpB,MAAM,eAAe,KAAK,WAAW,KAAK,GACtC,OACA,KAAK,QAAQ,aAAa,KAAK;CACnC,MAAM,UAAU,CAAC,cAAc,KAAK,KAAK,aAAa,eAAe,CAAC;AAEtE,MAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,sBAAsB,cAAc,OAAO;EACjD,IAAI;AACJ,MAAI;AACF,qBAAkB,oBAAoB,QAAQ,mBAAmB;WAC1D,OAAO;AACd,OAAI,gBAAgB,MAAM,CA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@generaltranslation/format/types';
2
+ /**
3
+ * Version-neutral Vue compiler surface accepted by programmatic extraction.
4
+ *
5
+ * Vue's compiler AST types are nominally incompatible across even patch
6
+ * releases. Keeping the callable members opaque lets an app pass its exact
7
+ * `vue/compiler-sfc` module while runtime validation protects the boundary.
8
+ */
9
+ export type VueCompiler = {
10
+ /** Compiles one Vue SFC template. */
11
+ compileTemplate: (...args: never[]) => unknown;
12
+ /** Parses one Vue single-file component. */
13
+ parse: (...args: never[]) => unknown;
14
+ /** Optional exact compiler-dom parser for older Vue 3 releases. */
15
+ parseTemplate?: (...args: never[]) => unknown;
16
+ /** Exact Vue compiler release. */
17
+ version: string;
18
+ };
19
+ /** Vue template compiler options that can change extracted source hashes. */
20
+ export type VueCompilerOptions = {
21
+ /** Controls how Vue normalizes whitespace between template children. */
22
+ whitespace?: 'condense' | 'preserve';
23
+ /** Replaces Vue's default `{{` and `}}` interpolation delimiters. */
24
+ delimiters?: [string, string];
25
+ };
26
+ /** Source lines captured around an extracted translation. */
27
+ export type VueSourceCode = {
28
+ before: string;
29
+ target: string;
30
+ after: string;
31
+ };
32
+ /** Metadata attached to an extracted Vue translation. */
33
+ export type VueExtractionMetadata = {
34
+ context?: string;
35
+ filePaths?: string[];
36
+ sourceCode?: Record<string, VueSourceCode[]>;
37
+ };
38
+ /** A translation extracted from Vue source code before CLI post-processing. */
39
+ export type VueExtractionResult = {
40
+ dataFormat: 'JSX';
41
+ source: JsxChildren;
42
+ metadata: VueExtractionMetadata;
43
+ } | {
44
+ dataFormat: 'STRING';
45
+ source: string;
46
+ metadata: VueExtractionMetadata;
47
+ };
48
+ /** Options that control extraction from one Vue source file. */
49
+ export type VueExtractionOptions = {
50
+ /** Exact compiler used by the consuming Vue application. */
51
+ compiler?: VueCompiler;
52
+ /** Vue compiler options used by the consuming application. */
53
+ compilerOptions?: VueCompilerOptions;
54
+ /** Includes surrounding source lines in result metadata. */
55
+ includeSourceCodeContext?: boolean;
56
+ /** Root used to make metadata file paths relative. Defaults to `process.cwd()`. */
57
+ projectRoot?: string;
58
+ /**
59
+ * Resolves a static module specifier to a source file without loading or
60
+ * executing that module. Relative source files and index barrels are
61
+ * resolved automatically; provide this hook for aliases or workspace
62
+ * package exports that use application-specific resolution rules.
63
+ *
64
+ * The hook is consulted first for every specifier, including relative ones,
65
+ * so a project can preserve its compiler's source-over-build precedence.
66
+ *
67
+ * Returning `undefined` leaves the import unresolved and makes GT-shaped
68
+ * uses fail closed. The returned path must identify a readable local source
69
+ * file.
70
+ */
71
+ resolveModule?: (specifier: string, importer: string) => string | undefined;
72
+ /** Number of source lines captured before and after a translation. */
73
+ surroundingLineCount?: number;
74
+ };
75
+ /** Extraction output for one Vue single-file component or script. */
76
+ export type VueExtractionOutput = {
77
+ results: VueExtractionResult[];
78
+ errors: string[];
79
+ warnings: string[];
80
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@generaltranslation/vue-extractor",
3
+ "version": "0.0.0",
4
+ "description": "Vue source code extraction for General Translation",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "imports": {
10
+ "#vue-compiler-sfc": {
11
+ "bun": "@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js",
12
+ "default": "@vue/compiler-sfc"
13
+ }
14
+ },
15
+ "author": "General Translation, Inc.",
16
+ "license": "FSL-1.1-ALv2",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ },
22
+ "./config": {
23
+ "import": "./dist/config.js",
24
+ "types": "./dist/config.d.ts"
25
+ },
26
+ "./types": {
27
+ "import": "./dist/types.js",
28
+ "types": "./dist/types.d.ts"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/generaltranslation/gt.git"
37
+ },
38
+ "keywords": [
39
+ "vue",
40
+ "extraction",
41
+ "translation",
42
+ "i18n"
43
+ ],
44
+ "dependencies": {
45
+ "@babel/parser": "^7.25.7",
46
+ "@babel/traverse": "^7.25.7",
47
+ "@babel/types": "^7.25.7",
48
+ "@vue/shared": "^3.5.0",
49
+ "@generaltranslation/format": "0.1.4",
50
+ "generaltranslation": "9.1.1"
51
+ },
52
+ "devDependencies": {
53
+ "@types/babel__traverse": "^7.20.6",
54
+ "@types/node": "^22.13.5",
55
+ "@vue/compiler-dom": "^3.5.0",
56
+ "@vue/compiler-sfc": "^3.5.0",
57
+ "tsdown": "^0.21.10",
58
+ "typescript": "^5.9.2",
59
+ "vitest": "^3.2.4"
60
+ },
61
+ "scripts": {
62
+ "emit-types": "sh ../../scripts/emit-types.sh",
63
+ "transpile": "tsdown && pnpm run emit-types",
64
+ "build": "pnpm run transpile",
65
+ "build:watch": "tsdown --watch",
66
+ "build:clean": "sh ../../scripts/clean.sh && pnpm run build",
67
+ "build:release": "pnpm run build:clean",
68
+ "format": "oxfmt src",
69
+ "patch": "pnpm version patch",
70
+ "release": "pnpm run build:clean && pnpm publish",
71
+ "release:alpha": "pnpm run build:clean && pnpm publish --tag alpha",
72
+ "release:beta": "pnpm run build:clean && pnpm publish --tag beta",
73
+ "release:latest": "pnpm run build:clean && pnpm publish --tag latest",
74
+ "test": "vitest run",
75
+ "test:watch": "vitest",
76
+ "typecheck": "tsc --noEmit"
77
+ }
78
+ }