@esuiss/ui 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,4 +9,4 @@ npx @esuiss/ui@latest add button --diff
9
9
  npx @esuiss/ui@latest add button --overwrite
10
10
  ```
11
11
 
12
- `init` sets up Tailwind CSS v4, the `@/*` import alias, the theme stylesheet, and the button. Requires TypeScript.
12
+ `init` sets up Tailwind CSS (4.2 or later), the `@/*` import alias, the theme stylesheet with `@esuiss/tailwind`, and the button. Requires TypeScript.
package/lib/init.mjs CHANGED
@@ -38,7 +38,7 @@ const TOOLING = {
38
38
  next: ["tailwindcss", "@tailwindcss/postcss"],
39
39
  vite: ["tailwindcss", "@tailwindcss/vite", "@types/node"],
40
40
  }
41
- const RUNTIME = ["tw-animate-css"]
41
+ const MINIMUM_TAILWIND = [4, 2]
42
42
 
43
43
  function relative(project, file) {
44
44
  return path.relative(project.cwd, file)
@@ -59,16 +59,46 @@ function findStylesheet(project) {
59
59
  return path.join(appDir, "globals.css")
60
60
  }
61
61
 
62
+ function installedVersion(project, name) {
63
+ const manifest = path.join(project.cwd, "node_modules", name, "package.json")
64
+ if (existsSync(manifest)) {
65
+ return JSON.parse(readFileSync(manifest, "utf8")).version
66
+ }
67
+ return project.packages[name]
68
+ }
69
+
62
70
  function assertTailwindVersion(project) {
63
- const version = project.packages.tailwindcss
64
- const major = version && Number(version.match(/\d+/)?.[0])
65
- if (major && major < 4) {
71
+ const version = installedVersion(project, "tailwindcss")
72
+ const match = version?.match(/(\d+)(?:\.(\d+))?/)
73
+ if (!match) return
74
+ const major = Number(match[1])
75
+ const minor = match[2] === undefined ? undefined : Number(match[2])
76
+ const [requiredMajor, requiredMinor] = MINIMUM_TAILWIND
77
+ const tooOld =
78
+ major < requiredMajor ||
79
+ (major === requiredMajor && minor !== undefined && minor < requiredMinor)
80
+ if (tooOld) {
66
81
  throw new CliError(
67
- `Tailwind CSS v4 is required, this project uses ${version}.`
82
+ `Tailwind CSS ${requiredMajor}.${requiredMinor} or later is required, this project uses ${version}. Upgrade tailwindcss and run init again.`
68
83
  )
69
84
  }
70
85
  }
71
86
 
87
+ function stylesheetPackages(css) {
88
+ return [...css.matchAll(/@import\s+["']([^"']+)["']/g)]
89
+ .map(([, specifier]) => specifier)
90
+ .filter(
91
+ (specifier) =>
92
+ !specifier.startsWith(".") &&
93
+ !specifier.startsWith("/") &&
94
+ specifier !== "tailwindcss"
95
+ )
96
+ .map((specifier) => {
97
+ const parts = specifier.split("/")
98
+ return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]
99
+ })
100
+ }
101
+
72
102
  function addAliasTo(file, target) {
73
103
  let text = readFileSync(file, "utf8")
74
104
  const alias = `"@/*": ["${target}"]`
@@ -206,7 +236,7 @@ export async function init(options) {
206
236
  step("Added the @/* import alias to tsconfig")
207
237
 
208
238
  install(project, TOOLING[project.framework], { dev: true })
209
- install(project, RUNTIME)
239
+ install(project, stylesheetPackages(css))
210
240
 
211
241
  const manual =
212
242
  project.framework === "vite"
package/lib/project.mjs CHANGED
@@ -21,11 +21,11 @@ const INSTALL_ARGS = {
21
21
 
22
22
  const TSCONFIGS = ["tsconfig.json", "tsconfig.app.json"]
23
23
 
24
- export function readJsonc(file) {
24
+ function readJsonc(file) {
25
25
  const text = readFileSync(file, "utf8")
26
26
  const withoutComments = text.replace(
27
27
  /("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g,
28
- (match, string) => string ?? ""
28
+ (_match, string) => string ?? ""
29
29
  )
30
30
  return JSON.parse(withoutComments.replace(/,(\s*[}\]])/g, "$1"))
31
31
  }
package/lib/registry.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CliError } from "./output.mjs"
2
2
 
3
- const DEFAULT_BASE = "https://raw.githubusercontent.com/esuiss/esuiss-ui/main"
3
+ const DEFAULT_BASE = "https://raw.githubusercontent.com/e-suiss/ui/main"
4
4
  const base = (process.env.ESUISS_REGISTRY ?? DEFAULT_BASE).replace(/\/$/, "")
5
5
 
6
6
  export async function fetchText(file) {
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "@esuiss/ui",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Add esuiss-ui components to Next.js and React projects.",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/e-suiss/ui.git",
9
+ "directory": "packages/cli"
10
+ },
11
+ "homepage": "https://github.com/e-suiss/ui",
6
12
  "type": "module",
7
13
  "bin": {
8
14
  "esuiss": "index.mjs"