@csszyx/unplugin 0.12.0 → 0.14.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 +8 -10
- package/dist/index.cjs +14 -7
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/next-config.cjs +3 -0
- package/dist/next-config.d.cts +13 -2
- package/dist/next-config.d.mts +13 -2
- package/dist/next-config.mjs +3 -0
- package/dist/next-prebuild.cjs +13 -7
- package/dist/next-prebuild.d.cts +8 -2
- package/dist/next-prebuild.d.mts +8 -2
- package/dist/next-prebuild.mjs +13 -7
- package/dist/next-turbo-loader.cjs +31 -15
- package/dist/next-turbo-loader.d.cts +11 -2
- package/dist/next-turbo-loader.d.mts +11 -2
- package/dist/next-turbo-loader.mjs +30 -14
- package/dist/next-watcher.cjs +1 -1
- package/dist/next-watcher.mjs +1 -1
- package/dist/shared/{unplugin.CXV7fOa2.d.cts → unplugin.B32Exn-K.d.cts} +2 -2
- package/dist/shared/{unplugin.CXV7fOa2.d.mts → unplugin.B32Exn-K.d.mts} +2 -2
- package/dist/shared/{unplugin.Bb5TeU9B.cjs → unplugin.BJiWWF6w.cjs} +93 -23
- package/dist/shared/unplugin.BKGCkMgM.cjs +523 -0
- package/dist/shared/{unplugin.DMcbmP01.mjs → unplugin.BU0O4IkX.mjs} +4 -1
- package/dist/shared/unplugin.BcsvXjIV.mjs +579 -0
- package/dist/shared/{unplugin.CtnKJhAi.d.cts → unplugin.BsjD3mtb.d.cts} +165 -33
- package/dist/shared/{unplugin.CtnKJhAi.d.mts → unplugin.BsjD3mtb.d.mts} +165 -33
- package/dist/shared/{unplugin.DblMogcN.cjs → unplugin.Cji6O5jv.cjs} +4 -1
- package/dist/shared/unplugin.CkNQjA4G.cjs +613 -0
- package/dist/shared/unplugin.DKcwO8O4.mjs +490 -0
- package/dist/shared/{unplugin.DXgxFHzO.mjs → unplugin.DjRylBC_.mjs} +77 -25
- package/dist/shared/{unplugin.BK3XVHe8.cjs → unplugin.ZMa9YE1H.cjs} +621 -615
- package/dist/shared/{unplugin.B9vpjOhD.mjs → unplugin.gR_h2DVG.mjs} +585 -582
- package/dist/vite.cjs +3 -3
- package/dist/vite.d.cts +2 -2
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +3 -3
- package/dist/webpack.cjs +3 -3
- package/dist/webpack.d.cts +2 -2
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.mjs +3 -3
- package/package.json +9 -9
- package/dist/shared/unplugin.C2lHQFii.cjs +0 -114
- package/dist/shared/unplugin.CBMJufQ8.mjs +0 -108
- package/dist/shared/unplugin.CDqY7kmk.mjs +0 -224
- package/dist/shared/unplugin.DbZ7tCfN.cjs +0 -248
package/dist/vite.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const unplugin = require('./shared/unplugin.
|
|
5
|
+
const unplugin = require('./shared/unplugin.ZMa9YE1H.cjs');
|
|
6
6
|
require('node:crypto');
|
|
7
7
|
require('node:fs');
|
|
8
8
|
require('node:module');
|
|
@@ -16,11 +16,11 @@ require('@csszyx/svelte-adapter');
|
|
|
16
16
|
require('@csszyx/types');
|
|
17
17
|
require('@csszyx/vue-adapter');
|
|
18
18
|
require('unplugin');
|
|
19
|
-
require('./shared/unplugin.
|
|
19
|
+
require('./shared/unplugin.BKGCkMgM.cjs');
|
|
20
20
|
require('./css-mangler.cjs');
|
|
21
21
|
require('postcss');
|
|
22
22
|
require('postcss-selector-parser');
|
|
23
|
-
require('./shared/unplugin.
|
|
23
|
+
require('./shared/unplugin.CkNQjA4G.cjs');
|
|
24
24
|
require('./shared/unplugin.BkRah5Ot.cjs');
|
|
25
25
|
require('node:zlib');
|
|
26
26
|
require('postcss-value-parser');
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.mts
CHANGED
package/dist/vite.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a4 as default } from './shared/unplugin.gR_h2DVG.mjs';
|
|
2
2
|
import 'node:crypto';
|
|
3
3
|
import 'node:fs';
|
|
4
4
|
import 'node:module';
|
|
@@ -12,11 +12,11 @@ import '@csszyx/svelte-adapter';
|
|
|
12
12
|
import '@csszyx/types';
|
|
13
13
|
import '@csszyx/vue-adapter';
|
|
14
14
|
import 'unplugin';
|
|
15
|
-
import './shared/unplugin.
|
|
15
|
+
import './shared/unplugin.DKcwO8O4.mjs';
|
|
16
16
|
import './css-mangler.mjs';
|
|
17
17
|
import 'postcss';
|
|
18
18
|
import 'postcss-selector-parser';
|
|
19
|
-
import './shared/unplugin.
|
|
19
|
+
import './shared/unplugin.BcsvXjIV.mjs';
|
|
20
20
|
import './shared/unplugin.B3XoSRB8.mjs';
|
|
21
21
|
import 'node:zlib';
|
|
22
22
|
import 'postcss-value-parser';
|
package/dist/webpack.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const unplugin = require('./shared/unplugin.
|
|
5
|
+
const unplugin = require('./shared/unplugin.ZMa9YE1H.cjs');
|
|
6
6
|
require('node:crypto');
|
|
7
7
|
require('node:fs');
|
|
8
8
|
require('node:module');
|
|
@@ -16,11 +16,11 @@ require('@csszyx/svelte-adapter');
|
|
|
16
16
|
require('@csszyx/types');
|
|
17
17
|
require('@csszyx/vue-adapter');
|
|
18
18
|
require('unplugin');
|
|
19
|
-
require('./shared/unplugin.
|
|
19
|
+
require('./shared/unplugin.BKGCkMgM.cjs');
|
|
20
20
|
require('./css-mangler.cjs');
|
|
21
21
|
require('postcss');
|
|
22
22
|
require('postcss-selector-parser');
|
|
23
|
-
require('./shared/unplugin.
|
|
23
|
+
require('./shared/unplugin.CkNQjA4G.cjs');
|
|
24
24
|
require('./shared/unplugin.BkRah5Ot.cjs');
|
|
25
25
|
require('node:zlib');
|
|
26
26
|
require('postcss-value-parser');
|
package/dist/webpack.d.cts
CHANGED
package/dist/webpack.d.mts
CHANGED
package/dist/webpack.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a6 as default } from './shared/unplugin.gR_h2DVG.mjs';
|
|
2
2
|
import 'node:crypto';
|
|
3
3
|
import 'node:fs';
|
|
4
4
|
import 'node:module';
|
|
@@ -12,11 +12,11 @@ import '@csszyx/svelte-adapter';
|
|
|
12
12
|
import '@csszyx/types';
|
|
13
13
|
import '@csszyx/vue-adapter';
|
|
14
14
|
import 'unplugin';
|
|
15
|
-
import './shared/unplugin.
|
|
15
|
+
import './shared/unplugin.DKcwO8O4.mjs';
|
|
16
16
|
import './css-mangler.mjs';
|
|
17
17
|
import 'postcss';
|
|
18
18
|
import 'postcss-selector-parser';
|
|
19
|
-
import './shared/unplugin.
|
|
19
|
+
import './shared/unplugin.BcsvXjIV.mjs';
|
|
20
20
|
import './shared/unplugin.B3XoSRB8.mjs';
|
|
21
21
|
import 'node:zlib';
|
|
22
22
|
import 'postcss-value-parser';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csszyx/unplugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Vite and Webpack integration for csszyx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"csszyx",
|
|
@@ -117,14 +117,14 @@
|
|
|
117
117
|
"postcss-value-parser": "^4.2.0",
|
|
118
118
|
"proper-lockfile": "^4.1.2",
|
|
119
119
|
"unplugin": "^3.3.0",
|
|
120
|
-
"@csszyx/compiler": "0.
|
|
121
|
-
"@csszyx/core": "0.
|
|
122
|
-
"@csszyx/svelte-adapter": "0.
|
|
123
|
-
"@csszyx/vue-adapter": "0.
|
|
124
|
-
"@csszyx/types": "0.
|
|
120
|
+
"@csszyx/compiler": "0.14.0",
|
|
121
|
+
"@csszyx/core": "0.14.0",
|
|
122
|
+
"@csszyx/svelte-adapter": "0.14.0",
|
|
123
|
+
"@csszyx/vue-adapter": "0.14.0",
|
|
124
|
+
"@csszyx/types": "0.14.0"
|
|
125
125
|
},
|
|
126
126
|
"peerDependencies": {
|
|
127
|
-
"@csszyx/runtime": "^0.
|
|
127
|
+
"@csszyx/runtime": "^0.14.0"
|
|
128
128
|
},
|
|
129
129
|
"devDependencies": {
|
|
130
130
|
"@tailwindcss/node": "4.3.3",
|
|
@@ -137,8 +137,8 @@
|
|
|
137
137
|
"vite": "^8.1.5",
|
|
138
138
|
"vitest": "^4.1.10",
|
|
139
139
|
"webpack": "^5.109.0",
|
|
140
|
-
"@csszyx/
|
|
141
|
-
"@csszyx/
|
|
140
|
+
"@csszyx/tooling-metadata": "0.14.0",
|
|
141
|
+
"@csszyx/runtime": "0.14.0"
|
|
142
142
|
},
|
|
143
143
|
"sideEffects": false,
|
|
144
144
|
"engines": {
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const LEADING_WHITESPACE_RE = /^\s+/;
|
|
4
|
-
const LINE_COMMENT_RE = /^\/\/[^\n]*(?:\n|$)/;
|
|
5
|
-
const BLOCK_COMMENT_RE = /^\/\*[\s\S]*?\*\//;
|
|
6
|
-
const USE_DIRECTIVE_RE = /^['"]use (?:client|server)['"];?\s*/;
|
|
7
|
-
function insertAfterUseDirective(code, insertion) {
|
|
8
|
-
let offset = 0;
|
|
9
|
-
while (offset < code.length) {
|
|
10
|
-
const triviaLength = leadingTriviaLength(code.slice(offset));
|
|
11
|
-
if (triviaLength === 0) break;
|
|
12
|
-
offset += triviaLength;
|
|
13
|
-
}
|
|
14
|
-
const directive = USE_DIRECTIVE_RE.exec(code.slice(offset));
|
|
15
|
-
if (!directive) return `${insertion}${code}`;
|
|
16
|
-
const insertionOffset = offset + directive[0].length;
|
|
17
|
-
return `${code.slice(0, insertionOffset)}${insertion}${code.slice(insertionOffset)}`;
|
|
18
|
-
}
|
|
19
|
-
function leadingTriviaLength(source) {
|
|
20
|
-
return LEADING_WHITESPACE_RE.exec(source)?.[0].length ?? LINE_COMMENT_RE.exec(source)?.[0].length ?? BLOCK_COMMENT_RE.exec(source)?.[0].length ?? 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const RUNTIME_IMPORT_CLAUSE_RE = /(?:import|export)\s+\{([^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/g;
|
|
24
|
-
function clauseNames(clauseBody) {
|
|
25
|
-
const names = [];
|
|
26
|
-
for (const part of clauseBody.split(",")) {
|
|
27
|
-
const trimmed = part.trim();
|
|
28
|
-
if (!trimmed) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const spaceAt = trimmed.search(/\s/);
|
|
32
|
-
names.push(spaceAt === -1 ? trimmed : trimmed.slice(0, spaceAt));
|
|
33
|
-
}
|
|
34
|
-
return names;
|
|
35
|
-
}
|
|
36
|
-
function importsRuntimeHelper(code, helper) {
|
|
37
|
-
RUNTIME_IMPORT_CLAUSE_RE.lastIndex = 0;
|
|
38
|
-
for (let match = RUNTIME_IMPORT_CLAUSE_RE.exec(code); match; match = RUNTIME_IMPORT_CLAUSE_RE.exec(code)) {
|
|
39
|
-
if (clauseNames(match[1]).includes(helper)) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
const RUNTIME_IMPORT_APPEND_RE = /(import\s+\{[^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/;
|
|
46
|
-
function findRuntimeImportClause(code) {
|
|
47
|
-
const match = RUNTIME_IMPORT_APPEND_RE.exec(code);
|
|
48
|
-
return match ? { statement: match[0], prefixWithBody: match[1] } : null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function runtimeHelperGroupsFromUsage(usage) {
|
|
52
|
-
const slim = usage.usesSzPart === true && usage.szPartArgsProvable === true && usage.usesRuntime !== true && usage.usesMerge !== true;
|
|
53
|
-
const groups = { all: [], barrel: [], merge: [] };
|
|
54
|
-
const append = (helper, toMerge = false) => {
|
|
55
|
-
groups.all.push(helper);
|
|
56
|
-
(toMerge ? groups.merge : groups.barrel).push(helper);
|
|
57
|
-
};
|
|
58
|
-
if (usage.usesRuntime) append("_sz");
|
|
59
|
-
if (usage.usesMerge) append("_szMerge");
|
|
60
|
-
if (usage.usesSzcn) append("_szcn", slim);
|
|
61
|
-
if (usage.usesSzPart) append("_szPart", slim);
|
|
62
|
-
if (usage.usesSzvPick) append("__szvPick");
|
|
63
|
-
if (usage.usesSzvPick1) append("__szvPick1");
|
|
64
|
-
if (usage.usesColorVar) append("__szColorVar");
|
|
65
|
-
if (usage.usesSpacingVar) append("__szSpacingVar");
|
|
66
|
-
if (usage.usesUnitVar) append("__szUnitVar");
|
|
67
|
-
return groups;
|
|
68
|
-
}
|
|
69
|
-
function injectNextRuntimeImports(code, usage) {
|
|
70
|
-
const groups = runtimeHelperGroupsFromUsage(usage);
|
|
71
|
-
const helpers = groups.all;
|
|
72
|
-
if (helpers.length === 0) {
|
|
73
|
-
return { code, injected: [] };
|
|
74
|
-
}
|
|
75
|
-
const hasRuntimeImport = code.includes("@csszyx/runtime");
|
|
76
|
-
const missing = hasRuntimeImport ? helpers.filter((helper) => !importsRuntimeHelper(code, helper)) : helpers;
|
|
77
|
-
if (missing.length === 0) {
|
|
78
|
-
return { code, injected: [] };
|
|
79
|
-
}
|
|
80
|
-
if (groups.merge.length > 0) {
|
|
81
|
-
const mergeHelpers = missing.filter((helper) => groups.merge.includes(helper));
|
|
82
|
-
const barrelHelpers = missing.filter((helper) => groups.barrel.includes(helper));
|
|
83
|
-
let next = insertRuntimeImport(
|
|
84
|
-
code,
|
|
85
|
-
`import { ${mergeHelpers.join(", ")} } from '@csszyx/runtime/merge';
|
|
86
|
-
`
|
|
87
|
-
);
|
|
88
|
-
if (barrelHelpers.length > 0) {
|
|
89
|
-
next = insertRuntimeImport(
|
|
90
|
-
next,
|
|
91
|
-
`import { ${barrelHelpers.join(", ")} } from '@csszyx/runtime';
|
|
92
|
-
`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return { code: next, injected: missing };
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
code: insertRuntimeImport(
|
|
99
|
-
code,
|
|
100
|
-
`import { ${missing.join(", ")} } from '@csszyx/runtime';
|
|
101
|
-
`
|
|
102
|
-
),
|
|
103
|
-
injected: missing
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
function insertRuntimeImport(code, importStmt) {
|
|
107
|
-
return insertAfterUseDirective(code, importStmt);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
exports.findRuntimeImportClause = findRuntimeImportClause;
|
|
111
|
-
exports.importsRuntimeHelper = importsRuntimeHelper;
|
|
112
|
-
exports.injectNextRuntimeImports = injectNextRuntimeImports;
|
|
113
|
-
exports.insertAfterUseDirective = insertAfterUseDirective;
|
|
114
|
-
exports.runtimeHelperGroupsFromUsage = runtimeHelperGroupsFromUsage;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
const LEADING_WHITESPACE_RE = /^\s+/;
|
|
2
|
-
const LINE_COMMENT_RE = /^\/\/[^\n]*(?:\n|$)/;
|
|
3
|
-
const BLOCK_COMMENT_RE = /^\/\*[\s\S]*?\*\//;
|
|
4
|
-
const USE_DIRECTIVE_RE = /^['"]use (?:client|server)['"];?\s*/;
|
|
5
|
-
function insertAfterUseDirective(code, insertion) {
|
|
6
|
-
let offset = 0;
|
|
7
|
-
while (offset < code.length) {
|
|
8
|
-
const triviaLength = leadingTriviaLength(code.slice(offset));
|
|
9
|
-
if (triviaLength === 0) break;
|
|
10
|
-
offset += triviaLength;
|
|
11
|
-
}
|
|
12
|
-
const directive = USE_DIRECTIVE_RE.exec(code.slice(offset));
|
|
13
|
-
if (!directive) return `${insertion}${code}`;
|
|
14
|
-
const insertionOffset = offset + directive[0].length;
|
|
15
|
-
return `${code.slice(0, insertionOffset)}${insertion}${code.slice(insertionOffset)}`;
|
|
16
|
-
}
|
|
17
|
-
function leadingTriviaLength(source) {
|
|
18
|
-
return LEADING_WHITESPACE_RE.exec(source)?.[0].length ?? LINE_COMMENT_RE.exec(source)?.[0].length ?? BLOCK_COMMENT_RE.exec(source)?.[0].length ?? 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const RUNTIME_IMPORT_CLAUSE_RE = /(?:import|export)\s+\{([^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/g;
|
|
22
|
-
function clauseNames(clauseBody) {
|
|
23
|
-
const names = [];
|
|
24
|
-
for (const part of clauseBody.split(",")) {
|
|
25
|
-
const trimmed = part.trim();
|
|
26
|
-
if (!trimmed) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const spaceAt = trimmed.search(/\s/);
|
|
30
|
-
names.push(spaceAt === -1 ? trimmed : trimmed.slice(0, spaceAt));
|
|
31
|
-
}
|
|
32
|
-
return names;
|
|
33
|
-
}
|
|
34
|
-
function importsRuntimeHelper(code, helper) {
|
|
35
|
-
RUNTIME_IMPORT_CLAUSE_RE.lastIndex = 0;
|
|
36
|
-
for (let match = RUNTIME_IMPORT_CLAUSE_RE.exec(code); match; match = RUNTIME_IMPORT_CLAUSE_RE.exec(code)) {
|
|
37
|
-
if (clauseNames(match[1]).includes(helper)) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const RUNTIME_IMPORT_APPEND_RE = /(import\s+\{[^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/;
|
|
44
|
-
function findRuntimeImportClause(code) {
|
|
45
|
-
const match = RUNTIME_IMPORT_APPEND_RE.exec(code);
|
|
46
|
-
return match ? { statement: match[0], prefixWithBody: match[1] } : null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function runtimeHelperGroupsFromUsage(usage) {
|
|
50
|
-
const slim = usage.usesSzPart === true && usage.szPartArgsProvable === true && usage.usesRuntime !== true && usage.usesMerge !== true;
|
|
51
|
-
const groups = { all: [], barrel: [], merge: [] };
|
|
52
|
-
const append = (helper, toMerge = false) => {
|
|
53
|
-
groups.all.push(helper);
|
|
54
|
-
(toMerge ? groups.merge : groups.barrel).push(helper);
|
|
55
|
-
};
|
|
56
|
-
if (usage.usesRuntime) append("_sz");
|
|
57
|
-
if (usage.usesMerge) append("_szMerge");
|
|
58
|
-
if (usage.usesSzcn) append("_szcn", slim);
|
|
59
|
-
if (usage.usesSzPart) append("_szPart", slim);
|
|
60
|
-
if (usage.usesSzvPick) append("__szvPick");
|
|
61
|
-
if (usage.usesSzvPick1) append("__szvPick1");
|
|
62
|
-
if (usage.usesColorVar) append("__szColorVar");
|
|
63
|
-
if (usage.usesSpacingVar) append("__szSpacingVar");
|
|
64
|
-
if (usage.usesUnitVar) append("__szUnitVar");
|
|
65
|
-
return groups;
|
|
66
|
-
}
|
|
67
|
-
function injectNextRuntimeImports(code, usage) {
|
|
68
|
-
const groups = runtimeHelperGroupsFromUsage(usage);
|
|
69
|
-
const helpers = groups.all;
|
|
70
|
-
if (helpers.length === 0) {
|
|
71
|
-
return { code, injected: [] };
|
|
72
|
-
}
|
|
73
|
-
const hasRuntimeImport = code.includes("@csszyx/runtime");
|
|
74
|
-
const missing = hasRuntimeImport ? helpers.filter((helper) => !importsRuntimeHelper(code, helper)) : helpers;
|
|
75
|
-
if (missing.length === 0) {
|
|
76
|
-
return { code, injected: [] };
|
|
77
|
-
}
|
|
78
|
-
if (groups.merge.length > 0) {
|
|
79
|
-
const mergeHelpers = missing.filter((helper) => groups.merge.includes(helper));
|
|
80
|
-
const barrelHelpers = missing.filter((helper) => groups.barrel.includes(helper));
|
|
81
|
-
let next = insertRuntimeImport(
|
|
82
|
-
code,
|
|
83
|
-
`import { ${mergeHelpers.join(", ")} } from '@csszyx/runtime/merge';
|
|
84
|
-
`
|
|
85
|
-
);
|
|
86
|
-
if (barrelHelpers.length > 0) {
|
|
87
|
-
next = insertRuntimeImport(
|
|
88
|
-
next,
|
|
89
|
-
`import { ${barrelHelpers.join(", ")} } from '@csszyx/runtime';
|
|
90
|
-
`
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
return { code: next, injected: missing };
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
code: insertRuntimeImport(
|
|
97
|
-
code,
|
|
98
|
-
`import { ${missing.join(", ")} } from '@csszyx/runtime';
|
|
99
|
-
`
|
|
100
|
-
),
|
|
101
|
-
injected: missing
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function insertRuntimeImport(code, importStmt) {
|
|
105
|
-
return insertAfterUseDirective(code, importStmt);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export { importsRuntimeHelper as a, insertAfterUseDirective as b, findRuntimeImportClause as f, injectNextRuntimeImports as i, runtimeHelperGroupsFromUsage as r };
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import { OxcNotImplementedError } from '@csszyx/compiler';
|
|
2
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
-
import * as fs from 'node:fs';
|
|
4
|
-
import * as path from 'node:path';
|
|
5
|
-
|
|
6
|
-
const WINDOWS_PATH_SEPARATOR = String.fromCodePoint(92);
|
|
7
|
-
function normalizePathSeparators(value) {
|
|
8
|
-
return value.split(WINDOWS_PATH_SEPARATOR).join("/");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function babelFallbackReason(error) {
|
|
12
|
-
if (error instanceof OxcNotImplementedError) {
|
|
13
|
-
return error.detail;
|
|
14
|
-
}
|
|
15
|
-
return error instanceof Error ? error.message : String(error);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const CACHE_SCHEMA_VERSION = 15;
|
|
19
|
-
function resolveTransformCacheDir(rootDir, cacheDir) {
|
|
20
|
-
return path.resolve(rootDir, cacheDir ?? ".csszyx/cache", "transform");
|
|
21
|
-
}
|
|
22
|
-
function createTransformCacheKey(input) {
|
|
23
|
-
const inputSha256 = createHash("sha256").update(input.source).digest("hex");
|
|
24
|
-
const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
|
|
25
|
-
const keyMaterial = [
|
|
26
|
-
`schema=${CACHE_SCHEMA_VERSION}`,
|
|
27
|
-
`plugin=${input.pluginVersion}`,
|
|
28
|
-
`compiler=${input.compilerVersion}`,
|
|
29
|
-
`native=${input.nativeIdentity ?? "none"}`,
|
|
30
|
-
`parser=${input.parserMode}`,
|
|
31
|
-
`producer=${input.producer}`,
|
|
32
|
-
`astBudget=${input.astBudget ?? "default"}`,
|
|
33
|
-
`mangleVars=${input.mangleVars === true}`,
|
|
34
|
-
`mangleVarHoistMaxDepth=${input.mangleVarHoistMaxDepth ?? "default"}`,
|
|
35
|
-
`globalVarAliases=${JSON.stringify(globalVarAliases)}`,
|
|
36
|
-
`crossModuleStatics=${input.crossModuleStatics ?? "none"}`,
|
|
37
|
-
`filename=${input.filename}`,
|
|
38
|
-
`source=${inputSha256}`
|
|
39
|
-
].join("\n");
|
|
40
|
-
return {
|
|
41
|
-
key: createHash("sha256").update(keyMaterial).digest("hex").slice(0, 16),
|
|
42
|
-
inputSha256
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function readTransformCache(cacheRoot, input, precomputedKey) {
|
|
46
|
-
const { key, inputSha256 } = precomputedKey ?? createTransformCacheKey(input);
|
|
47
|
-
const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
|
|
48
|
-
const file = cacheEntryPath(cacheRoot, key);
|
|
49
|
-
let entry;
|
|
50
|
-
try {
|
|
51
|
-
entry = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
52
|
-
} catch {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
if (entry.version !== CACHE_SCHEMA_VERSION || entry.pluginVersion !== input.pluginVersion || entry.compilerVersion !== input.compilerVersion || entry.nativeIdentity !== (input.nativeIdentity ?? null) || entry.parserMode !== input.parserMode || entry.producer !== input.producer || entry.astBudget !== (input.astBudget ?? null) || entry.mangleVars !== (input.mangleVars === true) || entry.mangleVarHoistMaxDepth !== (input.mangleVarHoistMaxDepth ?? null) || !sameGlobalVarAliases(entry.globalVarAliases, globalVarAliases) || entry.filename !== input.filename || entry.inputSha256 !== inputSha256) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
return deserializeResult(entry.result);
|
|
59
|
-
}
|
|
60
|
-
function writeTransformCache(cacheRoot, input, result, precomputedKey) {
|
|
61
|
-
const { key, inputSha256 } = precomputedKey ?? createTransformCacheKey(input);
|
|
62
|
-
const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
|
|
63
|
-
const file = cacheEntryPath(cacheRoot, key);
|
|
64
|
-
const dir = path.dirname(file);
|
|
65
|
-
const tmp = path.join(dir, `.tmp-${process.pid}-${Date.now()}-${randomUUID()}.json`);
|
|
66
|
-
const entry = {
|
|
67
|
-
version: CACHE_SCHEMA_VERSION,
|
|
68
|
-
pluginVersion: input.pluginVersion,
|
|
69
|
-
compilerVersion: input.compilerVersion,
|
|
70
|
-
nativeIdentity: input.nativeIdentity ?? null,
|
|
71
|
-
parserMode: input.parserMode,
|
|
72
|
-
producer: input.producer,
|
|
73
|
-
astBudget: input.astBudget ?? null,
|
|
74
|
-
mangleVars: input.mangleVars === true,
|
|
75
|
-
mangleVarHoistMaxDepth: input.mangleVarHoistMaxDepth ?? null,
|
|
76
|
-
globalVarAliases,
|
|
77
|
-
filename: input.filename,
|
|
78
|
-
inputSha256,
|
|
79
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
80
|
-
result: serializeResult(result)
|
|
81
|
-
};
|
|
82
|
-
try {
|
|
83
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
84
|
-
fs.writeFileSync(tmp, JSON.stringify(entry), "utf8");
|
|
85
|
-
fs.renameSync(tmp, file);
|
|
86
|
-
} catch {
|
|
87
|
-
try {
|
|
88
|
-
fs.rmSync(tmp, { force: true });
|
|
89
|
-
} catch {
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function evictOldTransformCacheEntries(cacheRoot, options) {
|
|
94
|
-
let deleted = 0;
|
|
95
|
-
const now = options.now ?? Date.now();
|
|
96
|
-
const survivors = [];
|
|
97
|
-
for (const file of listJsonFiles(cacheRoot)) {
|
|
98
|
-
try {
|
|
99
|
-
const entry = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
100
|
-
const timestamp = typeof entry.timestamp === "string" ? Date.parse(entry.timestamp) : 0;
|
|
101
|
-
if (!Number.isFinite(timestamp) || now - timestamp > options.maxAgeMs) {
|
|
102
|
-
fs.rmSync(file, { force: true });
|
|
103
|
-
deleted++;
|
|
104
|
-
} else {
|
|
105
|
-
survivors.push({ file, timestamp });
|
|
106
|
-
}
|
|
107
|
-
} catch {
|
|
108
|
-
fs.rmSync(file, { force: true });
|
|
109
|
-
deleted++;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const overflow = survivors.length - options.maxEntries ;
|
|
113
|
-
if (overflow > 0) {
|
|
114
|
-
survivors.sort((a, b) => a.timestamp - b.timestamp);
|
|
115
|
-
for (const survivor of survivors.slice(0, overflow)) {
|
|
116
|
-
fs.rmSync(survivor.file, { force: true });
|
|
117
|
-
deleted++;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return deleted;
|
|
121
|
-
}
|
|
122
|
-
function cacheEntryPath(cacheRoot, key) {
|
|
123
|
-
return path.join(cacheRoot, key.slice(0, 2), `${key.slice(2)}.json`);
|
|
124
|
-
}
|
|
125
|
-
function serializeResult(result) {
|
|
126
|
-
return {
|
|
127
|
-
code: result.code,
|
|
128
|
-
transformed: result.transformed,
|
|
129
|
-
usesRuntime: result.usesRuntime,
|
|
130
|
-
usesMerge: result.usesMerge,
|
|
131
|
-
usesSzcn: result.usesSzcn,
|
|
132
|
-
usesSzPart: result.usesSzPart,
|
|
133
|
-
usesSzvPick: result.usesSzvPick,
|
|
134
|
-
usesSzvPick1: result.usesSzvPick1,
|
|
135
|
-
szPartArgsProvable: result.szPartArgsProvable,
|
|
136
|
-
usesColorVar: result.usesColorVar,
|
|
137
|
-
usesSpacingVar: result.usesSpacingVar,
|
|
138
|
-
usesUnitVar: result.usesUnitVar,
|
|
139
|
-
classes: [...result.classes],
|
|
140
|
-
rawClassNames: [...result.rawClassNames],
|
|
141
|
-
diagnostics: [...result.diagnostics],
|
|
142
|
-
recoveryTokens: [...result.recoveryTokens],
|
|
143
|
-
cssVariableMap: [...result.cssVariableMap ?? /* @__PURE__ */ new Map()]
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function deserializeResult(result) {
|
|
147
|
-
return {
|
|
148
|
-
code: result.code,
|
|
149
|
-
transformed: result.transformed,
|
|
150
|
-
usesRuntime: result.usesRuntime,
|
|
151
|
-
usesMerge: result.usesMerge,
|
|
152
|
-
usesSzcn: result.usesSzcn,
|
|
153
|
-
usesSzPart: result.usesSzPart,
|
|
154
|
-
usesSzvPick: result.usesSzvPick,
|
|
155
|
-
usesSzvPick1: result.usesSzvPick1,
|
|
156
|
-
szPartArgsProvable: result.szPartArgsProvable,
|
|
157
|
-
usesColorVar: result.usesColorVar,
|
|
158
|
-
usesSpacingVar: result.usesSpacingVar,
|
|
159
|
-
usesUnitVar: result.usesUnitVar,
|
|
160
|
-
classes: new Set(result.classes),
|
|
161
|
-
rawClassNames: new Set(result.rawClassNames),
|
|
162
|
-
diagnostics: [...result.diagnostics],
|
|
163
|
-
recoveryTokens: new Map(result.recoveryTokens),
|
|
164
|
-
cssVariableMap: new Map(result.cssVariableMap ?? [])
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
function normalizeGlobalVarAliasEntries(aliases) {
|
|
168
|
-
if (!aliases || aliases.length === 0) {
|
|
169
|
-
return [];
|
|
170
|
-
}
|
|
171
|
-
const normalized = /* @__PURE__ */ new Map();
|
|
172
|
-
for (const [original, alias] of aliases) {
|
|
173
|
-
if (typeof original === "string" && typeof alias === "string") {
|
|
174
|
-
normalized.set(original, alias);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return [...normalized].sort(([left], [right]) => left.localeCompare(right));
|
|
178
|
-
}
|
|
179
|
-
function sameGlobalVarAliases(left, right) {
|
|
180
|
-
if (!Array.isArray(left) || left.length !== right.length) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
for (let index = 0; index < left.length; index++) {
|
|
184
|
-
const leftEntry = left[index];
|
|
185
|
-
const rightEntry = right[index];
|
|
186
|
-
if (leftEntry?.[0] !== rightEntry?.[0] || leftEntry?.[1] !== rightEntry?.[1]) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
function listJsonFiles(dir) {
|
|
193
|
-
let entries;
|
|
194
|
-
try {
|
|
195
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
196
|
-
} catch {
|
|
197
|
-
return [];
|
|
198
|
-
}
|
|
199
|
-
const files = [];
|
|
200
|
-
for (const entry of entries) {
|
|
201
|
-
const fullPath = path.join(dir, entry.name);
|
|
202
|
-
if (entry.isDirectory()) {
|
|
203
|
-
files.push(...listJsonFiles(fullPath));
|
|
204
|
-
} else if (entry.isFile() && entry.name.endsWith(".json")) {
|
|
205
|
-
files.push(fullPath);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return files;
|
|
209
|
-
}
|
|
210
|
-
function evictMemoryCacheToBudget(cache, totalCodeChars, maxEntries, maxCodeChars) {
|
|
211
|
-
let total = totalCodeChars;
|
|
212
|
-
while (cache.size > maxEntries || total > maxCodeChars && cache.size > 1) {
|
|
213
|
-
const oldest = cache.keys().next().value;
|
|
214
|
-
if (oldest === void 0) {
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
const evicted = cache.get(oldest);
|
|
218
|
-
cache.delete(oldest);
|
|
219
|
-
total -= evicted?.code.length ?? 0;
|
|
220
|
-
}
|
|
221
|
-
return total;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export { readTransformCache as a, babelFallbackReason as b, createTransformCacheKey as c, evictMemoryCacheToBudget as d, evictOldTransformCacheEntries as e, normalizePathSeparators as n, resolveTransformCacheDir as r, writeTransformCache as w };
|