Skip to content
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

make safeguards to work on windows #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/codesandboxer-fs/src/loadRelativeFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ const fs = require('fs');
const path = require('path');
const resolve = require('resolve');

const safeGuardPath = (resolvedPath: string) =>
path.join(...resolvedPath.split('/'));

const relToRelPkgRoot = (resolvedPath, rootDir) =>
path.relative(rootDir, resolvedPath);

async function loadJS(resolvedPath, pkgJSON, rootDir) {
let content = fs.readFileSync(resolvedPath, 'utf-8');
let content = fs.readFileSync(safeGuardPath(resolvedPath), 'utf-8');
let file = await csb.parseFile(content, pkgJSON);

return Object.assign({}, file, {
Expand All @@ -17,23 +20,23 @@ async function loadJS(resolvedPath, pkgJSON, rootDir) {
}

async function loadSass(resolvedPath, pkgJSON, rootDir) {
let content = fs.readFileSync(resolvedPath, 'utf-8');
let content = fs.readFileSync(safeGuardPath(resolvedPath), 'utf-8');
let file = await csb.parseSassFile(content);
return Object.assign({}, file, {
filePath: relToRelPkgRoot(resolvedPath, rootDir),
});
}

async function loadScss(resolvedPath, pkgJSON, rootDir) {
let content = fs.readFileSync(resolvedPath, 'utf-8');
let content = fs.readFileSync(safeGuardPath(resolvedPath), 'utf-8');
let file = await csb.parseScssFile(content);
return Object.assign({}, file, {
filePath: relToRelPkgRoot(resolvedPath, rootDir),
});
}

async function loadRaw(resolvedPath, rootDir) {
let file = fs.readFileSync(resolvedPath, 'utf-8');
let file = fs.readFileSync(safeGuardPath(resolvedPath), 'utf-8');
return {
file,
deps: {},
Expand All @@ -44,7 +47,7 @@ async function loadRaw(resolvedPath, rootDir) {
/* Remove the disable once image loading has been built */
/* eslint-disable-next-line no-unused-vars */
async function loadImages(resolvedPath, rootDir) {
let file = fs.readFileSync(resolvedPath);
let file = fs.readFileSync(safeGuardPath(resolvedPath));
return {
file: new Buffer(file).toString('base64'),
deps: {},
Expand Down