Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/node-test.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: yarn install
- run: yarn test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ results
node_modules
npm-debug.log
tmp
.nyc_output/
.idea
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org/
4 changes: 4 additions & 0 deletions .taprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
branches: 0
functions: 0
lines: 0
statements: 0
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 0.6.3 (2023-05-17)


### Bug Fixes

* add empty mapping ([c99e7c3](https://github.com/thlorenz/inline-source-map/commit/c99e7c38ea5361dcbf6e06056f0d272083985a3c))
* Buffer warning & update ci ([37672e6](https://github.com/thlorenz/inline-source-map/commit/37672e6c5556a39db06ff3e51b6a07d217e3a033))
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ function newlinesIn(src) {

return newlines ? newlines.length : 0;
}

function Generator(opts) {
opts = opts || {};
this.generator = new SourceMapGenerator({ file: opts.file || '', sourceRoot: opts.sourceRoot || '' });
this.generator = new SourceMapGenerator({ file: opts.file || '', sourceRoot: opts.sourceRoot || '', skipValidation: true });
this.sourcesContent = undefined;
this.opts = opts;
}

/**
* Adds the given mappings to the generator and offsets them if offset is given
* Adds the given mappings to the generator and offsets them if offset is given
*
* @name addMappings
* @function
Expand All @@ -29,8 +29,8 @@ function Generator(opts) {
* @param offset {Object} offset to apply to each mapping. Has the form { line: _, column: _ }
* @return {Object} the generator to allow chaining
*/
Generator.prototype.addMappings = function (sourceFile, mappings, offset) {
var generator = this.generator;
Generator.prototype.addMappings = function (sourceFile, mappings, offset) {
var generator = this.generator;

offset = offset || {};
offset.line = offset.hasOwnProperty('line') ? offset.line : 0;
Expand Down Expand Up @@ -71,7 +71,7 @@ Generator.prototype.addGeneratedMappings = function (sourceFile, source, offset)

/**
* Adds source content for the given source file.
*
*
* @name addSourceContent
* @function
* @param sourceFile {String} The source file for which a mapping is included
Expand All @@ -91,13 +91,13 @@ Generator.prototype.addSourceContent = function (sourceFile, sourcesContent) {
*/
Generator.prototype.base64Encode = function () {
var map = this.toString();
return new Buffer(map).toString('base64');
return Buffer.from(map).toString('base64');
};

/**
* @name inlineMappingUrl
* @function
* @return {String} comment with base64 encoded representation of the added mappings. Can be inlined at the end of the generated file.
* @return {String} comment with base64 encoded representation of the added mappings. Can be inlined at the end of the generated file.
*/
Generator.prototype.inlineMappingUrl = function () {
var charset = this.opts.charset || 'utf-8';
Expand Down
15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
{
"name": "inline-source-map",
"version": "0.6.2",
"version": "0.6.3",
"description": "Adds source mappings and base64 encodes them, so they can be inlined in your generated file.",
"main": "index.js",
"scripts": {
"test-main": "tap test/*.js",
"test-0.8": "nave use 0.8 npm run test-main",
"test-0.10": "nave use 0.10 npm run test-main",
"test-0.12": "nave use 0.12 npm run test-main",
"test-all": "npm run test-main && npm run test-0.8 && npm run test-0.10 && npm run test-0.12",
"test": "if [ -e $TRAVIS ]; then npm run test-all; else npm run test-main; fi"
"test": "tap test/*.js"
},
"repository": {
"type": "git",
Expand All @@ -20,8 +15,8 @@
"source-map": "~0.5.3"
},
"devDependencies": {
"tap": "~0.7.0",
"nave": "~0.5.0"
"nave": "~3.3.1",
"tap": "~16.3.2"
},
"keywords": [
"source",
Expand All @@ -39,6 +34,6 @@
},
"license": "MIT",
"engine": {
"node": ">=0.6"
"node": ">= 12"
}
}
32 changes: 16 additions & 16 deletions test/inline-source-map.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
/*jshint asi: true*/

var test = require('tap').test
var tap = require('tap')
var generator = require('..');

var foo = '' + function foo () {
Expand All @@ -15,20 +15,20 @@ var bar = '' + function bar () {
}

function decode(base64) {
return new Buffer(base64, 'base64').toString();
return Buffer.from(base64, 'base64').toString();
}

function inspect(obj, depth) {
console.error(require('util').inspect(obj, false, depth || 5, true));
}

test('generated mappings', function (t) {
tap.pass('generated mappings', function (t) {

t.test('one file no offset', function (t) {
var gen = generator()
.addGeneratedMappings('foo.js', foo)

t.deepEqual(
t.same(
gen._mappings()
, [ { generatedLine: 1,
generatedColumn: 0,
Expand Down Expand Up @@ -63,7 +63,7 @@ test('generated mappings', function (t) {
, 'generates correct mappings'
)

t.deepEqual(
t.same(
JSON.parse(decode(gen.base64Encode()))
, {"version":3,"file":"","sources":["foo.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA","sourceRoot":""}
, 'encodes generated mappings'
Expand All @@ -81,7 +81,7 @@ test('generated mappings', function (t) {
.addGeneratedMappings('foo.js', foo)
.addGeneratedMappings('bar.js', bar)

t.deepEqual(
t.same(
gen._mappings()
, [ { generatedLine: 1,
generatedColumn: 0,
Expand Down Expand Up @@ -133,7 +133,7 @@ test('generated mappings', function (t) {
name: null } ]
, 'generates correct mappings'
)
t.deepEqual(
t.same(
JSON.parse(decode(gen.base64Encode()))
, {"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":"ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA","sourceRoot": ""}
, 'encodes generated mappings'
Expand All @@ -148,7 +148,7 @@ test('generated mappings', function (t) {

t.test('one line source', function (t) {
var gen = generator().addGeneratedMappings('one-liner.js', 'console.log("line one");')
t.deepEqual(
t.same(
gen._mappings()
, [ { generatedLine: 1,
generatedColumn: 0,
Expand All @@ -166,7 +166,7 @@ test('generated mappings', function (t) {
.addGeneratedMappings('foo.js', foo, { line: 20 })
.addGeneratedMappings('bar.js', bar, { line: 23, column: 22 })

t.deepEqual(
t.same(
gen._mappings()
, [ { generatedLine: 21,
generatedColumn: 0,
Expand Down Expand Up @@ -219,7 +219,7 @@ test('generated mappings', function (t) {
, 'generates correct mappings'
)

t.deepEqual(
t.same(
JSON.parse(decode(gen.base64Encode()))
, {"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA,sBCHA;ADIA,sBCHA;sBACA", "sourceRoot": ""}
, 'encodes generated mappings with offset'
Expand All @@ -228,7 +228,7 @@ test('generated mappings', function (t) {
})
})

test('given mappings, with one having no original', function (t) {
tap.pass('given mappings, with one having no original', function (t) {
t.test('no offset', function (t) {
var gen = generator()
.addMappings('foo.js', [{ original: { line: 2, column: 3 } , generated: { line: 5, column: 10 } }])
Expand All @@ -243,7 +243,7 @@ test('given mappings, with one having no original', function (t) {
, { generated: { line: 8, column: 30 } }
])

t.deepEqual(
t.same(
gen._mappings()
, [ { generatedLine: 5,
generatedColumn: 10,
Expand All @@ -265,7 +265,7 @@ test('given mappings, with one having no original', function (t) {
name: null } ]
, 'adds correct mappings'
)
t.deepEqual(
t.same(
JSON.parse(decode(gen.base64Encode()))
, {"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":";;;;UACG;;oBCIH;8B", sourceRoot: ""}
, 'encodes generated mappings'
Expand All @@ -283,7 +283,7 @@ test('given mappings, with one having no original', function (t) {
.addMappings('foo.js', [{ original: { line: 2, column: 3 } , generated: { line: 5, column: 10 } }], { line: 5 })
.addMappings('bar.js', [{ original: { line: 6, column: 0 } , generated: { line: 7, column: 20 } }, { generated: { line: 8, column: 30 } }], { line: 9, column: 3 })

t.deepEqual(
t.same(
gen._mappings()
, [ { generatedLine: 10,
generatedColumn: 10,
Expand All @@ -305,7 +305,7 @@ test('given mappings, with one having no original', function (t) {
name: null } ]
, 'adds correct mappings'
)
t.deepEqual(
t.same(
JSON.parse(decode(gen.base64Encode()))
, {"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":";;;;;;;;;UACG;;;;;;uBCIH;iC", sourceRoot: ""}
, 'encodes mappings with offset'
Expand All @@ -314,7 +314,7 @@ test('given mappings, with one having no original', function (t) {
})
});

test('inline mapping url with charset opt', function(t){
tap.pass('inline mapping url with charset opt', function(t){
t.test('set inline mapping url charset to gbk', function(t){
var gen = generator({charset: 'gbk'})
.addGeneratedMappings('foo.js', foo);
Expand Down
Loading