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

move from source-map to source-map-sync #11070

Closed
wants to merge 2 commits into from
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
6 changes: 4 additions & 2 deletions e2e/coverage-handlebars/transform-handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
*/

const Handlebars = require('handlebars/dist/cjs/handlebars.js');
const {SourceMapConsumer, SourceNode} = require('source-map');
const {SourceMapConsumer, SourceNode} = require('source-map-sync');

exports.process = (code, filename) => {
const pc = Handlebars.precompile(code, {srcName: filename});
const consumer = new SourceMapConsumer(pc.map);
const out = new SourceNode(null, null, null, [
'const Handlebars = require("handlebars/dist/cjs/handlebars.runtime.js");\n',
'module.exports = Handlebars.template(',
SourceNode.fromStringWithSourceMap(pc.code, new SourceMapConsumer(pc.map)),
SourceNode.fromStringWithSourceMap(pc.code, consumer),
');\n',
]).toStringWithSourceMap();
consumer.destroy();
return {code: out.code, map: out.map.toString()};
};
1 change: 1 addition & 0 deletions packages/jest-jasmine2/src/jasmine/Spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type SpecResult = {
pendingReason: string;
status: Status;
__callsite?: {
destroy: () => void;
getColumnNumber: () => number;
getLineNumber: () => number;
};
Expand Down
1 change: 1 addition & 0 deletions packages/jest-jasmine2/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export default class Jasmine2Reporter implements Reporter {
line: specResult.__callsite.getLineNumber(),
}
: null;
if (specResult.__callsite) specResult.__callsite.destroy();
const results: AssertionResult = {
ancestorTitles,
duration,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-reporters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"jest-util": "^27.0.0-next.1",
"jest-worker": "^27.0.0-next.2",
"slash": "^3.0.0",
"source-map": "^0.6.0",
"source-map-sync": "^0.8.0-beta.1",
"string-length": "^4.0.1",
"terminal-link": "^2.0.0",
"v8-to-istanbul": "^7.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-reporters/src/CoverageReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import istanbulCoverage = require('istanbul-lib-coverage');
import istanbulReport = require('istanbul-lib-report');
import libSourceMaps = require('istanbul-lib-source-maps');
import istanbulReports = require('istanbul-reports');
import type {RawSourceMap} from 'source-map';
import type {RawSourceMap} from 'source-map-sync';
import v8toIstanbul = require('v8-to-istanbul');
import type {
AggregatedResult,
Expand All @@ -35,7 +35,7 @@ import type {
} from './types';

// This is fixed in a newer versions of source-map, but our dependencies are still stuck on old versions
interface FixedRawSourceMap extends Omit<RawSourceMap, 'version'> {
interface FixedRawSourceMap extends Omit<RawSourceMap, 'version' | 'file'> {
version: number;
file?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-source-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"callsites": "^3.0.0",
"graceful-fs": "^4.2.4",
"source-map": "^0.6.0"
"source-map-sync": "^0.8.0-beta.1"
},
"devDependencies": {
"@types/graceful-fs": "^4.1.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-source-map/src/__tests__/getCallsite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import * as fs from 'graceful-fs';
import SourceMap from 'source-map';
import SourceMap from 'source-map-sync';
import getCallsite from '../getCallsite';

// Node 10.5.x compatibility
Expand Down
10 changes: 7 additions & 3 deletions packages/jest-source-map/src/getCallsite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import callsites = require('callsites');
import {readFileSync} from 'graceful-fs';
import {SourceMapConsumer} from 'source-map';
import {SourceMapConsumer} from 'source-map-sync';
import type {SourceMapRegistry} from './types';

// Copied from https://github.com/rexxars/sourcemap-decorate-callsites/blob/5b9735a156964973a75dc62fd2c7f0c1975458e8/lib/index.js#L113-L158
Expand All @@ -26,11 +26,16 @@ const addSourceMapConsumer = (
line: getLineNumber.call(callsite) || -1,
});
}

return position;
}

Object.defineProperties(callsite, {
destroy: {
value() {
consumer.destroy();
},
writable: false,
},
getColumnNumber: {
value() {
return getPosition().column || getColumnNumber.call(callsite);
Expand All @@ -57,7 +62,6 @@ export default (
if (sourceMapFileName) {
try {
const sourceMap = readFileSync(sourceMapFileName, 'utf8');
// @ts-expect-error: Not allowed to pass string
addSourceMapConsumer(stack, new SourceMapConsumer(sourceMap));
} catch {
// ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"micromatch": "^4.0.2",
"pirates": "^4.0.1",
"slash": "^3.0.0",
"source-map": "^0.6.1",
"source-map-sync": "^0.8.0-beta.1",
"write-file-atomic": "^3.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-transform/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import type {RawSourceMap} from 'source-map';
import type {RawSourceMap} from 'source-map-sync';
import type {Config, TransformTypes} from '@jest/types';

export type ShouldInstrumentOptions = Pick<
Expand Down
15 changes: 12 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ __metadata:
jest-worker: ^27.0.0-next.2
mock-fs: ^4.4.1
slash: ^3.0.0
source-map: ^0.6.0
source-map-sync: ^0.8.0-beta.1
string-length: ^4.0.1
strip-ansi: ^6.0.0
terminal-link: ^2.0.0
Expand All @@ -2027,7 +2027,7 @@ __metadata:
"@types/graceful-fs": ^4.1.2
callsites: ^3.0.0
graceful-fs: ^4.2.4
source-map: ^0.6.0
source-map-sync: ^0.8.0-beta.1
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -2130,7 +2130,7 @@ __metadata:
micromatch: ^4.0.2
pirates: ^4.0.1
slash: ^3.0.0
source-map: ^0.6.1
source-map-sync: ^0.8.0-beta.1
write-file-atomic: ^3.0.0
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -18102,6 +18102,15 @@ react-native@0.63.2:
languageName: node
linkType: hard

"source-map-sync@npm:^0.8.0-beta.1":
version: 0.8.0-beta.1
resolution: "source-map-sync@npm:0.8.0-beta.1"
dependencies:
whatwg-url: ^7.0.0
checksum: a45bf3b3075404b80794a890f43addd75d0eb1d7c2694f6d9c60284e5942945d051e66b13de6a7f13be5e99ca8b0b775ec334aff347a8a02cd21afc8b08268c2
languageName: node
linkType: hard

"source-map-url@npm:^0.4.0":
version: 0.4.0
resolution: "source-map-url@npm:0.4.0"
Expand Down