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

fix: ima dev and ima-plugin link command not updating in edge cases #597

Merged
merged 2 commits into from
Dec 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading