@pandacss/parser 0.0.0-dev-20230716135255 → 0.0.0-dev-20230718085443
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/dist/index.d.mts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +24 -5
- package/dist/index.mjs +24 -5
- package/package.json +9 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ts_morph from 'ts-morph';
|
|
2
2
|
import { ProjectOptions as ProjectOptions$1 } from 'ts-morph';
|
|
3
|
-
import { ResultItem, RecipeConfig, PandaHookable } from '@pandacss/types';
|
|
3
|
+
import { ResultItem, RecipeConfig, ConfigTsOptions, Runtime, PandaHookable } from '@pandacss/types';
|
|
4
4
|
|
|
5
5
|
declare class ParserResult {
|
|
6
6
|
jsx: Set<ResultItem>;
|
|
@@ -48,21 +48,25 @@ type ParserRecipeNode = {
|
|
|
48
48
|
};
|
|
49
49
|
type ParserNodeOptions = ParserPatternNode | ParserRecipeNode;
|
|
50
50
|
type ParserOptions = {
|
|
51
|
-
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string>;
|
|
51
|
+
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string[]>;
|
|
52
52
|
jsx?: {
|
|
53
53
|
factory: string;
|
|
54
54
|
nodes: ParserNodeOptions[];
|
|
55
55
|
isStyleProp: (prop: string) => boolean;
|
|
56
56
|
};
|
|
57
57
|
getRecipesByJsxName: (jsxName: string) => RecipeConfig[];
|
|
58
|
+
tsOptions?: ConfigTsOptions;
|
|
59
|
+
join: Runtime['path']['join'];
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
type ProjectOptions = Partial<ProjectOptions$1> & {
|
|
61
|
-
readFile:
|
|
63
|
+
readFile: Runtime['fs']['readFileSync'];
|
|
62
64
|
getFiles: () => string[];
|
|
63
65
|
hooks: PandaHookable;
|
|
64
66
|
parserOptions: ParserOptions;
|
|
67
|
+
tsOptions?: ConfigTsOptions;
|
|
65
68
|
};
|
|
69
|
+
|
|
66
70
|
declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...projectOptions }: ProjectOptions) => {
|
|
67
71
|
getSourceFile: (filePath: string) => ts_morph.SourceFile | undefined;
|
|
68
72
|
removeSourceFile: (filePath: string) => void;
|
|
@@ -74,4 +78,4 @@ declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...pro
|
|
|
74
78
|
};
|
|
75
79
|
type Project = ReturnType<typeof createProject>;
|
|
76
80
|
|
|
77
|
-
export { ParserResult, Project,
|
|
81
|
+
export { ParserResult, Project, createParserResult, createProject };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ts_morph from 'ts-morph';
|
|
2
2
|
import { ProjectOptions as ProjectOptions$1 } from 'ts-morph';
|
|
3
|
-
import { ResultItem, RecipeConfig, PandaHookable } from '@pandacss/types';
|
|
3
|
+
import { ResultItem, RecipeConfig, ConfigTsOptions, Runtime, PandaHookable } from '@pandacss/types';
|
|
4
4
|
|
|
5
5
|
declare class ParserResult {
|
|
6
6
|
jsx: Set<ResultItem>;
|
|
@@ -48,21 +48,25 @@ type ParserRecipeNode = {
|
|
|
48
48
|
};
|
|
49
49
|
type ParserNodeOptions = ParserPatternNode | ParserRecipeNode;
|
|
50
50
|
type ParserOptions = {
|
|
51
|
-
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string>;
|
|
51
|
+
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string[]>;
|
|
52
52
|
jsx?: {
|
|
53
53
|
factory: string;
|
|
54
54
|
nodes: ParserNodeOptions[];
|
|
55
55
|
isStyleProp: (prop: string) => boolean;
|
|
56
56
|
};
|
|
57
57
|
getRecipesByJsxName: (jsxName: string) => RecipeConfig[];
|
|
58
|
+
tsOptions?: ConfigTsOptions;
|
|
59
|
+
join: Runtime['path']['join'];
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
type ProjectOptions = Partial<ProjectOptions$1> & {
|
|
61
|
-
readFile:
|
|
63
|
+
readFile: Runtime['fs']['readFileSync'];
|
|
62
64
|
getFiles: () => string[];
|
|
63
65
|
hooks: PandaHookable;
|
|
64
66
|
parserOptions: ParserOptions;
|
|
67
|
+
tsOptions?: ConfigTsOptions;
|
|
65
68
|
};
|
|
69
|
+
|
|
66
70
|
declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...projectOptions }: ProjectOptions) => {
|
|
67
71
|
getSourceFile: (filePath: string) => ts_morph.SourceFile | undefined;
|
|
68
72
|
removeSourceFile: (filePath: string) => void;
|
|
@@ -74,4 +78,4 @@ declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...pro
|
|
|
74
78
|
};
|
|
75
79
|
type Project = ReturnType<typeof createProject>;
|
|
76
80
|
|
|
77
|
-
export { ParserResult, Project,
|
|
81
|
+
export { ParserResult, Project, createParserResult, createProject };
|
package/dist/index.js
CHANGED
|
@@ -67,9 +67,10 @@ function getImportDeclarations(file, options) {
|
|
|
67
67
|
specifiers.forEach((specifier) => {
|
|
68
68
|
const name = specifier.getNameNode().getText();
|
|
69
69
|
const alias = specifier.getAliasNode()?.getText() || name;
|
|
70
|
-
|
|
70
|
+
const importMapValue = match2({ name, alias, mod: source });
|
|
71
|
+
if (!importMapValue)
|
|
71
72
|
return;
|
|
72
|
-
result.push({ name, alias, mod: source });
|
|
73
|
+
result.push({ name, alias, mod: source, importMapValue });
|
|
73
74
|
});
|
|
74
75
|
});
|
|
75
76
|
return {
|
|
@@ -81,7 +82,7 @@ function getImportDeclarations(file, options) {
|
|
|
81
82
|
return result.find((o) => o.alias === id);
|
|
82
83
|
},
|
|
83
84
|
createMatch(mod) {
|
|
84
|
-
const mods = result.filter((o) => o.mod.includes(mod));
|
|
85
|
+
const mods = result.filter((o) => o.mod.includes(mod) || o.importMapValue === mod);
|
|
85
86
|
return (0, import_shared.memo)((id) => !!mods.find((mod2) => mod2.alias === id || mod2.name === id));
|
|
86
87
|
},
|
|
87
88
|
match(id) {
|
|
@@ -174,6 +175,7 @@ var ParserResult = class _ParserResult {
|
|
|
174
175
|
var createParserResult = () => new ParserResult();
|
|
175
176
|
|
|
176
177
|
// src/parser.ts
|
|
178
|
+
var import_ts_path = require("@pandacss/config/ts-path");
|
|
177
179
|
var isNodeRecipe = (node) => node.type === "recipe";
|
|
178
180
|
var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
|
|
179
181
|
var isCva = (map) => cvaProps.some((prop) => map.has(prop));
|
|
@@ -197,7 +199,8 @@ var fallback = (box2) => ({
|
|
|
197
199
|
});
|
|
198
200
|
var defaultEnv = { preset: "NONE" };
|
|
199
201
|
function createParser(options) {
|
|
200
|
-
const { jsx,
|
|
202
|
+
const { jsx, getRecipesByJsxName, tsOptions, join } = options;
|
|
203
|
+
const importMap = Object.fromEntries(Object.entries(options.importMap).map(([key, value]) => [key, join(...value)]));
|
|
201
204
|
const importRegex = [
|
|
202
205
|
createImportMatcher(importMap.css, ["css", "cva"]),
|
|
203
206
|
createImportMatcher(importMap.recipe),
|
|
@@ -212,7 +215,23 @@ function createParser(options) {
|
|
|
212
215
|
const filePath = sourceFile.getFilePath();
|
|
213
216
|
const imports = getImportDeclarations(sourceFile, {
|
|
214
217
|
match(value) {
|
|
215
|
-
|
|
218
|
+
let found = false;
|
|
219
|
+
for (const { regex, mod } of importRegex) {
|
|
220
|
+
if (!regex.test(value.name))
|
|
221
|
+
continue;
|
|
222
|
+
if (value.mod.includes(mod)) {
|
|
223
|
+
found = true;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (tsOptions?.pathMappings) {
|
|
227
|
+
const filename = (0, import_ts_path.resolveTsPathPattern)(tsOptions.pathMappings, value.mod);
|
|
228
|
+
if (filename?.includes(mod)) {
|
|
229
|
+
found = mod;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return found;
|
|
216
235
|
}
|
|
217
236
|
});
|
|
218
237
|
const collector = createParserResult();
|
package/dist/index.mjs
CHANGED
|
@@ -29,9 +29,10 @@ function getImportDeclarations(file, options) {
|
|
|
29
29
|
specifiers.forEach((specifier) => {
|
|
30
30
|
const name = specifier.getNameNode().getText();
|
|
31
31
|
const alias = specifier.getAliasNode()?.getText() || name;
|
|
32
|
-
|
|
32
|
+
const importMapValue = match2({ name, alias, mod: source });
|
|
33
|
+
if (!importMapValue)
|
|
33
34
|
return;
|
|
34
|
-
result.push({ name, alias, mod: source });
|
|
35
|
+
result.push({ name, alias, mod: source, importMapValue });
|
|
35
36
|
});
|
|
36
37
|
});
|
|
37
38
|
return {
|
|
@@ -43,7 +44,7 @@ function getImportDeclarations(file, options) {
|
|
|
43
44
|
return result.find((o) => o.alias === id);
|
|
44
45
|
},
|
|
45
46
|
createMatch(mod) {
|
|
46
|
-
const mods = result.filter((o) => o.mod.includes(mod));
|
|
47
|
+
const mods = result.filter((o) => o.mod.includes(mod) || o.importMapValue === mod);
|
|
47
48
|
return memo((id) => !!mods.find((mod2) => mod2.alias === id || mod2.name === id));
|
|
48
49
|
},
|
|
49
50
|
match(id) {
|
|
@@ -136,6 +137,7 @@ var ParserResult = class _ParserResult {
|
|
|
136
137
|
var createParserResult = () => new ParserResult();
|
|
137
138
|
|
|
138
139
|
// src/parser.ts
|
|
140
|
+
import { resolveTsPathPattern } from "@pandacss/config/ts-path";
|
|
139
141
|
var isNodeRecipe = (node) => node.type === "recipe";
|
|
140
142
|
var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
|
|
141
143
|
var isCva = (map) => cvaProps.some((prop) => map.has(prop));
|
|
@@ -159,7 +161,8 @@ var fallback = (box2) => ({
|
|
|
159
161
|
});
|
|
160
162
|
var defaultEnv = { preset: "NONE" };
|
|
161
163
|
function createParser(options) {
|
|
162
|
-
const { jsx,
|
|
164
|
+
const { jsx, getRecipesByJsxName, tsOptions, join } = options;
|
|
165
|
+
const importMap = Object.fromEntries(Object.entries(options.importMap).map(([key, value]) => [key, join(...value)]));
|
|
163
166
|
const importRegex = [
|
|
164
167
|
createImportMatcher(importMap.css, ["css", "cva"]),
|
|
165
168
|
createImportMatcher(importMap.recipe),
|
|
@@ -174,7 +177,23 @@ function createParser(options) {
|
|
|
174
177
|
const filePath = sourceFile.getFilePath();
|
|
175
178
|
const imports = getImportDeclarations(sourceFile, {
|
|
176
179
|
match(value) {
|
|
177
|
-
|
|
180
|
+
let found = false;
|
|
181
|
+
for (const { regex, mod } of importRegex) {
|
|
182
|
+
if (!regex.test(value.name))
|
|
183
|
+
continue;
|
|
184
|
+
if (value.mod.includes(mod)) {
|
|
185
|
+
found = true;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
if (tsOptions?.pathMappings) {
|
|
189
|
+
const filename = resolveTsPathPattern(tsOptions.pathMappings, value.mod);
|
|
190
|
+
if (filename?.includes(mod)) {
|
|
191
|
+
found = mod;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return found;
|
|
178
197
|
}
|
|
179
198
|
});
|
|
180
199
|
const collector = createParserResult();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/parser",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20230718085443",
|
|
4
4
|
"description": "The static parser for panda css",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -16,16 +16,17 @@
|
|
|
16
16
|
"magic-string": "^0.30.1",
|
|
17
17
|
"ts-morph": "18.0.0",
|
|
18
18
|
"ts-pattern": "5.0.1",
|
|
19
|
-
"@pandacss/
|
|
20
|
-
"@pandacss/
|
|
21
|
-
"@pandacss/
|
|
22
|
-
"@pandacss/
|
|
23
|
-
"@pandacss/
|
|
19
|
+
"@pandacss/config": "^0.0.0-dev-20230718085443",
|
|
20
|
+
"@pandacss/extractor": "0.0.0-dev-20230718085443",
|
|
21
|
+
"@pandacss/is-valid-prop": "0.0.0-dev-20230718085443",
|
|
22
|
+
"@pandacss/logger": "0.0.0-dev-20230718085443",
|
|
23
|
+
"@pandacss/shared": "0.0.0-dev-20230718085443",
|
|
24
|
+
"@pandacss/types": "0.0.0-dev-20230718085443"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"hookable": "5.5.3",
|
|
27
|
-
"@pandacss/fixture": "0.0.0-dev-
|
|
28
|
-
"@pandacss/generator": "0.0.0-dev-
|
|
28
|
+
"@pandacss/fixture": "0.0.0-dev-20230718085443",
|
|
29
|
+
"@pandacss/generator": "0.0.0-dev-20230718085443"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
31
32
|
"dist"
|