pax_global_header00006660000000000000000000000064136314662000014513gustar00rootroot0000000000000052 comment=251b51598d02e5aedaea8f1a475dfc42103a2727 identity-map-2.0.1/000077500000000000000000000000001363146620000141175ustar00rootroot00000000000000identity-map-2.0.1/.editorconfig000066400000000000000000000003051363146620000165720ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false identity-map-2.0.1/.eslintignore000066400000000000000000000000161363146620000166170ustar00rootroot00000000000000test/fixtures identity-map-2.0.1/.eslintrc000066400000000000000000000000301363146620000157340ustar00rootroot00000000000000{ "extends": "gulp" } identity-map-2.0.1/.gitignore000066400000000000000000000012701363146620000161070ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript # Garbage files .DS_Store # Generated by integration tests test/fixtures/tmp test/fixtures/out .nyc_output identity-map-2.0.1/.travis.yml000066400000000000000000000001551363146620000162310ustar00rootroot00000000000000sudo: false language: node_js node_js: - '12' - '10' - '8' - '6' after_script: - npm run coveralls identity-map-2.0.1/LICENSE000066400000000000000000000021241363146620000151230ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2017 Blaine Bublitz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. identity-map-2.0.1/README.md000066400000000000000000000027541363146620000154060ustar00rootroot00000000000000# @gulp-sourcemaps/identity-map [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] Gulp plugin for generating an identity sourcemap for a file. ## Example ```js var identityMap = require('@gulp-sourcemaps/identity-map'); gulp.src(...) .pipe(sourcemaps.init()) .pipe(identityMap()) // .js and .css files will get a generated sourcemap .pipe(sourcemaps.write()) .pipe(gulp.dest(...)) ``` ## API ### `identityMap()` Returns an `objectMode` Transform stream that processes each file with a `.sourceMap` property and buffered contents. A sourcemap is generated and attached for each `.js` and `.css` file. ## License MIT [downloads-image]: http://img.shields.io/npm/dm/@gulp-sourcemaps/identity-map.svg [npm-url]: https://npmjs.org/package/@gulp-sourcemaps/identity-map [npm-image]: http://img.shields.io/npm/v/@gulp-sourcemaps/identity-map.svg [travis-url]: https://travis-ci.org/gulp-sourcemaps/identity-map [travis-image]: http://img.shields.io/travis/gulp-sourcemaps/identity-map.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/phated/identity-map [appveyor-image]: https://img.shields.io/appveyor/ci/phated/identity-map.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulp-sourcemaps/identity-map [coveralls-image]: http://img.shields.io/coveralls/gulp-sourcemaps/identity-map.svg identity-map-2.0.1/appveyor.yml000066400000000000000000000007611363146620000165130ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # http://www.appveyor.com/docs/lang/nodejs-iojs environment: matrix: # node.js - nodejs_version: "6" - nodejs_version: "8" - nodejs_version: "10" # Waiting on https://github.com/appveyor/ci/issues/2921 # - nodejs_version: "12" install: - ps: Install-Product node $env:nodejs_version - npm install test_script: - node --version - npm --version - cmd: npm test build: off # build version format version: "{build}" identity-map-2.0.1/index.js000066400000000000000000000013151363146620000155640ustar00rootroot00000000000000'use strict'; var through = require('through2'); var normalizePath = require('normalize-path'); var generate = require('./lib/generate'); function identityMap() { function transform(file, _, cb) { if (!file.sourceMap || !file.isBuffer()) { return cb(null, file); } var sourcePath = normalizePath(file.relative); var contents = file.contents.toString(); switch (file.extname) { case '.js': { file.sourceMap = generate.js(sourcePath, contents); break; } case '.css': { file.sourceMap = generate.css(sourcePath, contents); break; } } cb(null, file); } return through.obj(transform); } module.exports = identityMap; identity-map-2.0.1/lib/000077500000000000000000000000001363146620000146655ustar00rootroot00000000000000identity-map-2.0.1/lib/generate.js000066400000000000000000000023251363146620000170170ustar00rootroot00000000000000'use strict'; var acorn = require('acorn'); var postcss = require('postcss'); var SourceMapGenerator = require('source-map').SourceMapGenerator; function generateJs(sourcePath, fileContent) { var generator = new SourceMapGenerator({ file: sourcePath }); var tokenizer = acorn.tokenizer(fileContent, { allowHashBang: true, locations: true, }); /* eslint no-constant-condition: 0 */ while (true) { var token = tokenizer.getToken(); if (token.type.label === 'eof') { break; } var mapping = { original: token.loc.start, generated: token.loc.start, source: sourcePath, }; if (token.type.label === 'name') { mapping.name = token.value; } generator.addMapping(mapping); } generator.setSourceContent(sourcePath, fileContent); return generator.toJSON(); } var postcssSourceMapOptions = { inline: false, prev: false, sourcesContent: true, annotation: false, }; function generateCss(sourcePath, fileContent) { var root = postcss.parse(fileContent, { from: sourcePath }); var result = root.toResult({ to: sourcePath, map: postcssSourceMapOptions }); return result.map.toJSON(); } module.exports = { js: generateJs, css: generateCss, }; identity-map-2.0.1/package.json000066400000000000000000000021201363146620000164000ustar00rootroot00000000000000{ "name": "@gulp-sourcemaps/identity-map", "version": "2.0.1", "description": "Gulp plugin for generating an identity sourcemap for a file.", "author": "Gulp-sourcemaps Team", "contributors": [ "Blaine Bublitz " ], "repository": "gulp-sourcemaps/identity-map", "license": "MIT", "engines": { "node": ">= 0.10" }, "main": "index.js", "files": [ "LICENSE", "index.js", "lib" ], "scripts": { "lint": "eslint .", "pretest": "npm run lint", "test": "nyc mocha --async-only", "coveralls": "nyc report --reporter=text-lcov | coveralls" }, "dependencies": { "acorn": "^6.4.1", "normalize-path": "^3.0.0", "postcss": "^7.0.16", "source-map": "^0.6.0", "through2": "^3.0.1" }, "devDependencies": { "coveralls": "^3.0.3", "eslint": "^5.16.0", "eslint-config-gulp": "^3.0.1", "expect": "^1.19.0", "mississippi": "^4.0.0", "mocha": "^6.1.4", "nyc": "^14.1.0", "vinyl": "^2.2.0" }, "keywords": [ "sourcemap", "identity", "generate", "stream" ] } identity-map-2.0.1/test/000077500000000000000000000000001363146620000150765ustar00rootroot00000000000000identity-map-2.0.1/test/.eslintrc000066400000000000000000000000351363146620000167200ustar00rootroot00000000000000{ "extends": "gulp/test" } identity-map-2.0.1/test/fixtures/000077500000000000000000000000001363146620000167475ustar00rootroot00000000000000identity-map-2.0.1/test/fixtures/es2018.js000066400000000000000000000010331363146620000202240ustar00rootroot00000000000000const justA = { a: 1 }; // Object Spread const AandB = { ...justA, b: 2 }; // Object Rest const { a: _, ...justB } = AandB; // RegExp unicode ("u") flag Boolean(/abc/u.exec("abc")); // Promise.prototype.finally() Promise.resolve().finally(() => { // at last! }); // RegExp "s" flag Boolean(/.{3}/s.exec("a\nb")); // Regex Lookbehind Assertions Boolean(/(?<=\$)\d+/.exec("$42")); // Tagged template literal revision String.raw`\unicode`; // Good // RegExp named capture groups /(?\d{4})-(?\d{4})/.exec("1992-2019"); identity-map-2.0.1/test/fixtures/helloworld.bin.js000066400000000000000000000001341363146620000222250ustar00rootroot00000000000000#!/usr/bin/env node 'use strict'; function helloWorld() { console.log('Hello world!'); } identity-map-2.0.1/test/fixtures/helloworld.css000066400000000000000000000000521363146620000216310ustar00rootroot00000000000000body { background: #eee; color: #888; } identity-map-2.0.1/test/fixtures/helloworld.js000066400000000000000000000001071363146620000214560ustar00rootroot00000000000000'use strict'; function helloWorld() { console.log('Hello world!'); } identity-map-2.0.1/test/index.js000066400000000000000000000137521363146620000165530ustar00rootroot00000000000000'use strict'; var fs = require('fs'); var path = require('path'); var expect = require('expect'); var miss = require('mississippi'); var File = require('vinyl'); var generate = require('../lib/generate'); var identityMap = require('../'); var pipe = miss.pipe; var from = miss.from; var concat = miss.concat; var jsContent = fs.readFileSync(path.join(__dirname, 'fixtures/helloworld.js')); var jsHashBangContent = fs.readFileSync(path.join(__dirname, 'fixtures/helloworld.bin.js')); var jsES2018Content = fs.readFileSync(path.join(__dirname, 'fixtures/es2018.js')); var cssContent = fs.readFileSync(path.join(__dirname, 'fixtures/helloworld.css')); function makeFile() { var file = new File({ cwd: __dirname, base: __dirname + '/assets', path: __dirname + '/assets/helloworld.js', contents: jsContent, }); file.sourceMap = { version: 3, file: 'helloworld.js', names: [], mappings: '', sources: ['helloworld.js'], }; return file; } describe('identityMap', function() { it('ignores a file without sourceMap property', function(done) { var file = makeFile(); delete file.sourceMap; var spy = expect.spyOn(generate, 'js'); function assert(files) { expect.restoreSpies(); expect(files.length).toEqual(1); expect(spy).toNotHaveBeenCalled(); } pipe([ from.obj([file]), identityMap(), concat(assert), ], done); }); it('only ignores a file without sourceMap property', function(done) { var file = makeFile(); delete file.sourceMap; var file2 = makeFile(); var spy = expect.spyOn(generate, 'js'); function assert(files) { expect.restoreSpies(); expect(files.length).toEqual(2); expect(spy.calls.length).toEqual(1); } pipe([ from.obj([file, file2]), identityMap(), concat(assert), ], done); }); it('ignores a non-Buffer file', function(done) { var file = makeFile(); file.contents = null; var spy = expect.spyOn(generate, 'js'); function assert(files) { expect.restoreSpies(); expect(files.length).toEqual(1); expect(spy).toNotHaveBeenCalled(); } pipe([ from.obj([file]), identityMap(), concat(assert), ], done); }); it('only ignores a non-Buffer file', function(done) { var file = makeFile(); file.contents = null; var file2 = makeFile(); var spy = expect.spyOn(generate, 'js'); function assert(files) { expect.restoreSpies(); expect(files.length).toEqual(2); expect(spy.calls.length).toEqual(1); } pipe([ from.obj([file, file2]), identityMap(), concat(assert), ], done); }); it('adds a valid sourcemap for JS', function(done) { var file = makeFile(); function assert(files) { expect(files.length).toEqual(1); var sourcemap = files[0].sourceMap; expect(sourcemap).toExist(); expect(sourcemap.version).toEqual('3'); expect(sourcemap.sources[0]).toEqual('helloworld.js'); expect(sourcemap.sourcesContent[0]).toEqual(jsContent); expect(sourcemap.names).toEqual(['helloWorld', 'console','log']); expect(sourcemap.mappings).toEqual('AAAA,YAAY;;AAEZ,SAASA,UAAU,CAAC,EAAE;CACrBC,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC;AAC5B'); } pipe([ from.obj([file]), identityMap(), concat(assert), ], done); }); it('adds a valid sourcemap for JS with hashBang', function(done) { var file = makeFile(); file.contents = jsHashBangContent; function assert(files) { expect(files.length).toEqual(1); var sourcemap = files[0].sourceMap; expect(sourcemap).toExist(); expect(sourcemap.version).toEqual('3'); expect(sourcemap.sources[0]).toEqual('helloworld.js'); expect(sourcemap.sourcesContent[0]).toEqual(jsHashBangContent); expect(sourcemap.names).toEqual(['helloWorld', 'console','log']); expect(sourcemap.mappings).toEqual(';AACA,YAAY;;AAEZ,SAASA,UAAU,CAAC,EAAE;EACpBC,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC;AAC7B'); } pipe([ from.obj([file]), identityMap(), concat(assert), ], done); }); it('adds a valid sourcemap for JS with ES2018 syntax', function(done) { var file = makeFile(); file.contents = jsES2018Content; function assert(files) { expect(files.length).toEqual(1); var sourcemap = files[0].sourceMap; expect(sourcemap).toExist(); expect(sourcemap.version).toEqual('3'); expect(sourcemap.sources[0]).toBe('helloworld.js'); expect(sourcemap.sourcesContent[0]).toEqual(jsES2018Content); expect(sourcemap.names).toEqual(['justA', 'a', 'AandB', 'b', '_', 'justB', 'Boolean', 'exec', 'Promise', 'resolve', 'String', 'raw']); expect(sourcemap.mappings).toBe('AAAA,MAAMA,MAAM,EAAE,EAAEC,CAAC,EAAE,EAAE,CAAC;;AAEtB,MAAMC,MAAM,EAAE,EAAE,GAAGF,KAAK,EAAEG,CAAC,EAAE,EAAE,CAAC;;AAEhC,MAAM,EAAEF,CAAC,EAAEG,CAAC,EAAE,GAAGC,MAAM,EAAE,EAAEH,KAAK;;;AAGhCI,OAAO,CAAC,MAAM,CAACC,IAAI,CAAC,KAAK,CAAC,CAAC;;;AAG3BC,OAAO,CAACC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG;;AAEhC,CAAC,CAAC;;;AAGFH,OAAO,CAAC,OAAO,CAACC,IAAI,CAAC,MAAM,CAAC,CAAC;;;AAG7BD,OAAO,CAAC,YAAY,CAACC,IAAI,CAAC,KAAK,CAAC,CAAC;;;AAGjCG,MAAM,CAACC,GAAG,CAAC,QAAQ,CAAC;;;AAGpB,iCAAiC,CAACJ,IAAI,CAAC,WAAW,CAAC'); } pipe([ from.obj([file]), identityMap(), concat(assert), ], done); }); it('adds a valid source map for CSS', function(done) { var file = makeFile(); file.extname = '.css'; file.contents = cssContent; function assert(files) { expect(files.length).toEqual(1); var sourcemap = files[0].sourceMap; expect(sourcemap).toExist(); expect(sourcemap.version).toEqual('3'); expect(sourcemap.sources[0]).toBe('helloworld.css'); expect(sourcemap.sourcesContent[0]).toEqual(cssContent); expect(sourcemap.names).toEqual([]); expect(sourcemap.mappings).toBe('AAAA;CACC,gBAAgB;CAChB,WAAW;AACZ'); } pipe([ from.obj([file]), identityMap(), concat(assert), ], done); }); });