Skip to content

Commit d1f5304

Browse files
committed
fix(content-utils): release failed build loaders
1 parent ee6be36 commit d1f5304

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

packages/content-utils/src/integration/gitPlugin.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,29 @@ export const gitBuildPlugin = (state: IntegrationState): Plugin => {
7979
let collectedGitInformation: Map<string, BuildGitTrackingInfo> | undefined;
8080
let retainedContentFiles: Set<string> | undefined;
8181
let buildContentLoaderRegistered = false;
82+
const releaseBuildContentLoader = () => {
83+
if (!buildContentLoaderRegistered) return;
84+
const registration = Reflect.get(globalThis, buildContentLoaderSymbol) as
85+
| BuildContentLoaderRegistration
86+
| undefined;
87+
if (registration !== undefined) {
88+
registration.references -= 1;
89+
if (registration.references === 0) {
90+
Reflect.deleteProperty(globalThis, buildContentLoaderSymbol);
91+
}
92+
}
93+
buildContentLoaderRegistered = false;
94+
};
8295

8396
return {
8497
name: '@inox-tools/content-utils/gitTimes',
8598
resolveId(id) {
8699
if (id === MODULE_ID) return RESOLVED_MODULE_ID;
87100
if (id === INNER_MODULE_ID) return RESOLVED_INNER_MODULE_ID;
88101
},
102+
buildEnd(error) {
103+
if (error) releaseBuildContentLoader();
104+
},
89105
transform(code, id) {
90106
if (id !== '\0astro:data-layer-content') return;
91107
const ast = this.parse(code);
@@ -160,17 +176,7 @@ export const gitBuildPlugin = (state: IntegrationState): Plugin => {
160176
);
161177
}
162178
} finally {
163-
if (buildContentLoaderRegistered) {
164-
const registration = Reflect.get(
165-
globalThis,
166-
buildContentLoaderSymbol
167-
) as BuildContentLoaderRegistration;
168-
registration.references -= 1;
169-
if (registration.references === 0) {
170-
Reflect.deleteProperty(globalThis, buildContentLoaderSymbol);
171-
}
172-
buildContentLoaderRegistered = false;
173-
}
179+
releaseBuildContentLoader();
174180
}
175181
});
176182
}

0 commit comments

Comments
 (0)