From 51dbe8b3df46fb7b84a9d1b48f9c9a36ebb6a7f9 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Thu, 4 Apr 2024 10:28:51 +0100 Subject: [PATCH] Make paths host-agnostic (issue #41) --- lib/AdaptFrameworkBuild.js | 4 ++-- lib/AdaptFrameworkImport.js | 9 +++++---- lib/AdaptFrameworkUtils.js | 2 +- package.json | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/AdaptFrameworkBuild.js b/lib/AdaptFrameworkBuild.js index cde0bad..26b9e11 100644 --- a/lib/AdaptFrameworkBuild.js +++ b/lib/AdaptFrameworkBuild.js @@ -3,7 +3,7 @@ import AdaptCli from 'adapt-cli' import { App, Hook } from 'adapt-authoring-core' import { createWriteStream } from 'fs' import fs from 'fs-extra' -import path from 'path' +import path from 'upath' import semver from 'semver' import zipper from 'zipper' @@ -348,7 +348,7 @@ class AdaptFrameworkBuild { // replace asset _ids with correct paths const idMapEntries = Object.entries(this.assetData.idMap) const itemString = idMapEntries.reduce((s, [_id, assetPath]) => { - const relPath = assetPath.replace(this.courseDir, 'course').replaceAll(path.sep, '/') + const relPath = assetPath.replace(this.courseDir, 'course') return s.replace(new RegExp(_id, 'g'), relPath) }, JSON.stringify(i)) Object.assign(i, JSON.parse(itemString)) diff --git a/lib/AdaptFrameworkImport.js b/lib/AdaptFrameworkImport.js index 7f34417..0cd3616 100644 --- a/lib/AdaptFrameworkImport.js +++ b/lib/AdaptFrameworkImport.js @@ -2,7 +2,7 @@ import { App } from 'adapt-authoring-core' import fs from 'fs-extra' import { glob } from 'glob' import octopus from 'adapt-octopus' -import path from 'path' +import path from 'upath' import semver from 'semver' import ComponentTransform from './migrations/component.js' @@ -76,7 +76,7 @@ class AdaptFrameworkImport { * Path that the import will be unzipped to * @type {String} */ - this.unzipPath = unzipPath.replace(/\\/g, '/') + this.unzipPath = unzipPath /** * List of asset folders to check * @type {Array} @@ -315,7 +315,8 @@ class AdaptFrameworkImport { await Promise.all(usedPluginPaths.map(async p => { const { name, version, targetAttribute } = await fs.readJson(`${p}/bower.json`) - this.usedContentPlugins[p.split('/').pop()] = { name, path: p, version, targetAttribute } + const pluginName = path.basename(p) + this.usedContentPlugins[pluginName] = { name, path: p, version, targetAttribute } })) const files = await glob(`${this.coursePath}/**/*.json`, { absolute: true }) @@ -410,7 +411,7 @@ class AdaptFrameworkImport { tags: data.tags }) // store the asset _id so we can map it to the old path later - const resolved = path.relative(`${this.coursePath}/..`, filepath).replaceAll(path.sep, '/') + const resolved = path.relative(`${this.coursePath}/..`, filepath) this.assetMap[resolved] = asset._id.toString() } catch (e) { this.statusReport.warn.push({ code: 'ASSET_IMPORT_FAILED', data: { filepath } }) diff --git a/lib/AdaptFrameworkUtils.js b/lib/AdaptFrameworkUtils.js index d84c41d..3d23827 100644 --- a/lib/AdaptFrameworkUtils.js +++ b/lib/AdaptFrameworkUtils.js @@ -2,7 +2,7 @@ import { App } from 'adapt-authoring-core' import FrameworkBuild from './AdaptFrameworkBuild.js' import FrameworkImport from './AdaptFrameworkImport.js' import fs from 'fs' -import path from 'path' +import path from 'upath' import semver from 'semver' /** @ignore */ const buildCache = {} diff --git a/package.json b/package.json index aa12a21..398a5d2 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "glob": "^10.3.10", "lodash": "^4.17.21", "semver": "^7.6.0", + "upath": "^2.0.1", "zipper": "github:adapt-security/zipper" }, "peerDependencies": {