Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-better-rollup

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-better-rollup - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

84

index.js

@@ -46,9 +46,9 @@ 'use strict'

// user should not specify the entry file path, but let him if he insists for some reason
if (rollupOptions.entry === undefined)
// determine entry from file filename
rollupOptions.entry = path.relative(file.cwd, file.path)
// user should not specify the input file path, but let him if he insists for some reason
if (rollupOptions.input === undefined)
// determine input from file filename
rollupOptions.input = path.relative(file.cwd, file.path)
else
// rename file if entry is given
file.path = path.join(file.cwd, rollupOptions.entry)
// rename file if input is given
file.path = path.join(file.cwd, rollupOptions.input)

@@ -58,3 +58,3 @@ // caching is enabled by default because of the nature of gulp and the watching/recompilatin

if (rollupOptions.cache !== false)
rollupOptions.cache = rollupCache.get(rollupOptions.entry)
rollupOptions.cache = rollupCache.get(rollupOptions.input)

@@ -71,4 +71,4 @@ // enable sourcemap is gulp-sourcemaps plugin is enabled

// to generateOptions (if not defined)
if (generateOptions.dest === undefined)
generateOptions.dest = rollupOptions.dest
if (generateOptions.file === undefined)
generateOptions.file = rollupOptions.file
if (generateOptions['exports'] === undefined)

@@ -78,4 +78,2 @@ generateOptions['exports'] = rollupOptions['exports']

generateOptions.format = rollupOptions.format
if (generateOptions.moduleId === undefined)
generateOptions.moduleId = rollupOptions.moduleId
if (generateOptions.globals === undefined)

@@ -85,26 +83,27 @@ generateOptions.globals = rollupOptions.globals

// But it won't say anything either, leaving a space for confusion
if (generateOptions.moduleName === undefined)
generateOptions.moduleName = rollupOptions.moduleName || moduleName
if (generateOptions.moduleId === undefined)
generateOptions.moduleId = generateOptions.moduleName
generateOptions.sourceMap = createSourceMap
if (generateOptions.name === undefined)
generateOptions.name = rollupOptions.name || moduleName
if (generateOptions.amd === undefined || generateOptions.amd.id === undefined)
generateOptions.amd = Object.assign({}, generateOptions.amd, {id: generateOptions.name})
generateOptions.sourcemap = createSourceMap
// generate bundle according to given or autocompleted options
var result = bundle.generate(generateOptions)
// Pass sourcemap content and metadata to gulp-sourcemaps plugin to handle
// destination (and custom name) was given, possibly multiple output bundles.
if (createSourceMap) {
result.map.file = path.relative(originalCwd, originalPath)
result.map.sources = result.map.sources.map(source => path.relative(originalCwd, source))
}
// return bundled file as buffer
targetFile.contents = new Buffer(result.code)
// apply sourcemap to output file
if (createSourceMap)
applySourceMap(targetFile, result.map)
return bundle.generate(generateOptions).then(result => {
// Pass sourcemap content and metadata to gulp-sourcemaps plugin to handle
// destination (and custom name) was given, possibly multiple output bundles.
if (createSourceMap) {
result.map.file = path.relative(originalCwd, originalPath)
result.map.sources = result.map.sources.map(source => path.relative(originalCwd, source))
}
// return bundled file as buffer
targetFile.contents = new Buffer(result.code)
// apply sourcemap to output file
if (createSourceMap)
applySourceMap(targetFile, result.map)
})
}
var createBundle = (bundle, generateOptions, injectNewFile) => {
// custom output name might be set
if (generateOptions.dest) {
// setup filename name from generateOptions.dest
var newFileName = path.basename(generateOptions.dest)
if (generateOptions.file) {
// setup filename name from generateOptions.file
var newFileName = path.basename(generateOptions.file)
var newFilePath = path.join(file.base, newFileName)

@@ -127,8 +126,10 @@ if (injectNewFile) {

})
generateAndApplyBundle(bundle, generateOptions, newFile)
this.push(newFile)
return generateAndApplyBundle(bundle, generateOptions, newFile).then(result => {
this.push(newFile)
return result
})
} else {
// rename original file
file.path = newFilePath
generateAndApplyBundle(bundle, generateOptions, file)
return generateAndApplyBundle(bundle, generateOptions, file)
}

@@ -138,3 +139,3 @@ } else {

// apply data and sourcemaps to the original file
generateAndApplyBundle(bundle, generateOptions, file)
return generateAndApplyBundle(bundle, generateOptions, file)
}

@@ -154,10 +155,11 @@ }

if (rollupOptions.cache !== false)
rollupCache.set(rollupOptions.entry, bundle)
rollupCache.set(rollupOptions.input, bundle)
// generate ouput according to (each of) given generateOptions
bundleList.forEach((generateOptions, i) => createBundle(bundle, generateOptions, i))
// pass file to gulp and end stream
cb(null, file)
}).catch(err => {
return Promise.all(bundleList.map((generateOptions, i) => createBundle(bundle, generateOptions, i)))
})
// pass file to gulp and end stream
.then(() => cb(null, file))
.catch(err => {
if (rollupOptions.cache !== false)
rollupCache.delete(rollupOptions.entry)
rollupCache.delete(rollupOptions.input)
process.nextTick(() => {

@@ -164,0 +166,0 @@ this.emit('error', new PluginError(PLUGIN_NAME, err))

{
"name": "gulp-better-rollup",
"version": "1.1.1",
"version": "2.0.0",
"description": "Better Gulp plugin for Rollup ES6 module bundler",

@@ -28,3 +28,3 @@ "author": "Mike Kovarik",

"lodash.camelcase": "^4.3.0",
"rollup": "^0.41.5",
"rollup": "^0.50.0",
"vinyl-sourcemaps-apply": "^0.2.1"

@@ -31,0 +31,0 @@ },

@@ -23,6 +23,6 @@ # gulp-better-rollup

.pipe(rollup({
// notice there is no `entry` option as rollup integrates into gulp pipeline
// notice there is no `input` option as rollup integrates into gulp pipeline
plugins: [babel()]
}, {
// also rollups `sourceMap` option is replaced by gulp-sourcemaps plugin
// also rollups `sourcemap` option is replaced by gulp-sourcemaps plugin
format: 'cjs',

@@ -42,3 +42,3 @@ }))

.pipe(sourcemaps.init())
// note that UMD and IIFE format requires `moduleName` but it was guessed based on source file `mylibrary.js`
// note that UMD and IIFE format requires `name` but it was guessed based on source file `mylibrary.js`
.pipe(rollup({plugins: [babel()]}, 'umd'))

@@ -60,3 +60,3 @@ // save sourcemap as separate file (in the same folder)

`entry` should not be used as the entry file is provided by gulp. It also works with gulp-watch
`input` should not be used as the entry file is provided by gulp. It also works with gulp-watch

@@ -76,3 +76,3 @@ ``` js

.pipe(rollup({
entry: 'src/app.js'
input: 'src/app.js'
}, 'umd'))

@@ -88,17 +88,17 @@ .pipe(gulp.dest('./dist'))

`moduleName` and `moduleId` are by default assigned by filename but can be explicitly specified
`name` and `amd.id` are by default assigned by filename but can be explicitly specified
**Caveat:** Exporting to UMD or IIFE format requires to specify `moduleName`. This plugin takes care of autoassigning it based on filename. But if your main file is named `index.js` or `main.js` then your module will be also named `index` or `main`.
**Caveat:** Exporting to UMD or IIFE format requires to specify `name`. This plugin takes care of autoassigning it based on filename. But if your main file is named `index.js` or `main.js` then your module will be also named `index` or `main`.
**Caveat:** If you don't want `moduleId` to be automatically assigned for your AMD modules, set `moduleId` it to empty string `.pipe(rollup({moduleId:''}))`
**Caveat:** If you don't want `amd.id` to be automatically assigned for your AMD modules, set `amd.id` to empty string `.pipe(rollup({amd:{id:''}}))`
`intro/outro` are discouraged to use in favor of gulps standard plugins like [gulp-header](https://www.npmjs.com/package/gulp-header) and [gulp-footer](https://www.npmjs.com/package/gulp-footer)
`sourceMap` option is omitted. Use the standard [gulp-sourcemaps](https://www.npmjs.com/package/gulp-sourcemaps) plugin instead.
`sourcemap` option is omitted. Use the standard [gulp-sourcemaps](https://www.npmjs.com/package/gulp-sourcemaps) plugin instead.
`sourceMapFile` is unvailable as well.
`sourcemapFile` is unvailable as well.
#### shortcuts
If you don't need to define `plugins` like babel, use `external` modules, explicitly specify `entry` file, or any other options of `rollupOptions` object, you can just skip this first argument alltogether. Also `generateOptions` can be replaced by string of module format if you only export in a single format.
If you don't need to define `plugins` like babel, use `external` modules, explicitly specify `input` file, or any other options of `rollupOptions` object, you can just skip this first argument alltogether. Also `generateOptions` can be replaced by string of module format if you only export in a single format.

@@ -123,3 +123,3 @@ ``` js

}, {
moduleName: 'CustomModuleName',
name: 'CustomModuleName',
format: 'umd',

@@ -140,3 +140,3 @@ }))

external: ['first-dep', 'OtherDependency'],
moduleName: 'CustomModuleName',
name: 'CustomModuleName',
format: 'umd',

@@ -158,6 +158,6 @@ }))

.pipe(rollup(rollupOptions, [{
dest: pkg['jsnext:main'],
file: pkg['jsnext:main'],
format: 'es',
}, {
dest: pkg['main'],
file: pkg['main'],
format: 'umd',

@@ -170,5 +170,5 @@ }]))

**Caveat 1:** `dest` can take path instead of just a file name, but the file won't be saved there. Exporting files from gulp always relies on the `.pipe(gulp.dest(...))` and not the plugin itself.
**Caveat 1:** `file` can take path instead of just a file name, but the file won't be saved there. Exporting files from gulp always relies on the `.pipe(gulp.dest(...))` and not the plugin itself.
**Caveat 2:** `gulp-sourcemaps` plugin doesn't (yet) support the `.mjs` extension you might want to use to export ES format into. Specifically it can inline the sourcemap into the bundle file (using `sourcemaps.write()`), and it can also create external sourcemap file with `sourcemaps.write(PATH_TO_SOURCEMAP_FOLDER)`, it just won't insert the `//# sourceMappingURL=` linking comment at the end of your `.mjs` file, effectivelly rendering the sourcemap useless.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc