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: support analysing AMD module format #8389

Merged
merged 24 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d39db15
feat(amd): add amd runtime globals, dep category, and dep type
nilptr Oct 20, 2024
7eea7a8
feat(amd): add amd deps
nilptr Oct 20, 2024
797b1f7
feat(amd): add amd_define_dependency_parser_plugin and require_js_stu…
nilptr Oct 28, 2024
046f3cc
feat(amd): set AmdRequireItem dep factory
nilptr Oct 29, 2024
260a409
fix(amd): json_stringify named_module
nilptr Oct 29, 2024
5f3c1f5
chore: save tests
nilptr Oct 29, 2024
0fee5a3
fix(amd): flag local module used when it's actually used
nilptr Oct 31, 2024
823bf30
feat(amd): add amd_require_dependencies_block_parser_plugin
nilptr Nov 5, 2024
1105bf1
chore: save amd require tests
nilptr Nov 10, 2024
f93209d
chore: save amd require tests
nilptr Nov 10, 2024
e1c9916
feat(amd): add unsupported dependency
nilptr Nov 10, 2024
aee8f9c
feat(amd): add amd option
nilptr Nov 21, 2024
7de7fde
feat(amd): add amd runtime modules
nilptr Nov 21, 2024
c8c18b9
feat(amd): use amd plugins
nilptr Nov 21, 2024
49ed652
feat(amd): move amd test cases under config
nilptr Nov 23, 2024
b42223e
feat(amd): add AMDPlugin requirejs-related logic to RequireJsStuffPlugin
nilptr Nov 24, 2024
35db167
chore(amd): update test cases
nilptr Nov 24, 2024
6a3f350
feat(amd): add real amd libs as amd test cases
nilptr Nov 24, 2024
1505d7a
refactor(amd_define_dependency): use format macro named parameters to…
nilptr Nov 24, 2024
a434965
fix(amd ci): update jest snapshot
nilptr Nov 24, 2024
cc60625
chore: format code
nilptr Nov 24, 2024
109ce4c
chore: fix rust check issues
nilptr Nov 24, 2024
48f3f4c
chore: revert unexpected change
nilptr Nov 25, 2024
e769a2c
chore: fix spellchecker issues
nilptr Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,7 @@ export interface RawOptions {
experiments: RawExperiments
node?: RawNodeOption
profile: boolean
amd?: string
bail: boolean
__references: Record<string, any>
}
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_binding_options/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct RawOptions {
pub experiments: RawExperiments,
pub node: Option<RawNodeOption>,
pub profile: bool,
pub amd: Option<String>,
pub bail: bool,
#[napi(js_name = "__references", ts_type = "Record<string, any>")]
pub __references: References,
Expand Down Expand Up @@ -93,6 +94,7 @@ impl TryFrom<RawOptions> for CompilerOptions {
optimization,
node,
profile: value.profile,
amd: value.amd,
bail: value.bail,
__references: value.__references,
})
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_core/src/dependency/dependency_category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub enum DependencyCategory {
Unknown,
Esm,
CommonJS,
Amd,
Url,
CssImport,
CssCompose,
Expand Down Expand Up @@ -41,6 +42,7 @@ impl DependencyCategory {
DependencyCategory::Unknown => "unknown",
DependencyCategory::Esm => "esm",
DependencyCategory::CommonJS => "commonjs",
DependencyCategory::Amd => "amd",
DependencyCategory::Url => "url",
DependencyCategory::CssImport => "css-import",
DependencyCategory::CssCompose => "css-compose",
Expand Down
15 changes: 13 additions & 2 deletions crates/rspack_core/src/dependency/dependency_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub enum DependencyType {
Unknown,
ExportInfoApi,
Entry,
// ESM import
// Harmony import
ahabhgk marked this conversation as resolved.
Show resolved Hide resolved
EsmImport,
EsmImportSpecifier,
// ESM export
// Harmony export
ahabhgk marked this conversation as resolved.
Show resolved Hide resolved
EsmExport,
EsmExportImportedSpecifier,
EsmExportSpecifier,
Expand All @@ -33,6 +33,12 @@ pub enum DependencyType {
CjsExportRequire,
// cjs self reference
CjsSelfReference,
// AMD
AmdDefine,
AmdRequireArray,
AmdRequireContext,
AmdRequire,
AmdRequireItem,
// new URL("./foo", import.meta.url)
NewUrl,
// new Worker()
Expand Down Expand Up @@ -126,6 +132,11 @@ impl DependencyType {
DependencyType::CjsExports => "cjs exports",
DependencyType::CjsExportRequire => "cjs export require",
DependencyType::CjsSelfReference => "cjs self exports reference",
DependencyType::AmdDefine => "amd define",
DependencyType::AmdRequireArray => "amd require array",
DependencyType::AmdRequireContext => "amd require context",
DependencyType::AmdRequire => "amd",
DependencyType::AmdRequireItem => "amd require",
DependencyType::NewUrl => "new URL()",
DependencyType::NewWorker => "new Worker()",
DependencyType::CreateScriptUrl => "create script url",
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_core/src/options/compiler_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct CompilerOptions {
pub node: Option<NodeOption>,
pub optimization: Optimization,
pub profile: bool,
pub amd: Option<String>,
pub bail: bool,
pub __references: References,
}
Expand Down
6 changes: 6 additions & 0 deletions crates/rspack_core/src/runtime_globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ bitflags! {
const RSPACK_UNIQUE_ID = 1 << 65;

const HAS_FETCH_PRIORITY = 1 << 66;

// amd module support
const AMD_DEFINE = 1 << 67;
const AMD_OPTIONS = 1 << 68;
}
}

Expand Down Expand Up @@ -295,6 +299,8 @@ impl RuntimeGlobals {
R::GET_CHUNK_UPDATE_CSS_FILENAME => "__webpack_require__.hk",
R::HMR_MODULE_DATA => "__webpack_require__.hmrD",
R::HMR_RUNTIME_STATE_PREFIX => "__webpack_require__.hmrS",
R::AMD_DEFINE => "__webpack_require__.amdD",
R::AMD_OPTIONS => "__webpack_require__.amdO",
R::EXTERNAL_INSTALL_CHUNK => "__webpack_require__.C",
R::GET_FULL_HASH => "__webpack_require__.h",
R::GLOBAL => "__webpack_require__.g",
Expand Down
Loading
Loading