Skip to content

Commit

Permalink
fix: composes on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored and madyankin committed Aug 15, 2022
1 parent 7d5965d commit acb6a82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ on:
jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [10.x, 12.x, 14.x, 15.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
14 changes: 11 additions & 3 deletions src/css-loader-core/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Core {
let parser = new Parser(pathFetcher, trace);

return postcss(this.plugins.concat([parser.plugin()]))
.process(sourceString, { from: "/" + sourcePath })
.process(sourceString, { from: sourcePath })
.then((result) => {
return {
injectableSource: result.css,
Expand Down Expand Up @@ -44,6 +44,14 @@ const traceKeySorter = (a, b) => {

export default class FileSystemLoader {
constructor(root, plugins) {
if (root === '/' && process.platform === "win32") {
const cwdDrive = process.cwd().slice(0, 3)
if (!/^[A-Z]:\\$/.test(cwdDrive)) {
throw new Error(`Failed to obtain root from "${process.cwd()}".`)
}
root = cwdDrive
}

this.root = root;
this.sources = {};
this.traces = {};
Expand All @@ -59,12 +67,12 @@ export default class FileSystemLoader {
let relativeDir = path.dirname(relativeTo),
rootRelativePath = path.resolve(relativeDir, newPath),
fileRelativePath = path.resolve(
path.join(this.root, relativeDir),
path.resolve(this.root, relativeDir),
newPath
);

// if the path is not relative or absolute, try to resolve it in node_modules
if (newPath[0] !== "." && newPath[0] !== "/") {
if (newPath[0] !== "." && !path.isAbsolute(newPath)) {
try {
fileRelativePath = require.resolve(newPath);
} catch (e) {
Expand Down

0 comments on commit acb6a82

Please sign in to comment.