Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): produce TS typings for @lingui/cli #1579

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"prettier:check": "prettier --check '**/*.{ts,tsx,js,jsx}'",
"verdaccio:release": "node -r @swc-node/register ./scripts/verdaccio-release.ts",
"verdaccio:integration": "node -r @swc-node/register ./scripts/verdaccio-integration.ts",
"release:build": "yarn workspaces foreach -ptv run build",
"release:build": "yarn workspaces foreach --topological-dev -pv run build",
"release:test": "yarn release:build && yarn test:all",
"version:next": "lerna version --exact --force-publish --no-private --preid next --create-release github --conventional-commits --conventional-prerelease --yes",
"version:latest": "lerna version --exact --force-publish --no-private --create-release github --conventional-commits --yes",
Expand Down
21 changes: 15 additions & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,26 @@
"require": "./dist/lingui.js"
},
"./api": {
"require": "./dist/api/index.js"
"require": {
"types": "./dist/api/index.d.ts",
"default": "./dist/api/index.js"
}
},
"./api/extractors/babel": {
"require": "./dist/api/extractors/babel.js"
"require": {
"types": "./dist/api/extractors/babel.d.ts",
"default": "./dist/api/extractors/babel.js"
}
},
"./api/extractors/typescript": {
"require": "./dist/api/extractors/typescript.js"
"require": {
"types": "./dist/api/extractors/typescript.d.ts",
"default": "./dist/api/extractors/typescript.js"
}
}
},
"scripts": {
"build": "rimraf ./dist && swc ./src -d dist"
"build": "rimraf ./dist && tsc -p tsconfig.build.json"
},
"engines": {
"node": ">=16.0.0"
Expand Down Expand Up @@ -79,9 +88,9 @@
},
"devDependencies": {
"@lingui/jest-mocks": "*",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.42",
"@lingui/macro": "^4.0.0-next.4",
"@types/convert-source-map": "^2.0.0",
"@types/glob": "^8.1.0",
"@types/micromatch": "^4.0.1",
"@types/normalize-path": "^3.0.0",
"mock-fs": "^5.2.0",
Expand Down
16 changes: 0 additions & 16 deletions packages/cli/src/.swcrc

This file was deleted.

3 changes: 2 additions & 1 deletion packages/cli/src/api/extractors/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import linguiExtractMessages from "@lingui/babel-plugin-extract-messages"
import type { ExtractorType } from "@lingui/conf"
import { ParserPlugin } from "@babel/parser"
import { SourceMapConsumer } from "source-map"
import { LinguiMacroOpts } from "@lingui/macro/node"

const babelRe = new RegExp(
"\\.(" +
Expand Down Expand Up @@ -89,7 +90,7 @@ const extractor: ExtractorType = {
lingui: {
extract: true,
linguiConfig: ctx.linguiConfig,
} satisfies import("../../../../macro/src").LinguiMacroOpts,
} satisfies LinguiMacroOpts,
},
],
[
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/api/stats.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
import Table from "cli-table"
import chalk from "chalk"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getEntryPoints } from "./getEntryPoints"
import { resolveCatalogPath } from "./resolveCatalogPath"
import { Catalog } from "../api/catalog"
import { resolveTemplatePath } from "./resolveTemplatePath"
import { getFormat } from "@lingui/cli/api"
import { getFormat } from "../api/formats"

export async function getExperimentalCatalogs(
linguiConfig: LinguiConfigNormalized
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/lingui.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env node

import { program } from "commander"
import { version } from "../package.json"
import { readFileSync } from "node:fs"

const packageJson = JSON.parse(readFileSync("../package.json", "utf8"))

program
.version(version)
.version(packageJson.version)
.command("extract [files...]", "Extracts messages from source files")
.command(
"extract-experimental",
Expand Down
22 changes: 22 additions & 0 deletions packages/cli/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"strictNullChecks": false,
"declaration": true,
"paths": {},
"noEmit": false,
"outDir": "./dist",
"rootDir": "./src",
"skipLibCheck": true,
"moduleResolution": "Node16"
},
"include": ["./src"],
"exclude": [
"**/test/**",
"src/tests.ts",
"**/*.test.ts",
"dist",
"**/fixtures/**"
]
}
2 changes: 1 addition & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"strictNullChecks": false,
"strictNullChecks": false
}
}
3 changes: 2 additions & 1 deletion packages/conf/src/makeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { multipleValidOptions, validate } from "jest-validate"
import { setCldrParentLocales } from "./migrations/setCldrParentLocales"
import { pathJoinPosix } from "./utils/pathJoinPosix"
import { normalizeRuntimeConfigModule } from "./migrations/normalizeRuntimeConfigModule"
import { ExperimentalExtractorOptions } from "./types"

export function makeConfig(
userConfig: Partial<LinguiConfig>,
Expand Down Expand Up @@ -99,7 +100,7 @@ export const exampleConfig = {
output: "",
resolveEsbuildOptions: Function,
},
},
} as { extractor: ExperimentalExtractorOptions },
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/conf/src/migrations/setCldrParentLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function setCldrParentLocales(
if (!config.fallbackLocales.default) {
config.locales.forEach((locale) => {
const fl = getCldrParentLocale(locale.toLowerCase())
if (fl && !config.fallbackLocales[locale]) {
if (fl && !(config.fallbackLocales as FallbackLocales)[locale]) {
config.fallbackLocales = {
...config.fallbackLocales,
[locale]: fl,
Expand Down
4 changes: 3 additions & 1 deletion packages/conf/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"outDir": "./build",
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true
"skipLibCheck": true,
"strict": true,
"strictNullChecks": false
},
"files": [
"./src/index.ts"
Expand Down
8 changes: 8 additions & 0 deletions packages/macro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
"types": "./index.d.ts",
"default": "./dist/index.mjs"
}
},
"./node": {
"require": {
"types": "./dist/index.d.ts"
},
"import": {
"types": "./dist/index.d.ts"
}
}
},
"files": [
Expand Down
4 changes: 2 additions & 2 deletions packages/message-utils/src/compileMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function processTokens(tokens: Token[], mapText?: MapTextFn): CompiledMessage {
const offset = token.pluralOffset

// complex argument with cases
const formatProps = {}
const formatProps: Record<string, CompiledMessage> = {}
token.cases.forEach((item) => {
formatProps[item.key.replace(/^=(.)+/, "$1")] = processTokens(
item.tokens,
Expand All @@ -69,7 +69,7 @@ export function compileMessage(
try {
return processTokens(parse(message), mapText)
} catch (e) {
console.error(`${e.message} \n\nMessage: ${message}`)
console.error(`${(e as Error).message} \n\nMessage: ${message}`)
return message
}
}
10 changes: 10 additions & 0 deletions packages/message-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"lib": [
"ES2019.Array"
],
"strict": true,
"strictNullChecks": false
}
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@lingui/cli/api": ["./packages/cli/src/api"],
"@lingui/react": ["./packages/react/src"],
"@lingui/conf": ["./packages/conf/src"],
"@lingui/macro/node": ["./packages/macro/src/index.ts"],
"@lingui/macro": ["./packages/macro/src"],
"@lingui/format-po": ["./packages/format-po/src/po.ts"],
"@lingui/format-json": ["./packages/format-json/src/json.ts"]
Expand Down
Loading