@let-value/translate-extract 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/cli.cjs +2 -2
- package/dist/bin/cli.js +2 -2
- package/dist/bin/cli.js.map +1 -1
- package/dist/run-8jCGSKUe.cjs +184 -0
- package/dist/run-CMzN4vHt.js +150 -0
- package/dist/run-CMzN4vHt.js.map +1 -0
- package/dist/src/index.cjs +282 -120
- package/dist/src/index.d.cts +141 -62
- package/dist/src/index.d.cts.map +1 -1
- package/dist/src/index.d.ts +142 -63
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +281 -118
- package/dist/src/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/run-BMvkoNJ4.js +0 -192
- package/dist/run-BMvkoNJ4.js.map +0 -1
- package/dist/run-CbsVUbM3.cjs +0 -226
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["path","importQuery: ImportQuerySpec","current: Parser.SyntaxNode | null","messageQuery: QuerySpec","allowed","messageInvalidQuery: QuerySpec","ids: string[]","strs: string[]","subMatch: Parser.QueryMatch","translation: Translation","contextMsgQuery: QuerySpec","msgCall","contextPluralQuery: QuerySpec","contextInvalidQuery: QuerySpec","gettextQuery: QuerySpec","gettextInvalidQuery: QuerySpec","msgCall","plainMsg","msgArg","ngettextQuery: QuerySpec","msgCall","npgettextQuery: QuerySpec","pgettextQuery: QuerySpec","pluralQuery: QuerySpec","queries: QuerySpec[]","messageQuery","pluralQuery","getCachedParser","path","parseSource","context: Context","translations: Translation[]","imports: string[]","fs","resolved: string[]","filter","path","parseSource","translations: GetTextTranslationRecord","headers: Record<string, string>","obsoleteTranslations: GetTextTranslationRecord","collected: GetTextTranslationRecord","existing","poObj: GetTextTranslations","path","defaultDestination: DestinationFn","defaultExclude: Exclude[]","plugins: ExtractorPlugin[]","entrypoints: ResolvedEntrypoint[]","path","exclude","strings: string[]","values: string[]","text","messageQuery: QuerySpec","attrs: Parser.SyntaxNode[]","msgctxt: string | undefined","childValue: Parser.SyntaxNode | undefined","error: string | undefined","translation: Translation","forms: string[]","pluralQuery: QuerySpec","attrs: Parser.SyntaxNode[]","msgctxt: string | undefined","formsNode: Parser.SyntaxNode | null | undefined","translation: Translation","queries: QuerySpec[]","context: Context","path","translations: Translation[]","imports: string[]","coreQueries","reactQueries","path"],"sources":["../../src/plugins/core/queries/comment.ts","../../src/plugins/core/queries/import.ts","../../src/plugins/core/queries/utils.ts","../../src/plugins/core/queries/message.ts","../../src/plugins/core/queries/plural-utils.ts","../../src/plugins/core/queries/context.ts","../../src/plugins/core/queries/gettext.ts","../../src/plugins/core/queries/ngettext.ts","../../src/plugins/core/queries/npgettext.ts","../../src/plugins/core/queries/pgettext.ts","../../src/plugins/core/queries/plural.ts","../../src/plugins/core/queries/index.ts","../../src/plugins/core/parse.ts","../../src/plugins/core/resolve.ts","../../src/plugins/core/core.ts","../../src/plugins/po/po.ts","../../src/configuration.ts","../../src/plugins/react/queries/utils.ts","../../src/plugins/react/queries/message.ts","../../src/plugins/react/queries/plural.ts","../../src/plugins/react/queries/index.ts","../../src/plugins/react/parse.ts","../../src/plugins/react/react.ts"],"sourcesContent":["import { relative } from \"node:path\";\nimport type Parser from \"tree-sitter\";\n\nimport type { Context, QuerySpec } from \"./types.ts\";\n\nexport function getReference(node: Parser.SyntaxNode, { path }: Context) {\n const line = node.startPosition.row + 1;\n const rel = relative(process.cwd(), path).replace(/\\\\+/g, \"/\");\n return `${rel}:${line}`;\n}\n\nfunction getComment(node: Parser.SyntaxNode): string {\n const text = node.text;\n if (text.startsWith(\"/*\")) {\n return text\n .slice(2, -2)\n .replace(/^\\s*\\*?\\s*/gm, \"\")\n .trim();\n }\n return text.replace(/^\\/\\/\\s?/, \"\").trim();\n}\n\nexport const withComment = (query: QuerySpec): QuerySpec => ({\n pattern: `(\n\t((comment) @comment)?\n .\n\t(_ ${query.pattern})\n)`,\n extract(match) {\n const result = query.extract(match);\n if (!result?.translation) {\n return result;\n }\n\n const comment = match.captures.find((c) => c.name === \"comment\")?.node;\n if (!comment) {\n return result;\n }\n\n if (comment) {\n result.translation.comments = {\n ...result.translation.comments,\n extracted: getComment(comment),\n };\n }\n\n return result;\n },\n});\n","import type Parser from \"tree-sitter\";\nimport type { ImportQuerySpec } from \"./types.ts\";\n\nexport const importQuery: ImportQuerySpec = {\n pattern: `\n [\n (import_statement\n source: (string (string_fragment) @import))\n (export_statement\n source: (string (string_fragment) @import))\n (call_expression\n function: (identifier) @func\n arguments: (arguments (string (string_fragment) @import))\n (#eq? @func \"require\"))\n (call_expression\n function: (member_expression\n object: (identifier) @obj\n property: (property_identifier) @method)\n arguments: (arguments (string (string_fragment) @import))\n (#eq? @obj \"require\")\n (#eq? @method \"resolve\"))\n (call_expression\n function: (import)\n arguments: (arguments (string (string_fragment) @import)))\n ]\n `,\n extract(match: Parser.QueryMatch): string | undefined {\n const node = match.captures.find((c) => c.name === \"import\")?.node;\n return node?.text;\n },\n};\n","import type Parser from \"tree-sitter\";\n\nexport const callPattern = (fnName: string, args: string, allowMember = true): string => `(\n (call_expression\n function: ${\n allowMember\n ? `[\n (identifier) @func\n (member_expression property: (property_identifier) @func)\n ]`\n : `(identifier) @func`\n }\n arguments: ${args}\n ) @call\n (#eq? @func \"${fnName}\")\n)`;\n\nexport function isDescendant(node: Parser.SyntaxNode, ancestor: Parser.SyntaxNode): boolean {\n let current: Parser.SyntaxNode | null = node;\n while (current) {\n if (current.id === ancestor.id) return true;\n current = current.parent;\n }\n return false;\n}\n","import type Parser from \"tree-sitter\";\nimport { withComment } from \"./comment.ts\";\nimport type { MessageMatch, QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nconst notInPlural = (query: QuerySpec): QuerySpec => ({\n pattern: query.pattern,\n extract(match) {\n const result = query.extract(match);\n if (!result?.node) {\n return result;\n }\n\n let parent = result.node.parent;\n\n if (parent && parent.type === \"arguments\") {\n parent = parent.parent;\n }\n\n if (parent && parent.type === \"call_expression\") {\n const fn = parent.childForFieldName(\"function\");\n if (fn) {\n if (\n (fn.type === \"identifier\" &&\n (fn.text === \"plural\" ||\n fn.text === \"ngettext\" ||\n fn.text === \"pgettext\" ||\n fn.text === \"npgettext\")) ||\n (fn.type === \"member_expression\" &&\n [\"plural\", \"ngettext\", \"pgettext\", \"npgettext\"].includes(\n fn.childForFieldName(\"property\")?.text ?? \"\",\n ))\n ) {\n return undefined;\n }\n }\n }\n\n return result;\n },\n});\n\nexport const messageArg = `[\n (string (string_fragment) @msgid)\n (object\n (_)*\n (pair\n key: (property_identifier) @id_key\n value: (string (string_fragment) @id)\n (#eq? @id_key \"id\")\n )?\n (_)*\n (pair\n key: (property_identifier) @msg_key\n value: (string (string_fragment) @message)\n (#eq? @msg_key \"message\")\n )?\n (_)*\n )\n (template_string) @tpl\n]`;\n\nexport const messageArgs = `[ (arguments ${messageArg}) (template_string) @tpl ]`;\n\nexport const extractMessage =\n (name: string) =>\n (match: Parser.QueryMatch): MessageMatch | undefined => {\n const node = match.captures.find((c) => c.name === \"call\")?.node;\n if (!node) {\n return undefined;\n }\n\n const msgid = match.captures.find((c) => c.name === \"msgid\")?.node.text;\n if (msgid) {\n return {\n node,\n translation: {\n id: msgid,\n message: [msgid],\n },\n };\n }\n\n const tpl = match.captures.find((c) => c.name === \"tpl\")?.node;\n if (tpl) {\n for (const child of tpl.children) {\n if (child.type !== \"template_substitution\") {\n continue;\n }\n\n const expr = child.namedChildren[0];\n if (!expr || expr.type !== \"identifier\") {\n return {\n node,\n error: `${name}() template expressions must be simple identifiers`,\n };\n }\n }\n\n const text = tpl.text.slice(1, -1);\n\n return {\n node,\n translation: { id: text, message: [text] },\n };\n }\n\n const id = match.captures.find((c) => c.name === \"id\")?.node.text;\n const message = match.captures.find((c) => c.name === \"message\")?.node.text;\n const msgId = id ?? message;\n if (!msgId) {\n return undefined;\n }\n\n const msgstr = message ?? id ?? \"\";\n\n return {\n node,\n translation: {\n id: msgId,\n message: [msgstr],\n },\n };\n };\n\nexport const messageQuery: QuerySpec = notInPlural(\n withComment({\n pattern: callPattern(\"message\", messageArgs),\n extract: extractMessage(\"message\"),\n }),\n);\n\nconst allowed = new Set([\"string\", \"object\", \"template_string\"]);\n\nexport const messageInvalidQuery: QuerySpec = notInPlural({\n pattern: callPattern(\"message\", \"(arguments (_) @arg)\"),\n extract(match) {\n const call = match.captures.find((c) => c.name === \"call\")?.node;\n const node = match.captures.find((c) => c.name === \"arg\")?.node;\n\n if (!call || !node) {\n return undefined;\n }\n\n if (allowed.has(node.type)) {\n return undefined;\n }\n\n return {\n node,\n error: \"message() argument must be a string literal, object literal, or template literal\",\n };\n },\n});\n","import type Parser from \"tree-sitter\";\nimport { extractMessage } from \"./message.ts\";\nimport type { MessageMatch, Translation } from \"./types.ts\";\nimport { isDescendant } from \"./utils.ts\";\n\nexport const extractPluralForms =\n (name: string) =>\n (match: Parser.QueryMatch): MessageMatch | undefined => {\n const call = match.captures.find((c) => c.name === \"call\")?.node;\n const n = match.captures.find((c) => c.name === \"n\")?.node;\n if (!call || !n || n.nextNamedSibling) {\n return undefined;\n }\n\n const msgctxt = match.captures.find((c) => c.name === \"msgctxt\")?.node?.text;\n const msgNodes = match.captures.filter((c) => c.name === \"msg\").map((c) => c.node);\n\n const ids: string[] = [];\n const strs: string[] = [];\n\n for (const node of msgNodes) {\n const relevant = match.captures.filter(\n (c) => [\"msgid\", \"id\", \"message\", \"tpl\"].includes(c.name) && isDescendant(c.node, node),\n );\n\n const subMatch: Parser.QueryMatch = {\n pattern: 0,\n captures: [{ name: \"call\", node }, ...relevant],\n };\n\n const result = extractMessage(name)(subMatch);\n if (!result) continue;\n if (result.error) {\n return { node: call, error: result.error };\n }\n if (result.translation) {\n ids.push(result.translation.id);\n strs.push(result.translation.message[0] ?? \"\");\n }\n }\n\n if (ids.length === 0) {\n return undefined;\n }\n\n const translation: Translation = {\n id: ids[0],\n plural: ids[1],\n message: strs,\n };\n if (msgctxt) translation.context = msgctxt;\n\n return { node: call, translation };\n };\n","import { withComment } from \"./comment.ts\";\nimport { extractMessage, messageArgs } from \"./message.ts\";\nimport { extractPluralForms } from \"./plural-utils.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nconst ctxCall = callPattern(\"context\", `(arguments (string (string_fragment) @msgctxt))`)\n .replace(/@call/g, \"@ctx\")\n .replace(/@func/g, \"@ctxfn\");\n\nexport const contextMsgQuery: QuerySpec = withComment({\n pattern: `(\n (call_expression\n function: (member_expression\n object: ${ctxCall}\n property: (property_identifier) @func\n )\n arguments: ${messageArgs}\n ) @call\n (#eq? @func \"message\")\n)`,\n extract(match) {\n const result = extractMessage(\"context.message\")(match);\n const contextNode = match.captures.find((c) => c.name === \"msgctxt\")?.node;\n if (!result || !result.translation || !contextNode) {\n return result;\n }\n return {\n node: result.node,\n translation: {\n ...result.translation,\n context: contextNode.text,\n },\n };\n },\n});\n\nconst msgCall = callPattern(\"message\", messageArgs, false).replace(/@call/g, \"@msg\").replace(/@func/g, \"@msgfn\");\n\nexport const contextPluralQuery: QuerySpec = withComment({\n pattern: `(\n (call_expression\n function: (member_expression\n object: ${ctxCall}\n property: (property_identifier) @func\n )\n arguments: (arguments (\n (${msgCall} (\",\" )?)+\n (number) @n\n ))\n ) @call\n (#eq? @func \"plural\")\n)`,\n extract: extractPluralForms(\"context.plural\"),\n});\n\nexport const contextInvalidQuery: QuerySpec = withComment({\n pattern: ctxCall,\n extract(match) {\n const call = match.captures.find((c) => c.name === \"ctx\")?.node;\n if (!call) {\n return undefined;\n }\n\n const parent = call.parent;\n if (parent && parent.type === \"member_expression\" && parent.childForFieldName(\"object\")?.id === call.id) {\n const property = parent.childForFieldName(\"property\")?.text;\n const grandparent = parent.parent;\n if (\n grandparent &&\n grandparent.type === \"call_expression\" &&\n grandparent.childForFieldName(\"function\")?.id === parent.id &&\n (property === \"message\" || property === \"plural\")\n ) {\n return undefined;\n }\n }\n\n return {\n node: call,\n error: \"context() must be used with message() or plural() in the same expression\",\n };\n },\n});\n","import { withComment } from \"./comment.ts\";\nimport { extractMessage, messageArgs } from \"./message.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nexport const gettextQuery: QuerySpec = withComment({\n pattern: callPattern(\"gettext\", messageArgs),\n extract: extractMessage(\"gettext\"),\n});\n\nconst allowed = new Set([\"string\", \"object\", \"template_string\", \"identifier\", \"call_expression\"]);\n\nexport const gettextInvalidQuery: QuerySpec = {\n pattern: callPattern(\"gettext\", \"(arguments (_) @arg)\"),\n extract(match) {\n const call = match.captures.find((c) => c.name === \"call\")?.node;\n const node = match.captures.find((c) => c.name === \"arg\")?.node;\n\n if (!call || !node) {\n return undefined;\n }\n\n if (allowed.has(node.type)) {\n return undefined;\n }\n\n return {\n node,\n error: \"gettext() argument must be a string literal, object literal, or template literal\",\n };\n },\n};\n","import { withComment } from \"./comment.ts\";\nimport { messageArg, messageArgs } from \"./message.ts\";\nimport { extractPluralForms } from \"./plural-utils.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nconst msgCall = callPattern(\"message\", messageArgs).replace(/@call/g, \"@msg\").replace(/@func/g, \"@msgfn\");\nconst plainMsg = `(${messageArg}) @msg`;\nconst msgArg = `[${msgCall} ${plainMsg}]`;\n\nexport const ngettextQuery: QuerySpec = withComment({\n pattern: callPattern(\"ngettext\", `(arguments ${msgArg} \",\" ${msgArg} (\",\" ${msgArg})* \",\" (_) @n)`),\n extract: extractPluralForms(\"ngettext\"),\n});\n","import { withComment } from \"./comment.ts\";\nimport { messageArg, messageArgs } from \"./message.ts\";\nimport { extractPluralForms } from \"./plural-utils.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nconst msgCall = callPattern(\"message\", messageArgs).replace(/@call/g, \"@msg\").replace(/@func/g, \"@msgfn\");\nconst plainMsg = `(${messageArg}) @msg`;\nconst msgArg = `[${msgCall} ${plainMsg}]`;\n\nexport const npgettextQuery: QuerySpec = withComment({\n pattern: callPattern(\n \"npgettext\",\n `(arguments (string (string_fragment) @msgctxt) \",\" ${msgArg} \",\" ${msgArg} (\",\" ${msgArg})* \",\" (_) @n)`,\n ),\n extract: extractPluralForms(\"npgettext\"),\n});\n","import { withComment } from \"./comment.ts\";\nimport { extractMessage, messageArg } from \"./message.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nexport const pgettextQuery: QuerySpec = withComment({\n pattern: callPattern(\"pgettext\", `(arguments (string (string_fragment) @msgctxt) \",\" ${messageArg})`),\n extract(match) {\n const result = extractMessage(\"pgettext\")(match);\n const contextNode = match.captures.find((c) => c.name === \"msgctxt\")?.node;\n if (!result || !contextNode || !result.translation) {\n return result;\n }\n return {\n node: result.node,\n translation: {\n ...result.translation,\n context: contextNode.text,\n },\n };\n },\n});\n","import { withComment } from \"./comment.ts\";\nimport { messageArgs } from \"./message.ts\";\nimport { extractPluralForms } from \"./plural-utils.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nconst msgCall = callPattern(\"message\", messageArgs, false).replace(/@call/g, \"@msg\").replace(/@func/g, \"@msgfn\");\n\nexport const pluralQuery: QuerySpec = withComment({\n pattern: callPattern(\n \"plural\",\n `(arguments (\n (${msgCall} (\",\" )?)+\n (number) @n\n ))`,\n false,\n ),\n extract: extractPluralForms(\"plural\"),\n});\n","import { contextInvalidQuery, contextMsgQuery, contextPluralQuery } from \"./context.ts\";\nimport { gettextInvalidQuery, gettextQuery } from \"./gettext.ts\";\nimport { messageInvalidQuery, messageQuery } from \"./message.ts\";\nimport { ngettextQuery } from \"./ngettext.ts\";\nimport { npgettextQuery } from \"./npgettext.ts\";\nimport { pgettextQuery } from \"./pgettext.ts\";\nimport { pluralQuery } from \"./plural.ts\";\nimport type { QuerySpec } from \"./types.ts\";\n\nexport type { MessageMatch, QuerySpec } from \"./types.ts\";\n\nexport const queries: QuerySpec[] = [\n messageQuery,\n messageInvalidQuery,\n gettextQuery,\n gettextInvalidQuery,\n pluralQuery,\n ngettextQuery,\n pgettextQuery,\n npgettextQuery,\n contextMsgQuery,\n contextPluralQuery,\n contextInvalidQuery,\n];\n","import fs from \"node:fs\";\nimport { extname, resolve } from \"node:path\";\n\nimport { memo } from \"radash\";\nimport Parser from \"tree-sitter\";\nimport JavaScript from \"tree-sitter-javascript\";\nimport TS from \"tree-sitter-typescript\";\n\nimport { getReference } from \"./queries/comment.ts\";\nimport { importQuery } from \"./queries/import.ts\";\nimport { queries } from \"./queries/index.ts\";\nimport type { Context, Translation } from \"./queries/types.ts\";\n\nexport interface ParseResult {\n translations: Translation[];\n imports: string[];\n}\n\nfunction getLanguage(ext: string) {\n switch (ext) {\n case \".ts\":\n return TS.typescript;\n case \".tsx\":\n return TS.tsx;\n default:\n return JavaScript;\n }\n}\n\nconst getCachedParser = memo(function getCachedParser(ext: string) {\n const parser = new Parser();\n const language = getLanguage(ext) as Parser.Language;\n parser.setLanguage(language);\n\n return { parser, language };\n});\n\nexport function getParser(path: string) {\n const ext = extname(path);\n return getCachedParser(ext);\n}\n\nexport function parseFile(filePath: string): ParseResult {\n const path = resolve(filePath);\n const source = fs.readFileSync(path, \"utf8\");\n return parseSource(source, path);\n}\n\nexport function parseSource(source: string, path: string): ParseResult {\n const context: Context = {\n path,\n };\n\n const { parser, language } = getParser(path);\n const tree = parser.parse(source);\n\n const translations: Translation[] = [];\n const imports: string[] = [];\n\n const seen = new Set<number>();\n\n for (const spec of queries) {\n const query = new Parser.Query(language, spec.pattern);\n for (const match of query.matches(tree.rootNode)) {\n const message = spec.extract(match);\n if (!message) {\n continue;\n }\n\n const { node, translation, error } = message;\n if (seen.has(node.id)) {\n continue;\n }\n seen.add(node.id);\n const reference = getReference(node, context);\n\n if (translation) {\n translations.push({\n ...translation,\n comments: {\n ...translation.comments,\n reference,\n },\n });\n }\n\n if (error) {\n console.warn(`Parsing error at ${reference}: ${error}`);\n }\n }\n }\n\n const importTreeQuery = new Parser.Query(language, importQuery.pattern);\n for (const match of importTreeQuery.matches(tree.rootNode)) {\n const imp = importQuery.extract(match);\n if (imp) {\n imports.push(imp);\n }\n }\n\n return { translations, imports };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { ResolverFactory } from \"oxc-resolver\";\n\nfunction findTsconfig(dir: string): string | undefined {\n let current = dir;\n while (true) {\n const config = path.join(current, \"tsconfig.json\");\n if (fs.existsSync(config)) {\n return config;\n }\n const parent = path.dirname(current);\n if (parent === current) {\n return undefined;\n }\n current = parent;\n }\n}\n\nconst resolverCache = new Map<string, ResolverFactory>();\n\nfunction getResolver(dir: string) {\n const tsconfig = findTsconfig(dir);\n const key = tsconfig ?? \"__default__\";\n let resolver = resolverCache.get(key);\n if (!resolver) {\n resolver = new ResolverFactory({\n extensions: [\".ts\", \".tsx\", \".js\", \".jsx\", \".mjs\", \".cjs\", \".json\"],\n conditionNames: [\"import\", \"require\", \"node\"],\n ...(tsconfig ? { tsconfig: { configFile: tsconfig } } : {}),\n });\n resolverCache.set(key, resolver);\n }\n return resolver;\n}\n\nfunction resolveFromDir(dir: string, spec: string): string | undefined {\n const resolver = getResolver(dir);\n const res = resolver.sync(dir, spec) as { path?: string };\n return res.path;\n}\n\nexport function resolveImport(file: string, spec: string): string | undefined {\n const dir = path.dirname(path.resolve(file));\n return resolveFromDir(dir, spec);\n}\n\nexport function resolveImports(file: string, imports: string[]): string[] {\n const dir = path.dirname(path.resolve(file));\n const resolver = getResolver(dir);\n const resolved: string[] = [];\n for (const spec of imports) {\n const res = resolver.sync(dir, spec) as { path?: string };\n if (res.path) {\n resolved.push(res.path);\n }\n }\n return resolved;\n}\n","import { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport type { ExtractorPlugin } from \"../../plugin.ts\";\nimport { parseSource } from \"./parse.ts\";\nimport { resolveImports } from \"./resolve.ts\";\n\nconst filter = /\\.([cm]?tsx?|jsx?)$/;\n\nexport function core(): ExtractorPlugin {\n return {\n name: \"core\",\n setup(build) {\n build.context.logger?.debug(\"core plugin initialized\");\n build.onResolve({ filter: /.*/ }, ({ entrypoint, path }) => {\n return {\n entrypoint,\n path: resolve(path),\n };\n });\n build.onLoad({ filter }, async ({ entrypoint, path }) => {\n const contents = await readFile(path, \"utf8\");\n return { entrypoint, path, contents };\n });\n build.onExtract({ filter }, ({ entrypoint, path, contents }) => {\n const { translations, imports } = parseSource(contents, path);\n if (build.context.config.walk) {\n const paths = resolveImports(path, imports);\n for (const path of paths) {\n build.resolvePath({\n entrypoint,\n path,\n });\n }\n }\n return {\n entrypoint,\n path,\n translations,\n };\n });\n },\n } satisfies ExtractorPlugin;\n}\n","import fs from \"node:fs/promises\";\nimport { basename, dirname, extname, join } from \"node:path\";\nimport type { GetTextTranslationRecord, GetTextTranslations } from \"gettext-parser\";\nimport * as gettextParser from \"gettext-parser\";\nimport { getFormula, getNPlurals } from \"plural-forms\";\nimport type { ObsoleteStrategy } from \"../../configuration.ts\";\nimport type { CollectResult, ExtractContext, ExtractorPlugin, GenerateArgs } from \"../../plugin.ts\";\nimport type { Translation } from \"../core/queries/types.ts\";\n\nexport function formatDate(date: Date): string {\n const pad = (n: number) => n.toString().padStart(2, \"0\");\n const year = date.getFullYear();\n const month = pad(date.getMonth() + 1);\n const day = pad(date.getDate());\n const hours = pad(date.getHours());\n const minutes = pad(date.getMinutes());\n const tzo = -date.getTimezoneOffset();\n const sign = tzo >= 0 ? \"+\" : \"-\";\n const offsetHours = pad(Math.floor(Math.abs(tzo) / 60));\n const offsetMinutes = pad(Math.abs(tzo) % 60);\n return `${year}-${month}-${day} ${hours}:${minutes}${sign}${offsetHours}${offsetMinutes}`;\n}\n\nexport function collect(source: Translation[], locale?: string): GetTextTranslationRecord {\n const translations: GetTextTranslationRecord = { \"\": {} };\n const nplurals = locale ? getNPlurals(locale) : undefined;\n\n for (const { context, id, message, comments, obsolete, plural } of source) {\n const ctx = context || \"\";\n if (!translations[ctx]) {\n translations[ctx] = {};\n }\n\n const length = plural ? (nplurals ?? message.length) : 1;\n\n const existing = translations[ctx][id];\n const refs = new Set<string>();\n if (existing?.comments?.reference) {\n existing.comments.reference.split(/\\r?\\n|\\r/).forEach((r) => {\n refs.add(r);\n });\n }\n if (comments?.reference) {\n comments.reference.split(/\\r?\\n|\\r/).forEach((r) => {\n refs.add(r);\n });\n }\n\n const msgstr = existing?.msgstr ? existing.msgstr.slice(0, length) : Array.from({ length }, () => \"\");\n while (msgstr.length < length) msgstr.push(\"\");\n\n translations[ctx][id] = {\n msgctxt: context || undefined,\n msgid: id,\n msgid_plural: plural,\n msgstr,\n comments: {\n ...existing?.comments,\n ...comments,\n reference: refs.size ? Array.from(refs).join(\"\\n\") : undefined,\n },\n obsolete: existing?.obsolete ?? obsolete,\n };\n }\n\n return translations;\n}\n\nexport function merge(\n sources: CollectResult[],\n existing: string | Buffer | undefined,\n obsolete: ObsoleteStrategy,\n locale: string,\n generatedAt: Date,\n): string {\n let headers: Record<string, string> = {};\n let translations: GetTextTranslationRecord = { \"\": {} };\n let obsoleteTranslations: GetTextTranslationRecord = {};\n const nplurals = getNPlurals(locale);\n\n if (existing) {\n const parsed = gettextParser.po.parse(existing);\n headers = parsed.headers || {};\n translations = parsed.translations || { \"\": {} };\n obsoleteTranslations = parsed.obsolete || {};\n for (const ctx of Object.keys(translations)) {\n for (const id of Object.keys(translations[ctx])) {\n if (ctx === \"\" && id === \"\") continue;\n translations[ctx][id].obsolete = true;\n }\n }\n }\n\n const collected: GetTextTranslationRecord = { \"\": {} };\n for (const { translations: record } of sources) {\n for (const [ctx, msgs] of Object.entries(record as GetTextTranslationRecord)) {\n if (!collected[ctx]) collected[ctx] = {};\n for (const [id, entry] of Object.entries(msgs)) {\n const existing = collected[ctx][id];\n const refs = new Set<string>();\n if (existing?.comments?.reference) {\n existing.comments.reference.split(/\\r?\\n|\\r/).forEach((r) => {\n refs.add(r);\n });\n }\n if (entry.comments?.reference) {\n entry.comments.reference.split(/\\r?\\n|\\r/).forEach((r) => {\n refs.add(r);\n });\n }\n collected[ctx][id] = {\n ...existing,\n ...entry,\n comments: {\n ...existing?.comments,\n ...entry.comments,\n reference: refs.size ? Array.from(refs).join(\"\\n\") : undefined,\n },\n };\n }\n }\n }\n\n for (const [ctx, msgs] of Object.entries(collected)) {\n if (!translations[ctx]) translations[ctx] = {};\n for (const [id, entry] of Object.entries(msgs)) {\n const existingEntry = translations[ctx][id] ?? obsoleteTranslations[ctx]?.[id];\n if (existingEntry) {\n entry.msgstr = existingEntry.msgstr;\n entry.comments = {\n ...entry.comments,\n translator: existingEntry.comments?.translator,\n };\n }\n entry.obsolete = false;\n entry.msgstr = entry.msgstr.slice(0, nplurals);\n while (entry.msgstr.length < nplurals) entry.msgstr.push(\"\");\n translations[ctx][id] = entry;\n if (obsoleteTranslations[ctx]) delete obsoleteTranslations[ctx][id];\n }\n }\n\n for (const ctx of Object.keys(translations)) {\n for (const id of Object.keys(translations[ctx])) {\n if (ctx === \"\" && id === \"\") continue;\n const entry = translations[ctx][id];\n if (entry.obsolete) {\n if (!obsoleteTranslations[ctx]) obsoleteTranslations[ctx] = {};\n obsoleteTranslations[ctx][id] = entry;\n delete translations[ctx][id];\n }\n }\n }\n\n headers = {\n ...headers,\n \"content-type\": headers[\"content-type\"] || \"text/plain; charset=UTF-8\",\n \"plural-forms\": `nplurals=${nplurals}; plural=${getFormula(locale)};`,\n language: locale,\n \"pot-creation-date\": formatDate(generatedAt),\n \"x-generator\": \"@let-value/translate-extract\",\n };\n\n const poObj: GetTextTranslations = {\n charset: \"utf-8\",\n headers,\n translations,\n ...(obsolete === \"mark\" && Object.keys(obsoleteTranslations).length ? { obsolete: obsoleteTranslations } : {}),\n };\n\n return gettextParser.po.compile(poObj).toString();\n}\n\nexport function po(): ExtractorPlugin {\n return {\n name: \"po\",\n setup(build) {\n build.context.logger?.debug(\"po plugin initialized\");\n build.onCollect({ filter: /.*/ }, ({ entrypoint, translations, destination, ...rest }, ctx) => {\n const record = collect(translations as Translation[], ctx.locale);\n const redirected = join(dirname(destination), `${basename(destination, extname(destination))}.po`);\n\n return {\n ...rest,\n entrypoint,\n destination: redirected,\n translations: record,\n };\n });\n build.onGenerate({ filter: /\\.po$/ }, async ({ path, collected }: GenerateArgs, ctx: ExtractContext) => {\n const existing = await fs.readFile(path).catch(() => undefined);\n const out = merge(collected, existing, ctx.config.obsolete, ctx.locale, ctx.generatedAt);\n await fs.mkdir(dirname(path), { recursive: true });\n await fs.writeFile(path, out);\n });\n },\n };\n}\n","import { basename, dirname, extname, join } from \"node:path\";\nimport { globSync } from \"glob\";\nimport type { LevelWithSilent } from \"pino\";\nimport type { ExtractorPlugin } from \"./plugin.ts\";\nimport { core } from \"./plugins/core/core.ts\";\nimport { po } from \"./plugins/po/po.ts\";\n\nexport type DestinationFn = (args: { locale: string; entrypoint: string; path: string }) => string;\nexport type ExcludeFn = (path: string) => boolean;\nexport type Exclude = RegExp | ExcludeFn;\n\nconst defaultPlugins = { core, po };\ntype DefaultPlugins = typeof defaultPlugins;\n\nexport type ObsoleteStrategy = \"mark\" | \"remove\";\n\nexport interface EntrypointConfig {\n entrypoint: string;\n destination?: DestinationFn;\n obsolete?: ObsoleteStrategy;\n exclude?: Exclude | Exclude[];\n}\n\nexport interface UserConfig {\n plugins?: ExtractorPlugin[] | ((defaultPlugins: DefaultPlugins) => ExtractorPlugin[]);\n entrypoints: string | EntrypointConfig | Array<string | EntrypointConfig>;\n defaultLocale?: string;\n locales?: string[];\n destination?: DestinationFn;\n obsolete?: ObsoleteStrategy;\n walk?: boolean;\n logLevel?: LevelWithSilent;\n exclude?: Exclude | Exclude[];\n}\n\nexport interface ResolvedEntrypoint extends Omit<EntrypointConfig, \"exclude\"> {\n exclude?: Exclude[];\n}\n\nexport interface ResolvedConfig {\n plugins: ExtractorPlugin[];\n entrypoints: ResolvedEntrypoint[];\n defaultLocale: string;\n locales: string[];\n destination: DestinationFn;\n obsolete: ObsoleteStrategy;\n walk: boolean;\n logLevel: LevelWithSilent;\n exclude: Exclude[];\n}\n\nconst defaultDestination: DestinationFn = ({ entrypoint, locale }) =>\n join(dirname(entrypoint), \"translations\", `${basename(entrypoint, extname(entrypoint))}.${locale}.po`);\n\nconst defaultExclude: Exclude[] = [\n /(?:^|[\\\\/])node_modules(?:[\\\\/]|$)/,\n /(?:^|[\\\\/])dist(?:[\\\\/]|$)/,\n /(?:^|[\\\\/])build(?:[\\\\/]|$)/,\n];\n\nfunction normalizeExclude(exclude?: Exclude | Exclude[]): Exclude[] {\n if (!exclude) return [];\n return Array.isArray(exclude) ? exclude : [exclude];\n}\n\nexport function defineConfig(config: UserConfig): ResolvedConfig {\n let plugins: ExtractorPlugin[];\n const user = config.plugins;\n if (typeof user === \"function\") {\n plugins = user(defaultPlugins);\n } else if (Array.isArray(user)) {\n plugins = [...Object.values(defaultPlugins).map((plugin) => plugin()), ...user];\n } else {\n plugins = Object.values(defaultPlugins).map((plugin) => plugin());\n }\n\n const raw = Array.isArray(config.entrypoints) ? config.entrypoints : [config.entrypoints];\n const entrypoints: ResolvedEntrypoint[] = [];\n for (const ep of raw) {\n if (typeof ep === \"string\") {\n const paths = globSync(ep, { nodir: true });\n if (paths.length === 0) {\n entrypoints.push({ entrypoint: ep });\n } else {\n for (const path of paths) entrypoints.push({ entrypoint: path });\n }\n } else {\n const { entrypoint, destination, obsolete, exclude } = ep;\n const paths = globSync(entrypoint, { nodir: true });\n const epExclude = exclude ? [...defaultExclude, ...normalizeExclude(exclude)] : undefined;\n if (paths.length === 0) {\n entrypoints.push({ entrypoint, destination, obsolete, exclude: epExclude });\n } else {\n for (const path of paths)\n entrypoints.push({ entrypoint: path, destination, obsolete, exclude: epExclude });\n }\n }\n }\n\n const defaultLocale = config.defaultLocale ?? \"en\";\n const locales = config.locales ?? [defaultLocale];\n const destination = config.destination ?? defaultDestination;\n const obsolete = config.obsolete ?? \"mark\";\n const walk = config.walk ?? true;\n const logLevel = config.logLevel ?? \"info\";\n const exclude = [...defaultExclude, ...normalizeExclude(config.exclude)];\n return { plugins, entrypoints, defaultLocale, locales, destination, obsolete, walk, logLevel, exclude };\n}\n","import type Parser from \"tree-sitter\";\n\nexport function buildTemplate(node: Parser.SyntaxNode): { text: string; error?: string } {\n const children = node.namedChildren.slice(1, -1);\n const strings: string[] = [\"\"];\n const values: string[] = [];\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (child.type === \"jsx_text\") {\n let text = child.text;\n if (i === 0) text = text.replace(/^\\s+/, \"\");\n if (i === children.length - 1) text = text.replace(/\\s+$/, \"\");\n if (text) strings[strings.length - 1] += text;\n } else if (child.type === \"jsx_expression\") {\n const expr = child.namedChildren[0];\n if (!expr || expr.type !== \"identifier\") {\n return { text: \"\", error: \"JSX expressions must be simple identifiers\" };\n }\n values.push(expr.text);\n strings.push(\"\");\n } else if (child.type === \"string\") {\n strings[strings.length - 1] += child.text.slice(1, -1);\n } else {\n return { text: \"\", error: \"Unsupported JSX child\" };\n }\n }\n let text = \"\";\n for (let i = 0; i < strings.length; i++) {\n text += strings[i];\n if (values[i]) {\n text += `\\${${values[i]}}`;\n }\n }\n return { text };\n}\n\nexport function buildAttrValue(node: Parser.SyntaxNode): { text: string; error?: string } {\n if (node.type === \"string\") {\n return { text: node.text.slice(1, -1) };\n }\n if (node.type === \"jsx_expression\") {\n const expr = node.namedChildren[0];\n if (!expr || expr.type !== \"identifier\") {\n return { text: \"\", error: \"JSX expressions must be simple identifiers\" };\n }\n return { text: `\\${${expr.text}}` };\n }\n return { text: \"\", error: \"Unsupported JSX child\" };\n}\n","import type Parser from \"tree-sitter\";\n\nimport { withComment } from \"../../core/queries/comment.ts\";\nimport type { MessageMatch, QuerySpec, Translation } from \"../../core/queries/types.ts\";\nimport { buildAttrValue, buildTemplate } from \"./utils.ts\";\n\nexport const messageQuery: QuerySpec = withComment({\n pattern: `(\n [\n (jsx_element (jsx_opening_element name: (identifier) @name))\n (jsx_self_closing_element name: (identifier) @name)\n ] @call\n (#eq? @name \"Message\")\n )`,\n extract(match: Parser.QueryMatch): MessageMatch | undefined {\n const node = match.captures.find((c) => c.name === \"call\")?.node;\n if (!node) return undefined;\n let attrs: Parser.SyntaxNode[] = [];\n if (node.type === \"jsx_element\") {\n const open = node.childForFieldName(\"open_tag\");\n if (open) attrs = open.namedChildren;\n } else if (node.type === \"jsx_self_closing_element\") {\n attrs = node.namedChildren.slice(1);\n }\n let msgctxt: string | undefined;\n let childValue: Parser.SyntaxNode | undefined;\n for (const child of attrs) {\n if (child.type !== \"jsx_attribute\") continue;\n const name = child.child(0);\n const value = child.child(child.childCount - 1);\n if (name?.text === \"context\" && value?.type === \"string\") {\n msgctxt = value.text.slice(1, -1);\n } else if (name?.text === \"children\" && value) {\n childValue = value;\n }\n }\n let text = \"\";\n let error: string | undefined;\n if (node.type === \"jsx_element\") {\n ({ text, error } = buildTemplate(node));\n } else if (childValue) {\n ({ text, error } = buildAttrValue(childValue));\n }\n if (error) {\n return { node, error };\n }\n if (!text) return undefined;\n const translation: Translation = {\n id: text,\n message: [text],\n };\n if (msgctxt) translation.context = msgctxt;\n return { node, translation };\n },\n});\n","import type Parser from \"tree-sitter\";\n\nimport { withComment } from \"../../core/queries/comment.ts\";\nimport type { MessageMatch, QuerySpec, Translation } from \"../../core/queries/types.ts\";\nimport { buildTemplate } from \"./utils.ts\";\n\nfunction parseForms(node: Parser.SyntaxNode): { forms: string[]; error?: string } {\n const forms: string[] = [];\n if (node.type === \"jsx_expression\") {\n const arr = node.namedChildren[0];\n if (!arr || arr.type !== \"array\") {\n return { forms: [], error: \"Plural forms must be an array\" };\n }\n for (const el of arr.namedChildren) {\n if (el.type === \"jsx_element\" || el.type === \"jsx_fragment\") {\n const { text, error } = buildTemplate(el);\n if (error) return { forms: [], error };\n forms.push(text);\n } else if (el.type === \"string\") {\n forms.push(el.text.slice(1, -1));\n } else {\n return { forms: [], error: \"Unsupported plural form\" };\n }\n }\n }\n return { forms };\n}\n\nexport const pluralQuery: QuerySpec = withComment({\n pattern: `(\n [\n (jsx_element (jsx_opening_element name: (identifier) @name))\n (jsx_self_closing_element name: (identifier) @name)\n ] @call\n (#eq? @name \"Plural\")\n )`,\n extract(match: Parser.QueryMatch): MessageMatch | undefined {\n const node = match.captures.find((c) => c.name === \"call\")?.node;\n if (!node) return undefined;\n let attrs: Parser.SyntaxNode[] = [];\n if (node.type === \"jsx_element\") {\n const open = node.childForFieldName(\"open_tag\");\n if (open) attrs = open.namedChildren;\n } else if (node.type === \"jsx_self_closing_element\") {\n attrs = node.namedChildren.slice(1);\n }\n let msgctxt: string | undefined;\n let formsNode: Parser.SyntaxNode | null | undefined;\n for (const child of attrs) {\n if (child.type !== \"jsx_attribute\") continue;\n const name = child.child(0);\n const value = child.child(child.childCount - 1);\n if (name?.text === \"context\" && value?.type === \"string\") {\n msgctxt = value.text.slice(1, -1);\n } else if (name?.text === \"forms\" && value) {\n formsNode = value;\n }\n }\n if (!formsNode) return undefined;\n const { forms, error } = parseForms(formsNode);\n if (error) {\n return { node, error };\n }\n if (forms.length === 0) return undefined;\n const translation: Translation = {\n id: forms[0],\n plural: forms[1],\n message: forms,\n };\n if (msgctxt) translation.context = msgctxt;\n return { node, translation };\n },\n});\n","import type { QuerySpec } from \"../../core/queries/types.ts\";\nimport { messageQuery } from \"./message.ts\";\nimport { pluralQuery } from \"./plural.ts\";\n\nexport const queries: QuerySpec[] = [messageQuery, pluralQuery];\n","import fs from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport Parser from \"tree-sitter\";\n\nimport { getParser } from \"../core/parse.ts\";\nimport { getReference } from \"../core/queries/comment.ts\";\nimport { importQuery } from \"../core/queries/import.ts\";\nimport { queries as coreQueries } from \"../core/queries/index.ts\";\nimport type { Context, Translation } from \"../core/queries/types.ts\";\nimport { queries as reactQueries } from \"./queries/index.ts\";\n\nexport interface ParseResult {\n translations: Translation[];\n imports: string[];\n}\n\nexport function parseFile(filePath: string): ParseResult {\n const path = resolve(filePath);\n const source = fs.readFileSync(path, \"utf8\");\n return parseSource(source, path);\n}\n\nexport function parseSource(source: string, path: string): ParseResult {\n const context: Context = { path };\n const { parser, language } = getParser(path);\n const tree = parser.parse(source);\n\n const translations: Translation[] = [];\n const imports: string[] = [];\n const seen = new Set<number>();\n\n for (const spec of [...coreQueries, ...reactQueries]) {\n const query = new Parser.Query(language, spec.pattern);\n for (const match of query.matches(tree.rootNode)) {\n const message = spec.extract(match);\n if (!message) continue;\n const { node, translation, error } = message;\n if (seen.has(node.id)) continue;\n seen.add(node.id);\n const reference = getReference(node, context);\n if (translation) {\n translations.push({\n ...translation,\n comments: {\n ...translation.comments,\n reference,\n },\n });\n }\n if (error) {\n console.warn(`Parsing error at ${reference}: ${error}`);\n }\n }\n }\n\n const importTreeQuery = new Parser.Query(language, importQuery.pattern);\n for (const match of importTreeQuery.matches(tree.rootNode)) {\n const imp = importQuery.extract(match);\n if (imp) imports.push(imp);\n }\n\n return { translations, imports };\n}\n","import { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\n\nimport type { ExtractorPlugin } from \"../../plugin.ts\";\nimport { resolveImports } from \"../core/resolve.ts\";\nimport { parseSource } from \"./parse.ts\";\n\nconst filter = /\\.[cm]?[jt]sx$/;\n\nexport function react(): ExtractorPlugin {\n return {\n name: \"react\",\n setup(build) {\n build.context.logger?.debug(\"react plugin initialized\");\n build.onResolve({ filter: /.*/ }, ({ entrypoint, path }) => {\n return {\n entrypoint,\n path: resolve(path),\n };\n });\n build.onLoad({ filter }, async ({ entrypoint, path }) => {\n const contents = await readFile(path, \"utf8\");\n return { entrypoint, path, contents };\n });\n build.onExtract({ filter }, ({ entrypoint, path, contents }) => {\n const { translations, imports } = parseSource(contents, path);\n if (build.context.config.walk) {\n const paths = resolveImports(path, imports);\n for (const p of paths) {\n build.resolvePath({ entrypoint, path: p });\n }\n }\n return {\n entrypoint,\n path,\n translations,\n };\n });\n },\n } satisfies ExtractorPlugin;\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MAAM,QAAQ,OAAO,MAAM;KAC3B,MAAM,QAAQ,eAAeA,QAAM;AACnC,UAAK,MAAM,KAAK,MACZ,OAAM,YAAY;MAAE;MAAY,MAAM;;;AAG9C,WAAO;KACH;KACA;KACA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["path","path","importQuery: ImportQuerySpec","current: Parser.SyntaxNode | null","messageQuery: QuerySpec","allowed","messageInvalidQuery: QuerySpec","ids: string[]","strs: string[]","subMatch: Parser.QueryMatch","translation: Translation","contextMsgQuery: QuerySpec","msgCall","contextPluralQuery: QuerySpec","contextInvalidQuery: QuerySpec","gettextQuery: QuerySpec","gettextInvalidQuery: QuerySpec","msgCall","plainMsg","msgArg","ngettextQuery: QuerySpec","msgCall","npgettextQuery: QuerySpec","pgettextQuery: QuerySpec","pluralQuery: QuerySpec","queries: QuerySpec[]","messageQuery","pluralQuery","path","parseSource","context: Context","translations: Translation[]","warnings: Warning[]","imports: string[]","queries","fs","resolved: string[]","filter","namespace","path","parseSource","translations: GetTextTranslationRecord","headers: Record<string, string>","obsoleteTranslations: GetTextTranslationRecord","collected: GetTextTranslationRecord","existing","poObj: GetTextTranslations","path","defaultDestination: DestinationFn","defaultExclude: Exclude[]","strings: string[]","values: string[]","text","messageQuery: QuerySpec","attrs: Parser.SyntaxNode[]","msgctxt: string | undefined","childValue: Parser.SyntaxNode | undefined","error: string | undefined","translation: Translation","forms: string[]","pluralQuery: QuerySpec","attrs: Parser.SyntaxNode[]","msgctxt: string | undefined","formsNode: Parser.SyntaxNode | null | undefined","translation: Translation","queries: QuerySpec[]","context: Context","path","translations: Translation[]","warnings: Warning[]","path"],"sources":["../../src/plugins/cleanup/cleanup.ts","../../src/plugins/core/queries/comment.ts","../../src/plugins/core/queries/import.ts","../../src/plugins/core/queries/utils.ts","../../src/plugins/core/queries/message.ts","../../src/plugins/core/queries/plural-utils.ts","../../src/plugins/core/queries/context.ts","../../src/plugins/core/queries/gettext.ts","../../src/plugins/core/queries/ngettext.ts","../../src/plugins/core/queries/npgettext.ts","../../src/plugins/core/queries/pgettext.ts","../../src/plugins/core/queries/plural.ts","../../src/plugins/core/queries/index.ts","../../src/plugins/core/parse.ts","../../src/plugins/core/resolve.ts","../../src/plugins/core/core.ts","../../src/plugins/po/po.ts","../../src/configuration.ts","../../src/plugins/react/queries/utils.ts","../../src/plugins/react/queries/message.ts","../../src/plugins/react/queries/plural.ts","../../src/plugins/react/queries/index.ts","../../src/plugins/react/parse.ts","../../src/plugins/react/react.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\n\nimport * as gettextParser from \"gettext-parser\";\n\nimport type { Plugin } from \"../../plugin.ts\";\n\nexport function cleanup(): Plugin {\n return {\n name: \"cleanup\",\n setup(build) {\n build.context.logger?.debug(\"cleanup plugin initialized\");\n const processedDirs = new Set<string>();\n const generated = new Set<string>();\n\n build.onResolve({ namespace: \"cleanup\", filter: /.*/ }, (args) => {\n generated.add(args.path);\n return args;\n });\n\n build.onProcess({ namespace: \"cleanup\", filter: /.*/ }, async ({ path }) => {\n await build.defer(\"translate\");\n const dir = dirname(path);\n if (processedDirs.has(dir)) return undefined;\n processedDirs.add(dir);\n const files = await fs.readdir(dir).catch(() => []);\n for (const f of files.filter((p) => p.endsWith(\".po\"))) {\n const full = join(dir, f);\n if (generated.has(full)) continue;\n const contents = await fs.readFile(full).catch(() => undefined);\n if (!contents) continue;\n const parsed = gettextParser.po.parse(contents);\n const hasTranslations = Object.entries(parsed.translations || {}).some(([ctx, msgs]) =>\n Object.keys(msgs).some((id) => !(ctx === \"\" && id === \"\")),\n );\n if (hasTranslations) {\n build.context.logger?.warn({ path: full }, \"stray translation file\");\n } else {\n await fs.unlink(full);\n build.context.logger?.info({ path: full }, \"removed empty translation file\");\n }\n }\n return undefined;\n });\n },\n };\n}\n","import { relative } from \"node:path\";\nimport type Parser from \"tree-sitter\";\n\nimport type { Context, QuerySpec } from \"./types.ts\";\n\nexport function getReference(node: Parser.SyntaxNode, { path }: Context) {\n const line = node.startPosition.row + 1;\n const rel = relative(process.cwd(), path).replace(/\\\\+/g, \"/\");\n return `${rel}:${line}`;\n}\n\nfunction getComment(node: Parser.SyntaxNode): string {\n const text = node.text;\n if (text.startsWith(\"/*\")) {\n return text\n .slice(2, -2)\n .replace(/^\\s*\\*?\\s*/gm, \"\")\n .trim();\n }\n return text.replace(/^\\/\\/\\s?/, \"\").trim();\n}\n\nexport const withComment = (query: QuerySpec): QuerySpec => ({\n pattern: `(\n\t((comment) @comment)?\n .\n\t(_ ${query.pattern})\n)`,\n extract(match) {\n const result = query.extract(match);\n if (!result?.translation) {\n return result;\n }\n\n const comment = match.captures.find((c) => c.name === \"comment\")?.node;\n if (!comment) {\n return result;\n }\n\n if (comment) {\n result.translation.comments = {\n ...result.translation.comments,\n extracted: getComment(comment),\n };\n }\n\n return result;\n },\n});\n","import type Parser from \"tree-sitter\";\nimport type { ImportQuerySpec } from \"./types.ts\";\n\nexport const importQuery: ImportQuerySpec = {\n pattern: `\n [\n (import_statement\n source: (string (string_fragment) @import))\n (export_statement\n source: (string (string_fragment) @import))\n (call_expression\n function: (identifier) @func\n arguments: (arguments (string (string_fragment) @import))\n (#eq? @func \"require\"))\n (call_expression\n function: (member_expression\n object: (identifier) @obj\n property: (property_identifier) @method)\n arguments: (arguments (string (string_fragment) @import))\n (#eq? @obj \"require\")\n (#eq? @method \"resolve\"))\n (call_expression\n function: (import)\n arguments: (arguments (string (string_fragment) @import)))\n ]\n `,\n extract(match: Parser.QueryMatch): string | undefined {\n const node = match.captures.find((c) => c.name === \"import\")?.node;\n return node?.text;\n },\n};\n","import type Parser from \"tree-sitter\";\n\nexport const callPattern = (fnName: string, args: string, allowMember = true): string => `(\n (call_expression\n function: ${\n allowMember\n ? `[\n (identifier) @func\n (member_expression property: (property_identifier) @func)\n ]`\n : `(identifier) @func`\n }\n arguments: ${args}\n ) @call\n (#eq? @func \"${fnName}\")\n)`;\n\nexport function isDescendant(node: Parser.SyntaxNode, ancestor: Parser.SyntaxNode): boolean {\n let current: Parser.SyntaxNode | null = node;\n while (current) {\n if (current.id === ancestor.id) return true;\n current = current.parent;\n }\n return false;\n}\n","import type Parser from \"tree-sitter\";\nimport { withComment } from \"./comment.ts\";\nimport type { MessageMatch, QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nconst notInPlural = (query: QuerySpec): QuerySpec => ({\n pattern: query.pattern,\n extract(match) {\n const result = query.extract(match);\n if (!result?.node) {\n return result;\n }\n\n let parent = result.node.parent;\n\n if (parent && parent.type === \"arguments\") {\n parent = parent.parent;\n }\n\n if (parent && parent.type === \"call_expression\") {\n const fn = parent.childForFieldName(\"function\");\n if (fn) {\n if (\n (fn.type === \"identifier\" &&\n (fn.text === \"plural\" ||\n fn.text === \"ngettext\" ||\n fn.text === \"pgettext\" ||\n fn.text === \"npgettext\")) ||\n (fn.type === \"member_expression\" &&\n [\"plural\", \"ngettext\", \"pgettext\", \"npgettext\"].includes(\n fn.childForFieldName(\"property\")?.text ?? \"\",\n ))\n ) {\n return undefined;\n }\n }\n }\n\n return result;\n },\n});\n\nexport const messageArg = `[\n (string (string_fragment) @msgid)\n (object\n (_)*\n (pair\n key: (property_identifier) @id_key\n value: (string (string_fragment) @id)\n (#eq? @id_key \"id\")\n )?\n (_)*\n (pair\n key: (property_identifier) @msg_key\n value: (string (string_fragment) @message)\n (#eq? @msg_key \"message\")\n )?\n (_)*\n )\n (template_string) @tpl\n]`;\n\nexport const messageArgs = `[ (arguments ${messageArg}) (template_string) @tpl ]`;\n\nexport const extractMessage =\n (name: string) =>\n (match: Parser.QueryMatch): MessageMatch | undefined => {\n const node = match.captures.find((c) => c.name === \"call\")?.node;\n if (!node) {\n return undefined;\n }\n\n const msgid = match.captures.find((c) => c.name === \"msgid\")?.node.text;\n if (msgid) {\n return {\n node,\n translation: {\n id: msgid,\n message: [msgid],\n },\n };\n }\n\n const tpl = match.captures.find((c) => c.name === \"tpl\")?.node;\n if (tpl) {\n for (const child of tpl.children) {\n if (child.type !== \"template_substitution\") {\n continue;\n }\n\n const expr = child.namedChildren[0];\n if (!expr || expr.type !== \"identifier\") {\n return {\n node,\n error: `${name}() template expressions must be simple identifiers`,\n };\n }\n }\n\n const text = tpl.text.slice(1, -1);\n\n return {\n node,\n translation: { id: text, message: [text] },\n };\n }\n\n const id = match.captures.find((c) => c.name === \"id\")?.node.text;\n const message = match.captures.find((c) => c.name === \"message\")?.node.text;\n const msgId = id ?? message;\n if (!msgId) {\n return undefined;\n }\n\n const msgstr = message ?? id ?? \"\";\n\n return {\n node,\n translation: {\n id: msgId,\n message: [msgstr],\n },\n };\n };\n\nexport const messageQuery: QuerySpec = notInPlural(\n withComment({\n pattern: callPattern(\"message\", messageArgs),\n extract: extractMessage(\"message\"),\n }),\n);\n\nconst allowed = new Set([\"string\", \"object\", \"template_string\"]);\n\nexport const messageInvalidQuery: QuerySpec = notInPlural({\n pattern: callPattern(\"message\", \"(arguments (_) @arg)\"),\n extract(match) {\n const call = match.captures.find((c) => c.name === \"call\")?.node;\n const node = match.captures.find((c) => c.name === \"arg\")?.node;\n\n if (!call || !node) {\n return undefined;\n }\n\n if (allowed.has(node.type)) {\n return undefined;\n }\n\n return {\n node,\n error: \"message() argument must be a string literal, object literal, or template literal\",\n };\n },\n});\n","import type Parser from \"tree-sitter\";\nimport { extractMessage } from \"./message.ts\";\nimport type { MessageMatch, Translation } from \"./types.ts\";\nimport { isDescendant } from \"./utils.ts\";\n\nexport const extractPluralForms =\n (name: string) =>\n (match: Parser.QueryMatch): MessageMatch | undefined => {\n const call = match.captures.find((c) => c.name === \"call\")?.node;\n const n = match.captures.find((c) => c.name === \"n\")?.node;\n if (!call || !n || n.nextNamedSibling) {\n return undefined;\n }\n\n const msgctxt = match.captures.find((c) => c.name === \"msgctxt\")?.node?.text;\n const msgNodes = match.captures.filter((c) => c.name === \"msg\").map((c) => c.node);\n\n const ids: string[] = [];\n const strs: string[] = [];\n\n for (const node of msgNodes) {\n const relevant = match.captures.filter(\n (c) => [\"msgid\", \"id\", \"message\", \"tpl\"].includes(c.name) && isDescendant(c.node, node),\n );\n\n const subMatch: Parser.QueryMatch = {\n pattern: 0,\n captures: [{ name: \"call\", node }, ...relevant],\n };\n\n const result = extractMessage(name)(subMatch);\n if (!result) continue;\n if (result.error) {\n return { node: call, error: result.error };\n }\n if (result.translation) {\n ids.push(result.translation.id);\n strs.push(result.translation.message[0] ?? \"\");\n }\n }\n\n if (ids.length === 0) {\n return undefined;\n }\n\n const translation: Translation = {\n id: ids[0],\n plural: ids[1],\n message: strs,\n };\n if (msgctxt) translation.context = msgctxt;\n\n return { node: call, translation };\n };\n","import { withComment } from \"./comment.ts\";\nimport { extractMessage, messageArgs } from \"./message.ts\";\nimport { extractPluralForms } from \"./plural-utils.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nconst ctxCall = callPattern(\"context\", `(arguments (string (string_fragment) @msgctxt))`)\n .replace(/@call/g, \"@ctx\")\n .replace(/@func/g, \"@ctxfn\");\n\nexport const contextMsgQuery: QuerySpec = withComment({\n pattern: `(\n (call_expression\n function: (member_expression\n object: ${ctxCall}\n property: (property_identifier) @func\n )\n arguments: ${messageArgs}\n ) @call\n (#eq? @func \"message\")\n)`,\n extract(match) {\n const result = extractMessage(\"context.message\")(match);\n const contextNode = match.captures.find((c) => c.name === \"msgctxt\")?.node;\n if (!result || !result.translation || !contextNode) {\n return result;\n }\n return {\n node: result.node,\n translation: {\n ...result.translation,\n context: contextNode.text,\n },\n };\n },\n});\n\nconst msgCall = callPattern(\"message\", messageArgs, false).replace(/@call/g, \"@msg\").replace(/@func/g, \"@msgfn\");\n\nexport const contextPluralQuery: QuerySpec = withComment({\n pattern: `(\n (call_expression\n function: (member_expression\n object: ${ctxCall}\n property: (property_identifier) @func\n )\n arguments: (arguments (\n (${msgCall} (\",\" )?)+\n (number) @n\n ))\n ) @call\n (#eq? @func \"plural\")\n)`,\n extract: extractPluralForms(\"context.plural\"),\n});\n\nexport const contextInvalidQuery: QuerySpec = withComment({\n pattern: ctxCall,\n extract(match) {\n const call = match.captures.find((c) => c.name === \"ctx\")?.node;\n if (!call) {\n return undefined;\n }\n\n const parent = call.parent;\n if (parent && parent.type === \"member_expression\" && parent.childForFieldName(\"object\")?.id === call.id) {\n const property = parent.childForFieldName(\"property\")?.text;\n const grandparent = parent.parent;\n if (\n grandparent &&\n grandparent.type === \"call_expression\" &&\n grandparent.childForFieldName(\"function\")?.id === parent.id &&\n (property === \"message\" || property === \"plural\")\n ) {\n return undefined;\n }\n }\n\n return {\n node: call,\n error: \"context() must be used with message() or plural() in the same expression\",\n };\n },\n});\n","import { withComment } from \"./comment.ts\";\nimport { extractMessage, messageArgs } from \"./message.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nexport const gettextQuery: QuerySpec = withComment({\n pattern: callPattern(\"gettext\", messageArgs),\n extract: extractMessage(\"gettext\"),\n});\n\nconst allowed = new Set([\"string\", \"object\", \"template_string\", \"identifier\", \"call_expression\"]);\n\nexport const gettextInvalidQuery: QuerySpec = {\n pattern: callPattern(\"gettext\", \"(arguments (_) @arg)\"),\n extract(match) {\n const call = match.captures.find((c) => c.name === \"call\")?.node;\n const node = match.captures.find((c) => c.name === \"arg\")?.node;\n\n if (!call || !node) {\n return undefined;\n }\n\n if (allowed.has(node.type)) {\n return undefined;\n }\n\n return {\n node,\n error: \"gettext() argument must be a string literal, object literal, or template literal\",\n };\n },\n};\n","import { withComment } from \"./comment.ts\";\nimport { messageArg, messageArgs } from \"./message.ts\";\nimport { extractPluralForms } from \"./plural-utils.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nconst msgCall = callPattern(\"message\", messageArgs).replace(/@call/g, \"@msg\").replace(/@func/g, \"@msgfn\");\nconst plainMsg = `(${messageArg}) @msg`;\nconst msgArg = `[${msgCall} ${plainMsg}]`;\n\nexport const ngettextQuery: QuerySpec = withComment({\n pattern: callPattern(\"ngettext\", `(arguments ${msgArg} \",\" ${msgArg} (\",\" ${msgArg})* \",\" (_) @n)`),\n extract: extractPluralForms(\"ngettext\"),\n});\n","import { withComment } from \"./comment.ts\";\nimport { messageArg, messageArgs } from \"./message.ts\";\nimport { extractPluralForms } from \"./plural-utils.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nconst msgCall = callPattern(\"message\", messageArgs).replace(/@call/g, \"@msg\").replace(/@func/g, \"@msgfn\");\nconst plainMsg = `(${messageArg}) @msg`;\nconst msgArg = `[${msgCall} ${plainMsg}]`;\n\nexport const npgettextQuery: QuerySpec = withComment({\n pattern: callPattern(\n \"npgettext\",\n `(arguments (string (string_fragment) @msgctxt) \",\" ${msgArg} \",\" ${msgArg} (\",\" ${msgArg})* \",\" (_) @n)`,\n ),\n extract: extractPluralForms(\"npgettext\"),\n});\n","import { withComment } from \"./comment.ts\";\nimport { extractMessage, messageArg } from \"./message.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nexport const pgettextQuery: QuerySpec = withComment({\n pattern: callPattern(\"pgettext\", `(arguments (string (string_fragment) @msgctxt) \",\" ${messageArg})`),\n extract(match) {\n const result = extractMessage(\"pgettext\")(match);\n const contextNode = match.captures.find((c) => c.name === \"msgctxt\")?.node;\n if (!result || !contextNode || !result.translation) {\n return result;\n }\n return {\n node: result.node,\n translation: {\n ...result.translation,\n context: contextNode.text,\n },\n };\n },\n});\n","import { withComment } from \"./comment.ts\";\nimport { messageArgs } from \"./message.ts\";\nimport { extractPluralForms } from \"./plural-utils.ts\";\nimport type { QuerySpec } from \"./types.ts\";\nimport { callPattern } from \"./utils.ts\";\n\nconst msgCall = callPattern(\"message\", messageArgs, false).replace(/@call/g, \"@msg\").replace(/@func/g, \"@msgfn\");\n\nexport const pluralQuery: QuerySpec = withComment({\n pattern: callPattern(\n \"plural\",\n `(arguments (\n (${msgCall} (\",\" )?)+\n (number) @n\n ))`,\n false,\n ),\n extract: extractPluralForms(\"plural\"),\n});\n","import { contextInvalidQuery, contextMsgQuery, contextPluralQuery } from \"./context.ts\";\nimport { gettextInvalidQuery, gettextQuery } from \"./gettext.ts\";\nimport { messageInvalidQuery, messageQuery } from \"./message.ts\";\nimport { ngettextQuery } from \"./ngettext.ts\";\nimport { npgettextQuery } from \"./npgettext.ts\";\nimport { pgettextQuery } from \"./pgettext.ts\";\nimport { pluralQuery } from \"./plural.ts\";\nimport type { QuerySpec } from \"./types.ts\";\n\nexport type { MessageMatch, QuerySpec } from \"./types.ts\";\n\nexport const queries: QuerySpec[] = [\n messageQuery,\n messageInvalidQuery,\n gettextQuery,\n gettextInvalidQuery,\n pluralQuery,\n ngettextQuery,\n pgettextQuery,\n npgettextQuery,\n contextMsgQuery,\n contextPluralQuery,\n contextInvalidQuery,\n];\n","import fs from \"node:fs\";\nimport { extname, resolve } from \"node:path\";\n\nimport Parser from \"tree-sitter\";\nimport JavaScript from \"tree-sitter-javascript\";\nimport TS from \"tree-sitter-typescript\";\n\nimport { getReference } from \"./queries/comment.ts\";\nimport { importQuery } from \"./queries/import.ts\";\nimport { queries } from \"./queries/index.ts\";\nimport type { Context, Translation, Warning } from \"./queries/types.ts\";\n\nexport interface ParseResult {\n translations: Translation[];\n imports: string[];\n warnings: Warning[];\n}\n\nfunction getLanguage(ext: string) {\n switch (ext) {\n case \".ts\":\n return TS.typescript;\n case \".tsx\":\n return TS.tsx;\n default:\n return JavaScript;\n }\n}\n\nconst parserCache = new Map<string, { parser: Parser; language: Parser.Language }>();\nconst queryCache = new WeakMap<Parser.Language, Map<string, Parser.Query>>();\n\nfunction getCachedParser(ext: string) {\n let cached = parserCache.get(ext);\n if (!cached) {\n const parser = new Parser();\n const language = getLanguage(ext) as Parser.Language;\n parser.setLanguage(language);\n cached = { parser, language };\n parserCache.set(ext, cached);\n }\n return cached;\n}\n\nfunction getCachedQuery(language: Parser.Language, pattern: string) {\n let cache = queryCache.get(language);\n if (!cache) {\n cache = new Map();\n queryCache.set(language, cache);\n }\n\n let query = cache.get(pattern);\n if (!query) {\n query = new Parser.Query(language, pattern);\n cache.set(pattern, query);\n }\n\n return query;\n}\n\nexport function getParser(path: string) {\n const ext = extname(path);\n return getCachedParser(ext);\n}\n\nexport function getQuery(language: Parser.Language, pattern: string) {\n return getCachedQuery(language, pattern);\n}\n\nexport function parseFile(filePath: string): ParseResult {\n const path = resolve(filePath);\n const source = fs.readFileSync(path, \"utf8\");\n return parseSource(source, path);\n}\n\nexport function parseSource(source: string, path: string): ParseResult {\n const context: Context = {\n path,\n };\n\n const { parser, language } = getParser(path);\n const tree = parser.parse(source);\n\n const translations: Translation[] = [];\n const warnings: Warning[] = [];\n const imports: string[] = [];\n\n const seen = new Set<number>();\n\n for (const spec of queries) {\n const query = getCachedQuery(language, spec.pattern);\n for (const match of query.matches(tree.rootNode)) {\n const message = spec.extract(match);\n if (!message) {\n continue;\n }\n\n const { node, translation, error } = message;\n if (seen.has(node.id)) {\n continue;\n }\n seen.add(node.id);\n const reference = getReference(node, context);\n\n if (translation) {\n translations.push({\n ...translation,\n comments: {\n ...translation.comments,\n reference,\n },\n });\n }\n\n if (error) {\n warnings.push({\n error,\n reference,\n });\n }\n }\n }\n\n const importTreeQuery = getCachedQuery(language, importQuery.pattern);\n for (const match of importTreeQuery.matches(tree.rootNode)) {\n const imp = importQuery.extract(match);\n if (imp) {\n imports.push(imp);\n }\n }\n\n return { translations, imports, warnings };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { ResolverFactory } from \"oxc-resolver\";\n\nfunction findTsconfig(dir: string): string | undefined {\n let current = dir;\n while (true) {\n const config = path.join(current, \"tsconfig.json\");\n if (fs.existsSync(config)) {\n return config;\n }\n const parent = path.dirname(current);\n if (parent === current) {\n return undefined;\n }\n current = parent;\n }\n}\n\nconst resolverCache = new Map<string, ResolverFactory>();\n\nfunction getResolver(dir: string) {\n const tsconfig = findTsconfig(dir);\n const key = tsconfig ?? \"__default__\";\n let resolver = resolverCache.get(key);\n if (!resolver) {\n resolver = new ResolverFactory({\n extensions: [\".ts\", \".tsx\", \".js\", \".jsx\", \".mjs\", \".cjs\", \".json\"],\n conditionNames: [\"import\", \"require\", \"node\"],\n ...(tsconfig ? { tsconfig: { configFile: tsconfig } } : {}),\n });\n resolverCache.set(key, resolver);\n }\n return resolver;\n}\n\nfunction resolveFromDir(dir: string, spec: string): string | undefined {\n const resolver = getResolver(dir);\n const res = resolver.sync(dir, spec) as { path?: string };\n return res.path;\n}\n\nexport function resolveImport(file: string, spec: string): string | undefined {\n const dir = path.dirname(path.resolve(file));\n return resolveFromDir(dir, spec);\n}\n\nexport function resolveImports(file: string, imports: string[]): string[] {\n const dir = path.dirname(path.resolve(file));\n const resolver = getResolver(dir);\n const resolved: string[] = [];\n for (const spec of imports) {\n const res = resolver.sync(dir, spec) as { path?: string };\n if (res.path) {\n resolved.push(res.path);\n }\n }\n return resolved;\n}\n","import { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\n\nimport type { Plugin } from \"../../plugin.ts\";\nimport { parseSource } from \"./parse.ts\";\nimport type { Translation } from \"./queries/types.ts\";\nimport { resolveImports } from \"./resolve.ts\";\n\nconst filter = /\\.([cm]?tsx?|jsx?)$/;\nconst namespace = \"source\";\n\nexport function core(): Plugin<string, Translation[]> {\n return {\n name: \"core\",\n setup(build) {\n build.context.logger?.debug(\"core plugin initialized\");\n build.onResolve({ filter, namespace }, ({ entrypoint, path }) => {\n return {\n entrypoint,\n namespace,\n path: resolve(path),\n };\n });\n\n build.onLoad({ filter, namespace }, async ({ entrypoint, path }) => {\n const data = await readFile(path, \"utf8\");\n return {\n entrypoint,\n path,\n namespace,\n data,\n };\n });\n\n build.onProcess({ filter, namespace }, ({ entrypoint, path, data }) => {\n const { translations, imports, warnings } = parseSource(data, path);\n\n if (build.context.config.walk) {\n const paths = resolveImports(path, imports);\n for (const path of paths) {\n build.resolve({ entrypoint, path, namespace });\n }\n }\n\n for (const warning of warnings) {\n build.context.logger?.warn(`${warning.error} at ${warning.reference}`);\n }\n\n build.resolve({\n entrypoint,\n path,\n namespace: \"translate\",\n data: translations,\n });\n\n return undefined;\n });\n },\n };\n}\n","import fs from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\n\nimport type { GetTextTranslationRecord, GetTextTranslations } from \"gettext-parser\";\nimport * as gettextParser from \"gettext-parser\";\nimport { getFormula, getNPlurals } from \"plural-forms\";\n\nimport type { ObsoleteStrategy } from \"../../configuration.ts\";\nimport type { Plugin } from \"../../plugin.ts\";\nimport type { Translation } from \"../core/queries/types.ts\";\n\nexport interface Collected {\n translations: GetTextTranslationRecord;\n}\n\nexport function formatDate(date: Date): string {\n const pad = (n: number) => n.toString().padStart(2, \"0\");\n const year = date.getFullYear();\n const month = pad(date.getMonth() + 1);\n const day = pad(date.getDate());\n const hours = pad(date.getHours());\n const minutes = pad(date.getMinutes());\n const tzo = -date.getTimezoneOffset();\n const sign = tzo >= 0 ? \"+\" : \"-\";\n const offsetHours = pad(Math.floor(Math.abs(tzo) / 60));\n const offsetMinutes = pad(Math.abs(tzo) % 60);\n return `${year}-${month}-${day} ${hours}:${minutes}${sign}${offsetHours}${offsetMinutes}`;\n}\n\nexport function collect(source: Translation[], locale?: string): GetTextTranslationRecord {\n const translations: GetTextTranslationRecord = { \"\": {} };\n const nplurals = locale ? getNPlurals(locale) : undefined;\n\n for (const { context, id, message, comments, obsolete, plural } of source) {\n const ctx = context || \"\";\n if (!translations[ctx]) {\n translations[ctx] = {};\n }\n\n const length = plural ? (nplurals ?? message.length) : 1;\n\n const existing = translations[ctx][id];\n const refs = new Set<string>();\n if (existing?.comments?.reference) {\n existing.comments.reference.split(/\\r?\\n|\\r/).forEach((r) => {\n refs.add(r);\n });\n }\n if (comments?.reference) {\n comments.reference.split(/\\r?\\n|\\r/).forEach((r) => {\n refs.add(r);\n });\n }\n\n const msgstr = existing?.msgstr ? existing.msgstr.slice(0, length) : Array.from({ length }, () => \"\");\n while (msgstr.length < length) msgstr.push(\"\");\n\n translations[ctx][id] = {\n msgctxt: context || undefined,\n msgid: id,\n msgid_plural: plural,\n msgstr,\n comments: {\n ...existing?.comments,\n ...comments,\n reference: refs.size ? Array.from(refs).join(\"\\n\") : undefined,\n },\n obsolete: existing?.obsolete ?? obsolete,\n };\n }\n\n return translations;\n}\n\nexport function merge(\n sources: Collected[],\n existing: string | Buffer | undefined,\n obsolete: ObsoleteStrategy,\n locale: string,\n generatedAt: Date,\n): string {\n let headers: Record<string, string> = {};\n let translations: GetTextTranslationRecord = { \"\": {} };\n let obsoleteTranslations: GetTextTranslationRecord = {};\n const nplurals = getNPlurals(locale);\n\n if (existing) {\n const parsed = gettextParser.po.parse(existing);\n headers = parsed.headers || {};\n translations = parsed.translations || { \"\": {} };\n obsoleteTranslations = parsed.obsolete || {};\n for (const ctx of Object.keys(translations)) {\n for (const id of Object.keys(translations[ctx])) {\n if (ctx === \"\" && id === \"\") continue;\n translations[ctx][id].obsolete = true;\n }\n }\n }\n\n const collected: GetTextTranslationRecord = { \"\": {} };\n for (const { translations: record } of sources) {\n for (const [ctx, msgs] of Object.entries(record)) {\n if (!collected[ctx]) collected[ctx] = {};\n for (const [id, entry] of Object.entries(msgs)) {\n const existing = collected[ctx][id];\n const refs = new Set<string>();\n if (existing?.comments?.reference) {\n existing.comments.reference.split(/\\r?\\n|\\r/).forEach((r) => {\n refs.add(r);\n });\n }\n if (entry.comments?.reference) {\n entry.comments.reference.split(/\\r?\\n|\\r/).forEach((r) => {\n refs.add(r);\n });\n }\n collected[ctx][id] = {\n ...existing,\n ...entry,\n comments: {\n ...existing?.comments,\n ...entry.comments,\n reference: refs.size ? Array.from(refs).join(\"\\n\") : undefined,\n },\n };\n }\n }\n }\n\n for (const [ctx, msgs] of Object.entries(collected)) {\n if (!translations[ctx]) translations[ctx] = {};\n for (const [id, entry] of Object.entries(msgs)) {\n const existingEntry = translations[ctx][id] ?? obsoleteTranslations[ctx]?.[id];\n if (existingEntry) {\n entry.msgstr = existingEntry.msgstr;\n entry.comments = {\n ...entry.comments,\n translator: existingEntry.comments?.translator,\n };\n }\n entry.obsolete = false;\n entry.msgstr = entry.msgstr.slice(0, nplurals);\n while (entry.msgstr.length < nplurals) entry.msgstr.push(\"\");\n translations[ctx][id] = entry;\n if (obsoleteTranslations[ctx]) delete obsoleteTranslations[ctx][id];\n }\n }\n\n for (const ctx of Object.keys(translations)) {\n for (const id of Object.keys(translations[ctx])) {\n if (ctx === \"\" && id === \"\") continue;\n const entry = translations[ctx][id];\n if (entry.obsolete) {\n if (!obsoleteTranslations[ctx]) obsoleteTranslations[ctx] = {};\n obsoleteTranslations[ctx][id] = entry;\n delete translations[ctx][id];\n }\n }\n }\n\n headers = {\n ...headers,\n \"content-type\": headers[\"content-type\"] || \"text/plain; charset=UTF-8\",\n \"plural-forms\": `nplurals=${nplurals}; plural=${getFormula(locale)};`,\n language: locale,\n \"pot-creation-date\": formatDate(generatedAt),\n \"x-generator\": \"@let-value/translate-extract\",\n };\n\n const poObj: GetTextTranslations = {\n charset: \"utf-8\",\n headers,\n translations,\n ...(obsolete === \"mark\" && Object.keys(obsoleteTranslations).length ? { obsolete: obsoleteTranslations } : {}),\n };\n\n return gettextParser.po.compile(poObj).toString();\n}\n\nconst namespace = \"translate\";\n\nexport function po(): Plugin {\n return {\n name: \"po\",\n setup(build) {\n build.context.logger?.debug(\"po plugin initialized\");\n const collections = new Map<\n string,\n {\n locale: string;\n translations: Translation[];\n }\n >();\n let dispatched = false;\n\n build.onResolve({ filter: /.*/, namespace }, async ({ entrypoint, path, data }) => {\n if (!data || !Array.isArray(data)) {\n return undefined;\n }\n\n for (const locale of build.context.config.locales) {\n const destination = build.context.config.destination({ entrypoint, locale, path });\n if (!collections.has(destination)) {\n collections.set(destination, { locale, translations: [] });\n }\n\n collections.get(destination)?.translations.push(...data);\n }\n\n build.defer(\"source\").then(() => {\n if (dispatched) {\n return;\n }\n dispatched = true;\n\n for (const path of collections.keys()) {\n build.load({ entrypoint, path, namespace });\n }\n });\n\n return undefined;\n });\n\n build.onLoad({ filter: /.*\\.po$/, namespace }, async ({ entrypoint, path }) => {\n const data = await fs.readFile(path).catch(() => undefined);\n return {\n entrypoint,\n path,\n namespace,\n data,\n };\n });\n\n build.onProcess({ filter: /.*\\.po$/, namespace }, async ({ entrypoint, path, data }) => {\n const collected = collections.get(path);\n if (!collected) {\n build.context.logger?.warn({ path }, \"no translations collected for this path\");\n return undefined;\n }\n\n const { locale, translations } = collected;\n\n const record = collect(translations, locale);\n\n const out = merge(\n [{ translations: record }],\n data as never,\n build.context.config.obsolete,\n locale,\n build.context.generatedAt,\n );\n await fs.mkdir(dirname(path), { recursive: true });\n await fs.writeFile(path, out);\n\n build.resolve({\n entrypoint,\n path,\n namespace: \"cleanup\",\n data: translations,\n });\n });\n },\n };\n}\n","import { basename, dirname, extname, join } from \"node:path\";\nimport type { Locale } from \"@let-value/translate\";\nimport type { LevelWithSilent } from \"pino\";\n\nimport type { Plugin } from \"./plugin.ts\";\nimport { cleanup } from \"./plugins/cleanup/cleanup.ts\";\nimport { core } from \"./plugins/core/core.ts\";\nimport { po } from \"./plugins/po/po.ts\";\n\nexport type DestinationFn = (args: { locale: string; entrypoint: string; path: string }) => string;\nexport type ExcludeFn = (args: { entrypoint: string; path: string }) => boolean;\nexport type Exclude = RegExp | ExcludeFn;\n\nconst defaultPlugins = { core, po, cleanup };\ntype DefaultPlugins = typeof defaultPlugins;\n\n/**\n * Strategy to handle obsolete translations in existing locale files:\n * - \"mark\": keep obsolete entries in the locale file but mark them as obsolete\n * - \"remove\": remove obsolete entries from the locale file\n */\nexport type ObsoleteStrategy = \"mark\" | \"remove\";\n\nexport interface EntrypointConfig {\n entrypoint: string;\n destination?: DestinationFn;\n obsolete?: ObsoleteStrategy;\n walk?: boolean;\n exclude?: Exclude | Exclude[];\n}\n\nexport interface UserConfig {\n /**\n * Default locale to use as the base for extraction\n * @default \"en\"\n * @see {@link Locale} for available locales\n */\n defaultLocale?: Locale;\n /**\n * Array of locales to extract translations for\n * @default [defaultLocale]\n * @see {@link Locale} for available locales\n */\n locales?: Locale[];\n /**\n * Array of plugins to use or a function to override the default plugins\n * @default DefaultPlugins\n * @see {@link DefaultPlugins} for available plugins\n */\n plugins?: Plugin[] | ((defaultPlugins: DefaultPlugins) => Plugin[]);\n /**\n * One or more entrypoints to extract translations from, could be:\n * - file path, will be treated as a single file entrypoint\n * - glob pattern will be expanded to match files, each treated as a separate entrypoint\n * - configuration object with options for the entrypoint\n * @see {@link EntrypointConfig} for configuration options\n */\n entrypoints: string | EntrypointConfig | Array<string | EntrypointConfig>;\n /**\n * Function to determine the destination path for each extracted locale file\n * @default `./translations/entrypoint.locale.po`\n * @see {@link DestinationFn}\n * @see Can be overridden per entrypoint via `destination` in {@link EntrypointConfig\n */\n destination?: DestinationFn;\n /**\n * Strategy to handle obsolete translations in existing locale files\n * @default \"mark\"\n * @see {@link ObsoleteStrategy} for available strategies\n * @see Can be overridden per entrypoint via `obsolete` in {@link EntrypointConfig\n */\n obsolete?: ObsoleteStrategy;\n /**\n * Whether to recursively walk dependencies of the entrypoints\n * @default true\n * @see Can be overridden per entrypoint via `walk` in {@link EntrypointConfig}.\n */\n walk?: boolean;\n /**\n * Paths or patterns to exclude from extraction, applied to all entrypoints\n * @default [/node_modules/, /dist/, /build/]\n * @see Can be overridden per entrypoint via `exclude` in {@link EntrypointConfig}.\n */\n exclude?: Exclude | Exclude[];\n /**\n * Log level for the extraction process\n * @default \"info\"\n */\n logLevel?: LevelWithSilent;\n}\n\nexport interface ResolvedEntrypoint extends Omit<EntrypointConfig, \"exclude\"> {\n exclude?: Exclude[];\n}\n\nexport interface ResolvedConfig {\n plugins: Plugin[];\n entrypoints: ResolvedEntrypoint[];\n defaultLocale: string;\n locales: string[];\n destination: DestinationFn;\n obsolete: ObsoleteStrategy;\n walk: boolean;\n logLevel: LevelWithSilent;\n exclude: Exclude[];\n}\n\nconst defaultDestination: DestinationFn = ({ entrypoint, locale }) =>\n join(dirname(entrypoint), \"translations\", `${basename(entrypoint, extname(entrypoint))}.${locale}.po`);\n\nconst defaultExclude: Exclude[] = [\n /(?:^|[\\\\/])node_modules(?:[\\\\/]|$)/,\n /(?:^|[\\\\/])dist(?:[\\\\/]|$)/,\n /(?:^|[\\\\/])build(?:[\\\\/]|$)/,\n];\n\nfunction normalizeExclude(exclude?: Exclude | Exclude[]): Exclude[] {\n if (!exclude) return [];\n return Array.isArray(exclude) ? exclude : [exclude];\n}\n\nfunction resolveEntrypoint(ep: string | EntrypointConfig): ResolvedEntrypoint {\n if (typeof ep === \"string\") {\n return { entrypoint: ep };\n }\n const { entrypoint, destination, obsolete, exclude } = ep;\n return { entrypoint, destination, obsolete, exclude: exclude ? normalizeExclude(exclude) : undefined };\n}\n\nfunction resolvePlugins(user?: UserConfig[\"plugins\"]): Plugin[] {\n if (typeof user === \"function\") {\n return user(defaultPlugins);\n }\n if (Array.isArray(user)) {\n return [...Object.values(defaultPlugins).map((plugin) => plugin()), ...user];\n }\n return Object.values(defaultPlugins).map((plugin) => plugin());\n}\n\n/**\n * Type helper to make it easier to use translate.config.ts\n * @param config - {@link UserConfig}.\n */\nexport function defineConfig(config: UserConfig): ResolvedConfig {\n const defaultLocale = config.defaultLocale ?? \"en\";\n\n const plugins = resolvePlugins(config.plugins);\n\n const raw = Array.isArray(config.entrypoints) ? config.entrypoints : [config.entrypoints];\n const entrypoints = raw.map(resolveEntrypoint);\n\n return {\n plugins,\n entrypoints,\n defaultLocale,\n locales: config.locales ?? [defaultLocale],\n destination: config.destination ?? defaultDestination,\n obsolete: config.obsolete ?? \"mark\",\n walk: config.walk ?? true,\n logLevel: config.logLevel ?? \"info\",\n exclude: config.exclude ? normalizeExclude(config.exclude) : defaultExclude,\n };\n}\n","import type Parser from \"tree-sitter\";\n\nexport function buildTemplate(node: Parser.SyntaxNode): { text: string; error?: string } {\n const children = node.namedChildren.slice(1, -1);\n const strings: string[] = [\"\"];\n const values: string[] = [];\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (child.type === \"jsx_text\") {\n let text = child.text;\n if (i === 0) text = text.replace(/^\\s+/, \"\");\n if (i === children.length - 1) text = text.replace(/\\s+$/, \"\");\n if (text) strings[strings.length - 1] += text;\n } else if (child.type === \"jsx_expression\") {\n const expr = child.namedChildren[0];\n if (!expr) {\n return { text: \"\", error: \"Empty JSX expression\" };\n }\n \n if (expr.type === \"identifier\") {\n values.push(expr.text);\n strings.push(\"\");\n } else if (expr.type === \"string\") {\n strings[strings.length - 1] += expr.text.slice(1, -1);\n } else if (expr.type === \"template_string\") {\n // Check if it's a simple template string with no substitutions\n const hasSubstitutions = expr.children.some(c => c.type === \"template_substitution\");\n if (hasSubstitutions) {\n return { text: \"\", error: \"JSX expressions with template substitutions are not supported\" };\n }\n // Extract the text content from the template string\n const content = expr.text.slice(1, -1); // Remove backticks\n strings[strings.length - 1] += content;\n } else {\n return { text: \"\", error: \"JSX expressions must be simple identifiers, strings, or template literals\" };\n }\n } else if (child.type === \"string\") {\n strings[strings.length - 1] += child.text.slice(1, -1);\n } else {\n return { text: \"\", error: \"Unsupported JSX child\" };\n }\n }\n let text = \"\";\n for (let i = 0; i < strings.length; i++) {\n text += strings[i];\n if (values[i]) {\n text += `\\${${values[i]}}`;\n }\n }\n return { text };\n}\n\nexport function buildAttrValue(node: Parser.SyntaxNode): { text: string; error?: string } {\n if (node.type === \"string\") {\n return { text: node.text.slice(1, -1) };\n }\n if (node.type === \"jsx_expression\") {\n const expr = node.namedChildren[0];\n if (!expr) {\n return { text: \"\", error: \"Empty JSX expression\" };\n }\n \n if (expr.type === \"identifier\") {\n return { text: `\\${${expr.text}}` };\n } else if (expr.type === \"string\") {\n return { text: expr.text.slice(1, -1) };\n } else if (expr.type === \"template_string\") {\n // Check if it's a simple template string with no substitutions\n const hasSubstitutions = expr.children.some(c => c.type === \"template_substitution\");\n if (hasSubstitutions) {\n return { text: \"\", error: \"JSX expressions with template substitutions are not supported\" };\n }\n // Extract the text content from the template string\n const content = expr.text.slice(1, -1); // Remove backticks\n return { text: content };\n } else {\n return { text: \"\", error: \"JSX expressions must be simple identifiers, strings, or template literals\" };\n }\n }\n return { text: \"\", error: \"Unsupported JSX child\" };\n}\n","import type Parser from \"tree-sitter\";\n\nimport { withComment } from \"../../core/queries/comment.ts\";\nimport type { MessageMatch, QuerySpec, Translation } from \"../../core/queries/types.ts\";\nimport { buildAttrValue, buildTemplate } from \"./utils.ts\";\n\nexport const messageQuery: QuerySpec = withComment({\n pattern: `(\n [\n (jsx_element (jsx_opening_element name: (identifier) @name)) @call\n (jsx_self_closing_element name: (identifier) @name) @call\n (lexical_declaration \n (variable_declarator \n value: [\n (jsx_element (jsx_opening_element name: (identifier) @name)) @call\n (jsx_self_closing_element name: (identifier) @name) @call\n ]\n )\n )\n ]\n (#eq? @name \"Message\")\n )`,\n extract(match: Parser.QueryMatch): MessageMatch | undefined {\n const node = match.captures.find((c) => c.name === \"call\")?.node;\n if (!node) return undefined;\n let attrs: Parser.SyntaxNode[] = [];\n if (node.type === \"jsx_element\") {\n const open = node.childForFieldName(\"open_tag\");\n if (open) attrs = open.namedChildren;\n } else if (node.type === \"jsx_self_closing_element\") {\n attrs = node.namedChildren.slice(1);\n }\n let msgctxt: string | undefined;\n let childValue: Parser.SyntaxNode | undefined;\n for (const child of attrs) {\n if (child.type !== \"jsx_attribute\") continue;\n const name = child.child(0);\n const value = child.child(child.childCount - 1);\n if (name?.text === \"context\" && value?.type === \"string\") {\n msgctxt = value.text.slice(1, -1);\n } else if (name?.text === \"children\" && value) {\n childValue = value;\n }\n }\n let text = \"\";\n let error: string | undefined;\n if (node.type === \"jsx_element\") {\n ({ text, error } = buildTemplate(node));\n } else if (childValue) {\n ({ text, error } = buildAttrValue(childValue));\n }\n if (error) {\n return { node, error };\n }\n if (!text) return undefined;\n const translation: Translation = {\n id: text,\n message: [text],\n };\n if (msgctxt) translation.context = msgctxt;\n return { node, translation };\n },\n});\n","import type Parser from \"tree-sitter\";\n\nimport { withComment } from \"../../core/queries/comment.ts\";\nimport type { MessageMatch, QuerySpec, Translation } from \"../../core/queries/types.ts\";\nimport { buildTemplate } from \"./utils.ts\";\n\nfunction parseForms(node: Parser.SyntaxNode): { forms: string[]; error?: string } {\n const forms: string[] = [];\n if (node.type === \"jsx_expression\") {\n const arr = node.namedChildren[0];\n if (!arr || arr.type !== \"array\") {\n return { forms: [], error: \"Plural forms must be an array\" };\n }\n for (const el of arr.namedChildren) {\n if (el.type === \"jsx_element\" || el.type === \"jsx_fragment\") {\n const { text, error } = buildTemplate(el);\n if (error) return { forms: [], error };\n forms.push(text);\n } else if (el.type === \"string\") {\n forms.push(el.text.slice(1, -1));\n } else {\n return { forms: [], error: \"Unsupported plural form\" };\n }\n }\n }\n return { forms };\n}\n\nexport const pluralQuery: QuerySpec = withComment({\n pattern: `(\n [\n (jsx_element (jsx_opening_element name: (identifier) @name))\n (jsx_self_closing_element name: (identifier) @name)\n ] @call\n (#eq? @name \"Plural\")\n )`,\n extract(match: Parser.QueryMatch): MessageMatch | undefined {\n const node = match.captures.find((c) => c.name === \"call\")?.node;\n if (!node) return undefined;\n let attrs: Parser.SyntaxNode[] = [];\n if (node.type === \"jsx_element\") {\n const open = node.childForFieldName(\"open_tag\");\n if (open) attrs = open.namedChildren;\n } else if (node.type === \"jsx_self_closing_element\") {\n attrs = node.namedChildren.slice(1);\n }\n let msgctxt: string | undefined;\n let formsNode: Parser.SyntaxNode | null | undefined;\n for (const child of attrs) {\n if (child.type !== \"jsx_attribute\") continue;\n const name = child.child(0);\n const value = child.child(child.childCount - 1);\n if (name?.text === \"context\" && value?.type === \"string\") {\n msgctxt = value.text.slice(1, -1);\n } else if (name?.text === \"forms\" && value) {\n formsNode = value;\n }\n }\n if (!formsNode) return undefined;\n const { forms, error } = parseForms(formsNode);\n if (error) {\n return { node, error };\n }\n if (forms.length === 0) return undefined;\n const translation: Translation = {\n id: forms[0],\n plural: forms[1],\n message: forms,\n };\n if (msgctxt) translation.context = msgctxt;\n return { node, translation };\n },\n});\n","import type { QuerySpec } from \"../../core/queries/types.ts\";\nimport { messageQuery } from \"./message.ts\";\nimport { pluralQuery } from \"./plural.ts\";\n\nexport const queries: QuerySpec[] = [messageQuery, pluralQuery];\n","import fs from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { getParser, getQuery } from \"../core/parse.ts\";\nimport { getReference } from \"../core/queries/comment.ts\";\n\nimport type { Context, Translation, Warning } from \"../core/queries/types.ts\";\nimport { queries } from \"./queries/index.ts\";\n\nexport interface ParseResult {\n translations: Translation[];\n warnings: Warning[];\n}\n\nexport function parseFile(filePath: string): ParseResult {\n const path = resolve(filePath);\n const source = fs.readFileSync(path, \"utf8\");\n return parseSource(source, path);\n}\n\nexport function parseSource(source: string, path: string): ParseResult {\n const context: Context = { path };\n const { parser, language } = getParser(path);\n const tree = parser.parse(source);\n\n const translations: Translation[] = [];\n const warnings: Warning[] = [];\n const seen = new Set<number>();\n\n for (const spec of queries) {\n const query = getQuery(language, spec.pattern);\n for (const match of query.matches(tree.rootNode)) {\n const message = spec.extract(match);\n if (!message) continue;\n const { node, translation, error } = message;\n if (seen.has(node.id)) continue;\n seen.add(node.id);\n const reference = getReference(node, context);\n if (translation) {\n translations.push({\n ...translation,\n comments: {\n ...translation.comments,\n reference,\n },\n });\n }\n if (error) {\n warnings.push({\n error,\n reference,\n });\n }\n }\n }\n\n return { translations, warnings };\n}\n","import { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\n\nimport type { Plugin } from \"../../plugin.ts\";\nimport type { Translation } from \"../core/queries/types.ts\";\nimport { parseSource } from \"./parse.ts\";\n\nconst filter = /\\.[cm]?[jt]sx$/;\n\nexport function react(): Plugin<string, Translation[]> {\n return {\n name: \"react\",\n setup(build) {\n build.context.logger?.debug(\"react plugin initialized\");\n build.onResolve({ filter: /.*/, namespace: \"source\" }, ({ entrypoint, path, namespace }) => {\n return {\n entrypoint,\n namespace,\n path: resolve(path),\n };\n });\n build.onLoad({ filter, namespace: \"source\" }, async ({ entrypoint, path, namespace }) => {\n const data = await readFile(path, \"utf8\");\n return {\n entrypoint,\n path,\n namespace,\n data,\n };\n });\n build.onProcess({ filter, namespace: \"source\" }, ({ entrypoint, path, data }) => {\n const { translations, warnings } = parseSource(data, path);\n\n for (const warning of warnings) {\n build.context.logger?.warn(`${warning.error} at ${warning.reference}`);\n }\n\n build.resolve({\n entrypoint,\n path,\n namespace: \"translate\",\n data: translations,\n });\n\n return undefined;\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;AAOA,SAAgB,UAAkB;AAC9B,QAAO;EACH,MAAM;EACN,MAAM,OAAO;AACT,SAAM,QAAQ,QAAQ,MAAM;GAC5B,MAAM,gCAAgB,IAAI;GAC1B,MAAM,4BAAY,IAAI;AAEtB,SAAM,UAAU;IAAE,WAAW;IAAW,QAAQ;OAAS,SAAS;AAC9D,cAAU,IAAI,KAAK;AACnB,WAAO;;AAGX,SAAM,UAAU;IAAE,WAAW;IAAW,QAAQ;MAAQ,OAAO,EAAE,mBAAW;AACxE,UAAM,MAAM,MAAM;IAClB,MAAM,MAAM,QAAQA;AACpB,QAAI,cAAc,IAAI,KAAM,QAAO;AACnC,kBAAc,IAAI;IAClB,MAAM,QAAQ,MAAM,GAAG,QAAQ,KAAK,YAAY;AAChD,SAAK,MAAM,KAAK,MAAM,QAAQ,MAAM,EAAE,SAAS,SAAS;KACpD,MAAM,OAAO,KAAK,KAAK;AACvB,SAAI,UAAU,IAAI,MAAO;KACzB,MAAM,WAAW,MAAM,GAAG,SAAS,MAAM,YAAY;AACrD,SAAI,CAAC,SAAU;KACf,MAAM,SAAS,cAAc,GAAG,MAAM;KACtC,MAAM,kBAAkB,OAAO,QAAQ,OAAO,gBAAgB,IAAI,MAAM,CAAC,KAAK,UAC1E,OAAO,KAAK,MAAM,MAAM,OAAO,EAAE,QAAQ,MAAM,OAAO;AAE1D,SAAI,gBACA,OAAM,QAAQ,QAAQ,KAAK,EAAE,MAAM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;;AAGtB,SAAM,OAAO;IAAE;IAAQ,WAAW;MAAY,OAAO,EAAE,YAAY,cAAM,6BAAgB;IACrF,MAAM,OAAO,MAAM,SAASA,QAAM;AAClC,WAAO;KACH;KACA;KACA;KACA;;;AAGR,SAAM,UAAU;IAAE;IAAQ,WAAW;OAAa,EAAE,YAAY,cAAM,WAAW;IAC7E,MAAM,EAAE,cAAc,aAAa,YAAY,MAAMA;AAErD,SAAK,MAAM,WAAW,SAClB,OAAM,QAAQ,QAAQ,KAAK,GAAG,QAAQ,MAAM,MAAM,QAAQ;AAG9D,UAAM,QAAQ;KACV;KACA;KACA,WAAW;KACX,MAAM;;AAGV,WAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@let-value/translate-extract",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@let-value/translate": "1.0.
|
|
23
|
+
"@let-value/translate": "1.0.10",
|
|
24
24
|
"gettext-parser": "8.0.0",
|
|
25
25
|
"oxc-resolver": "11.7.1",
|
|
26
26
|
"plural-forms": "0.5.5",
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
"check": "biome check .",
|
|
44
44
|
"format": "biome check --write .",
|
|
45
45
|
"typecheck": "tsc --build",
|
|
46
|
-
"test": "node --test
|
|
46
|
+
"test": "node --test"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/dist/run-BMvkoNJ4.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
//#region src/run.ts
|
|
2
|
-
async function run(entrypoint, { config, logger }) {
|
|
3
|
-
const entryConfig = config.entrypoints.find((e) => e.entrypoint === entrypoint);
|
|
4
|
-
const destination = entryConfig?.destination ?? config.destination;
|
|
5
|
-
const obsolete = entryConfig?.obsolete ?? config.obsolete;
|
|
6
|
-
const exclude = entryConfig?.exclude ?? config.exclude;
|
|
7
|
-
const queue = [{
|
|
8
|
-
entrypoint,
|
|
9
|
-
path: entrypoint
|
|
10
|
-
}];
|
|
11
|
-
const defaultLocale = config.defaultLocale;
|
|
12
|
-
logger?.info({
|
|
13
|
-
entrypoint,
|
|
14
|
-
locale: defaultLocale
|
|
15
|
-
}, "starting extraction");
|
|
16
|
-
const context = {
|
|
17
|
-
entrypoint,
|
|
18
|
-
config: {
|
|
19
|
-
...config,
|
|
20
|
-
destination,
|
|
21
|
-
obsolete,
|
|
22
|
-
exclude
|
|
23
|
-
},
|
|
24
|
-
generatedAt: /* @__PURE__ */ new Date(),
|
|
25
|
-
locale: defaultLocale,
|
|
26
|
-
logger
|
|
27
|
-
};
|
|
28
|
-
const resolves = [];
|
|
29
|
-
const loads = [];
|
|
30
|
-
const extracts = [];
|
|
31
|
-
const collects = [];
|
|
32
|
-
const generates = [];
|
|
33
|
-
function resolvePath(args) {
|
|
34
|
-
for (const ex of context.config.exclude) if (ex instanceof RegExp ? ex.test(args.path) : ex(args.path)) return;
|
|
35
|
-
if (context.config.walk) queue.push(args);
|
|
36
|
-
}
|
|
37
|
-
const build = {
|
|
38
|
-
onResolve({ filter }, hook) {
|
|
39
|
-
resolves.push({
|
|
40
|
-
filter,
|
|
41
|
-
hook
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
onLoad({ filter }, hook) {
|
|
45
|
-
loads.push({
|
|
46
|
-
filter,
|
|
47
|
-
hook
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
onExtract({ filter }, hook) {
|
|
51
|
-
extracts.push({
|
|
52
|
-
filter,
|
|
53
|
-
hook
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
onCollect({ filter }, hook) {
|
|
57
|
-
collects.push({
|
|
58
|
-
filter,
|
|
59
|
-
hook
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
onGenerate({ filter }, hook) {
|
|
63
|
-
generates.push({
|
|
64
|
-
filter,
|
|
65
|
-
hook
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
resolvePath,
|
|
69
|
-
context
|
|
70
|
-
};
|
|
71
|
-
for (const plugin of config.plugins) {
|
|
72
|
-
logger?.debug({ plugin: plugin.name }, "setting up plugin");
|
|
73
|
-
plugin.setup(build);
|
|
74
|
-
}
|
|
75
|
-
const visited = /* @__PURE__ */ new Set();
|
|
76
|
-
async function applyResolve({ entrypoint: entrypoint$1, path }) {
|
|
77
|
-
for (const { filter, hook } of resolves) {
|
|
78
|
-
if (!filter.test(path)) continue;
|
|
79
|
-
const result = await hook({
|
|
80
|
-
entrypoint: entrypoint$1,
|
|
81
|
-
path
|
|
82
|
-
}, context);
|
|
83
|
-
if (result) logger?.debug(result, "resolved");
|
|
84
|
-
if (result) return result;
|
|
85
|
-
}
|
|
86
|
-
return void 0;
|
|
87
|
-
}
|
|
88
|
-
async function applyLoad({ entrypoint: entrypoint$1, path }) {
|
|
89
|
-
for (const { filter, hook } of loads) {
|
|
90
|
-
if (!filter.test(path)) continue;
|
|
91
|
-
const result = await hook({
|
|
92
|
-
entrypoint: entrypoint$1,
|
|
93
|
-
path
|
|
94
|
-
}, context);
|
|
95
|
-
if (result) logger?.debug({
|
|
96
|
-
entrypoint: entrypoint$1,
|
|
97
|
-
path
|
|
98
|
-
}, "loaded");
|
|
99
|
-
if (result) return result;
|
|
100
|
-
}
|
|
101
|
-
return void 0;
|
|
102
|
-
}
|
|
103
|
-
async function applyExtract({ entrypoint: entrypoint$1, path, contents }) {
|
|
104
|
-
const results = [];
|
|
105
|
-
for (const { filter, hook } of extracts) {
|
|
106
|
-
if (!filter.test(path)) continue;
|
|
107
|
-
const result = await hook({
|
|
108
|
-
entrypoint: entrypoint$1,
|
|
109
|
-
path,
|
|
110
|
-
contents
|
|
111
|
-
}, context);
|
|
112
|
-
if (result) {
|
|
113
|
-
logger?.debug({
|
|
114
|
-
entrypoint: entrypoint$1,
|
|
115
|
-
path
|
|
116
|
-
}, "extracted");
|
|
117
|
-
results.push(result);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return results;
|
|
121
|
-
}
|
|
122
|
-
async function applyCollect({ entrypoint: entrypoint$1, path, translations, destination: destination$1 }) {
|
|
123
|
-
for (const { filter, hook } of collects) {
|
|
124
|
-
if (!filter.test(path)) continue;
|
|
125
|
-
const result = await hook({
|
|
126
|
-
entrypoint: entrypoint$1,
|
|
127
|
-
path,
|
|
128
|
-
translations,
|
|
129
|
-
destination: destination$1
|
|
130
|
-
}, context);
|
|
131
|
-
if (result) logger?.debug({
|
|
132
|
-
entrypoint: entrypoint$1,
|
|
133
|
-
path,
|
|
134
|
-
destination: destination$1,
|
|
135
|
-
...destination$1 !== result.destination && { redirected: result.destination }
|
|
136
|
-
}, "collected");
|
|
137
|
-
if (result) return result;
|
|
138
|
-
}
|
|
139
|
-
return void 0;
|
|
140
|
-
}
|
|
141
|
-
const extractedResults = [];
|
|
142
|
-
while (queue.length) {
|
|
143
|
-
const args = queue.shift();
|
|
144
|
-
const resolved = await applyResolve(args);
|
|
145
|
-
if (!resolved || visited.has(resolved.path)) continue;
|
|
146
|
-
visited.add(resolved.path);
|
|
147
|
-
const loaded = await applyLoad(resolved);
|
|
148
|
-
if (!loaded) continue;
|
|
149
|
-
const extracted = await applyExtract(loaded);
|
|
150
|
-
if (!extracted.length) continue;
|
|
151
|
-
extractedResults.push(...extracted);
|
|
152
|
-
}
|
|
153
|
-
for (const locale of config.locales) {
|
|
154
|
-
context.locale = locale;
|
|
155
|
-
const collectedByDest = {};
|
|
156
|
-
for (const extracted of extractedResults) {
|
|
157
|
-
const destination$1 = context.config.destination({
|
|
158
|
-
entrypoint,
|
|
159
|
-
locale,
|
|
160
|
-
path: extracted.path
|
|
161
|
-
});
|
|
162
|
-
const collected = await applyCollect({
|
|
163
|
-
...extracted,
|
|
164
|
-
destination: destination$1
|
|
165
|
-
});
|
|
166
|
-
if (!collected) continue;
|
|
167
|
-
if (!collectedByDest[collected.destination]) collectedByDest[collected.destination] = [];
|
|
168
|
-
collectedByDest[collected.destination].push(collected);
|
|
169
|
-
}
|
|
170
|
-
for (const [path, collected] of Object.entries(collectedByDest)) for (const { filter, hook } of generates) {
|
|
171
|
-
if (!filter.test(path)) continue;
|
|
172
|
-
logger?.info({
|
|
173
|
-
path,
|
|
174
|
-
locale
|
|
175
|
-
}, "generating output");
|
|
176
|
-
await hook({
|
|
177
|
-
entrypoint,
|
|
178
|
-
path,
|
|
179
|
-
collected
|
|
180
|
-
}, context);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
logger?.info({
|
|
184
|
-
entrypoint,
|
|
185
|
-
locale: defaultLocale
|
|
186
|
-
}, "extraction completed");
|
|
187
|
-
return extractedResults;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
//#endregion
|
|
191
|
-
export { run };
|
|
192
|
-
//# sourceMappingURL=run-BMvkoNJ4.js.map
|
package/dist/run-BMvkoNJ4.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run-BMvkoNJ4.js","names":["queue: ResolveArgs[]","context: ExtractContext","resolves: { filter: RegExp; hook: ResolveHook }[]","loads: { filter: RegExp; hook: LoadHook }[]","extracts: { filter: RegExp; hook: ExtractHook }[]","collects: { filter: RegExp; hook: CollectHook }[]","generates: { filter: RegExp; hook: GenerateHook }[]","build: ExtractBuild","results: ExtractResult[]","destination","extractedResults: ExtractResult[]","collectedByDest: Record<string, CollectResult[]>"],"sources":["../src/run.ts"],"sourcesContent":["import type { ResolvedConfig } from \"./configuration.ts\";\nimport type { Logger } from \"./logger.ts\";\nimport type {\n CollectArgs,\n CollectHook,\n CollectResult,\n ExtractArgs,\n ExtractBuild,\n ExtractContext,\n ExtractHook,\n ExtractResult,\n GenerateHook,\n LoadArgs,\n LoadHook,\n LoadResult,\n ResolveArgs,\n ResolveHook,\n ResolveResult,\n} from \"./plugin.ts\";\n\nexport async function run(entrypoint: string, { config, logger }: { config: ResolvedConfig; logger?: Logger }) {\n const entryConfig = config.entrypoints.find((e) => e.entrypoint === entrypoint);\n const destination = entryConfig?.destination ?? config.destination;\n const obsolete = entryConfig?.obsolete ?? config.obsolete;\n const exclude = entryConfig?.exclude ?? config.exclude;\n\n const queue: ResolveArgs[] = [{ entrypoint, path: entrypoint }];\n\n const defaultLocale = config.defaultLocale;\n\n logger?.info({ entrypoint, locale: defaultLocale }, \"starting extraction\");\n\n const context: ExtractContext = {\n entrypoint,\n config: { ...config, destination, obsolete, exclude },\n generatedAt: new Date(),\n locale: defaultLocale,\n logger,\n };\n\n const resolves: { filter: RegExp; hook: ResolveHook }[] = [];\n const loads: { filter: RegExp; hook: LoadHook }[] = [];\n const extracts: { filter: RegExp; hook: ExtractHook }[] = [];\n const collects: { filter: RegExp; hook: CollectHook }[] = [];\n const generates: { filter: RegExp; hook: GenerateHook }[] = [];\n\n function resolvePath(args: ResolveArgs) {\n for (const ex of context.config.exclude) {\n if (ex instanceof RegExp ? ex.test(args.path) : ex(args.path)) {\n return;\n }\n }\n if (context.config.walk) {\n queue.push(args);\n }\n }\n\n const build: ExtractBuild = {\n onResolve({ filter }, hook) {\n resolves.push({ filter, hook });\n },\n onLoad({ filter }, hook) {\n loads.push({ filter, hook });\n },\n onExtract({ filter }, hook) {\n extracts.push({ filter, hook });\n },\n onCollect({ filter }, hook) {\n collects.push({ filter, hook });\n },\n onGenerate({ filter }, hook) {\n generates.push({ filter, hook });\n },\n resolvePath,\n context,\n };\n\n for (const plugin of config.plugins) {\n logger?.debug({ plugin: plugin.name }, \"setting up plugin\");\n plugin.setup(build);\n }\n\n const visited = new Set<string>();\n\n async function applyResolve({ entrypoint, path }: ResolveArgs): Promise<ResolveResult | undefined> {\n for (const { filter, hook } of resolves) {\n if (!filter.test(path)) continue;\n const result = await hook({ entrypoint, path }, context);\n if (result) {\n logger?.debug(result, \"resolved\");\n }\n if (result) return result;\n }\n return undefined;\n }\n\n async function applyLoad({ entrypoint, path }: LoadArgs): Promise<LoadResult | undefined> {\n for (const { filter, hook } of loads) {\n if (!filter.test(path)) continue;\n const result = await hook({ entrypoint, path }, context);\n if (result) {\n logger?.debug({ entrypoint, path }, \"loaded\");\n }\n if (result) return result;\n }\n return undefined;\n }\n\n async function applyExtract({ entrypoint, path, contents }: ExtractArgs): Promise<ExtractResult[]> {\n const results: ExtractResult[] = [];\n for (const { filter, hook } of extracts) {\n if (!filter.test(path)) continue;\n const result = await hook({ entrypoint, path, contents }, context);\n if (result) {\n logger?.debug({ entrypoint, path }, \"extracted\");\n results.push(result);\n }\n }\n return results;\n }\n\n async function applyCollect({\n entrypoint,\n path,\n translations,\n destination,\n }: CollectArgs): Promise<CollectResult | undefined> {\n for (const { filter, hook } of collects) {\n if (!filter.test(path)) continue;\n const result = await hook({ entrypoint, path, translations, destination }, context);\n if (result) {\n logger?.debug(\n {\n entrypoint,\n path,\n destination,\n ...(destination !== result.destination && { redirected: result.destination }),\n },\n \"collected\",\n );\n }\n if (result) return result;\n }\n return undefined;\n }\n\n const extractedResults: ExtractResult[] = [];\n\n while (queue.length) {\n // biome-ignore lint/style/noNonNullAssertion: queue is checked above\n const args = queue.shift()!;\n const resolved = await applyResolve(args);\n if (!resolved || visited.has(resolved.path)) continue;\n visited.add(resolved.path);\n\n const loaded = await applyLoad(resolved);\n if (!loaded) continue;\n\n const extracted = await applyExtract(loaded);\n if (!extracted.length) continue;\n\n extractedResults.push(...extracted);\n }\n\n for (const locale of config.locales) {\n context.locale = locale;\n const collectedByDest: Record<string, CollectResult[]> = {};\n\n for (const extracted of extractedResults) {\n const destination = context.config.destination({ entrypoint, locale, path: extracted.path });\n const collected = await applyCollect({ ...extracted, destination });\n if (!collected) continue;\n\n if (!collectedByDest[collected.destination]) {\n collectedByDest[collected.destination] = [];\n }\n collectedByDest[collected.destination].push(collected);\n }\n\n for (const [path, collected] of Object.entries(collectedByDest)) {\n for (const { filter, hook } of generates) {\n if (!filter.test(path)) continue;\n logger?.info({ path, locale }, \"generating output\");\n await hook({ entrypoint, path, collected }, context);\n }\n }\n }\n\n logger?.info({ entrypoint, locale: defaultLocale }, \"extraction completed\");\n return extractedResults;\n}\n"],"mappings":";AAoBA,eAAsB,IAAI,YAAoB,EAAE,QAAQ,UAAuD;CAC3G,MAAM,cAAc,OAAO,YAAY,MAAM,MAAM,EAAE,eAAe;CACpE,MAAM,cAAc,aAAa,eAAe,OAAO;CACvD,MAAM,WAAW,aAAa,YAAY,OAAO;CACjD,MAAM,UAAU,aAAa,WAAW,OAAO;CAE/C,MAAMA,QAAuB,CAAC;EAAE;EAAY,MAAM;;CAElD,MAAM,gBAAgB,OAAO;AAE7B,SAAQ,KAAK;EAAE;EAAY,QAAQ;IAAiB;CAEpD,MAAMC,UAA0B;EAC5B;EACA,QAAQ;GAAE,GAAG;GAAQ;GAAa;GAAU;;EAC5C,6BAAa,IAAI;EACjB,QAAQ;EACR;;CAGJ,MAAMC,WAAoD;CAC1D,MAAMC,QAA8C;CACpD,MAAMC,WAAoD;CAC1D,MAAMC,WAAoD;CAC1D,MAAMC,YAAsD;CAE5D,SAAS,YAAY,MAAmB;AACpC,OAAK,MAAM,MAAM,QAAQ,OAAO,QAC5B,KAAI,cAAc,SAAS,GAAG,KAAK,KAAK,QAAQ,GAAG,KAAK,MACpD;AAGR,MAAI,QAAQ,OAAO,KACf,OAAM,KAAK;;CAInB,MAAMC,QAAsB;EACxB,UAAU,EAAE,UAAU,MAAM;AACxB,YAAS,KAAK;IAAE;IAAQ;;;EAE5B,OAAO,EAAE,UAAU,MAAM;AACrB,SAAM,KAAK;IAAE;IAAQ;;;EAEzB,UAAU,EAAE,UAAU,MAAM;AACxB,YAAS,KAAK;IAAE;IAAQ;;;EAE5B,UAAU,EAAE,UAAU,MAAM;AACxB,YAAS,KAAK;IAAE;IAAQ;;;EAE5B,WAAW,EAAE,UAAU,MAAM;AACzB,aAA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