Skip to content

Fix resolve path error#32

Open
baurine wants to merge 3 commits intomartonlederer:mainfrom
baurine:fix-resolve-path-2
Open

Fix resolve path error#32
baurine wants to merge 3 commits intomartonlederer:mainfrom
baurine:fix-resolve-path-2

Conversation

@baurine
Copy link

@baurine baurine commented Dec 10, 2021

This PR is cherry-pick from: baurine#4

What did:

Use resolve npm package instead of resolve-file npm package to resolve the import path, this can fix the 2 below bugs:

The root reason I have reported to resolve-file repo in doowb/resolve-file#2 (comment)

* update package name and version

* test with empty options

* fix resove path error

* support compile fake css but js file

* clean up

* Revert "update package name and version"

This reverts commit fd545d6.

* fix fmt
Comment on lines +97 to +99
let sourceFullPath = resolve.sync(args.path, {
basedir: args.resolveDir
});
Copy link
Author

@baurine baurine Dec 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can resolve all imported files correctly, not only local but from node_modules.

Comment on lines +54 to +60
plugins = [],
modules = true,
rootDir = process.cwd(),
sassOptions = {},
lessOptions = {},
stylusOptions = {},
writeToFile = true
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this back to pass the test.

Comment on lines +102 to +110
if (
sourceExt !== ".css" &&
sourceExt !== ".sass" &&
sourceExt !== ".scss" &&
sourceExt !== ".less" &&
sourceExt !== ".styl"
) {
return;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file may be a .js file, if so, we can skip it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using a regular expression? if (!/\.(scss|sass|css|less|styl)/.test(sourceExt)) {. Or even extract that check into a separate function to make it more readable

function isStyle(extension) {
  return /\.(scss|sass|css|less|styl)/.test(extension);
}

...

if (!isStyle(sourceExt) {

"types": "src/modules.d.ts",
"dependencies": {
"autoprefixer": "^10.2.5",
"bulma": "^0.9.3",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get why you add this as production dependency to get only the css. You should pay more attention and use less css. For the test it would be totally sufficient to create a test css file which contains the problematic css code.

"postcss-modules": "^4.0.0",
"resolve-file": "^0.3.0",
"resolve": "^1.20.0",
"sass": "^1.x",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually sass, less, stylus etc should also be just peerDependencies and no hard dependencies.

@fragsalat
Copy link

I would recommend you to switch to the esbuild-style-plugin. It's maintained and working in this regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants