Skip to content

Commit

Permalink
fix: windows support (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud authored Aug 16, 2024
1 parent 74cca93 commit 50380a7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [18, 20]
runs-on: ${{ matrix.os }}

Expand Down
3 changes: 2 additions & 1 deletion lib/classes/asset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mime from "mime";
import path from "node:path";
import { toUrlPathname } from "../utils/url.js";

/**
* @typedef {object} AssetOptions
Expand Down Expand Up @@ -31,7 +32,7 @@ const Asset = class Asset {
this._size = -1;

this._integrity = "";
this._pathname = path.join("/", pathname);
this._pathname = toUrlPathname(path.join("/", pathname));
this._version = version;
this._name = name;
this._org = org;
Expand Down
14 changes: 7 additions & 7 deletions lib/sinks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Metrics from "@metrics/client";
import Sink from "@eik/sink";
import mime from "mime";
import path from "node:path";

import { toUrlPathname } from "../utils/url.js";
import Entry from "./mem-entry.js";

const DEFAULT_ROOT_PATH = "/eik";
Expand Down Expand Up @@ -41,7 +41,7 @@ export default class SinkTest extends Sink {
}

set(filePath, payload) {
const pathname = path.join(this._rootPath, filePath);
const pathname = toUrlPathname(path.join(this._rootPath, filePath));
const mimeType = mime.getType(pathname) || "application/octet-stream";

let entry;
Expand All @@ -56,7 +56,7 @@ export default class SinkTest extends Sink {
}

get(filePath) {
const pathname = path.join(this._rootPath, filePath);
const pathname = toUrlPathname(path.join(this._rootPath, filePath));
if (this._state.has(pathname)) {
const entry = this._state.get(pathname);
return entry.payload.join("");
Expand Down Expand Up @@ -110,7 +110,7 @@ export default class SinkTest extends Sink {
return;
}

const pathname = path.join(this._rootPath, filePath);
const pathname = toUrlPathname(path.join(this._rootPath, filePath));

if (pathname.indexOf(this._rootPath) !== 0) {
this._counter.inc({ labels: { operation } });
Expand Down Expand Up @@ -178,7 +178,7 @@ export default class SinkTest extends Sink {
return;
}

const pathname = path.join(this._rootPath, filePath);
const pathname = toUrlPathname(path.join(this._rootPath, filePath));

if (pathname.indexOf(this._rootPath) !== 0) {
this._counter.inc({ labels: { operation } });
Expand Down Expand Up @@ -228,7 +228,7 @@ export default class SinkTest extends Sink {
return;
}

const pathname = path.join(this._rootPath, filePath);
const pathname = toUrlPathname(path.join(this._rootPath, filePath));

if (pathname.indexOf(this._rootPath) !== 0) {
this._counter.inc({ labels: { operation } });
Expand Down Expand Up @@ -267,7 +267,7 @@ export default class SinkTest extends Sink {
return;
}

const pathname = path.join(this._rootPath, filePath);
const pathname = toUrlPathname(path.join(this._rootPath, filePath));

if (pathname.indexOf(this._rootPath) !== 0) {
this._counter.inc({ labels: { operation } });
Expand Down
23 changes: 8 additions & 15 deletions lib/utils/path-builders-uri.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
import path from "node:path";
import globals from "./globals.js";

// Build URL pathname to a package log file
import { toUrlPathname } from "./url.js";

const createURIPathToPkgLog = ({ type = "", name = "", version = "" } = {}) =>
path.join(globals.ROOT, type, name, version);

// Build URL pathname to an asset in a package
toUrlPathname(path.join(globals.ROOT, type, name, version));

const createURIPathToAsset = ({
type = "",
name = "",
version = "",
asset = "",
} = {}) => path.join(globals.ROOT, type, name, version, asset);

// Build URL pathname to an import map
} = {}) => toUrlPathname(path.join(globals.ROOT, type, name, version, asset));

const createURIPathToImportMap = ({ name = "", version = "" } = {}) =>
path.join(globals.ROOT, globals.BASE_IMPORT_MAPS, name, version);

// Build URL pathname to an alias source
toUrlPathname(
path.join(globals.ROOT, globals.BASE_IMPORT_MAPS, name, version),
);

const createURIToAlias = ({ type = "", name = "", alias = "" } = {}) =>
path.join(globals.ROOT, type, name, `v${alias}`);

// Build URL pathname to an alias target destination
toUrlPathname(path.join(globals.ROOT, type, name, `v${alias}`));

const createURIToTargetOfAlias = ({
type = "",
name = "",
version = "",
extra = "",
} = {}) => path.join(globals.ROOT, type, name, version, extra);
} = {}) => toUrlPathname(path.join(globals.ROOT, type, name, version, extra));

export {
createURIPathToPkgLog,
Expand Down
8 changes: 8 additions & 0 deletions lib/utils/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Takes a pathname that may have win32 separators and ensures it's ready to be used as a URI
* @param {string} pathname
* @returns {string}
*/
export function toUrlPathname(pathname) {
return pathname.replace(/\\/g, "/");
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@eik/common": "4.1.0",
"@eik/common": "4.1.1",
"@eik/sink": "1.2.5",
"@eik/sink-file-system": "1.0.1",
"@eik/sink-memory": "1.1.2",
Expand Down

0 comments on commit 50380a7

Please sign in to comment.