Skip to content

Commit

Permalink
handle bundling of relative node_modules paths for CSS url paths
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Dec 28, 2024
1 parent b9aaf7a commit 5a39b1e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/cli/src/plugins/resource/plugin-standard-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ function bundleCss(body, sourceUrl, compilation, workingUrl) {
} else if (value.startsWith('/node_modules/')) {
// if it's a node modules shortcut alias, just use that
finalValue = value;
} else if (value.indexOf('../node_modules/') >= 0) {
// if it's a relative node_modules path, convert it to a shortcut alias
finalValue = `/${value.replace(/\.\.\//g, '')}`;
} else if (resolvedUrl.href.indexOf('/node_modules/') >= 0) {
// if we are deep in node_modules land, use resolution logic to figure out the specifier
const resolvedRoot = derivePackageRoot(resolvedUrl.href);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Build Greenwood With: ', function() {
before(async function() {
// this package has a known issue with import.meta.resolve
// in that it has no main, module, or exports so it has to be hoisted
// at least for this current version
// at least for this current version, as well as for testing relative ../node_modules references
// https://unpkg.com/browse/[email protected]/package.json
// https://github.com/FortAwesome/Font-Awesome/pull/19041
const fontAwesomePackageJson = await getDependencyFiles(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@import url('/node_modules/@spectrum-web-components/styles/all-large-dark.css');
@import url('/node_modules/font-awesome/css/font-awesome.css');
@import url('../../node_modules/font-awesome/css/font-awesome.css');

0 comments on commit 5a39b1e

Please sign in to comment.