Skip to content

Commit

Permalink
Rename @content to @source (#14127)
Browse files Browse the repository at this point in the history
This PR renames the `@content` directive to `@source`.
  • Loading branch information
RobinMalfait committed Aug 7, 2024
1 parent 2424fb5 commit 58d4fa9
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions integrations/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test(
`,
'project-a/src/index.css': css`
@import 'tailwindcss/utilities';
@content '../../project-b/src/**/*.js';
@source '../../project-b/src/**/*.js';
@plugin '../plugin.js';
`,
'project-a/src/index.js': js`
Expand Down Expand Up @@ -91,7 +91,7 @@ test(
`,
'project-a/src/index.css': css`
@import 'tailwindcss/utilities';
@content '../../project-b/src/**/*.js';
@source '../../project-b/src/**/*.js';
@plugin '../plugin.js';
`,
'project-a/src/index.js': js`
Expand Down
4 changes: 2 additions & 2 deletions integrations/postcss/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test(
`,
'project-a/src/index.css': css`
@import 'tailwindcss/utilities';
@content '../../project-b/src/**/*.js';
@source '../../project-b/src/**/*.js';
@plugin '../plugin.js';
`,
'project-a/src/index.js': js`
Expand Down Expand Up @@ -109,7 +109,7 @@ test(
`,
'project-a/src/index.css': css`
@import 'tailwindcss/utilities';
@content '../../project-b/src/**/*.js';
@source '../../project-b/src/**/*.js';
@plugin '../plugin.js';
`,
'project-a/src/index.js': js`
Expand Down
4 changes: 2 additions & 2 deletions integrations/vite/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test(
'project-a/src/index.css': css`
@import 'tailwindcss/theme' theme(reference);
@import 'tailwindcss/utilities';
@content '../../project-b/src/**/*.js';
@source '../../project-b/src/**/*.js';
`,
'project-b/src/index.js': js`
const className = "content-['project-b/src/index.js']"
Expand Down Expand Up @@ -124,7 +124,7 @@ test(
'project-a/src/index.css': css`
@import 'tailwindcss/theme' theme(reference);
@import 'tailwindcss/utilities';
@content '../../project-b/src/**/*.js';
@source '../../project-b/src/**/*.js';
`,
'project-b/src/index.js': js`
const className = "content-['project-b/src/index.js']"
Expand Down
2 changes: 1 addition & 1 deletion packages/@tailwindcss-cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ function handleImports(
// Relevant specification:
// - CSS Import Resolve: https://csstools.github.io/css-import-resolve/

if (!input.includes('@import') && !input.includes('@plugin') && !input.includes('@content')) {
if (!input.includes('@import') && !input.includes('@plugin') && !input.includes('@source')) {
return [input, [file]]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@content "./**/*.ts";
@content "!./**/*.ts";
@source "./**/*.ts";
@source "!./**/*.ts";
@plugin "./plugin.js";
@plugin "./what\"s-this.js";
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { describe, expect, test } from 'vitest'
import fixRelativePathsPlugin from '.'

describe('fixRelativePathsPlugin', () => {
test('rewrites @content and @plugin to be relative to the initial css file', async () => {
test('rewrites @source and @plugin to be relative to the initial css file', async () => {
let cssPath = path.join(__dirname, 'fixtures', 'external-import', 'src', 'index.css')
let css = fs.readFileSync(cssPath, 'utf-8')

Expand All @@ -15,8 +15,8 @@ describe('fixRelativePathsPlugin', () => {
let result = await processor.process(css, { from: cssPath })

expect(result.css.trim()).toMatchInlineSnapshot(`
"@content "../../example-project/src/**/*.ts";
@content "!../../example-project/src/**/*.ts";
"@source "../../example-project/src/**/*.ts";
@source "!../../example-project/src/**/*.ts";
@plugin "../../example-project/src/plugin.js";
@plugin "../../example-project/src/what\\"s-this.js";"
`)
Expand Down
2 changes: 1 addition & 1 deletion packages/internal-postcss-fix-relative-paths/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function fixRelativePathsPlugin(): Plugin {
return {
postcssPlugin: 'tailwindcss-postcss-fix-relative-paths',
AtRule: {
content: fixRelativePath,
source: fixRelativePath,
plugin: fixRelativePath,
},
}
Expand Down
12 changes: 6 additions & 6 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1514,19 +1514,19 @@ describe('plugins', () => {
})
})

describe('@content', () => {
test('emits @content files', () => {
describe('@source', () => {
test('emits @source files', () => {
let { globs } = compile(css`
@content "./foo/bar/*.ts";
@source "./foo/bar/*.ts";
`)

expect(globs).toEqual(['./foo/bar/*.ts'])
})

test('emits multiple @content files', () => {
test('emits multiple @source files', () => {
let { globs } = compile(css`
@content "./foo/**/*.ts";
@content "./php/secr3t/smarty.php";
@source "./foo/**/*.ts";
@source "./php/secr3t/smarty.php";
`)

expect(globs).toEqual(['./foo/**/*.ts', './php/secr3t/smarty.php'])
Expand Down
12 changes: 6 additions & 6 deletions packages/tailwindcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,23 @@ export function compile(
return
}

// Collect paths from `@content` at-rules
if (node.selector.startsWith('@content ')) {
// Collect paths from `@source` at-rules
if (node.selector.startsWith('@source ')) {
if (node.nodes.length > 0) {
throw new Error('`@content` cannot have a body.')
throw new Error('`@source` cannot have a body.')
}

if (parent !== null) {
throw new Error('`@content` cannot be nested.')
throw new Error('`@source` cannot be nested.')
}

let path = node.selector.slice(9)
let path = node.selector.slice(8)
if (
(path[0] === '"' && path[path.length - 1] !== '"') ||
(path[0] === "'" && path[path.length - 1] !== "'") ||
(path[0] !== "'" && path[0] !== '"')
) {
throw new Error('`@content` paths must be quoted.')
throw new Error('`@source` paths must be quoted.')
}
globs.push(path.slice(1, -1))
replaceWith([])
Expand Down

0 comments on commit 58d4fa9

Please sign in to comment.