Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

use async // await in build #382

Merged
merged 2 commits into from
Dec 21, 2018
Merged

use async // await in build #382

merged 2 commits into from
Dec 21, 2018

Conversation

xavdid
Copy link
Contributor

@xavdid xavdid commented Dec 20, 2018

I originally started this as an improvement to source.zip generation (namely, always excluding node_modules) but got distracted and inspired by your PR yesterday that I wanted to do the same. I'll get to that another day.

No functionality should have changed - this is purely a rewrite using async and await.

@xavdid xavdid requested a review from eliangcs December 20, 2018 01:01
Copy link
Member

@eliangcs eliangcs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for refactoring! I tested locally and found some bugs. See my comments below.

'node_modules',
constants.PLATFORM_PACKAGE
);
if (!await fs.exists(corePath)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!await fs.exists(corePath)) {
if (!fs.existsSync(corePath)) {

We need to use fs.existsSync here because fs.exists is a callback-style function (rather than promise-style) and deprecated.

return {}; // TODO err, what should we do on windows?
const fileWriteError = await writeFile(
`${tmpDir}/definition.json`,
prettyJSONstringify(rawDefinition.results)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant to write

Suggested change
prettyJSONstringify(rawDefinition.results)
prettyJSONstringify(rawDefinition)

because .results has been done previously.

'zapier-' + crypto.randomBytes(4).toString('hex')
);

const maybeNotifyAboutOutdated = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for making it a function!

wdir = wdir || process.cwd();
zipPath = zipPath || constants.BUILD_PATH;
sourceZipPath = sourceZipPath || constants.SOURCE_PATH;
const osTmpDir = await fse.realpath(os.tmpdir());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const osTmpDir = await fse.realpath(os.tmpdir());
const osTmpDir = fse.realpathSync(os.tmpdir());

This needs to be sync version as fs.realpath is a callback-style function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one's ok, since it's using fs-extra, which makes everything into promises.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 TIL!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! If we had been using fs, you'd be correct, but the whole point of fs-extra is that all the async methods are promise-baed.

@xavdid
Copy link
Contributor Author

xavdid commented Dec 20, 2018

I think we're good on the fse front. Updated the rest in a41baab.

@xavdid xavdid merged commit be8b7d8 into master Dec 21, 2018
@xavdid xavdid deleted the build-update branch December 21, 2018 19:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants