Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Jun 15, 2024
1 parent d540361 commit afc6242
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 49 deletions.
8 changes: 3 additions & 5 deletions Website/src/native/IsolatedEval/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chooser } from "@Native/Chooser";
import { Terminal } from "@Native/Terminal";
import path from "@Util/path.js";
import { Path } from "@Util/path.js";
import { transform } from "@babel/standalone";
import Sandbox from "@nyariv/sandboxjs";
import { IScope } from "@nyariv/sandboxjs/dist/node/executor";
Expand Down Expand Up @@ -86,7 +86,7 @@ class IsolatedEval<T = any> {
private readonly _prototypeWhitelist = Sandbox.SAFE_PROTOTYPES;
public moduleCache: {};
public module: IsoModule;
public path: typeof path;
public path: Path;
public libraries: Record<string, any>;
public indexFile: string;
public scope: IScope;
Expand Down Expand Up @@ -129,9 +129,7 @@ class IsolatedEval<T = any> {
};
this.moduleCache = {};

this.path = path;
// @ts-ignore
this.path.cwd = cwd;
this.path = new Path(cwd);

this.libraries = libraries;
this.indexFile = indexFile;
Expand Down
81 changes: 37 additions & 44 deletions Website/src/util/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,27 @@ function _format(sep, pathObject) {
return dir + sep + base;
}

const posix = {
_cwd: undefined,

set cwd(path) {
this._cwd = path;
},

get cwd() {
return this._cwd;
},
class Path {
cwd = undefined;
sep = "/";
delimiter = ":";
win32 = null;
posix = null;

constructor(cwd) {
this.cwd = cwd;
}

// path.resolve([from ...], to)
resolve: function resolve() {
resolve() {
var resolvedPath = "";
var resolvedAbsolute = false;

for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path;
if (i >= 0) path = arguments[i];
else {
if (this._cwd === undefined) this._cwd = "/";
path = this._cwd;
if (this.cwd === undefined) this.cwd = "/";
path = this.cwd;
}

assertPath(path);
Expand Down Expand Up @@ -129,9 +128,9 @@ const posix = {
} else {
return ".";
}
},
}

normalize: function normalize(path) {
normalize(path) {
assertPath(path);

if (path.length === 0) return ".";
Expand All @@ -147,14 +146,14 @@ const posix = {

if (isAbsolute) return "/" + path;
return path;
},
}

isAbsolute: function isAbsolute(path) {
isAbsolute(path) {
assertPath(path);
return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
},
}

join: function join() {
join() {
if (arguments.length === 0) return ".";
var joined;
for (var i = 0; i < arguments.length; ++i) {
Expand All @@ -167,9 +166,9 @@ const posix = {
}
if (joined === undefined) return ".";
return posix.normalize(joined);
},
}

relative: function relative(from, to) {
relative(from, to) {
assertPath(from);
assertPath(to);

Expand Down Expand Up @@ -249,13 +248,13 @@ const posix = {
if (to.charCodeAt(toStart) === 47 /*/*/) ++toStart;
return to.slice(toStart);
}
},
}

_makeLong: function _makeLong(path) {
_makeLong(path) {
return path;
},
}

dirname: function dirname(path) {
dirname(path) {
assertPath(path);
if (path.length === 0) return ".";
var code = path.charCodeAt(0);
Expand All @@ -278,9 +277,9 @@ const posix = {
if (end === -1) return hasRoot ? "/" : ".";
if (hasRoot && end === 1) return "//";
return path.slice(0, end);
},
}

basename: function basename(path, ext) {
basename(path, ext) {
if (ext !== undefined && typeof ext !== "string") throw new TypeError('"ext" argument must be a string');
assertPath(path);

Expand Down Expand Up @@ -350,9 +349,9 @@ const posix = {
if (end === -1) return "";
return path.slice(start, end);
}
},
}

extname: function extname(path) {
extname(path) {
assertPath(path);
var startDot = -1;
var startPart = 0;
Expand Down Expand Up @@ -400,16 +399,16 @@ const posix = {
return "";
}
return path.slice(startDot, end);
},
}

format: function format(pathObject) {
format(pathObject) {
if (pathObject === null || typeof pathObject !== "object") {
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
}
return _format("/", pathObject);
},
}

parse: function parse(path) {
parse(path) {
assertPath(path);

var ret = { root: "", dir: "", base: "", ext: "", name: "" };
Expand Down Expand Up @@ -489,14 +488,8 @@ const posix = {
else if (isAbsolute) ret.dir = "/";

return ret;
},

sep: "/",
delimiter: ":",
win32: null,
posix: null,
};

posix.posix = posix;
}
}

export default posix;
const path = new Path(undefined);
export { path, Path };

0 comments on commit afc6242

Please sign in to comment.