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

Redirect source-map-support to @cspotcode/source-map-support #1496

Merged
merged 2 commits into from Oct 10, 2021
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
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -10,3 +10,4 @@ tests/main-realpath/symlink/tsconfig.json
tests/throw error.ts
tests/throw error react tsx.tsx
tests/esm/throw error.ts
tests/legacy-source-map-support-interop/index.ts
16 changes: 13 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -152,7 +152,7 @@
}
},
"dependencies": {
"@cspotcode/source-map-support": "0.6.1",
"@cspotcode/source-map-support": "github:cspotcode/node-source-map-support",
"@tsconfig/node10": "^1.0.7",
"@tsconfig/node12": "^1.0.7",
"@tsconfig/node14": "^1.0.0",
Expand Down
14 changes: 14 additions & 0 deletions src/index.ts
Expand Up @@ -677,6 +677,20 @@ export function create(rawOptions: CreateOptions = {}): Service {
path = normalizeSlashes(path);
return outputCache.get(path)?.content || '';
},
redirectConflictingLibrary: true,
onConflictingLibraryRedirect(
request,
parent,
isMain,
options,
redirectedRequest
) {
debug(
`Redirected an attempt to require source-map-support to instead receive @cspotcode/source-map-support. "${
(parent as NodeJS.Module).filename
}" attempted to require or resolve "${request}" and was redirected to "${redirectedRequest}".`
);
},
});

const shouldHavePrettyErrors =
Expand Down
30 changes: 30 additions & 0 deletions src/test/sourcemaps.spec.ts
@@ -0,0 +1,30 @@
import * as expect from 'expect';
import { createExec, createExecTester } from './exec-helpers';
import {
CMD_TS_NODE_WITH_PROJECT_FLAG,
contextTsNodeUnderTest,
TEST_DIR,
} from './helpers';
import { test as _test } from './testlib';
const test = _test.context(contextTsNodeUnderTest);

const exec = createExecTester({
cmd: CMD_TS_NODE_WITH_PROJECT_FLAG,
exec: createExec({
cwd: TEST_DIR,
}),
});

test('Redirects source-map-support to @cspotcode/source-map-support so that third-party libraries get correct source-mapped locations', async () => {
const { stdout } = await exec({
flags: `./legacy-source-map-support-interop/index.ts`,
});
expect(stdout.split('\n')).toMatchObject([
expect.stringContaining('.ts:2 '),
'true',
'true',
expect.stringContaining('.ts:100:'),
expect.stringContaining('.ts:101 '),
'',
]);
});
101 changes: 101 additions & 0 deletions tests/legacy-source-map-support-interop/index.ts
@@ -0,0 +1,101 @@
import { Logger } from 'tslog';
new Logger().info('hi');
console.log(require.resolve('source-map-support') === require.resolve('@cspotcode/source-map-support'));
console.log(require.resolve('source-map-support/register') === require.resolve('@cspotcode/source-map-support/register'));
/*
tslog uses `require('source-map-support').wrapCallSite` directly.
Without redirection to @cspotcode/source-map-support it does not have access to the sourcemap information we provide.
*/
interface Foo {

























































































}
console.log(new Error().stack!.split('\n')[1]);
new Logger().info('hi');
3 changes: 2 additions & 1 deletion tests/package.json
@@ -1,6 +1,7 @@
{
"dependencies": {
"@swc/core": "latest",
"ts-node": "file:ts-node-packed.tgz"
"ts-node": "file:ts-node-packed.tgz",
"tslog": "3.2.2"
}
}