Skip to content

Commit

Permalink
Fixed issue where ManifestPlugin produced manifest.json file without …
Browse files Browse the repository at this point in the history
…client assets
  • Loading branch information
jsimck committed Mar 6, 2023
1 parent b4e7bad commit ad1c47f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-avocados-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ima/cli": patch
---

Fixed issue where ManifestPlugin produced manifest.json file without client assets. This could resolve in error where application loads without and JS and CSS assets and is not revived.
22 changes: 16 additions & 6 deletions packages/cli/src/webpack/plugins/ManifestPlugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ class ManifestPlugin {
#pluginName: string;
#options: ManifestPluginOptions;

static #instances = 0;
static #generated = 0;
static #generated: {
[key in ImaConfigurationContext['name']]?: boolean;
} = {};

constructor(options: ManifestPluginOptions) {
this.#pluginName = this.constructor.name;
this.#options = options;
ManifestPlugin.#instances++;

// Track generated configurations status
ManifestPlugin.#generated[options.context.name] = false;

// Validate options
validate(schema as Schema, this.#options, {
Expand All @@ -76,7 +79,6 @@ class ManifestPlugin {
* Generate runner code from compiled assets.
*/
generate(assets: Compilation['assets'], compilation: Compilation): void {
ManifestPlugin.#generated++;
const compilationName = compilation?.name as
| ImaConfigurationContext['name']
| undefined;
Expand Down Expand Up @@ -115,8 +117,16 @@ class ManifestPlugin {
seed.assets[name] = assetWithInfo;
});

if (ManifestPlugin.#generated === ManifestPlugin.#instances) {
ManifestPlugin.#generated = 0;
// Mark this configuration as generated
ManifestPlugin.#generated[compilationName] = true;

if (Object.values(ManifestPlugin.#generated).every(v => v)) {
// Reset tracking info
Object.keys(ManifestPlugin.#generated).forEach(
key =>
(ManifestPlugin.#generated[key as ImaConfigurationContext['name']] =
false)
);

// Emit compiled ima runner with embedded runtime codes
return compilation.emitAsset(
Expand Down

0 comments on commit ad1c47f

Please sign in to comment.