Skip to content

Commit 9f591a5

Browse files
authored
Always prepend the license comment (#11476)
* always prepend the Tailwind License Even when you are not using preflight. * drop the Tailwind License from the preflight plugin * drop the license in the tests This allows us to focus on the actual generated CSS without the license. The license also includes the version number which we would have to update every time we release a new version. * update the source maps snapshots * always prepend the license when using the CLI * update Tailwind CLI integration test
1 parent a2196b0 commit 9f591a5

File tree

6 files changed

+376
-356
lines changed

6 files changed

+376
-356
lines changed

integrations/tailwindcss-cli/tests/cli.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ describe('Build command', () => {
120120
// This contains --webkit-user-select which may be strange, but it is expected because we are
121121
// not handling the `--no-autoprefixer` flag anymore at all.
122122
expect(withoutAutoprefixer).toMatchInlineSnapshot(`
123-
".select-none {
123+
"/* ! tailwindcss v3.3.2 | MIT License | https://tailwindcss.com */
124+
.select-none {
124125
-webkit-user-select: none;
125126
user-select: none;
126127
}

jest/customMatchers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const prettier = require('prettier')
22
const { diff } = require('jest-diff')
33
const log = require('../src/util/log').default
4+
const { version } = require('../package.json')
5+
6+
function license() {
7+
return `/* ! tailwindcss v${version} | MIT License | https://tailwindcss.com */\n`
8+
}
49

510
let warn
611

@@ -31,6 +36,11 @@ function toMatchFormattedCss(received = '', argument = '') {
3136
promise: this.promise,
3237
}
3338

39+
// Drop the license from the tests such that we can purely focus on the actual CSS being
40+
// generated.
41+
received = received.replace(license(), '')
42+
argument = argument.replace(license(), '')
43+
3444
let formattedReceived = format(received)
3545
let formattedArgument = format(argument)
3646

src/cli/build/plugin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ import { validateConfig } from '../../util/validateConfig'
2626
import { handleImportAtRules } from '../../lib/handleImportAtRules'
2727
import { flagEnabled } from '../../featureFlags'
2828

29+
function license() {
30+
return `/* ! tailwindcss v${pkg.version} | MIT License | https://tailwindcss.com */\n`
31+
}
32+
2933
async function lightningcss(result, { map = true, minify = true } = {}) {
3034
try {
3135
let resolvedBrowsersListConfig = browserslist.findConfig(
@@ -377,12 +381,12 @@ export async function createProcessor(args, cliConfigPath) {
377381
})
378382
.then((result) => {
379383
if (!output) {
380-
process.stdout.write(result.css)
384+
process.stdout.write(license() + result.css)
381385
return
382386
}
383387

384388
return Promise.all([
385-
outputFile(result.opts.to, result.css),
389+
outputFile(result.opts.to, license() + result.css),
386390
result.map && outputFile(result.opts.to + '.map', result.map.toString()),
387391
])
388392
})

src/corePlugins.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import withAlphaVariable, { withAlphaValue } from './util/withAlphaVariable'
1010
import toColorValue from './util/toColorValue'
1111
import isPlainObject from './util/isPlainObject'
1212
import transformThemeValue from './util/transformThemeValue'
13-
import { version as tailwindVersion } from '../package.json'
1413
import log from './util/log'
1514
import {
1615
normalizeScreens,
@@ -496,12 +495,7 @@ export let corePlugins = {
496495
fs.readFileSync(path.join(__dirname, './css/preflight.css'), 'utf8')
497496
)
498497

499-
addBase([
500-
postcss.comment({
501-
text: `! tailwindcss v${tailwindVersion} | MIT License | https://tailwindcss.com`,
502-
}),
503-
...preflightStyles.nodes,
504-
])
498+
addBase(preflightStyles.nodes)
505499
},
506500

507501
container: (() => {

src/plugin.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import processTailwindFeatures from './processTailwindFeatures'
66
import { env } from './lib/sharedState'
77
import { findAtConfigPath } from './lib/findAtConfigPath'
88
import { handleImportAtRules } from './lib/handleImportAtRules'
9+
import { version as tailwindVersion } from '../package.json'
10+
11+
function license() {
12+
return `/* ! tailwindcss v${tailwindVersion} | MIT License | https://tailwindcss.com */\n`
13+
}
914

1015
module.exports = function tailwindcss(configOrPath) {
1116
return {
@@ -87,7 +92,7 @@ module.exports = function tailwindcss(configOrPath) {
8792
}
8893
}
8994

90-
result.root = postcss.parse(code, {
95+
result.root = postcss.parse(license() + code, {
9196
...result.opts,
9297
map: intermediateMap,
9398
})

0 commit comments

Comments
 (0)