diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c009cc69..b935cc70 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }} diff --git a/lib/classes/asset.js b/lib/classes/asset.js index bb761941..4e23b9bb 100644 --- a/lib/classes/asset.js +++ b/lib/classes/asset.js @@ -1,5 +1,6 @@ import mime from "mime"; import path from "node:path"; +import { toUrlPathname } from "../utils/url.js"; /** * @typedef {object} AssetOptions @@ -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; diff --git a/lib/sinks/test.js b/lib/sinks/test.js index 2d5f1c2e..d76cdaab 100644 --- a/lib/sinks/test.js +++ b/lib/sinks/test.js @@ -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"; @@ -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; @@ -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(""); @@ -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 } }); @@ -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 } }); @@ -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 } }); @@ -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 } }); diff --git a/lib/utils/path-builders-uri.js b/lib/utils/path-builders-uri.js index dce4d72b..145bea3a 100644 --- a/lib/utils/path-builders-uri.js +++ b/lib/utils/path-builders-uri.js @@ -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, diff --git a/lib/utils/url.js b/lib/utils/url.js new file mode 100644 index 00000000..91e931cc --- /dev/null +++ b/lib/utils/url.js @@ -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, "/"); +} diff --git a/package.json b/package.json index d173f003..22265d03 100644 --- a/package.json +++ b/package.json @@ -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",