mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
only use json-cycles when opt-in, for state serialization
This commit is contained in:
parent
543bed3cbd
commit
8d9f4a296b
@ -39,15 +39,15 @@ class Utils {
|
||||
return fse.mkdirsSync(path.dirname(filePath));
|
||||
}
|
||||
|
||||
writeFileSync(filePath, contents) {
|
||||
return writeFileSync(filePath, contents);
|
||||
writeFileSync(filePath, contents, cycles) {
|
||||
return writeFileSync(filePath, contents, cycles);
|
||||
}
|
||||
|
||||
writeFile(filePath, contents) {
|
||||
writeFile(filePath, contents, cycles) {
|
||||
const that = this;
|
||||
return new BbPromise((resolve, reject) => {
|
||||
try {
|
||||
that.writeFileSync(filePath, contents);
|
||||
that.writeFileSync(filePath, contents, cycles);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ module.exports = {
|
||||
},
|
||||
};
|
||||
|
||||
this.serverless.utils.writeFileSync(serviceStateFilePath, state);
|
||||
this.serverless.utils.writeFileSync(serviceStateFilePath, state, true);
|
||||
|
||||
return BbPromise.resolve();
|
||||
},
|
||||
|
||||
@ -63,7 +63,7 @@ describe('#saveServiceState()', () => {
|
||||
};
|
||||
|
||||
expect(getServiceStateFileNameStub.calledOnce).to.equal(true);
|
||||
expect(writeFileSyncStub.calledWithExactly(filePath, expectedStateFileContent))
|
||||
expect(writeFileSyncStub.calledWithExactly(filePath, expectedStateFileContent, true))
|
||||
.to.equal(true);
|
||||
});
|
||||
});
|
||||
@ -97,7 +97,7 @@ describe('#saveServiceState()', () => {
|
||||
};
|
||||
|
||||
expect(getServiceStateFileNameStub.calledOnce).to.equal(true);
|
||||
expect(writeFileSyncStub.calledWithExactly(filePath, expectedStateFileContent))
|
||||
expect(writeFileSyncStub.calledWithExactly(filePath, expectedStateFileContent, true))
|
||||
.to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
@ -5,13 +5,17 @@ const path = require('path');
|
||||
const jc = require('json-cycle');
|
||||
const YAML = require('js-yaml');
|
||||
|
||||
function writeFile(filePath, conts) {
|
||||
function writeFile(filePath, conts, cycles) {
|
||||
let contents = conts || '';
|
||||
|
||||
return fse.mkdirsAsync(path.dirname(filePath))
|
||||
.then(() => {
|
||||
if (filePath.indexOf('.json') !== -1 && typeof contents !== 'string') {
|
||||
contents = jc.stringify(contents, null, 2);
|
||||
if (cycles) {
|
||||
contents = jc.stringify(contents, null, 2);
|
||||
} else {
|
||||
contents = JSON.stringify(contents, null, 2);
|
||||
}
|
||||
}
|
||||
|
||||
const yamlFileExists = (filePath.indexOf('.yaml') !== -1);
|
||||
|
||||
@ -49,7 +49,7 @@ describe('#writeFile()', function () {
|
||||
bar.foo = bar;
|
||||
const expected = '{\n "foo": {\n "$ref": "$"\n }\n}';
|
||||
|
||||
return writeFile(tmpFilePath, bar)
|
||||
return writeFile(tmpFilePath, bar, true)
|
||||
.then(() =>
|
||||
expect(fse.readFileAsync(tmpFilePath, 'utf8')).to.eventually.equal(expected)
|
||||
);
|
||||
|
||||
@ -5,13 +5,17 @@ const path = require('path');
|
||||
const jc = require('json-cycle');
|
||||
const YAML = require('js-yaml');
|
||||
|
||||
function writeFileSync(filePath, conts) {
|
||||
function writeFileSync(filePath, conts, cycles) {
|
||||
let contents = conts || '';
|
||||
|
||||
fse.mkdirsSync(path.dirname(filePath));
|
||||
|
||||
if (filePath.indexOf('.json') !== -1 && typeof contents !== 'string') {
|
||||
contents = jc.stringify(contents, null, 2);
|
||||
if (cycles) {
|
||||
contents = jc.stringify(contents, null, 2);
|
||||
} else {
|
||||
contents = JSON.stringify(contents, null, 2);
|
||||
}
|
||||
}
|
||||
|
||||
const yamlFileExists = (filePath.indexOf('.yaml') !== -1);
|
||||
|
||||
@ -53,7 +53,7 @@ describe('#writeFileSync()', () => {
|
||||
bar.foo = bar;
|
||||
const expected = '{\n "foo": {\n "$ref": "$"\n }\n}';
|
||||
|
||||
writeFileSync(tmpFilePath, bar);
|
||||
writeFileSync(tmpFilePath, bar, true);
|
||||
|
||||
return fse.readFileAsync(tmpFilePath, 'utf8').then((contents) => {
|
||||
expect(contents).to.equal(expected);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user