carbon-design-system / carbon-preprocess-svelte

Svelte preprocessors for the Carbon Design System
Apache License 2.0
68 stars 6 forks source link

`optimizeImports` incompatible with Carbon icons v11 #33

Closed brunnerh closed 2 years ago

brunnerh commented 2 years ago

Named imports are no longer resolved correctly with the structure of v11.

E.g.

import { BrightnessContrast, Tools, ... } from 'carbon-icons-svelte';

Results in errors like:

Module not found: Error: Can't resolve 'carbon-icons-svelte/lib/BrightnessContrast/BrightnessContrast.svelte' in '...'

(The same thing happens for optimizeCarbonImports from 'carbon-components-svelte/preprocess')

metonym commented 2 years ago

This should support it but it's not released: https://github.com/carbon-design-system/carbon-preprocess-svelte/pull/32

metonym commented 2 years ago

carbon-icons-svelte version 11 is now supported in v0.8.0.

brunnerh commented 2 years ago

@metonym This currently does not work for me because the code that determines the version makes an assumption which does not always hold.

In utils.ts the function getPackageJson looks for the package.json only in the current working directory when checking the package versions. I have multiple build configurations in separate sub-directories which all implicitly use the packages from the repository root directory (which also contains the package.json)1. During build the working directory is the directory of the current build file so the versions are not being determined correctly.

Hence the fallback kicks in which uses the LATEST_MAJOR_VERSION from constants.ts, which is still at 10 for the icons.

1 If I recall correctly, Node actually uses all node_modules directories on the way to the root of the file system directory tree.

metonym commented 2 years ago

Nice catch. The latest version for icons is now set to 11 in v0.8.2