-
-
Notifications
You must be signed in to change notification settings - Fork 143
refactor: Migrate the whole project from cjs to esm #137
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
Changes from 18 commits
f9b9518
88cef2d
2d2b733
69dfbe9
61f7d4d
c8ccf79
f3b1249
e1de83c
d16e568
71193ab
40fa198
94cdcca
8bbeafc
58a9ad5
d48515f
d8f4f2b
a9648f6
b033cbd
5d8715f
454aa0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||||
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 缺少 代码中使用了 +import path from 'node:path'; 这将确保代码的正确性和一致性。 Committable suggestion
Suggested change
|
||||||||
import path from 'node:path'; | ||||||||
|
||||||||
/** | ||||||||
* Ensure the file exists, if not, create it and its directory. | ||||||||
* @param {string} filePath - The path to the file. | ||||||||
*/ | ||||||||
export function ensureFileSync(filePath) { | ||||||||
try { | ||||||||
// Check if the file already exists | ||||||||
if (!existsSync(filePath)) { | ||||||||
// Get the directory name of the file | ||||||||
const dir = path.dirname(filePath); | ||||||||
|
||||||||
// Recursively create the directory if it doesn't exist | ||||||||
if (!existsSync(dir)) { | ||||||||
mkdirSync(dir, { recursive: true }); | ||||||||
} | ||||||||
|
||||||||
// Create an empty file | ||||||||
writeFileSync(filePath, ''); | ||||||||
} | ||||||||
} catch (error) { | ||||||||
console.error(`Error ensuring file: ${error.message}`); | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
"author": "afc163 <[email protected]>", | ||
"license": "MIT", | ||
"bin": { | ||
"fy": "bin/fanyi.js", | ||
"fanyi": "bin/fanyi.js" | ||
"fy": "bin/fanyi.mjs", | ||
"fanyi": "bin/fanyi.mjs" | ||
}, | ||
"keywords": ["chinese", "translator", "iciba", "groq", "llama", "cli", "fanyi"], | ||
"engines": { | ||
|
@@ -20,27 +20,28 @@ | |
"readmeFilename": "README.md", | ||
"files": ["index.js", "bin", "lib"], | ||
"dependencies": { | ||
"chalk": "^4.1.2", | ||
"chalk": "^5.3.0", | ||
"commander": "^12.1.0", | ||
"dayjs": "^1.11.13", | ||
"fast-xml-parser": "^4.5.0", | ||
"fs-extra": "^11.2.0", | ||
"gradient-string": "^2.0.2", | ||
"groq-sdk": "^0.7.0", | ||
"node-fetch": "^3.3.2", | ||
"ora": "^5.4.1", | ||
"update-notifier": "^5.1.0" | ||
"ora": "^8.1.0", | ||
"update-notifier": "^7.3.1" | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts,json,yml}": ["biome check --write --files-ignore-unknown=true"] | ||
"*.{js,mjs,ts,json,yml}": [ | ||
"biome check --write --files-ignore-unknown=true --no-errors-on-unmatched" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.9.0", | ||
"@biomejs/biome": "^1.9.2", | ||
"c8": "^10.1.2", | ||
"husky": "^9.1.6", | ||
"lint-staged": "^15.2.10", | ||
"np": "^10.0.7", | ||
"vitest": "^2.1.0" | ||
"vitest": "^2.1.1" | ||
}, | ||
"scripts": { | ||
"test": "vitest run", | ||
|
@@ -50,5 +51,6 @@ | |
"prepublishOnly": "np --no-cleanup --no-publish", | ||
"lint-staged": "lint-staged", | ||
"prepare": "husky" | ||
} | ||
}, | ||
"type": "module" | ||
} |
Uh oh!
There was an error while loading. Please reload this page.