Return resolved path in loadStylesheet and loadModule

Source map support needs this in loadStylesheet but it makes more sense to be consistent and require it for both.
This commit is contained in:
Jordan Pittman 2025-04-18 10:40:54 -04:00
parent a4cd44d426
commit 68ce361ef4
12 changed files with 160 additions and 0 deletions

View file

@ -116,6 +116,7 @@ async function loadStylesheet(id: string, base: string) {
function load() {
if (id === 'tailwindcss') {
return {
path: 'virtual:tailwindcss/index.css',
base,
content: assets.css.index,
}
@ -125,6 +126,7 @@ async function loadStylesheet(id: string, base: string) {
id === './preflight.css'
) {
return {
path: 'virtual:tailwindcss/preflight.css',
base,
content: assets.css.preflight,
}
@ -134,6 +136,7 @@ async function loadStylesheet(id: string, base: string) {
id === './theme.css'
) {
return {
path: 'virtual:tailwindcss/theme.css',
base,
content: assets.css.theme,
}
@ -143,6 +146,7 @@ async function loadStylesheet(id: string, base: string) {
id === './utilities.css'
) {
return {
path: 'virtual:tailwindcss/utilities.css',
base,
content: assets.css.utilities,
}

View file

@ -125,6 +125,7 @@ export async function loadModule(
let module = await importModule(pathToFileURL(resolvedPath).href)
return {
path: resolvedPath,
base: path.dirname(resolvedPath),
module: module.default ?? module,
}
@ -144,6 +145,7 @@ export async function loadModule(
onDependency(file)
}
return {
path: resolvedPath,
base: path.dirname(resolvedPath),
module: module.default ?? module,
}
@ -164,6 +166,7 @@ async function loadStylesheet(
let file = await globalThis.__tw_readFile(resolvedPath, 'utf-8')
if (file) {
return {
path: resolvedPath,
base: path.dirname(resolvedPath),
content: file,
}
@ -172,6 +175,7 @@ async function loadStylesheet(
let file = await fsPromises.readFile(resolvedPath, 'utf-8')
return {
path: resolvedPath,
base: path.dirname(resolvedPath),
content: file,
}

View file

@ -7,6 +7,7 @@ type LoadStylesheet = (
id: string,
basedir: string,
) => Promise<{
path: string
base: string
content: string
}>

View file

@ -31,6 +31,7 @@ export async function applyCompatibilityHooks({
base: string,
resourceHint: 'plugin' | 'config',
) => Promise<{
path: string
base: string
module: any
}>

View file

@ -1156,6 +1156,7 @@ test('utilities must be prefixed', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => ({
path: '',
base,
module: { prefix: 'tw' },
}),
@ -1183,6 +1184,7 @@ test('utilities must be prefixed', async () => {
// Non-prefixed utilities are ignored
compiler = await compile(input, {
loadModule: async (id, base) => ({
path: '',
base,
module: { prefix: 'tw' },
}),
@ -1202,6 +1204,7 @@ test('utilities used in @apply must be prefixed', async () => {
`,
{
loadModule: async (id, base) => ({
path: '',
base,
module: { prefix: 'tw' },
}),
@ -1228,6 +1231,7 @@ test('utilities used in @apply must be prefixed', async () => {
`,
{
loadModule: async (id, base) => ({
path: '',
base,
module: { prefix: 'tw' },
}),
@ -1258,6 +1262,7 @@ test('Prefixes configured in CSS take precedence over those defined in JS config
{
async loadModule(id, base) {
return {
path: '',
base,
module: { prefix: 'tw' },
}
@ -1282,6 +1287,7 @@ test('a prefix must be letters only', async () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: { prefix: '__' },
}
@ -1305,6 +1311,7 @@ test('important: `#app`', async () => {
let compiler = await compile(input, {
loadModule: async (_, base) => ({
path: '',
base,
module: { important: '#app' },
}),
@ -1342,6 +1349,7 @@ test('important: true', async () => {
let compiler = await compile(input, {
loadModule: async (_, base) => ({
path: '',
base,
module: { important: true },
}),
@ -1378,6 +1386,7 @@ test('blocklisted candidates are not generated', async () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: {
blocklist: ['bg-white'],
@ -1421,6 +1430,7 @@ test('blocklisted candidates cannot be used with `@apply`', async () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: {
blocklist: ['bg-white'],
@ -1473,6 +1483,7 @@ test('old theme values are merged with their renamed counterparts in the CSS the
{
async loadModule(id, base) {
return {
path: '',
base,
module: plugin(function ({ theme }) {
didCallPluginFn()

View file

@ -17,6 +17,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ addBase, theme }) {
@ -80,6 +81,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(function ({ addUtilities, theme }) {
addUtilities({
@ -116,6 +118,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ matchUtilities, theme }) {
@ -164,6 +167,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ matchUtilities, theme }) {
@ -211,6 +215,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ matchUtilities, theme }) {
@ -265,6 +270,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(function ({ addUtilities, theme }) {
addUtilities({
@ -313,6 +319,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ addUtilities, theme }) {
@ -398,6 +405,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ matchUtilities, theme }) {
@ -452,6 +460,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ matchUtilities, theme }) {
@ -499,6 +508,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(function ({ matchUtilities, theme }) {
matchUtilities(
@ -557,6 +567,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ matchUtilities, theme }) {
@ -611,6 +622,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ matchUtilities, theme }) {
@ -660,6 +672,7 @@ describe('theme', async () => {
await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ theme }) {
@ -695,6 +708,7 @@ describe('theme', async () => {
let { build } = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(function ({ matchUtilities, theme }) {
function utility(name: string, themeKey: string) {
@ -942,6 +956,7 @@ describe('theme', async () => {
await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
({ theme }) => {
@ -984,6 +999,7 @@ describe('theme', async () => {
await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(({ theme }) => {
fn(theme('transitionTimingFunction.DEFAULT'))
@ -1015,6 +1031,7 @@ describe('theme', async () => {
await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(({ theme }) => {
fn(theme('color.red.100'))
@ -1043,6 +1060,7 @@ describe('theme', async () => {
await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(({ theme }) => {
fn(theme('i.do.not.exist'))
@ -1069,6 +1087,7 @@ describe('theme', async () => {
let { build } = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(({ addUtilities, matchUtilities }) => {
addUtilities({
@ -1124,6 +1143,7 @@ describe('theme', async () => {
let { build } = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(function ({ matchUtilities }) {
function utility(name: string, themeKey: string) {
@ -1342,6 +1362,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ matchUtilities, theme }) {
@ -1400,6 +1421,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(function ({ matchUtilities, theme }) {
matchUtilities(
@ -1446,6 +1468,7 @@ describe('theme', async () => {
let compiler = await compile(input, {
loadModule: async (id, base) => {
return {
path: '',
base,
module: plugin(
function ({ matchUtilities, theme }) {
@ -1493,6 +1516,7 @@ describe('addBase', () => {
loadModule: async (id, base) => {
if (id === 'inside') {
return {
path: '',
base,
module: plugin(function ({ addBase }) {
addBase({ inside: { color: 'red' } })
@ -1500,6 +1524,7 @@ describe('addBase', () => {
}
}
return {
path: '',
base,
module: plugin(function ({ addBase }) {
addBase({ outside: { color: 'red' } })
@ -1508,6 +1533,7 @@ describe('addBase', () => {
},
async loadStylesheet() {
return {
path: '',
base: '',
content: css`
@plugin "inside";
@ -1533,6 +1559,7 @@ describe('addBase', () => {
let compiler = await compile(input, {
loadModule: async () => ({
path: '',
base: '/root',
module: plugin(function ({ addBase }) {
addBase({
@ -1571,6 +1598,7 @@ describe('addVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', '&:hover, &:focus')
@ -1605,6 +1633,7 @@ describe('addVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', ['&:hover', '&:focus'])
@ -1640,6 +1669,7 @@ describe('addVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', {
@ -1677,6 +1707,7 @@ describe('addVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', {
@ -1728,6 +1759,7 @@ describe('addVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ addVariant }: PluginAPI) => {
addVariant(
@ -1769,6 +1801,7 @@ describe('addVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', {
@ -1811,6 +1844,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('potato', (flavor) => `.potato-${flavor} &`)
@ -1845,6 +1879,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('potato', (flavor) => `@media (potato: ${flavor})`)
@ -1883,6 +1918,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant(
@ -1929,6 +1965,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('tooltip', (side) => `&${side}`, {
@ -1968,6 +2005,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('alphabet', (side) => `&${side}`, {
@ -2010,6 +2048,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('test', (selector) =>
@ -2042,6 +2081,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('testmin', (value) => `@media (min-width: ${value})`, {
@ -2094,6 +2134,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('testmin', (value) => `@media (min-width: ${value})`, {
@ -2149,6 +2190,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('testmin', (value) => `@media (min-width: ${value})`, {
@ -2221,6 +2263,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('testmin', (value) => `@media (min-width: ${value})`, {
@ -2275,6 +2318,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('testmin', (value) => `@media (min-width: ${value})`, {
@ -2347,6 +2391,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('testmin', (value) => `@media (min-width: ${value})`, {
@ -2415,6 +2460,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('testmin', (value) => `@media (min-width: ${value})`, {
@ -2495,6 +2541,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('foo', (value) => `.foo${value} &`, {
@ -2529,6 +2576,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('foo', (value) => `.foo${value} &`)
@ -2553,6 +2601,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('foo', (value) => `.foo${value === null ? '-good' : '-bad'} &`, {
@ -2585,6 +2634,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('foo', (value) => `.foo${value === undefined ? '-good' : '-bad'} &`, {
@ -2615,6 +2665,7 @@ describe('matchVariant', () => {
{
loadModule: async (id, base) => {
return {
path: '',
base,
module: ({ matchVariant }: PluginAPI) => {
matchVariant('my-container', (value, { modifier }) => {
@ -2669,6 +2720,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities({
@ -2710,6 +2762,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities([
@ -2743,6 +2796,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities([
@ -2782,6 +2836,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities([
@ -2816,6 +2871,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities({
@ -2857,6 +2913,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities({
@ -2913,6 +2970,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities({
@ -2942,6 +3000,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities({
@ -2985,6 +3044,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities({
@ -3026,6 +3086,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities({
@ -3122,6 +3183,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities({
@ -3175,6 +3237,7 @@ describe('addUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addUtilities }: PluginAPI) => {
addUtilities({
@ -3240,6 +3303,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3320,6 +3384,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3361,6 +3426,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3410,6 +3476,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3480,6 +3547,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3554,6 +3622,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3609,6 +3678,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3647,6 +3717,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3691,6 +3762,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3818,6 +3890,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3903,6 +3976,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -3961,6 +4035,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -4028,6 +4103,7 @@ describe('matchUtilities()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities({
@ -4056,6 +4132,7 @@ describe('matchUtilities()', () => {
{
async loadModule(base) {
return {
path: '',
base,
module: ({ matchUtilities }: PluginAPI) => {
matchUtilities(
@ -4122,6 +4199,7 @@ describe('addComponents()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ addComponents }: PluginAPI) => {
addComponents({
@ -4190,6 +4268,7 @@ describe('matchComponents()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ matchComponents }: PluginAPI) => {
matchComponents(
@ -4235,6 +4314,7 @@ describe('prefix()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ prefix }: PluginAPI) => {
fn(prefix('btn'))
@ -4258,6 +4338,7 @@ describe('config()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ config }: PluginAPI) => {
fn(config())
@ -4285,6 +4366,7 @@ describe('config()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ config }: PluginAPI) => {
fn(config('theme'))
@ -4310,6 +4392,7 @@ describe('config()', () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: ({ config }: PluginAPI) => {
fn(config('somekey', 'defaultvalue'))

View file

@ -412,6 +412,7 @@ describe('--theme(…)', () => {
[],
{
loadModule: async () => ({
path: '',
base: '/root',
module: () => {},
}),
@ -772,6 +773,7 @@ describe('theme(…)', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: {},
}),
@ -1199,6 +1201,7 @@ describe('in plugins', () => {
{
async loadModule() {
return {
path: '',
base: '/root',
module: plugin(({ addBase, addUtilities }) => {
addBase({
@ -1256,6 +1259,7 @@ describe('in JS config files', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: {
theme: {
@ -1317,6 +1321,7 @@ test('replaces CSS theme() function with values inside imported stylesheets', as
{
async loadStylesheet() {
return {
path: '',
base: '/bar.css',
content: css`
.red {

View file

@ -126,6 +126,7 @@ describe('compiling CSS', () => {
{
async loadStylesheet(id) {
return {
path: '',
base: '',
content: fs.readFileSync(
path.resolve(__dirname, '..', id === 'tailwindcss' ? 'index.css' : id),
@ -401,6 +402,7 @@ describe('@apply', () => {
{
async loadStylesheet() {
return {
path: '',
base: '/bar.css',
content: css`
.foo {
@ -2320,6 +2322,7 @@ describe('Parsing theme values from CSS', () => {
{
async loadStylesheet() {
return {
path: '',
base: '',
content: css`
@theme {
@ -2407,6 +2410,7 @@ describe('Parsing theme values from CSS', () => {
{
async loadStylesheet() {
return {
path: '',
base: '',
content: css`
@theme {
@ -2704,6 +2708,7 @@ describe('Parsing theme values from CSS', () => {
{
loadModule: async () => {
return {
path: '',
base: '/root',
module: plugin(({}) => {}, {
theme: {
@ -2750,6 +2755,7 @@ describe('Parsing theme values from CSS', () => {
{
loadModule: async () => {
return {
path: '',
base: '/root',
module: {
theme: {
@ -2839,6 +2845,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', '&:hover, &:focus')
@ -2857,6 +2864,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', '&:hover, &:focus')
@ -2877,6 +2885,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', '&:hover, &:focus')
@ -2899,6 +2908,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: plugin.withOptions((options) => {
expect(options).toEqual({
@ -2951,6 +2961,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: plugin.withOptions((options) => {
expect(options).toEqual({
@ -2991,6 +3002,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: plugin.withOptions((options) => {
return ({ addUtilities }) => {
@ -3029,6 +3041,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: plugin(({ addUtilities }) => {
addUtilities({
@ -3055,6 +3068,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: plugin(() => {}),
}),
@ -3079,6 +3093,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: plugin(() => {}),
}),
@ -3105,6 +3120,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', '&:hover, &:focus')
@ -3137,6 +3153,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', ['&:hover', '&:focus'])
@ -3170,6 +3187,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', {
@ -3205,6 +3223,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', {
@ -3254,6 +3273,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({ addVariant }: PluginAPI) => {
addVariant('hocus', {
@ -3292,6 +3312,7 @@ describe('plugins', () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({ addVariant }: PluginAPI) => {
addVariant('dark', '&:is([data-theme=dark] *)')
@ -4148,6 +4169,7 @@ test('addBase', async () => {
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({ addBase }: PluginAPI) => {
addBase({
@ -4187,6 +4209,7 @@ it("should error when `layer(…)` is used, but it's not the first param", async
{
async loadStylesheet() {
return {
path: '',
base: '/bar.css',
content: css`
.foo {
@ -4207,6 +4230,7 @@ describe('`@reference "…" imports`', () => {
let loadStylesheet = async (id: string, base: string) => {
if (id === './foo/baz.css') {
return {
path: '',
base: '/root/foo',
content: css`
.foo {
@ -4223,6 +4247,7 @@ describe('`@reference "…" imports`', () => {
}
}
return {
path: '',
base: '/root/foo',
content: css`
@import './foo/baz.css';
@ -4255,6 +4280,7 @@ describe('`@reference "…" imports`', () => {
let loadStylesheet = async (id: string, base: string) => {
if (id === './foo/baz.css') {
return {
path: '',
base: '/root/foo',
content: css`
@layer utilities {
@ -4264,6 +4290,7 @@ describe('`@reference "…" imports`', () => {
}
}
return {
path: '',
base: '/root/foo',
content: css`
@import './foo/baz.css';
@ -4317,6 +4344,7 @@ describe('`@reference "…" imports`', () => {
['animate-spin', 'match-utility-initial', 'match-components-initial'],
{
loadModule: async () => ({
path: '',
base: '/root',
module: ({
addBase,
@ -4372,6 +4400,7 @@ describe('`@reference "…" imports`', () => {
switch (id) {
case './one.css': {
return {
path: '',
base: '/root',
content: css`
@import './two.css' layer(two);
@ -4380,6 +4409,7 @@ describe('`@reference "…" imports`', () => {
}
case './two.css': {
return {
path: '',
base: '/root',
content: css`
@import './three.css' layer(three);
@ -4388,6 +4418,7 @@ describe('`@reference "…" imports`', () => {
}
case './three.css': {
return {
path: '',
base: '/root',
content: css`
.foo {
@ -4446,6 +4477,7 @@ describe('`@reference "…" imports`', () => {
test('supports `@import "…" reference` syntax', async () => {
let loadStylesheet = async () => {
return {
path: '',
base: '/root/foo',
content: css`
.foo {

View file

@ -57,6 +57,7 @@ type CompileOptions = {
base: string,
resourceHint: 'plugin' | 'config',
) => Promise<{
path: string
base: string
module: Plugin | Config
}>
@ -64,6 +65,7 @@ type CompileOptions = {
id: string,
base: string,
) => Promise<{
path: string
base: string
content: string
}>

View file

@ -172,10 +172,12 @@ test('Utilities do not show wrapping selector in intellisense', async () => {
let design = await __unstable__loadDesignSystem(input, {
loadStylesheet: async (_, base) => ({
path: '',
base,
content: '@tailwind utilities;',
}),
loadModule: async () => ({
path: '',
base: '',
module: {
important: '#app',
@ -208,6 +210,7 @@ test('Utilities, when marked as important, show as important in intellisense', a
let design = await __unstable__loadDesignSystem(input, {
loadStylesheet: async (_, base) => ({
path: '',
base,
content: '@tailwind utilities;',
}),
@ -239,10 +242,12 @@ test('Static utilities from plugins are listed in hovers and completions', async
let design = await __unstable__loadDesignSystem(input, {
loadStylesheet: async (_, base) => ({
path: '',
base,
content: '@tailwind utilities;',
}),
loadModule: async () => ({
path: '',
base: '',
module: plugin(({ addUtilities }) => {
addUtilities({
@ -274,10 +279,12 @@ test('Functional utilities from plugins are listed in hovers and completions', a
let design = await __unstable__loadDesignSystem(input, {
loadStylesheet: async (_, base) => ({
path: '',
base,
content: '@tailwind utilities;',
}),
loadModule: async () => ({
path: '',
base: '',
module: plugin(({ matchUtilities }) => {
matchUtilities(
@ -420,10 +427,12 @@ test('Custom at-rule variants do not show up as a value under `group`', async ()
let design = await __unstable__loadDesignSystem(input, {
loadStylesheet: async (_, base) => ({
path: '',
base,
content: '@tailwind utilities;',
}),
loadModule: async () => ({
path: '',
base: '',
module: plugin(({ addVariant }) => {
addVariant('variant-3', '@media baz')
@ -510,6 +519,7 @@ test('Custom functional @utility', async () => {
let design = await __unstable__loadDesignSystem(input, {
loadStylesheet: async (_, base) => ({
path: '',
base,
content: '@tailwind utilities;',
}),
@ -587,6 +597,7 @@ test('Theme keys with underscores are suggested with underscores', async () => {
let design = await __unstable__loadDesignSystem(input, {
loadStylesheet: async (_, base) => ({
path: '',
base,
content: '@tailwind utilities;',
}),

View file

@ -169,6 +169,7 @@ test('JS theme functions do not use the prefix', async () => {
{
async loadModule(id, base) {
return {
path: '',
base,
module: plugin(({ addUtilities, theme }) => {
addUtilities({
@ -206,6 +207,7 @@ test('a prefix can be configured via @import theme(…)', async () => {
let compiler = await compile(input, {
async loadStylesheet(id, base) {
return {
path: '',
base,
content: css`
@theme {
@ -250,6 +252,7 @@ test('a prefix can be configured via @import theme(…)', async () => {
compiler = await compile(input, {
async loadStylesheet(id, base) {
return {
path: '',
base,
content: css`
@theme {
@ -275,6 +278,7 @@ test('a prefix can be configured via @import prefix(…)', async () => {
let compiler = await compile(input, {
async loadStylesheet(id, base) {
return {
path: '',
base,
content: css`
@theme {
@ -314,6 +318,7 @@ test('a prefix can be configured via @import prefix(…)', async () => {
compiler = await compile(input, {
async loadStylesheet(id, base) {
return {
path: '',
base,
content: css`
@theme {

View file

@ -2528,6 +2528,7 @@ test('matchVariant sorts deterministically', async () => {
let output = await compileCss('@tailwind utilities; @plugin "./plugin.js";', classList, {
async loadModule(id: string) {
return {
path: '',
base: '/',
module: createPlugin(({ matchVariant }) => {
matchVariant('is-data', (value) => `&:is([data-${value}])`, {