通过 AST 检测 JS 文件是不是 ESM,并非读取 "package.json " 文件中 "type" 设置。
path
,{ String },路径
import { log } from "console";
import { isESM, isESMSync } from "@iyowei/is-esm";
(async () => {
log(await isESM("/Users/iyowei/Development/iyowei/create-esm/src/print.js")); // 异步
// true
log(isESMSync("/Users/iyowei/Development/iyowei/create-esm/src/print.js")); // 串行
// true
})();
# Pnpm
pnpm add @iyowei/is-esm
# yarn
yarn add @iyowei/is-esm
# npm
npm add @iyowei/is-esm