Sha256: c866c64778ee9cf51a6140699bf3652693e8e601109c1d749e4ba2f466552988
Contents?: true
Size: 1.37 KB
Versions: 8
Compression:
Stored size: 1.37 KB
Contents
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; const fs = require('fs'); const path = require('path'); const temp = require('temp'); function renameFileTo(oldPath, newFilename, extension = '') { const projectPath = path.dirname(oldPath); const newPath = path.join(projectPath, newFilename + extension); fs.mkdirSync(path.dirname(newPath), { recursive: true }); fs.renameSync(oldPath, newPath); return newPath; } function createTempFileWith(content, filename, extension) { const info = temp.openSync({ suffix: extension }); let filePath = info.path; fs.writeSync(info.fd, content); fs.closeSync(info.fd); if (filename) { filePath = renameFileTo(filePath, filename, extension); } return filePath; } exports.createTempFileWith = createTempFileWith; // Test transform files need a js extension to work with @babel/register // .ts or .tsx work as well function createTransformWith(content, ext='.js') { return createTempFileWith( 'module.exports = function(fileInfo, api, options) { ' + content + ' }', undefined, ext ); } exports.createTransformWith = createTransformWith; function getFileContent(filePath) { return fs.readFileSync(filePath).toString(); } exports.getFileContent = getFileContent;
Version data entries
8 entries across 8 versions & 1 rubygems