• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript graceful-fs.readFileSync函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中graceful-fs.readFileSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readFileSync函数的具体用法?TypeScript readFileSync怎么用?TypeScript readFileSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了readFileSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: _loadModule

  private _loadModule(
    localModule: InitialModule,
    from: Config.Path,
    moduleName: string | undefined,
    modulePath: Config.Path,
    options: InternalModuleOptions | undefined,
    moduleRegistry: ModuleRegistry,
  ) {
    if (path.extname(modulePath) === '.json') {
      const text = stripBOM(fs.readFileSync(modulePath, 'utf8'));

      const transformedFile = this._scriptTransformer.transformJson(
        modulePath,
        this._getFullTransformationOptions(options),
        text,
      );

      localModule.exports = this._environment.global.JSON.parse(
        transformedFile,
      );
    } else if (path.extname(modulePath) === '.node') {
      localModule.exports = require(modulePath);
    } else {
      // Only include the fromPath if a moduleName is given. Else treat as root.
      const fromPath = moduleName ? from : null;
      this._execModule(localModule, options, moduleRegistry, fromPath);
    }
    localModule.loaded = true;
  }
开发者ID:facebook,项目名称:jest,代码行数:29,代码来源:index.ts


示例2: catch

const readCacheFile = (cachePath: Config.Path): string | null => {
  if (!fs.existsSync(cachePath)) {
    return null;
  }

  let fileData;
  try {
    fileData = fs.readFileSync(cachePath, 'utf8');
  } catch (e) {
    e.message =
      'jest: failed to read cache file: ' +
      cachePath +
      '\nFailure message: ' +
      e.message;
    removeFile(cachePath);
    throw e;
  }

  if (fileData == null) {
    // We must have somehow created the file but failed to write to it,
    // let's delete it and retry.
    removeFile(cachePath);
  }
  return fileData;
};
开发者ID:Volune,项目名称:jest,代码行数:25,代码来源:ScriptTransformer.ts


示例3: getServer

function getServer(): any {
    if (config.get("protocol") === "https" ) {
        let certificate = fs.readFileSync(config.get("ssl_cert") as string);
        let privateKey = fs.readFileSync(config.get("ssl_key") as string);
        console.log("creating https server");
        let server = https.createServer({key: privateKey, cert: certificate}, app);
        server.setTimeout(0);
        return server;
    }
    else {
        console.log("creating http server");
        let server = http.createServer(app);
        server.setTimeout(0);
        return server;
    }
}
开发者ID:usa-npn,项目名称:pop-service,代码行数:16,代码来源:server.ts


示例4:

  const getContent = (): string => {
    if (content === undefined) {
      content = fs.readFileSync(filePath, 'utf8');
    }

    return content;
  };
开发者ID:Volune,项目名称:jest,代码行数:7,代码来源:worker.ts


示例5: getSha1

export async function getSha1(data: WorkerMessage): Promise<WorkerMetadata> {
  const sha1 = data.computeSha1
    ? sha1hex(fs.readFileSync(data.filePath))
    : null;

  return {
    dependencies: undefined,
    id: undefined,
    module: undefined,
    sha1,
  };
}
开发者ID:Volune,项目名称:jest,代码行数:12,代码来源:worker.ts


示例6: catch

    retrieveSourceMap: source => {
      const sourceMaps = runtime && runtime.getSourceMaps();
      const sourceMapSource = sourceMaps && sourceMaps[source];

      if (sourceMapSource) {
        try {
          return {
            map: JSON.parse(fs.readFileSync(sourceMapSource, 'utf8')),
            url: source,
          };
        } catch (e) {}
      }
      return null;
    },
开发者ID:Volune,项目名称:jest,代码行数:14,代码来源:runTest.ts


示例7: default

export default (level: number, sourceMaps?: SourceMapRegistry | null) => {
  const levelAfterThisCall = level + 1;
  const stack = callsites()[levelAfterThisCall];
  const sourceMapFileName = sourceMaps && sourceMaps[stack.getFileName() || ''];

  if (sourceMapFileName) {
    try {
      const sourceMap = fs.readFileSync(sourceMapFileName, 'utf8');
      // @ts-ignore: Not allowed to pass string
      addSourceMapConsumer(stack, new SourceMapConsumer(sourceMap));
    } catch (e) {
      // ignore
    }
  }

  return stack;
};
开发者ID:Volune,项目名称:jest,代码行数:17,代码来源:getCallsite.ts


示例8: requireModule

  requireModule(
    from: Config.Path,
    moduleName?: string,
    options?: InternalModuleOptions,
    isRequireActual?: boolean | null,
  ) {
    const moduleID = this._resolver.getModuleID(
      this._virtualMocks,
      from,
      moduleName,
    );
    let modulePath;

    // Some old tests rely on this mocking behavior. Ideally we'll change this
    // to be more explicit.
    const moduleResource = moduleName && this._resolver.getModule(moduleName);
    const manualMock =
      moduleName && this._resolver.getMockModule(from, moduleName);
    if (
      (!options || !options.isInternalModule) &&
      !isRequireActual &&
      !moduleResource &&
      manualMock &&
      manualMock !== this._isCurrentlyExecutingManualMock &&
      this._explicitShouldMock[moduleID] !== false
    ) {
      modulePath = manualMock;
    }

    if (moduleName && this._resolver.isCoreModule(moduleName)) {
      return this._requireCoreModule(moduleName);
    }

    if (!modulePath) {
      modulePath = this._resolveModule(from, moduleName);
    }

    let moduleRegistry;

    if (!options || !options.isInternalModule) {
      if (this._moduleRegistry[modulePath] || !this._isolatedModuleRegistry) {
        moduleRegistry = this._moduleRegistry;
      } else {
        moduleRegistry = this._isolatedModuleRegistry;
      }
    } else {
      moduleRegistry = this._internalModuleRegistry;
    }

    if (!moduleRegistry[modulePath]) {
      // We must register the pre-allocated module object first so that any
      // circular dependencies that may arise while evaluating the module can
      // be satisfied.
      const localModule: InitialModule = {
        children: [],
        exports: {},
        filename: modulePath,
        id: modulePath,
        loaded: false,
      };
      moduleRegistry[modulePath] = localModule;
      if (path.extname(modulePath) === '.json') {
        localModule.exports = this._environment.global.JSON.parse(
          stripBOM(fs.readFileSync(modulePath, 'utf8')),
        );
      } else if (path.extname(modulePath) === '.node') {
        localModule.exports = require(modulePath);
      } else {
        // Only include the fromPath if a moduleName is given. Else treat as root.
        const fromPath = moduleName ? from : null;
        this._execModule(localModule, options, moduleRegistry, fromPath);
      }

      localModule.loaded = true;
    }
    return moduleRegistry[modulePath].exports;
  }
开发者ID:Volune,项目名称:jest,代码行数:77,代码来源:index.ts


示例9: runTestInternal

// Keeping the core of "runTest" as a separate function (as "runTestInternal")
// is key to be able to detect memory leaks. Since all variables are local to
// the function, when "runTestInternal" finishes its execution, they can all be
// freed, UNLESS something else is leaking them (and that's why we can detect
// the leak!).
//
// If we had all the code in a single function, we should manually nullify all
// references to verify if there is a leak, which is not maintainable and error
// prone. That's why "runTestInternal" CANNOT be inlined inside "runTest".
async function runTestInternal(
  path: Config.Path,
  globalConfig: Config.GlobalConfig,
  config: Config.ProjectConfig,
  resolver: Resolver,
  context?: TestRunnerContext,
): Promise<RunTestInternalResult> {
  const testSource = fs.readFileSync(path, 'utf8');
  const parsedDocblock = docblock.parse(docblock.extract(testSource));
  const customEnvironment = parsedDocblock['jest-environment'];

  let testEnvironment = config.testEnvironment;

  if (customEnvironment) {
    if (Array.isArray(customEnvironment)) {
      throw new Error(
        `You can only define a single test environment through docblocks, got "${customEnvironment.join(
          ', ',
        )}"`,
      );
    }
    testEnvironment = getTestEnvironment({
      ...config,
      testEnvironment: customEnvironment,
    });
  }

  const TestEnvironment: typeof JestEnvironment = require(testEnvironment);
  const testFramework: TestFramework =
    process.env.JEST_CIRCUS === '1'
      ? require('jest-circus/runner') // eslint-disable-line import/no-extraneous-dependencies
      : require(config.testRunner);
  const Runtime: typeof RuntimeClass = config.moduleLoader
    ? require(config.moduleLoader)
    : require('jest-runtime');

  let runtime: RuntimeClass | undefined = undefined;

  const consoleOut = globalConfig.useStderr ? process.stderr : process.stdout;
  const consoleFormatter = (type: LogType, message: LogMessage) =>
    getConsoleOutput(
      config.cwd,
      !!globalConfig.verbose,
      // 4 = the console call is buried 4 stack frames deep
      BufferedConsole.write(
        [],
        type,
        message,
        4,
        runtime && runtime.getSourceMaps(),
      ),
    );

  let testConsole;

  if (globalConfig.silent) {
    testConsole = new NullConsole(consoleOut, process.stderr, consoleFormatter);
  } else if (globalConfig.verbose) {
    testConsole = new CustomConsole(
      consoleOut,
      process.stderr,
      consoleFormatter,
    );
  } else {
    testConsole = new BufferedConsole(() => runtime && runtime.getSourceMaps());
  }

  const environment = new TestEnvironment(config, {
    console: testConsole,
    testPath: path,
  });
  const leakDetector = config.detectLeaks
    ? new LeakDetector(environment)
    : null;

  const cacheFS = {[path]: testSource};
  setGlobal(environment.global, 'console', testConsole);

  runtime = new Runtime(config, environment, resolver, cacheFS, {
    changedFiles: context && context.changedFiles,
    collectCoverage: globalConfig.collectCoverage,
    collectCoverageFrom: globalConfig.collectCoverageFrom,
    collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom,
  });

  const start = Date.now();

  const sourcemapOptions: SourceMapOptions = {
    environment: 'node',
    handleUncaughtExceptions: false,
    retrieveSourceMap: source => {
//.........这里部分代码省略.........
开发者ID:Volune,项目名称:jest,代码行数:101,代码来源:runTest.ts


示例10: express

import cassandraSeed from './cassandra-db/seed';
import mongoSeed from './mongo-db/seed';
import sqlSeed from './sql-db/seed';
import {connect, disconnect} from './db-connect';

const isSecure = config.https_secure && (process.env.NODE_ENV === 'production' || !process.env.NODE_ENV);

// Initialize express
let app = express();

// Initialize http server
let server: any = http.createServer(app);
// If specified in the default assets, https will be used
if (isSecure) {
  let credentials = {
    key: fs.readFileSync(config.key_loc, 'utf8'),
    cert: fs.readFileSync(config.cert_loc, 'utf8')
  };

  server = https.createServer(credentials, app);
}
// Initialize the socketio with the respective server
let socketio = require('socket.io')(server, {
  // serveClient: process.env.NODE_ENV !== 'production',
  path: '/socket.io-client'
});

connect().subscribe(
  x => {},
  err => console.log(err),
  () => {
开发者ID:projectSHAI,项目名称:expressgular2,代码行数:31,代码来源:server.ts



注:本文中的graceful-fs.readFileSync函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript graceful-fs.writeFile函数代码示例发布时间:2022-05-25
下一篇:
TypeScript graceful-fs.readFile函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap