Skip to content

Instantly share code, notes, and snippets.

@LorenzoBloedow
LorenzoBloedow / fixRelativeImports.cjs
Last active June 17, 2023 17:34
Node.js Script to Fix Relative Imports of a File
const fs = require("fs");
const path = require("path");
const chalk = require("chalk");
/**
ARGUMENTS:
(-P | --paths): Comma-separated list of base paths. All files under these paths will be fixed.
(-I | --import-paths): Comma-separated list of import paths. All files under these paths will be used when searching for imports.
If not provided, the paths from (-P | --paths) will be used.
(-D | --dry-run): Prints the results but doesn't actually write them to the files.