postman-local icon indicating copy to clipboard operation
postman-local copied to clipboard

Enable 2-way sync

Open kevinswiber opened this issue 3 years ago • 1 comments

It would be nice if we could make changes in the Postman app and have them sync with the postman-cli'd bootstrapped version. Right now, I think improvements introduced by a solution to #12 could help facilitate that. Three-way merge on conflict is a related big deal, so I'll defer.

Otherwise, we can potentially detect if the Postman-hosted script has been browserify'd and extract the source using a JavaScript parser.

A quick and dirty test seems to show it could work:

const fs = require('fs');
const acorn = require('acorn');

const source = fs.readFileSync('./subject.js').toString('utf8');
const result = acorn.parse(source, { ecmaVersion: 2020 });
const bundledSources = result.body[0].expression.arguments[0].properties;
const scriptSource = bundledSources[bundledSources.length - 1];
const bodyElements = scriptSource.value.elements[0].body.body;

const start = bodyElements[0].start;
const end = bodyElements[bodyElements.length - 1].end;

const body = source.substring(start, end);
console.log(body);

Just not sure if we'd want it to work. 😅

Ian Malcolm

kevinswiber avatar Sep 04 '20 21:09 kevinswiber

I agree with your last point - I am conflicted on this. What I would love is to be able to somehow abstract everything browserify does, but I am not sure how.

To me this also plays into trying to remove sync altogether - having some kind of autosync on save or something like hot reloading for Postman.

matt-ball avatar Sep 07 '20 14:09 matt-ball