Skip to content

Commit

Permalink
[FIX] Windows: Correctly handle project paths containing non-ASCII ch…
Browse files Browse the repository at this point in the history
…aracters

The `slash` module does not convert "extended-length" paths or paths
which contain non-ASCII characters as documented in the modules README:
https://github.com/sindresorhus/slash/blob/7a9158487d8046c13f2de1db7e3734d33bdbb1bd/readme.md#slash-

Since in our case the resulting POSIX paths are only used in our virtual
fs "@ui5/fs", these limitations are not relevent to us.

Therefore we can simply replace any backslashes.

Related to SAP/ui5-fs#294
Resolves SAP/ui5-tooling#469
  • Loading branch information
RandomByte committed Dec 18, 2020
1 parent 9f29bba commit b229bf3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
3 changes: 1 addition & 2 deletions lib/types/application/ApplicationFormatter.js
Expand Up @@ -3,7 +3,6 @@ const path = require("path");
const fs = require("graceful-fs");
const {promisify} = require("util");
const readFile = promisify(fs.readFile);
const slash = require("slash");
const AbstractUi5Formatter = require("../AbstractUi5Formatter");

class ApplicationFormatter extends AbstractUi5Formatter {
Expand Down Expand Up @@ -44,7 +43,7 @@ class ApplicationFormatter extends AbstractUi5Formatter {
let p = path;
let projectPath = this._project.path;
if (posix) {
projectPath = slash(projectPath);
projectPath = projectPath.replace(/\\/g, "/");
p = path.posix;
}
return p.join(projectPath, this._project.resources.pathMappings["/"]);
Expand Down
5 changes: 2 additions & 3 deletions lib/types/library/LibraryFormatter.js
Expand Up @@ -4,7 +4,6 @@ const fs = require("graceful-fs");
const {promisify} = require("util");
const readFile = promisify(fs.readFile);
const glob = require("globby");
const slash = require("slash");
const AbstractUi5Formatter = require("../AbstractUi5Formatter");

const SAP_THEMES_NS_EXEMPTIONS = ["themelib_sap_fiori_3", "themelib_sap_bluecrystal", "themelib_sap_belize"];
Expand Down Expand Up @@ -67,7 +66,7 @@ class LibraryFormatter extends AbstractUi5Formatter {
let p = path;
let projectPath = this._project.path;
if (posix) {
projectPath = slash(projectPath);
projectPath = projectPath.replace(/\\/g, "/");
p = path.posix;
}
return p.join(projectPath, this._project.resources.pathMappings["/resources/"]);
Expand Down Expand Up @@ -247,7 +246,7 @@ class LibraryFormatter extends AbstractUi5Formatter {

getNamespaceFromFsPath(fsPath) {
// Transform path to POSIX and remove any trailing slashes
const posixFsPath = slash(fsPath).replace(/\/$/, "");
const posixFsPath = fsPath.replace(/\\/g, "/").replace(/\/$/, "");

// Remove base path from fsPath
const posixBasePath = this.getSourceBasePath(true);
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -122,7 +122,6 @@
"replacestream": "^4.0.3",
"rimraf": "^3.0.2",
"semver": "^7.3.4",
"slash": "^3.0.0",
"terser": "^5.5.1",
"xml2js": "^0.4.23",
"yazl": "^2.5.1"
Expand Down

0 comments on commit b229bf3

Please sign in to comment.