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: rolldown cli first implementation #610

Merged
merged 19 commits into from Mar 21, 2024

Conversation

kazupon
Copy link
Sponsor Contributor

@kazupon kazupon commented Mar 19, 2024

Description

related #599

This PR is support rolldown cli.
The first rolldown cli supports the --config option.
The following is usage:

rolldown --config rolldown.config.js

Test Plan


Copy link

netlify bot commented Mar 19, 2024

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 7d8fa5b
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/65fbd53ae1bd0f000855e398

yarn.lock Outdated
Copy link
Member

Choose a reason for hiding this comment

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

We have switched to pnpm from yarn

@kazupon kazupon force-pushed the feat/cli-first-implemetation branch from 6e2a9ed to b417cda Compare March 19, 2024 05:47
@milesj
Copy link
Contributor

milesj commented Mar 19, 2024

This should also be written in TypeScript.

@hyf0
Copy link
Member

hyf0 commented Mar 19, 2024

This should also be written in TypeScript.

This is expected. We plan to move this to rolldown package instead of a new standalone package. Thus, we decide to use js + jsdoc to get type safety and get rid of build steps for cli. This way we won't be needed to modify the build steps.

@hyf0 hyf0 linked an issue Mar 19, 2024 that may be closed by this pull request
@hyf0
Copy link
Member

hyf0 commented Mar 19, 2024

Support config formats are .js, .mjs, and .ts (support esm only).

@kazupon You could delay the support for .ts files. It's kind of tricky and have some traps. let's have a fully research before we doing it.


/**
* NOTE:
* currenctly, It's hard to customize usage with citty `renderUsage`.
Copy link

Choose a reason for hiding this comment

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

Please let me know or feel free to open an issue for what you like to be customizable or better rendered in citty usage renderer 👍🏼 :)

packages/cli/package.json Outdated Show resolved Hide resolved
packages/cli/bin/cli.js Outdated Show resolved Hide resolved
packages/cli/lib/main.js Outdated Show resolved Hide resolved
packages/cli/test/config.test.js Outdated Show resolved Hide resolved
import { getPackageJSON } from './utils.js'

const __dirname = path.dirname(new URL(import.meta.url).pathname)
const { version, description } = getPackageJSON(path.resolve(__dirname, '..'))
Copy link
Member

@hyf0 hyf0 Mar 19, 2024

Choose a reason for hiding this comment

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

You should be able to import .json file directly while using node.

Just write import { version, description } from '../package.json' and it should works.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

I am implementing cli based on es module. So the rolldown package must have "type": "module".

And in that case, node throw the following error when importing json:

TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "file:///path/to/rolldown/packages/rolldown/package.json" needs an import attribute of type "json

We must use import assertion as follow:

import pkgJson from '../package.json' assert { type: 'json' }

@kazupon
Copy link
Sponsor Contributor Author

kazupon commented Mar 19, 2024

@kazupon You could delay the support for .ts files. It's kind of tricky and have some traps. let's have a fully research before we doing it.

I use jiti for TS config loading.
https://github.com/unjs/jiti
jiti can also resolve typescript. In fact, it is also used as a config loader for c12 in unjs.
https://github.com/unjs/c12

another show case, jiti also used in tailwind config loading.
https://github.com/tailwindlabs/tailwindcss/blob/3.4/src/lib/load-config.ts

So I understand that I may use it to resolve TS configs.

@pi0
If you have any comments to add, please feel free to comment. :)

@hyf0 hyf0 marked this pull request as ready for review March 20, 2024 04:59
@hyf0 hyf0 force-pushed the feat/cli-first-implemetation branch 2 times, most recently from 3364c78 to cf844b1 Compare March 20, 2024 05:04
@hyf0
Copy link
Member

hyf0 commented Mar 20, 2024

Something wrong with the filename conventions.

You could add **/*.config.{js,mjs,cjs,ts,cts,mts} to .ls-lint.yml.

@kazupon
Copy link
Sponsor Contributor Author

kazupon commented Mar 20, 2024

Hmm, 🤔 I've done basic implementation of build with config, and rolldown write seems to work, but the file is not generated. In my environment...

examples/basic-vue is building, but I don't know what's causing it...

You can try that:

CONSOLA_LEVEL=4 node ./bin/cli.js -c test/fixtures/basic/rolldown.config.js

@hyf0 hyf0 self-assigned this Mar 20, 2024
@hyf0
Copy link
Member

hyf0 commented Mar 20, 2024

I think this PR is good to go. Thank your wonderful work! @kazupon

Let me takes this PR from here. With some thoughts come to my head, I will do some refactor.

  • We want to rolldown to have almost zero dependencies.
    • If we apply this rule on CLI, it means either we implement the CLI from the ground or we introduce build steps to bundle these dependencies. I prefer the bundle solution, because it's simple to do.
  • Since build steps can't be avoided, using ts to implement CLI is fine now.(Sorry to @kazupon
  • I'm gonna remove support for .ts. As I said before, supporting .ts config file could introduce a lot of issues, such as vite.config.ts can't import untranspiled ts files from other packages in the same monorepo vitejs/vite#5370. Let's have a fully research on this to get the best solution for using .ts config file. In the meanwhile the command some-ts-transpiler ./rolldown.config.ts --out ./rolldown.config.js && rolldown --config ./rolldown.config.js could be a workaround.

@hyf0 hyf0 force-pushed the feat/cli-first-implemetation branch from cd337d1 to ab832b2 Compare March 20, 2024 18:27
@pi0
Copy link

pi0 commented Mar 20, 2024

@hyf0 Regarding the .ts extension, I totally respect your judgment if you prefer to delay or not support .ts extension. But I guess it won't have edge cases like vitejs/vite#5370. jiti even allows mixed syntaxes and is heavily tested over years -- we might even replace it's transpile step with rolldown natives! (probably the only limitation is top-level await support that will be added in the future versions of it)

@hyf0
Copy link
Member

hyf0 commented Mar 20, 2024

@hyf0 Regarding the .ts extension, I totally respect your judgment if you prefer to delay or not support .ts extension. But I guess it won't have edge cases like vitejs/vite#5370. jiti even allows mixed syntaxes and is heavily tested over years -- we might even replace it's transpile step with rolldown natives! (probably the only limitation is top-level await support that will be added in the future versions of it)

Glod to know that. Will look into jiti for sure.

@kazupon
Copy link
Sponsor Contributor Author

kazupon commented Mar 21, 2024

@hyf0

Let me takes this PR from here. With some thoughts come to my head, I will do some refactor.

okay! 👌
If you need any help with the CLI, let me know. I am always happy to help rolldown. :)

@kazupon
Copy link
Sponsor Contributor Author

kazupon commented Mar 21, 2024

We want to rolldown to have almost zero dependencies.

  • If we apply this rule on CLI, it means either we implement the CLI from the ground or we introduce build steps to bundle these dependencies. I prefer the bundle solution, because it's simple to do.

if you will use cli library, you can bundle with unbuild.
In the current version of unbuild, deps under node_modules cannot be bundled without a little hook adjustment.
Fortunately, @pi0 is also the author of unbuild. He may be able to provide some support. :)

Copy link
Member

@hyf0 hyf0 left a comment

Choose a reason for hiding this comment

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

Again. Thank @kazupon for his great work.

@hyf0 hyf0 force-pushed the feat/cli-first-implemetation branch from bcb24ac to 7d8fa5b Compare March 21, 2024 06:35
@hyf0 hyf0 merged commit c82e59d into rolldown:main Mar 21, 2024
15 checks passed
@kazupon kazupon deleted the feat/cli-first-implemetation branch March 21, 2024 07:05
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.

Implement CLI in rolldown
4 participants