Skip to content

Commit 8d714d6

Browse files
authored
Cleaning up loadPartial to make sure they are registered properly before generation (#1558)
- The partialFile loading await fsPromise.readFile(singlePkg.path, 'utf8'); is now done before registering the partial. - We are hitting a use case intermittently where the partial is not loaded and generation is triggered. Believe that this was happening due to partial file loading and registering happening asynchronously(Not always before generation). - JIRA: ZAPP-1623
1 parent d814b12 commit 8d714d6

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

docs/api.md

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7770,9 +7770,9 @@ Get endpoint type events from the given endpoint type ID.
77707770
* [~produceContent(hb, metaInfo, db, sessionId, singlePkg, overridePath:)](#module_JS API_ generator logic..produceContent) ⇒
77717771
* [~wrapOverridable(originalFn, overrideFn)](#module_JS API_ generator logic..wrapOverridable) ⇒
77727772
* [~loadOverridable(path)](#module_JS API_ generator logic..loadOverridable)
7773-
* [~loadPartial(path)](#module_JS API_ generator logic..loadPartial)
7773+
* [~loadPartial(hb, name, data)](#module_JS API_ generator logic..loadPartial)
77747774
* [~helperWrapper(wrappedHelper)](#module_JS API_ generator logic..helperWrapper) ⇒
7775-
* [~loadHelper(helpers)](#module_JS API_ generator logic..loadHelper)
7775+
* [~loadHelper(hb, helpers, context)](#module_JS API_ generator logic..loadHelper)
77767776
* [~allBuiltInHelpers()](#module_JS API_ generator logic..allBuiltInHelpers) ⇒
77777777
* [~findHelperPackageByAlias(alias)](#module_JS API_ generator logic..findHelperPackageByAlias) ⇒
77787778
* [~initializeBuiltInHelpersForPackage()](#module_JS API_ generator logic..initializeBuiltInHelpersForPackage)
@@ -8126,14 +8126,16 @@ This function is responsible to load the overridable function container.
81268126

81278127
<a name="module_JS API_ generator logic..loadPartial"></a>
81288128

8129-
### JS API: generator logic~loadPartial(path)
8129+
### JS API: generator logic~loadPartial(hb, name, data)
81308130
Function that loads the partials.
81318131

81328132
**Kind**: inner method of [<code>JS API: generator logic</code>](#module_JS API_ generator logic)
81338133

81348134
| Param | Type |
81358135
| --- | --- |
8136-
| path | <code>\*</code> |
8136+
| hb | <code>\*</code> |
8137+
| name | <code>\*</code> |
8138+
| data | <code>\*</code> |
81378139

81388140
<a name="module_JS API_ generator logic..helperWrapper"></a>
81398141

@@ -8147,14 +8149,16 @@ Function that loads the partials.
81478149

81488150
<a name="module_JS API_ generator logic..loadHelper"></a>
81498151

8150-
### JS API: generator logic~loadHelper(helpers)
8152+
### JS API: generator logic~loadHelper(hb, helpers, context)
81518153
Function that loads the helpers.
81528154

81538155
**Kind**: inner method of [<code>JS API: generator logic</code>](#module_JS API_ generator logic)
81548156

8155-
| Param | Type | Description |
8156-
| --- | --- | --- |
8157-
| helpers | <code>\*</code> | a string path if value is passed through CLI, the nativeRequire() is leverage the native js function instead of webpack's special sauce. a required() module if invoked by backend js code. this is required to force webpack to resolve the included files as path will be difference after being packed for production. |
8157+
| Param | Type | Default | Description |
8158+
| --- | --- | --- | --- |
8159+
| hb | <code>\*</code> | | |
8160+
| helpers | <code>\*</code> | | a string path if value is passed through CLI, the nativeRequire() is leverage the native js function instead of webpack's special sauce. a required() module if invoked by backend js code. this is required to force webpack to resolve the included files as path will be difference after being packed for production. |
8161+
| context | <code>\*</code> | <code></code> | |
81588162

81598163
<a name="module_JS API_ generator logic..allBuiltInHelpers"></a>
81608164

@@ -13104,9 +13108,9 @@ This module contains the API for templating. For more detailed instructions, rea
1310413108
* [~produceContent(hb, metaInfo, db, sessionId, singlePkg, overridePath:)](#module_JS API_ generator logic..produceContent) ⇒
1310513109
* [~wrapOverridable(originalFn, overrideFn)](#module_JS API_ generator logic..wrapOverridable) ⇒
1310613110
* [~loadOverridable(path)](#module_JS API_ generator logic..loadOverridable)
13107-
* [~loadPartial(path)](#module_JS API_ generator logic..loadPartial)
13111+
* [~loadPartial(hb, name, data)](#module_JS API_ generator logic..loadPartial)
1310813112
* [~helperWrapper(wrappedHelper)](#module_JS API_ generator logic..helperWrapper) ⇒
13109-
* [~loadHelper(helpers)](#module_JS API_ generator logic..loadHelper)
13113+
* [~loadHelper(hb, helpers, context)](#module_JS API_ generator logic..loadHelper)
1311013114
* [~allBuiltInHelpers()](#module_JS API_ generator logic..allBuiltInHelpers) ⇒
1311113115
* [~findHelperPackageByAlias(alias)](#module_JS API_ generator logic..findHelperPackageByAlias) ⇒
1311213116
* [~initializeBuiltInHelpersForPackage()](#module_JS API_ generator logic..initializeBuiltInHelpersForPackage)
@@ -13460,14 +13464,16 @@ This function is responsible to load the overridable function container.
1346013464

1346113465
<a name="module_JS API_ generator logic..loadPartial"></a>
1346213466

13463-
### JS API: generator logic~loadPartial(path)
13467+
### JS API: generator logic~loadPartial(hb, name, data)
1346413468
Function that loads the partials.
1346513469

1346613470
**Kind**: inner method of [<code>JS API: generator logic</code>](#module_JS API_ generator logic)
1346713471

1346813472
| Param | Type |
1346913473
| --- | --- |
13470-
| path | <code>\*</code> |
13474+
| hb | <code>\*</code> |
13475+
| name | <code>\*</code> |
13476+
| data | <code>\*</code> |
1347113477

1347213478
<a name="module_JS API_ generator logic..helperWrapper"></a>
1347313479

@@ -13481,14 +13487,16 @@ Function that loads the partials.
1348113487

1348213488
<a name="module_JS API_ generator logic..loadHelper"></a>
1348313489

13484-
### JS API: generator logic~loadHelper(helpers)
13490+
### JS API: generator logic~loadHelper(hb, helpers, context)
1348513491
Function that loads the helpers.
1348613492

1348713493
**Kind**: inner method of [<code>JS API: generator logic</code>](#module_JS API_ generator logic)
1348813494

13489-
| Param | Type | Description |
13490-
| --- | --- | --- |
13491-
| helpers | <code>\*</code> | a string path if value is passed through CLI, the nativeRequire() is leverage the native js function instead of webpack's special sauce. a required() module if invoked by backend js code. this is required to force webpack to resolve the included files as path will be difference after being packed for production. |
13495+
| Param | Type | Default | Description |
13496+
| --- | --- | --- | --- |
13497+
| hb | <code>\*</code> | | |
13498+
| helpers | <code>\*</code> | | a string path if value is passed through CLI, the nativeRequire() is leverage the native js function instead of webpack's special sauce. a required() module if invoked by backend js code. this is required to force webpack to resolve the included files as path will be difference after being packed for production. |
13499+
| context | <code>\*</code> | <code></code> | |
1349213500

1349313501
<a name="module_JS API_ generator logic..allBuiltInHelpers"></a>
1349413502

@@ -13762,9 +13770,9 @@ Function wrapper that can be used when a helper is deprecated.
1376213770
* [~produceContent(hb, metaInfo, db, sessionId, singlePkg, overridePath:)](#module_JS API_ generator logic..produceContent) ⇒
1376313771
* [~wrapOverridable(originalFn, overrideFn)](#module_JS API_ generator logic..wrapOverridable) ⇒
1376413772
* [~loadOverridable(path)](#module_JS API_ generator logic..loadOverridable)
13765-
* [~loadPartial(path)](#module_JS API_ generator logic..loadPartial)
13773+
* [~loadPartial(hb, name, data)](#module_JS API_ generator logic..loadPartial)
1376613774
* [~helperWrapper(wrappedHelper)](#module_JS API_ generator logic..helperWrapper) ⇒
13767-
* [~loadHelper(helpers)](#module_JS API_ generator logic..loadHelper)
13775+
* [~loadHelper(hb, helpers, context)](#module_JS API_ generator logic..loadHelper)
1376813776
* [~allBuiltInHelpers()](#module_JS API_ generator logic..allBuiltInHelpers) ⇒
1376913777
* [~findHelperPackageByAlias(alias)](#module_JS API_ generator logic..findHelperPackageByAlias) ⇒
1377013778
* [~initializeBuiltInHelpersForPackage()](#module_JS API_ generator logic..initializeBuiltInHelpersForPackage)
@@ -14118,14 +14126,16 @@ This function is responsible to load the overridable function container.
1411814126

1411914127
<a name="module_JS API_ generator logic..loadPartial"></a>
1412014128

14121-
### JS API: generator logic~loadPartial(path)
14129+
### JS API: generator logic~loadPartial(hb, name, data)
1412214130
Function that loads the partials.
1412314131

1412414132
**Kind**: inner method of [<code>JS API: generator logic</code>](#module_JS API_ generator logic)
1412514133

1412614134
| Param | Type |
1412714135
| --- | --- |
14128-
| path | <code>\*</code> |
14136+
| hb | <code>\*</code> |
14137+
| name | <code>\*</code> |
14138+
| data | <code>\*</code> |
1412914139

1413014140
<a name="module_JS API_ generator logic..helperWrapper"></a>
1413114141

@@ -14139,14 +14149,16 @@ Function that loads the partials.
1413914149

1414014150
<a name="module_JS API_ generator logic..loadHelper"></a>
1414114151

14142-
### JS API: generator logic~loadHelper(helpers)
14152+
### JS API: generator logic~loadHelper(hb, helpers, context)
1414314153
Function that loads the helpers.
1414414154

1414514155
**Kind**: inner method of [<code>JS API: generator logic</code>](#module_JS API_ generator logic)
1414614156

14147-
| Param | Type | Description |
14148-
| --- | --- | --- |
14149-
| helpers | <code>\*</code> | a string path if value is passed through CLI, the nativeRequire() is leverage the native js function instead of webpack's special sauce. a required() module if invoked by backend js code. this is required to force webpack to resolve the included files as path will be difference after being packed for production. |
14157+
| Param | Type | Default | Description |
14158+
| --- | --- | --- | --- |
14159+
| hb | <code>\*</code> | | |
14160+
| helpers | <code>\*</code> | | a string path if value is passed through CLI, the nativeRequire() is leverage the native js function instead of webpack's special sauce. a required() module if invoked by backend js code. this is required to force webpack to resolve the included files as path will be difference after being packed for production. |
14161+
| context | <code>\*</code> | <code></code> | |
1415014162

1415114163
<a name="module_JS API_ generator logic..allBuiltInHelpers"></a>
1415214164

src-electron/generator/generation-engine.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,15 @@ async function generateAllTemplates(
742742
})
743743

744744
// Next load the partials
745-
packages.forEach((singlePkg) => {
746-
if (singlePkg.type == dbEnum.packageType.genPartial) {
747-
templateEngine.loadPartial(hb, singlePkg.category, singlePkg.path)
748-
}
745+
const partialPackages = packages.filter(
746+
(pkg) => pkg.type === dbEnum.packageType.genPartial
747+
)
748+
const partialDataArray = await Promise.all(
749+
partialPackages.map((pkg) => fsPromise.readFile(pkg.path, 'utf8'))
750+
)
751+
partialDataArray.forEach((data, index) => {
752+
const singlePkg = partialPackages[index]
753+
templateEngine.loadPartial(hb, singlePkg.category, data)
749754
})
750755

751756
// Let's collect the required list of helpers.

src-electron/generator/template-engine.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ function loadOverridable(overridePath) {
284284

285285
/**
286286
* Function that loads the partials.
287-
*
288-
* @param {*} path
287+
* @param {*} hb
288+
* @param {*} name
289+
* @param {*} data
289290
*/
290-
async function loadPartial(hb, name, path) {
291+
function loadPartial(hb, name, data) {
291292
try {
292-
let data = await fsPromise.readFile(path, 'utf8')
293293
hb.registerPartial(name, data)
294294
} catch (err) {
295295
console.log('Could not load partial ' + name + ': ' + err)
@@ -339,13 +339,14 @@ function helperWrapper(wrappedHelper) {
339339
}
340340
/**
341341
* Function that loads the helpers.
342-
*
342+
* @param {*} hb
343343
* @param {*} helpers - a string path if value is passed through CLI,
344344
* the nativeRequire() is leverage the native js function instead
345345
* of webpack's special sauce.
346346
* a required() module if invoked by backend js code.
347347
* this is required to force webpack to resolve the included files
348348
* as path will be difference after being packed for production.
349+
* @param {*} context
349350
*/
350351
function loadHelper(hb, helpers, context = null) {
351352
// helper

0 commit comments

Comments
 (0)