@wix/zero-config-implementation 1.18.0 → 1.19.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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "registry": "https://registry.npmjs.org/",
5
5
  "access": "public"
6
6
  },
7
- "version": "1.18.0",
7
+ "version": "1.19.0",
8
8
  "description": "Core library for extracting component manifests from JS and CSS files",
9
9
  "type": "module",
10
10
  "main": "dist/index.js",
@@ -75,5 +75,5 @@
75
75
  ]
76
76
  }
77
77
  },
78
- "falconPackageHash": "28d3025e283d998b34b77ef31c51e4195289ad39631c5054675ce0b6"
78
+ "falconPackageHash": "c023fc2f7c36ad9d9d7f5d3e24b22d292e138350cb6a48ae6964e8a0"
79
79
  }
@@ -1,26 +1,44 @@
1
1
  import * as path from 'node:path'
2
2
  import ts, { type Program } from 'typescript'
3
3
 
4
+ const MAX_DEPTH = 100
5
+
4
6
  export function extractCssImports(program: Program): string[] {
5
7
  const cssFiles = new Set<string>()
8
+ const visited = new Set<string>()
6
9
 
7
- for (const sourceFile of program.getSourceFiles()) {
8
- // Skip external libraries
9
- if (sourceFile.isDeclarationFile || sourceFile.fileName.includes('node_modules')) continue
10
+ function walk(sourceFile: ts.SourceFile, depth: number): void {
11
+ if (depth > MAX_DEPTH) return
12
+ if (visited.has(sourceFile.fileName)) return
13
+ visited.add(sourceFile.fileName)
10
14
 
11
15
  ts.forEachChild(sourceFile, (node) => {
12
- // Look for: import './style.css' or import x from './style.css'
13
- if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
14
- const importPath = node.moduleSpecifier.text
15
-
16
- if (importPath.endsWith('.css')) {
17
- // Resolve relative path to an absolute disk path
18
- const fullPath = path.resolve(path.dirname(sourceFile.fileName), importPath)
19
- cssFiles.add(fullPath)
20
- }
16
+ if (!ts.isImportDeclaration(node) || !ts.isStringLiteral(node.moduleSpecifier)) return
17
+ const importPath = node.moduleSpecifier.text
18
+
19
+ if (importPath.endsWith('.css')) {
20
+ const fullPath = path.resolve(path.dirname(sourceFile.fileName), importPath)
21
+ cssFiles.add(fullPath)
22
+ return
21
23
  }
24
+
25
+ // Resolve the module to a source file in the program
26
+ const resolved = ts.resolveModuleName(importPath, sourceFile.fileName, program.getCompilerOptions(), ts.sys)
27
+ const resolvedFileName = resolved.resolvedModule?.resolvedFileName
28
+ if (!resolvedFileName) return
29
+
30
+ const resolvedSource = program.getSourceFile(resolvedFileName)
31
+ // Skip declaration files (.d.ts and @types packages)
32
+ if (!resolvedSource || resolvedSource.isDeclarationFile) return
33
+ walk(resolvedSource, depth + 1)
22
34
  })
23
35
  }
24
36
 
37
+ for (const sourceFile of program.getSourceFiles()) {
38
+ // Only start walks from project source files (skip .d.ts and node_modules)
39
+ if (sourceFile.isDeclarationFile || sourceFile.fileName.includes('node_modules')) continue
40
+ walk(sourceFile, 0)
41
+ }
42
+
25
43
  return Array.from(cssFiles)
26
44
  }