Skip to content
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

fix(deploy): move saving the build config to deploy plugins #888

Conversation

rmarscher
Copy link
Contributor

This (along with the previous #874) resolves the issue in #871. The build config was being written to the wrong location for cloudflare pages This PR exports a function from the build module that appends the build config to the given entries file location. It uses a new unstable build config state variable (unstable_buildConfigSave) to track whether or not the build config has be saved to the entries file. This allows the cloudflare deploy plugin to write the build config into the worker function directory instead of the root.

We could merge #879 and then I can edit the base branch to main and continue with this PR. Or however you want to handle it. Thank you!

Copy link

vercel bot commented Sep 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Sep 18, 2024 1:21pm

Copy link

codesandbox-ci bot commented Sep 17, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@@ -64,6 +64,7 @@ import { deployCloudflarePlugin } from '../plugins/vite-plugin-deploy-cloudflare
import { deployDenoPlugin } from '../plugins/vite-plugin-deploy-deno.js';
import { deployPartykitPlugin } from '../plugins/vite-plugin-deploy-partykit.js';
import { deployAwsLambdaPlugin } from '../plugins/vite-plugin-deploy-aws-lambda.js';
import { appendFileSync } from 'node:fs';
Copy link
Contributor Author

@rmarscher rmarscher Sep 17, 2024

Choose a reason for hiding this comment

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

The other vite deploy fs operations are sync which is why this is not using a promise.

@dai-shi
Copy link
Owner

dai-shi commented Sep 17, 2024

The build config was being written to the wrong location for cloudflare pages

Yeah, I was also curious about it. Good that you confirm.

Comment on lines 212 to 215
unstable_writeBuildConfig(
path.join(outDir, WORKER_JS_NAME, DIST_ENTRIES_JS),
);
Copy link
Owner

Choose a reason for hiding this comment

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

I don't like the complexity and exposing the function from build.ts (which doesn't work if you own the plugin outside waku repo.)

Let's simply do this here:

Suggested change
unstable_writeBuildConfig(
path.join(outDir, WORKER_JS_NAME, DIST_ENTRIES_JS),
);
appendFileSync(
path.join(outDir, WORKER_JS_NAME, DIST_ENTRIES_JS),
`export const buildData = ${JSON.stringify(platformObject.buildData)};`,
);

We will revisit the build process in the future anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. A library of helper functions for deploy authors to use would be nice. The "isNodeCompatible" replacement is another candidate for a helper function:

      config.ssr.target = 'webworker';
      config.ssr.resolve ||= {};
      config.ssr.resolve.conditions ||= [];
      config.ssr.resolve.conditions.push('worker');
      config.ssr.resolve.externalConditions ||= [];
      config.ssr.resolve.externalConditions.push('worker');

@rmarscher
Copy link
Contributor Author

@dai-shi I attempted to move the updating of entries.js with build data to each deploy plugin. I tested with cloudflare and it works great. Implementation in the other deploy plugins needs testing.

@rmarscher rmarscher changed the title fix(deploy): option for deploy plugins to save the build config fix(deploy): move saving the build config to deploy plugins Sep 17, 2024
@rmarscher rmarscher force-pushed the fix/deploy-plugin-save-build-config branch from 03f4f4f to b2c4836 Compare September 17, 2024 19:56
Comment on lines 777 to 782
delete platformObject.buildOptions.unstable_phase;

await appendFile(
distEntriesFile,
`export const buildData = ${JSON.stringify(platformObject.buildData)};`,
);
Copy link
Owner

Choose a reason for hiding this comment

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

Please keep this because this is required even without deploy plugins.
Only change cloudflare deploy plugin. I don't know the future, but my understanding is only cloudflare has special requirement for the dist folder structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK... this means the entries.js will be exposed publicly on Cloudflare deployments at /entries.js unless users know to delete it from their dist folder before deploying.

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 can add a note about it in the guide.

Copy link
Owner

Choose a reason for hiding this comment

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

Wouldn't it be the same previously?
I'm fine to add a check:

if (existsSync(distEntriesFile)) {
  await appendFile(
    distEntriesFile,
    `export const buildData = ${JSON.stringify(platformObject.buildData)};`,
  );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah... good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dai-shi OK great. I amended this PR.

@rmarscher rmarscher force-pushed the fix/deploy-plugin-save-build-config branch from 8301362 to b34ce5c Compare September 18, 2024 13:20
@dai-shi dai-shi merged commit 77f32bb into dai-shi:refactor/deploy/cloudflare Sep 18, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants