1.0.0 • Published 2 years ago

gulp-sourcemaps-identity v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

gulp-sourcemaps-identity

Latest version Dependency status Code coverage

Gulp plugin for adding identity mappings to source maps with no mappings, handling JavaScript sources.

Some gulp plugins may have troubles processing a source, which was just read from a file and not generated by a transpiler. The source map mappings will be empty in such case. This plugin will replace the empty string with mappings pointing every token to its original location. It will ensure identity mappings, but only if no mappings have been included and only for JavaScript sources.

Usage

First, install gulp-sourcemaps-identity as a development dependency:

npm i -D gulp-sourcemaps-identity

Then, add it to your gulpfile.js:

import gulp from 'gulp'
import sourcemaps from 'gulp-sourcemaps'
import { ensureMappings } from 'gulp-sourcemaps-identity'

gulp
  .src('src/**/*.js')
	.pipe(sourcemaps.init())
	.pipe(ensureMappings())
	.pipe(sourcemaps.write('../dist', {
		includeContent: false,
		sourceRoot: '../dist'
	}))
	.pipe(gulp.dest('dist'))

API

ensureMappings(options)

Options may be passed as properties in an object to the jsonlint function. The following are their defaults:

ensureMappings({
	filter: undefined,
  verbose: false
})
  • filter: when set to a function, if the function returns true, the file and its source map will be processed, otherwise they will be skipped
  • verbose: when set to true, status of each processed file will be printed on the console, otherwise only warnings and errors will be printed
// if sources include various types, process only scripts
filter(file) {
	return file.relative.endsWith('.js')
}

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.

License

Copyright (C) 2022 Ferdinand Prantl

Licensed under the MIT License.