Skip to content

Commit c0486ca

Browse files
VAIBHAVSINGmaxprilutskiymathio
authored
feat(cli): ignoredKeys in typescript being ignored (#1065)
* feat(cli): fix typescript ignoredKeys for export default and exports * feat(cli): added types * feat(cli): updated existing test cases for ignoredKeys in typescript * fix(cli/run): remove unwanted changes as not needed * fix(cli/loaders): remove unwanted changes as not needed * Revert "fix(cli/run): remove unwanted changes as not needed" This reverts commit 518237f. * feat(cli): remove unnecessary change * feat(cli): added ignorekeys support for run * feat: add changeset * feat(cli): remove unwanted changes * feat(cli): remove unwanted changes * feat(cli): remove unwanted changes * feat(cli): added ignorekeys for typescript and it test --------- Co-authored-by: Max Prilutskiy <5614659+maxprilutskiy@users.noreply.github.com> Co-authored-by: Matej Lednicky <matej@lednicky.name>
1 parent ed91768 commit c0486ca

8 files changed

Lines changed: 479 additions & 12 deletions

File tree

.changeset/few-boats-tap.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"lingo.dev": minor
3+
---
4+
5+
Add support for `ignoredKeys` in TypeScript loader
6+
7+
The TypeScript loader now fully supports the `ignoredKeys` option, allowing you to exclude specific keys (including nested keys) from localization when using both `export default` and `export const` patterns. This works seamlessly with the `run` method and the CLI, and is compatible with flattened key structures. All related tests now pass.

packages/cli/src/cli/cmd/run/_types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type CmdRunTask = {
2828
injectLocale: string[];
2929
lockedKeys: string[];
3030
lockedPatterns: string[];
31+
ignoredKeys: string[];
3132
onlyKeys: string[];
3233
};
3334

packages/cli/src/cli/cmd/run/execute.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ function createLoaderForTask(assignedTask: CmdRunTask) {
127127
},
128128
assignedTask.lockedKeys,
129129
assignedTask.lockedPatterns,
130+
assignedTask.ignoredKeys,
130131
);
131132
bucketLoader.setDefaultLocale(assignedTask.sourceLocale);
132133

packages/cli/src/cli/cmd/run/plan.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export default async function plan(
132132
injectLocale: bucket.injectLocale || [],
133133
lockedKeys: bucket.lockedKeys || [],
134134
lockedPatterns: bucket.lockedPatterns || [],
135+
ignoredKeys: bucket.ignoredKeys || [],
135136
onlyKeys: input.flags.key || [],
136137
});
137138
}

packages/cli/src/cli/loaders/ignored-keys.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ describe("ignored-keys loader", () => {
7979
// The loader should have re-inserted the ignored keys from the pull input.
8080
expect(pushResult).toEqual({
8181
greeting: "hola",
82-
meta: "meta es",
83-
todo: "todo es",
8482
});
8583
});
8684

@@ -170,13 +168,15 @@ describe("ignored-keys loader", () => {
170168
const pushResult = await loader.push(targetLocale, dataToPush);
171169
expect(pushResult).toEqual({
172170
greeting: "hola",
173-
meta: "meta es",
174-
"pages/0/title": "Título 0",
175171
"pages/0/content": "Contenido Nuveo",
176-
"pages/foo/title": "Título Foo",
177172
"pages/foo/content": "Contenido Nuevo Foo",
178173
"pages/bar/notitle": "No Título",
179174
"pages/bar/content": "Contenido Nuevo Bar",
180175
});
176+
expect(pushResult).not.toEqual({
177+
meta: "meta es",
178+
"pages/0/title": "Título 0",
179+
"pages/foo/title": "Título Foo",
180+
});
181181
});
182182
});

packages/cli/src/cli/loaders/ignored-keys.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ export default function createIgnoredKeysLoader(
1414
return result;
1515
},
1616
push: async (locale, data, originalInput, originalLocale, pullInput) => {
17-
const ignoredSubObject = _.pickBy(pullInput, (value, key) =>
17+
// Ignored keys loader should remove ignored keys from push data too
18+
const result = _.omitBy(data, (value, key) =>
1819
_isIgnoredKey(key, ignoredKeys),
1920
);
20-
const result = _.merge({}, data, ignoredSubObject);
21+
2122
return result;
2223
},
2324
});

0 commit comments

Comments
 (0)