當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fs.realpathSync函數代碼示例

本文整理匯總了TypeScript中fs.realpathSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript realpathSync函數的具體用法?TypeScript realpathSync怎麽用?TypeScript realpathSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了realpathSync函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getNodeSystem


//.........這裏部分代碼省略.........
                args: process.argv.slice(2),
                newLine: _os.EOL,
                useCaseSensitiveFileNames: useCaseSensitiveFileNames,
                write(s: string): void {
                    process.stdout.write(s);
                },
                readFile,
                writeFile,
                watchFile: (fileName, callback) => {
                    if (useNonPollingWatchers) {
                        const watchedFile = watchedFileSet.addFile(fileName, callback);
                        return {
                            close: () => watchedFileSet.removeFile(watchedFile)
                        };
                    }
                    else {
                        _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged);
                        return {
                            close: () => _fs.unwatchFile(fileName, fileChanged)
                        };
                    }

                    function fileChanged(curr: any, prev: any) {
                        if (+curr.mtime <= +prev.mtime) {
                            return;
                        }

                        callback(fileName);
                    }
                },
                watchDirectory: (directoryName, callback, recursive) => {
                    // Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
                    // (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
                    let options: any;
                    if (isNode4OrLater() && (process.platform === "win32" || process.platform === "darwin")) {
                        options = { persistent: true, recursive: !!recursive };
                    }
                    else {
                        options = { persistent: true };
                    }

                    return _fs.watch(
                        directoryName,
                        options,
                        (eventName: string, relativeFileName: string) => {
                            // In watchDirectory we only care about adding and removing files (when event name is
                            // "rename"); changes made within files are handled by corresponding fileWatchers (when
                            // event name is "change")
                            if (eventName === "rename") {
                                // When deleting a file, the passed baseFileName is null
                                callback(!relativeFileName ? relativeFileName : normalizePath(combinePaths(directoryName, relativeFileName)));
                            };
                        }
                    );
                },
                resolvePath: function (path: string): string {
                    return _path.resolve(path);
                },
                fileExists,
                directoryExists,
                createDirectory(directoryName: string) {
                    if (!this.directoryExists(directoryName)) {
                        _fs.mkdirSync(directoryName);
                    }
                },
                getExecutingFilePath() {
                    return __filename;
                },
                getCurrentDirectory() {
                    return process.cwd();
                },
                getDirectories,
                readDirectory,
                getModifiedTime(path) {
                    try {
                        return _fs.statSync(path).mtime;
                    }
                    catch (e) {
                        return undefined;
                    }
                },
                createHash(data) {
                    const hash = _crypto.createHash("md5");
                    hash.update(data);
                    return hash.digest("hex");
                },
                getMemoryUsage() {
                    if (global.gc) {
                        global.gc();
                    }
                    return process.memoryUsage().heapUsed;
                },
                exit(exitCode?: number): void {
                    process.exit(exitCode);
                },
                realpath(path: string): string {
                    return _fs.realpathSync(path);
                }
            };
        }
開發者ID:om3r,項目名稱:typescript-closure-compiler-1.8,代碼行數:101,代碼來源:sys.ts

示例2:

				.find((d) => path.join(root, "packages", d) === fs.realpathSync(path.join(root, "packages", d)))
開發者ID:DanTup,項目名稱:Dart-Code,代碼行數:1,代碼來源:utils.ts

示例3: checkPath

 private checkPath(path: string) {
   if (!fs.realpathSync(path).startsWith(fs.realpathSync(this.repoRoot))) {
     throw new Error('invalid path');
   }
 }
開發者ID:elastic,項目名稱:kibana,代碼行數:5,代碼來源:git_operations.ts

示例4: if

import * as path from 'path'
import resolve from 'resolve'

const ensureSlash = (filepath: any, needsSlash: boolean) => {
  const hasSlash = filepath.endsWith('/')

  if (hasSlash && !needsSlash) {
    return filepath.substr(filepath, filepath.length - 1)
  } else if (!hasSlash && needsSlash) {
    return `${filepath}/`
  } else {
    return filepath
  }
}

export const root = fs.realpathSync(process.cwd())
const resolveApp = (to: string) => path.resolve(root, to)

export interface Paths {
  root: string
  templates: string
  packageJson: string
  servedPath: (base: string) => string
  docz: string
  app: string
  getDist: (dest: string) => string
  distPublic: (dest: string) => string
  importsJs: string
  rootJs: string
  indexJs: string
  indexHtml: string
開發者ID:leslieSie,項目名稱:docz,代碼行數:31,代碼來源:paths.ts

示例5:

    {
        let s = '123';
        let b: Buffer;
        fs.realpath('/path/to/folder', (err, resolvedPath) => s = resolvedPath);
        fs.realpath('/path/to/folder', undefined, (err, resolvedPath) => s = resolvedPath);
        fs.realpath('/path/to/folder', 'utf8', (err, resolvedPath) => s = resolvedPath);
        fs.realpath('/path/to/folder', 'buffer', (err, resolvedPath) => b = resolvedPath);
        fs.realpath('/path/to/folder', s, (err, resolvedPath) => typeof resolvedPath === 'string' ? s = resolvedPath : b = resolvedPath);
        fs.realpath('/path/to/folder', {}, (err, resolvedPath) => s = resolvedPath);
        fs.realpath('/path/to/folder', { encoding: undefined }, (err, resolvedPath) => s = resolvedPath);
        fs.realpath('/path/to/folder', { encoding: 'utf8' }, (err, resolvedPath) => s = resolvedPath);
        fs.realpath('/path/to/folder', { encoding: 'buffer' }, (err, resolvedPath) => b = resolvedPath);
        fs.realpath('/path/to/folder', { encoding: s }, (err, resolvedPath) => typeof resolvedPath === "string" ? s = resolvedPath : b = resolvedPath);

        s = fs.realpathSync('/path/to/folder');
        s = fs.realpathSync('/path/to/folder', undefined);
        s = fs.realpathSync('/path/to/folder', 'utf8');
        b = fs.realpathSync('/path/to/folder', 'buffer');
        const v1 = fs.realpathSync('/path/to/folder', s);
        typeof v1 === "string" ? s = v1 : b = v1;

        s = fs.realpathSync('/path/to/folder', {});
        s = fs.realpathSync('/path/to/folder', { encoding: undefined });
        s = fs.realpathSync('/path/to/folder', { encoding: 'utf8' });
        b = fs.realpathSync('/path/to/folder', { encoding: 'buffer' });
        const v2 = fs.realpathSync('/path/to/folder', { encoding: s });
        typeof v2 === "string" ? s = v2 : b = v2;

        // native
        fs.realpath.native('/path/to/folder', (err, resolvedPath) => s = resolvedPath);
開發者ID:ChaosinaCan,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:node-tests.ts

示例6:

 filePaths.map((filePath: string): string => fs.realpathSync(filePath)));
開發者ID:dufrannea,項目名稱:TSLint.MSBuild,代碼行數:1,代碼來源:LintRunner.ts

示例7: comparePath

 function comparePath(pathA: string, pathB: string) {
   const pa = fs.realpathSync(pathA);
   const pb = fs.realpathSync(pathB);
   return path.resolve(pa) === path.resolve(pb);
 }
開發者ID:elastic,項目名稱:kibana,代碼行數:5,代碼來源:lsp_service.ts


注:本文中的fs.realpathSync函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。