get-compiled-path.js 749 B

123456789101112131415161718
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.getCompiledPath = void 0;
  7. var crypto_1 = __importDefault(require("crypto"));
  8. var path_1 = __importDefault(require("path"));
  9. var cwd = process.cwd();
  10. exports.getCompiledPath = function (code, fileName, compiledDir) {
  11. var hash = crypto_1.default
  12. .createHash('sha256')
  13. .update(fileName + code, 'utf8')
  14. .digest('hex');
  15. fileName = path_1.default.relative(cwd, fileName);
  16. var hashed = fileName.replace(/[^\w]/g, '_') + '_' + hash + '.js';
  17. return path_1.default.join(compiledDir, hashed);
  18. };