@wix/zero-config-implementation 1.23.0 → 1.24.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.23.0",
7
+ "version": "1.24.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",
@@ -83,5 +83,5 @@
83
83
  ]
84
84
  }
85
85
  },
86
- "falconPackageHash": "93d5823d13acb8bb58ccf6bfebbbba2f1f65e9250a67b60a9204b722"
86
+ "falconPackageHash": "79d9ab055f999610e162c914b9c616eed125490c1816f8b91e2dac53"
87
87
  }
@@ -1,6 +1,21 @@
1
+ import { existsSync } from 'node:fs'
1
2
  import { createRequire } from 'node:module'
3
+ import { dirname, join } from 'node:path'
2
4
  import { Result, err } from 'neverthrow'
3
5
 
6
+ function collectNodeModulesPaths(filePath: string): string[] {
7
+ const paths: string[] = []
8
+ let dir = dirname(filePath)
9
+ while (true) {
10
+ const candidate = join(dir, 'node_modules')
11
+ if (existsSync(candidate)) paths.push(candidate)
12
+ const parent = dirname(dir)
13
+ if (parent === dir) break
14
+ dir = parent
15
+ }
16
+ return paths
17
+ }
18
+
4
19
  const require = createRequire(import.meta.url)
5
20
 
6
21
  export function compileSass(filePath: string): Result<string, Error> {
@@ -14,26 +29,11 @@ export function compileSass(filePath: string): Result<string, Error> {
14
29
  ),
15
30
  )
16
31
  }
32
+ const loadPaths = collectNodeModulesPaths(filePath)
17
33
  return Result.fromThrowable(
18
34
  () =>
19
35
  sass.compile(filePath, {
20
- importers: [
21
- {
22
- // Return null for relative paths and built-in sass: modules so the
23
- // built-in filesystem resolver handles them. For everything else
24
- // (aliases, missing node_modules, etc.) silently return empty content
25
- // rather than failing the whole compilation.
26
- canonicalize(url: string): URL | null {
27
- if (url.startsWith('.') || url.startsWith('/') || url.startsWith('sass:')) {
28
- return null
29
- }
30
- return new URL(`empty-sass-import:${encodeURIComponent(url)}`)
31
- },
32
- load(): { contents: string; syntax: 'scss' } {
33
- return { contents: '', syntax: 'scss' }
34
- },
35
- },
36
- ],
36
+ loadPaths,
37
37
  }).css,
38
38
  (thrown) => (thrown instanceof Error ? thrown : new Error(String(thrown))),
39
39
  )()