Last active
January 27, 2021 14:43
-
-
Save nyan-left/892e934f36692d7eb6e170c4e590c446 to your computer and use it in GitHub Desktop.
Fix for TypeError: Os.tmpDir is not a function (https://github.com/alhazmy13/serverless-offline-python/issues/18 )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const LINE_NUMBER = 6; | |
const FILE_LOCATION = 'node_modules/hapi/lib/defaults.js' | |
const INJECT_FIX_STRING = ` | |
const isWin = process.platform === "win32"; | |
const isLinux = process.platform === "linux"; | |
const isDarwin = process.platform === "darwin"; | |
if (isDarwin || isLinux) { | |
Os.tmpDir = Os.tmpdir; | |
} else if (isWin) { | |
Os.tmpDir = os.tmpDir; | |
} | |
` | |
let data = fs.readFileSync(FILE_LOCATION) | |
if (data.includes(INJECT_FIX_STRING)) { | |
console.log("Skipping fix injection, already exists.") | |
} else { | |
data = data.toString().split("\n"); | |
data.splice(LINE_NUMBER, 0, INJECT_FIX_STRING); | |
let text = data.join("\n"); | |
fs.writeFile(FILE_LOCATION, text, (err) => { | |
if (err) { | |
return console.log(err); | |
} else { | |
return console.log('Injected fix successfully') | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: