@hitachivantara/app-shell-vite-plugin 0.9.2 → 0.10.0

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":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAc,MAAM,MAAM,CAAC;AAsRhD,oBAAY,qBAAqB;IAC/B,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED,KAAK,wBAAwB,GAAG,GAAG,qBAAqB,EAAE,CAAC;AAE3D,UAAU,yBAAyB;IACjC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,wBAAwB,CAAC;IAEhC;;;;;;;;;;;;OAYG;IACH,kBAAkB,CAAC,EAAE,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,GAAE,yBAA8B,GACnC,YAAY,CAiMd;AAED,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAc,MAAM,MAAM,CAAC;AAwUhD,oBAAY,qBAAqB;IAC/B,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED,KAAK,wBAAwB,GAAG,GAAG,qBAAqB,EAAE,CAAC;AAE3D,UAAU,yBAAyB;IACjC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,wBAAwB,CAAC;IAEhC;;;;;;;;;;;;OAYG;IACH,kBAAkB,CAAC,EAAE,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,GAAE,yBAA8B,GACnC,YAAY,CAiMd;AAED,eAAe,kBAAkB,CAAC"}
@@ -72,7 +72,7 @@ var ViteCommand;
72
72
  * @param root Project root directory.
73
73
  * @param appShellConfig The App Shell configuration.
74
74
  */
75
- function getAppModules(root, appShellConfig) {
75
+ function getAppModules(root, appShellConfig, selfAppName) {
76
76
  const appModules = {};
77
77
  const selfApp = getMainApp(appShellConfig);
78
78
  const selfViews = selfApp?.views?.map(view => {
@@ -95,6 +95,26 @@ function getAppModules(root, appShellConfig) {
95
95
  selfModules.forEach(module => {
96
96
  appModules[module.bundleName] = path.resolve(root, module.bundle);
97
97
  });
98
+ const implicitThemeModules = appShellConfig?.theming?.themes?.map(theme => {
99
+ if (theme.startsWith("/src/") ||
100
+ theme.startsWith("@self/") ||
101
+ theme.startsWith(selfAppName)) {
102
+ const bundle = theme
103
+ .replace(/^@self\//, "")
104
+ .replace(new RegExp(`^${selfAppName}/`), "");
105
+ const bundleName = bundle.replace(/^(\/?)src\//, "");
106
+ return {
107
+ bundle,
108
+ bundleName
109
+ };
110
+ }
111
+ return undefined;
112
+ }) ?? [];
113
+ implicitThemeModules.forEach(module => {
114
+ if (module != null && appModules[module.bundleName] == null) {
115
+ appModules[module.bundleName] = path.resolve(root, module.bundle);
116
+ }
117
+ });
98
118
  console.info("Modules exported by the application bundle:", appModules);
99
119
  return appModules;
100
120
  }
@@ -125,7 +145,7 @@ function processConfiguration(root, appShellConfig, selfAppName, buildEntryPoint
125
145
  fs.existsSync(path.resolve(projectRoot, "index.html"))
126
146
  ? { main: path.resolve(projectRoot, "index.html") }
127
147
  : {}),
128
- ...getAppModules(projectRoot, appShellConfig)
148
+ ...getAppModules(projectRoot, appShellConfig, selfAppName)
129
149
  },
130
150
  output: {
131
151
  entryFileNames: "[name].js"
@@ -196,6 +216,22 @@ function processConfiguration(root, appShellConfig, selfAppName, buildEntryPoint
196
216
  });
197
217
  // replace references to @self with the name of this application bundle
198
218
  selfApp.id = selfAppName;
219
+ // also replace implicit references to selfApp in other parts of the configuration
220
+ const { theming } = appShellConfig;
221
+ if (theming != null) {
222
+ theming.themes = theming.themes?.map(theme => {
223
+ if (theme.startsWith("@self/") ||
224
+ theme.startsWith(selfAppName) ||
225
+ theme.startsWith("/src/")) {
226
+ const bundleName = theme
227
+ .replace(/^@self\//, "")
228
+ .replace(new RegExp(`^${selfAppName}/`), "")
229
+ .replace(/^(\/?)src\//, "");
230
+ return `${selfAppName}/${chunks[bundleName]}`;
231
+ }
232
+ return theme;
233
+ });
234
+ }
199
235
  }
200
236
  const finalAppShellConfig = buildEntryPoint
201
237
  ? { ...appShellConfig }
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAE7C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C,OAAO,iBAAiB,MAAM,4BAA4B,CAAC;AAE3D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,GAAG,CACjB,cAAgC,EACE,EAAE;IACpC,OAAO,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC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IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;gBAClD,IAAI,GAAG,CAAC,EAAE,KAAK,OAAO,EAAE;oBACtB,GAAG,CAAC,GAAG,WAAW,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;oBAC1C,IAAI,OAAO,EAAE;wBACX,GAAG,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;qBACjC;iBACF;qBAAM;oBACL,GAAG,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;iBACjC;gBACD,OAAO,GAAG,CAAC;YACb,CAAC,EAAE,EAA4B,CAAC;SACjC,EACD;YACE,OAAO;YACP,WAAW;YACX,kBAAkB;YAClB,kCAAkC;YAClC,oCAAoC;YACpC,gBAAgB;YAChB,gBAAgB;YAChB,OAAO;YACP,WAAW,CAAC,IAAI;SACjB,EACD,iBAAiB,IAAI,eAAe,CACrC;QACD,eAAe,IAAI,eAAe,CAAC,qBAAqB,CAAC;QACzD,wBAAwB;QACxB,oBAAoB,CAClB,IAAI,EACJ,qBAAqB,EACrB,WAAW,CAAC,IAAI,EAChB,eAAe,CAChB;KACF,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC","sourcesContent":["import { NormalizedOutputOptions, OutputBundle } from \"rollup\";\nimport virtual from \"@rollup/plugin-virtual\";\n\nimport fs from \"fs\";\nimport path from \"path\";\n\nimport { viteStaticCopy } from \"vite-plugin-static-copy\";\nimport { PluginOption, UserConfig } from \"vite\";\n\nimport { createRequire } from \"node:module\";\nimport {\n HvAppShellAppsConfig,\n HvAppShellConfig\n} from \"@hitachivantara/app-shell-shared\";\nimport generateImportmap from \"./vite-importmap-plugin.js\";\n\nconst require = createRequire(import.meta.url);\n\n/**\n * Return the main app (identified by @self)\n * @param appShellConfig The App shell configuration\n */\nconst getMainApp = (\n appShellConfig: HvAppShellConfig\n): HvAppShellAppsConfig | undefined => {\n return appShellConfig.apps.filter(app => app.id === \"@self\")[0];\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 */\nconst getPublicPath = (appShellConfig: HvAppShellConfig): string => {\n const mainApp = getMainApp(appShellConfig);\n if (!mainApp) {\n return \"/\";\n }\n const url = mainApp.baseUrl;\n try {\n return new URL(url).pathname;\n } catch {\n return url;\n }\n};\n\n/**\n * Resolves the module name and normalizes slashes to be posix/unix-like forward slashes.\n *\n * @param moduleName The name of the module to be searched for\n * @returns The module path normalized\n */\nfunction resolveModule(moduleName: string) {\n const module = require.resolve(moduleName);\n return module.replace(/\\\\+/g, \"/\");\n}\n\n/**\n * This function will find out the module path using node `require.resolve` function\n * and add the suffix param after the folder with module name.\n *\n * @param moduleName \"@module/name\"\n * @param suffix to be added after the module path\n * @returns the /path/to/@module/name/<suffix>\n */\nfunction getModulePath(moduleName: string, suffix: string) {\n const moduleNameWithSlashes = `/${moduleName}/`;\n const module = resolveModule(moduleName);\n const modulePosition = module.lastIndexOf(moduleNameWithSlashes);\n return `${module.slice(\n 0,\n modulePosition + moduleNameWithSlashes.length\n )}${suffix}`;\n}\n\nenum ViteBuildMode {\n PRODUCTION = \"production\",\n DEVELOPMENT = \"development\"\n}\n\nenum ViteCommand {\n BUILD = \"build\",\n SERVE = \"serve\"\n}\n\n/**\n * Returns the modules to be created by the build of the app.\n * The list of modules is defined by the app-shell-config.json file routes ( limited to the @self app)\n * The bundles will be created following the original directories structure ( having the src folder path removed)\n *\n * @param root Project root directory.\n * @param appShellConfig The App Shell configuration.\n */\nfunction getAppModules(root: string, appShellConfig: HvAppShellConfig) {\n const appModules: { [key: string]: string } = {};\n\n const selfApp = getMainApp(appShellConfig);\n const selfViews =\n selfApp?.views?.map(view => {\n const bundleName = view.bundle.replace(/^src\\//, \"\");\n return {\n ...view,\n bundleName\n };\n }) ?? [];\n\n selfViews.forEach(view => {\n appModules[view.bundleName] = path.resolve(root, view.bundle);\n });\n\n const selfModules =\n selfApp?.modules?.map(module => {\n const bundleName = module.bundle.replace(/^src\\//, \"\");\n return {\n ...module,\n bundleName\n };\n }) ?? [];\n\n selfModules.forEach(module => {\n appModules[module.bundleName] = path.resolve(root, module.bundle);\n });\n\n console.info(\"Modules exported by the application bundle:\", appModules);\n return appModules;\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 * - Injects the APP_BASE_PATH env prop, to be used by the apps (if required)\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 */\nfunction processConfiguration(\n root: string,\n appShellConfig: HvAppShellConfig,\n selfAppName: string,\n buildEntryPoint: boolean\n): PluginOption {\n const selfApp = getMainApp(appShellConfig);\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 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 ...getAppModules(projectRoot, appShellConfig)\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 define: {\n ...config.define,\n APP_BASE_PATH: JSON.stringify(publicPath)\n }\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 * @param bundle bundles information\n */\n async generateBundle(\n options: NormalizedOutputOptions,\n bundle: OutputBundle\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 /**\n * Creating a map with each chunk and the final name. Only the bundles with type=chunck are important\n * Filename do not include the src path at the value\n */\n const chunks: Record<string, string> = {};\n\n Object.keys(bundle).forEach(key => {\n const chunk = bundle[key];\n if (chunk.type === \"chunk\") {\n const outputChunk = chunk;\n if (outputChunk.isEntry) {\n const { fileName } = outputChunk;\n const { name } = outputChunk;\n\n chunks[name] = fileName;\n }\n }\n });\n\n if (selfApp) {\n selfApp.views = selfApp.views?.map(view => {\n const bundleName = view.bundle.replace(/^src\\//, \"\");\n return {\n ...view,\n bundle: chunks[bundleName]\n };\n });\n selfApp.modules = selfApp.modules?.map(module => {\n const bundleName = module.bundle.replace(/^src\\//, \"\");\n return {\n ...module,\n bundle: chunks[bundleName]\n };\n });\n\n // replace references to @self with the name of this application bundle\n selfApp.id = selfAppName;\n }\n\n const finalAppShellConfig = buildEntryPoint\n ? { ...appShellConfig }\n : { name: appShellConfig.name, apps: [selfApp] };\n\n fs.writeFileSync(\n path.resolve(targetDir, \"app-shell.config.json\"),\n JSON.stringify(finalAppShellConfig)\n );\n }\n };\n}\n\n/**\n * Add the <BASE> tag at index.html file. Tag value is obtained by the main app ({@link #getMainApp}) baseUrl ({@link #getPublicPath})‘\n * @param appShellConfig The app shell configuration.\n */\nconst generateBaseTag = (appShellConfig: HvAppShellConfig): PluginOption => {\n const publicPath = getPublicPath(appShellConfig);\n return {\n name: \"vite-plugin-generate-base\",\n enforce: \"pre\",\n // except for react and react-dom when in dev mode\n transformIndexHtml: {\n enforce: \"post\",\n transform: (html: string) => ({\n html,\n tags: [\n {\n tag: \"base\",\n attrs: { href: publicPath },\n injectTo: \"head-prepend\"\n }\n ]\n })\n }\n };\n};\n\nexport enum ApplicationBundleType {\n APP = \"app\",\n BUNDLE = \"bundle\"\n}\n\ntype ApplicationBundleTypeKey = `${ApplicationBundleType}`;\n\ninterface AppShellVitePluginOptions {\n /**\n * Project root directory. Most likely 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 * 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 * @default false\n */\n externalImportMap?: boolean;\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?: ApplicationBundleTypeKey;\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 * \"id\": \"@hv/user-notifications-client\",\n * \"baseUrl\": \"@@USER_NOTIFICATIONS_URL@@\"\n * }\n */\n configReplacements?: [{ token: string; value: string }];\n}\n\n/**\n * Vite plugin to support App Shell apps setup\n * @param opts Plugin options\n */\nexport function appShellVitePlugin(\n opts: AppShellVitePluginOptions = {}\n): PluginOption {\n const root = opts.root || process.cwd();\n const mode = opts.mode || ViteBuildMode.PRODUCTION;\n const externalImportMap = opts.externalImportMap || false;\n const type = opts.type ?? ApplicationBundleType.APP;\n\n const buildEntryPoint = type !== ApplicationBundleType.BUNDLE;\n\n console.info(`Vite running in mode: ${mode}`);\n\n const devMode = mode === ViteBuildMode.DEVELOPMENT;\n\n const packageJsonRaw = fs.readFileSync(\n path.resolve(root, \"package.json\"),\n \"utf-8\"\n );\n const packageJson = JSON.parse(packageJsonRaw);\n\n let appShellConfigRaw = fs.readFileSync(\n path.resolve(root, \"app-shell.config.json\"),\n \"utf-8\"\n );\n\n opts.configReplacements?.forEach(item => {\n appShellConfigRaw = appShellConfigRaw.replaceAll(\n `@@${item.token}@@`,\n item.value\n );\n });\n\n const appShellConfiguration = JSON.parse(\n appShellConfigRaw\n ) as HvAppShellConfig;\n\n return [\n // Copy all the required js bundles to final \"bundles\" folders, that will be injected by the importmap\n (buildEntryPoint || devMode) &&\n viteStaticCopy({\n targets: [\n {\n src: getModulePath(\"es-module-shims\", \"dist/*\"),\n dest: \"bundles\"\n },\n ...(!devMode && buildEntryPoint\n ? [\n {\n src: [\n resolveModule(\"./esm-externals/react.production.min.js\"),\n resolveModule(\n \"./esm-externals/react.production.min.js.map\"\n ),\n resolveModule(\n \"./esm-externals/react-dom.production.min.js\"\n ),\n resolveModule(\n \"./esm-externals/react-dom.production.min.js.map\"\n ),\n resolveModule(\n \"./esm-externals/react-router-dom.production.min.js\"\n ),\n resolveModule(\n \"./esm-externals/react-router-dom.production.min.js.map\"\n ),\n resolveModule(\n \"./esm-externals/emotion-react.production.min.js\"\n ),\n resolveModule(\n \"./esm-externals/emotion-react.production.min.js.map\"\n ),\n resolveModule(\n \"./esm-externals/emotion-cache.production.min.js\"\n ),\n resolveModule(\n \"./esm-externals/emotion-cache.production.min.js.map\"\n ),\n resolveModule(\n \"@hitachivantara/app-shell-shared/bundles/app-shell-shared.esm.js\"\n ),\n resolveModule(\n \"@hitachivantara/app-shell-shared/bundles/app-shell-shared.esm.js.map\"\n ),\n resolveModule(\n \"@hitachivantara/uikit-react-shared/bundles/uikit-react-shared.esm.js\"\n ),\n resolveModule(\n \"@hitachivantara/uikit-react-shared/bundles/uikit-react-shared.esm.js.map\"\n )\n ],\n dest: \"bundles\"\n }\n ]\n : [])\n ]\n }),\n\n // create virtual endpoints to support dev mode\n virtual({\n \"/bundles/react.production.min.js\": `import * as React from \"react\";\n export default React;\n\n export {\n Fragment,\n StrictMode,\n Profiler,\n Suspense,\n Children,\n Component,\n PureComponent,\n cloneElement,\n createContext,\n createElement,\n createFactory,\n createRef,\n forwardRef,\n isValidElement,\n lazy,\n memo,\n useCallback,\n useContext,\n useDebugValue,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n version,\n } from \"react\";`,\n \"/bundles/react-dom.production.min.js\": `export {\n default,\n flushSync,\n createPortal,\n findDOMNode,\n hydrate,\n render,\n unmountComponentAtNode,\n unstable_batchedUpdates,\n unstable_renderSubtreeIntoContainer,\n version,\n } from \"react-dom\";`,\n \"/bundles/react-router-dom.production.min.js\": `export * from \"react-router-dom\";`,\n \"/bundles/emotion-react.production.min.js\": `export * from \"@emotion/react\";`,\n \"/bundles/emotion-cache.production.min.js\": `import createCache from \"@emotion/cache\"; export default createCache;`,\n \"/bundles/app-shell-shared.esm.js\": `export * from \"@hitachivantara/app-shell-shared\";`,\n \"/bundles/uikit-react-shared.esm.js\": `export * from \"@hitachivantara/uikit-react-shared\";`\n }),\n\n // generation of the importmap to create the link to the js bundles\n generateImportmap(\n {\n react: `./bundles/react.production.min.js`,\n \"react-dom\": `./bundles/react-dom.production.min.js`,\n \"react-router-dom\": `./bundles/react-router-dom.production.min.js`,\n \"@hitachivantara/app-shell-shared\": \"./bundles/app-shell-shared.esm.js\",\n \"@emotion/react\": \"./bundles/emotion-react.production.min.js\",\n \"@emotion/cache\": \"./bundles/emotion-cache.production.min.js\",\n \"@hitachivantara/uikit-react-shared\":\n \"./bundles/uikit-react-shared.esm.js\",\n ...appShellConfiguration?.apps?.reduce((acc, app) => {\n if (app.id === \"@self\") {\n acc[`${packageJson.name}/`] = app.baseUrl;\n if (devMode) {\n acc[`${app.id}/`] = app.baseUrl;\n }\n } else {\n acc[`${app.id}/`] = app.baseUrl;\n }\n return acc;\n }, {} as Record<string, string>)\n },\n [\n \"react\",\n \"react-dom\",\n \"react-router-dom\",\n \"@hitachivantara/app-shell-shared\",\n \"@hitachivantara/uikit-react-shared\",\n \"@emotion/react\",\n \"@emotion/cache\",\n \"@self\",\n packageJson.name\n ],\n externalImportMap && buildEntryPoint\n ),\n buildEntryPoint && generateBaseTag(appShellConfiguration),\n // process configuration\n processConfiguration(\n root,\n appShellConfiguration,\n packageJson.name,\n buildEntryPoint\n )\n ];\n}\n\nexport default appShellVitePlugin;\n"]}
1
+ {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAE7C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C,OAAO,iBAAiB,MAAM,4BAA4B,CAAC;AAE3D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,GAAG,CACjB,cAAgC,EACE,EAAE;IACpC,OAAO,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,aAAa,GAAG,CAAC,cAAgC,EAAU,EAAE;IACjE,MAAM,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,GAAG,CAAC;KACZ;IACD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAC5B,IAAI;QACF,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;KAC9B;IAAC,MAAM;QACN,OAAO,GAAG,CAAC;KACZ;AACH,CAAC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E;oBACtB,GAAG,CAAC,GAAG,WAAW,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;oBAC1C,IAAI,OAAO,EAAE;wBACX,GAAG,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;qBACjC;iBACF;qBAAM;oBACL,GAAG,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;iBACjC;gBACD,OAAO,GAAG,CAAC;YACb,CAAC,EAAE,EAA4B,CAAC;SACjC,EACD;YACE,OAAO;YACP,WAAW;YACX,kBAAkB;YAClB,kCAAkC;YAClC,oCAAoC;YACpC,gBAAgB;YAChB,gBAAgB;YAChB,OAAO;YACP,WAAW,CAAC,IAAI;SACjB,EACD,iBAAiB,IAAI,eAAe,CACrC;QACD,eAAe,IAAI,eAAe,CAAC,qBAAqB,CAAC;QACzD,wBAAwB;QACxB,oBAAoB,CAClB,IAAI,EACJ,qBAAqB,EACrB,WAAW,CAAC,IAAI,EAChB,eAAe,CAChB;KACF,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC","sourcesContent":["import { NormalizedOutputOptions, OutputBundle } from \"rollup\";\nimport virtual from \"@rollup/plugin-virtual\";\n\nimport fs from \"fs\";\nimport path from \"path\";\n\nimport { viteStaticCopy } from \"vite-plugin-static-copy\";\nimport { PluginOption, UserConfig } from \"vite\";\n\nimport { createRequire } from \"node:module\";\nimport {\n HvAppShellAppsConfig,\n HvAppShellConfig\n} from \"@hitachivantara/app-shell-shared\";\nimport generateImportmap from \"./vite-importmap-plugin.js\";\n\nconst require = createRequire(import.meta.url);\n\n/**\n * Return the main app (identified by @self)\n * @param appShellConfig The App shell configuration\n */\nconst getMainApp = (\n appShellConfig: HvAppShellConfig\n): HvAppShellAppsConfig | undefined => {\n return appShellConfig.apps.filter(app => app.id === \"@self\")[0];\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 */\nconst getPublicPath = (appShellConfig: HvAppShellConfig): string => {\n const mainApp = getMainApp(appShellConfig);\n if (!mainApp) {\n return \"/\";\n }\n const url = mainApp.baseUrl;\n try {\n return new URL(url).pathname;\n } catch {\n return url;\n }\n};\n\n/**\n * Resolves the module name and normalizes slashes to be posix/unix-like forward slashes.\n *\n * @param moduleName The name of the module to be searched for\n * @returns The module path normalized\n */\nfunction resolveModule(moduleName: string) {\n const module = require.resolve(moduleName);\n return module.replace(/\\\\+/g, \"/\");\n}\n\n/**\n * This function will find out the module path using node `require.resolve` function\n * and add the suffix param after the folder with module name.\n *\n * @param moduleName \"@module/name\"\n * @param suffix to be added after the module path\n * @returns the /path/to/@module/name/<suffix>\n */\nfunction getModulePath(moduleName: string, suffix: string) {\n const moduleNameWithSlashes = `/${moduleName}/`;\n const module = resolveModule(moduleName);\n const modulePosition = module.lastIndexOf(moduleNameWithSlashes);\n return `${module.slice(\n 0,\n modulePosition + moduleNameWithSlashes.length\n )}${suffix}`;\n}\n\nenum ViteBuildMode {\n PRODUCTION = \"production\",\n DEVELOPMENT = \"development\"\n}\n\nenum ViteCommand {\n BUILD = \"build\",\n SERVE = \"serve\"\n}\n\n/**\n * Returns the modules to be created by the build of the app.\n * The list of modules is defined by the app-shell-config.json file routes ( limited to the @self app)\n * The bundles will be created following the original directories structure ( having the src folder path removed)\n *\n * @param root Project root directory.\n * @param appShellConfig The App Shell configuration.\n */\nfunction getAppModules(\n root: string,\n appShellConfig: HvAppShellConfig,\n selfAppName: string\n) {\n const appModules: { [key: string]: string } = {};\n\n const selfApp = getMainApp(appShellConfig);\n const selfViews =\n selfApp?.views?.map(view => {\n const bundleName = view.bundle.replace(/^src\\//, \"\");\n return {\n ...view,\n bundleName\n };\n }) ?? [];\n\n selfViews.forEach(view => {\n appModules[view.bundleName] = path.resolve(root, view.bundle);\n });\n\n const selfModules =\n selfApp?.modules?.map(module => {\n const bundleName = module.bundle.replace(/^src\\//, \"\");\n return {\n ...module,\n bundleName\n };\n }) ?? [];\n\n selfModules.forEach(module => {\n appModules[module.bundleName] = path.resolve(root, module.bundle);\n });\n\n const implicitThemeModules =\n appShellConfig?.theming?.themes?.map(theme => {\n if (\n theme.startsWith(\"/src/\") ||\n theme.startsWith(\"@self/\") ||\n theme.startsWith(selfAppName)\n ) {\n const bundle = theme\n .replace(/^@self\\//, \"\")\n .replace(new RegExp(`^${selfAppName}/`), \"\");\n const bundleName = bundle.replace(/^(\\/?)src\\//, \"\");\n return {\n bundle,\n bundleName\n };\n }\n\n return undefined;\n }) ?? [];\n\n implicitThemeModules.forEach(module => {\n if (module != null && appModules[module.bundleName] == null) {\n appModules[module.bundleName] = path.resolve(root, module.bundle);\n }\n });\n\n console.info(\"Modules exported by the application bundle:\", appModules);\n return appModules;\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 * - Injects the APP_BASE_PATH env prop, to be used by the apps (if required)\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 */\nfunction processConfiguration(\n root: string,\n appShellConfig: HvAppShellConfig,\n selfAppName: string,\n buildEntryPoint: boolean\n): PluginOption {\n const selfApp = getMainApp(appShellConfig);\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 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 ...getAppModules(projectRoot, appShellConfig, selfAppName)\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 define: {\n ...config.define,\n APP_BASE_PATH: JSON.stringify(publicPath)\n }\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 * @param bundle bundles information\n */\n async generateBundle(\n options: NormalizedOutputOptions,\n bundle: OutputBundle\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 /**\n * Creating a map with each chunk and the final name. Only the bundles with type=chunck are important\n * Filename do not include the src path at the value\n */\n const chunks: Record<string, string> = {};\n\n Object.keys(bundle).forEach(key => {\n const chunk = bundle[key];\n if (chunk.type === \"chunk\") {\n const outputChunk = chunk;\n if (outputChunk.isEntry) {\n const { fileName } = outputChunk;\n const { name } = outputChunk;\n\n chunks[name] = fileName;\n }\n }\n });\n\n if (selfApp) {\n selfApp.views = selfApp.views?.map(view => {\n const bundleName = view.bundle.replace(/^src\\//, \"\");\n return {\n ...view,\n bundle: chunks[bundleName]\n };\n });\n selfApp.modules = selfApp.modules?.map(module => {\n const bundleName = module.bundle.replace(/^src\\//, \"\");\n return {\n ...module,\n bundle: chunks[bundleName]\n };\n });\n\n // replace references to @self with the name of this application bundle\n selfApp.id = selfAppName;\n\n // also replace implicit references to selfApp in other parts of the configuration\n const { theming } = appShellConfig;\n if (theming != null) {\n theming.themes = theming.themes?.map(theme => {\n if (\n theme.startsWith(\"@self/\") ||\n theme.startsWith(selfAppName) ||\n theme.startsWith(\"/src/\")\n ) {\n const bundleName = theme\n .replace(/^@self\\//, \"\")\n .replace(new RegExp(`^${selfAppName}/`), \"\")\n .replace(/^(\\/?)src\\//, \"\");\n return `${selfAppName}/${chunks[bundleName]}`;\n }\n\n return theme;\n });\n }\n }\n\n const finalAppShellConfig = buildEntryPoint\n ? { ...appShellConfig }\n : { name: appShellConfig.name, apps: [selfApp] };\n\n fs.writeFileSync(\n path.resolve(targetDir, \"app-shell.config.json\"),\n JSON.stringify(finalAppShellConfig)\n );\n }\n };\n}\n\n/**\n * Add the <BASE> tag at index.html file. Tag value is obtained by the main app ({@link #getMainApp}) baseUrl ({@link #getPublicPath})‘\n * @param appShellConfig The app shell configuration.\n */\nconst generateBaseTag = (appShellConfig: HvAppShellConfig): PluginOption => {\n const publicPath = getPublicPath(appShellConfig);\n return {\n name: \"vite-plugin-generate-base\",\n enforce: \"pre\",\n // except for react and react-dom when in dev mode\n transformIndexHtml: {\n enforce: \"post\",\n transform: (html: string) => ({\n html,\n tags: [\n {\n tag: \"base\",\n attrs: { href: publicPath },\n injectTo: \"head-prepend\"\n }\n ]\n })\n }\n };\n};\n\nexport enum ApplicationBundleType {\n APP = \"app\",\n BUNDLE = \"bundle\"\n}\n\ntype ApplicationBundleTypeKey = `${ApplicationBundleType}`;\n\ninterface AppShellVitePluginOptions {\n /**\n * Project root directory. Most likely 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 * 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 * @default false\n */\n externalImportMap?: boolean;\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?: ApplicationBundleTypeKey;\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 * \"id\": \"@hv/user-notifications-client\",\n * \"baseUrl\": \"@@USER_NOTIFICATIONS_URL@@\"\n * }\n */\n configReplacements?: [{ token: string; value: string }];\n}\n\n/**\n * Vite plugin to support App Shell apps setup\n * @param opts Plugin options\n */\nexport function appShellVitePlugin(\n opts: AppShellVitePluginOptions = {}\n): PluginOption {\n const root = opts.root || process.cwd();\n const mode = opts.mode || ViteBuildMode.PRODUCTION;\n const externalImportMap = opts.externalImportMap || false;\n const type = opts.type ?? ApplicationBundleType.APP;\n\n const buildEntryPoint = type !== ApplicationBundleType.BUNDLE;\n\n console.info(`Vite running in mode: ${mode}`);\n\n const devMode = mode === ViteBuildMode.DEVELOPMENT;\n\n const packageJsonRaw = fs.readFileSync(\n path.resolve(root, \"package.json\"),\n \"utf-8\"\n );\n const packageJson = JSON.parse(packageJsonRaw);\n\n let appShellConfigRaw = fs.readFileSync(\n path.resolve(root, \"app-shell.config.json\"),\n \"utf-8\"\n );\n\n opts.configReplacements?.forEach(item => {\n appShellConfigRaw = appShellConfigRaw.replaceAll(\n `@@${item.token}@@`,\n item.value\n );\n });\n\n const appShellConfiguration = JSON.parse(\n appShellConfigRaw\n ) as HvAppShellConfig;\n\n return [\n // Copy all the required js bundles to final \"bundles\" folders, that will be injected by the importmap\n (buildEntryPoint || devMode) &&\n viteStaticCopy({\n targets: [\n {\n src: getModulePath(\"es-module-shims\", \"dist/*\"),\n dest: \"bundles\"\n },\n ...(!devMode && buildEntryPoint\n ? [\n {\n src: [\n resolveModule(\"./esm-externals/react.production.min.js\"),\n resolveModule(\n \"./esm-externals/react.production.min.js.map\"\n ),\n resolveModule(\n \"./esm-externals/react-dom.production.min.js\"\n ),\n resolveModule(\n \"./esm-externals/react-dom.production.min.js.map\"\n ),\n resolveModule(\n \"./esm-externals/react-router-dom.production.min.js\"\n ),\n resolveModule(\n \"./esm-externals/react-router-dom.production.min.js.map\"\n ),\n resolveModule(\n \"./esm-externals/emotion-react.production.min.js\"\n ),\n resolveModule(\n \"./esm-externals/emotion-react.production.min.js.map\"\n ),\n resolveModule(\n \"./esm-externals/emotion-cache.production.min.js\"\n ),\n resolveModule(\n \"./esm-externals/emotion-cache.production.min.js.map\"\n ),\n resolveModule(\n \"@hitachivantara/app-shell-shared/bundles/app-shell-shared.esm.js\"\n ),\n resolveModule(\n \"@hitachivantara/app-shell-shared/bundles/app-shell-shared.esm.js.map\"\n ),\n resolveModule(\n \"@hitachivantara/uikit-react-shared/bundles/uikit-react-shared.esm.js\"\n ),\n resolveModule(\n \"@hitachivantara/uikit-react-shared/bundles/uikit-react-shared.esm.js.map\"\n )\n ],\n dest: \"bundles\"\n }\n ]\n : [])\n ]\n }),\n\n // create virtual endpoints to support dev mode\n virtual({\n \"/bundles/react.production.min.js\": `import * as React from \"react\";\n export default React;\n\n export {\n Fragment,\n StrictMode,\n Profiler,\n Suspense,\n Children,\n Component,\n PureComponent,\n cloneElement,\n createContext,\n createElement,\n createFactory,\n createRef,\n forwardRef,\n isValidElement,\n lazy,\n memo,\n useCallback,\n useContext,\n useDebugValue,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n version,\n } from \"react\";`,\n \"/bundles/react-dom.production.min.js\": `export {\n default,\n flushSync,\n createPortal,\n findDOMNode,\n hydrate,\n render,\n unmountComponentAtNode,\n unstable_batchedUpdates,\n unstable_renderSubtreeIntoContainer,\n version,\n } from \"react-dom\";`,\n \"/bundles/react-router-dom.production.min.js\": `export * from \"react-router-dom\";`,\n \"/bundles/emotion-react.production.min.js\": `export * from \"@emotion/react\";`,\n \"/bundles/emotion-cache.production.min.js\": `import createCache from \"@emotion/cache\"; export default createCache;`,\n \"/bundles/app-shell-shared.esm.js\": `export * from \"@hitachivantara/app-shell-shared\";`,\n \"/bundles/uikit-react-shared.esm.js\": `export * from \"@hitachivantara/uikit-react-shared\";`\n }),\n\n // generation of the importmap to create the link to the js bundles\n generateImportmap(\n {\n react: `./bundles/react.production.min.js`,\n \"react-dom\": `./bundles/react-dom.production.min.js`,\n \"react-router-dom\": `./bundles/react-router-dom.production.min.js`,\n \"@hitachivantara/app-shell-shared\": \"./bundles/app-shell-shared.esm.js\",\n \"@emotion/react\": \"./bundles/emotion-react.production.min.js\",\n \"@emotion/cache\": \"./bundles/emotion-cache.production.min.js\",\n \"@hitachivantara/uikit-react-shared\":\n \"./bundles/uikit-react-shared.esm.js\",\n ...appShellConfiguration?.apps?.reduce((acc, app) => {\n if (app.id === \"@self\") {\n acc[`${packageJson.name}/`] = app.baseUrl;\n if (devMode) {\n acc[`${app.id}/`] = app.baseUrl;\n }\n } else {\n acc[`${app.id}/`] = app.baseUrl;\n }\n return acc;\n }, {} as Record<string, string>)\n },\n [\n \"react\",\n \"react-dom\",\n \"react-router-dom\",\n \"@hitachivantara/app-shell-shared\",\n \"@hitachivantara/uikit-react-shared\",\n \"@emotion/react\",\n \"@emotion/cache\",\n \"@self\",\n packageJson.name\n ],\n externalImportMap && buildEntryPoint\n ),\n buildEntryPoint && generateBaseTag(appShellConfiguration),\n // process configuration\n processConfiguration(\n root,\n appShellConfiguration,\n packageJson.name,\n buildEntryPoint\n )\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": "0.9.2",
3
+ "version": "0.10.0",
4
4
  "description": "AppShell Vite Plugin",
5
5
  "author": "Hitachi Vantara - Boba Fett Team",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@emotion/cache": "^11.11.0",
36
36
  "@emotion/react": "^11.11.1",
37
- "@hitachivantara/app-shell-shared": "0.7.5",
37
+ "@hitachivantara/app-shell-shared": "0.8.0",
38
38
  "@hitachivantara/uikit-react-shared": "5.1.0",
39
39
  "@rollup/plugin-commonjs": "^24.0.0",
40
40
  "@rollup/plugin-json": "^6.0.0",
@@ -55,5 +55,5 @@
55
55
  "@types/react-dom": "^18.0.11",
56
56
  "tsc-watch": "^6.0.0"
57
57
  },
58
- "gitHead": "5f66b0d9c1279f7ebf7f1da27956c899ebce2ea7"
58
+ "gitHead": "e460ddf7e870321827581df908985394baa04050"
59
59
  }