Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sourcemap validation #72

Merged
merged 1 commit into from Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 0 additions & 18 deletions lib/source-map.js
Expand Up @@ -9,7 +9,6 @@ const crypto = require('crypto');
const chalk = require('chalk');
const EOL = require('os').EOL;
const endsWith = require('./endsWith');
const validator = require('sourcemap-validator');
const logger = require('heimdalljs-logger')('fast-sourcemap-concat:');


Expand Down Expand Up @@ -112,24 +111,7 @@ class SourceMap {
inputSrcMap = this._resolveSourcemap(filename, url);
}

let valid = true;

if (inputSrcMap) {
try {
// TODO: don't stringify here
validator(source, JSON.stringify(inputSrcMap));
} catch (e) {
logger.error(' invalid sourcemap for: %s', filename);
if (typeof e === 'object' && e !== null) {
logger.error(' error: ', e.message);
}

// print
valid = false;
}
}

if (inputSrcMap && valid) {
let haveLines = countNewLines(source);
source = this._addMap(filename, inputSrcMap, source, haveLines);
} else {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -20,8 +20,7 @@
"memory-streams": "^0.1.3",
"mkdirp": "^0.5.0",
"@jacobq/source-map": "^1.1.0",
"source-map-url": "^0.3.0",
"sourcemap-validator": "^1.1.0"
"source-map-url": "^0.3.0"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/emptyish/too-few-sources.js

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/emptyish/too-many-sources.js

This file was deleted.

7 changes: 0 additions & 7 deletions test/fixtures/sprintf/first.js

This file was deleted.

4 changes: 0 additions & 4 deletions test/fixtures/sprintf/sprintf.min.js

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/sprintf/sprintf.min.map

This file was deleted.

45 changes: 4 additions & 41 deletions test/test.js
Expand Up @@ -15,7 +15,6 @@ const path = require('path');
const rimraf = require('rimraf');
const sinon = require('sinon');
const EOL = require('os').EOL;
const validateSourcemap = require('sourcemap-validator');
const FSMerger = require('fs-merger');

function createFS(rootPath = './') {
Expand Down Expand Up @@ -265,17 +264,6 @@ describe('fast sourcemap concat', function() {
});
});

it("absorbs broken (sprintf)", function() {
let s = new SourceMap({ outputFile: 'tmp/sprintf-multi.js' });

s.addFile('fixtures/sprintf/sprintf.min.js');

s.addFile('fixtures/sprintf/first.js');
return s.end().then(function(){
expectValidSourcemap('sprintf-multi.js').in('tmp');
});
});

it("deals with missing newline followed by single newline", function() {
let s = new SourceMap({outputFile: 'tmp/iife-wrapping.js'});
s.addFile('fixtures/other/fourth.js');
Expand All @@ -298,27 +286,7 @@ describe('fast sourcemap concat', function() {
s.addFile('fixtures/emptyish/src/b.js');
s.addFile('fixtures/other/third.js');
return s.end().then(function(){
expectValidSourcemap('no-sources-content-out.js', 'no-sources-content-out.map').in('tmp');
});
});

it("should discard invalid sourcemaps with more sources than sourcesContent", function() {
let s = new SourceMap({outputFile: 'tmp/too-many-sources-out.js'});
s.addFile('fixtures/other/fourth.js');
s.addFile('fixtures/emptyish/too-many-sources.js');
s.addFile('fixtures/other/third.js');
return s.end().then(function(){
expectValidSourcemap('too-many-sources-out.js', 'too-many-sources-out.map').in('tmp');
});
});

it("should discard invalid sourcemaps with more sourcesContent than sources", function() {
let s = new SourceMap({outputFile: 'tmp/too-few-sources-out.js'});
s.addFile('fixtures/other/fourth.js');
s.addFile('fixtures/emptyish/too-few-sources.js');
s.addFile('fixtures/other/third.js');
return s.end().then(function(){
expectValidSourcemap('too-few-sources-out.js', 'too-few-sources-out.map').in('tmp');
expectSourcemap('no-sources-content-out.js', 'no-sources-content-out.map').in('tmp');
});
});

Expand All @@ -343,15 +311,15 @@ describe('fast sourcemap concat', function() {
expectFile('hello-world-output.js').in('tmp');
copySync('tmp/hello-world-output.map', 'tmp/hello-world-output-1.map');

expectValidSourcemap('hello-world-output.js', 'hello-world-output-1.map').in('tmp');
expectSourcemap('hello-world-output.js', 'hello-world-output-1.map').in('tmp');

copySync('fixtures/typescript/2/hello-world.js', 'tmp/hello-world.js');
copySync('fixtures/typescript/2/hello-world.ts', 'tmp/hello-world.ts');
return runOnce();
}).then(function() {
expectFile('hello-world-output.js').in('tmp');
copySync('tmp/hello-world-output.map', 'tmp/hello-world-output-2.map');
expectValidSourcemap('hello-world-output.js', 'hello-world-output-2.map').in('tmp');
expectSourcemap('hello-world-output.js', 'hello-world-output-2.map').in('tmp');
});
});

Expand Down Expand Up @@ -503,7 +471,7 @@ function expectFile(filename, actualContent) {
};
}

function expectValidSourcemap(jsFilename, mapFilename) {
function expectSourcemap(jsFilename, mapFilename) {
return {
in: function (result, subdir) {
if (!subdir) {
Expand All @@ -516,11 +484,6 @@ function expectValidSourcemap(jsFilename, mapFilename) {

expectFile(jsFilename).in(result, subdir);
expectFile(mapFilename).in(result, subdir);

let actualMin = fs.readFileSync(path.join(result, subdir, jsFilename), 'utf-8');
let actualMap = fs.readFileSync(path.join(result, subdir, mapFilename), 'utf-8');

validateSourcemap(actualMin, actualMap, {});
}
}
}
Expand Down