@@ -124,8 +124,10 @@ function _compileComponentTypescript({
124124 ( ) => _setupTypescriptCompilation ( context ) ,
125125 // run before_component_typescript hook
126126 ( ) => 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 } ) ,
129131 // compile component typescript
130132 ( ) => _runTypescriptCompilation ( { context, pack, component } ) ,
131133 // copy runtime resources to /js
@@ -169,6 +171,12 @@ function _compileComponentTypescript({
169171 _generateApiDocumentation ,
170172 { context }
171173 ) ,
174+ // verifies the contents of a built mono-pack
175+ ( ) => _runIfTypescriptCompilationSucceeded (
176+ context ,
177+ _verifyMonoPacks ,
178+ { context }
179+ ) ,
172180 // deletes declared global block
173181 ( ) => _runIfTypescriptCompilationSucceeded (
174182 context ,
@@ -238,8 +246,10 @@ function compileApplicationTypescript(context) {
238246 ( ) => _setupTypescriptCompilation ( context ) ,
239247 // run before_app_typescript hook
240248 ( ) => 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 } ) ,
243253 // compile app typescript
244254 ( ) => _runTypescriptCompilation ( { context } ) ,
245255 // copy runtime sources to /js
@@ -266,6 +276,12 @@ function compileApplicationTypescript(context) {
266276 _organizeComponentsTypeDefinitions ,
267277 { context }
268278 ) ,
279+ // verifies the contents of a built mono-pack
280+ ( ) => _runIfTypescriptCompilationSucceeded (
281+ context ,
282+ _verifyMonoPacks ,
283+ { context }
284+ ) ,
269285 // deletes declared global block
270286 ( ) => _runIfTypescriptCompilationSucceeded (
271287 context ,
@@ -286,49 +302,62 @@ function compileApplicationTypescript(context) {
286302}
287303
288304/**
289- * ## _renameIndexFileInMonoPack
305+ * ## _generateStubFile
290306 *
291307 * 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:
293309 *
294310 * @private
295311 * @param {object } context - build context
296312 */
297- function _renameIndexFileInMonoPack ( { context } ) {
313+ function _generateStubFile ( { context } ) {
298314 const compositeComponents = context . opts . component ? [ context . opts . component ] :
299315 util . getLocalCompositeComponents ( ) ;
300316 compositeComponents . forEach ( ( compositeComponent ) => {
301317 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 ) ) {
303320 const vComponentsInMonoPack = util . getVComponentsInJETPack ( { pack : compositeComponent } ) ;
321+ const useUnversionedStructure = context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ||
322+ util . getOraclejetConfigJson ( ) . unversioned ;
304323 vComponentsInMonoPack . forEach ( ( vComponent ) => {
305324 const pathToComponentInTsFolder = path . join (
306325 context . opts . stagingPath ,
307326 'ts' ,
308327 context . paths . components ,
309328 compositeComponent ,
310- context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ? `${ vComponent } ` :
329+ useUnversionedStructure ? `${ vComponent } ` :
311330 path . join ( componentJson . version , vComponent )
312331 ) ;
313332 const pathToComponentWithoutTsFolder = path . join (
314333 context . opts . stagingPath ,
315334 context . paths . components ,
316335 compositeComponent ,
317- context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ? `${ vComponent } ` :
336+ useUnversionedStructure ? `${ vComponent } ` :
318337 path . join ( componentJson . version , vComponent )
319338 ) ;
320339 const pathToComponentsInWeb = fs . existsSync ( pathToComponentInTsFolder ) ?
321340 pathToComponentInTsFolder : pathToComponentWithoutTsFolder ;
322341 const pathToStubFile = `${ pathToComponentsInWeb } .ts` ;
342+ // eslint-disable-next-line no-useless-escape
343+ const importMatch = new RegExp ( `["|'].\/${ vComponent } ["|']` ) ;
323344 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+ }
332361 }
333362 } ) ;
334363 }
@@ -425,7 +454,9 @@ function _runTypescriptCompilation({ context, pack, component }) {
425454 apiDocDir = null ;
426455 }
427456 // 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 ) {
429460 if ( component && pack ) {
430461 const packVersion = util . getComponentVersion ( { component : pack } ) ;
431462 apiDocDir = path . join ( components , pack , packVersion , component ) ;
@@ -1223,7 +1254,7 @@ function cleanTypescript(context) {
12231254 *
12241255 * Deletes global declaration for if component's full name is of type any
12251256 *
1226- * @public
1257+ * @private
12271258 * @param {object } context
12281259 * @returns {Promise<object> }
12291260 */
@@ -1235,19 +1266,21 @@ function _redefineIndexFileStub({ context }) {
12351266 // Take note that the structure for VDOM apps (where there is no ts/js folders)
12361267 // is observed.
12371268 const componentJson = util . getComponentJson ( { component : compositeComponent } ) ;
1269+ const useUnversionedStructure = context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ||
1270+ util . getOraclejetConfigJson ( ) . unversioned ;
12381271 const pathToComponent = path . join (
12391272 context . opts . stagingPath ,
12401273 util . isVDOMApplication ( ) ? '' : 'ts' ,
12411274 context . paths . components ,
12421275 compositeComponent ,
1243- context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ? '' : componentJson . version
1276+ useUnversionedStructure ? '' : componentJson . version
12441277 ) ;
12451278 const pathToComponentInJsFolder = path . join (
12461279 context . opts . stagingPath ,
12471280 util . isVDOMApplication ( ) ? '' : 'js' ,
12481281 context . paths . components ,
12491282 compositeComponent ,
1250- context . opts [ CONSTANTS . OMIT_COMPONENT_VERSION_FLAG ] ? '' : componentJson . version
1283+ useUnversionedStructure ? '' : componentJson . version
12511284 ) ;
12521285 if ( componentJson . type === 'pack' || componentJson . type === CONSTANTS . PACK_TYPE . MONO_PACK ) {
12531286 const vComponentsInMonoPack = util . getVComponentsInJETPack ( { pack : compositeComponent } ) ;
@@ -1297,6 +1330,15 @@ function _redefineIndexFileStub({ context }) {
12971330 return Promise . resolve ( context ) ;
12981331}
12991332
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+ */
13001342function _removeGlobalDeclaration ( filePathsArray , componentName ) {
13011343 filePathsArray . forEach ( ( filePath ) => {
13021344 if ( fs . existsSync ( filePath ) ) {
@@ -1316,6 +1358,182 @@ function _removeGlobalDeclaration(filePathsArray, componentName) {
13161358 } ) ;
13171359}
13181360
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+
13191537module . exports = {
13201538 compileComponentTypescript,
13211539 compileApplicationTypescript,
0 commit comments