Skip to content

Commit

Permalink
fix: 🐛 replace separator for windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisermann committed Nov 8, 2020
1 parent 01ccd23 commit 4a270c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [8, 10, 12]
node-version: [10, 12]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2-beta
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run test:ci
- uses: bahmutov/npm-install@v1
- run: npm run test
env:
CI: true
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"build": "tsc --build tsconfig.build.json",
"dev": "npm run build -- -w",
"test": "jest",
"test:ci": "jest --silent --no-cache",
"lint": "eslint --ext js,ts .",
"format": "prettier --write \"**/*.{ts,js,json}\"",
"postinstall": "echo \"[svelte-preprocess] Don't forget to install the preprocessors packages that will be used: node-sass/sass, stylus, less, postcss & postcss-load-config, coffeescript, pug, etc...\"",
Expand Down
16 changes: 12 additions & 4 deletions src/transformers/scss.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, join } from 'path';
import { dirname, join, sep } from 'path';
import { existsSync } from 'fs';

import type { Importer, Result } from 'sass';
Expand Down Expand Up @@ -29,15 +29,23 @@ const tildeImporter: Importer = (url, _prev) => {
// not sure why this ends up here, but let's remove it
_prev = _prev.replace('http://localhost', '');

if (process.platform === 'win32') {
_prev = decodeURIComponent(_prev);
}

// possible dirs where a node_modules may live in, includes cwd
const possibleDirs = dirname(_prev).slice(cwd.length).split('/');
const possibleDirs = dirname(_prev).slice(cwd.length).split(sep);

const existingNodeModules = possibleDirs
// innermost dirs first
.reverse()
// return the first existing one
.find((_, i, arr) => {
const absPath = join(cwd, ...arr.slice(0, i + 1), 'node_modules');
const absPath = join(
cwd,
...arr.slice(0, i + sep.length),
'node_modules',
);

return existsSync(absPath);
});
Expand All @@ -49,7 +57,7 @@ const tildeImporter: Importer = (url, _prev) => {
cwd,
existingNodeModules,
'node_modules',
url.slice(1),
url.slice(1).replace('/', sep),
);

return { file: resolvedUrl };
Expand Down

0 comments on commit 4a270c9

Please sign in to comment.