@10stars/config 16.0.1 → 16.0.2
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/package.json +2 -2
- package/src/index.ts +3 -0
- package/src/patch-vanilla-extract.ts +57 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@10stars/config",
|
|
3
|
-
"version": "16.0.
|
|
3
|
+
"version": "16.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"bin": {
|
|
6
6
|
"config": "./src/index.ts"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"oxfmt": "0.57.0",
|
|
31
31
|
"oxlint": "^1.72.0",
|
|
32
32
|
"oxlint-tsgolint": "^0.24.0",
|
|
33
|
-
"tsx": "^4.
|
|
33
|
+
"tsx": "^4.23.0",
|
|
34
34
|
"type-fest": "^5.7.0",
|
|
35
35
|
"typescript": "7.0.1-rc"
|
|
36
36
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import path from "node:path"
|
|
|
6
6
|
import { resetColorIndex } from "./colors"
|
|
7
7
|
import { checkIsMonorepo, dedupeSingletons, linkPackages } from "./link-packages"
|
|
8
8
|
import { setupOverrides } from "./manage-overrides"
|
|
9
|
+
import { patchVanillaExtract } from "./patch-vanilla-extract"
|
|
9
10
|
import { runConcurrently, type CommandConfig } from "./runner"
|
|
10
11
|
import { setupVSCode } from "./vscode-config"
|
|
11
12
|
|
|
@@ -44,6 +45,8 @@ const actions = {
|
|
|
44
45
|
prepare: {
|
|
45
46
|
info: `Runs husky and links packages`,
|
|
46
47
|
action: async () => {
|
|
48
|
+
await patchVanillaExtract(cwd) // patch VE before the CI guard: builds (incl. CI) need the `css.ts`-only filter in node_modules
|
|
49
|
+
|
|
47
50
|
if (process.env.CI) return
|
|
48
51
|
|
|
49
52
|
// we must copy it first, because the following steps might have formatting cmds
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from "node:fs/promises"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
|
|
4
|
+
// Vanilla Extract hardcodes its file filter as a `const` regex in @vanilla-extract/integration and
|
|
5
|
+
// imports it into both its vite-plugin and its compiler — there's no option to customize it. We
|
|
6
|
+
// rewrite the regex on disk so ONLY `css.ts` (our single-filename convention) is treated as a VE
|
|
7
|
+
// module; the conventional `.css.ts` suffix is intentionally no longer matched.
|
|
8
|
+
// original: matches any `*.css.ts` (a `.` may precede `css`)
|
|
9
|
+
// patched: matches a `css.ts` filename (only start-of-path or a separator may precede `css`)
|
|
10
|
+
const ORIGINAL = String.raw`/\.css\.(js|cjs|mjs|jsx|ts|tsx)(\?used)?$/`
|
|
11
|
+
const PATCHED = String.raw`/(?:^|[/\\])css\.(js|cjs|mjs|jsx|ts|tsx)(\?used)?$/`
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Rewrite VE's `cssFileFilter` to a `css.ts`-only matcher in every installed copy.
|
|
15
|
+
*
|
|
16
|
+
* Runs on `prepare` (postinstall), so it re-applies after each `bun install` re-materializes
|
|
17
|
+
* node_modules. Idempotent, and a no-op for repos without VE (e.g. backend-only). If VE is present
|
|
18
|
+
* but the filter definition can't be found, it throws: a silent miss would stop every `css.ts` from
|
|
19
|
+
* compiling, so a VE build change must surface at install time rather than as missing styles.
|
|
20
|
+
*/
|
|
21
|
+
export const patchVanillaExtract = async (cwd: string) => {
|
|
22
|
+
const nodeModules = path.join(cwd, `node_modules`)
|
|
23
|
+
const glob = new Bun.Glob(`**/@vanilla-extract/integration/dist/*.js`)
|
|
24
|
+
|
|
25
|
+
let integrationFound = false
|
|
26
|
+
let definitionFound = false
|
|
27
|
+
const patched: string[] = []
|
|
28
|
+
|
|
29
|
+
for await (const rel of glob.scan({ cwd: nodeModules, onlyFiles: true })) {
|
|
30
|
+
integrationFound = true
|
|
31
|
+
const file = path.join(nodeModules, rel)
|
|
32
|
+
const content = await fs.readFile(file, `utf8`)
|
|
33
|
+
|
|
34
|
+
if (content.includes(PATCHED)) {
|
|
35
|
+
definitionFound = true // already patched by an earlier run
|
|
36
|
+
continue
|
|
37
|
+
}
|
|
38
|
+
if (!content.includes(ORIGINAL)) continue // entry stub / file without the filter definition
|
|
39
|
+
|
|
40
|
+
definitionFound = true
|
|
41
|
+
await fs.writeFile(file, content.replaceAll(ORIGINAL, PATCHED))
|
|
42
|
+
patched.push(rel)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!integrationFound) return // VE not installed here
|
|
46
|
+
|
|
47
|
+
if (!definitionFound) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`@10stars/config: found @vanilla-extract/integration but not its cssFileFilter definition — ` +
|
|
50
|
+
`the VE build likely changed. Update ORIGINAL in src/patch-vanilla-extract.ts.`,
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (patched.length) {
|
|
55
|
+
console.info(`Patched @vanilla-extract file filter to css.ts (${patched.length} file(s))`)
|
|
56
|
+
}
|
|
57
|
+
}
|