|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * The translatable-key walk moved to `@objectstack/lint` (`i18n-walk.ts`) so a |
| 5 | + * browser can run it; the CLI's extractor module kept everything else and |
| 6 | + * re-exports the walk. This pins that the module still offers exactly what |
| 7 | + * `utils/i18n-extract.ts` offered before the move, and that the walk names are |
| 8 | + * lint's own functions, not a second copy that could drift from them. |
| 9 | + */ |
| 10 | + |
| 11 | +import { describe, it, expect } from 'vitest'; |
| 12 | +import * as lint from '@objectstack/lint'; |
| 13 | +import * as bundleExtract from '../src/utils/i18n-bundle-extract.js'; |
| 14 | +import type { |
| 15 | + ExpectedEntry, |
| 16 | + ExpectedEntryOptions, |
| 17 | + ExtractOptions, |
| 18 | + ExtractResult, |
| 19 | + FillStrategy, |
| 20 | + TranslationModuleKind, |
| 21 | +} from '../src/utils/i18n-bundle-extract.js'; |
| 22 | + |
| 23 | +/** The runtime exports of `packages/cli/src/utils/i18n-extract.ts` before the move. */ |
| 24 | +const RUNTIME_EXPORTS_BEFORE_THE_MOVE = [ |
| 25 | + 'authorWarnedTranslationGroups', |
| 26 | + 'collectExpectedEntries', |
| 27 | + 'countTranslationLeaves', |
| 28 | + 'extractTranslations', |
| 29 | + 'humanizeFieldPath', |
| 30 | + 'narrowToCommittedSections', |
| 31 | + 'parseSourceHashModule', |
| 32 | + 'renderSourceHashModule', |
| 33 | + 'renderTranslationModule', |
| 34 | + 'stackAuthoredSubtree', |
| 35 | + 'translationModulePayload', |
| 36 | + 'translationModuleSections', |
| 37 | +]; |
| 38 | + |
| 39 | +// The type exports, held by type-check: removing one fails `typecheck`. |
| 40 | +type TypeExportsBeforeTheMove = [ |
| 41 | + ExpectedEntry, |
| 42 | + ExpectedEntryOptions, |
| 43 | + ExtractOptions, |
| 44 | + ExtractResult, |
| 45 | + FillStrategy, |
| 46 | + TranslationModuleKind, |
| 47 | +]; |
| 48 | + |
| 49 | +describe('the CLI extractor module after the walk moved to @objectstack/lint', () => { |
| 50 | + it('exports exactly the runtime names it exported before', () => { |
| 51 | + expect(Object.keys(bundleExtract).sort()).toEqual(RUNTIME_EXPORTS_BEFORE_THE_MOVE); |
| 52 | + }); |
| 53 | + |
| 54 | + it("re-exports lint's walk functions themselves", () => { |
| 55 | + expect(bundleExtract.collectExpectedEntries).toBe(lint.collectExpectedEntries); |
| 56 | + expect(bundleExtract.authorWarnedTranslationGroups).toBe(lint.authorWarnedTranslationGroups); |
| 57 | + expect(bundleExtract.humanizeFieldPath).toBe(lint.humanizeFieldPath); |
| 58 | + }); |
| 59 | + |
| 60 | + it('still offers its type exports, with the extract options extending the walk options', () => { |
| 61 | + const none: TypeExportsBeforeTheMove | undefined = undefined; |
| 62 | + const options: ExtractOptions = { warnedGroups: new Set<string>() }; |
| 63 | + const walkOptions: ExpectedEntryOptions = options; |
| 64 | + expect(none).toBeUndefined(); |
| 65 | + expect(walkOptions.warnedGroups?.size).toBe(0); |
| 66 | + }); |
| 67 | +}); |
0 commit comments