πβπ¦ Build tool to generate proxy directories.
Build tool to generate proxy directories with package.json
files such as this:
{
"name": "redux-saga/effects",
"private": true,
"main": "../lib/effects.js",
"module": "../es/effects.js"
}
When it comes to "main" entry points of our libraries we have an easy way for
supporting both CJS & ESM files with respectively "main"
and "module"
fields
in package.json
. This allows resolution algorithms to chose a file with the
best format automatically. However if we have multiple files in a package and
we want all of them to be importable we often suggest to users doing it like
this:
import module from "package/lib/module";
There are problems with this approach:
babel
has i.e.webpack
just bails out on CJS fileslib
is innpm
and ifpackage/lib/module
and package/es/module
. This is a mentalThis technique was also described by me in more details in this article.
cherry-pick [input-dir]
Create proxy directories
Commands:
cherry-pick [input-dir] Create proxy directories [default]
cherry-pick clean [input-dir] Cleanup generated directories
Options:
--help, -h Show help [boolean]
--version, -v Show version number [boolean]
--cjs-dir [default: "lib"]
--esm-dir [default: "es"]
--types-dir
--cwd [default: "."]
--input-dir [default: "src"]
cherry-pick clean [input-dir]
Cleanup generated directories
Options:
--help, -h Show help [boolean]
--version, -v Show version number [boolean]
--cwd [default: "."]
--input-dir [default: "src"]
cherry-pick
exports a default
method which creates proxy directories and
clean
which removes them. Both accepts the same options as corresponding CLI
commands, only they are camelCased.
const { default: cherryPick, clean } = require("cherry-pick");
cherryPick({ inputDir: "source" })
.then(cherryPicked =>
console.log(`Created proxy directories: ${cherryPicked.join(", ")}`)
)
.then(() => clean({ inputDir: "source" }))
.then(removed =>
console.log(`Removed proxy directories: ${Removed.join(", ")}`)
);