Skip to content

Commit cc7fe27

Browse files
authored
feat: add metro transformer (#1999)
1 parent c20ce12 commit cc7fe27

25 files changed

Lines changed: 1598 additions & 399 deletions

jest.config.integration.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = {
77
...sourceConfig,
88
projects: sourceConfig.projects.map((project) => ({
99
...project,
10-
// Redirect imports to the compiled bundles
10+
// Redirect imports to the compiled bundles.
11+
// This is to test compiled code instead of source (applies to code under test and also its deps).
1112
moduleNameMapper: {},
1213
})),
1314

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module.exports = {
6262
"<rootDir>/packages/cli",
6363
"<rootDir>/packages/conf",
6464
"<rootDir>/packages/loader",
65+
"<rootDir>/packages/metro-transformer",
6566
"<rootDir>/packages/macro",
6667
"<rootDir>/packages/vite-plugin",
6768
"<rootDir>/packages/format-po",

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test": "jest",
1212
"test:ci": "jest --ci --runInBand",
1313
"test:ci:coverage": "yarn test:ci --coverage",
14-
"test:integration": "jest -c jest.config.integration.js",
14+
"test:integration": "yarn node --experimental-vm-modules $(yarn bin jest) -c jest.config.integration.js",
1515
"test:e2e": "yarn workspaces foreach -p run test:e2e",
1616
"test:tsd": "jest -c jest.config.types.js",
1717
"test:all": "yarn test && yarn test:integration && yarn test:e2e && yarn test:tsd",
@@ -51,7 +51,7 @@
5151
"@typescript-eslint/eslint-plugin": "^5.50.0",
5252
"@typescript-eslint/parser": "^5.50.0",
5353
"babel-eslint": "^10.1.0",
54-
"babel-jest": "^29.4.3",
54+
"babel-jest": "^29.7.0",
5555
"chalk": "^4.1.0",
5656
"cross-env": "^7.0.2",
5757
"eslint": "^7.32.0",
@@ -61,9 +61,9 @@
6161
"eslint-plugin-node": "^11.1.0",
6262
"eslint-plugin-promise": "^4.1.1",
6363
"husky": "^8.0.3",
64-
"jest": "^29.4.3",
65-
"jest-environment-jsdom": "^29.4.3",
66-
"jest-environment-node-single-context": "^29.0.0",
64+
"jest": "^29.7.0",
65+
"jest-environment-jsdom": "^29.7.0",
66+
"jest-environment-node-single-context": "^29.4.0",
6767
"jest-runner-tsd": "^4.0.0",
6868
"lerna": "^6.5.1",
6969
"lint-staged": "^13.1.0",
@@ -78,7 +78,7 @@
7878
"size-limit": "^8.1.1",
7979
"strip-ansi": "^6.0.1",
8080
"swc-node": "^1.0.0",
81-
"ts-jest": "^29.0.5",
81+
"ts-jest": "^29.2.4",
8282
"typescript": "^4.9.5"
8383
},
8484
"workspaces": [

packages/cli/src/api/catalog/getTranslationsForCatalog.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ export async function getTranslationsForCatalog(
1818
locale: string,
1919
options: GetTranslationsOptions
2020
) {
21-
const catalogs = await catalog.readAll()
22-
const template = (await catalog.readTemplate()) || {}
21+
const [catalogs, template] = await Promise.all([
22+
catalog.readAll(),
23+
catalog.readTemplate(),
24+
])
2325

2426
const sourceLocaleCatalog = catalogs[options.sourceLocale] || {}
2527

packages/cli/src/lingui-extract.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ export default async function command(
6060

6161
if (!options.watch) {
6262
console.log(
63-
`(use "${chalk.yellow(
63+
`(Use "${chalk.yellow(
6464
helpRun("extract")
65-
)}" to update catalogs with new messages)`
65+
)}" to update catalogs with new messages.)`
6666
)
6767
console.log(
68-
`(use "${chalk.yellow(
68+
`(Use "${chalk.yellow(
6969
helpRun("compile")
70-
)}" to compile catalogs for production)`
70+
)}" to compile catalogs for production. Alternatively, use bundler plugins: https://lingui.dev/ref/cli#compiling-catalogs-in-ci)`
7171
)
7272
}
7373

packages/cli/test/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ describe("E2E Extractor Test", () => {
7373
│ pl │ 8 │ 8 │
7474
└─────────────┴─────────────┴─────────┘
7575
76-
(use "yarn extract" to update catalogs with new messages)
77-
(use "yarn compile" to compile catalogs for production)
76+
(Use "yarn extract" to update catalogs with new messages.)
77+
(Use "yarn compile" to compile catalogs for production. Alternatively, use bundler plugins: https://lingui.dev/ref/cli#compiling-catalogs-in-ci)
7878
`)
7979
})
8080

packages/conf/src/getConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function getConfig({
7171
)
7272

7373
// gracefully stop further executing
74-
throw new Error("No Config")
74+
throw new Error("No Lingui config found")
7575
}
7676

7777
const userConfig = result ? result.config : {}

packages/loader/src/webpackLoader.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ Please check that \`catalogs.path\` is filled properly.\n`
5454
sourceLocale: config.sourceLocale,
5555
})
5656

57-
// In production we don't want untranslated strings. It's better to use message
57+
// In production, we don't want untranslated strings. It's better to use message
5858
// keys as a last resort.
5959
// In development, however, we want to catch missing strings with `missing` parameter
60-
// of I18nProvider (React) or setupI18n (core) and therefore we need to get
61-
// empty translations if missing.
60+
// of setupI18n (core) and therefore we need to get empty translations if missing.
6261
const strict = process.env.NODE_ENV !== "production"
6362

6463
return createCompiledCatalog(locale, messages, {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
### Features
7+
8+
- initial implementation of metro transformer [#1999](https://github.com/lingui/js-lingui/pull/1999)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[![License][badge-license]][license]
2+
[![Version][badge-version]][package]
3+
[![Downloads][badge-downloads]][package]
4+
5+
# @lingui/metro-transformer
6+
7+
> Metro bundler transformer for LinguiJS catalogs
8+
9+
`@lingui/metro-transformer` is part of [LinguiJS][linguijs]. See the
10+
[documentation][documentation] for all information, tutorials and examples.
11+
12+
## Installation & Usage
13+
14+
See the [reference][reference] documentation.
15+
16+
## License
17+
18+
This package is licensed under [MIT][license] license.
19+
20+
[license]: https://github.com/lingui/js-lingui/blob/main/LICENSE
21+
[linguijs]: https://github.com/lingui/js-lingui
22+
[documentation]: https://lingui.dev
23+
[reference]: https://lingui.dev/ref/metro-transformer
24+
[package]: https://www.npmjs.com/package/@lingui/metro-transformer
25+
[badge-downloads]: https://img.shields.io/npm/dw/@lingui/metro-transformer.svg
26+
[badge-version]: https://img.shields.io/npm/v/@lingui/metro-transformer.svg
27+
[badge-license]: https://img.shields.io/npm/l/@lingui/metro-transformer.svg

0 commit comments

Comments
 (0)