refactor: allow ES import for cloud string if package type is module (#7560)

* allow module import for Parse Cloud

* Update .babelrc

* catch esm error

* Update ParseServer.js

* add tests

* Update CHANGELOG.md

* Update CloudCode.spec.js

Co-authored-by: Manuel <5673677+mtrezza@users.noreply.github.com>
This commit is contained in:
dblythy
2021-09-14 22:10:37 +10:00
committed by GitHub
parent fdb7dfba9f
commit 0225340ccb
5 changed files with 23 additions and 6 deletions

View File

@@ -103,7 +103,11 @@ class ParseServer {
if (typeof cloud === 'function') {
cloud(Parse);
} else if (typeof cloud === 'string') {
require(path.resolve(process.cwd(), cloud));
if (process.env.npm_package_type === 'module') {
import(path.resolve(process.cwd(), cloud));
} else {
require(path.resolve(process.cwd(), cloud));
}
} else {
throw "argument 'cloud' must either be a string or a function";
}