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

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a4cd44d
Cleanup code a bit
thecrypticace Apr 3, 2025
68ce361
Return resolved path in `loadStylesheet` and `loadModule`
thecrypticace Apr 18, 2025
c53f344
Skip over the CR in CRLF when parsing CSS
thecrypticace Apr 29, 2025
e7652b7
Check for CRLF when scanning consecutive whitespace
thecrypticace Apr 29, 2025
da86e23
Handle CRLF in strings
thecrypticace Apr 29, 2025
65409a9
Don’t replace CRLF with LF before parsing CSS
thecrypticace Apr 29, 2025
8319bd8
Update CSS parser tests to preserve CRLF where needed
thecrypticace Apr 29, 2025
f08f89d
Track source locations in the AST
thecrypticace Apr 16, 2025
e95e6e2
Track locations when parsing
thecrypticace Apr 16, 2025
c129f48
Track locations inside `@import`
thecrypticace Apr 3, 2025
3bc80cd
Track wrapping at-rules created by imports
thecrypticace Apr 18, 2025
3143eb6
Track theme variables
thecrypticace Apr 16, 2025
386e721
Track generated utilities
thecrypticace Apr 16, 2025
fcd4e2d
Track locations when optimizing
thecrypticace Apr 16, 2025
6febfd9
Track locations when printing
thecrypticace Apr 16, 2025
6b9ace2
Track utilities generated by `@apply`
thecrypticace Apr 16, 2025
9a9b47a
Track utilities per-candidate in `@apply`
thecrypticace Apr 16, 2025
a0a9a33
Use offset information to generate source maps
thecrypticace Jan 13, 2025
b191165
Prep for source maps in build tools
thecrypticace Apr 29, 2025
2302668
Add integration test helpers for source maps
thecrypticace Apr 29, 2025
acf5f31
Update source maps when optimizing output CSS
thecrypticace Apr 29, 2025
2f25e3e
Add source map support to the CLI
thecrypticace Apr 29, 2025
bb78c59
Add source map support to Vite
thecrypticace Apr 29, 2025
00358d0
Add source map support to PostCSS
thecrypticace Apr 3, 2025
502bda7
Update lockfile
thecrypticace Apr 16, 2025
c9cb8a7
Fix UI tests
thecrypticace May 5, 2025
65e2c17
Optimize `LineTable#find` implementation
thecrypticace May 6, 2025
5e2fd98
Don’t double clone nodes
thecrypticace May 6, 2025
2e8d099
Move walk into map fn
thecrypticace May 6, 2025
78915dc
Remove leftover logs
thecrypticace May 6, 2025
db5d974
Fix typo
thecrypticace May 6, 2025
8fdb8ba
Increment unknown source ID when generating maps
thecrypticace May 6, 2025
1992ba5
Add comment clarifying magic number
thecrypticace May 6, 2025
58932d5
Inline function to push mappings
thecrypticace May 6, 2025
e3561fb
Update type
thecrypticace May 6, 2025
347d9e2
Remove unncessary settings from test
thecrypticace May 7, 2025
f3fc813
Add line table benchmark
thecrypticace May 7, 2025
83e2cd2
Clarify perf comment
thecrypticace May 7, 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
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