|
1 | 1 | import os from 'node:os'
|
2 | 2 | import path from 'node:path'
|
3 |
| -import { candidate, css, html, json, test } from '../utils' |
| 3 | +import { candidate, css, html, js, json, test } from '../utils' |
4 | 4 |
|
5 | 5 | const STANDALONE_BINARY = (() => {
|
6 | 6 | switch (os.platform()) {
|
@@ -56,3 +56,110 @@ test(
|
56 | 56 | ])
|
57 | 57 | },
|
58 | 58 | )
|
| 59 | + |
| 60 | +test( |
| 61 | + 'includes js APIs for plugins', |
| 62 | + { |
| 63 | + fs: { |
| 64 | + 'package.json': json` |
| 65 | + { |
| 66 | + "dependencies": {} |
| 67 | + } |
| 68 | + `, |
| 69 | + 'index.html': html` |
| 70 | + <div class="underline example1 example2 example3"></div> |
| 71 | + `, |
| 72 | + 'src/index.css': css` |
| 73 | + @import 'tailwindcss/theme' theme(reference); |
| 74 | + @import 'tailwindcss/utilities'; |
| 75 | + @plugin './plugin.js'; |
| 76 | + @plugin './plugin.cjs'; |
| 77 | + @plugin './plugin.ts'; |
| 78 | + `, |
| 79 | + 'src/plugin.js': js` |
| 80 | + import plugin from 'tailwindcss/plugin' |
| 81 | +
|
| 82 | + // Make sure all available JS APIs can be imported and used |
| 83 | + import * as tw from 'tailwindcss' |
| 84 | + import colors from 'tailwindcss/colors' |
| 85 | + import flattenColorPalette from 'tailwindcss/lib/util/flattenColorPalette' |
| 86 | + import defaultTheme from 'tailwindcss/defaultTheme' |
| 87 | + import * as pkg from 'tailwindcss/package.json' |
| 88 | +
|
| 89 | + export default plugin(function ({ addUtilities }) { |
| 90 | + addUtilities({ |
| 91 | + '.example1': { |
| 92 | + '--version': pkg.version, |
| 93 | + '--default-theme': typeof defaultTheme, |
| 94 | + '--flatten-color-palette': typeof flattenColorPalette, |
| 95 | + '--colors': typeof colors, |
| 96 | + '--core': typeof tw, |
| 97 | + color: 'red', |
| 98 | + }, |
| 99 | + }) |
| 100 | + }) |
| 101 | + `, |
| 102 | + 'src/plugin.cjs': js` |
| 103 | + const plugin = require('tailwindcss/plugin') |
| 104 | +
|
| 105 | + // Make sure all available JS APIs can be imported and used |
| 106 | + const tw = require('tailwindcss') |
| 107 | + const colors = require('tailwindcss/colors') |
| 108 | + const flattenColorPalette = require('tailwindcss/lib/util/flattenColorPalette') |
| 109 | + const defaultTheme = require('tailwindcss/defaultTheme') |
| 110 | + const pkg = require('tailwindcss/package.json') |
| 111 | +
|
| 112 | + module.exports = plugin(function ({ addUtilities }) { |
| 113 | + addUtilities({ |
| 114 | + '.example2': { |
| 115 | + '--version': pkg.version, |
| 116 | + '--default-theme': typeof defaultTheme, |
| 117 | + '--flatten-color-palette': typeof flattenColorPalette, |
| 118 | + '--colors': typeof colors, |
| 119 | + '--core': typeof tw, |
| 120 | + color: 'red', |
| 121 | + }, |
| 122 | + }) |
| 123 | + }) |
| 124 | + `, |
| 125 | + 'src/plugin.ts': js` |
| 126 | + import plugin from 'tailwindcss/plugin' |
| 127 | +
|
| 128 | + // Make sure all available JS APIs can be imported and used |
| 129 | + import * as tw from 'tailwindcss' |
| 130 | + import colors from 'tailwindcss/colors' |
| 131 | + import flattenColorPalette from 'tailwindcss/lib/util/flattenColorPalette' |
| 132 | + import defaultTheme from 'tailwindcss/defaultTheme' |
| 133 | + import * as pkg from 'tailwindcss/package.json' |
| 134 | +
|
| 135 | + export interface PluginOptions { |
| 136 | + } |
| 137 | +
|
| 138 | + export default plugin(function ({ addUtilities }) { |
| 139 | + addUtilities({ |
| 140 | + '.example3': { |
| 141 | + '--version': pkg.version, |
| 142 | + '--default-theme': typeof defaultTheme, |
| 143 | + '--flatten-color-palette': typeof flattenColorPalette, |
| 144 | + '--colors': typeof colors, |
| 145 | + '--core': typeof tw, |
| 146 | + color: 'red', |
| 147 | + }, |
| 148 | + }) |
| 149 | + }) |
| 150 | + `, |
| 151 | + }, |
| 152 | + }, |
| 153 | + async ({ fs, exec }) => { |
| 154 | + await exec( |
| 155 | + `${path.resolve(__dirname, `../../packages/@tailwindcss-standalone/dist/${STANDALONE_BINARY}`)} --input src/index.css --output dist/out.css`, |
| 156 | + ) |
| 157 | + |
| 158 | + await fs.expectFileToContain('dist/out.css', [ |
| 159 | + candidate`underline`, |
| 160 | + candidate`example1`, |
| 161 | + candidate`example2`, |
| 162 | + candidate`example3`, |
| 163 | + ]) |
| 164 | + }, |
| 165 | +) |
0 commit comments