Skip to content

Commit 6556fc5

Browse files
authored
Merge branch 'master' into cleanup-code
2 parents 76fffbc + 0225340 commit 6556fc5

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
["@babel/preset-env", {
88
"targets": {
99
"node": "12"
10-
}
10+
},
11+
"exclude": ["proposal-dynamic-import"]
1112
}]
1213
],
1314
"sourceMaps": "inline"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ ___
151151
- Refactor: uniform issue templates across repos (Manuel Trezza) [#7528](https://github.com/parse-community/parse-server/pull/7528)
152152
- ci: bump ci environment (Manuel Trezza) [#7539](https://github.com/parse-community/parse-server/pull/7539)
153153
- CI now pushes docker images to Docker Hub (Corey Baker) [#7548](https://github.com/parse-community/parse-server/pull/7548)
154+
- Allow cloud string for ES modules (Daniel Blyth) [#7560](https://github.com/parse-community/parse-server/pull/7560)
154155
- docs: Introduce deprecation ID for reference in comments and online search (Manuel Trezza) [#7562](https://github.com/parse-community/parse-server/pull/7562)
155156
- refactor: simplify Cloud Code tests and FunctionsRouter (Daniel Blyth) [#7564](https://github.com/parse-community/parse-server/pull/7564)
156157

spec/CloudCode.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ describe('Cloud Code', () => {
3838
it('can create functions', async () => {
3939
Parse.Cloud.define('hello', () => 'Hello world!');
4040
await expectAsync(Parse.Cloud.run('hello')).toBeResolvedTo('Hello world!');
41+
42+
it('can load cloud code as a module', async () => {
43+
process.env.npm_package_type = 'module';
44+
await reconfigureServer({ cloud: './spec/cloud/cloudCodeModuleFile.js' });
45+
const result = await Parse.Cloud.run('cloudCodeInFile');
46+
expect(result).toEqual('It is possible to define cloud code in a file.');
47+
delete process.env.npm_package_type;
4148
});
4249

4350
it('show warning on duplicate cloud functions', () => {

spec/cloud/cloudCodeModuleFile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Parse.Cloud.define('cloudCodeInFile', () => {
2+
return 'It is possible to define cloud code in a file.';
3+
});

src/ParseServer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ class ParseServer {
103103
if (typeof cloud === 'function') {
104104
cloud(Parse);
105105
} else if (typeof cloud === 'string') {
106-
require(path.resolve(process.cwd(), cloud));
106+
if (process.env.npm_package_type === 'module') {
107+
import(path.resolve(process.cwd(), cloud));
108+
} else {
109+
require(path.resolve(process.cwd(), cloud));
110+
}
107111
} else {
108112
throw "argument 'cloud' must either be a string or a function";
109113
}

0 commit comments

Comments
 (0)