index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. exports.deserialize = deserialize;
  7. exports.readFileSync = readFileSync;
  8. exports.serialize = serialize;
  9. exports.writeFileSync = writeFileSync;
  10. function _v() {
  11. const data = require('v8');
  12. _v = function () {
  13. return data;
  14. };
  15. return data;
  16. }
  17. function fs() {
  18. const data = _interopRequireWildcard(require('graceful-fs'));
  19. fs = function () {
  20. return data;
  21. };
  22. return data;
  23. }
  24. function _getRequireWildcardCache(nodeInterop) {
  25. if (typeof WeakMap !== 'function') return null;
  26. var cacheBabelInterop = new WeakMap();
  27. var cacheNodeInterop = new WeakMap();
  28. return (_getRequireWildcardCache = function (nodeInterop) {
  29. return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
  30. })(nodeInterop);
  31. }
  32. function _interopRequireWildcard(obj, nodeInterop) {
  33. if (!nodeInterop && obj && obj.__esModule) {
  34. return obj;
  35. }
  36. if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
  37. return {default: obj};
  38. }
  39. var cache = _getRequireWildcardCache(nodeInterop);
  40. if (cache && cache.has(obj)) {
  41. return cache.get(obj);
  42. }
  43. var newObj = {};
  44. var hasPropertyDescriptor =
  45. Object.defineProperty && Object.getOwnPropertyDescriptor;
  46. for (var key in obj) {
  47. if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
  48. var desc = hasPropertyDescriptor
  49. ? Object.getOwnPropertyDescriptor(obj, key)
  50. : null;
  51. if (desc && (desc.get || desc.set)) {
  52. Object.defineProperty(newObj, key, desc);
  53. } else {
  54. newObj[key] = obj[key];
  55. }
  56. }
  57. }
  58. newObj.default = obj;
  59. if (cache) {
  60. cache.set(obj, newObj);
  61. }
  62. return newObj;
  63. }
  64. /**
  65. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  66. *
  67. * This source code is licensed under the MIT license found in the
  68. * LICENSE file in the root directory of this source tree.
  69. */
  70. // TODO: Remove this
  71. /// <reference path="../v8.d.ts" />
  72. // JSON and V8 serializers are both stable when it comes to compatibility. The
  73. // current JSON specification is well defined in RFC 8259, and V8 ensures that
  74. // the versions are compatible by encoding the serialization version in the own
  75. // generated buffer.
  76. // In memory functions.
  77. function deserialize(buffer) {
  78. return (0, _v().deserialize)(buffer);
  79. }
  80. function serialize(content) {
  81. return (0, _v().serialize)(content);
  82. } // Synchronous filesystem functions.
  83. function readFileSync(filePath) {
  84. return (0, _v().deserialize)(fs().readFileSync(filePath));
  85. }
  86. function writeFileSync(filePath, content) {
  87. return fs().writeFileSync(filePath, (0, _v().serialize)(content));
  88. }
  89. var _default = {
  90. deserialize,
  91. readFileSync,
  92. serialize,
  93. writeFileSync
  94. };
  95. exports.default = _default;