@toolbuilder/rollup-plugin-create-pack-file
v0.1.7
Published
Rollup plugin to create a pack file and move it somewhere else for testing.
Downloads
18
Maintainers
Readme
Rollup-Plugin-Create-Pack-File
This Rollup plugin creates a pack file from your package, and moves it somewhere else as part of testing your package.
This plugin is used by @toolbuilder/rollup-plugin-test-tools, which tests your pack file in temporary ES, CommonJS, and Electron projects.
Installation
npm install --save-dev @toolbuilder/rollup-plugin-create-pack-file
Use
import createPackFile from '@toolbuilder/rollup-plugin-create-pack-file'
export default {
input: 'entry-point.js',
output: {
// By default the plugin will use output.dir or dirname(output.file) for the output directory
file: 'somewhere/es/entry-point.js'
format: 'es'
},
plugins: [
createPackFile({
// if you want the packfile in another place than dirname(output.file) or output.dir,
// specify that directory here.
outputDir: 'somewhere'
})
]
}
This plugin runs using the generateBundle
hook. This lets you use the pack file when the writeBundle
hook runs. The writeBundle
hook runs plugins in parallel, so you can't control plugin execution order.
Options
There are a number of options. The advanced options exist for unit testing, but you might find them useful.
Basic Options:
rootDir
- tell the plugin where the package root is located. By default, this isprocess.cwd()
.outputDir
- tell the plugin the output directory for the pack file. By default the plugin uses Rollup optionsoutput.dir
ordirname(output.file)
- whichever was specified.packCommand
- tell the plugin what command to use to generate the pack file. This is not run in a shell, butexeca
is used to parse the command. By default, this isnpm pack
. For example, I use pnpm instead ofnpm
, so my packCommand option looks likepnpm pack
. The plugin expects the pack file name to matchnpm
naming conventions.
Advanced options:
packageJson
- By default, the plugin readspackage.json
atrootDir
to figure out the pack file name. If you want something else, provide this option an Object that hasname
andversion
attributes just likepackage.json
does.mover
- Async method that moves the pack file. Signature looks like this: async (fullPackFilePath, fullTargetPackFilePath) => {}. No return value is expected. AnError
should be thrown on failure. By default the plugin provides a function to move the file.shellCommand
- An async method that creates the pack file when given thepackCommand
option value. No return value is expected, anError
should be thrown on failure. By default, the plugin usesexeca.command
to runpackCommand
.
Contributing
Contributions are welcome. Please create a pull request.
I use pnpm instead of npm.
Issues
This project uses Github issues.