From acb6a82f46b2ac9b76420c3e3ff587de4326961c Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Mon, 23 May 2022 23:24:30 +0900 Subject: [PATCH] fix: composes on windows --- .github/workflows/test.js.yml | 5 +++-- src/css-loader-core/loader.js | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.js.yml b/.github/workflows/test.js.yml index c58f45b..3ff38ca 100644 --- a/.github/workflows/test.js.yml +++ b/.github/workflows/test.js.yml @@ -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 }} diff --git a/src/css-loader-core/loader.js b/src/css-loader-core/loader.js index 669c91f..29990fb 100644 --- a/src/css-loader-core/loader.js +++ b/src/css-loader-core/loader.js @@ -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, @@ -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 = {}; @@ -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) {