Skip to content

Commit

Permalink
Fix asset path issue for "compound-design-tokens" package
Browse files Browse the repository at this point in the history
Fixed path issue for "compound-design-tokens" package independent of whether the package is cloned and linked within "matrix-react-sdk" or not.

Resource paths are e.g. ...

- Not linked package -
resourcePath: C:\src\matrix-react-sdk\node_modules\@vector-im\compound-design-tokens\icons\chat-solid.svg

- Cloned & linked package -
resourcePath: C:\src\compound-design-tokens\icons\chat-solid.svg

Problem: 
The "compound-design-tokens" package does not have a 'dist' or "res" subfolder for the assets so that the regex /^.*[/\\](dist|res)[/\\]/ does not match. 

Solution: 
Add the missing root folder name for the compound tokens assets to the regex in the "webpack.config.js" to match the paths, with resulting regex... 

/^.*[/\\](dist|res|compound-design-tokens)[/\\]/

Tested both scenarios (linked/not linked) on Windows.
  • Loading branch information
menturion authored Nov 25, 2023
1 parent 2ee0826 commit 56c8b15
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ function getAssetOutputPath(url, resourcePath) {
const isKaTeX = resourcePath.includes("KaTeX");
// `res` is the parent dir for our own assets in various layers
// `dist` is the parent dir for KaTeX assets
const prefix = /^.*[/\\](dist|res)[/\\]/;
const prefix = /^.*[/\\](dist|res|compound-design-tokens)[/\\]/;

/**
* Only needed for https://github.com/vector-im/element-web/pull/15939
Expand All @@ -819,20 +819,6 @@ function getAssetOutputPath(url, resourcePath) {
}
let outputDir = path.dirname(resourcePath).replace(prefix, "");

/**
* Imports from Compound are "absolute", we need to strip out the prefix
* coming before the npm package name.
*
* This logic is scoped to compound packages for now as they are the only
* package that imports external assets. This might need to be made more
* generic in the future
*/
const compoundImportsPrefix = /@vector-im(?:\\|\/)compound-(.*?)(?:\\|\/)/;
const compoundMatch = outputDir.match(compoundImportsPrefix);
if (compoundMatch) {
outputDir = outputDir.substring(compoundMatch.index + compoundMatch[0].length);
}

if (isKaTeX) {
// Add a clearly named directory segment, rather than leaving the KaTeX
// assets loose in each asset type directory.
Expand Down

0 comments on commit 56c8b15

Please sign in to comment.