How to use path-is-inside - 8 common examples

To help you get started, we’ve selected a few path-is-inside examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thomasboyt / peridot / src / core / watch.js View on Github external
console.log(`File "${changedPath}" changed...`);

  // Non-absolute paths are relative to cwd
  let absPath;
  if (!path.isAbsolute(changedPath)) {
    absPath = path.join(process.cwd(), changedPath);
  } else {
    absPath = changedPath;
  }

  const stylesDir = path.join(process.cwd(), 'styles');

  if (changedPath === '_entries.yml') {
    await build(['entries', 'pages']);
  } else if (pathIsInside(absPath, stylesDir)) {
    await build(['webpack']);
  } else {
    await build(['pages', 'webpack']);
  }

  if (queuedPath) {
    rebuild();
  } else {
    building = false;
  }
}
github simplyboo6 / Vimtur / server / src / config.ts View on Github external
);
    merged.transcoder.streamQualities = [...new Set(merged.transcoder.streamQualities)].sort(
      (a, b) => a - b,
    );

    const validationResult = this.validator.validate(merged);
    if (!validationResult.success) {
      throw new Error(
        validationResult.errorText || 'Merged configuration schema failed to validate.',
      );
    }

    // On the first call store the layers as the write-once base layers.
    if (!this.baseLayers) {
      // Some additional validation.
      if (PathIsInside(Path.resolve(merged.cachePath), Path.resolve(merged.libraryPath))) {
        throw new Error('Cache folder cannot be inside the library');
      }
      this.baseLayers = layers;
    }
    // Otherwise don't store the layers because they're stored in the database.
    this.merged = merged;
  }
}
github open-wc / open-wc / packages / es-dev-server / src / utils / resolve-module-imports.js View on Github external
// if this dynamic import is a concatenated string, try our best to resolve. Otherwise leave it untouched and resolve it at runtime.
      try {
        resolvedImportFilePath = await resolveConcatenatedImport(
          rootDir,
          sourceFilePath,
          importPath,
          config,
        );
      } catch (error) {
        return importPath;
      }
    } else {
      resolvedImportFilePath = await nodeResolve(rootDir, sourceFilePath, importPath, config);
    }

    if (!pathIsInside(resolvedImportFilePath, rootDir)) {
      throw new Error(
        `Import "${importPath}" resolved to the file "${resolvedImportFilePath}" which is outside the web server root, and cannot be served ` +
          'by es-dev-server. Install the module locally in the current project, or expand the root directory. ' +
          'If this is a symlink or if you used npm link, you can run es-dev-server with the --preserve-symlinks option',
      );
    }

    const relativeImportFilePath = path.relative(sourceFileDir, resolvedImportFilePath);
    const resolvedImportPath = toBrowserPath(relativeImportFilePath);
    return resolvedImportPath.startsWith('.') ? resolvedImportPath : `./${resolvedImportPath}`;
  } catch (error) {
    // make module not found error message shorter
    if (error.code === 'MODULE_NOT_FOUND') {
      const relativeImportFilePath = path.relative(rootDir, sourceFilePath);
      const resolvedImportPath = toBrowserPath(relativeImportFilePath);
      const realtivePathToErrorFile = resolvedImportPath.startsWith('.')
github simplyboo6 / Vimtur / server / src / index.ts View on Github external
app.get('/cache/:file(*)', (req: Request, res: Response) => {
    try {
      const absPath = Path.resolve(Config.get().cachePath, req.params.file);
      if (!PathIsInside(absPath, Path.resolve(Config.get().cachePath))) {
        throw new Error('File is not inside cache directory');
      }
      return res.sendFile(absPath);
    } catch (err) {
      return res.status(400).json({ message: err.message, type: 'config' });
    }
  });
github vladimiry / ElectronMail / src / electron-main / protocol.ts View on Github external
async function resolveFileSystemResourceLocation(directory: string, request: RegisterFileProtocolRequest): Promise {
    const resource = path.join(directory, new url.URL(request.url).pathname);

    if (!pathIsInside(resource, directory)) {
        throw new Error(`Forbidden file system resource "${resource}"`);
    }

    try {
        const stat = await fsAsync.stat(resource);

        if (stat.isFile()) {
            return resource;
        }

        if (stat.isDirectory()) {
            return path.join(resource, "index.html");
        }
    } catch (error) {
        if (error.code === "ENOENT") {
            return path.join(directory, "index.html");
github vladimiry / ElectronMail / scripts / prepare-webclient / lib.ts View on Github external
import mkdirp from "mkdirp";
import path from "path";
import pathIsInside from "path-is-inside";
import {promisify} from "util";

import {AccountType} from "src/shared/model/account";
import {CWD, LOG, LOG_LEVELS, execShell} from "scripts/lib";
import {PROVIDER_REPO} from "src/shared/constants";

const [, , baseDestDir] = process.argv;

if (!baseDestDir) {
    throw new Error(`Empty base destination directory argument`);
}

if (!pathIsInside(path.resolve(CWD, baseDestDir), CWD)) {
    throw new Error(`Invalid base destination directory argument value: ${LOG_LEVELS.value(baseDestDir)}`);
}

export interface FolderAsDomainEntry {
    folderNameAsDomain: string;
    options: T;
}

export type Flow = (
    arg: {
        repoDir: string;
        folderAsDomainEntry: FolderAsDomainEntry;
    },
) => Promise;

export async function execAccountTypeFlow["options"]>(
github xyc / vscode-mdx-preview / packages / extension / security / checkFsPath.ts View on Github external
export function checkFsPath(entryFsDirectory: string, fsPath: string): boolean {
  const rootDirectory = getRootDirectoryPath(entryFsDirectory);
  if (path.sep === '\\') {
    fsPath = path.normalize(fsPath);
  }
  if (!pathIsInside(fsPath, rootDirectory)) {
    return false;
  }
  return true;
}
github xyc / vscode-mdx-preview / packages / extension / security / checkFsPath.ts View on Github external
workspaceFolder => {
      return pathIsInside(entryFsDirectory, workspaceFolder.uri.fsPath);
    }
  );

path-is-inside

Tests whether one path is inside another path

(WTFPL OR MIT)
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis

Popular path-is-inside functions