@@ -124,8 +124,10 @@ function _compileComponentTypescript({
124
124
( ) => _setupTypescriptCompilation ( context ) ,
125
125
// run before_component_typescript hook
126
126
( ) => hookRunner ( 'before_component_typescript' , context ) ,
127
- // compile component typescript
128
- ( ) => _renameIndexFileInMonoPack ( { context } ) ,
127
+ // rename the index files in vcomponents in packs
128
+ ( ) => _generateStubFile ( { context } ) ,
129
+ // remove the pre-existing type folders if exists
130
+ ( ) => _removePreExistingTypesFoldersInWeb ( { context } ) ,
129
131
// compile component typescript
130
132
( ) => _runTypescriptCompilation ( { context, pack, component } ) ,
131
133
// copy runtime resources to /js
@@ -169,6 +171,12 @@ function _compileComponentTypescript({
169
171
_generateApiDocumentation ,
170
172
{ context }
171
173
) ,
174
+ // verifies the contents of a built mono-pack
175
+ ( ) => _runIfTypescriptCompilationSucceeded (
176
+ context ,
177
+ _verifyMonoPacks ,
178
+ { context }
179
+ ) ,
172
180
// deletes declared global block
173
181
( ) => _runIfTypescriptCompilationSucceeded (
174
182
context ,
@@ -238,8 +246,10 @@ function compileApplicationTypescript(context) {
238
246
( ) => _setupTypescriptCompilation ( context ) ,
239
247
// run before_app_typescript hook
240
248
( ) => hookRunner ( 'before_app_typescript' , context ) ,
241
- // rename the index files in vcomponents in mono-packs
242
- ( ) => _renameIndexFileInMonoPack ( { context } ) ,
249
+ // rename the index files in vcomponents in packs
250
+ ( ) => _generateStubFile ( { context } ) ,
251
+ // remove the pre-existing type folders if exists
252
+ ( ) => _removePreExistingTypesFoldersInWeb ( { context } ) ,
243
253
// compile app typescript
244
254
( ) => _runTypescriptCompilation ( { context } ) ,
245
255
// copy runtime sources to /js
@@ -266,6 +276,12 @@ function compileApplicationTypescript(context) {
266
276
_organizeComponentsTypeDefinitions ,
267
277
{ context }
268
278
) ,
279
+ // verifies the contents of a built mono-pack
280
+ ( ) => _runIfTypescriptCompilationSucceeded (
281
+ context ,
282
+ _verifyMonoPacks ,
283
+ { context }
284
+ ) ,
269
285
// deletes declared global block
270
286
( ) => _runIfTypescriptCompilationSucceeded (
271
287
context ,
@@ -286,49 +302,62 @@ function compileApplicationTypescript(context) {
286
302
}
287
303
288
304
/**
289
- * ## _renameIndexFileInMonoPack
305
+ * ## _generateStubFile
290
306
*
291
307
* renames the vcomponent index.ts file in a mono-pack to <componentName>.ts,
292
- * and copies it to the mono- pack root level:
308
+ * and copies it to the pack root level:
293
309
*
294
310
* @private
295
311
* @param {object } context - build context
296
312
*/
297
- function _renameIndexFileInMonoPack ( { context } ) {
313
+ function _generateStubFile ( { context } ) {
298
314
const compositeComponents = context . opts . component ? [ context . opts . component ] :
299
315
util . getLocalCompositeComponents ( ) ;
300
316
compositeComponents . forEach ( ( compositeComponent ) => {
301
317
const componentJson = util . getComponentJson ( { component : compositeComponent } ) ;
302
- if ( componentJson . type && componentJson . type === CONSTANTS . PACK_TYPE . MONO_PACK ) {
318
+ if ( componentJson . type && ( componentJson . type === 'pack' ||
319
+ componentJson . type === CONSTANTS . PACK_TYPE . MONO_PACK ) ) {
303
320
const vComponentsInMonoPack = util . getVComponentsInJETPack ( { pack : compositeComponent } ) ;
321
+ const useUnversionedStructure = context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ||
322
+ util . getOraclejetConfigJson ( ) . unversioned ;
304
323
vComponentsInMonoPack . forEach ( ( vComponent ) => {
305
324
const pathToComponentInTsFolder = path . join (
306
325
context . opts . stagingPath ,
307
326
'ts' ,
308
327
context . paths . components ,
309
328
compositeComponent ,
310
- context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ? `${ vComponent } ` :
329
+ useUnversionedStructure ? `${ vComponent } ` :
311
330
path . join ( componentJson . version , vComponent )
312
331
) ;
313
332
const pathToComponentWithoutTsFolder = path . join (
314
333
context . opts . stagingPath ,
315
334
context . paths . components ,
316
335
compositeComponent ,
317
- context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ? `${ vComponent } ` :
336
+ useUnversionedStructure ? `${ vComponent } ` :
318
337
path . join ( componentJson . version , vComponent )
319
338
) ;
320
339
const pathToComponentsInWeb = fs . existsSync ( pathToComponentInTsFolder ) ?
321
340
pathToComponentInTsFolder : pathToComponentWithoutTsFolder ;
322
341
const pathToStubFile = `${ pathToComponentsInWeb } .ts` ;
342
+ // eslint-disable-next-line no-useless-escape
343
+ const importMatch = new RegExp ( `["|'].\/${ vComponent } ["|']` ) ;
323
344
const indexFile = path . join ( pathToComponentsInWeb , 'index.ts' ) ;
324
- if ( ! fs . existsSync ( pathToStubFile ) && fs . existsSync ( indexFile ) ) {
325
- const indexFileContent = fs . readFileSync ( indexFile , { encoding : 'utf-8' } ) ;
326
- // eslint-disable-next-line no-useless-escape
327
- const importMatch = new RegExp ( `["|'].\/${ vComponent } ["|']` ) ;
328
- fs . writeFileSync (
329
- pathToStubFile ,
330
- indexFileContent . replace ( importMatch , `"./${ vComponent } /${ vComponent } "` )
331
- ) ;
345
+ const loaderFile = path . join ( pathToComponentsInWeb , 'loader.ts' ) ;
346
+ if ( ! fs . existsSync ( pathToStubFile ) ) {
347
+ if ( fs . existsSync ( indexFile ) ) {
348
+ const indexFileContent = fs . readFileSync ( indexFile , { encoding : 'utf-8' } ) ;
349
+ fs . writeFileSync (
350
+ pathToStubFile ,
351
+ indexFileContent . replace ( importMatch , `"${ componentJson . name } /${ vComponent } /${ vComponent } "` )
352
+ ) ;
353
+ } else if ( fs . existsSync ( loaderFile ) &&
354
+ componentJson . type === CONSTANTS . PACK_TYPE . MONO_PACK ) {
355
+ const loaderFileContent = fs . readFileSync ( loaderFile , { encoding : 'utf-8' } ) ;
356
+ fs . writeFileSync (
357
+ pathToStubFile ,
358
+ loaderFileContent . replace ( importMatch , `"${ componentJson . name } /${ vComponent } /${ vComponent } "` )
359
+ ) ;
360
+ }
332
361
}
333
362
} ) ;
334
363
}
@@ -425,7 +454,9 @@ function _runTypescriptCompilation({ context, pack, component }) {
425
454
apiDocDir = null ;
426
455
}
427
456
// For component(s) in a pack, the version number is between the pack and component:
428
- if ( apiDocDir && ! context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ) {
457
+ const useUnversionedStructure = context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ||
458
+ util . getOraclejetConfigJson ( ) . unversioned ;
459
+ if ( apiDocDir && ! useUnversionedStructure ) {
429
460
if ( component && pack ) {
430
461
const packVersion = util . getComponentVersion ( { component : pack } ) ;
431
462
apiDocDir = path . join ( components , pack , packVersion , component ) ;
@@ -1223,7 +1254,7 @@ function cleanTypescript(context) {
1223
1254
*
1224
1255
* Deletes global declaration for if component's full name is of type any
1225
1256
*
1226
- * @public
1257
+ * @private
1227
1258
* @param {object } context
1228
1259
* @returns {Promise<object> }
1229
1260
*/
@@ -1235,19 +1266,21 @@ function _redefineIndexFileStub({ context }) {
1235
1266
// Take note that the structure for VDOM apps (where there is no ts/js folders)
1236
1267
// is observed.
1237
1268
const componentJson = util . getComponentJson ( { component : compositeComponent } ) ;
1269
+ const useUnversionedStructure = context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ||
1270
+ util . getOraclejetConfigJson ( ) . unversioned ;
1238
1271
const pathToComponent = path . join (
1239
1272
context . opts . stagingPath ,
1240
1273
util . isVDOMApplication ( ) ? '' : 'ts' ,
1241
1274
context . paths . components ,
1242
1275
compositeComponent ,
1243
- context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ? '' : componentJson . version
1276
+ useUnversionedStructure ? '' : componentJson . version
1244
1277
) ;
1245
1278
const pathToComponentInJsFolder = path . join (
1246
1279
context . opts . stagingPath ,
1247
1280
util . isVDOMApplication ( ) ? '' : 'js' ,
1248
1281
context . paths . components ,
1249
1282
compositeComponent ,
1250
- context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ? '' : componentJson . version
1283
+ useUnversionedStructure ? '' : componentJson . version
1251
1284
) ;
1252
1285
if ( componentJson . type === 'pack' || componentJson . type === CONSTANTS . PACK_TYPE . MONO_PACK ) {
1253
1286
const vComponentsInMonoPack = util . getVComponentsInJETPack ( { pack : compositeComponent } ) ;
@@ -1297,6 +1330,15 @@ function _redefineIndexFileStub({ context }) {
1297
1330
return Promise . resolve ( context ) ;
1298
1331
}
1299
1332
1333
+ /**
1334
+ * ## _redefineIndexFileStub
1335
+ *
1336
+ * Deletes global declaration for if component's full name is of type any
1337
+ *
1338
+ * @private
1339
+ * @param {string } componentName
1340
+ * @param {array } filePathsArray
1341
+ */
1300
1342
function _removeGlobalDeclaration ( filePathsArray , componentName ) {
1301
1343
filePathsArray . forEach ( ( filePath ) => {
1302
1344
if ( fs . existsSync ( filePath ) ) {
@@ -1316,6 +1358,182 @@ function _removeGlobalDeclaration(filePathsArray, componentName) {
1316
1358
} ) ;
1317
1359
}
1318
1360
1361
+ /**
1362
+ * ## _verifyMonoPacks
1363
+ *
1364
+ * Verifies the contents of the built mono-packs
1365
+ *
1366
+ * @private
1367
+ * @param {objetc } context
1368
+ */
1369
+ function _verifyMonoPacks ( { context } ) {
1370
+ let compositeComponents ;
1371
+
1372
+ if ( context && context . opts && context . opts . component ) {
1373
+ compositeComponents = [ context . opts . component ] ;
1374
+ } else {
1375
+ compositeComponents = util . getLocalCompositeComponents ( ) ;
1376
+ }
1377
+
1378
+ // Filter the composite components to get packs only:
1379
+ const packArray = compositeComponents . filter ( component => util . isJETPack ( { pack : component } ) ) ;
1380
+
1381
+ // Verify each mono-pack in the pack array:
1382
+ packArray . forEach ( pack => verifyMonoPack ( { pack, context } ) ) ;
1383
+ }
1384
+
1385
+ /**
1386
+ * ## verifyMonoPack
1387
+ *
1388
+ * Verifies the contents of a given built-mono-pack
1389
+ *
1390
+ * @param {object } context
1391
+ * @param {string } pack
1392
+ */
1393
+ function verifyMonoPack ( { pack, context } ) {
1394
+ const componentJson = util . getComponentJson ( { component : pack } ) ;
1395
+ if ( componentJson && componentJson . type === CONSTANTS . PACK_TYPE . MONO_PACK ) {
1396
+ const packContents = componentJson . contents || [ ] ;
1397
+ packContents . forEach ( ( packContent ) => {
1398
+ if ( util . isLocalComponent ( { pack, component : packContent . name } ) ) {
1399
+ verifyComponentsInMonoPack ( {
1400
+ context,
1401
+ packComponentJson : componentJson ,
1402
+ component : packContent . name
1403
+ } ) ;
1404
+ } else {
1405
+ verifyOtherContentsInMonoPack ( {
1406
+ context,
1407
+ packComponentJson : componentJson ,
1408
+ packContent
1409
+ } ) ;
1410
+ }
1411
+ } ) ;
1412
+ }
1413
+ }
1414
+
1415
+ /**
1416
+ * ## verifyComponentsInMonoPack
1417
+ *
1418
+ * @param {object } context
1419
+ * @param {object } packComponentJson
1420
+ * @param {string } component
1421
+ */
1422
+ function verifyComponentsInMonoPack ( { context, packComponentJson, component } ) {
1423
+ const pack = packComponentJson . name ;
1424
+ const version = packComponentJson . version ;
1425
+ const componentTypes = [ 'composite' , 'resource' , undefined ] ;
1426
+ // At this point, we should have the component json for all components in the
1427
+ // pack; so, we can retrieve it for verification purposes.
1428
+ const componentJson = util . getComponentJson ( {
1429
+ context,
1430
+ pack,
1431
+ component,
1432
+ built : true
1433
+ } ) ;
1434
+
1435
+ // The built component's component json must have a matching name attribute
1436
+ // as that mentioned in the mono-pack's contents name property and the pack
1437
+ // name in the respective component json file matches that of the pack, too:
1438
+ if ( componentJson . name !== component ) {
1439
+ util . log . error ( `Listed component ${ component } name does not match` ) ;
1440
+ } else if ( ! componentJson . pack && componentJson . type !== 'resource' ) {
1441
+ // It is possible that the pack property in the resource component is not defined:
1442
+ util . log . error ( `Component "${ component } " does not have a pack property defined in its component.json file.` ) ;
1443
+ } else if ( componentJson . pack && componentJson . pack !== pack ) {
1444
+ util . log . error ( `The name of the pack in "${ component } " component json does not match with pack ${ pack } ` ) ;
1445
+ } else if ( ! componentTypes . includes ( componentJson . type ) ) {
1446
+ util . log . error ( `Component "${ component } " has invalid type` ) ;
1447
+ }
1448
+
1449
+ // If the main attribute is present, verify the main value scaffolded is in
1450
+ // the form "main":"<pack>/<component-name>" and that there is a corresponding
1451
+ // physical .js file:
1452
+ if ( componentJson . main ) {
1453
+ const useUnversionedStructure = context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ||
1454
+ util . getOraclejetConfigJson ( ) . unversioned ;
1455
+ const pathToStubJsFile = path . join (
1456
+ context . opts . stagingPath ,
1457
+ util . isVDOMApplication ( ) ? '' : 'js' ,
1458
+ context . paths . components ,
1459
+ pack ,
1460
+ useUnversionedStructure ? '' : version ,
1461
+ component ,
1462
+ `${ component } .js`
1463
+ ) ;
1464
+
1465
+ if ( componentJson . main !== `${ pack } /${ component } ` ) {
1466
+ util . log . error ( `Component ${ component } has an invalid main attribute value ${ pack } /${ component } ` ) ;
1467
+ } else if ( ! fs . existsSync ( pathToStubJsFile ) ) {
1468
+ util . log . error ( `Stub file ${ component } .js not present at the root of pack ${ pack } ` ) ;
1469
+ }
1470
+ }
1471
+ }
1472
+
1473
+ /**
1474
+ * ## verifyOtherContentsInMonoPack
1475
+ *
1476
+ * @param {object } context
1477
+ * @param {object } packComponentJson
1478
+ * @param {object } packContent
1479
+ */
1480
+ function verifyOtherContentsInMonoPack ( { context, packComponentJson, packContent } ) {
1481
+ const pack = packComponentJson . name ;
1482
+ const contentName = packContent . name ;
1483
+ const version = packComponentJson . version ;
1484
+ const contentMainEntry = packContent . main ;
1485
+ const useUnversionedStructure = context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ||
1486
+ util . getOraclejetConfigJson ( ) . unversioned ;
1487
+ const pathToPackInStaging = path . join (
1488
+ context . opts . stagingPath ,
1489
+ util . isVDOMApplication ( ) ? '' : 'js' ,
1490
+ context . paths . components ,
1491
+ pack ,
1492
+ useUnversionedStructure ? '' : version
1493
+ ) ;
1494
+
1495
+ if ( contentMainEntry ) {
1496
+ const pathToMainEntryInJsFolder = path . join ( pathToPackInStaging , contentMainEntry ) ;
1497
+ if ( ! fs . existsSync ( pathToMainEntryInJsFolder ) ) {
1498
+ util . log . error ( `Content "${ contentName } " has a main entry "${ contentMainEntry } " that is not in the pack "${ pack } ".` ) ;
1499
+ }
1500
+ } else {
1501
+ const pathToContentInJsFolder = path . join ( pathToPackInStaging , contentName ) ;
1502
+ if ( ! fs . existsSync ( pathToContentInJsFolder ) ) {
1503
+ util . log . error ( `Content "${ contentName } " is declared in the content manifest but it is not in the pack "${ pack } ".` ) ;
1504
+ }
1505
+ }
1506
+ }
1507
+
1508
+ /**
1509
+ * ## _removePreExistingTypesFoldersInWeb
1510
+ *
1511
+ * Cleans up the pre-existing types before compilation
1512
+ *
1513
+ * @param {object } context
1514
+ */
1515
+ function _removePreExistingTypesFoldersInWeb ( { context } ) {
1516
+ const compositeComponents = context . opts . component ? [ context . opts . component ] :
1517
+ util . getLocalCompositeComponents ( ) ;
1518
+ compositeComponents . forEach ( ( compositeComponent ) => {
1519
+ const componentJson = util . getComponentJson ( { component : compositeComponent } ) ;
1520
+ const useUnversionedStructure = context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ||
1521
+ util . getOraclejetConfigJson ( ) . unversioned ;
1522
+ const pathToComponentTypesFolder = path . join (
1523
+ context . opts . stagingPath ,
1524
+ util . isVDOMApplication ( ) ? '' : 'ts' ,
1525
+ context . paths . components ,
1526
+ compositeComponent ,
1527
+ useUnversionedStructure ? '' : componentJson . version ,
1528
+ 'types'
1529
+ ) ;
1530
+ if ( fs . existsSync ( pathToComponentTypesFolder ) ) {
1531
+ fs . removeSync ( pathToComponentTypesFolder ) ;
1532
+ }
1533
+ } ) ;
1534
+ return Promise . resolve ( context ) ;
1535
+ }
1536
+
1319
1537
module . exports = {
1320
1538
compileComponentTypescript,
1321
1539
compileApplicationTypescript,
0 commit comments