Skip to content

feat(swc/core): introduce swc_core package#5364

Merged
kdy1 merged 12 commits intoswc-project:mainfrom
kwonoj:feat-swc-core
Aug 2, 2022
Merged

feat(swc/core): introduce swc_core package#5364
kdy1 merged 12 commits intoswc-project:mainfrom
kwonoj:feat-swc-core

Conversation

@kwonoj
Copy link
Member

@kwonoj kwonoj commented Aug 2, 2022

Description:

First step implementation for #5244.

PR introduces new package swc_core, then move swc_plugin's feature under the swc_core as first step. This is a breaking change to any plugins that we'll need to update references accordingly.

The idea of swc_core is simple, that mostly reexport all the features, without having its own code as much as it can.
I'd like to setup these principles for those, while it may / should change depends on how we'll going to make it work actually.

  • single package to import : plugin author, or custom binary author should not need to import any swc_* dependencies other than swc_core. (We do not care about any other 3rd party deps though, like serde, etcs)
  • no default features: There are too many conflicting features to be exposed (i.e plugin vs. host runtime) and it's not easy to bring common set of default features with its transitive deps. We'll start off from no default until we see valid usecase.
  • Complete opt-in: all deps are trying to be optional as much, and correct feature opt in should enable those.
  • Compile time validatable feature dependencies: if A needs A' or A'', better to validate in build time.
  • Flattened dep tree: this is probably moon shot, but hoping to reduce circular references / complex transitive deps and making it flatten as much to optimize build.
  • Transparent forward: instead of trying to re-categorize, attempt to reexport transparently. For example: swc_common::* -> swc_core::common::*.

This is probably not the complete swc_plugin support, may need to check with existing plugins to find out missing exports. Still it is a first step.

BREAKING CHANGE:

Related issue (if exists):

#5244

@kwonoj kwonoj added the A-build label Aug 2, 2022
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Thanks!

#![cfg_attr(docsrs, feature(doc_cfg))]

// Quote
#[cfg(feature = "quote")]
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 we need #[cfg(any(docsrs, feature = "quote")] along with #[cfg_attr(docsrs, doc(cfg(feature = "quote")))]

}

// Plugins
#[cfg(feature = "__plugin_transform")]
Copy link
Member

Choose a reason for hiding this comment

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

Same here

// ast exposed via swc_ecma_ast
// TODO: Can dependency tree simplified
// by swc_ecma_ast reexports swc_atoms?
#[cfg(any(feature = "__ast"))]
Copy link
Member

Choose a reason for hiding this comment

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

Same here

}

// visit* interfaces
#[cfg(any(feature = "__visit"))]
Copy link
Member

Choose a reason for hiding this comment

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

Same here

}

// swc_common features
#[cfg(any(feature = "__common"))]
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@@ -0,0 +1,36 @@
// #[plugin_transform] macro
#[cfg(feature = "__plugin_transform")]
pub use swc_plugin_macro::plugin_transform;
Copy link
Member

Choose a reason for hiding this comment

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

Same here


/// Global HANDLER implementation for the plugin
/// for error reporting.
#[cfg(feature = "__plugin_transform")]
Copy link
Member

Choose a reason for hiding this comment

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

Same here

}

/// Plugin's environment metadata context.
#[cfg(feature = "__plugin_transform")]
Copy link
Member

Choose a reason for hiding this comment

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

Same here

}

/// Proxy to the host's data not attached to the AST, like sourcemap / comments.
#[cfg(feature = "__plugin_transform")]
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@kwonoj kwonoj force-pushed the feat-swc-core branch 2 times, most recently from a3258ee to 9cb23f0 Compare August 2, 2022 05:39
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Thanks!


swc-bump:

  • swc_plugin_macro --breaking

@kdy1 kdy1 enabled auto-merge (squash) August 2, 2022 06:49
@kdy1 kdy1 added this to the Planned milestone Aug 2, 2022
@kdy1 kdy1 merged commit 27b464d into swc-project:main Aug 2, 2022
Austaras pushed a commit to Austaras/swc that referenced this pull request Aug 2, 2022
@kwonoj kwonoj deleted the feat-swc-core branch August 2, 2022 17:38
@kdy1 kdy1 modified the milestones: Planned, v1.2.223 Aug 3, 2022
@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments