-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow users to bundle node_modules #580
Allow users to bundle node_modules #580
Conversation
src/push/plugin.ts
Outdated
// Spin off another build to copy over the imported modules without bundling | ||
const result = await esbuild.build({ | ||
...commonOptions(), | ||
entryPoints: { | ||
[entryPath]: entryPath, | ||
}, | ||
bundle: false, | ||
bundle: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would change our journey files format IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's interesting, do you mean the file format itself (the extension)? Or do you mean the content format (i.e. bundling the CommonJS infra)?
In my tests, I added an fs.writeFile
to the code so I could save the generated zips to my disk. Then, once I opened them, I did manage to see that the file extension was .js
and that the content was also valid JavaScript.
I also checked the docs here: https://esbuild.github.io/api/#bundle and couldn't see a reference for format changes.
Can you go into a bit more detail about your concern here? Perhaps I'm missing something or misunderstood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the content of the journey itself. Lets say when you push a journey file file.journey.ts
, What does the content look like? Did it get changed to something else and whether the files were bundled - concatenated in to a single file for the files(utils, helpers) that were imported by the journey?
a9136ce
to
e0f58e5
Compare
CC @vigneshshanmugam feel free to merge this whenever you're happy with it, all tests are now passing 😄 |
74285f7
to
d7e01b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this solution works, this defeats the purpose of our Plugin and kind of bundles everything together in a single file.
The goal of our push command is to replicate exactly how your folder structure is on your local and run the same inside HB when pushed. This would make it presentable in Kibana when we add unzipping support and allow users to view and edit monitors.
TLDR: If i push the advanced.journey.ts
to Kibana, the structure should like
// Main branch
/example/todos/advanced.journey.ts
/example/todos/helper.ts
// PR branch
/example/todos/advanced.journey.ts
@vigneshshanmugam can you double check whether you had the last version during your test? That behaviour you mentioned was happening before the changes I did yesterday morning. Right now, I just tried to push a journey which depends on another local file and it did separate the necessary files. To test that, I added the following line to async build(entry: string, output: string) {
await this.prepare(entry);
await this.zip(output);
const data = await this.encode(output);
await writeFile('/tmp/new-synth.zip', data, { encoding: 'base64' });
await this.cleanup(output);
return data;
} Then I extracted the Is this what you meant? Or did I misunderstand? |
As discussed in Tech Sync, we should ensure this feature includes a check and handling the failure of the compressed bundle being too big for either the Saved Object, or configmap to support, and feed this back to the user (e.g. ...failed to create the monitor as the bundle size is bigger than the maximum 800KB...) |
@vigneshshanmugam I was looking into not bundling the Considering that Kibana only shows the code inside the step, as shown in the screenshot below, what do you think of us merging this one as is? |
6ad61de
to
c3fb030
Compare
Hi guys. We're currently waiting on this change, is there any timeframe for its release? |
Hey @StuGray86, we're trying to expedite it at the moment, so we're working actively on it. I can't promise exact dates, but we'll do our best for it to be speedy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
Post FF Testing I was able to import a simple library like Script I used: import { journey, step, monitor } from '@elastic/synthetics';
import { v4 as uuidv4 } from 'uuid';
journey('Journey uuid Test', ({ page, params }) => {
monitor.use({
id: 'uuid-lib-test-001',
enabled: true,
schedule: 20,
});
step('Generate UUID', async () => {
const uuid = uuidv4();
await page.goto('https://onlinetexttools.com/convert-text-to-image');
const textAreaLocator = page.locator('textarea').first();
await textAreaLocator.fill(uuid);
await textAreaLocator.type(' ');
});
}); However, I did find an issue with bundling certain imports and raised a bug. |
Summary
This PR allows users to bundle modules into the scripts they push.
I've marked it as draft as it still needs E2E tests.
How to test this PR
To test this PR, try including a JS library into your journey, by importing it into the journey file.
Then push your journey with the extra imported module to Kibana.
You should be able to run the Journey just fine.