Skip to content

Commit 1f71e7d

Browse files
akamecoclaude
andcommitted
Update dependencies to latest versions and modernize configuration
- Update major packages: meow@13, js-yaml@4, glob@11, prettier@3, husky@9, lint-staged@16 - Migrate to ESM modules with "type": "module" in package.json - Update Husky to v9 format with simplified .husky/pre-commit configuration - Modernize meow CLI configuration with importMeta and shortFlag syntax - Update js-yaml API calls from deprecated safeLoad/safeDump to load/dump - Fix TypeScript configuration for Node16 module resolution with ESM - Update Jest configuration for ESM support with proper transform settings - Fix test files to use updated js-yaml API - Resolve all ESLint errors with proper type annotations - Update lint-staged configuration format - All tests passing (15/16, 1 skipped) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 71ddd9c commit 1f71e7d

File tree

9 files changed

+8621
-4152
lines changed

9 files changed

+8621
-4152
lines changed

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged

jest.config.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
module.exports = {
1+
export default {
22
testPathIgnorePatterns: [
33
'<rootDir>[/\\\\](dist|compiled|node_modules)[/\\\\]'
44
],
55
testEnvironment: 'node',
6-
preset: 'ts-jest'
6+
preset: 'ts-jest',
7+
extensionsToTreatAsEsm: ['.ts'],
8+
moduleNameMapper: {
9+
'^(\\.{1,2}/.*)\\.js$': '$1'
10+
},
11+
transform: {
12+
'^.+\\.ts$': [
13+
'ts-jest',
14+
{
15+
useESM: true,
16+
tsconfig: {
17+
module: 'esnext'
18+
}
19+
}
20+
]
21+
},
22+
transformIgnorePatterns: ['node_modules/(?!(.*\\.mjs$))']
723
}

package-lock.json

Lines changed: 8529 additions & 4074 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Extract react-intl messages",
55
"license": "MIT",
66
"repository": "akameco/extract-react-intl-messages",
7+
"type": "module",
78
"author": {
89
"name": "akameco",
910
"email": "akameco.t@gmail.com",
@@ -22,7 +23,8 @@
2223
"lint": "eslint src/**/*.ts --fix --cache",
2324
"pretest": "rimraf .test-cache",
2425
"test": "jest",
25-
"posttest": "rimraf .test-cache"
26+
"posttest": "rimraf .test-cache",
27+
"prepare": "husky"
2628
},
2729
"bin": {
2830
"extract-messages": "dist/cli.js",
@@ -41,68 +43,63 @@
4143
"messages"
4244
],
4345
"dependencies": {
44-
"@babel/core": "^7.9.0",
45-
"babel-plugin-react-intl": "^7.0.0",
46+
"@babel/core": "^7.28.3",
47+
"babel-plugin-react-intl": "^7.9.4",
4648
"deepmerge": "^4.3.1",
4749
"file-entry-cache": "^5.0.1",
48-
"flat": "^5.0.1",
49-
"glob": "^7.1.6",
50-
"js-yaml": "^3.13.1",
50+
"flat": "^5.0.2",
51+
"glob": "11.0.3",
52+
"js-yaml": "4.1.0",
5153
"load-json-file": "^6.2.0",
5254
"lodash.merge": "^4.6.2",
53-
"meow": "^6.1.0",
54-
"mkdirp": "^1.0.3",
55+
"meow": "13.2.0",
56+
"mkdirp": "^1.0.4",
5557
"pify": "^5.0.0",
5658
"read-babelrc-up": "^1.1.0",
57-
"sort-keys": "^4.0.0",
59+
"sort-keys": "^4.2.0",
5860
"write-json-file": "^4.3.0"
5961
},
6062
"devDependencies": {
6163
"@akameco/tsconfig": "^0.4.0",
62-
"@babel/plugin-proposal-class-properties": "^7.8.3",
63-
"@babel/preset-env": "^7.9.0",
64-
"@babel/preset-flow": "^7.9.0",
65-
"@babel/preset-react": "^7.9.1",
66-
"@types/file-entry-cache": "^5.0.0",
67-
"@types/flat": "^5.0.0",
68-
"@types/glob": "^7.1.1",
69-
"@types/jest": "^25.1.4",
70-
"@types/js-yaml": "^3.12.2",
64+
"@babel/plugin-proposal-class-properties": "^7.18.6",
65+
"@babel/preset-env": "^7.28.3",
66+
"@babel/preset-flow": "^7.27.1",
67+
"@babel/preset-react": "^7.27.1",
68+
"@types/file-entry-cache": "^5.0.4",
69+
"@types/flat": "^5.0.5",
70+
"@types/glob": "^7.2.0",
71+
"@types/jest": "^25.2.3",
72+
"@types/js-yaml": "^3.12.10",
7173
"@types/load-json-file": "^2.0.7",
72-
"@types/lodash.merge": "^4.6.6",
73-
"@types/mkdirp": "^1.0.0",
74-
"@types/node": "^24.1.0",
74+
"@types/lodash.merge": "^4.6.9",
75+
"@types/mkdirp": "^1.0.2",
76+
"@types/node": "^24.3.0",
7577
"@types/pify": "^3.0.2",
7678
"@types/temp-write": "^4.0.0",
7779
"@types/write-json-file": "^2.2.1",
7880
"babel-core": "7.0.0-bridge.0",
79-
"babel-plugin-react-intl-auto": "^3.2.0",
80-
"eslint": "^9.32.0",
81-
"husky": "^4.2.3",
82-
"jest": "^30.0.5",
83-
"lint-staged": "^10.0.9",
84-
"prettier": "^2.0.2",
85-
"react": "^16.13.1",
86-
"react-intl": "^4.2.2",
81+
"babel-plugin-react-intl-auto": "^3.3.0",
82+
"eslint": "^9.34.0",
83+
"husky": "9.1.7",
84+
"jest": "^30.1.1",
85+
"lint-staged": "16.1.5",
86+
"prettier": "3.6.2",
87+
"react": "^16.14.0",
88+
"react-intl": "^4.7.6",
8789
"rimraf": "^3.0.2",
8890
"temp-write": "^4.0.0",
8991
"tempy": "^0.5.0",
90-
"ts-jest": "^29.4.0",
91-
"typescript": "^5.8.3",
92-
"typescript-eslint": "^8.38.0"
92+
"ts-jest": "^29.4.1",
93+
"typescript": "^5.9.2",
94+
"typescript-eslint": "^8.41.0"
9395
},
9496
"lint-staged": {
95-
"*.{ts}": [
97+
"*.ts": [
9698
"prettier --write",
9799
"eslint --fix"
98100
],
99101
"*.{js,json,md}": [
100102
"prettier --write"
101103
]
102-
},
103-
"husky": {
104-
"hooks": {
105-
"pre-commit": "lint-staged"
106-
}
107104
}
108105
}

src/cli.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
2-
/* eslint-disable no-console */
2+
33
import meow from 'meow'
4-
import extractMessage from '.'
4+
import extractMessage from './index.js'
55

66
const cli = meow(
77
`
@@ -25,26 +25,27 @@ const cli = meow(
2525
$ extract-messages -l=ja,en -o app/translations -f yaml 'app/**/messages.js'
2626
`,
2727
{
28+
importMeta: import.meta,
2829
flags: {
2930
flat: {
3031
type: 'boolean'
3132
},
3233
output: {
3334
type: 'string',
34-
alias: 'o'
35+
shortFlag: 'o'
3536
},
3637
locales: {
3738
type: 'string',
38-
alias: 'l'
39+
shortFlag: 'l'
3940
},
4041
format: {
4142
type: 'string',
42-
alias: 'f',
43+
shortFlag: 'f',
4344
default: 'json'
4445
},
4546
defaultLocale: {
4647
type: 'string',
47-
alias: 'd'
48+
shortFlag: 'd'
4849
},
4950
overwriteDefault: {
5051
type: 'boolean',
@@ -88,4 +89,5 @@ if (!locales || typeof locales !== 'string') {
8889

8990
const localesMap = locales.split(',')
9091

91-
extractMessage(localesMap, cli.input[0], output, cli.flags)
92+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
93+
extractMessage(localesMap, cli.input[0], output, cli.flags as any)

src/extract-react-intl/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path'
2-
import glob from 'glob'
2+
import { glob } from 'glob'
33
import pify from 'pify'
44
import merge from 'lodash.merge'
55
import deepmerge from 'deepmerge'
@@ -21,7 +21,6 @@ const localeMap = (arr: string[]): LocaleMap =>
2121
return obj
2222
}, {})
2323

24-
2524
const createResolveList =
2625
(fn: (name: string, dirname: string) => string | null) =>
2726
(list: PluginItem[], cwd: string) =>
@@ -112,7 +111,8 @@ export default async (
112111

113112
if (
114113
!plugins.find(
115-
(plugin: PluginItem) => (Array.isArray(plugin) ? plugin[0] : plugin) === 'react-intl'
114+
(plugin: PluginItem) =>
115+
(Array.isArray(plugin) ? plugin[0] : plugin) === 'react-intl'
116116
)
117117
) {
118118
// Append a the `react-intl` babel plugin only when it isn’t already included in the babel config
@@ -131,7 +131,7 @@ export default async (
131131
})
132132
}
133133

134-
const files: string[] = await pify(glob)(pattern)
134+
const files: string[] = await glob(pattern)
135135
if (files.length === 0) {
136136
throw new Error(`File not found (${pattern})`)
137137
}

src/index.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { flatten, unflatten } from 'flat'
77
import loadJsonFile from 'load-json-file'
88
import writeJsonFile from 'write-json-file'
99
import sortKeys from 'sort-keys'
10-
import _extractReactIntl from './extract-react-intl'
10+
import _extractReactIntl from './extract-react-intl/index.js'
1111

1212
const writeJson = (outputPath: string, obj: object, indent: number) => {
1313
return writeJsonFile(`${outputPath}.json`, obj, { indent })
@@ -16,7 +16,7 @@ const writeJson = (outputPath: string, obj: object, indent: number) => {
1616
const writeYaml = (outputPath: string, obj: object, indent: number) => {
1717
return pify(fs.writeFile)(
1818
`${outputPath}.yml`,
19-
yaml.safeDump(obj, { indent }),
19+
yaml.dump(obj, { indent }),
2020
'utf8'
2121
)
2222
}
@@ -28,35 +28,35 @@ function loadLocaleFiles(locales: string[], buildDir: string, ext: string) {
2828

2929
try {
3030
mkdirp.sync(buildDir)
31-
} catch (error) {}
31+
} catch {
32+
// Directory already exists or other error, continue
33+
}
3234

3335
for (const locale of locales) {
3436
const file = path.resolve(buildDir, `${locale}.${ext}`)
3537
// Initialize json file
3638
try {
37-
const output = isJson(ext) ? JSON.stringify({}) : yaml.safeDump({})
39+
const output = isJson(ext) ? JSON.stringify({}) : yaml.dump({})
3840
fs.writeFileSync(file, output, { flag: 'wx' })
39-
} catch (error) {
40-
// @ts-expect-error
41-
if (error.code !== 'EEXIST') {
41+
} catch (error: unknown) {
42+
if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {
4243
throw error
4344
}
4445
}
4546

4647
let messages = isJson(ext)
4748
? loadJsonFile.sync(file)
48-
: yaml.safeLoad(fs.readFileSync(file, 'utf8'), { json: true })
49+
: yaml.load(fs.readFileSync(file, 'utf8'), { json: true })
4950

5051
messages = flatten(messages)
5152

5253
oldLocaleMaps[locale] = {}
53-
// @ts-expect-error
54-
for (const messageKey of Object.keys(messages)) {
55-
// @ts-expect-error
56-
const message = messages[messageKey]
54+
for (const messageKey of Object.keys(messages as object)) {
55+
const message = (messages as Record<string, unknown>)[messageKey]
5756
if (message && typeof message === 'string' && message !== '') {
58-
// @ts-expect-error
59-
oldLocaleMaps[locale][messageKey] = messages[messageKey]
57+
oldLocaleMaps[locale][messageKey] = (
58+
messages as Record<string, unknown>
59+
)[messageKey]
6060
}
6161
}
6262
}
@@ -73,7 +73,7 @@ type Opts = {
7373
indent?: number
7474
}
7575

76-
// eslint-disable-next-line max-lines-per-function
76+
7777
const extractMessage = async (
7878
locales: string[],
7979
pattern: string,
@@ -148,7 +148,3 @@ const extractMessage = async (
148148
extractMessage.extractReactIntl = _extractReactIntl
149149

150150
export default extractMessage
151-
152-
// For CommonJS default export support
153-
module.exports = extractMessage
154-
module.exports.default = extractMessage

src/test/yaml/test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import fs from 'fs'
22
import path from 'path'
3-
// eslint-disable-next-line import/no-extraneous-dependencies
43
import tempy from 'tempy'
5-
// eslint-disable-next-line import/no-extraneous-dependencies
64
import tempWrite from 'temp-write'
75
import yaml from 'js-yaml'
86
import m from '../..'
97

108
const fixturesPath = 'src/test/fixtures/default/**/*.js'
119

1210
const yamlLoad = (tmp: string, file = '') =>
13-
yaml.safeLoad(fs.readFileSync(path.resolve(tmp, file), 'utf8'))
11+
yaml.load(fs.readFileSync(path.resolve(tmp, file), 'utf8'))
1412

1513
const defaultLocale = 'en'
1614

@@ -37,18 +35,18 @@ test('export yaml - flat', async () => {
3735
test('exsit yaml', async () => {
3836
const x = { a: { hello: 'hello2' } }
3937

40-
const tmpEn = tempWrite.sync(yaml.safeDump(x), 'en.yml')
38+
const tmpEn = tempWrite.sync(yaml.dump(x), 'en.yml')
4139
await m(['en'], fixturesPath, path.dirname(tmpEn), {
4240
defaultLocale,
4341
format: 'yaml'
4442
})
45-
expect(yaml.safeLoad(fs.readFileSync(tmpEn, 'utf8'))).toMatchSnapshot()
43+
expect(yaml.load(fs.readFileSync(tmpEn, 'utf8'))).toMatchSnapshot()
4644

47-
const tmpJa = tempWrite.sync(yaml.safeDump(x), 'ja.yml')
45+
const tmpJa = tempWrite.sync(yaml.dump(x), 'ja.yml')
4846
await m(['ja'], fixturesPath, path.dirname(tmpJa), {
4947
defaultLocale,
5048
format: 'yaml'
5149
})
5250

53-
expect(yaml.safeLoad(fs.readFileSync(tmpJa, 'utf8'))).toMatchSnapshot()
51+
expect(yaml.load(fs.readFileSync(tmpJa, 'utf8'))).toMatchSnapshot()
5452
})

tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"extends": "@akameco/tsconfig",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"skipLibCheck": true
5+
"skipLibCheck": true,
6+
"module": "Node16",
7+
"target": "ES2020",
8+
"moduleResolution": "node16",
9+
"isolatedModules": true
610
},
711
"include": ["src"],
812
"exclude": ["node_modules", "**/test.*", "dist"]

0 commit comments

Comments
 (0)