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

feat: write generate resource and some utils #2081

Open
wants to merge 11 commits into
base: v2-dev
Choose a base branch
from

Conversation

ErKeLost
Copy link
Member

@ErKeLost ErKeLost commented Feb 8, 2025

#1793

  1. add output file print log
    image

  2. add writeBundle

  3. prepare out dir logic move to rust side

    • create out_dir dir
    • copy public dir
    • filter resource.emitter === true
  4. add rust side logger

  5. add some toolkit utils

Copy link

changeset-bot bot commented Feb 8, 2025

⚠️ No Changeset found

Latest commit: ca51a28

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

💥 An error occurred when fetching the changed packages and changesets in this PR
Some errors occurred when validating the changesets config:
The package or glob expression "farm-docs" is specified in the `ignore` option but it is not found in the project. You may have misspelled the package name or provided an invalid glob expression. Note that glob expressions must be defined according to https://www.npmjs.com/package/micromatch.

@ErKeLost ErKeLost marked this pull request as draft February 8, 2025 08:15
@ErKeLost ErKeLost added the WIP Working in progress label Feb 8, 2025
@ErKeLost ErKeLost changed the title chore: write generate resource moves into rust side feat: write generate resource and some utils Feb 15, 2025
@ErKeLost ErKeLost marked this pull request as ready for review February 16, 2025 09:58
);
}

self.copy_dir(public_dir_path, output_dir_path);
Copy link
Member

Choose a reason for hiding this comment

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

wdyt to add a plugin driver hook to notify plugins about public resource copy? or just leave the plugins to resolve completed files itself?somtimes some elder projects may need users add some files to public dir so we cannot optimize these files for now

Copy link
Member Author

Choose a reason for hiding this comment

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

Copying publicDir should be our internal behavior of the framework. If the user needs to perform other special operations, they can do so in the finish hook or the upcoming writeBundle hook.

Copy link
Member Author

Choose a reason for hiding this comment

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

After the entire write is completed, we can provide users with a writeBundle hook to manipulate the output file or other files.

@@ -8,7 +8,7 @@
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"bootstrap": "node scripts/bootstrap.mjs",
"bootstrap": "node scripts/bootstrap.mjs -v",
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 maybe it's better to use pnpm bootstrap -v instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason why I suggest using verbose is that in some special cases, such as the first run of farm, Rust build can be extremely slow. Many developers cannot see the real Rust compilation progress and come to ask me if it is stuck. This is also why I use inherit to prompt developers.

Copy link
Member Author

Choose a reason for hiding this comment

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

can add another command, but I still feel that verbose is the user's first intuition.

@ErKeLost
Copy link
Member Author

image

Outputting the output file size in the Rust hook causes the program to wait for all threads to finish executing before proceeding, even though multiple threads have been started. This leads to longer overall compilation times. In JavaScript, we could make this run asynchronously, but I wonder if there are any better solutions; otherwise, we'll have to implement it in JavaScript after all.

Wait for all threads to finish execution here.

    const startTime = performance.now();
    await compiler.compile();
    const elapsedTime = Math.floor(performance.now() - startTime);
    const persistentCacheText = persistentCache
      ? bold(PersistentCacheBrand)
      : '';

@@ -165,6 +165,17 @@ export async function resolveConfig(
sortFarmJsPlugins
);

if (config.compilation.mode === 'production' && !config.watch) {
Copy link
Member

Choose a reason for hiding this comment

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

add a config option like output.fileSize and move this if statement to rust compiler similar to minify or tree shake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Working in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants