@hitachivantara/app-shell-vite-plugin 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"automatic-utils.d.ts","sourceRoot":"","sources":["../src/automatic-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAEhB,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AA6B1C;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB;IACD,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;CAChB,EAAE,CAyCF;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,MAAM,EAAE,CAyCV;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,QAoD1D"}
1
+ {"version":3,"file":"automatic-utils.d.ts","sourceRoot":"","sources":["../src/automatic-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAEhB,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AA+B1C;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB;IACD,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;CAChB,EAAE,CAoCF;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,MAAM,EAAE,CAyCV;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,QAoD1D"}
@@ -1,5 +1,6 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
+ import { getFinalModuleName } from "./config-utils.js";
3
4
  function createLabel(str) {
4
5
  const noExtension = str.replace(/\.[^/.]+$/, "");
5
6
  const splitByCapital = noExtension.split(/(?=[A-Z])/).join(" ");
@@ -44,19 +45,16 @@ export function mapFolderIndexFilesToRoutes(root, viewsFolder) {
44
45
  const normalizedFilePath = filePath.replaceAll(path.sep, "/");
45
46
  // fetches what is between the normalizedViewsFolder (inclusive) and the last '/' (exclusive)
46
47
  // example: 'dummy/path/src/pages/Page1/index.tsx' and 'src/pages' returns src/pages/Page1
47
- let bundle = normalizedFilePath.substring(normalizedFilePath.lastIndexOf(`/${normalizedViewsFolder}/`) + 1, normalizedFilePath.lastIndexOf("/"));
48
+ const bundle = normalizedFilePath.substring(normalizedFilePath.lastIndexOf(`/${normalizedViewsFolder}/`) + 1, normalizedFilePath.lastIndexOf("/"));
48
49
  const route = bundle
49
50
  .replace(new RegExp(`^${normalizedViewsFolder}`), "")
50
51
  .replaceAll(/\$/g, ":")
51
52
  .toLowerCase();
52
- // module to be added when building the application
53
- const module = bundle;
54
- // src needs to be replaced either with '@self' (that when built is replaced by the app id)
55
- bundle = bundle.replace(/^(\/?)src\//, "@self/");
56
- bundle = bundle.replaceAll("$", "_");
57
- bundle += ".js";
58
- const viewConfig = { bundle, route };
59
- routes.push({ viewConfig, module });
53
+ const viewConfig = {
54
+ bundle: `@self/${getFinalModuleName(bundle)}.js`,
55
+ route
56
+ };
57
+ routes.push({ viewConfig, module: bundle });
60
58
  });
61
59
  return routes;
62
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"automatic-utils.js","sourceRoot":"","sources":["../src/automatic-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAQxB,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACjD,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C;YAChE,MAAM,KAAK,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,IAAI,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;YAC7D,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;gBACpB,OAAO,GAAG;oBACR,KAAK;oBACL,QAAQ,EAAE,EAAE;iBACb,CAAC;gBACF,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;YACD,WAAW,GAAG,OAAO,CAAC,QAAS,CAAC;QAClC,CAAC;QAED,MAAM,KAAK,GAAG,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/D,IAAI,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;QAC9D,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,QAAQ,GAAG;gBACT,KAAK;aACN,CAAC;YACF,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;QACD,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,qBAAqB,CAAC,IAAI,GAAG,IAAI,CAAC;AACpC,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type {\n HvAppShellConfig,\n HvAppShellMenuConfig,\n HvAppShellViewsConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nfunction createLabel(str: string) {\n const noExtension = str.replace(/\\.[^/.]+$/, \"\");\n const splitByCapital = noExtension.split(/(?=[A-Z])/).join(\" \");\n return splitByCapital.charAt(0).toUpperCase() + splitByCapital.slice(1);\n}\n\n/**\n * Find all the index.tsx or index.jsx files existent at the provided path (including all the subdirectories)\n * @param dir the path to search for the index.tsx or index.jsx files\n */\nfunction findIndexFiles(dir: string): string[] {\n const files: string[] = [];\n\n fs.readdirSync(dir).forEach(file => {\n const filePath = path.join(dir, file);\n const stat = fs.statSync(filePath);\n\n if (stat.isDirectory()) {\n files.push(...findIndexFiles(filePath));\n } else if (/^index\\.[tj]sx?$/.exec(file)) {\n files.push(filePath);\n }\n });\n\n return files;\n}\n\n/**\n * Maps, through all the index files under viewsFolderPath, to a set of main views config (@see HvAppShellViewsConfig)\n * and the respective module (to be transformed to the final bundle)\n * @param root the absolute path to the views folder\n * @param viewsFolder the relative base folder where the files are included\n * @return an array of viewConfig and their correspondent module definition\n */\nexport function mapFolderIndexFilesToRoutes(\n root: string,\n viewsFolder: string\n): {\n viewConfig: HvAppShellViewsConfig;\n module: string;\n}[] {\n // the regex removes any existing '/' either at the start, at the end or in both cases of the viewsFolder parameter.\n const normalizedViewsFolder = viewsFolder.replace(/(^\\/|\\/$|)/g, \"\");\n\n const viewsFolderPath = path.resolve(root, normalizedViewsFolder);\n if (!fs.existsSync(viewsFolderPath)) {\n return [];\n }\n\n const routes: { viewConfig: HvAppShellViewsConfig; module: string }[] = [];\n const indexFiles = findIndexFiles(viewsFolderPath);\n\n indexFiles.forEach(filePath => {\n // required to work on Windows and also on Linux/macOS\n const normalizedFilePath = filePath.replaceAll(path.sep, \"/\");\n\n // fetches what is between the normalizedViewsFolder (inclusive) and the last '/' (exclusive)\n // example: 'dummy/path/src/pages/Page1/index.tsx' and 'src/pages' returns src/pages/Page1\n let bundle = normalizedFilePath.substring(\n normalizedFilePath.lastIndexOf(`/${normalizedViewsFolder}/`) + 1,\n normalizedFilePath.lastIndexOf(\"/\")\n );\n\n const route = bundle\n .replace(new RegExp(`^${normalizedViewsFolder}`), \"\")\n .replaceAll(/\\$/g, \":\")\n .toLowerCase();\n\n // module to be added when building the application\n const module = bundle;\n\n // src needs to be replaced either with '@self' (that when built is replaced by the app id)\n bundle = bundle.replace(/^(\\/?)src\\//, \"@self/\");\n bundle = bundle.replaceAll(\"$\", \"_\");\n bundle += \".js\";\n\n const viewConfig = { bundle, route };\n routes.push({ viewConfig, module });\n });\n\n return routes;\n}\n\n/**\n * Adds the automatically identified view (from the \"viewsFolder\" folder) to the AppShell configuration and calculate\n * the correspondent module to be generated\n * It guarantees that any new route will not overlap any manual defined route\n * @param config The app Shell config file\n * @param root Project root folder\n * @param viewsFolder Views folder\n * @return the array of modules to be created by the rollup mechanism\n */\nexport function applyAutomaticViewsAndRoutes(\n config: HvAppShellConfig,\n root: string,\n viewsFolder: string\n): string[] {\n const appShellConfiguration = config;\n\n const routes = mapFolderIndexFilesToRoutes(root, viewsFolder);\n if (routes.length === 0) {\n return [];\n }\n\n const views = routes.map(r => r.viewConfig);\n const modules = routes.map(r => r.module);\n\n if (\n !appShellConfiguration.mainPanel?.views ||\n appShellConfiguration.mainPanel.views.length === 0\n ) {\n if (!appShellConfiguration.mainPanel) {\n appShellConfiguration.mainPanel = { views: [] };\n }\n appShellConfiguration.mainPanel.views = views;\n return modules;\n }\n\n const nonOverlappingRoutes = routes.filter(route => {\n const exists = appShellConfiguration.mainPanel?.views?.some(\n existingView =>\n existingView.bundle === route.viewConfig.bundle ||\n existingView.route === route.viewConfig.route\n );\n if (exists) {\n console.info(\n `SKIPPED: View with bundle:[${route.viewConfig.bundle}] or route:[${route.viewConfig.route}] will not be created as their values are already used by another one.`\n );\n }\n return !exists;\n });\n\n const nonOverlappingViews = nonOverlappingRoutes.map(r => r.viewConfig);\n const nonOverlappingModules = nonOverlappingRoutes.map(r => r.module);\n\n appShellConfiguration.mainPanel.views.push(...nonOverlappingViews);\n return nonOverlappingModules;\n}\n\nexport function applyAutomaticMenu(config: HvAppShellConfig) {\n const appShellConfiguration = config;\n\n if (\n !appShellConfiguration.mainPanel?.views ||\n appShellConfiguration.mainPanel?.views.length === 0\n ) {\n return;\n }\n\n const menu: HvAppShellMenuConfig[] = [];\n\n appShellConfiguration.mainPanel?.views.forEach(view => {\n // skip dynamic routes (e.g. /list/:id))\n if (view.route.indexOf(\":\") !== -1) {\n return;\n }\n\n let currentMenu = menu;\n const bundleParts = view.bundle.split(\"/\");\n const numberOfParts = view.route\n .split(\"/\")\n .filter(part => part !== \"\").length;\n const srcFolderParts = bundleParts.length - numberOfParts;\n if (bundleParts.length <= srcFolderParts) {\n return;\n }\n for (let j = srcFolderParts; j < bundleParts.length - 1; j += 1) {\n const label = createLabel(bundleParts[j]);\n let submenu = currentMenu.find(item => item.label === label);\n if (submenu == null) {\n submenu = {\n label,\n submenus: []\n };\n currentMenu.push(submenu);\n }\n currentMenu = submenu.submenus!;\n }\n\n const label = createLabel(bundleParts[bundleParts.length - 1]);\n let menuitem = currentMenu.find(item => item.label === label);\n if (menuitem == null) {\n menuitem = {\n label\n };\n currentMenu.push(menuitem);\n }\n menuitem.target = view.route;\n });\n\n appShellConfiguration.menu = menu;\n}\n"]}
1
+ {"version":3,"file":"automatic-utils.js","sourceRoot":"","sources":["../src/automatic-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAQxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACjD,MAAM,cAAc,GAAG,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChE,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,GAAW;IACjC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,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AC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;QAC9D,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,QAAQ,GAAG;gBACT,KAAK;aACN,CAAC;YACF,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;QACD,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,qBAAqB,CAAC,IAAI,GAAG,IAAI,CAAC;AACpC,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type {\n HvAppShellConfig,\n HvAppShellMenuConfig,\n HvAppShellViewsConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport { getFinalModuleName } from \"./config-utils.js\";\n\nfunction createLabel(str: string) {\n const noExtension = str.replace(/\\.[^/.]+$/, \"\");\n const splitByCapital = noExtension.split(/(?=[A-Z])/).join(\" \");\n return splitByCapital.charAt(0).toUpperCase() + splitByCapital.slice(1);\n}\n\n/**\n * Find all the index.tsx or index.jsx files existent at the provided path (including all the subdirectories)\n * @param dir the path to search for the index.tsx or index.jsx files\n */\nfunction findIndexFiles(dir: string): string[] {\n const files: string[] = [];\n\n fs.readdirSync(dir).forEach(file => {\n const filePath = path.join(dir, file);\n const stat = fs.statSync(filePath);\n\n if (stat.isDirectory()) {\n files.push(...findIndexFiles(filePath));\n } else if (/^index\\.[tj]sx?$/.exec(file)) {\n files.push(filePath);\n }\n });\n\n return files;\n}\n\n/**\n * Maps, through all the index files under viewsFolderPath, to a set of main views config (@see HvAppShellViewsConfig)\n * and the respective module (to be transformed to the final bundle)\n * @param root the absolute path to the views folder\n * @param viewsFolder the relative base folder where the files are included\n * @return an array of viewConfig and their correspondent module definition\n */\nexport function mapFolderIndexFilesToRoutes(\n root: string,\n viewsFolder: string\n): {\n viewConfig: HvAppShellViewsConfig;\n module: string;\n}[] {\n // the regex removes any existing '/' either at the start, at the end or in both cases of the viewsFolder parameter.\n const normalizedViewsFolder = viewsFolder.replace(/(^\\/|\\/$|)/g, \"\");\n\n const viewsFolderPath = path.resolve(root, normalizedViewsFolder);\n if (!fs.existsSync(viewsFolderPath)) {\n return [];\n }\n\n const routes: { viewConfig: HvAppShellViewsConfig; module: string }[] = [];\n const indexFiles = findIndexFiles(viewsFolderPath);\n\n indexFiles.forEach(filePath => {\n // required to work on Windows and also on Linux/macOS\n const normalizedFilePath = filePath.replaceAll(path.sep, \"/\");\n\n // fetches what is between the normalizedViewsFolder (inclusive) and the last '/' (exclusive)\n // example: 'dummy/path/src/pages/Page1/index.tsx' and 'src/pages' returns src/pages/Page1\n const bundle = normalizedFilePath.substring(\n normalizedFilePath.lastIndexOf(`/${normalizedViewsFolder}/`) + 1,\n normalizedFilePath.lastIndexOf(\"/\")\n );\n\n const route = bundle\n .replace(new RegExp(`^${normalizedViewsFolder}`), \"\")\n .replaceAll(/\\$/g, \":\")\n .toLowerCase();\n\n const viewConfig = {\n bundle: `@self/${getFinalModuleName(bundle)}.js`,\n route\n };\n routes.push({ viewConfig, module: bundle });\n });\n\n return routes;\n}\n\n/**\n * Adds the automatically identified view (from the \"viewsFolder\" folder) to the AppShell configuration and calculate\n * the correspondent module to be generated\n * It guarantees that any new route will not overlap any manual defined route\n * @param config The app Shell config file\n * @param root Project root folder\n * @param viewsFolder Views folder\n * @return the array of modules to be created by the rollup mechanism\n */\nexport function applyAutomaticViewsAndRoutes(\n config: HvAppShellConfig,\n root: string,\n viewsFolder: string\n): string[] {\n const appShellConfiguration = config;\n\n const routes = mapFolderIndexFilesToRoutes(root, viewsFolder);\n if (routes.length === 0) {\n return [];\n }\n\n const views = routes.map(r => r.viewConfig);\n const modules = routes.map(r => r.module);\n\n if (\n !appShellConfiguration.mainPanel?.views ||\n appShellConfiguration.mainPanel.views.length === 0\n ) {\n if (!appShellConfiguration.mainPanel) {\n appShellConfiguration.mainPanel = { views: [] };\n }\n appShellConfiguration.mainPanel.views = views;\n return modules;\n }\n\n const nonOverlappingRoutes = routes.filter(route => {\n const exists = appShellConfiguration.mainPanel?.views?.some(\n existingView =>\n existingView.bundle === route.viewConfig.bundle ||\n existingView.route === route.viewConfig.route\n );\n if (exists) {\n console.info(\n `SKIPPED: View with bundle:[${route.viewConfig.bundle}] or route:[${route.viewConfig.route}] will not be created as their values are already used by another one.`\n );\n }\n return !exists;\n });\n\n const nonOverlappingViews = nonOverlappingRoutes.map(r => r.viewConfig);\n const nonOverlappingModules = nonOverlappingRoutes.map(r => r.module);\n\n appShellConfiguration.mainPanel.views.push(...nonOverlappingViews);\n return nonOverlappingModules;\n}\n\nexport function applyAutomaticMenu(config: HvAppShellConfig) {\n const appShellConfiguration = config;\n\n if (\n !appShellConfiguration.mainPanel?.views ||\n appShellConfiguration.mainPanel?.views.length === 0\n ) {\n return;\n }\n\n const menu: HvAppShellMenuConfig[] = [];\n\n appShellConfiguration.mainPanel?.views.forEach(view => {\n // skip dynamic routes (e.g. /list/:id))\n if (view.route.indexOf(\":\") !== -1) {\n return;\n }\n\n let currentMenu = menu;\n const bundleParts = view.bundle.split(\"/\");\n const numberOfParts = view.route\n .split(\"/\")\n .filter(part => part !== \"\").length;\n const srcFolderParts = bundleParts.length - numberOfParts;\n if (bundleParts.length <= srcFolderParts) {\n return;\n }\n for (let j = srcFolderParts; j < bundleParts.length - 1; j += 1) {\n const label = createLabel(bundleParts[j]);\n let submenu = currentMenu.find(item => item.label === label);\n if (submenu == null) {\n submenu = {\n label,\n submenus: []\n };\n currentMenu.push(submenu);\n }\n currentMenu = submenu.submenus!;\n }\n\n const label = createLabel(bundleParts[bundleParts.length - 1]);\n let menuitem = currentMenu.find(item => item.label === label);\n if (menuitem == null) {\n menuitem = {\n label\n };\n currentMenu.push(menuitem);\n }\n menuitem.target = view.route;\n });\n\n appShellConfiguration.menu = menu;\n}\n"]}
@@ -14,6 +14,14 @@ export declare function loadConfigFile(appShellConfigFile: string | undefined, o
14
14
  * @param appShellConfig The App shell configuration
15
15
  */
16
16
  export declare const getPublicPath: (appShellConfig: HvAppShellConfig) => string;
17
+ /**
18
+ * Returns the extensionless module name of the output bundle
19
+ * for a given entry point module name.
20
+ *
21
+ * @param module The entry point module name.
22
+ * @returns The final module name of the output bundle.
23
+ */
24
+ export declare function getFinalModuleName(module: string): string;
17
25
  /**
18
26
  * Returns the modules to be created by the build of the app.
19
27
  * The list of modules is provided via parameter as one of the options used to initialize AppShellVitePlugin. {@link AppShellVitePluginOptions}
@@ -21,9 +29,7 @@ export declare const getPublicPath: (appShellConfig: HvAppShellConfig) => string
21
29
  * @param root Project root directory.
22
30
  * @param modules The list of modules to be exported by the application bundle.
23
31
  */
24
- export declare function getAppModules(root: string, modules?: string[]): {
25
- [key: string]: string;
26
- };
32
+ export declare function getAppModules(root: string, modules?: string[]): Record<string, string>;
27
33
  export declare function startsWithSelf(value: string): boolean;
28
34
  export declare function replaceSelf(value: string, replaceWith?: string): string;
29
35
  //# sourceMappingURL=config-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config-utils.d.ts","sourceRoot":"","sources":["../src/config-utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAalE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,sBAAsB,GAAG,CACnC,aAAa,EAAE,yBAAyB,EACxC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACxB,gBAAgB,CAAC;AAEtB,eAAO,MAAM,oBAAoB,UAIhC,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUvE;AAED,wBAAgB,cAAc,CAC5B,kBAAkB,EAAE,MAAM,GAAG,S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EAAE,MAAM,UAMhD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,EAAO,0BAsBjE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,WAE3C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,GAAE,MAAW,UAElE"}
@@ -56,6 +56,20 @@ export const getPublicPath = (appShellConfig) => {
56
56
  return url;
57
57
  }
58
58
  };
59
+ /**
60
+ * Returns the extensionless module name of the output bundle
61
+ * for a given entry point module name.
62
+ *
63
+ * @param module The entry point module name.
64
+ * @returns The final module name of the output bundle.
65
+ */
66
+ export function getFinalModuleName(module) {
67
+ return module
68
+ .replace(/^\//, "")
69
+ .replace(/^src\//, "")
70
+ .replace(/\.[tj]sx?$/, "")
71
+ .replaceAll("$", "_");
72
+ }
59
73
  /**
60
74
  * Returns the modules to be created by the build of the app.
61
75
  * The list of modules is provided via parameter as one of the options used to initialize AppShellVitePlugin. {@link AppShellVitePluginOptions}
@@ -67,10 +81,9 @@ export function getAppModules(root, modules = []) {
67
81
  const appModules = {};
68
82
  const selfModules = modules?.map(module => {
69
83
  if (module.startsWith("src/")) {
70
- const bundleName = module.replace(/^(\/?)src\//, "");
71
84
  return {
72
85
  bundle: module,
73
- bundleName
86
+ bundleName: getFinalModuleName(module)
74
87
  };
75
88
  }
76
89
  return undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"config-utils.js","sourceRoot":"","sources":["../src/config-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAMnD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,cAAc,CACZ,QAAQ,CAAC;IACP,aAAa,EAAE,IAAI;IACnB,WAAW,EAAE;QACX,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Aa;IAC1C,OAAO,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,cAAsB,EAAE;IACjE,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport { register, createEsmHooks } from \"ts-node\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport type { AppShellVitePluginOptions } from \"./vite-plugin.js\";\n\nimport { require } from \"./nodeModule.js\";\n\ncreateEsmHooks(\n register({\n transpileOnly: true,\n moduleTypes: {\n \"app-shell.config.ts\": \"cjs\"\n }\n })\n);\n\nexport interface ConfigReplacement {\n token: string;\n value: string;\n}\n\nexport type AppShellConfigFunction = (\n pluginOptions: AppShellVitePluginOptions,\n env: Record<string, string>\n) => HvAppShellConfig;\n\nexport const DEFAULT_CONFIG_FILES = [\n \"app-shell.config.ts\",\n \"app-shell.config.js\",\n \"app-shell.config.json\"\n];\n\nexport function findAppShellConfigFile(root: string): string | undefined {\n const filename = DEFAULT_CONFIG_FILES.find(file =>\n fs.existsSync(path.resolve(root, file))\n );\n\n if (filename) {\n return path.resolve(root, filename);\n }\n\n return undefined;\n}\n\nexport function loadConfigFile(\n appShellConfigFile: string | undefined,\n opts: AppShellVitePluginOptions,\n env: Record<string, string> = {}\n): HvAppShellConfig {\n if (!appShellConfigFile) {\n // an empty configuration is actually valid\n // and with the automatic views option, it can even make sense\n return {};\n }\n\n if (appShellConfigFile.endsWith(\".json\")) {\n let appShellConfigRaw = fs.readFileSync(appShellConfigFile, \"utf-8\");\n\n // token replacement is only supported for json files\n opts.configReplacements?.forEach(item => {\n appShellConfigRaw = appShellConfigRaw.replaceAll(\n `@@${item.token}@@`,\n item.value\n );\n });\n\n return JSON.parse(appShellConfigRaw) as HvAppShellConfig;\n }\n\n // using require instead of import to avoid using --experimental-loader ts-node/esm\n // eslint-disable-next-line import/no-dynamic-require\n const loadedAppShellConfig = require(appShellConfigFile).default as\n | AppShellConfigFunction\n | HvAppShellConfig;\n\n if (typeof loadedAppShellConfig === \"function\") {\n return loadedAppShellConfig(opts, env);\n }\n\n return loadedAppShellConfig;\n}\n\n/**\n * Return the public path to be use by vite to launch the application.\n * Value is obtained by returning the baseUrl value of the main app {@link #getMainApp}\n * @param appShellConfig The App shell configuration\n */\nexport const getPublicPath = (appShellConfig: HvAppShellConfig): string => {\n const url = appShellConfig.baseUrl ?? \"/\";\n try {\n return new URL(url).pathname;\n } catch {\n return url;\n }\n};\n\n/**\n * Returns the modules to be created by the build of the app.\n * The list of modules is provided via parameter as one of the options used to initialize AppShellVitePlugin. {@link AppShellVitePluginOptions}\n *\n * @param root Project root directory.\n * @param modules The list of modules to be exported by the application bundle.\n */\nexport function getAppModules(root: string, modules: string[] = []) {\n const appModules: { [key: string]: string } = {};\n\n const selfModules =\n modules?.map(module => {\n if (module.startsWith(\"src/\")) {\n const bundleName = module.replace(/^(\\/?)src\\//, \"\");\n\n return {\n bundle: module,\n bundleName\n };\n }\n\n return undefined;\n }) ?? [];\n\n selfModules.forEach(module => {\n if (module != null && appModules[module.bundleName] == null) {\n appModules[module.bundleName] = path.resolve(root, module.bundle);\n }\n });\n\n return appModules;\n}\n\nexport function startsWithSelf(value: string) {\n return value.startsWith(\"@self/\");\n}\n\nexport function replaceSelf(value: string, replaceWith: string = \"\") {\n return value.replace(/^@self\\//, replaceWith);\n}\n"]}
1
+ {"version":3,"file":"config-utils.js","sourceRoot":"","sources":["../src/config-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAMnD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,cAAc,CACZ,QAAQ,CAAC;IACP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AAC,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC;YAC5D,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QACpE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,OAAO,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,cAAsB,EAAE;IACjE,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport { register, createEsmHooks } from \"ts-node\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport type { AppShellVitePluginOptions } from \"./vite-plugin.js\";\n\nimport { require } from \"./nodeModule.js\";\n\ncreateEsmHooks(\n register({\n transpileOnly: true,\n moduleTypes: {\n \"app-shell.config.ts\": \"cjs\"\n }\n })\n);\n\nexport interface ConfigReplacement {\n token: string;\n value: string;\n}\n\nexport type AppShellConfigFunction = (\n pluginOptions: AppShellVitePluginOptions,\n env: Record<string, string>\n) => HvAppShellConfig;\n\nexport const DEFAULT_CONFIG_FILES = [\n \"app-shell.config.ts\",\n \"app-shell.config.js\",\n \"app-shell.config.json\"\n];\n\nexport function findAppShellConfigFile(root: string): string | undefined {\n const filename = DEFAULT_CONFIG_FILES.find(file =>\n fs.existsSync(path.resolve(root, file))\n );\n\n if (filename) {\n return path.resolve(root, filename);\n }\n\n return undefined;\n}\n\nexport function loadConfigFile(\n appShellConfigFile: string | undefined,\n opts: AppShellVitePluginOptions,\n env: Record<string, string> = {}\n): HvAppShellConfig {\n if (!appShellConfigFile) {\n // an empty configuration is actually valid\n // and with the automatic views option, it can even make sense\n return {};\n }\n\n if (appShellConfigFile.endsWith(\".json\")) {\n let appShellConfigRaw = fs.readFileSync(appShellConfigFile, \"utf-8\");\n\n // token replacement is only supported for json files\n opts.configReplacements?.forEach(item => {\n appShellConfigRaw = appShellConfigRaw.replaceAll(\n `@@${item.token}@@`,\n item.value\n );\n });\n\n return JSON.parse(appShellConfigRaw) as HvAppShellConfig;\n }\n\n // using require instead of import to avoid using --experimental-loader ts-node/esm\n // eslint-disable-next-line import/no-dynamic-require\n const loadedAppShellConfig = require(appShellConfigFile).default as\n | AppShellConfigFunction\n | HvAppShellConfig;\n\n if (typeof loadedAppShellConfig === \"function\") {\n return loadedAppShellConfig(opts, env);\n }\n\n return loadedAppShellConfig;\n}\n\n/**\n * Return the public path to be use by vite to launch the application.\n * Value is obtained by returning the baseUrl value of the main app {@link #getMainApp}\n * @param appShellConfig The App shell configuration\n */\nexport const getPublicPath = (appShellConfig: HvAppShellConfig): string => {\n const url = appShellConfig.baseUrl ?? \"/\";\n try {\n return new URL(url).pathname;\n } catch {\n return url;\n }\n};\n\n/**\n * Returns the extensionless module name of the output bundle\n * for a given entry point module name.\n *\n * @param module The entry point module name.\n * @returns The final module name of the output bundle.\n */\nexport function getFinalModuleName(module: string) {\n return module\n .replace(/^\\//, \"\")\n .replace(/^src\\//, \"\")\n .replace(/\\.[tj]sx?$/, \"\")\n .replaceAll(\"$\", \"_\");\n}\n\n/**\n * Returns the modules to be created by the build of the app.\n * The list of modules is provided via parameter as one of the options used to initialize AppShellVitePlugin. {@link AppShellVitePluginOptions}\n *\n * @param root Project root directory.\n * @param modules The list of modules to be exported by the application bundle.\n */\nexport function getAppModules(root: string, modules: string[] = []) {\n const appModules: Record<string, string> = {};\n\n const selfModules =\n modules?.map(module => {\n if (module.startsWith(\"src/\")) {\n return {\n bundle: module,\n bundleName: getFinalModuleName(module)\n };\n }\n\n return undefined;\n }) ?? [];\n\n selfModules.forEach(module => {\n if (module != null && appModules[module.bundleName] == null) {\n appModules[module.bundleName] = path.resolve(root, module.bundle);\n }\n });\n\n return appModules;\n}\n\nexport function startsWithSelf(value: string) {\n return value.startsWith(\"@self/\");\n}\n\nexport function replaceSelf(value: string, replaceWith: string = \"\") {\n return value.replace(/^@self\\//, replaceWith);\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import fs from "fs";
2
- import { findAppShellConfigFile, getAppModules, getPublicPath, loadConfigFile } from "../config-utils";
2
+ import { findAppShellConfigFile, getAppModules, getFinalModuleName, getPublicPath, loadConfigFile } from "../config-utils";
3
3
  vi.mock("path", async () => vi.importActual("./mocks/path.mock.ts"));
4
4
  const existsSyncMock = vi.fn();
5
5
  const readFileSyncMock = vi.fn();
@@ -65,14 +65,64 @@ describe("test app-shell-vite-generate-base plugin", () => {
65
65
  expect(getPublicPath({ baseUrl: "/teste" })).toBe("/teste");
66
66
  });
67
67
  });
68
+ describe("getFinalModuleName", () => {
69
+ it("removes leading 'src/' and file extension from module path", () => {
70
+ const modulePath = "/src/pages/DummyPath.tsx";
71
+ const finalModuleName = getFinalModuleName(modulePath);
72
+ expect(finalModuleName).toBe("pages/DummyPath");
73
+ });
74
+ it("replaces '$' with '_' in the module path", () => {
75
+ const modulePath = "/src/pages/DummyPath/$id/HelloWorld.tsx";
76
+ const finalModuleName = getFinalModuleName(modulePath);
77
+ expect(finalModuleName).toBe("pages/DummyPath/_id/HelloWorld");
78
+ });
79
+ it("handles module paths without 'src/' prefix", () => {
80
+ // this use case is not expected to happen, but let's test it anyway
81
+ const modulePath = "/other/pages/DummyPath.tsx";
82
+ const finalModuleName = getFinalModuleName(modulePath);
83
+ expect(finalModuleName).toBe("other/pages/DummyPath");
84
+ });
85
+ it("handles module paths without file extension", () => {
86
+ const modulePath = "/src/pages/DummyPath";
87
+ const finalModuleName = getFinalModuleName(modulePath);
88
+ expect(finalModuleName).toBe("pages/DummyPath");
89
+ });
90
+ it("handles module paths with '.ts' file extension", () => {
91
+ const modulePath = "/src/pages/DummyPath.ts";
92
+ const finalModuleName = getFinalModuleName(modulePath);
93
+ expect(finalModuleName).toBe("pages/DummyPath");
94
+ });
95
+ it("handles module paths with '.jsx' file extension", () => {
96
+ const modulePath = "/src/pages/DummyPath.jsx";
97
+ const finalModuleName = getFinalModuleName(modulePath);
98
+ expect(finalModuleName).toBe("pages/DummyPath");
99
+ });
100
+ it("handles module paths with '.tsx' file extension", () => {
101
+ const modulePath = "/src/pages/DummyPath.tsx";
102
+ const finalModuleName = getFinalModuleName(modulePath);
103
+ expect(finalModuleName).toBe("pages/DummyPath");
104
+ });
105
+ });
68
106
  describe("getAppModules", () => {
69
107
  it("modules are correctly mapped", () => {
70
108
  expect(getAppModules("dummyPath", [
71
109
  "src/pages/DummyPath",
72
- "src/pages/DummyPath-2"
73
- ])).toMatchObject({
110
+ "src/pages/DummyPath-2",
111
+ "src/pages/DummyPath/$id/HelloWorld",
112
+ "src/modules/DummyModule1",
113
+ "src/modules/DummyModule2.ts",
114
+ "src/modules/DummyModule3.tsx",
115
+ "src/modules/DummyModule4.js",
116
+ "src/modules/DummyModule5.jsx"
117
+ ])).toEqual({
74
118
  "pages/DummyPath": "dummyPath/src/pages/DummyPath",
75
- "pages/DummyPath-2": "dummyPath/src/pages/DummyPath-2"
119
+ "pages/DummyPath-2": "dummyPath/src/pages/DummyPath-2",
120
+ "pages/DummyPath/_id/HelloWorld": "dummyPath/src/pages/DummyPath/$id/HelloWorld",
121
+ "modules/DummyModule1": "dummyPath/src/modules/DummyModule1",
122
+ "modules/DummyModule2": "dummyPath/src/modules/DummyModule2.ts",
123
+ "modules/DummyModule3": "dummyPath/src/modules/DummyModule3.tsx",
124
+ "modules/DummyModule4": "dummyPath/src/modules/DummyModule4.js",
125
+ "modules/DummyModule5": "dummyPath/src/modules/DummyModule5.jsx"
76
126
  });
77
127
  });
78
128
  it("removes modules that are not defined at src folder", () => {
@@ -80,7 +130,7 @@ describe("test app-shell-vite-generate-base plugin", () => {
80
130
  "src/pages/DummyPath",
81
131
  "dummySrc/pages/DummyPath-2",
82
132
  "src/pages/DummyPath-3"
83
- ])).toMatchObject({
133
+ ])).toEqual({
84
134
  "pages/DummyPath": "dummyPath/src/pages/DummyPath",
85
135
  "pages/DummyPath-3": "dummyPath/src/pages/DummyPath-3"
86
136
  });
@@ -1 +1 @@
1
- {"version":3,"file":"config-utils.test.js","sourceRoot":"","sources":["../../src/tests/config-utils.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,cAAc,EACf,MAAM,iBAAiB,CAAC;AAEzB,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAC,CAAC;AAErE,MAAM,cAAc,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;AAC/B,MAAM,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;AACjC,EAAE,CAAC,UAAU,GAAG,cAAc,CAAC;AAC/B,EAAE,CAAC,YAAY,GAAG,gBAAgB,CAAC;AACnC,QAAQ,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACxD,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;QAC7C,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACzE,cAAc,CAAC,kBAAkB,CAAC,CAAC,IAAY,EAAE,EAAE;gBACjD,OAAO,IAAI,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;YACzE,CAAC,CAAC,CAAC;YACH,MAAM,QAAQ,GAAG,sBAAsB,CAAC,6BAA6B,CAAC,CAAC;YACvE,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CACnB,mDAAmD,CACpD,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;YAC1D,cAAc,CAAC,kBAAkB,CAAC,GAAG,EAAE;gBACrC,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,CA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CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\nimport fs from \"fs\";\nimport {\n findAppShellConfigFile,\n getAppModules,\n getPublicPath,\n loadConfigFile\n} from \"../config-utils\";\n\nvi.mock(\"path\", async () => vi.importActual(\"./mocks/path.mock.ts\"));\n\nconst existsSyncMock = vi.fn();\nconst readFileSyncMock = vi.fn();\nfs.existsSync = existsSyncMock;\nfs.readFileSync = readFileSyncMock;\ndescribe(\"test app-shell-vite-generate-base plugin\", () => {\n describe(\"test `findAppShellConfigFile`\", () => {\n it(\"it returns the config file location (and its content) if exists\", () => {\n existsSyncMock.mockImplementation((file: string) => {\n return file.match(\"/dummyPath/dummyRootProject/app-shell.config.json\");\n });\n const filePath = findAppShellConfigFile(\"/dummyPath/dummyRootProject\");\n expect(filePath).toBe(\n \"/dummyPath/dummyRootProject/app-shell.config.json\"\n );\n });\n\n it(\"it returns undefined if config file don't exists\", () => {\n existsSyncMock.mockImplementation(() => {\n return false;\n });\n const filePath = findAppShellConfigFile(\"/dummyPath/dummyRootProject\");\n expect(filePath).toBeUndefined();\n });\n });\n\n describe(\"test `loadConfigFile`\", () => {\n it(\"returns an empty config if the config file is not defined\", () => {\n const appShellConfig = loadConfigFile(undefined, {}, {});\n expect(appShellConfig).toMatchObject({});\n });\n\n it(\"returns the config if config file exists\", () => {\n const config: HvAppShellConfig = {\n baseUrl: \"dummyBaseUrl\"\n };\n\n existsSyncMock.mockImplementation((file: string) => {\n return file.match(\"/dummyPath/dummyRootProject/app-shell.config.json\");\n });\n\n readFileSyncMock.mockImplementation(() => {\n return JSON.stringify(config);\n });\n\n const appShellConfig = loadConfigFile(\n \"/dummyPath/dummyRootProject/app-shell.config.json\",\n {},\n {}\n );\n expect(appShellConfig).toMatchObject(config);\n });\n\n it(\"replaces tokens at configurations defined at json files\", () => {\n const config: HvAppShellConfig = {\n baseUrl: \"@@BASE_URL@@\"\n };\n\n existsSyncMock.mockImplementation((file: string) => {\n return file.match(\"/dummyPath/dummyRootProject/app-shell.config.json\");\n });\n\n readFileSyncMock.mockImplementation(() => {\n return JSON.stringify(config);\n });\n\n const appShellConfig = loadConfigFile(\n \"/dummyPath/dummyRootProject/app-shell.config.json\",\n {\n configReplacements: [\n { token: \"BASE_URL\", value: \"dummyBaseUrlWithTokens\" }\n ]\n },\n {}\n );\n expect(appShellConfig).toMatchObject({\n baseUrl: \"dummyBaseUrlWithTokens\"\n });\n });\n });\n\n describe(\"getPublicPath\", () => {\n it(\"getPublicPath\", () => {\n expect(getPublicPath({ baseUrl: \"/teste\" })).toBe(\"/teste\");\n });\n });\n\n describe(\"getAppModules\", () => {\n it(\"modules are correctly mapped\", () => {\n expect(\n getAppModules(\"dummyPath\", [\n \"src/pages/DummyPath\",\n \"src/pages/DummyPath-2\"\n ])\n ).toMatchObject({\n \"pages/DummyPath\": \"dummyPath/src/pages/DummyPath\",\n \"pages/DummyPath-2\": \"dummyPath/src/pages/DummyPath-2\"\n });\n });\n\n it(\"removes modules that are not defined at src folder\", () => {\n expect(\n getAppModules(\"dummyPath\", [\n \"src/pages/DummyPath\",\n \"dummySrc/pages/DummyPath-2\",\n \"src/pages/DummyPath-3\"\n ])\n ).toMatchObject({\n \"pages/DummyPath\": \"dummyPath/src/pages/DummyPath\",\n \"pages/DummyPath-3\": \"dummyPath/src/pages/DummyPath-3\"\n });\n });\n });\n});\n"]}
1
+ {"version":3,"file":"config-utils.test.js","sourceRoot":"","sources":["../../src/tests/config-utils.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,cAAc,EACf,MAAM,iBAAiB,CAAC;AAEzB,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAC,CAAC;AAErE,MAAM,c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CAAC,CAAC;QAEH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;YAC5D,MAAM,CACJ,aAAa,CAAC,WAAW,EAAE;gBACzB,qBAAqB;gBACrB,4BAA4B;gBAC5B,uBAAuB;aACxB,CAAC,CACH,CAAC,OAAO,CAAC;gBACR,iBAAiB,EAAE,+BAA+B;gBAClD,mBAAmB,EAAE,iCAAiC;aACvD,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\nimport fs from \"fs\";\nimport {\n findAppShellConfigFile,\n getAppModules,\n getFinalModuleName,\n getPublicPath,\n loadConfigFile\n} from \"../config-utils\";\n\nvi.mock(\"path\", async () => vi.importActual(\"./mocks/path.mock.ts\"));\n\nconst existsSyncMock = vi.fn();\nconst readFileSyncMock = vi.fn();\nfs.existsSync = existsSyncMock;\nfs.readFileSync = readFileSyncMock;\ndescribe(\"test app-shell-vite-generate-base plugin\", () => {\n describe(\"test `findAppShellConfigFile`\", () => {\n it(\"it returns the config file location (and its content) if exists\", () => {\n existsSyncMock.mockImplementation((file: string) => {\n return file.match(\"/dummyPath/dummyRootProject/app-shell.config.json\");\n });\n const filePath = findAppShellConfigFile(\"/dummyPath/dummyRootProject\");\n expect(filePath).toBe(\n \"/dummyPath/dummyRootProject/app-shell.config.json\"\n );\n });\n\n it(\"it returns undefined if config file don't exists\", () => {\n existsSyncMock.mockImplementation(() => {\n return false;\n });\n const filePath = findAppShellConfigFile(\"/dummyPath/dummyRootProject\");\n expect(filePath).toBeUndefined();\n });\n });\n\n describe(\"test `loadConfigFile`\", () => {\n it(\"returns an empty config if the config file is not defined\", () => {\n const appShellConfig = loadConfigFile(undefined, {}, {});\n expect(appShellConfig).toMatchObject({});\n });\n\n it(\"returns the config if config file exists\", () => {\n const config: HvAppShellConfig = {\n baseUrl: \"dummyBaseUrl\"\n };\n\n existsSyncMock.mockImplementation((file: string) => {\n return file.match(\"/dummyPath/dummyRootProject/app-shell.config.json\");\n });\n\n readFileSyncMock.mockImplementation(() => {\n return JSON.stringify(config);\n });\n\n const appShellConfig = loadConfigFile(\n \"/dummyPath/dummyRootProject/app-shell.config.json\",\n {},\n {}\n );\n expect(appShellConfig).toMatchObject(config);\n });\n\n it(\"replaces tokens at configurations defined at json files\", () => {\n const config: HvAppShellConfig = {\n baseUrl: \"@@BASE_URL@@\"\n };\n\n existsSyncMock.mockImplementation((file: string) => {\n return file.match(\"/dummyPath/dummyRootProject/app-shell.config.json\");\n });\n\n readFileSyncMock.mockImplementation(() => {\n return JSON.stringify(config);\n });\n\n const appShellConfig = loadConfigFile(\n \"/dummyPath/dummyRootProject/app-shell.config.json\",\n {\n configReplacements: [\n { token: \"BASE_URL\", value: \"dummyBaseUrlWithTokens\" }\n ]\n },\n {}\n );\n expect(appShellConfig).toMatchObject({\n baseUrl: \"dummyBaseUrlWithTokens\"\n });\n });\n });\n\n describe(\"getPublicPath\", () => {\n it(\"getPublicPath\", () => {\n expect(getPublicPath({ baseUrl: \"/teste\" })).toBe(\"/teste\");\n });\n });\n\n describe(\"getFinalModuleName\", () => {\n it(\"removes leading 'src/' and file extension from module path\", () => {\n const modulePath = \"/src/pages/DummyPath.tsx\";\n const finalModuleName = getFinalModuleName(modulePath);\n expect(finalModuleName).toBe(\"pages/DummyPath\");\n });\n\n it(\"replaces '$' with '_' in the module path\", () => {\n const modulePath = \"/src/pages/DummyPath/$id/HelloWorld.tsx\";\n const finalModuleName = getFinalModuleName(modulePath);\n expect(finalModuleName).toBe(\"pages/DummyPath/_id/HelloWorld\");\n });\n\n it(\"handles module paths without 'src/' prefix\", () => {\n // this use case is not expected to happen, but let's test it anyway\n\n const modulePath = \"/other/pages/DummyPath.tsx\";\n const finalModuleName = getFinalModuleName(modulePath);\n expect(finalModuleName).toBe(\"other/pages/DummyPath\");\n });\n\n it(\"handles module paths without file extension\", () => {\n const modulePath = \"/src/pages/DummyPath\";\n const finalModuleName = getFinalModuleName(modulePath);\n expect(finalModuleName).toBe(\"pages/DummyPath\");\n });\n\n it(\"handles module paths with '.ts' file extension\", () => {\n const modulePath = \"/src/pages/DummyPath.ts\";\n const finalModuleName = getFinalModuleName(modulePath);\n expect(finalModuleName).toBe(\"pages/DummyPath\");\n });\n\n it(\"handles module paths with '.jsx' file extension\", () => {\n const modulePath = \"/src/pages/DummyPath.jsx\";\n const finalModuleName = getFinalModuleName(modulePath);\n expect(finalModuleName).toBe(\"pages/DummyPath\");\n });\n\n it(\"handles module paths with '.tsx' file extension\", () => {\n const modulePath = \"/src/pages/DummyPath.tsx\";\n const finalModuleName = getFinalModuleName(modulePath);\n expect(finalModuleName).toBe(\"pages/DummyPath\");\n });\n });\n\n describe(\"getAppModules\", () => {\n it(\"modules are correctly mapped\", () => {\n expect(\n getAppModules(\"dummyPath\", [\n \"src/pages/DummyPath\",\n \"src/pages/DummyPath-2\",\n \"src/pages/DummyPath/$id/HelloWorld\",\n \"src/modules/DummyModule1\",\n \"src/modules/DummyModule2.ts\",\n \"src/modules/DummyModule3.tsx\",\n \"src/modules/DummyModule4.js\",\n \"src/modules/DummyModule5.jsx\"\n ])\n ).toEqual({\n \"pages/DummyPath\": \"dummyPath/src/pages/DummyPath\",\n \"pages/DummyPath-2\": \"dummyPath/src/pages/DummyPath-2\",\n \"pages/DummyPath/_id/HelloWorld\":\n \"dummyPath/src/pages/DummyPath/$id/HelloWorld\",\n \"modules/DummyModule1\": \"dummyPath/src/modules/DummyModule1\",\n \"modules/DummyModule2\": \"dummyPath/src/modules/DummyModule2.ts\",\n \"modules/DummyModule3\": \"dummyPath/src/modules/DummyModule3.tsx\",\n \"modules/DummyModule4\": \"dummyPath/src/modules/DummyModule4.js\",\n \"modules/DummyModule5\": \"dummyPath/src/modules/DummyModule5.jsx\"\n });\n });\n\n it(\"removes modules that are not defined at src folder\", () => {\n expect(\n getAppModules(\"dummyPath\", [\n \"src/pages/DummyPath\",\n \"dummySrc/pages/DummyPath-2\",\n \"src/pages/DummyPath-3\"\n ])\n ).toEqual({\n \"pages/DummyPath\": \"dummyPath/src/pages/DummyPath\",\n \"pages/DummyPath-3\": \"dummyPath/src/pages/DummyPath-3\"\n });\n });\n });\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"vite-configuration-processor-plugin.d.ts","sourceRoot":"","sources":["../src/vite-configuration-processor-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,MAAM,CAAC;AAGrD,OAAO,KAAK,EACV,gBAAgB,EAIjB,MAAM,kCAAkC,CAAC;AAgC1C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,gBAAgB,EAChC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,OAAO,EACxB,YAAY,EAAE,OAAO,EACrB,kBAAkB,EAAE,OAAO,EAC3B,OAAO,GAAE,MAAM,EAAO,GACrB,YAAY,CAwId"}
1
+ {"version":3,"file":"vite-configuration-processor-plugin.d.ts","sourceRoot":"","sources":["../src/vite-configuration-processor-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,MAAM,CAAC;AAGrD,OAAO,KAAK,EACV,gBAAgB,EAIjB,MAAM,kCAAkC,CAAC;AAgC1C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,gBAAgB,EAChC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,OAAO,EACxB,YAAY,EAAE,OAAO,EACrB,kBAAkB,EAAE,OAAO,EAC3B,OAAO,GAAE,MAAM,EAAO,GACrB,YAAY,CAiJd"}
@@ -38,7 +38,10 @@ export default function processConfiguration(root, appShellConfig, selfAppName,
38
38
  let appModules = {};
39
39
  if (!generateEmptyShell) {
40
40
  appModules = getAppModules(projectRoot, modules);
41
- console.info("Modules exported by the application bundle:", appModules);
41
+ console.info("Modules exported by the application bundle:", Object.entries(appModules).reduce((acc, [key, value]) => {
42
+ acc[`${selfAppName}/${key}.js`] = value;
43
+ return acc;
44
+ }, {}));
42
45
  }
43
46
  return {
44
47
  build: {
@@ -1 +1 @@
1
- {"version":3,"file":"vite-configuration-processor-plugin.js","sourceRoot":"","sources":["../src/vite-configuration-processor-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAYxB,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B,IAAK,WAGJ;AAHD,WAAK,WAAW;IACd,8BAAe,CAAA;IACf,8BAAe,CAAA;AACjB,CAAC,EAHI,WAAW,KAAX,WAAW,QAGf;AAOD,SAAS,uBAAuB,CAC9B,OAA2B,EAC3B,WAAmB;IAEnB,OAAO,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE;QACpC,IAAI,cAAc,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5C,MAAM,UAAU,GAAG,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;YACxD,OAAO,EAAE,GAAG,gBAAgB,EAAE,MAAM,EAAE,GAAG,WAAW,IAAI,UAAU,EAAE,EAAE,CAAC;QACzE,CAAC;QACD,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,IAAY,EACZ,cAAgC,EAChC,WAAmB,EACnB,eAAwB,EACxB,YAAqB,EACrB,kBAA2B,EAC3B,UAAoB,EAAE;IAEtB,IAAI,mBAAqC,CAAC;IAE1C,OAAO;QACL,IAAI,EAAE,8CAA8C;QAEpD,MAAM,CAAC,MAAkB,EAAE,EAAE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mB,CAAC,MAAM,EAAE,OAAO,IAAI,IAAI,EAAE,CAAC;gBAChD,mBAAmB,CAAC,MAAM,CAAC,OAAO,GAAG,uBAAuB,CAC1D,mBAAmB,CAAC,MAAM,EAAE,OAAO,EACnC,WAAW,CACZ,CAAC;YACJ,CAAC;YAED,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAChD,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,CAAC;YACJ,CAAC;QACH,CAAC;QAED,kBAAkB,EAAE;YAClB,OAAO,EAAE,IAAI,CAAC,EAAE;gBACd,IAAI,CAAC,YAAY,EAAE,CAAC;oBAClB,OAAO,SAAS,CAAC;gBACnB,CAAC;gBAED,OAAO;oBACL,IAAI;oBAEJ,IAAI,EAAE;wBACJ;4BACE,GAAG,EAAE,QAAQ;4BACb,QAAQ,EAAE,cAAc;4BACxB,QAAQ,EAAE,oCACR,kBAAkB;gCAChB,CAAC,CAAC,qBAAqB;gCACvB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,mBAAmB,IAAI,cAAc,CAC1D,GAAG;yBACJ;qBACF;iBACF,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type { PluginOption, UserConfig } from \"vite\";\nimport type { NormalizedOutputOptions } from \"rollup\";\n\nimport type {\n HvAppShellConfig,\n HvAppShellHeaderAction,\n HvAppShellProvidersConfig,\n HvAppShellViewsConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport {\n getAppModules,\n getPublicPath,\n replaceSelf,\n startsWithSelf\n} from \"./config-utils.js\";\n\nenum ViteCommand {\n BUILD = \"build\",\n SERVE = \"serve\"\n}\n\ntype BundleDefinition =\n | HvAppShellProvidersConfig\n | HvAppShellViewsConfig\n | HvAppShellHeaderAction;\n\nfunction replaceReferencesToSelf(\n bundles: BundleDefinition[],\n selfAppName: string\n) {\n return bundles.map(bundleDefinition => {\n if (startsWithSelf(bundleDefinition.bundle)) {\n const bundleName = replaceSelf(bundleDefinition.bundle);\n return { ...bundleDefinition, bundle: `${selfAppName}/${bundleName}` };\n }\n return bundleDefinition;\n });\n}\n\n/**\n * Process configuration, executing several tasks:\n * - Create rollup configuration to support module creation\n * - Generates final transformed configuration json\n * - \"base\" value is always \"./\" for build, and main app baseUrl for preview or dev\n * @param root Project root directory.\n * @param appShellConfig The original App Shell configuration json.\n * @param selfAppName The name of the application bundle being built.\n * @param buildEntryPoint If true, the index.html entry point will be added to the bundle.\n * @param inlineConfig flag to control if config is included at index.html\n * @param generateEmptyShell flag to control if we are creating an empty AppShell instance\n * @param modules the set of modules to be created by the rollup\n */\nexport default function processConfiguration(\n root: string,\n appShellConfig: HvAppShellConfig,\n selfAppName: string,\n buildEntryPoint: boolean,\n inlineConfig: boolean,\n generateEmptyShell: boolean,\n modules: string[] = []\n): PluginOption {\n let finalAppShellConfig: HvAppShellConfig;\n\n return {\n name: \"vite-plugin-appShell-configuration-processor\",\n\n config(config: UserConfig, { command }) {\n const projectRoot = root ?? config.root;\n\n const publicPath = getPublicPath(appShellConfig);\n let appModules = {};\n if (!generateEmptyShell) {\n appModules = getAppModules(projectRoot, modules);\n console.info(\"Modules exported by the application bundle:\", appModules);\n }\n\n return {\n build: {\n rollupOptions: {\n preserveEntrySignatures: \"strict\",\n input: {\n ...(buildEntryPoint &&\n fs.existsSync(path.resolve(projectRoot, \"index.html\"))\n ? { main: path.resolve(projectRoot, \"index.html\") }\n : {}),\n ...appModules\n },\n output: {\n entryFileNames: \"[name].js\"\n }\n }\n },\n // if serve (preview/dev) it uses the baseUrl. Otherwise(build), use ./\n base: command === ViteCommand.SERVE ? publicPath : \"./\"\n };\n },\n\n /**\n * Rollup hook with the info for bundle generation\n * It will be used to create a new configuration with:\n * - bundles replace with the final location (e.g. -> \"bundle\": \"src/pages/Main\" transformed to \"bundle\": \"pages/Main.js\",\n * @param options build options\n */\n async generateBundle(options: NormalizedOutputOptions) {\n if (generateEmptyShell || !buildEntryPoint) {\n return;\n }\n\n // obtain the directory (dist) where the new config file will be placed\n let targetDir: string | undefined;\n if (options.dir) {\n targetDir = options.dir;\n } else if (options.file) {\n targetDir = path.dirname(options.file);\n }\n\n if (!targetDir) {\n throw new Error(\n \"Please set outputPath, so we can know where to place the json file\"\n );\n }\n\n // create the targetDir if it does not exist\n if (!fs.existsSync(targetDir)) {\n fs.mkdirSync(targetDir, { recursive: true });\n }\n\n // theming structure does not rely on having the 'bundle' prop\n const { theming } = appShellConfig;\n if (theming != null) {\n theming.themes = theming.themes?.map(theme => {\n if (startsWithSelf(theme)) {\n const bundleName = replaceSelf(theme);\n return `${selfAppName}/${bundleName}`;\n }\n\n return theme;\n });\n }\n\n finalAppShellConfig = { ...appShellConfig };\n finalAppShellConfig.apps = undefined;\n // also replace implicit references to selfApp in other parts of the configuration\n if (finalAppShellConfig.providers != null) {\n finalAppShellConfig.providers = replaceReferencesToSelf(\n finalAppShellConfig.providers,\n selfAppName\n );\n }\n\n if (finalAppShellConfig.mainPanel?.views != null) {\n finalAppShellConfig.mainPanel.views = replaceReferencesToSelf(\n finalAppShellConfig.mainPanel.views,\n selfAppName\n ) as HvAppShellViewsConfig[];\n }\n\n if (finalAppShellConfig.header?.actions != null) {\n finalAppShellConfig.header.actions = replaceReferencesToSelf(\n finalAppShellConfig.header?.actions,\n selfAppName\n );\n }\n\n if (!inlineConfig) {\n fs.writeFileSync(\n path.resolve(targetDir, \"app-shell.config.json\"),\n JSON.stringify(finalAppShellConfig)\n );\n }\n },\n\n transformIndexHtml: {\n handler: html => {\n if (!inlineConfig) {\n return undefined;\n }\n\n return {\n html,\n\n tags: [\n {\n tag: \"script\",\n injectTo: \"head-prepend\",\n children: `globalThis.__appshell_config__ = ${\n generateEmptyShell\n ? \"%%APPSHELL_CONFIG%%\"\n : JSON.stringify(finalAppShellConfig ?? appShellConfig)\n };`\n }\n ]\n };\n }\n }\n };\n}\n"]}
1
+ {"version":3,"file":"vite-configuration-processor-plugin.js","sourceRoot":"","sources":["../src/vite-configuration-processor-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAYxB,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B,IAAK,WAGJ;AAHD,WAAK,WAAW;IACd,8BAAe,CAAA;IACf,8BAAe,CAAA;AACjB,CAAC,EAHI,WAAW,KAAX,WAAW,QAGf;AAOD,SAAS,uBAAuB,CAC9B,OAA2B,EAC3B,WAAmB;IAEnB,OAAO,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE;QACpC,IAAI,cAAc,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5C,MAAM,UAAU,GAAG,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;YACxD,OAAO,EAAE,GAAG,gBAAgB,EAAE,MAAM,EAAE,GAAG,WAAW,IAAI,UAAU,EAAE,EAAE,CAAC;QACzE,CAAC;QACD,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,IAAY,EACZ,cAAgC,EAChC,WAAmB,EACnB,eAAwB,EACxB,YAAqB,EACrB,kBAA2B,EAC3B,UAAoB,EAAE;IAEtB,IAAI,mBAAqC,CAAC;IAE1C,OAAO;QACL,IAAI,EAAE,8CAA8C;QAEpD,MAAM,CAAC,MAAkB,EAAE,EAAE,OAAO,EAAE;YACpC,MAAM,WAAW,GAAG,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC;YAExC,MAAM,UAAU,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;YACjD,IAAI,UAAU,GAA2B,EAAE,CAAC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CAAC,SAAS,CAAC,KAAK,EACnC,WAAW,CACe,CAAC;YAC/B,CAAC;YAED,IAAI,mBAAmB,CAAC,MAAM,EAAE,OAAO,IAAI,IAAI,EAAE,CAAC;gBAChD,mBAAmB,CAAC,MAAM,CAAC,OAAO,GAAG,uBAAuB,CAC1D,mBAAmB,CAAC,MAAM,EAAE,OAAO,EACnC,WAAW,CACZ,CAAC;YACJ,CAAC;YAED,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAChD,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,CAAC;YACJ,CAAC;QACH,CAAC;QAED,kBAAkB,EAAE;YAClB,OAAO,EAAE,IAAI,CAAC,EAAE;gBACd,IAAI,CAAC,YAAY,EAAE,CAAC;oBAClB,OAAO,SAAS,CAAC;gBACnB,CAAC;gBAED,OAAO;oBACL,IAAI;oBAEJ,IAAI,EAAE;wBACJ;4BACE,GAAG,EAAE,QAAQ;4BACb,QAAQ,EAAE,cAAc;4BACxB,QAAQ,EAAE,oCACR,kBAAkB;gCAChB,CAAC,CAAC,qBAAqB;gCACvB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,mBAAmB,IAAI,cAAc,CAC1D,GAAG;yBACJ;qBACF;iBACF,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type { PluginOption, UserConfig } from \"vite\";\nimport type { NormalizedOutputOptions } from \"rollup\";\n\nimport type {\n HvAppShellConfig,\n HvAppShellHeaderAction,\n HvAppShellProvidersConfig,\n HvAppShellViewsConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport {\n getAppModules,\n getPublicPath,\n replaceSelf,\n startsWithSelf\n} from \"./config-utils.js\";\n\nenum ViteCommand {\n BUILD = \"build\",\n SERVE = \"serve\"\n}\n\ntype BundleDefinition =\n | HvAppShellProvidersConfig\n | HvAppShellViewsConfig\n | HvAppShellHeaderAction;\n\nfunction replaceReferencesToSelf(\n bundles: BundleDefinition[],\n selfAppName: string\n) {\n return bundles.map(bundleDefinition => {\n if (startsWithSelf(bundleDefinition.bundle)) {\n const bundleName = replaceSelf(bundleDefinition.bundle);\n return { ...bundleDefinition, bundle: `${selfAppName}/${bundleName}` };\n }\n return bundleDefinition;\n });\n}\n\n/**\n * Process configuration, executing several tasks:\n * - Create rollup configuration to support module creation\n * - Generates final transformed configuration json\n * - \"base\" value is always \"./\" for build, and main app baseUrl for preview or dev\n * @param root Project root directory.\n * @param appShellConfig The original App Shell configuration json.\n * @param selfAppName The name of the application bundle being built.\n * @param buildEntryPoint If true, the index.html entry point will be added to the bundle.\n * @param inlineConfig flag to control if config is included at index.html\n * @param generateEmptyShell flag to control if we are creating an empty AppShell instance\n * @param modules the set of modules to be created by the rollup\n */\nexport default function processConfiguration(\n root: string,\n appShellConfig: HvAppShellConfig,\n selfAppName: string,\n buildEntryPoint: boolean,\n inlineConfig: boolean,\n generateEmptyShell: boolean,\n modules: string[] = []\n): PluginOption {\n let finalAppShellConfig: HvAppShellConfig;\n\n return {\n name: \"vite-plugin-appShell-configuration-processor\",\n\n config(config: UserConfig, { command }) {\n const projectRoot = root ?? config.root;\n\n const publicPath = getPublicPath(appShellConfig);\n let appModules: Record<string, string> = {};\n if (!generateEmptyShell) {\n appModules = getAppModules(projectRoot, modules);\n console.info(\n \"Modules exported by the application bundle:\",\n Object.entries(appModules).reduce(\n (acc, [key, value]) => {\n acc[`${selfAppName}/${key}.js`] = value;\n return acc;\n },\n {} as Record<string, string>\n )\n );\n }\n\n return {\n build: {\n rollupOptions: {\n preserveEntrySignatures: \"strict\",\n input: {\n ...(buildEntryPoint &&\n fs.existsSync(path.resolve(projectRoot, \"index.html\"))\n ? { main: path.resolve(projectRoot, \"index.html\") }\n : {}),\n ...appModules\n },\n output: {\n entryFileNames: \"[name].js\"\n }\n }\n },\n // if serve (preview/dev) it uses the baseUrl. Otherwise(build), use ./\n base: command === ViteCommand.SERVE ? publicPath : \"./\"\n };\n },\n\n /**\n * Rollup hook with the info for bundle generation\n * It will be used to create a new configuration with:\n * - bundles replace with the final location (e.g. -> \"bundle\": \"src/pages/Main\" transformed to \"bundle\": \"pages/Main.js\",\n * @param options build options\n */\n async generateBundle(options: NormalizedOutputOptions) {\n if (generateEmptyShell || !buildEntryPoint) {\n return;\n }\n\n // obtain the directory (dist) where the new config file will be placed\n let targetDir: string | undefined;\n if (options.dir) {\n targetDir = options.dir;\n } else if (options.file) {\n targetDir = path.dirname(options.file);\n }\n\n if (!targetDir) {\n throw new Error(\n \"Please set outputPath, so we can know where to place the json file\"\n );\n }\n\n // create the targetDir if it does not exist\n if (!fs.existsSync(targetDir)) {\n fs.mkdirSync(targetDir, { recursive: true });\n }\n\n // theming structure does not rely on having the 'bundle' prop\n const { theming } = appShellConfig;\n if (theming != null) {\n theming.themes = theming.themes?.map(theme => {\n if (startsWithSelf(theme)) {\n const bundleName = replaceSelf(theme);\n return `${selfAppName}/${bundleName}`;\n }\n\n return theme;\n });\n }\n\n finalAppShellConfig = { ...appShellConfig };\n finalAppShellConfig.apps = undefined;\n // also replace implicit references to selfApp in other parts of the configuration\n if (finalAppShellConfig.providers != null) {\n finalAppShellConfig.providers = replaceReferencesToSelf(\n finalAppShellConfig.providers,\n selfAppName\n );\n }\n\n if (finalAppShellConfig.mainPanel?.views != null) {\n finalAppShellConfig.mainPanel.views = replaceReferencesToSelf(\n finalAppShellConfig.mainPanel.views,\n selfAppName\n ) as HvAppShellViewsConfig[];\n }\n\n if (finalAppShellConfig.header?.actions != null) {\n finalAppShellConfig.header.actions = replaceReferencesToSelf(\n finalAppShellConfig.header?.actions,\n selfAppName\n );\n }\n\n if (!inlineConfig) {\n fs.writeFileSync(\n path.resolve(targetDir, \"app-shell.config.json\"),\n JSON.stringify(finalAppShellConfig)\n );\n }\n },\n\n transformIndexHtml: {\n handler: html => {\n if (!inlineConfig) {\n return undefined;\n }\n\n return {\n html,\n\n tags: [\n {\n tag: \"script\",\n injectTo: \"head-prepend\",\n children: `globalThis.__appshell_config__ = ${\n generateEmptyShell\n ? \"%%APPSHELL_CONFIG%%\"\n : JSON.stringify(finalAppShellConfig ?? appShellConfig)\n };`\n }\n ]\n };\n }\n }\n };\n}\n"]}
@@ -48,7 +48,7 @@ export interface AppShellVitePluginOptions {
48
48
  autoViewsAndRoutes?: boolean;
49
49
  /**
50
50
  * If true, the plugin will try to automatically add the views to the menu.
51
- * This is only valid if the app-shell.config.json file does not contain any menu configuration already.
51
+ * Any menu defined in the App Shell config file will be overwritten.
52
52
  */
53
53
  autoMenu?: boolean;
54
54
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,YAAY,EAAE,MAAM,MAAM,CAAC;AAa7C,OAAO,EACL,iBAAiB,EAGlB,MAAM,mBAAmB,CAAC;AAc3B,MAAM,MAAM,qBAAqB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAErD,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,qBAAqB,CAAC;IAE7B;;;;;;;;;;;OAWG;IACH,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEzC;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;;;;;OA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AAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,YAAY,CA2Kd;AAED,eAAe,kBAAkB,CAAC"}
@@ -9,7 +9,7 @@ import generateBaseTag from "./vite-generate-base-plugin.js";
9
9
  import injectMetadata from "./vite-metadata-plugin.js";
10
10
  import serveAppShellConfig from "./vite-watch-config-plugin.js";
11
11
  import generateBashScript from "./vite-generate-bash-script-plugin.js";
12
- import { findAppShellConfigFile, loadConfigFile } from "./config-utils.js";
12
+ import { findAppShellConfigFile, getFinalModuleName, loadConfigFile } from "./config-utils.js";
13
13
  import { getModulePath, resolveModule } from "./nodeModule.js";
14
14
  import { applyAutomaticMenu, applyAutomaticViewsAndRoutes } from "./automatic-utils.js";
15
15
  import getVirtualEntrypoints from "./virtual-entrypoints.js";
@@ -95,12 +95,10 @@ function appShellVitePlugin(opts = {}, env = {}) {
95
95
  acc[`${key}/`] = value;
96
96
  return acc;
97
97
  }, {}),
98
- [`${packageJson.name}/`]: (appShellConfiguration.baseUrl ?? "/") + (devMode ? "src/" : ""),
98
+ [`${packageJson.name}/`]: appShellConfiguration.baseUrl ?? "/",
99
99
  ...(devMode
100
100
  ? modules.concat(autoViewsBundles).reduce((acc, module) => {
101
- const finalModule = module
102
- .replace(/^(\/?)src\//, "")
103
- .replace(/\.(t|j)sx?$/, "");
101
+ const finalModule = getFinalModuleName(module);
104
102
  acc[`${packageJson.name}/${finalModule}.js`] =
105
103
  (appShellConfiguration.baseUrl ?? "/") + module;
106
104
  return acc;
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;AAI7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AAkB,EAClB,kBAAkB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAC7C;QAED,0EAA0E;QAC1E,kBAAkB,IAAI,kBAAkB,CAAC,iBAAiB,EAAE,YAAY,CAAC;KAC1E,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport virtual from \"@rollup/plugin-virtual\";\nimport { viteStaticCopy } from \"vite-plugin-static-copy\";\n\nimport { loadEnv, PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport generateImportmap, {\n extraDependencies\n} from \"./vite-importmap-plugin.js\";\nimport processConfiguration from \"./vite-configuration-processor-plugin.js\";\nimport generateBaseTag from \"./vite-generate-base-plugin.js\";\nimport injectMetadata from \"./vite-metadata-plugin.js\";\nimport serveAppShellConfig from \"./vite-watch-config-plugin.js\";\nimport generateBashScript from \"./vite-generate-bash-script-plugin.js\";\n\nimport {\n ConfigReplacement,\n findAppShellConfigFile,\n loadConfigFile\n} from \"./config-utils.js\";\nimport { getModulePath, resolveModule } from \"./nodeModule.js\";\nimport {\n applyAutomaticMenu,\n applyAutomaticViewsAndRoutes\n} from \"./automatic-utils.js\";\nimport getVirtualEntrypoints from \"./virtual-entrypoints.js\";\nimport SHARED_DEPENDENCIES from \"./shared-dependencies.js\";\n\nenum ViteBuildMode {\n PRODUCTION = \"production\",\n DEVELOPMENT = \"development\"\n}\n\nexport type ApplicationBundleType = \"app\" | \"bundle\";\n\nexport interface AppShellVitePluginOptions {\n /**\n * Project root directory. Most likely the location of the vite config file.\n *\n * @default process.cwd()\n */\n root?: string;\n /**\n * Execution mode.\n */\n mode?: string;\n\n /**\n * Type of application bundle being built. Can be \"app\" or \"bundle\".\n *\n * - \"app\": The application bundle includes both the index.html entry point and the exported modules.\n * - \"bundle\": The application bundle will not include the index.html entry point.\n *\n * @default \"app\"\n */\n type?: ApplicationBundleType;\n\n /** Array of tokens that are replaced at app-shell.config.json during the build of the solution.\n * e.g.\n * {\n * token: \"USER_NOTIFICATIONS_URL\",\n * value: \"http://localhost:8080\"\n * }\n * Tokens used at config file must be wrapped (at the beginning and at the end) by @@ sequence\n * e.g.\n * {\n * \"@hv/user-notifications-client\": \"@@USER_NOTIFICATIONS_URL@@\"\n * }\n */\n configReplacements?: ConfigReplacement[];\n\n /**\n * The folder containing Views to be shared as Shared Modules. Defaults to \"src/pages\".\n *\n * The folder path must be relative to the project root (e.g. \"src/pages\").\n */\n viewsFolder?: string;\n /**\n * If set, the plugin will search for Views at the folder specified by `viewsFolder` and will add them to the App Shell configuration as views.\n * The views' modules will be exported accordingly, and a route will be created from the folder structure.\n * Dynamic route parameters are supported by prefixing the folder name with a $ (e.g. \"src/pages/List/$id/index.tsx\" will be configured as \"/list/:id\").\n */\n autoViewsAndRoutes?: boolean;\n /**\n * If true, the plugin will try to automatically add the views to the menu.\n * This is only valid if the app-shell.config.json file does not contain any menu configuration already.\n */\n autoMenu?: boolean;\n\n /**\n * If true, the plugin will generate the importmap with an external js file instead of inline in the html.\n * The map will be saved at the root of the application destination dir and named as \"importmap.js\".\n *\n * This option is not for general use. It is only intended to be used for easing the automated testing of the App Shell.\n *\n * @default false\n * @private\n */\n externalImportMap?: boolean;\n /**\n * If true, the plugin will inline the app-shell.config.json file in a script tag of the index html.\n *\n * This option is not for general use. Its value will be automatically managed by the App Shell build process.\n *\n * @default false, true if generateEmptyShell is true\n * @private\n */\n inlineConfig?: boolean;\n /**\n * If true, the config file is ignored, only the App Shell is built and the generated index.html will contain a placeholders\n * for importmap (if externalImportMap is false), app shell config (if inlineConfig is true) and title.\n *\n * A bash script will also be added to the dist folder to replace the placeholders with the actual content,\n * when provided with a concrete configuration.\n *\n * This option is not for general use. It is used for generating the App Shell container image.\n *\n * @default false\n * @private\n */\n generateEmptyShell?: boolean;\n /**\n * The modules to be exported by the application.\n *\n * All the modules that the application need to export should be declared here in order to have them built properly.\n *\n */\n modules?: string[];\n}\n\n/**\n * Vite plugin to support App Shell apps setup\n * @param opts Plugin options\n * @param env Environment variable\n */\nfunction appShellVitePlugin(\n opts: AppShellVitePluginOptions = {},\n env: Record<string, string> = {}\n): PluginOption {\n const {\n root = process.cwd(),\n mode = ViteBuildMode.PRODUCTION,\n externalImportMap = false,\n viewsFolder = \"src/pages\",\n autoViewsAndRoutes = false,\n autoMenu = false,\n inlineConfig = opts.generateEmptyShell ?? false,\n generateEmptyShell = false,\n modules = []\n } = opts;\n\n const globalEnv = loadEnv(mode, process.cwd(), \"\");\n\n const { type = globalEnv.CI ? \"bundle\" : \"app\" } = opts;\n\n console.info(`Vite running in mode: ${mode}`);\n console.info(`AppShell Vite plugin running with type: ${type}`);\n\n const devMode = mode === ViteBuildMode.DEVELOPMENT;\n const buildEntryPoint = type !== \"bundle\";\n\n const packageJsonRaw = fs.readFileSync(\n path.resolve(root, \"package.json\"),\n \"utf-8\"\n );\n const packageJson = JSON.parse(packageJsonRaw);\n\n const appShellConfigFile = !generateEmptyShell\n ? findAppShellConfigFile(root)\n : undefined;\n const appShellConfiguration: HvAppShellConfig = loadConfigFile(\n appShellConfigFile,\n opts,\n env\n );\n\n let autoViewsBundles: string[] = [];\n\n if (!generateEmptyShell) {\n if (autoViewsAndRoutes) {\n autoViewsBundles = applyAutomaticViewsAndRoutes(\n appShellConfiguration,\n root,\n viewsFolder\n );\n }\n\n if (autoMenu) {\n applyAutomaticMenu(appShellConfiguration);\n }\n }\n\n return [\n // copy the shared dependencies js bundles to the \"bundles\" folder\n (buildEntryPoint || devMode) &&\n viteStaticCopy({\n targets: [\n {\n src: getModulePath(\"es-module-shims\", \"dist/*\"),\n dest: \"bundles\"\n },\n // copy the ui kit icons' sprites to the \"icons\" folder\n {\n src: [\n getModulePath(\n \"@hitachivantara/uikit-react-icons\",\n \"dist/sprites/*.svg\"\n )\n ],\n dest: \"icons\"\n },\n ...(!devMode && buildEntryPoint\n ? [\n {\n src: SHARED_DEPENDENCIES.flatMap(dep => [\n resolveModule(dep.bundleSrc),\n resolveModule(`${dep.bundleSrc}.map`)\n ]),\n dest: \"bundles\"\n }\n ]\n : [])\n ]\n }),\n\n // create virtual endpoints for shell code and for shared dependencies\n virtual({\n ...getVirtualEntrypoints(inlineConfig),\n\n ...SHARED_DEPENDENCIES.reduce(\n (acc, dep) => {\n acc[`/bundles/${dep.bundle}`] = dep.virtualSrc;\n return acc;\n },\n {} as Record<string, string>\n )\n }),\n\n // generate the importmap for shared dependencies and for apps referenced in the config file\n generateImportmap(\n {\n ...SHARED_DEPENDENCIES.reduce(\n (acc, dep) => {\n acc[dep.moduleId] = `./bundles/${dep.bundle}`;\n return acc;\n },\n {} as Record<string, string>\n ),\n\n ...extraDependencies,\n\n ...Object.entries(appShellConfiguration?.apps ?? {}).reduce(\n (acc, [key, value]) => {\n acc[`${key}/`] = value;\n return acc;\n },\n {} as Record<string, string>\n ),\n\n [`${packageJson.name}/`]:\n (appShellConfiguration.baseUrl ?? \"/\") + (devMode ? \"src/\" : \"\"),\n\n ...(devMode\n ? modules.concat(autoViewsBundles).reduce(\n (acc, module) => {\n const finalModule = module\n .replace(/^(\\/?)src\\//, \"\")\n .replace(/\\.(t|j)sx?$/, \"\");\n acc[`${packageJson.name}/${finalModule}.js`] =\n (appShellConfiguration.baseUrl ?? \"/\") + module;\n return acc;\n },\n {} as Record<string, string>\n )\n : {})\n },\n packageJson.name,\n [...SHARED_DEPENDENCIES.map(dep => dep.moduleId), packageJson.name],\n externalImportMap && buildEntryPoint,\n generateEmptyShell\n ),\n\n // inject version metadata in the index.html\n buildEntryPoint && injectMetadata(),\n\n // set the base tag and replace the title in the index.html\n buildEntryPoint &&\n generateBaseTag(appShellConfiguration, generateEmptyShell),\n\n // configure the build process based on the config file\n processConfiguration(\n root,\n appShellConfiguration,\n packageJson.name,\n buildEntryPoint,\n inlineConfig,\n generateEmptyShell,\n modules.concat(autoViewsBundles)\n ),\n\n // serve the app shell config file as json and watch for changes\n serveAppShellConfig(\n appShellConfiguration,\n root,\n packageJson.name,\n appShellConfigFile,\n autoViewsAndRoutes ? viewsFolder : undefined\n ),\n\n // generate the shell script to replace the placeholders in the index.html\n generateEmptyShell && generateBashScript(externalImportMap, inlineConfig)\n ];\n}\n\nexport default appShellVitePlugin;\n"]}
1
+ {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;AAI7C,OAAO,iBAAiB,EAAE,EACxB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,oBAAoB,MAAM,0CAA0C,CAAC;AAC5E,OAAO,eAAe,MAAM,gCAAgC,CAAC;AAC7D,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,mBAAmB,MAAM,+BAA+B,CAAC;AAChE,OAAO,kBAAkB,MAAM,uCAAuC,CAAC;AAEvE,OAAO,EAEL,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAC7D,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D,IAAK,aAGJ;AAHD,WAAK,aAAa;IAChB,0CAAyB,CAAA;IACzB,4CAA2B,CAAA;AAC7B,CAAC,EAHI,aAAa,KAAb,aAAa,QAGjB;AAmGD;;;;GAIG;AACH,SAAS,kBAAkB,CACzB,OAAkC,EAAE,EACpC,MAA8B,EAAE;IA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AE;QAEnC,2DAA2D;QAC3D,eAAe;YACb,eAAe,CAAC,qBAAqB,EAAE,kBAAkB,CAAC;QAE5D,uDAAuD;QACvD,oBAAoB,CAClB,IAAI,EACJ,qBAAqB,EACrB,WAAW,CAAC,IAAI,EAChB,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CACjC;QAED,gEAAgE;QAChE,mBAAmB,CACjB,qBAAqB,EACrB,IAAI,EACJ,WAAW,CAAC,IAAI,EAChB,kBAAkB,EAClB,kBAAkB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAC7C;QAED,0EAA0E;QAC1E,kBAAkB,IAAI,kBAAkB,CAAC,iBAAiB,EAAE,YAAY,CAAC;KAC1E,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport virtual from \"@rollup/plugin-virtual\";\nimport { viteStaticCopy } from \"vite-plugin-static-copy\";\n\nimport { loadEnv, PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport generateImportmap, {\n extraDependencies\n} from \"./vite-importmap-plugin.js\";\nimport processConfiguration from \"./vite-configuration-processor-plugin.js\";\nimport generateBaseTag from \"./vite-generate-base-plugin.js\";\nimport injectMetadata from \"./vite-metadata-plugin.js\";\nimport serveAppShellConfig from \"./vite-watch-config-plugin.js\";\nimport generateBashScript from \"./vite-generate-bash-script-plugin.js\";\n\nimport {\n ConfigReplacement,\n findAppShellConfigFile,\n getFinalModuleName,\n loadConfigFile\n} from \"./config-utils.js\";\nimport { getModulePath, resolveModule } from \"./nodeModule.js\";\nimport {\n applyAutomaticMenu,\n applyAutomaticViewsAndRoutes\n} from \"./automatic-utils.js\";\nimport getVirtualEntrypoints from \"./virtual-entrypoints.js\";\nimport SHARED_DEPENDENCIES from \"./shared-dependencies.js\";\n\nenum ViteBuildMode {\n PRODUCTION = \"production\",\n DEVELOPMENT = \"development\"\n}\n\nexport type ApplicationBundleType = \"app\" | \"bundle\";\n\nexport interface AppShellVitePluginOptions {\n /**\n * Project root directory. Most likely the location of the vite config file.\n *\n * @default process.cwd()\n */\n root?: string;\n /**\n * Execution mode.\n */\n mode?: string;\n\n /**\n * Type of application bundle being built. Can be \"app\" or \"bundle\".\n *\n * - \"app\": The application bundle includes both the index.html entry point and the exported modules.\n * - \"bundle\": The application bundle will not include the index.html entry point.\n *\n * @default \"app\"\n */\n type?: ApplicationBundleType;\n\n /** Array of tokens that are replaced at app-shell.config.json during the build of the solution.\n * e.g.\n * {\n * token: \"USER_NOTIFICATIONS_URL\",\n * value: \"http://localhost:8080\"\n * }\n * Tokens used at config file must be wrapped (at the beginning and at the end) by @@ sequence\n * e.g.\n * {\n * \"@hv/user-notifications-client\": \"@@USER_NOTIFICATIONS_URL@@\"\n * }\n */\n configReplacements?: ConfigReplacement[];\n\n /**\n * The folder containing Views to be shared as Shared Modules. Defaults to \"src/pages\".\n *\n * The folder path must be relative to the project root (e.g. \"src/pages\").\n */\n viewsFolder?: string;\n /**\n * If set, the plugin will search for Views at the folder specified by `viewsFolder` and will add them to the App Shell configuration as views.\n * The views' modules will be exported accordingly, and a route will be created from the folder structure.\n * Dynamic route parameters are supported by prefixing the folder name with a $ (e.g. \"src/pages/List/$id/index.tsx\" will be configured as \"/list/:id\").\n */\n autoViewsAndRoutes?: boolean;\n /**\n * If true, the plugin will try to automatically add the views to the menu.\n * Any menu defined in the App Shell config file will be overwritten.\n */\n autoMenu?: boolean;\n\n /**\n * If true, the plugin will generate the importmap with an external js file instead of inline in the html.\n * The map will be saved at the root of the application destination dir and named as \"importmap.js\".\n *\n * This option is not for general use. It is only intended to be used for easing the automated testing of the App Shell.\n *\n * @default false\n * @private\n */\n externalImportMap?: boolean;\n /**\n * If true, the plugin will inline the app-shell.config.json file in a script tag of the index html.\n *\n * This option is not for general use. Its value will be automatically managed by the App Shell build process.\n *\n * @default false, true if generateEmptyShell is true\n * @private\n */\n inlineConfig?: boolean;\n /**\n * If true, the config file is ignored, only the App Shell is built and the generated index.html will contain a placeholders\n * for importmap (if externalImportMap is false), app shell config (if inlineConfig is true) and title.\n *\n * A bash script will also be added to the dist folder to replace the placeholders with the actual content,\n * when provided with a concrete configuration.\n *\n * This option is not for general use. It is used for generating the App Shell container image.\n *\n * @default false\n * @private\n */\n generateEmptyShell?: boolean;\n /**\n * The modules to be exported by the application.\n *\n * All the modules that the application need to export should be declared here in order to have them built properly.\n *\n */\n modules?: string[];\n}\n\n/**\n * Vite plugin to support App Shell apps setup\n * @param opts Plugin options\n * @param env Environment variable\n */\nfunction appShellVitePlugin(\n opts: AppShellVitePluginOptions = {},\n env: Record<string, string> = {}\n): PluginOption {\n const {\n root = process.cwd(),\n mode = ViteBuildMode.PRODUCTION,\n externalImportMap = false,\n viewsFolder = \"src/pages\",\n autoViewsAndRoutes = false,\n autoMenu = false,\n inlineConfig = opts.generateEmptyShell ?? false,\n generateEmptyShell = false,\n modules = []\n } = opts;\n\n const globalEnv = loadEnv(mode, process.cwd(), \"\");\n\n const { type = globalEnv.CI ? \"bundle\" : \"app\" } = opts;\n\n console.info(`Vite running in mode: ${mode}`);\n console.info(`AppShell Vite plugin running with type: ${type}`);\n\n const devMode = mode === ViteBuildMode.DEVELOPMENT;\n const buildEntryPoint = type !== \"bundle\";\n\n const packageJsonRaw = fs.readFileSync(\n path.resolve(root, \"package.json\"),\n \"utf-8\"\n );\n const packageJson = JSON.parse(packageJsonRaw);\n\n const appShellConfigFile = !generateEmptyShell\n ? findAppShellConfigFile(root)\n : undefined;\n const appShellConfiguration: HvAppShellConfig = loadConfigFile(\n appShellConfigFile,\n opts,\n env\n );\n\n let autoViewsBundles: string[] = [];\n\n if (!generateEmptyShell) {\n if (autoViewsAndRoutes) {\n autoViewsBundles = applyAutomaticViewsAndRoutes(\n appShellConfiguration,\n root,\n viewsFolder\n );\n }\n\n if (autoMenu) {\n applyAutomaticMenu(appShellConfiguration);\n }\n }\n\n return [\n // copy the shared dependencies js bundles to the \"bundles\" folder\n (buildEntryPoint || devMode) &&\n viteStaticCopy({\n targets: [\n {\n src: getModulePath(\"es-module-shims\", \"dist/*\"),\n dest: \"bundles\"\n },\n // copy the ui kit icons' sprites to the \"icons\" folder\n {\n src: [\n getModulePath(\n \"@hitachivantara/uikit-react-icons\",\n \"dist/sprites/*.svg\"\n )\n ],\n dest: \"icons\"\n },\n ...(!devMode && buildEntryPoint\n ? [\n {\n src: SHARED_DEPENDENCIES.flatMap(dep => [\n resolveModule(dep.bundleSrc),\n resolveModule(`${dep.bundleSrc}.map`)\n ]),\n dest: \"bundles\"\n }\n ]\n : [])\n ]\n }),\n\n // create virtual endpoints for shell code and for shared dependencies\n virtual({\n ...getVirtualEntrypoints(inlineConfig),\n\n ...SHARED_DEPENDENCIES.reduce(\n (acc, dep) => {\n acc[`/bundles/${dep.bundle}`] = dep.virtualSrc;\n return acc;\n },\n {} as Record<string, string>\n )\n }),\n\n // generate the importmap for shared dependencies and for apps referenced in the config file\n generateImportmap(\n {\n ...SHARED_DEPENDENCIES.reduce(\n (acc, dep) => {\n acc[dep.moduleId] = `./bundles/${dep.bundle}`;\n return acc;\n },\n {} as Record<string, string>\n ),\n\n ...extraDependencies,\n\n ...Object.entries(appShellConfiguration?.apps ?? {}).reduce(\n (acc, [key, value]) => {\n acc[`${key}/`] = value;\n return acc;\n },\n {} as Record<string, string>\n ),\n\n [`${packageJson.name}/`]: appShellConfiguration.baseUrl ?? \"/\",\n\n ...(devMode\n ? modules.concat(autoViewsBundles).reduce(\n (acc, module) => {\n const finalModule = getFinalModuleName(module);\n acc[`${packageJson.name}/${finalModule}.js`] =\n (appShellConfiguration.baseUrl ?? \"/\") + module;\n return acc;\n },\n {} as Record<string, string>\n )\n : {})\n },\n packageJson.name,\n [...SHARED_DEPENDENCIES.map(dep => dep.moduleId), packageJson.name],\n externalImportMap && buildEntryPoint,\n generateEmptyShell\n ),\n\n // inject version metadata in the index.html\n buildEntryPoint && injectMetadata(),\n\n // set the base tag and replace the title in the index.html\n buildEntryPoint &&\n generateBaseTag(appShellConfiguration, generateEmptyShell),\n\n // configure the build process based on the config file\n processConfiguration(\n root,\n appShellConfiguration,\n packageJson.name,\n buildEntryPoint,\n inlineConfig,\n generateEmptyShell,\n modules.concat(autoViewsBundles)\n ),\n\n // serve the app shell config file as json and watch for changes\n serveAppShellConfig(\n appShellConfiguration,\n root,\n packageJson.name,\n appShellConfigFile,\n autoViewsAndRoutes ? viewsFolder : undefined\n ),\n\n // generate the shell script to replace the placeholders in the index.html\n generateEmptyShell && generateBashScript(externalImportMap, inlineConfig)\n ];\n}\n\nexport default appShellVitePlugin;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hitachivantara/app-shell-vite-plugin",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "AppShell Vite Plugin",
5
5
  "author": "Hitachi Vantara - Boba Fett Team",
6
6
  "license": "Apache-2.0",
@@ -64,5 +64,5 @@
64
64
  "peerDependencies": {
65
65
  "vite": "^4.1.4 || ^5.0.4"
66
66
  },
67
- "gitHead": "350741fa1c73417931caede99e0193b6955a9a29"
67
+ "gitHead": "a470d2d3ff9ec182df6fe1fa925dfe2be99a6ea4"
68
68
  }