Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
resolver.getHook('resolved').tap('LuaRootResolvePlugin', request => {
let result;
// TODO: Check if there's a better way to check if resolved path is a module
const isModule = request.descriptionFileRoot !== this.localDescriptionFileRoot;
// Array.from(resolveContext.stack).some(x => x.startsWith('module: '));
if (isModule) {
const relative = path.relative(path.dirname(request.descriptionFileRoot), request.path);
result = `node_modules/${relative}`;
} else {
result = path.relative(this.luaRoot, request.path);
if (result.startsWith('..') || path.isAbsolute(result)) {
throw new Error(`Couldn't resolve path "${request.path}" within luaRoot`);
}
}
result = path.toUnix(path.trimExt(result));
if (result.includes('.')) {
throw new Error(`Resolved path shouldn't contain dots`);
}
result = result.replace(/\//g, '.');
request.path = result;
return request;
});
}
const findLibrariesForResourceImpl = () => {
var ns;
var pos;
// check for absolute path first, in windows c:/ is a valid absolute name
if (path.isAbsolute(uri)) {
let library = this.__analyser.getLibraries().find(lib => uri.startsWith(path.resolve(lib.getRootDir())));
return library || null;
}
// Explicit library?
pos = uri.indexOf(":");
if (pos !== -1) {
ns = uri.substring(0, pos);
let library = this.__analyser.findLibrary(ns);
return library || null;
}
// Non-wildcards are a direct lookup
// check for $ and *. less pos wins
// fix for https://github.com/qooxdoo/qooxdoo-compiler/issues/260
var pos1 = uri.indexOf("$"); // Variable references are effectively a wildcard lookup
getUserQxPath : async function() {
let qxpath = await this.getAppQxPath();
return path.isAbsolute(qxpath) ? qxpath : path.resolve(qxpath);
},
getAsset(srcPath, create) {
let library = this.findLibraryForResource(srcPath);
if (!library) {
this.warn("Cannot find library for " + srcPath);
return null;
}
let resourceDir = path.join(library.getRootDir(), library.getResourcePath());
srcPath = path.relative(resourceDir, path.isAbsolute(srcPath)?srcPath:path.join(resourceDir, srcPath));
let asset = this.__assets[library.getNamespace() + ":" + srcPath];
if (!asset && create) {
asset = new qx.tool.compiler.resources.Asset(library, srcPath, {
resourcePath: "resourcePath"
});
this.__addAsset(asset);
}
return asset;
},
private getPathRelativeToInstallPath(
normalizedInstallPath: string,
maybeRelativePath: string
) {
const normalizedRelativePath = path.normalizeSafe(maybeRelativePath);
if (path.isAbsolute(normalizedRelativePath)) {
return normalizedRelativePath;
}
return path.resolve(
path.join(normalizedInstallPath, maybeRelativePath)
);
}
resolvePathPackage (req: string) {
if (!path.isAbsolute(req)) {
req = path.resolve(this.cwd, req)
}
const normalized = fsExistsFallback([
req,
req + '.js',
path.resolve(req, 'index.js')
])
if (!normalized) {
throw new Error(`${req} Not Found.`)
}
const dirname = path.parse(normalized).name
const { shortcut, name } = this.normalizeName(dirname)
try {
export = function toAbsolutePath (raw: string, cwd: string = process.cwd()) {
if (path.isAbsolute(raw)) {
return raw
}
return path.resolve(cwd, raw)
}