@pandacss/parser 0.0.0-dev-20230203184408 → 0.0.0-dev-20230204123646

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.ts CHANGED
@@ -1,32 +1,28 @@
1
- import { ProjectOptions, Project, SourceFile } from 'ts-morph';
1
+ import * as ts_morph from 'ts-morph';
2
+ import { ProjectOptions as ProjectOptions$1 } from 'ts-morph';
2
3
 
3
4
  type Result = {
4
5
  name?: string;
5
6
  data: Record<string, any>;
6
7
  type?: string;
7
8
  };
8
- declare class Collector {
9
+ type PartialResult = {
10
+ data: Record<string, any>;
11
+ };
12
+ declare const createParserResult: () => {
9
13
  jsx: Set<Result>;
10
14
  css: Set<Result>;
11
15
  cva: Set<Result>;
12
16
  recipe: Map<string, Set<Result>>;
13
17
  pattern: Map<string, Set<Result>>;
14
- set(name: string, result: {
15
- data: Record<string, any>;
16
- }): void;
17
- setCva(result: {
18
- data: Record<string, any>;
19
- }): void;
20
- setPattern(name: string, result: {
21
- data: Record<string, any>;
22
- }): void;
23
- setRecipe(name: string, result: {
24
- data: Record<string, any>;
25
- }): void;
26
- get isEmpty(): boolean;
27
- }
18
+ set(name: 'cva' | 'css', result: PartialResult): void;
19
+ setCva(result: PartialResult): void;
20
+ setPattern(name: string, result: PartialResult): void;
21
+ setRecipe(name: string, result: PartialResult): void;
22
+ isEmpty(): boolean;
23
+ };
24
+ type ParserResult = ReturnType<typeof createParserResult>;
28
25
 
29
- declare function createProject(options?: Partial<ProjectOptions>): Project;
30
26
  type ParserNodeOptions = {
31
27
  name: string;
32
28
  type: 'pattern' | 'recipe';
@@ -40,6 +36,59 @@ type ParserOptions = {
40
36
  isStyleProp: (prop: string) => boolean;
41
37
  };
42
38
  };
43
- declare function createParser(options: ParserOptions): (sourceFile: SourceFile | undefined) => Collector | undefined;
44
39
 
45
- export { Collector, createParser, createProject };
40
+ type ProjectOptions = Partial<ProjectOptions$1> & {
41
+ readFile: (filePath: string) => string;
42
+ getFiles: () => string[];
43
+ parserOptions: ParserOptions;
44
+ };
45
+ declare const createProject: ({ getFiles, readFile, parserOptions, ...projectOptions }: ProjectOptions) => {
46
+ getSourceFile: (filePath: string) => ts_morph.SourceFile | undefined;
47
+ removeSourceFile: (filePath: string) => void;
48
+ createSourceFile: (filePath: string) => ts_morph.SourceFile;
49
+ parseSourceFile: (filePath: string) => {
50
+ jsx: Set<{
51
+ name?: string | undefined;
52
+ data: Record<string, any>;
53
+ type?: string | undefined;
54
+ }>;
55
+ css: Set<{
56
+ name?: string | undefined;
57
+ data: Record<string, any>;
58
+ type?: string | undefined;
59
+ }>;
60
+ cva: Set<{
61
+ name?: string | undefined;
62
+ data: Record<string, any>;
63
+ type?: string | undefined;
64
+ }>;
65
+ recipe: Map<string, Set<{
66
+ name?: string | undefined;
67
+ data: Record<string, any>;
68
+ type?: string | undefined;
69
+ }>>;
70
+ pattern: Map<string, Set<{
71
+ name?: string | undefined;
72
+ data: Record<string, any>;
73
+ type?: string | undefined;
74
+ }>>;
75
+ set(name: "cva" | "css", result: {
76
+ data: Record<string, any>;
77
+ }): void;
78
+ setCva(result: {
79
+ data: Record<string, any>;
80
+ }): void;
81
+ setPattern(name: string, result: {
82
+ data: Record<string, any>;
83
+ }): void;
84
+ setRecipe(name: string, result: {
85
+ data: Record<string, any>;
86
+ }): void;
87
+ isEmpty(): boolean;
88
+ } | undefined;
89
+ reloadSourceFile: (filePath: string) => ts_morph.FileSystemRefreshResult | undefined;
90
+ reloadSourceFiles: () => void;
91
+ };
92
+ type Project = ReturnType<typeof createProject>;
93
+
94
+ export { ParserResult, Project, ProjectOptions, createProject };
package/dist/index.js CHANGED
@@ -20,15 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- createParser: () => createParser,
24
23
  createProject: () => createProject
25
24
  });
26
25
  module.exports = __toCommonJS(src_exports);
27
26
 
27
+ // src/project.ts
28
+ var import_lil_fp = require("lil-fp");
29
+ var import_ts_morph4 = require("ts-morph");
30
+
28
31
  // src/parser.ts
29
32
  var import_logger = require("@pandacss/logger");
30
33
  var import_shared2 = require("@pandacss/shared");
31
- var import_ts_morph4 = require("ts-morph");
32
34
  var import_ts_pattern3 = require("ts-pattern");
33
35
 
34
36
  // src/call-expression.ts
@@ -136,32 +138,6 @@ function visitCallExpressions(file, options) {
136
138
  }
137
139
  }
138
140
 
139
- // src/collector.ts
140
- var Collector = class {
141
- jsx = /* @__PURE__ */ new Set();
142
- css = /* @__PURE__ */ new Set();
143
- cva = /* @__PURE__ */ new Set();
144
- recipe = /* @__PURE__ */ new Map();
145
- pattern = /* @__PURE__ */ new Map();
146
- set(name, result) {
147
- this[name].add({ type: "object", ...result });
148
- }
149
- setCva(result) {
150
- this.cva.add({ type: "cva", ...result });
151
- }
152
- setPattern(name, result) {
153
- this.pattern.get(name) ?? this.pattern.set(name, /* @__PURE__ */ new Set());
154
- this.pattern.get(name)?.add({ type: "pattern", name, ...result });
155
- }
156
- setRecipe(name, result) {
157
- this.recipe.get(name) ?? this.recipe.set(name, /* @__PURE__ */ new Set());
158
- this.recipe.get(name)?.add({ type: "recipe", ...result });
159
- }
160
- get isEmpty() {
161
- return this.css.size === 0 && this.cva.size === 0 && this.recipe.size === 0 && this.pattern.size === 0 && this.jsx.size === 0;
162
- }
163
- };
164
-
165
141
  // src/import.ts
166
142
  var import_shared = require("@pandacss/shared");
167
143
  function getImportDeclarations(file, options) {
@@ -247,21 +223,33 @@ function visitJsxElement(file, options) {
247
223
  }
248
224
  }
249
225
 
226
+ // src/parser-result.ts
227
+ var createParserResult = () => ({
228
+ jsx: /* @__PURE__ */ new Set(),
229
+ css: /* @__PURE__ */ new Set(),
230
+ cva: /* @__PURE__ */ new Set(),
231
+ recipe: /* @__PURE__ */ new Map(),
232
+ pattern: /* @__PURE__ */ new Map(),
233
+ set(name, result) {
234
+ this[name].add({ type: "object", ...result });
235
+ },
236
+ setCva(result) {
237
+ this.cva.add({ type: "cva", ...result });
238
+ },
239
+ setPattern(name, result) {
240
+ this.pattern.get(name) ?? this.pattern.set(name, /* @__PURE__ */ new Set());
241
+ this.pattern.get(name)?.add({ type: "pattern", name, ...result });
242
+ },
243
+ setRecipe(name, result) {
244
+ this.recipe.get(name) ?? this.recipe.set(name, /* @__PURE__ */ new Set());
245
+ this.recipe.get(name)?.add({ type: "recipe", ...result });
246
+ },
247
+ isEmpty() {
248
+ return this.css.size === 0 && this.cva.size === 0 && this.recipe.size === 0 && this.pattern.size === 0 && this.jsx.size === 0;
249
+ }
250
+ });
251
+
250
252
  // src/parser.ts
251
- function createProject(options = {}) {
252
- return new import_ts_morph4.Project({
253
- skipAddingFilesFromTsConfig: true,
254
- skipFileDependencyResolution: true,
255
- skipLoadingLibFiles: true,
256
- ...options,
257
- compilerOptions: {
258
- allowJs: true,
259
- strictNullChecks: false,
260
- skipLibCheck: true,
261
- ...options.compilerOptions
262
- }
263
- });
264
- }
265
253
  function createImportMatcher(mod, values) {
266
254
  const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
267
255
  return {
@@ -277,7 +265,7 @@ function createParser(options) {
277
265
  if (!sourceFile)
278
266
  return;
279
267
  const fileName = sourceFile.getFilePath();
280
- const collector = new Collector();
268
+ const collector = createParserResult();
281
269
  const { jsx, importMap } = options;
282
270
  const importRegex = [
283
271
  createImportMatcher(importMap.css, ["css", "cva"]),
@@ -349,8 +337,59 @@ function createParser(options) {
349
337
  };
350
338
  }
351
339
  var isUpperCase = (value) => value[0] === value[0].toUpperCase();
340
+
341
+ // src/project.ts
342
+ var createTsProject = (options) => new import_ts_morph4.Project({
343
+ skipAddingFilesFromTsConfig: true,
344
+ skipFileDependencyResolution: true,
345
+ skipLoadingLibFiles: true,
346
+ ...options,
347
+ compilerOptions: {
348
+ allowJs: true,
349
+ strictNullChecks: false,
350
+ skipLibCheck: true,
351
+ ...options.compilerOptions
352
+ }
353
+ });
354
+ var createProject = ({ getFiles, readFile, parserOptions, ...projectOptions }) => (0, import_lil_fp.pipe)(
355
+ {
356
+ project: createTsProject(projectOptions),
357
+ parser: createParser(parserOptions)
358
+ },
359
+ import_lil_fp.Obj.assign(({ project, parser }) => ({
360
+ getSourceFile: (filePath) => project.getSourceFile(filePath),
361
+ removeSourceFile: (filePath) => {
362
+ const sourceFile = project.getSourceFile(filePath);
363
+ if (sourceFile)
364
+ project.removeSourceFile(sourceFile);
365
+ },
366
+ createSourceFile: (filePath) => project.createSourceFile(filePath, readFile(filePath), {
367
+ overwrite: true,
368
+ scriptKind: import_ts_morph4.ScriptKind.TSX
369
+ }),
370
+ parseSourceFile: (filePath) => {
371
+ return parser(project.getSourceFile(filePath));
372
+ }
373
+ })),
374
+ (0, import_lil_fp.tap)(({ createSourceFile }) => {
375
+ const files = getFiles();
376
+ for (const file of files) {
377
+ createSourceFile(file);
378
+ }
379
+ }),
380
+ import_lil_fp.Obj.assign(({ getSourceFile, project }) => ({
381
+ reloadSourceFile: (filePath) => getSourceFile(filePath)?.refreshFromFileSystemSync(),
382
+ reloadSourceFiles: () => {
383
+ const files = getFiles();
384
+ for (const file of files) {
385
+ const source = getSourceFile(file);
386
+ source?.refreshFromFileSystemSync() ?? project.addSourceFileAtPath(file);
387
+ }
388
+ }
389
+ })),
390
+ import_lil_fp.Obj.omit(["project", "parser"])
391
+ );
352
392
  // Annotate the CommonJS export names for ESM import in node:
353
393
  0 && (module.exports = {
354
- createParser,
355
394
  createProject
356
395
  });
package/dist/index.mjs CHANGED
@@ -1,7 +1,10 @@
1
+ // src/project.ts
2
+ import { Obj, pipe, tap } from "lil-fp";
3
+ import { Project as TsProject, ScriptKind } from "ts-morph";
4
+
1
5
  // src/parser.ts
2
6
  import { logger } from "@pandacss/logger";
3
7
  import { memo as memo2 } from "@pandacss/shared";
4
- import { Project } from "ts-morph";
5
8
  import { match as match3 } from "ts-pattern";
6
9
 
7
10
  // src/call-expression.ts
@@ -111,32 +114,6 @@ function visitCallExpressions(file, options) {
111
114
  }
112
115
  }
113
116
 
114
- // src/collector.ts
115
- var Collector = class {
116
- jsx = /* @__PURE__ */ new Set();
117
- css = /* @__PURE__ */ new Set();
118
- cva = /* @__PURE__ */ new Set();
119
- recipe = /* @__PURE__ */ new Map();
120
- pattern = /* @__PURE__ */ new Map();
121
- set(name, result) {
122
- this[name].add({ type: "object", ...result });
123
- }
124
- setCva(result) {
125
- this.cva.add({ type: "cva", ...result });
126
- }
127
- setPattern(name, result) {
128
- this.pattern.get(name) ?? this.pattern.set(name, /* @__PURE__ */ new Set());
129
- this.pattern.get(name)?.add({ type: "pattern", name, ...result });
130
- }
131
- setRecipe(name, result) {
132
- this.recipe.get(name) ?? this.recipe.set(name, /* @__PURE__ */ new Set());
133
- this.recipe.get(name)?.add({ type: "recipe", ...result });
134
- }
135
- get isEmpty() {
136
- return this.css.size === 0 && this.cva.size === 0 && this.recipe.size === 0 && this.pattern.size === 0 && this.jsx.size === 0;
137
- }
138
- };
139
-
140
117
  // src/import.ts
141
118
  import { memo } from "@pandacss/shared";
142
119
  function getImportDeclarations(file, options) {
@@ -222,21 +199,33 @@ function visitJsxElement(file, options) {
222
199
  }
223
200
  }
224
201
 
202
+ // src/parser-result.ts
203
+ var createParserResult = () => ({
204
+ jsx: /* @__PURE__ */ new Set(),
205
+ css: /* @__PURE__ */ new Set(),
206
+ cva: /* @__PURE__ */ new Set(),
207
+ recipe: /* @__PURE__ */ new Map(),
208
+ pattern: /* @__PURE__ */ new Map(),
209
+ set(name, result) {
210
+ this[name].add({ type: "object", ...result });
211
+ },
212
+ setCva(result) {
213
+ this.cva.add({ type: "cva", ...result });
214
+ },
215
+ setPattern(name, result) {
216
+ this.pattern.get(name) ?? this.pattern.set(name, /* @__PURE__ */ new Set());
217
+ this.pattern.get(name)?.add({ type: "pattern", name, ...result });
218
+ },
219
+ setRecipe(name, result) {
220
+ this.recipe.get(name) ?? this.recipe.set(name, /* @__PURE__ */ new Set());
221
+ this.recipe.get(name)?.add({ type: "recipe", ...result });
222
+ },
223
+ isEmpty() {
224
+ return this.css.size === 0 && this.cva.size === 0 && this.recipe.size === 0 && this.pattern.size === 0 && this.jsx.size === 0;
225
+ }
226
+ });
227
+
225
228
  // src/parser.ts
226
- function createProject(options = {}) {
227
- return new Project({
228
- skipAddingFilesFromTsConfig: true,
229
- skipFileDependencyResolution: true,
230
- skipLoadingLibFiles: true,
231
- ...options,
232
- compilerOptions: {
233
- allowJs: true,
234
- strictNullChecks: false,
235
- skipLibCheck: true,
236
- ...options.compilerOptions
237
- }
238
- });
239
- }
240
229
  function createImportMatcher(mod, values) {
241
230
  const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
242
231
  return {
@@ -252,7 +241,7 @@ function createParser(options) {
252
241
  if (!sourceFile)
253
242
  return;
254
243
  const fileName = sourceFile.getFilePath();
255
- const collector = new Collector();
244
+ const collector = createParserResult();
256
245
  const { jsx, importMap } = options;
257
246
  const importRegex = [
258
247
  createImportMatcher(importMap.css, ["css", "cva"]),
@@ -324,7 +313,58 @@ function createParser(options) {
324
313
  };
325
314
  }
326
315
  var isUpperCase = (value) => value[0] === value[0].toUpperCase();
316
+
317
+ // src/project.ts
318
+ var createTsProject = (options) => new TsProject({
319
+ skipAddingFilesFromTsConfig: true,
320
+ skipFileDependencyResolution: true,
321
+ skipLoadingLibFiles: true,
322
+ ...options,
323
+ compilerOptions: {
324
+ allowJs: true,
325
+ strictNullChecks: false,
326
+ skipLibCheck: true,
327
+ ...options.compilerOptions
328
+ }
329
+ });
330
+ var createProject = ({ getFiles, readFile, parserOptions, ...projectOptions }) => pipe(
331
+ {
332
+ project: createTsProject(projectOptions),
333
+ parser: createParser(parserOptions)
334
+ },
335
+ Obj.assign(({ project, parser }) => ({
336
+ getSourceFile: (filePath) => project.getSourceFile(filePath),
337
+ removeSourceFile: (filePath) => {
338
+ const sourceFile = project.getSourceFile(filePath);
339
+ if (sourceFile)
340
+ project.removeSourceFile(sourceFile);
341
+ },
342
+ createSourceFile: (filePath) => project.createSourceFile(filePath, readFile(filePath), {
343
+ overwrite: true,
344
+ scriptKind: ScriptKind.TSX
345
+ }),
346
+ parseSourceFile: (filePath) => {
347
+ return parser(project.getSourceFile(filePath));
348
+ }
349
+ })),
350
+ tap(({ createSourceFile }) => {
351
+ const files = getFiles();
352
+ for (const file of files) {
353
+ createSourceFile(file);
354
+ }
355
+ }),
356
+ Obj.assign(({ getSourceFile, project }) => ({
357
+ reloadSourceFile: (filePath) => getSourceFile(filePath)?.refreshFromFileSystemSync(),
358
+ reloadSourceFiles: () => {
359
+ const files = getFiles();
360
+ for (const file of files) {
361
+ const source = getSourceFile(file);
362
+ source?.refreshFromFileSystemSync() ?? project.addSourceFileAtPath(file);
363
+ }
364
+ }
365
+ })),
366
+ Obj.omit(["project", "parser"])
367
+ );
327
368
  export {
328
- createParser,
329
369
  createProject
330
370
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/parser",
3
- "version": "0.0.0-dev-20230203184408",
3
+ "version": "0.0.0-dev-20230204123646",
4
4
  "description": "The static parser for panda css",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -11,15 +11,16 @@
11
11
  "access": "public"
12
12
  },
13
13
  "dependencies": {
14
- "ts-pattern": "4.1.3",
14
+ "lil-fp": "1.1.8",
15
15
  "ts-morph": "17.0.1",
16
- "@pandacss/logger": "0.0.0-dev-20230203184408",
17
- "@pandacss/shared": "0.0.0-dev-20230203184408",
18
- "@pandacss/is-valid-prop": "0.0.0-dev-20230203184408",
19
- "@pandacss/types": "0.0.0-dev-20230203184408"
16
+ "ts-pattern": "4.1.3",
17
+ "@pandacss/is-valid-prop": "0.0.0-dev-20230204123646",
18
+ "@pandacss/logger": "0.0.0-dev-20230204123646",
19
+ "@pandacss/shared": "0.0.0-dev-20230204123646",
20
+ "@pandacss/types": "0.0.0-dev-20230204123646"
20
21
  },
21
22
  "devDependencies": {
22
- "@pandacss/fixture": "0.0.0-dev-20230203184408"
23
+ "@pandacss/fixture": "0.0.0-dev-20230204123646"
23
24
  },
24
25
  "files": [
25
26
  "dist"