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: transform compiler architecture #4566

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/docs/src/routes/api/qwik-optimizer/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
}
],
"kind": "Interface",
"content": "```typescript\nexport interface HookEntryStrategy \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [type](#) | | 'hook' | |",
"content": "```typescript\nexport interface HookEntryStrategy \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [manual?](#) | | Record<string, string> | _(Optional)_ |\n| [type](#) | | 'hook' | |",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts",
"mdFile": "qwik.hookentrystrategy.md"
},
Expand Down Expand Up @@ -386,7 +386,7 @@
}
],
"kind": "Interface",
"content": "```typescript\nexport interface QwikManifest \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [bundles](#) | | { \\[fileName: string\\]: [QwikBundle](#qwikbundle)<!-- -->; } | |\n| [injections?](#) | | [GlobalInjections](#globalinjections)<!-- -->\\[\\] | _(Optional)_ |\n| [mapping](#) | | { \\[symbolName: string\\]: string; } | |\n| [options?](#) | | { target?: string; buildMode?: string; forceFullBuild?: boolean; entryStrategy?: { \\[key: string\\]: any; }; } | _(Optional)_ |\n| [platform?](#) | | { \\[name: string\\]: string; } | _(Optional)_ |\n| [symbols](#) | | { \\[symbolName: string\\]: [QwikSymbol](#qwiksymbol)<!-- -->; } | |\n| [version](#) | | string | |",
"content": "```typescript\nexport interface QwikManifest \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [bundles](#) | | { \\[fileName: string\\]: [QwikBundle](#qwikbundle)<!-- -->; } | |\n| [injections?](#) | | [GlobalInjections](#globalinjections)<!-- -->\\[\\] | _(Optional)_ |\n| [mapping](#) | | { \\[symbolName: string\\]: string; } | |\n| [options?](#) | | { target?: string; buildMode?: string; entryStrategy?: { \\[key: string\\]: any; }; } | _(Optional)_ |\n| [platform?](#) | | { \\[name: string\\]: string; } | _(Optional)_ |\n| [symbols](#) | | { \\[symbolName: string\\]: [QwikSymbol](#qwiksymbol)<!-- -->; } | |\n| [version](#) | | string | |",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts",
"mdFile": "qwik.qwikmanifest.md"
},
Expand Down Expand Up @@ -414,7 +414,7 @@
}
],
"kind": "Interface",
"content": "```typescript\nexport interface QwikRollupPluginOptions \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [buildMode?](#) | | [QwikBuildMode](#qwikbuildmode) | _(Optional)_ Build <code>production</code> or <code>development</code>. Default <code>development</code> |\n| [debug?](#) | | boolean | _(Optional)_ Prints verbose Qwik plugin debug logs. Default <code>false</code> |\n| [entryStrategy?](#) | | [EntryStrategy](#entrystrategy) | _(Optional)_ The Qwik entry strategy to use while building for production. During development the type is always <code>hook</code>. Default <code>{ type: &quot;smart&quot; }</code>) |\n| [forceFullBuild?](#) | | boolean | _(Optional)_ |\n| [manifestInput?](#) | | [QwikManifest](#qwikmanifest) | _(Optional)_ The SSR build requires the manifest generated during the client build. The <code>manifestInput</code> option can be used to manually provide a manifest. Default <code>undefined</code> |\n| [manifestOutput?](#) | | (manifest: [QwikManifest](#qwikmanifest)<!-- -->) =&gt; Promise&lt;void&gt; \\| void | _(Optional)_ The client build will create a manifest and this hook is called with the generated build data. Default <code>undefined</code> |\n| [optimizerOptions?](#) | | [OptimizerOptions](#optimizeroptions) | _(Optional)_ |\n| [rootDir?](#) | | string | _(Optional)_ The root of the application, which is commonly the same directory as <code>package.json</code> and <code>rollup.config.js</code>. Default <code>process.cwd()</code> |\n| [srcDir?](#) | | string | _(Optional)_ The source directory to find all the Qwik components. Since Qwik does not have a single input, the <code>srcDir</code> is used to recursively find Qwik files. Default <code>src</code> |\n| [srcInputs?](#) | | [TransformModuleInput](#transformmoduleinput)<!-- -->\\[\\] \\| null | _(Optional)_ Alternative to <code>srcDir</code>, where <code>srcInputs</code> is able to provide the files manually. This option is useful for an environment without a file system, such as a webworker. Default: <code>null</code> |\n| [target?](#) | | [QwikBuildTarget](#qwikbuildtarget) | _(Optional)_ Target <code>client</code> or <code>ssr</code>. Default <code>client</code> |\n| [transformedModuleOutput?](#) | | ((transformedModules: [TransformModule](#transformmodule)<!-- -->\\[\\]) =&gt; Promise&lt;void&gt; \\| void) \\| null | _(Optional)_ Hook that's called after the build and provides all of the transformed modules that were used before bundling. |",
"content": "```typescript\nexport interface QwikRollupPluginOptions \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [buildMode?](#) | | [QwikBuildMode](#qwikbuildmode) | _(Optional)_ Build <code>production</code> or <code>development</code>. Default <code>development</code> |\n| [debug?](#) | | boolean | _(Optional)_ Prints verbose Qwik plugin debug logs. Default <code>false</code> |\n| [entryStrategy?](#) | | [EntryStrategy](#entrystrategy) | _(Optional)_ The Qwik entry strategy to use while building for production. During development the type is always <code>hook</code>. Default <code>{ type: &quot;smart&quot; }</code>) |\n| [manifestInput?](#) | | [QwikManifest](#qwikmanifest) | _(Optional)_ The SSR build requires the manifest generated during the client build. The <code>manifestInput</code> option can be used to manually provide a manifest. Default <code>undefined</code> |\n| [manifestOutput?](#) | | (manifest: [QwikManifest](#qwikmanifest)<!-- -->) =&gt; Promise&lt;void&gt; \\| void | _(Optional)_ The client build will create a manifest and this hook is called with the generated build data. Default <code>undefined</code> |\n| [optimizerOptions?](#) | | [OptimizerOptions](#optimizeroptions) | _(Optional)_ |\n| [rootDir?](#) | | string | _(Optional)_ The root of the application, which is commonly the same directory as <code>package.json</code> and <code>rollup.config.js</code>. Default <code>process.cwd()</code> |\n| [srcDir?](#) | | string | _(Optional)_ The source directory to find all the Qwik components. Since Qwik does not have a single input, the <code>srcDir</code> is used to recursively find Qwik files. Default <code>src</code> |\n| [srcInputs?](#) | | [TransformModuleInput](#transformmoduleinput)<!-- -->\\[\\] \\| null | _(Optional)_ Alternative to <code>srcDir</code>, where <code>srcInputs</code> is able to provide the files manually. This option is useful for an environment without a file system, such as a webworker. Default: <code>null</code> |\n| [target?](#) | | [QwikBuildTarget](#qwikbuildtarget) | _(Optional)_ Target <code>client</code> or <code>ssr</code>. Default <code>client</code> |\n| [transformedModuleOutput?](#) | | ((transformedModules: [TransformModule](#transformmodule)<!-- -->\\[\\]) =&gt; Promise&lt;void&gt; \\| void) \\| null | _(Optional)_ Hook that's called after the build and provides all of the transformed modules that were used before bundling. |",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/rollup.ts",
"mdFile": "qwik.qwikrolluppluginoptions.md"
},
Expand Down
26 changes: 13 additions & 13 deletions packages/docs/src/routes/api/qwik-optimizer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ export interface HookAnalysis
export interface HookEntryStrategy
```

| Property | Modifiers | Type | Description |
| --------- | --------- | ------ | ----------- |
| [type](#) | | 'hook' | |
| Property | Modifiers | Type | Description |
| ------------ | --------- | ---------------------------- | ------------ |
| [manual?](#) | | Record&lt;string, string&gt; | _(Optional)_ |
| [type](#) | | 'hook' | |

[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts)

Expand Down Expand Up @@ -376,15 +377,15 @@ export interface QwikBundle
export interface QwikManifest
```

| Property | Modifiers | Type | Description |
| ---------------- | --------- | ----------------------------------------------------------------------------------------------------------- | ------------ |
| [bundles](#) | | { [fileName: string]: [QwikBundle](#qwikbundle); } | |
| [injections?](#) | | [GlobalInjections](#globalinjections)[] | _(Optional)_ |
| [mapping](#) | | { [symbolName: string]: string; } | |
| [options?](#) | | { target?: string; buildMode?: string; forceFullBuild?: boolean; entryStrategy?: { [key: string]: any; }; } | _(Optional)_ |
| [platform?](#) | | { [name: string]: string; } | _(Optional)_ |
| [symbols](#) | | { [symbolName: string]: [QwikSymbol](#qwiksymbol); } | |
| [version](#) | | string | |
| Property | Modifiers | Type | Description |
| ---------------- | --------- | --------------------------------------------------------------------------------- | ------------ |
| [bundles](#) | | { [fileName: string]: [QwikBundle](#qwikbundle); } | |
| [injections?](#) | | [GlobalInjections](#globalinjections)[] | _(Optional)_ |
| [mapping](#) | | { [symbolName: string]: string; } | |
| [options?](#) | | { target?: string; buildMode?: string; entryStrategy?: { [key: string]: any; }; } | _(Optional)_ |
| [platform?](#) | | { [name: string]: string; } | _(Optional)_ |
| [symbols](#) | | { [symbolName: string]: [QwikSymbol](#qwiksymbol); } | |
| [version](#) | | string | |

[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts)

Expand Down Expand Up @@ -417,7 +418,6 @@ export interface QwikRollupPluginOptions
| [buildMode?](#) | | [QwikBuildMode](#qwikbuildmode) | _(Optional)_ Build <code>production</code> or <code>development</code>. Default <code>development</code> |
| [debug?](#) | | boolean | _(Optional)_ Prints verbose Qwik plugin debug logs. Default <code>false</code> |
| [entryStrategy?](#) | | [EntryStrategy](#entrystrategy) | _(Optional)_ The Qwik entry strategy to use while building for production. During development the type is always <code>hook</code>. Default <code>{ type: &quot;smart&quot; }</code>) |
| [forceFullBuild?](#) | | boolean | _(Optional)_ |
| [manifestInput?](#) | | [QwikManifest](#qwikmanifest) | _(Optional)_ The SSR build requires the manifest generated during the client build. The <code>manifestInput</code> option can be used to manually provide a manifest. Default <code>undefined</code> |
| [manifestOutput?](#) | | (manifest: [QwikManifest](#qwikmanifest)) =&gt; Promise&lt;void&gt; \| void | _(Optional)_ The client build will create a manifest and this hook is called with the generated build data. Default <code>undefined</code> |
| [optimizerOptions?](#) | | [OptimizerOptions](#optimizeroptions) | _(Optional)_ |
Expand Down
22 changes: 18 additions & 4 deletions packages/qwik/src/optimizer/core/src/entry_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,31 @@ impl EntryPolicy for SingleStrategy {
}
}

#[derive(Default, Clone)]
pub struct PerHookStrategy {}
#[derive(Clone)]
pub struct PerHookStrategy {
map: Option<HashMap<String, JsWord>>,
}

impl PerHookStrategy {
pub const fn new(map: Option<HashMap<String, JsWord>>) -> Self {
Self { map }
}
}

impl EntryPolicy for PerHookStrategy {
fn get_entry_for_sym(
&self,
_hash: &str,
hash: &str,
_path: &PathData,
_context: &[String],
_hook_data: &HookData,
) -> Option<JsWord> {
if let Some(map) = &self.map {
let entry = map.get(hash);
if let Some(entry) = entry {
return Some(entry.clone());
}
}
None
}
}
Expand Down Expand Up @@ -169,8 +183,8 @@ pub fn parse_entry_strategy(
manual_chunks: Option<HashMap<String, JsWord>>,
) -> Box<dyn EntryPolicy> {
match strategy {
EntryStrategy::Hook => Box::new(PerHookStrategy::default()),
EntryStrategy::Inline | EntryStrategy::Hoist => Box::new(InlineStrategy::default()),
EntryStrategy::Hook => Box::new(PerHookStrategy::new(manual_chunks)),
EntryStrategy::Single => Box::new(SingleStrategy::new(manual_chunks)),
EntryStrategy::Component => Box::new(PerComponentStrategy::new(manual_chunks)),
EntryStrategy::Smart => Box::new(SmartStrategy::new(manual_chunks)),
Expand Down
46 changes: 34 additions & 12 deletions packages/qwik/src/optimizer/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,23 @@ pub fn transform_fs(config: TransformFsOptions) -> Result<TransformOutput, Error
.reduce(|| Ok(TransformOutput::new()), |x, y| Ok(x?.append(&mut y?)))?;

final_output.modules.sort_unstable_by_key(|key| key.order);
final_output = generate_entries(
final_output,
&core_module,
config.explicit_extensions,
root_dir,
)?;
if !matches!(
config.entry_strategy,
EntryStrategy::Hook | EntryStrategy::Inline | EntryStrategy::Hoist
) {
final_output = generate_entries(
final_output,
&core_module,
config.explicit_extensions,
root_dir,
)?;
}
// final_output = generate_entries(
// final_output,
// &core_module,
// config.explicit_extensions,
// root_dir,
// )?;
Ok(final_output)
}

Expand Down Expand Up @@ -216,12 +227,23 @@ pub fn transform_modules(config: TransformModulesOptions) -> Result<TransformOut

let mut final_output = final_output?;
final_output.modules.sort_unstable_by_key(|key| key.order);
final_output = generate_entries(
final_output,
&core_module,
config.explicit_extensions,
root_dir,
)?;
if !matches!(
config.entry_strategy,
EntryStrategy::Hook | EntryStrategy::Inline | EntryStrategy::Hoist
) {
final_output = generate_entries(
final_output,
&core_module,
config.explicit_extensions,
root_dir,
)?;
}
// final_output = generate_entries(
// final_output,
// &core_module,
// config.explicit_extensions,
// root_dir,
// )?;

Ok(final_output)
}
5 changes: 2 additions & 3 deletions packages/qwik/src/optimizer/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export interface HookAnalysis {

// @public (undocumented)
export interface HookEntryStrategy {
// (undocumented)
manual?: Record<string, string>;
// (undocumented)
type: 'hook';
}
Expand Down Expand Up @@ -209,7 +211,6 @@ export interface QwikManifest {
options?: {
target?: string;
buildMode?: string;
forceFullBuild?: boolean;
entryStrategy?: {
[key: string]: any;
};
Expand All @@ -234,8 +235,6 @@ export interface QwikRollupPluginOptions {
buildMode?: QwikBuildMode;
debug?: boolean;
entryStrategy?: EntryStrategy;
// (undocumented)
forceFullBuild?: boolean;
manifestInput?: QwikManifest;
manifestOutput?: (manifest: QwikManifest) => Promise<void> | void;
// (undocumented)
Expand Down
1 change: 0 additions & 1 deletion packages/qwik/src/optimizer/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ export function generateManifestFromBundles(
options: {
target: opts.target,
buildMode: opts.buildMode,
forceFullBuild: opts.forceFullBuild,
entryStrategy: opts.entryStrategy,
},
};
Expand Down