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

fix: drop special shebang handling #125

Merged
merged 2 commits into from Oct 24, 2020
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
4 changes: 2 additions & 2 deletions .nycrc
Expand Up @@ -7,6 +7,6 @@
"text"
],
"lines": 99.5,
"branches": "94",
"branches": "92",
"statements": "99.5"
}
}
4 changes: 3 additions & 1 deletion lib/source.js
Expand Up @@ -206,8 +206,10 @@ function originalPositionTryBoth (sourceMap, line, column) {
return original
}

// Not required since Node 13, see: https://github.com/nodejs/node/pull/27375
const isPrerNode13 = /^v1[0-2]\./u.test(process.version)
function getShebangLength (source) {
if (source.indexOf('#!') === 0) {
if (isPrerNode13 && source.indexOf('#!') === 0) {
const match = source.match(/(?<shebang>#!.*)/)
if (match) {
return match.groups.shebang.length
Expand Down
62 changes: 59 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -32,6 +32,7 @@
"devDependencies": {
"@types/node": "^12.7.11",
"c8": "^7.2.1",
"semver": "^7.3.2",
"should": "13.2.3",
"standard": "^14.3.1",
"tap": "^14.10.8"
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/shebang.js
@@ -1,5 +1,6 @@
module.exports = {
describe: 'shebang',
maxNodeVersion: 'v13.0.0',
coverageV8: {
"scriptId": "56",
"url": "./test/fixtures/scripts/shebang.js",
Expand Down
6 changes: 6 additions & 0 deletions test/utils/run-fixture.js
Expand Up @@ -2,13 +2,19 @@

const toIstanbul = require('../../')
const t = require('tap')
const semver = require('semver')

t.mochaGlobals()
require('should')

module.exports = async (fixture) => {
const script = toIstanbul(fixture.coverageV8.url)
await script.load()
if (fixture.maxNodeVersion && !semver.lt(process.version, fixture.maxNodeVersion)) {
console.info(`skipping "${fixture.describe}" fixture maxNodeVersion = ${fixture.maxNodeVersion}`)
return
}

script.applyCoverage(fixture.coverageV8.functions)

let coverageIstanbul = script.toIstanbul()
Expand Down