Skip to content

Commit

Permalink
Always prepend the license comment (#11476)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
RobinMalfait committed Jun 22, 2023
1 parent a2196b0 commit 9f591a5
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 356 deletions.
3 changes: 2 additions & 1 deletion integrations/tailwindcss-cli/tests/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ describe('Build command', () => {
// This contains --webkit-user-select which may be strange, but it is expected because we are
// not handling the `--no-autoprefixer` flag anymore at all.
expect(withoutAutoprefixer).toMatchInlineSnapshot(`
".select-none {
"/* ! tailwindcss v3.3.2 | MIT License | https://tailwindcss.com */
.select-none {
-webkit-user-select: none;
user-select: none;
}
Expand Down
10 changes: 10 additions & 0 deletions jest/customMatchers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const prettier = require('prettier')
const { diff } = require('jest-diff')
const log = require('../src/util/log').default
const { version } = require('../package.json')

function license() {
return `/* ! tailwindcss v${version} | MIT License | https://tailwindcss.com */\n`
}

let warn

Expand Down Expand Up @@ -31,6 +36,11 @@ function toMatchFormattedCss(received = '', argument = '') {
promise: this.promise,
}

// Drop the license from the tests such that we can purely focus on the actual CSS being
// generated.
received = received.replace(license(), '')
argument = argument.replace(license(), '')

let formattedReceived = format(received)
let formattedArgument = format(argument)

Expand Down
8 changes: 6 additions & 2 deletions src/cli/build/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import { validateConfig } from '../../util/validateConfig'
import { handleImportAtRules } from '../../lib/handleImportAtRules'
import { flagEnabled } from '../../featureFlags'

function license() {
return `/* ! tailwindcss v${pkg.version} | MIT License | https://tailwindcss.com */\n`
}

async function lightningcss(result, { map = true, minify = true } = {}) {
try {
let resolvedBrowsersListConfig = browserslist.findConfig(
Expand Down Expand Up @@ -377,12 +381,12 @@ export async function createProcessor(args, cliConfigPath) {
})
.then((result) => {
if (!output) {
process.stdout.write(result.css)
process.stdout.write(license() + result.css)
return
}

return Promise.all([
outputFile(result.opts.to, result.css),
outputFile(result.opts.to, license() + result.css),
result.map && outputFile(result.opts.to + '.map', result.map.toString()),
])
})
Expand Down
8 changes: 1 addition & 7 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import withAlphaVariable, { withAlphaValue } from './util/withAlphaVariable'
import toColorValue from './util/toColorValue'
import isPlainObject from './util/isPlainObject'
import transformThemeValue from './util/transformThemeValue'
import { version as tailwindVersion } from '../package.json'
import log from './util/log'
import {
normalizeScreens,
Expand Down Expand Up @@ -496,12 +495,7 @@ export let corePlugins = {
fs.readFileSync(path.join(__dirname, './css/preflight.css'), 'utf8')
)

addBase([
postcss.comment({
text: `! tailwindcss v${tailwindVersion} | MIT License | https://tailwindcss.com`,
}),
...preflightStyles.nodes,
])
addBase(preflightStyles.nodes)
},

container: (() => {
Expand Down
7 changes: 6 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import processTailwindFeatures from './processTailwindFeatures'
import { env } from './lib/sharedState'
import { findAtConfigPath } from './lib/findAtConfigPath'
import { handleImportAtRules } from './lib/handleImportAtRules'
import { version as tailwindVersion } from '../package.json'

function license() {
return `/* ! tailwindcss v${tailwindVersion} | MIT License | https://tailwindcss.com */\n`
}

module.exports = function tailwindcss(configOrPath) {
return {
Expand Down Expand Up @@ -87,7 +92,7 @@ module.exports = function tailwindcss(configOrPath) {
}
}

result.root = postcss.parse(code, {
result.root = postcss.parse(license() + code, {
...result.opts,
map: intermediateMap,
})
Expand Down

0 comments on commit 9f591a5

Please sign in to comment.