const {pick} = require("lodash")
import {pick} from "lodash-es"
Dependency migration:
sed -i 's/"lodash":/"lodash-es":/g' package.json && npm install && npx git-flush-cli "Changed dependency lodash to lodash-es"
const debug = require("debug")(process.env.REPLACE_PKG_NAME)
import createDebug from "debug"
const debug = createDebug(process.env.REPLACE_PKG_NAME)
const fileName = __filename
import {fileURLToPath} from "node:url"
const fileName = fileURLToPath(import.meta.url)
const dirName = __dirname
import path from "node:path"
import {fileURLToPath} from "node:url"
const dirName = path.dirname(fileURLToPath(import.meta.url))
const pkg = require("./package.json")
Using fs-extra:
import fs from "fs-extra"
const pkg = await fs.readJson("./package.json")
Without external packages:
import fs from "node:fs/promises"
const pkgContent = await fs.readFile("./package.json", "utf8")
const pkg = JSON.parse(pkgContent)
import path from "path"
const indexModule = require(process.env.MAIN ? path.resolve(process.env.MAIN) : path.join(__dirname, "..", "src", "index.js"))
/**
* @type { import("../src") }
*/
const {default: myModule} = indexModule
import {expect, it} from "@jest/globals"
import path from "node:path"
import {fileURLToPath, pathToFileURL} from "node:url"
const dirName = path.dirname(fileURLToPath(import.meta.url))
const indexPath = process.env.MAIN ?? path.join(dirName, "..", "src", "index.js")
/**
* @type { import("../src") }
*/
const {default: myModule} = await import(pathToFileURL(indexPath))
Natively supported with v10. Progress here:
jprichardson/node-fs-extra#746
🗎 test/test.js
import {mkdirp, writeFile, readJson} from "fs-extra"
🗎 test/test.js
import {mkdirp, writeFile, readJson} from "../src/lib/esm/fs-extra.js"
🗎 src/lib/esm/fs-extra.js
import {createRequire} from "node:module"
const require = createRequire(import.meta.url)
const commonJsModule = require("fs-extra")
export const fs = commonJsModule
export default fs
import yargs from "yargs"
/**
* @typedef {Object} Args
*/
/**
* @param {Args} args
* @return {Promise<void>}
*/
const job = async args => {
}
/**
* @type {import("yargs").CommandBuilder}
*/
const builder = {
}
yargs
.scriptName(process.env.REPLACE_PKG_NAME)
.version(process.env.REPLACE_PKG_VERSION)
.command("$0", process.env.REPLACE_PKG_DESCRIPTION, builder, job)
.argv
import yargs from "yargs"
import {hideBin} from "yargs/helpers"
/**
* @typedef {Object} Args
*/
/**
* @param {Args} args
* @return {Promise<void>}
*/
const job = async args => {
}
/**
* @type {import("yargs").CommandBuilder}
*/
const builder = {
}
await yargs(hideBin(process.argv))
.scriptName(process.env.REPLACE_PKG_NAME)
.version(process.env.REPLACE_PKG_VERSION)
.command("$0", process.env.REPLACE_PKG_DESCRIPTION, builder, job)
.parse()
up && rebuildLockfile && npm pkg set type=module && npx git-flush-cli 'Changed package type to module' && git sync && u acorn && esmPath && fix