Skip to content

Instantly share code, notes, and snippets.

@vhenzl
vhenzl / find-imports.mjs
Created May 19, 2023 03:19
Script to find all imports from a module in JS/TS code
#! /usr/bin/env node
// Based on https://github.com/montlebalm/find-js-imports
import { readFileSync } from 'fs';
import { basename } from 'path';
import glob from 'glob';
import { fileURLToPath } from 'url';
// https://gist.github.com/manekinekko/7e58a17bc62a9be47172
const IMPORT_RX = /^import (?:["'\s]*([\w*{}\n, ]+) from\s*)?["'\s]*([.@\w\/_-]+)["'\s]*;?/gm;