Skip to content
Open
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
17 changes: 6 additions & 11 deletions .github/workflows/node-test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ jobs:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version:
- 0.10.x
- 0.12.x
- 4.x
- 6.x
- 8.x
# - 10.x
# - 12.x
# - 14.x
# - 16.x
# - 18.x
# - 20.x
- 10.x
- 12.x
- 14.x
- 16.x
- 18.x
- 20.x

steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ Generator.prototype.addSourceContent = function (sourceFile, sourcesContent) {
*/
Generator.prototype.base64Encode = function () {
var map = this.toString();
if (Buffer.from) {
return Buffer.from(map).toString('base64');
}
return new Buffer(map).toString('base64');
return Buffer.from(map).toString('base64');
};

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"url": "http://thlorenz.com"
},
"license": "MIT",
"engine": {
"node": ">=0.6"
"engines": {
"node": ">=10"
}
}
5 changes: 1 addition & 4 deletions test/inline-source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ var bar = '' + function bar () {
}

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

function inspect(obj, depth) {
Expand Down
25 changes: 11 additions & 14 deletions test/source-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ var bar = '' + function bar () {
}

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

function inspect(obj, depth) {
Expand All @@ -43,20 +40,20 @@ test('generated mappings', function (t) {
"mappings": "AAAA;AACA;AACA;AACA;AACA",
"sourceRoot": "",
"sourcesContent": [
"function foo() {\n var hello = 'hello';\n var world = 'world';\n console.log('%s %s', hello, world);\n}"
"function foo () {\n var hello = 'hello';\n var world = 'world';\n console.log('%s %s', hello, world);\n}"
],
}
, 'includes source content'
)

t.equal(
decode(gen.base64Encode())
, '{"version":3,"sources":["foo.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":["function foo() {\\n var hello = \'hello\';\\n var world = \'world\';\\n console.log(\'%s %s\', hello, world);\\n}"]}'
, '{"version":3,"sources":["foo.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":["function foo () {\\n var hello = \'hello\';\\n var world = \'world\';\\n console.log(\'%s %s\', hello, world);\\n}"]}'
, 'encodes generated mappings including source content'
)
t.equal(
gen.inlineMappingUrl()
, '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJmdW5jdGlvbiBmb28oKSB7XG4gIHZhciBoZWxsbyA9ICdoZWxsbyc7XG4gIHZhciB3b3JsZCA9ICd3b3JsZCc7XG4gIGNvbnNvbGUubG9nKCclcyAlcycsIGhlbGxvLCB3b3JsZCk7XG59Il19'
, '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJmdW5jdGlvbiBmb28gKCkge1xuICB2YXIgaGVsbG8gPSAnaGVsbG8nO1xuICB2YXIgd29ybGQgPSAnd29ybGQnO1xuICBjb25zb2xlLmxvZygnJXMgJXMnLCBoZWxsbywgd29ybGQpO1xufSJdfQ=='
, 'returns correct inline mapping url including source content'
)
t.end()
Expand All @@ -81,21 +78,21 @@ test('generated mappings', function (t) {
"mappings": "ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA",
"sourceRoot": "",
"sourcesContent": [
"function foo() {\n var hello = 'hello';\n var world = 'world';\n console.log('%s %s', hello, world);\n}",
"function bar() {\n console.log('yes?');\n}"
"function foo () {\n var hello = 'hello';\n var world = 'world';\n console.log('%s %s', hello, world);\n}",
"function bar () {\n console.log('yes?');\n}"
],
}
, 'includes source content for both files'
)

t.same(
decode(gen.base64Encode())
, '{"version":3,"sources":["foo.js","bar.js"],"names":[],"mappings":"ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":["function foo() {\\n var hello = \'hello\';\\n var world = \'world\';\\n console.log(\'%s %s\', hello, world);\\n}","function bar() {\\n console.log(\'yes?\');\\n}"]}'
, '{"version":3,"sources":["foo.js","bar.js"],"names":[],"mappings":"ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":["function foo () {\\n var hello = \'hello\';\\n var world = \'world\';\\n console.log(\'%s %s\', hello, world);\\n}","function bar () {\\n console.log(\'yes?\');\\n}"]}'
, 'encodes generated mappings including source content'
)
t.equal(
gen.inlineMappingUrl()
, '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyIsImJhci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUNBQSxBREFBO0FDQ0EsQURBQTtBQ0NBLEFEQUE7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJmdW5jdGlvbiBmb28oKSB7XG4gIHZhciBoZWxsbyA9ICdoZWxsbyc7XG4gIHZhciB3b3JsZCA9ICd3b3JsZCc7XG4gIGNvbnNvbGUubG9nKCclcyAlcycsIGhlbGxvLCB3b3JsZCk7XG59IiwiZnVuY3Rpb24gYmFyKCkge1xuICBjb25zb2xlLmxvZygneWVzPycpO1xufSJdfQ=='
, '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyIsImJhci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUNBQSxBREFBO0FDQ0EsQURBQTtBQ0NBLEFEQUE7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJmdW5jdGlvbiBmb28gKCkge1xuICB2YXIgaGVsbG8gPSAnaGVsbG8nO1xuICB2YXIgd29ybGQgPSAnd29ybGQnO1xuICBjb25zb2xlLmxvZygnJXMgJXMnLCBoZWxsbywgd29ybGQpO1xufSIsImZ1bmN0aW9uIGJhciAoKSB7XG4gIGNvbnNvbGUubG9nKCd5ZXM/Jyk7XG59Il19'
, 'returns correct inline mapping url including source content'
)
t.end()
Expand All @@ -117,20 +114,20 @@ test('generated mappings', function (t) {
],
"names": [],
"mappings": "ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA",
"sourcesContent": [ null, "function bar() {\n console.log('yes?');\n}" ],
"sourcesContent": [ null, "function bar () {\n console.log('yes?');\n}" ],
"sourceRoot": ""
}
, 'includes source content for the file with source content and [null] for the other file'
)

t.same(
decode(gen.base64Encode())
, '{"version":3,"sources":["foo.js","bar.js"],"names":[],"mappings":"ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":[null,"function bar() {\\n console.log(\'yes?\');\\n}"]}'
, '{"version":3,"sources":["foo.js","bar.js"],"names":[],"mappings":"ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":[null,"function bar () {\\n console.log(\'yes?\');\\n}"]}'
, 'encodes generated mappings including source content'
)
t.equal(
gen.inlineMappingUrl()
, '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyIsImJhci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUNBQSxBREFBO0FDQ0EsQURBQTtBQ0NBLEFEQUE7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6W251bGwsImZ1bmN0aW9uIGJhcigpIHtcbiAgY29uc29sZS5sb2coJ3llcz8nKTtcbn0iXX0='
, '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyIsImJhci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUNBQSxBREFBO0FDQ0EsQURBQTtBQ0NBLEFEQUE7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6W251bGwsImZ1bmN0aW9uIGJhciAoKSB7XG4gIGNvbnNvbGUubG9nKCd5ZXM/Jyk7XG59Il19'
, 'returns correct inline mapping url including source content'
)
t.end()
Expand Down