Skip to content

Commit acb6a82

Browse files
sapphi-redmadyankin
authored andcommitted
fix: composes on windows
1 parent 7d5965d commit acb6a82

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.github/workflows/test.js.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ on:
1010
jobs:
1111
build:
1212

13-
runs-on: ubuntu-latest
14-
1513
strategy:
1614
matrix:
15+
os: [ubuntu-latest, windows-latest]
1716
node-version: [10.x, 12.x, 14.x, 15.x]
1817
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
1918

19+
runs-on: ${{ matrix.os }}
20+
2021
steps:
2122
- uses: actions/checkout@v2
2223
- name: Use Node.js ${{ matrix.node-version }}

src/css-loader-core/loader.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Core {
1515
let parser = new Parser(pathFetcher, trace);
1616

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

4545
export default class FileSystemLoader {
4646
constructor(root, plugins) {
47+
if (root === '/' && process.platform === "win32") {
48+
const cwdDrive = process.cwd().slice(0, 3)
49+
if (!/^[A-Z]:\\$/.test(cwdDrive)) {
50+
throw new Error(`Failed to obtain root from "${process.cwd()}".`)
51+
}
52+
root = cwdDrive
53+
}
54+
4755
this.root = root;
4856
this.sources = {};
4957
this.traces = {};
@@ -59,12 +67,12 @@ export default class FileSystemLoader {
5967
let relativeDir = path.dirname(relativeTo),
6068
rootRelativePath = path.resolve(relativeDir, newPath),
6169
fileRelativePath = path.resolve(
62-
path.join(this.root, relativeDir),
70+
path.resolve(this.root, relativeDir),
6371
newPath
6472
);
6573

6674
// if the path is not relative or absolute, try to resolve it in node_modules
67-
if (newPath[0] !== "." && newPath[0] !== "/") {
75+
if (newPath[0] !== "." && !path.isAbsolute(newPath)) {
6876
try {
6977
fileRelativePath = require.resolve(newPath);
7078
} catch (e) {

0 commit comments

Comments
 (0)