-
Notifications
You must be signed in to change notification settings - Fork 19
Fix resolve path error #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,11 +28,12 @@ | |
| "types": "src/modules.d.ts", | ||
| "dependencies": { | ||
| "autoprefixer": "^10.2.5", | ||
| "bulma": "^0.9.3", | ||
| "fs-extra": "^9.1.0", | ||
| "less": "^4.x", | ||
| "postcss": "8.x", | ||
| "postcss-modules": "^4.0.0", | ||
| "resolve-file": "^0.3.0", | ||
| "resolve": "^1.20.0", | ||
| "sass": "^1.x", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| "stylus": "^0.x", | ||
| "tmp": "^0.2.1" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ import postcss from "postcss"; | |
| import postcssModules from "postcss-modules"; | ||
| import less from "less"; | ||
| import stylus from "stylus"; | ||
| import resolveFile from "resolve-file"; | ||
| import resolve from "resolve"; | ||
|
|
||
| type StylusRenderOptions = Parameters<typeof stylus.render>[1]; // The Stylus.RenderOptions interface doesn't seem to be exported... So next best | ||
|
|
||
|
|
@@ -51,13 +51,13 @@ export const defaultOptions: PostCSSPluginOptions = { | |
| }; | ||
|
|
||
| const postCSSPlugin = ({ | ||
| plugins, | ||
| modules, | ||
| rootDir, | ||
| sassOptions, | ||
| lessOptions, | ||
| stylusOptions, | ||
| writeToFile | ||
| plugins = [], | ||
| modules = true, | ||
| rootDir = process.cwd(), | ||
| sassOptions = {}, | ||
| lessOptions = {}, | ||
| stylusOptions = {}, | ||
| writeToFile = true | ||
|
Comment on lines
+54
to
+60
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add this back to pass the test. |
||
| }: PostCSSPluginOptions = defaultOptions): Plugin => ({ | ||
| name: "postcss2", | ||
| setup(build) { | ||
|
|
@@ -94,12 +94,20 @@ const postCSSPlugin = ({ | |
| // Namespace is empty when using CSS as an entrypoint | ||
| if (args.namespace !== "file" && args.namespace !== "") return; | ||
|
|
||
| // Resolve files from node_modules (ex: npm install normalize.css) | ||
| let sourceFullPath = resolveFile(args.path); | ||
| if (!sourceFullPath) | ||
| sourceFullPath = path.resolve(args.resolveDir, args.path); | ||
| let sourceFullPath = resolve.sync(args.path, { | ||
| basedir: args.resolveDir | ||
| }); | ||
|
Comment on lines
+97
to
+99
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| const sourceExt = path.extname(sourceFullPath); | ||
| if ( | ||
| sourceExt !== ".css" && | ||
| sourceExt !== ".sass" && | ||
| sourceExt !== ".scss" && | ||
| sourceExt !== ".less" && | ||
| sourceExt !== ".styl" | ||
| ) { | ||
| return; | ||
| } | ||
|
Comment on lines
+102
to
+110
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file may be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not using a regular expression? |
||
| const sourceBaseName = path.basename(sourceFullPath, sourceExt); | ||
| const isModule = sourceBaseName.match(/\.module$/); | ||
| const sourceDir = path.dirname(sourceFullPath); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // This usage comes from office-ui-fabric-react (renamed to fluent-ui later) | ||
| // After installing office-ui-fabric-react | ||
| // The below code exists in node_modules/office-ui-fabric-react/lib/components/pickers/BasePicker.js | ||
| import * as stylesImport from "./BasePicker.scss"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| import "normalize.css"; | ||
| import "bulma/css/bulma.css"; |
There was a problem hiding this comment.
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.