Skip to content

Commit

Permalink
Merge pull request #35 from ParamagicDev/fix/support-windows
Browse files Browse the repository at this point in the history
Continued attempt to support windows...
  • Loading branch information
KonnorRogers authored Jan 31, 2021
2 parents e768839 + 9c0bfa4 commit b86c628
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
9 changes: 2 additions & 7 deletions src/emitHtmlFiles.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from "fs";
import path from "path";
import { parseHashFileName } from "./utils";
import { pathToUnix, parseHashFileName, prependSlash } from "./utils";
import { JSDOM } from "jsdom";
import url from "url";

/**
* An instance of JSDOM
Expand Down Expand Up @@ -77,11 +76,7 @@ export function rewriteScripts({ dom, manifest, baseUrl }) {
}

function fixUrl({ baseUrl, file }) {
if (url.parse(baseUrl).protocol == null) {
return path.join(baseUrl, file);
} else {
return url.resolve(baseUrl, file);
}
return prependSlash(pathToUnix(path.join(baseUrl, file)));
}

function insertBefore(existingNode, newNode) {
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { defaultInputOptions, defaultOutputOptions } from "./options";
import { proxyImportResolver } from "./proxyImportResolver";
import { addToManifest } from "./manifestUtils";
import { emitHtmlFiles } from "./emitHtmlFiles";
import { pathToUnix } from "./utils";

const TMP_BUILD_DIRECTORY = path.join(os.tmpdir(), "build");

Expand All @@ -20,7 +21,9 @@ function getEntrypoints({ entrypoints, buildDirectory }) {

// This fixes issues that were causing x.js-[hash].js
const fileWithoutExt = path.join(dir, name);
const buildFile = path.relative(buildDirectory, fileWithoutExt);
const buildFile = pathToUnix(
path.relative(buildDirectory, fileWithoutExt)
);

obj[buildFile] = file;
});
Expand Down Expand Up @@ -67,8 +70,7 @@ async function rollupBuild({

// Add assets to manifest, use path.relative to fix minor issues
glob.sync(`${TMP_BUILD_DIRECTORY}/**/*.*`).forEach((fileName) => {
console.log(fileName);
fileName = path.relative(TMP_BUILD_DIRECTORY, fileName);
fileName = pathToUnix(path.relative(TMP_BUILD_DIRECTORY, fileName));
const chunkOrAsset = { fileName, map: null };
addToManifest({
manifest,
Expand Down
4 changes: 2 additions & 2 deletions src/manifestUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prependSlash, parseHashFileName } from "./utils";
import { pathToUnix, prependSlash, parseHashFileName } from "./utils";
import path from "path";

export function addToManifest({
Expand Down Expand Up @@ -45,7 +45,7 @@ function assignAsset({ obj, asset, useFileType }) {
dir = dir.split("/").slice(1).join("");
}

baseName = path.posix.join(dir, name.split(".")[0]);
baseName = pathToUnix(path.join(dir, name.split(".")[0]));
}

const adjustedFileName = prependSlash(fileName);
Expand Down
14 changes: 13 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import path from "path";
import { spawnSync } from "child_process";

/**
* Normalizes \\ on windows to /
* @param {string} filePath - Normalizes \ to / on windows.
*/
export function pathToUnix(filePath) {
if (path.sep === "//") {
return filePath.replace(/\\/g, "/");
}

return filePath;
}

export function parseHashFileName(filePath) {
const { dir, base } = path.parse(filePath);

const fileWithoutHash = base.replace(/(.*)-\w+(\.\w+)/g, "$1$2");
return path.join(dir, fileWithoutHash);
return pathToUnix(path.join(dir, fileWithoutHash));
}

export function shellRun(cmd, options = {}) {
Expand Down

0 comments on commit b86c628

Please sign in to comment.