From cf5cd42c480bf7fa44483418388a201f864b856b Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 15 Dec 2025 13:14:00 -0500 Subject: [PATCH 1/5] Refactor --- packages/@tailwindcss-node/src/source-maps.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/@tailwindcss-node/src/source-maps.ts b/packages/@tailwindcss-node/src/source-maps.ts index 3f02efb24c00..211f39a6411a 100644 --- a/packages/@tailwindcss-node/src/source-maps.ts +++ b/packages/@tailwindcss-node/src/source-maps.ts @@ -44,16 +44,15 @@ function serializeSourceMap(map: DecodedSourceMap): string { export function toSourceMap(map: DecodedSourceMap | string): SourceMap { let raw = typeof map === 'string' ? map : serializeSourceMap(map) + function comment(url: string) { + return `/*# sourceMappingURL=${url} */\n` + } + return { raw, get inline() { - let tmp = '' - - tmp += '/*# sourceMappingURL=data:application/json;base64,' - tmp += Buffer.from(raw, 'utf-8').toString('base64') - tmp += ' */\n' - - return tmp + let inlined = Buffer.from(raw, 'utf-8').toString('base64') + return comment(`data:application/json;base64,${inlined}`) }, } } From ef47a2df82f290a9d6b9f6c449d33e55d78aa7a9 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 15 Dec 2025 13:14:21 -0500 Subject: [PATCH 2/5] Add comment when saving source maps to files --- .../@tailwindcss-cli/src/commands/build/index.ts | 12 ++++++++++++ packages/@tailwindcss-node/src/source-maps.ts | 2 ++ 2 files changed, 14 insertions(+) diff --git a/packages/@tailwindcss-cli/src/commands/build/index.ts b/packages/@tailwindcss-cli/src/commands/build/index.ts index f0d441fe2d99..eabd2a1de022 100644 --- a/packages/@tailwindcss-cli/src/commands/build/index.ts +++ b/packages/@tailwindcss-cli/src/commands/build/index.ts @@ -182,6 +182,18 @@ export async function handle(args: Result>) { output += `\n` output += map.inline } else if (typeof args['--map'] === 'string') { + let basePath = + args['--output'] && args['--output'] !== '-' + ? path.dirname(path.resolve(args['--output'])) + : process.cwd() + + let mapPath = path.resolve(args['--map']) + + let relativePath = path.relative(basePath, mapPath) + + output += `\n` + output += map.comment(relativePath) + DEBUG && I.start('Write source map') await outputFile(args['--map'], map.raw) DEBUG && I.end('Write source map') diff --git a/packages/@tailwindcss-node/src/source-maps.ts b/packages/@tailwindcss-node/src/source-maps.ts index 211f39a6411a..8810b106c5ef 100644 --- a/packages/@tailwindcss-node/src/source-maps.ts +++ b/packages/@tailwindcss-node/src/source-maps.ts @@ -6,6 +6,7 @@ export type { DecodedSource, DecodedSourceMap } export interface SourceMap { readonly raw: string readonly inline: string + comment(url: string): string } function serializeSourceMap(map: DecodedSourceMap): string { @@ -54,5 +55,6 @@ export function toSourceMap(map: DecodedSourceMap | string): SourceMap { let inlined = Buffer.from(raw, 'utf-8').toString('base64') return comment(`data:application/json;base64,${inlined}`) }, + comment, } } From 1aa51d66c6237602f3e720f062e7d7bf7ad170c5 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 15 Dec 2025 14:19:56 -0500 Subject: [PATCH 3/5] wip --- integrations/cli/index.test.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/integrations/cli/index.test.ts b/integrations/cli/index.test.ts index 870a1baec3a9..0db56d39894d 100644 --- a/integrations/cli/index.test.ts +++ b/integrations/cli/index.test.ts @@ -752,7 +752,7 @@ describe.each([ expect(map.at(4, 0)).toMatchObject({ source: null, original: '(none)', - generated: '}...', + generated: '}\n\n/*# sou...', }) }, ) @@ -786,7 +786,10 @@ describe.each([ await fs.expectFileToContain('dist/out.css', [candidate`flex`]) // Make sure we can find a source map - let map = parseSourceMap(await fs.read('dist/out.css')) + let map = parseSourceMap({ + filepath: 'dist/out.css', + content: await fs.read('dist/out.css'), + }) expect(map.at(1, 0)).toMatchObject({ source: null, @@ -815,7 +818,7 @@ describe.each([ expect(map.at(4, 0)).toMatchObject({ source: null, original: '(none)', - generated: '}...', + generated: '}\n\n/*# sou...', }) }, ) @@ -1118,7 +1121,7 @@ describe.each([ expect(map.at(4, 0)).toMatchObject({ source: null, original: '(none)', - generated: '}...', + generated: '}\n\n/*# sou...', }) // Write to project source files @@ -1190,7 +1193,7 @@ describe.each([ expect(map.at(7, 0)).toMatchObject({ source: null, original: '(none)', - generated: '}...', + generated: '}\n\n/*# sou...', }) // Write to the main CSS file @@ -1290,7 +1293,7 @@ describe.each([ expect(map.at(10, 0)).toMatchObject({ source: null, original: '(none)', - generated: '}...', + generated: '}\n\n/*# sou...', }) }, ) From 075f2340e3a462fd3602636abdfdb2f4fce57cde Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 15 Dec 2025 15:35:37 -0500 Subject: [PATCH 4/5] fix --- integrations/cli/index.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/integrations/cli/index.test.ts b/integrations/cli/index.test.ts index 0db56d39894d..409a9de7cd41 100644 --- a/integrations/cli/index.test.ts +++ b/integrations/cli/index.test.ts @@ -786,10 +786,7 @@ describe.each([ await fs.expectFileToContain('dist/out.css', [candidate`flex`]) // Make sure we can find a source map - let map = parseSourceMap({ - filepath: 'dist/out.css', - content: await fs.read('dist/out.css'), - }) + let map = parseSourceMap(await fs.read('dist/out.css')) expect(map.at(1, 0)).toMatchObject({ source: null, From e0c81cd5d53de7e38aef778d5b8da5210404b438 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 18 Dec 2025 14:39:08 -0500 Subject: [PATCH 5/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be8ec9aef242..b776a93e522c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Do not wrap `color-mix` in a `@supports` rule if one already exists ([#19450](https://github.com/tailwindlabs/tailwindcss/pull/19450)) - Allow whitespace around `@source inline()` argument ([#19461](https://github.com/tailwindlabs/tailwindcss/pull/19461)) +- CLI: Emit comment when source maps are saved to files ([#19447](https://github.com/tailwindlabs/tailwindcss/pull/19447)) ### Added