Skip to content

Commit

Permalink
Merge pull request #597 from seznam/link-bugs
Browse files Browse the repository at this point in the history
fix: ima dev and ima-plugin link command not updating in edge cases
  • Loading branch information
Filipoliko authored Dec 19, 2024
2 parents 30d506e + 3c4348d commit cc551d6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-owls-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ima/plugin-cli": patch
---

Fix link not working on linux environments in some edge cases
5 changes: 5 additions & 0 deletions .changeset/lemon-months-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ima/cli": patch
---

Fix `ima dev` watch re-build being one version behind the real changes in some random circumstances.
27 changes: 20 additions & 7 deletions packages/cli/src/webpack/plugins/ManifestPlugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class ManifestPlugin {
#options: ManifestPluginOptions;

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

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

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

// Validate options
validate(schema as Schema, this.#options, {
Expand Down Expand Up @@ -118,14 +118,27 @@ class ManifestPlugin {
});

// Mark this configuration as generated
ManifestPlugin.#generated[compilationName] = true;

if (Object.values(ManifestPlugin.#generated).every(v => v)) {
(ManifestPlugin.#generated[compilationName] as number)++;
const generatedValues = Object.values(ManifestPlugin.#generated);

// Once all configurations are generated the same amount of times then we can emit the manifest file
// Beware! If you are changing this code, please note:
// Using counter instead of boolean values prevents an issue, where configuration "A" is compiled multiple times
// before configuration "B" is compiled even once.
// With boolean values, we would emit the manifest file once configuration "B" is compiled for the first time.
// Emitting the manifest file resets the `generated` values and after the second configuration "B" is generated
// we get into inconsistent state, where we already consider configuration "B" to be ready for emitting,
// but it is not. The next manifest re-build is then triggered too early and we are stuck in this inconsistent state.
// From the user perspective, when we run `ima dev` and we change some file, the manifest file is always one version
// behind for one of the configurations. It is very hard to debug this issue, because it is not deterministic
// and it is hard to reproduce.
if (generatedValues.every(v => v === generatedValues[0])) {
// Reset tracking info
Object.keys(ManifestPlugin.#generated).forEach(
key =>
(ManifestPlugin.#generated[key as ImaConfigurationContext['name']] =
false)
(ManifestPlugin.#generated[
key as ImaConfigurationContext['name']
] = 0)
);

// Emit compiled ima runner with embedded runtime codes
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-cli/src/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export async function watch(args: Arguments) {

// Dev watcher
chokidar
.watch([path.join(inputDir, './**/*')], {
.watch([path.resolve(inputDir)], {
ignoreInitial: false,
ignored: config.exclude,
persistent: true,
Expand Down Expand Up @@ -239,7 +239,7 @@ export async function watch(args: Arguments) {
chokidar
.watch(
[
path.join(cwd, distBaseDir, '/**/*'),
path.join(cwd, distBaseDir),
Array.isArray(parsedArgs?.additionalWatchPaths) &&
parsedArgs?.additionalWatchPaths,
Array.isArray(config?.additionalWatchPaths) &&
Expand All @@ -249,7 +249,7 @@ export async function watch(args: Arguments) {
ignoreInitial: false,
persistent: true,
ignored: [
'**/tsconfig.tsbuildinfo/**',
'**/tsconfig.build.tsbuildinfo/**',
'**/node_modules/**',
'**/.DS_Store/**',
],
Expand Down

0 comments on commit cc551d6

Please sign in to comment.