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: SourceMap Not Linked When Enabled #1120 #1122

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/cli-main.ts
Original file line number Diff line number Diff line change
@@ -43,8 +43,8 @@ export async function main(options: Options = {}) {
'Generate declaration file (experimental)'
)
.option(
'--sourcemap [inline]',
'Generate external sourcemap, or inline source: --sourcemap inline'
'--sourcemap [type]',
'Generate a sourcemap, defaults to `external` or use a valid esbuild sourcemap type: `--sourcemap linked | inline | external | both`'
)
.option(
'--watch [path]',
7 changes: 6 additions & 1 deletion src/esbuild/index.ts
Original file line number Diff line number Diff line change
@@ -149,6 +149,11 @@ export async function runEsbuild(
...(options.esbuildPlugins || []),
]

const sourcemap = options.sourcemap === true
? "external"
: typeof options.sourcemap === 'string'
? options.sourcemap
: false;
const banner =
typeof options.banner === 'function'
? options.banner({ format })
@@ -168,7 +173,7 @@ export async function runEsbuild(
globalName: options.globalName,
jsxFactory: options.jsxFactory,
jsxFragment: options.jsxFragment,
sourcemap: options.sourcemap ? 'external' : false,
sourcemap,
target: options.target,
banner,
footer,
2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ export type Options = {
}
dts?: boolean | string | DtsConfig
experimentalDts?: boolean | string | ExperimentalDtsConfig
sourcemap?: boolean | 'inline'
sourcemap?: boolean | 'linked' | 'inline' | 'external' | 'both'
/** Always bundle modules matching given patterns */
noExternal?: (string | RegExp)[]
/** Don't bundle these modules */
5 changes: 4 additions & 1 deletion src/plugins/swc-target.ts
Original file line number Diff line number Diff line change
@@ -34,10 +34,13 @@ export const swcTarget = (): Plugin => {
`@swc/core is required for ${target} target. Please install it with \`npm install @swc/core -D\``
)
}
const sourceMaps = typeof this.options.sourcemap === 'string'
? this.options.sourcemap === 'inline' ? 'inline' : true
: this.options.sourcemap;

const result = await swc.transform(code, {
filename: info.path,
sourceMaps: this.options.sourcemap,
sourceMaps,
minify: Boolean(this.options.minify),
jsc: {
target,
59 changes: 58 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
@@ -198,8 +198,19 @@ test('enable --dts-resolve for specific module', async () => {
expect(content).toMatchSnapshot()
})

test('bundle graphql-tools without sourcemaps', async () => {
const { output, outFiles } = await run(
getTestName(),
{
'input.ts': `export { makeExecutableSchema } from 'graphql-tools'`,
}
)
expect(output).not.toContain('//# sourceMappingURL')
expect(outFiles).toEqual(['input.js'])
})

test('bundle graphql-tools with --sourcemap flag', async () => {
const { outFiles } = await run(
const { output, outFiles } = await run(
getTestName(),
{
'input.ts': `export { makeExecutableSchema } from 'graphql-tools'`,
@@ -208,6 +219,22 @@ test('bundle graphql-tools with --sourcemap flag', async () => {
flags: ['--sourcemap'],
}
)
expect(output).toContain('//# sourceMappingURL=input.js.map')
expect(outFiles).toEqual(['input.js', 'input.js.map'])
})

test('bundle graphql-tools with --sourcemap linked flag', async () => {
const { output, outFiles } = await run(
getTestName(),
{
'input.ts': `export { makeExecutableSchema } from 'graphql-tools'`,
},
{
flags: ['--sourcemap', 'linked'],
}
)

expect(output).toContain('//# sourceMappingURL=input.js.map')
expect(outFiles).toEqual(['input.js', 'input.js.map'])
})

@@ -226,6 +253,36 @@ test('bundle graphql-tools with --sourcemap inline flag', async () => {
expect(outFiles).toEqual(['input.js'])
})

test('bundle graphql-tools with --sourcemap external flag', async () => {
const { output, outFiles } = await run(
getTestName(),
{
'input.ts': `export { makeExecutableSchema } from 'graphql-tools'`,
},
{
flags: ['--sourcemap', 'external'],
}
)

expect(output).toContain('//# sourceMappingURL=input.js.map')
expect(outFiles).toEqual(['input.js', 'input.js.map'])
})

test('bundle graphql-tools with --sourcemap both flag', async () => {
const { output, outFiles } = await run(
getTestName(),
{
'input.ts': `export { makeExecutableSchema } from 'graphql-tools'`,
},
{
flags: ['--sourcemap', 'both'],
}
)

expect(output).toContain('//# sourceMappingURL=data:application/json;base64')
expect(outFiles).toEqual(['input.js', 'input.js.map'])
})

test('multiple formats', async () => {
const { output, outFiles } = await run(
getTestName(),