UNPKG

@ng-doc/builder

Version:

<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>

27 lines 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.importFreshEsm = importFreshEsm; const tslib_1 = require("tslib"); const fs = tslib_1.__importStar(require("fs")); const path = tslib_1.__importStar(require("path")); const import_esm_1 = require("./import-esm"); const posix_1 = require("./posix"); /** * Imports a module without caching it * * This is a workaround for the issue described here: * https://github.com/nodejs/modules/issues/307 * @param modulePath - The path to the module to import */ async function importFreshEsm(modulePath) { const filepath = path.resolve(modulePath); const fileContent = await fs.promises.readFile(filepath, 'utf8'); const ext = path.extname(filepath); const extRegex = new RegExp(`\\${ext}$`); const newFilepath = `${filepath.replace(extRegex, '')}${Date.now()}${ext}`; await fs.promises.writeFile(newFilepath, fileContent); const module = await (0, import_esm_1.importEsm)((0, posix_1.posix)(newFilepath)); fs.unlink(newFilepath, () => void 0); return module; } //# sourceMappingURL=import-fresh-esm.js.map