-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix polyfills and update SDK version (#4)
* FIX: polyfills now don't need fs module * [email protected] --------- Co-authored-by: Lesther Caballero <[email protected]>
- Loading branch information
1 parent
d486ea1
commit c680ecf
Showing
4 changed files
with
14 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,22 @@ | ||
import pathModule from "path"; | ||
import fs from "fs"; | ||
import { esmCjsMaps } from "./esm-cjs-maps.js"; | ||
|
||
// @ts-ignore | ||
import packageJson from "./package.json" assert { type: "json" }; | ||
|
||
/* | ||
This is a polyfill for the "require" Commonjs function | ||
This is needed because there are some dependencies that are not ESM compatible | ||
and we need to use the Commonjs version of the package | ||
*/ | ||
if (fs.existsSync("package.json")) { | ||
const packageJson = fs.readFileSync("package.json", "utf-8"); | ||
const packageJsonObj = JSON.parse(packageJson); | ||
|
||
if (packageJsonObj && packageJsonObj.type === "commonjs") { | ||
module.constructor.prototype.require = function (path: string) { | ||
var self = this; | ||
if (packageJson && packageJson.type === "commonjs") { | ||
module.constructor.prototype.require = function (path: string) { | ||
var self = this; | ||
|
||
if ( | ||
typeof esmCjsMaps[path] === "string" | ||
) { | ||
const dep = pathModule.resolve(__dirname, "deps", esmCjsMaps[path]); | ||
return self.constructor._load(dep, self); | ||
} | ||
return self.constructor._load(path, self); | ||
}; | ||
} | ||
if (typeof esmCjsMaps[path] === "string") { | ||
const dep = pathModule.resolve(__dirname, "deps", esmCjsMaps[path]); | ||
return self.constructor._load(dep, self); | ||
} | ||
return self.constructor._load(path, self); | ||
}; | ||
} |
This file contains 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