Skip to content

Commit

Permalink
Add support for windows
Browse files Browse the repository at this point in the history
docs: update CHANGELOG.md

docs: update CHANGELOG.md

docs: update CHANGELOG.md

v0.4.0

docs: update CHANGELOG.md

v0.4.1

prettier bullshit

docs: update CHANGELOG.md

docs: update CHANGELOG.md

v0.4.3

update screenshots

fix: maybe this actually works with windows?

remove unused import

fix pathToUnix

fix: supporting windows paths

minor tweak
  • Loading branch information
Filyus authored and KonnorRogers committed Jan 31, 2021
1 parent 1ecc668 commit 7b2bcb7
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 20 deletions.
52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
## [0.4.3](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/compare/v0.4.1...v0.4.3) (2021-01-30)



## [0.4.2](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/compare/v0.4.1...v0.4.2) (2021-01-30)



## [0.4.1](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/compare/v0.3.3...v0.4.1) (2021-01-30)


### Features

* add fs-extra for cross-platform support ([78c4c2b](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/78c4c2b5321a3c7393b0d67a1b7c16598f84c7a9))
* add sourcemaps if sourcemaps are enabled ([5718c62](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/5718c6299b527db02d5568aace01cb789cd13fa6))
* support windows with fs-extra ([adebc3c](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/adebc3cb9109100436190032c57a32c5df85cbd8))



# [0.4.0](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/compare/v0.3.3...v0.4.0) (2021-01-30)


### Features

* add fs-extra for cross-platform support ([78c4c2b](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/78c4c2b5321a3c7393b0d67a1b7c16598f84c7a9))
* add sourcemaps if sourcemaps are enabled ([5718c62](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/5718c6299b527db02d5568aace01cb789cd13fa6))
* support windows with fs-extra ([adebc3c](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/adebc3cb9109100436190032c57a32c5df85cbd8))



## [0.4.1](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/compare/v0.3.3...v0.4.1) (2021-01-30)


### Features

* add fs-extra for cross-platform support ([78c4c2b](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/78c4c2b5321a3c7393b0d67a1b7c16598f84c7a9))
* add sourcemaps if sourcemaps are enabled ([5718c62](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/5718c6299b527db02d5568aace01cb789cd13fa6))
* support windows with fs-extra ([adebc3c](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/adebc3cb9109100436190032c57a32c5df85cbd8))



# [0.4.0](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/compare/v0.3.3...v0.4.0) (2021-01-30)


### Features

* add fs-extra for cross-platform support ([78c4c2b](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/78c4c2b5321a3c7393b0d67a1b7c16598f84c7a9))
* add sourcemaps if sourcemaps are enabled ([5718c62](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/5718c6299b527db02d5568aace01cb789cd13fa6))
* support windows with fs-extra ([adebc3c](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/commit/adebc3cb9109100436190032c57a32c5df85cbd8))



## [0.3.3](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle/compare/v0.3.2...v0.3.3) (2020-10-17)


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@
"start-server-and-test": "^1.11.7",
"uvu": "^0.5.1"
},
"version": "0.3.3"
"version": "0.4.3"
}
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 } 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 pathToUnix(path.join(baseUrl, file));
}

function insertBefore(existingNode, newNode) {
Expand Down
22 changes: 13 additions & 9 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 Expand Up @@ -150,12 +152,14 @@ const plugin = (snowpackConfig, pluginOptions = {}) => {
});

// Rewrite "proxy.js" imports prior to building
glob.sync(buildDirectory + "/**/*.js").forEach((file) => {
const resolvedImports = proxyImportResolver(
fs.readFileSync(file, "utf8")
);
fs.writeFileSync(file, resolvedImports, "utf8");
});
glob
.sync(buildDirectory + "/**/*.js", { nodir: true })
.forEach((file) => {
const resolvedImports = proxyImportResolver(
fs.readFileSync(file, "utf8")
);
fs.writeFileSync(file, resolvedImports, "utf8");
});

await rollupBuild(extendedConfig);
},
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 7b2bcb7

Please sign in to comment.