Skip to content

Add support for source maps #17775

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

Merged
merged 40 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
149a177
Cleanup code a bit
thecrypticace Apr 3, 2025
6496bf7
Return resolved path in `loadStylesheet` and `loadModule`
thecrypticace Apr 18, 2025
8268c1d
Skip over the CR in CRLF when parsing CSS
thecrypticace Apr 29, 2025
e78d8e8
Check for CRLF when scanning consecutive whitespace
thecrypticace Apr 29, 2025
8123229
Handle CRLF in strings
thecrypticace Apr 29, 2025
e25dc9c
Don’t replace CRLF with LF before parsing CSS
thecrypticace Apr 29, 2025
d3e1f20
Update CSS parser tests to preserve CRLF where needed
thecrypticace Apr 29, 2025
0a0bf32
Track source locations in the AST
thecrypticace Apr 16, 2025
fc92c11
Track locations when parsing
thecrypticace Apr 16, 2025
65605e7
Track locations inside `@import`
thecrypticace Apr 3, 2025
47e8cac
Track wrapping at-rules created by imports
thecrypticace Apr 18, 2025
445d7a5
Track theme variables
thecrypticace Apr 16, 2025
cc5ef4b
Track generated utilities
thecrypticace Apr 16, 2025
f82d83e
Track locations when optimizing
thecrypticace Apr 16, 2025
9fcace1
Track locations when printing
thecrypticace Apr 16, 2025
4a905ad
Track utilities generated by `@apply`
thecrypticace Apr 16, 2025
81d0a61
Track utilities per-candidate in `@apply`
thecrypticace Apr 16, 2025
08cf666
Use offset information to generate source maps
thecrypticace Jan 13, 2025
b9a87a1
Prep for source maps in build tools
thecrypticace Apr 29, 2025
acd6b9c
Add integration test helpers for source maps
thecrypticace Apr 29, 2025
1c5d45b
Update source maps when optimizing output CSS
thecrypticace Apr 29, 2025
111a84b
Add source map support to the CLI
thecrypticace Apr 29, 2025
cd2421f
Add source map support to Vite
thecrypticace Apr 29, 2025
05de7e6
Add source map support to PostCSS
thecrypticace Apr 3, 2025
4ca30bc
Update lockfile
thecrypticace Apr 16, 2025
1b5937f
Fix UI tests
thecrypticace May 5, 2025
7325ec8
Optimize `LineTable#find` implementation
thecrypticace May 6, 2025
e2bc28e
Don’t double clone nodes
thecrypticace May 6, 2025
f258940
Move walk into map fn
thecrypticace May 6, 2025
e2b7fa9
Remove leftover logs
thecrypticace May 6, 2025
49df6af
Fix typo
thecrypticace May 6, 2025
781d5ec
Increment unknown source ID when generating maps
thecrypticace May 6, 2025
a6537f0
Add comment clarifying magic number
thecrypticace May 6, 2025
b5b16e4
Inline function to push mappings
thecrypticace May 6, 2025
9e67260
Update type
thecrypticace May 6, 2025
3b05163
Remove unncessary settings from test
thecrypticace May 7, 2025
f9c03c0
Add line table benchmark
thecrypticace May 7, 2025
69cfef1
Clarify perf comment
thecrypticace May 7, 2025
4b1ee96
Update CLI error printing
thecrypticace May 8, 2025
bffe8fe
Update changelog
thecrypticace May 8, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Upgrade: Automatically convert candidates with arbitrary values to their utilities ([#17831](https://github.com/tailwindlabs/tailwindcss/pull/17831), [#17854](https://github.com/tailwindlabs/tailwindcss/pull/17854))
- Write to log file when using `DEBUG=*` ([#17906](https://github.com/tailwindlabs/tailwindcss/pull/17906))
- Add support for source maps in development ([#17775](https://github.com/tailwindlabs/tailwindcss/pull/17775))

### Fixed

Expand Down
190 changes: 189 additions & 1 deletion integrations/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe.each([
'Standalone CLI',
path.resolve(__dirname, `../../packages/@tailwindcss-standalone/dist/${STANDALONE_BINARY}`),
],
])('%s', (_, command) => {
])('%s', (kind, command) => {
test(
'production build',
{
Expand Down Expand Up @@ -628,6 +628,194 @@ describe.each([
])
},
)

test(
'production build + inline source maps',
{
fs: {
'package.json': json`
{
"dependencies": {
"tailwindcss": "workspace:^",
"@tailwindcss/cli": "workspace:^"
}
}
`,
'ssrc/index.html': html`
<div class="flex"></div>
`,
'src/index.css': css`
@import 'tailwindcss/utilities';
/* */
`,
},
},
async ({ exec, expect, fs, parseSourceMap }) => {
await exec(`${command} --input src/index.css --output dist/out.css --map`)

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'))

expect(map.at(1, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '/*! tailwi...',
})

expect(map.at(2, 0)).toMatchObject({
source:
kind === 'CLI'
? expect.stringContaining('node_modules/tailwindcss/utilities.css')
: expect.stringMatching(/\/utilities-\w+\.css$/),
original: '@tailwind...',
generated: '.flex {...',
})

expect(map.at(3, 2)).toMatchObject({
source:
kind === 'CLI'
? expect.stringContaining('node_modules/tailwindcss/utilities.css')
: expect.stringMatching(/\/utilities-\w+\.css$/),
original: '@tailwind...',
generated: 'display: f...',
})

expect(map.at(4, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '}...',
})
},
)

test(
'production build + separate source maps',
{
fs: {
'package.json': json`
{
"dependencies": {
"tailwindcss": "workspace:^",
"@tailwindcss/cli": "workspace:^"
}
}
`,
'ssrc/index.html': html`
<div class="flex"></div>
`,
'src/index.css': css`
@import 'tailwindcss/utilities';
/* */
`,
},
},
async ({ exec, expect, fs, parseSourceMap }) => {
await exec(`${command} --input src/index.css --output dist/out.css --map dist/out.css.map`)

await fs.expectFileToContain('dist/out.css', [candidate`flex`])

// Make sure we can find a source map
let map = parseSourceMap({
map: await fs.read('dist/out.css.map'),
content: await fs.read('dist/out.css'),
})

expect(map.at(1, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '/*! tailwi...',
})

expect(map.at(2, 0)).toMatchObject({
source:
kind === 'CLI'
? expect.stringContaining('node_modules/tailwindcss/utilities.css')
: expect.stringMatching(/\/utilities-\w+\.css$/),
original: '@tailwind...',
generated: '.flex {...',
})

expect(map.at(3, 2)).toMatchObject({
source:
kind === 'CLI'
? expect.stringContaining('node_modules/tailwindcss/utilities.css')
: expect.stringMatching(/\/utilities-\w+\.css$/),
original: '@tailwind...',
generated: 'display: f...',
})

expect(map.at(4, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '}...',
})
},
)

// Skipped because Lightning CSS has a bug with source maps containing
// license comments and it breaks stuff.
test.skip(
'production build + minify + source maps',
{
fs: {
'package.json': json`
{
"dependencies": {
"tailwindcss": "workspace:^",
"@tailwindcss/cli": "workspace:^"
}
}
`,
'ssrc/index.html': html`
<div class="flex"></div>
`,
'src/index.css': css`
@import 'tailwindcss/utilities';
/* */
`,
},
},
async ({ exec, expect, fs, parseSourceMap }) => {
await exec(`${command} --input src/index.css --output dist/out.css --minify --map`)

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'))

expect(map.at(1, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '/*! tailwi...',
})

expect(map.at(2, 0)).toMatchObject({
source:
kind === 'CLI'
? expect.stringContaining('node_modules/tailwindcss/utilities.css')
: expect.stringMatching(/\/utilities-\w+\.css$/),
original: '@tailwind...',
generated: '.flex {...',
})

expect(map.at(3, 2)).toMatchObject({
source:
kind === 'CLI'
? expect.stringContaining('node_modules/tailwindcss/utilities.css')
: expect.stringMatching(/\/utilities-\w+\.css$/),
original: '@tailwind...',
generated: 'display: f...',
})

expect(map.at(4, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '}...',
})
},
)
})

test(
Expand Down
3 changes: 2 additions & 1 deletion integrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"devDependencies": {
"dedent": "1.5.3",
"fast-glob": "^3.3.3"
"fast-glob": "^3.3.3",
"source-map-js": "^1.2.1"
}
}
65 changes: 65 additions & 0 deletions integrations/postcss/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,68 @@ test(
await retryAssertion(async () => expect(await fs.read('dist/out.css')).toEqual(''))
},
)

test(
'dev mode + source maps',
{
fs: {
'package.json': json`
{
"dependencies": {
"postcss": "^8",
"postcss-cli": "^11",
"tailwindcss": "workspace:^",
"@tailwindcss/postcss": "workspace:^"
}
}
`,
'postcss.config.js': js`
module.exports = {
map: { inline: true },
plugins: {
'@tailwindcss/postcss': {},
},
}
`,
'src/index.html': html`
<div class="flex"></div>
`,
'src/index.css': css`
@import 'tailwindcss/utilities';
@source not inline("inline");
/* */
`,
},
},
async ({ fs, exec, expect, parseSourceMap }) => {
await exec('pnpm postcss src/index.css --output dist/out.css')

await fs.expectFileToContain('dist/out.css', [candidate`flex`])

let map = parseSourceMap(await fs.read('dist/out.css'))

expect(map.at(1, 0)).toMatchObject({
source: '<no source>',
original: '(none)',
generated: '/*! tailwi...',
})

expect(map.at(2, 0)).toMatchObject({
source: expect.stringContaining('node_modules/tailwindcss/utilities.css'),
original: '@tailwind...',
generated: '.flex {...',
})

expect(map.at(3, 2)).toMatchObject({
source: expect.stringContaining('node_modules/tailwindcss/utilities.css'),
original: '@tailwind...',
generated: 'display: f...',
})

expect(map.at(4, 0)).toMatchObject({
source: expect.stringContaining('node_modules/tailwindcss/utilities.css'),
original: ';...',
generated: '}...',
})
},
)
Loading