Skip to content

Commit 0225340

Browse files
dblythymtrezza
andauthored
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>
1 parent fdb7dfb commit 0225340

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

.babelrc

+2-1
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

+5-4
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

156157
## 4.10.3
@@ -178,15 +179,15 @@ ___
178179

179180
*Versions >4.5.2 and <4.10.0 are skipped.*
180181

181-
> ⚠️ A security incident caused a number of incorrect version tags to be pushed to the Parse Server repository. These version tags linked to a personal fork of a contributor who had write access to the repository. The code to which these tags linked has not been reviewed or approved by Parse Platform. Even though no releases were published with these incorrect versions, it was possible to define a Parse Server dependency that pointed to these version tags, for example if you defined this dependency:
182+
> ⚠️ A security incident caused a number of incorrect version tags to be pushed to the Parse Server repository. These version tags linked to a personal fork of a contributor who had write access to the repository. The code to which these tags linked has not been reviewed or approved by Parse Platform. Even though no releases were published with these incorrect versions, it was possible to define a Parse Server dependency that pointed to these version tags, for example if you defined this dependency:
182183
> ```js
183184
> "parse-server": "git@github.com:parse-community/parse-server.git#4.9.3"
184185
> ```
185-
>
186+
>
186187
> We have since deleted the incorrect version tags, but they may still show up if your personal fork on GitHub or locally. We do not know when these tags have been pushed to the Parse Server repository, but we first became aware of this issue on July 21, 2021. We are not aware of any malicious code or concerns related to privacy, security or legality (e.g. proprietary code). However, it has been reported that some functionality does not work as expected and the introduction of security vulnerabilities cannot be ruled out.
187188
>
188-
> You may be also affected if you used the Bitnami image for Parse Server. Bitnami picked up the incorrect version tag `4.9.3` and published a new Bitnami image for Parse Server.
189-
>
189+
> You may be also affected if you used the Bitnami image for Parse Server. Bitnami picked up the incorrect version tag `4.9.3` and published a new Bitnami image for Parse Server.
190+
>
190191
>**If you are using any of the affected versions, we urgently recommend to upgrade to version `4.10.0`.**
191192
192193
## 4.5.2

spec/CloudCode.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ describe('Cloud Code', () => {
3939
});
4040
});
4141

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;
48+
});
49+
4250
it('can create functions', done => {
4351
Parse.Cloud.define('hello', () => {
4452
return 'Hello world!';

spec/cloud/cloudCodeModuleFile.js

+3
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

+5-1
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)