日本語のREADMEはこちらです: README.ja.md
A Deno utility to automatically correct relative import paths in JavaScript and TypeScript files. It ensures that local module imports include the appropriate .js extension, which is often required in browser environments or for ES Modules in Node.js.
- Adds
.jsExtension: Automatically appends.jsto relative import paths that lack an extension (e.g.,from "./utils"becomesfrom "./utils.js"). - Replaces
.tsExtension: Converts.tsextensions in import paths to.js(e.g.,from "./types.ts"becomesfrom "./types.js"). - Handles Complex Imports: Correctly parses and fixes both single-line and multi-line import statements.
- CLI for Bulk Operations: Provides a command-line tool to fix a single file or recursively fix all
.js,.ts, and.mjsfiles in a directory. - Preserves Quote Style: Maintains the original quote style (single or double) of the import statement.
You can install the CLI globally using Deno:
deno install -n fiximport --allow-read --allow-write https://code4fukui.github.io/fixImport/cli.jsAfter installation, you can use the fiximport command.
Run the command without arguments to scan the current directory and all subdirectories. It will prompt for confirmation before modifying any .js, .ts, and .mjs files.
fiximportProvide a file path as an argument to fix a single file.
fiximport path/to/your/file.jsYou can also use fixImport as a function within your Deno projects.
import { fixImport } from "https://code4fukui.github.io/fixImport/fixImport.js";
const brokenCode = 'import { some } from "./some";\nimport { other } from "./other.ts";';
const fixedCode = fixImport(brokenCode);
console.log(fixedCode);
// Output:
// import { some } from "./some.js";
// import { other } from "./other.js";MIT License — see LICENSE.