Skip to content

Commit 118d183

Browse files
authored
feat: Switch to cosmiconfig-typescript-loader #1247
1 parent da25b94 commit 118d183

5 files changed

Lines changed: 250 additions & 776 deletions

File tree

packages/conf/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
},
2121
"dependencies": {
2222
"@babel/runtime": "^7.11.2",
23-
"@endemolshinegroup/cosmiconfig-typescript-loader": "^3.0.2",
2423
"chalk": "^4.1.0",
2524
"cosmiconfig": "^7.0.0",
25+
"cosmiconfig-typescript-loader": "^2.0.1",
2626
"jest-validate": "^26.5.2",
2727
"lodash.get": "^4.4.2"
2828
},

packages/conf/src/__snapshots__/index.test.ts.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ Documentation: https://lingui.js.org/ref/conf.html
7272
Please update your configuration.
7373
7474
75+
Documentation: https://lingui.js.org/ref/conf.html
76+
`;
77+
78+
exports[`@lingui/conf config file fallbackLocales logic if fallbackLocale is defined, we use the default one on fallbackLocales 1`] = `
79+
● Deprecation Warning:
80+
81+
Option fallbackLocale was replaced by fallbackLocales
82+
83+
You can find more information here: https://github.com/lingui/js-lingui/issues/791
84+
85+
@lingui/cli now treats your current configuration as:
86+
{
87+
"fallbackLocales": {
88+
default: "en"
89+
}
90+
}
91+
92+
Please update your configuration.
93+
94+
7595
Documentation: https://lingui.js.org/ref/conf.html
7696
`;
7797

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
locales: ["pl"],
3+
}

packages/conf/src/index.test.ts

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,18 @@ describe("@lingui/conf", function () {
119119
})
120120
})
121121

122-
it("searches for a config file", function () {
123-
// hide validation warning about missing locales
124-
mockConsole(() => {
125-
const config = getConfig({
126-
cwd: path.resolve(__dirname, path.join("fixtures", "valid")),
122+
describe("config file", function () {
123+
it("searches for a .linguirc config file", function () {
124+
// hide validation warning about missing locales
125+
mockConsole(() => {
126+
const config = getConfig({
127+
cwd: path.resolve(__dirname, path.join("fixtures", "valid")),
128+
})
129+
expect(config.locales).toEqual(["en-gb"])
127130
})
128-
expect(config.locales).toEqual(["en-gb"])
129131
})
130-
})
131132

132-
describe("with configPath parameter", function () {
133-
it("allows specific config file to be loaded", function () {
133+
it("allows specific config file to be loaded with configPath parameter", function () {
134134
// hide validation warning about missing locales
135135
mockConsole(() => {
136136
const config = getConfig({
@@ -142,39 +142,52 @@ describe("@lingui/conf", function () {
142142
expect(config.locales).toEqual(["cs", "sk"])
143143
})
144144
})
145-
})
146-
147-
describe("fallbackLocales logic", () => {
148-
afterEach(() => {
149-
mockFs.restore()
150-
})
151145

152-
it ("if fallbackLocale is defined, we use the default one on fallbackLocales", () => {
153-
mockFs({
154-
".linguirc": JSON.stringify({
155-
locales: ["en-US"],
156-
fallbackLocale: "en"
157-
})
158-
})
159-
mockConsole((console) => {
146+
it("loads TypeScript config", function () {
147+
// hide validation warning about missing locales
148+
mockConsole(() => {
160149
const config = getConfig({
161-
configPath: ".linguirc",
150+
configPath: path.resolve(
151+
__dirname,
152+
path.join("fixtures", "valid", "custom.config.ts")
153+
),
162154
})
163-
expect(config.fallbackLocales.default).toEqual("en")
164-
expect(getConsoleMockCalls(console.warn)).toMatchSnapshot()
155+
expect(config.locales).toEqual(["pl"])
165156
})
166157
})
167158

168-
it ("if fallbackLocales default is defined, we dont build the cldr", () => {
169-
const config = getConfig({
170-
configPath: path.resolve(
171-
__dirname,
172-
path.join("fixtures", "valid", ".fallbacklocalesrc")
173-
),
159+
describe("fallbackLocales logic", () => {
160+
afterEach(() => {
161+
mockFs.restore()
162+
})
163+
164+
it("if fallbackLocale is defined, we use the default one on fallbackLocales", () => {
165+
mockFs({
166+
".linguirc": JSON.stringify({
167+
locales: ["en-US"],
168+
fallbackLocale: "en",
169+
}),
170+
})
171+
mockConsole((console) => {
172+
const config = getConfig({
173+
configPath: ".linguirc",
174+
})
175+
expect(config.fallbackLocales.default).toEqual("en")
176+
expect(getConsoleMockCalls(console.warn)).toMatchSnapshot()
177+
})
174178
})
175-
expect(config.fallbackLocales).toEqual({
176-
"en-US": ["en"],
177-
default: "en",
179+
180+
it("if fallbackLocales default is defined, we dont build the cldr", () => {
181+
const config = getConfig({
182+
configPath: path.resolve(
183+
__dirname,
184+
path.join("fixtures", "valid", ".fallbacklocalesrc")
185+
),
186+
})
187+
expect(config.fallbackLocales).toEqual({
188+
"en-US": ["en"],
189+
default: "en",
190+
})
178191
})
179192
})
180193
})

0 commit comments

Comments
 (0)