@hitachivantara/app-shell-vite-plugin 1.5.2 → 1.6.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.
package/README.md CHANGED
@@ -57,7 +57,24 @@ Managing settings in TypeScript however provides more efficiency and type safety
57
57
  > Empty Configuration Validity: With these automatic features in place, the configuration file isn't even mandatory for dev environments.
58
58
 
59
59
 
60
- ## `<base href="...">` tag
60
+ ## \<base href> tag
61
61
 
62
- The <base href="..."> tag is automatically injected at index.html file during the build process and its value will be the same as the value in the `baseUrl` property of the App Shell [configuration file](../../../docs/config-file.md#application-identity).
62
+ The `<base href="...">` tag is automatically injected at the `index.html` file during the build process and its value will be the same as:
63
63
 
64
+ 1. the `base` property of Vite configuration if it is defined;
65
+ 2. or the `baseUrl` property of the App Shell configuration file;
66
+ 3. or `/`, if none of the above are set.
67
+
68
+ In the below snippet, the value injected in the base href tag will be `/example/` regardless of the App Shell configuration file.
69
+
70
+ ```typescript
71
+ // other configurations omitted
72
+ export default defineConfig(({ mode }) => {
73
+ return {
74
+ plugins: [
75
+ HvAppShellVitePlugin({ mode })
76
+ ],
77
+ base: "/example/",
78
+ };
79
+ });
80
+ ```
@@ -8,12 +8,6 @@ export type AppShellConfigFunction = (pluginOptions: AppShellVitePluginOptions,
8
8
  export declare const DEFAULT_CONFIG_FILES: string[];
9
9
  export declare function findAppShellConfigFile(root: string): string | undefined;
10
10
  export declare function loadConfigFile(appShellConfigFile: string | undefined, opts: AppShellVitePluginOptions, env?: Record<string, string>): HvAppShellConfig;
11
- /**
12
- * Return the public path to be use by vite to launch the application.
13
- * Value is obtained by returning the baseUrl value of the main app {@link #getMainApp}
14
- * @param appShellConfig The App shell configuration
15
- */
16
- export declare const getPublicPath: (appShellConfig: HvAppShellConfig) => string;
17
11
  /**
18
12
  * Returns the extensionless module name of the output bundle
19
13
  * for a given entry point module name.
@@ -32,4 +26,5 @@ export declare function getFinalModuleName(module: string): string;
32
26
  export declare function getAppModules(root: string, modules?: string[]): Record<string, string>;
33
27
  export declare function startsWithSelf(value: string): boolean;
34
28
  export declare function replaceSelf(value: string, replaceWith?: string): string;
29
+ export declare function getBasePath(configBaseUrl?: string, viteConfigBase?: string): string;
35
30
  //# 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,SAAS,EACtC,IAAI,EAAE,yBAAyB,EAC/B,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,gBAAgB,CAgClB;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,mBAAoB,gBAAgB,KAAG,MAOhE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,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"}
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,SAAS,EACtC,IAAI,EAAE,yBAAyB,EAC/B,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,gBAAgB,CAgClB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,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;AAED,wBAAgB,WAAW,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,UAE1E"}
@@ -42,20 +42,6 @@ export function loadConfigFile(appShellConfigFile, opts, env = {}) {
42
42
  }
43
43
  return loadedAppShellConfig;
44
44
  }
45
- /**
46
- * Return the public path to be use by vite to launch the application.
47
- * Value is obtained by returning the baseUrl value of the main app {@link #getMainApp}
48
- * @param appShellConfig The App shell configuration
49
- */
50
- export const getPublicPath = (appShellConfig) => {
51
- const url = appShellConfig.baseUrl ?? "/";
52
- try {
53
- return new URL(url).pathname;
54
- }
55
- catch {
56
- return url;
57
- }
58
- };
59
45
  /**
60
46
  * Returns the extensionless module name of the output bundle
61
47
  * for a given entry point module name.
@@ -101,4 +87,7 @@ export function startsWithSelf(value) {
101
87
  export function replaceSelf(value, replaceWith = "") {
102
88
  return value.replace(/^@self\//, replaceWith);
103
89
  }
90
+ export function getBasePath(configBaseUrl, viteConfigBase) {
91
+ return viteConfigBase ?? configBaseUrl ?? "/";
92
+ }
104
93
  //# sourceMappingURL=config-utils.js.map
@@ -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,qBAAqB,EAAE,KAAK;KAC7B;CACF,CAAC,CACH,CAAC;AAYF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,qBAAqB;IACrB,qBAAqB;IACrB,uBAAuB;CACxB,CAAC;AAEF,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,MAAM,QAAQ,GAAG,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAChD,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CACxC,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE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esContent":["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
+ {"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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pC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,cAAsB,EAAE;IACjE,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,aAAsB,EAAE,cAAuB;IACzE,OAAO,cAAc,IAAI,aAAa,IAAI,GAAG,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 * 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\nexport function getBasePath(configBaseUrl?: string, viteConfigBase?: string) {\n return viteConfigBase ?? configBaseUrl ?? \"/\";\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import fs from "fs";
2
- import { findAppShellConfigFile, getAppModules, getFinalModuleName, getPublicPath, loadConfigFile } from "../config-utils";
2
+ import { findAppShellConfigFile, getAppModules, getBasePath, getFinalModuleName, 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();
@@ -60,11 +60,6 @@ describe("test app-shell-vite-generate-base plugin", () => {
60
60
  });
61
61
  });
62
62
  });
63
- describe("getPublicPath", () => {
64
- it("getPublicPath", () => {
65
- expect(getPublicPath({ baseUrl: "/teste" })).toBe("/teste");
66
- });
67
- });
68
63
  describe("getFinalModuleName", () => {
69
64
  it("removes leading 'src/' and file extension from module path", () => {
70
65
  const modulePath = "/src/pages/DummyPath.tsx";
@@ -136,5 +131,19 @@ describe("test app-shell-vite-generate-base plugin", () => {
136
131
  });
137
132
  });
138
133
  });
134
+ describe("getBasePath", () => {
135
+ it("config url is defined", () => {
136
+ expect(getBasePath("/baseUrl")).toBe("/baseUrl");
137
+ });
138
+ it("config url and vite base are defined", () => {
139
+ expect(getBasePath("/baseUrl", "/viteBase/")).toBe("/viteBase/");
140
+ });
141
+ it("config url is undefined, vite base is defined", () => {
142
+ expect(getBasePath(undefined, "/viteBase")).toBe("/viteBase");
143
+ });
144
+ it("config url and vite base are undefined", () => {
145
+ expect(getBasePath(undefined, undefined)).toBe("/");
146
+ });
147
+ });
139
148
  });
140
149
  //# sourceMappingURL=config-utils.test.js.map
@@ -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,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,cAAc,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;AAC/B,MAAM,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC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E;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
+ {"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,WAAW,EACX,kBAAkB,EAClB,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,CAAC;YACH,MAAM,QAAQ,GAAG,sBAAsB,CAAC,6BAA6B,CAAC,CAAC;YACvE,MAAM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"@hitachivantara/app-shell-shared\";\nimport fs from \"fs\";\nimport {\n findAppShellConfigFile,\n getAppModules,\n getBasePath,\n getFinalModuleName,\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(\"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 describe(\"getBasePath\", () => {\n it(\"config url is defined\", () => {\n expect(getBasePath(\"/baseUrl\")).toBe(\"/baseUrl\");\n });\n it(\"config url and vite base are defined\", () => {\n expect(getBasePath(\"/baseUrl\", \"/viteBase/\")).toBe(\"/viteBase/\");\n });\n it(\"config url is undefined, vite base is defined\", () => {\n expect(getBasePath(undefined, \"/viteBase\")).toBe(\"/viteBase\");\n });\n it(\"config url and vite base are undefined\", () => {\n expect(getBasePath(undefined, undefined)).toBe(\"/\");\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,EAChB,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AAc1C,KAAK,gBAAgB,GACjB,yBAAyB,GACzB,qBAAqB,GACrB,sBAAsB,CAAC;AAE3B,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,gBAAgB,EAChE,OAAO,EAAE,CAAC,EAAE,EACZ,WAAW,EAAE,MAAM,GAClB,CAAC,EAAE,CAkBL;AAED;;;;;;;;;;;;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"}
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,EAChB,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AAc1C,KAAK,gBAAgB,GACjB,yBAAyB,GACzB,qBAAqB,GACrB,sBAAsB,CAAC;AAE3B,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,gBAAgB,EAChE,OAAO,EAAE,CAAC,EAAE,EACZ,WAAW,EAAE,MAAM,GAClB,CAAC,EAAE,CAkBL;AAED;;;;;;;;;;;;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,CAyJd"}
@@ -1,6 +1,6 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { getAppModules, getPublicPath, replaceSelf, startsWithSelf } from "./config-utils.js";
3
+ import { getAppModules, getBasePath, replaceSelf, startsWithSelf } from "./config-utils.js";
4
4
  var ViteCommand;
5
5
  (function (ViteCommand) {
6
6
  ViteCommand["BUILD"] = "build";
@@ -39,11 +39,11 @@ export function replaceReferencesToSelf(bundles, selfAppName) {
39
39
  */
40
40
  export default function processConfiguration(root, appShellConfig, selfAppName, buildEntryPoint, inlineConfig, generateEmptyShell, modules = []) {
41
41
  let finalAppShellConfig;
42
+ let basePath;
42
43
  return {
43
44
  name: "vite-plugin-appShell-configuration-processor",
44
45
  config(config, { command }) {
45
46
  const projectRoot = root ?? config.root;
46
- const publicPath = getPublicPath(appShellConfig);
47
47
  let appModules = {};
48
48
  if (!generateEmptyShell) {
49
49
  appModules = getAppModules(projectRoot, modules);
@@ -52,6 +52,7 @@ export default function processConfiguration(root, appShellConfig, selfAppName,
52
52
  return acc;
53
53
  }, {}));
54
54
  }
55
+ basePath = getBasePath(appShellConfig.baseUrl, config.base);
55
56
  return {
56
57
  build: {
57
58
  rollupOptions: {
@@ -68,8 +69,8 @@ export default function processConfiguration(root, appShellConfig, selfAppName,
68
69
  }
69
70
  }
70
71
  },
71
- // if serve (preview/dev) it uses the baseUrl. Otherwise(build), use ./
72
- base: command === ViteCommand.SERVE ? publicPath : "./"
72
+ // if serve (preview/dev) it uses the basePath. Otherwise(build), use ./
73
+ base: command === ViteCommand.SERVE ? basePath : "./"
73
74
  };
74
75
  },
75
76
  /**
@@ -109,6 +110,10 @@ export default function processConfiguration(root, appShellConfig, selfAppName,
109
110
  });
110
111
  }
111
112
  finalAppShellConfig = { ...appShellConfig };
113
+ // if no baseUrl is present on the configuration, then assume the calculated basePath
114
+ if (!finalAppShellConfig.baseUrl) {
115
+ finalAppShellConfig.baseUrl = basePath;
116
+ }
112
117
  finalAppShellConfig.apps = undefined;
113
118
  // also replace implicit references to selfApp in other parts of the configuration
114
119
  if (finalAppShellConfig.providers != null) {
@@ -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,MAAM,UAAU,uBAAuB,CACrC,OAAY,EACZ,WAAmB;IAEnB,OAAO,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE;QACpC,IAAI,OAAO,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;YAClE,OAAO;gBACL,GAAG,gBAAgB;gBACnB,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,WAAW,GAAG,CAAC;gBAC/D,KAAK,EAAE,uBAAuB,CAAC,gBAAgB,CAAC,KAAK,EAAE,WAAW,CAAC;aACpE,CAAC;QACJ,CAAC;QAED,IAAI,cAAc,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5C,OAAO;gBACL,GAAG,gBAAgB;gBACnB,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,WAAW,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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\nexport function replaceReferencesToSelf<T extends BundleDefinition>(\n bundles: T[],\n selfAppName: string\n): T[] {\n return bundles.map(bundleDefinition => {\n if (\"views\" in bundleDefinition && bundleDefinition.views != null) {\n return {\n ...bundleDefinition,\n bundle: replaceSelf(bundleDefinition.bundle, `${selfAppName}/`),\n views: replaceReferencesToSelf(bundleDefinition.views, selfAppName)\n };\n }\n\n if (startsWithSelf(bundleDefinition.bundle)) {\n return {\n ...bundleDefinition,\n bundle: replaceSelf(bundleDefinition.bundle, `${selfAppName}/`)\n };\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"]}
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,WAAW,EACX,WAAW,EACX,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B,IAAK,WAGJ;AAHD,WAAK,WAAW;IACd,8BAAe,CAAA;IACf,8BAAe,CAAA;AACjB,CAAC,EAHI,W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BACjD,mBAAmB,CAAC,SAAS,CAAC,KAAK,GAAG,uBAAuB,CAC3D,mBAAmB,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 getBasePath,\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\nexport function replaceReferencesToSelf<T extends BundleDefinition>(\n bundles: T[],\n selfAppName: string\n): T[] {\n return bundles.map(bundleDefinition => {\n if (\"views\" in bundleDefinition && bundleDefinition.views != null) {\n return {\n ...bundleDefinition,\n bundle: replaceSelf(bundleDefinition.bundle, `${selfAppName}/`),\n views: replaceReferencesToSelf(bundleDefinition.views, selfAppName)\n };\n }\n\n if (startsWithSelf(bundleDefinition.bundle)) {\n return {\n ...bundleDefinition,\n bundle: replaceSelf(bundleDefinition.bundle, `${selfAppName}/`)\n };\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 let basePath: string;\n\n return {\n name: \"vite-plugin-appShell-configuration-processor\",\n\n config(config: UserConfig, { command }) {\n const projectRoot = root ?? config.root;\n\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 basePath = getBasePath(appShellConfig.baseUrl, config.base);\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 basePath. Otherwise(build), use ./\n base: command === ViteCommand.SERVE ? basePath : \"./\"\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\n // if no baseUrl is present on the configuration, then assume the calculated basePath\n if (!finalAppShellConfig.baseUrl) {\n finalAppShellConfig.baseUrl = basePath;\n }\n\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"]}
@@ -10,7 +10,7 @@ import type { HvAppShellConfig } from "@hitachivantara/app-shell-shared";
10
10
  */
11
11
  export declare const getAppTitle: (generateEmptyShell: boolean, appShellConfig: HvAppShellConfig) => string | undefined;
12
12
  /**
13
- * Add the <BASE> tag at index.html file. Tag value is obtained by the baseUrl config value ({@link #getPublicPath})‘
13
+ * Add the <BASE> tag and icons preload in the index.html file.
14
14
  * @param appShellConfig The app shell configuration.
15
15
  * @param generateEmptyShell Flag that controls if an empty app shell application is created with tags instead of final values
16
16
  */
@@ -1 +1 @@
1
- {"version":3,"file":"vite-generate-base-plugin.d.ts","sourceRoot":"","sources":["../src/vite-generate-base-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAIzE;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,uBACF,OAAO,kBACX,gBAAgB,uBAGjC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,cAAc,EAAE,gBAAgB,EAChC,kBAAkB,EAAE,OAAO,GAC1B,YAAY,CAwCd"}
1
+ {"version":3,"file":"vite-generate-base-plugin.d.ts","sourceRoot":"","sources":["../src/vite-generate-base-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGzE;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,uBACF,OAAO,kBACX,gBAAgB,uBAGjC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,cAAc,EAAE,gBAAgB,EAChC,kBAAkB,EAAE,OAAO,GAC1B,YAAY,CAyCd"}
@@ -1,4 +1,4 @@
1
- import { getPublicPath } from "./config-utils.js";
1
+ import { getBasePath } from "./config-utils.js";
2
2
  /**
3
3
  * Calculate the App title, It applies the following rules to calculate the final value
4
4
  * - If we are generating an empty App Shell, it returns the value “%%APPSHELL_TITLE%%.”
@@ -11,15 +11,17 @@ export const getAppTitle = (generateEmptyShell, appShellConfig) => {
11
11
  return generateEmptyShell ? "%%APPSHELL_TITLE%%" : appShellConfig.name;
12
12
  };
13
13
  /**
14
- * Add the <BASE> tag at index.html file. Tag value is obtained by the baseUrl config value ({@link #getPublicPath})‘
14
+ * Add the <BASE> tag and icons preload in the index.html file.
15
15
  * @param appShellConfig The app shell configuration.
16
16
  * @param generateEmptyShell Flag that controls if an empty app shell application is created with tags instead of final values
17
17
  */
18
18
  export default function generateBaseTag(appShellConfig, generateEmptyShell) {
19
- const publicPath = getPublicPath(appShellConfig);
19
+ let basePath;
20
20
  return {
21
21
  name: "vite-plugin-generate-base",
22
- enforce: "pre",
22
+ config(config) {
23
+ basePath = getBasePath(appShellConfig.baseUrl, config.base);
24
+ },
23
25
  transformIndexHtml: {
24
26
  order: "post",
25
27
  handler: (html) => ({
@@ -30,7 +32,7 @@ export default function generateBaseTag(appShellConfig, generateEmptyShell) {
30
32
  {
31
33
  tag: "base",
32
34
  attrs: {
33
- href: generateEmptyShell ? "%%APPSHELL_BASE%%" : publicPath
35
+ href: generateEmptyShell ? "%%APPSHELL_BASE%%" : basePath
34
36
  },
35
37
  injectTo: "head-prepend"
36
38
  },
@@ -1 +1 @@
1
- {"version":3,"file":"vite-generate-base-plugin.js","sourceRoot":"","sources":["../src/vite-generate-base-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,kBAA2B,EAC3B,cAAgC,EAChC,EAAE;IACF,OAAO,kBAAkB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC;AACzE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,cAAgC,EAChC,kBAA2B;IAE3B,MAAM,UAAU,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;IAEjD,OAAO;QACL,IAAI,EAAE,2BAA2B;QACjC,OAAO,EAAE,KAAK;QACd,kBAAkB,EAAE;YAClB,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;gBAC1B,IAAI,EACF,kBAAkB,IAAI,cAAc,CAAC,IAAI,IAAI,IAAI;oBAC/C,CAAC,CAAC,IAAI,CAAC,OAAO,CACV,uBAAuB,EACvB,UAAU,WAAW,CACnB,kBAAkB,EAClB,cAAc,CACf,UAAU,CACZ;oBACH,CAAC,CAAC,IAAI;gBACV,IAAI,EAAE;oBACJ;wBACE,GAAG,EAAE,MAAM;wBACX,KAAK,EAAE;4BACL,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,UAAU;yBAC5D;wBACD,QAAQ,EAAE,cAAc;qBACzB;oBACD;wBACE,GAAG,EAAE,MAAM;wBACX,QAAQ,EAAE,cAAc;wBACxB,KAAK,EAAE;4BACL,GAAG,EAAE,SAAS;4BACd,EAAE,EAAE,OAAO;4BACX,IAAI,EAAE,mBAAmB;yBAC1B;qBACF;iBACF;aACF,CAAC;SACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport { getPublicPath } from \"./config-utils.js\";\n\n/**\n * Calculate the App title, It applies the following rules to calculate the final value\n * - If we are generating an empty App Shell, it returns the value “%%APPSHELL_TITLE%%.”\n * - Otherwise, it returns the value of the configuration name property.\n * @param generateEmptyShell flag to control if we are generating an empty App Shell instance\n * @param appShellConfig App shell config values\n * @returns The app title\n */\nexport const getAppTitle = (\n generateEmptyShell: boolean,\n appShellConfig: HvAppShellConfig\n) => {\n return generateEmptyShell ? \"%%APPSHELL_TITLE%%\" : appShellConfig.name;\n};\n\n/**\n * Add the <BASE> tag at index.html file. Tag value is obtained by the baseUrl config value ({@link #getPublicPath})‘\n * @param appShellConfig The app shell configuration.\n * @param generateEmptyShell Flag that controls if an empty app shell application is created with tags instead of final values\n */\nexport default function generateBaseTag(\n appShellConfig: HvAppShellConfig,\n generateEmptyShell: boolean\n): PluginOption {\n const publicPath = getPublicPath(appShellConfig);\n\n return {\n name: \"vite-plugin-generate-base\",\n enforce: \"pre\",\n transformIndexHtml: {\n order: \"post\",\n handler: (html: string) => ({\n html:\n generateEmptyShell || appShellConfig.name != null\n ? html.replace(\n /<title>(.*?)<\\/title>/,\n `<title>${getAppTitle(\n generateEmptyShell,\n appShellConfig\n )}</title>`\n )\n : html,\n tags: [\n {\n tag: \"base\",\n attrs: {\n href: generateEmptyShell ? \"%%APPSHELL_BASE%%\" : publicPath\n },\n injectTo: \"head-prepend\"\n },\n {\n tag: \"link\",\n injectTo: \"head-prepend\",\n attrs: {\n rel: \"preload\",\n as: \"image\",\n href: \"./icons/icons.svg\"\n }\n }\n ]\n })\n }\n };\n}\n"]}
1
+ {"version":3,"file":"vite-generate-base-plugin.js","sourceRoot":"","sources":["../src/vite-generate-base-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,kBAA2B,EAC3B,cAAgC,EAChC,EAAE;IACF,OAAO,kBAAkB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC;AACzE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,cAAgC,EAChC,kBAA2B;IAE3B,IAAI,QAAgB,CAAC;IACrB,OAAO;QACL,IAAI,EAAE,2BAA2B;QACjC,MAAM,CAAC,MAAM;YACX,QAAQ,GAAG,WAAW,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9D,CAAC;QACD,kBAAkB,EAAE;YAClB,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;gBAC1B,IAAI,EACF,kBAAkB,IAAI,cAAc,CAAC,IAAI,IAAI,IAAI;oBAC/C,CAAC,CAAC,IAAI,CAAC,OAAO,CACV,uBAAuB,EACvB,UAAU,WAAW,CACnB,kBAAkB,EAClB,cAAc,CACf,UAAU,CACZ;oBACH,CAAC,CAAC,IAAI;gBACV,IAAI,EAAE;oBACJ;wBACE,GAAG,EAAE,MAAM;wBACX,KAAK,EAAE;4BACL,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,QAAQ;yBAC1D;wBACD,QAAQ,EAAE,cAAc;qBACzB;oBACD;wBACE,GAAG,EAAE,MAAM;wBACX,QAAQ,EAAE,cAAc;wBACxB,KAAK,EAAE;4BACL,GAAG,EAAE,SAAS;4BACd,EAAE,EAAE,OAAO;4BACX,IAAI,EAAE,mBAAmB;yBAC1B;qBACF;iBACF;aACF,CAAC;SACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\nimport { getBasePath } from \"./config-utils.js\";\n\n/**\n * Calculate the App title, It applies the following rules to calculate the final value\n * - If we are generating an empty App Shell, it returns the value “%%APPSHELL_TITLE%%.”\n * - Otherwise, it returns the value of the configuration name property.\n * @param generateEmptyShell flag to control if we are generating an empty App Shell instance\n * @param appShellConfig App shell config values\n * @returns The app title\n */\nexport const getAppTitle = (\n generateEmptyShell: boolean,\n appShellConfig: HvAppShellConfig\n) => {\n return generateEmptyShell ? \"%%APPSHELL_TITLE%%\" : appShellConfig.name;\n};\n\n/**\n * Add the <BASE> tag and icons preload in the index.html file.\n * @param appShellConfig The app shell configuration.\n * @param generateEmptyShell Flag that controls if an empty app shell application is created with tags instead of final values\n */\nexport default function generateBaseTag(\n appShellConfig: HvAppShellConfig,\n generateEmptyShell: boolean\n): PluginOption {\n let basePath: string;\n return {\n name: \"vite-plugin-generate-base\",\n config(config) {\n basePath = getBasePath(appShellConfig.baseUrl, config.base);\n },\n transformIndexHtml: {\n order: \"post\",\n handler: (html: string) => ({\n html:\n generateEmptyShell || appShellConfig.name != null\n ? html.replace(\n /<title>(.*?)<\\/title>/,\n `<title>${getAppTitle(\n generateEmptyShell,\n appShellConfig\n )}</title>`\n )\n : html,\n tags: [\n {\n tag: \"base\",\n attrs: {\n href: generateEmptyShell ? \"%%APPSHELL_BASE%%\" : basePath\n },\n injectTo: \"head-prepend\"\n },\n {\n tag: \"link\",\n injectTo: \"head-prepend\",\n attrs: {\n rel: \"preload\",\n as: \"image\",\n href: \"./icons/icons.svg\"\n }\n }\n ]\n })\n }\n };\n}\n"]}
@@ -8,7 +8,10 @@ export declare const getExtraDependenciesString: () => string;
8
8
  /**
9
9
  * Generate and injects the importmap tag into index.html
10
10
  * @param importmapElements The importmap elements to be included
11
+ * @param packageName The application name identifier
11
12
  * @param sharedDependencies The shared packages (other than application bundles)
13
+ * @param externalImportMap Flag to control if the importmap should be externalized
14
+ * @param placeholderEntryPoint Flag to control if the importmap should be a placeholder
12
15
  */
13
16
  export default function generateImportmap(importmapElements: Record<string, string>, packageName: string, sharedDependencies: string[], externalImportMap?: boolean, placeholderEntryPoint?: boolean): PluginOption;
14
17
  //# sourceMappingURL=vite-importmap-plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite-importmap-plugin.d.ts","sourceRoot":"","sources":["../src/vite-importmap-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAMzC,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAEpD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,QAAO,MAQ7C,CAAC;AA4CF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,WAAW,EAAE,MAAM,EACnB,kBAAkB,EAAE,MAAM,EAAE,EAC5B,iBAAiB,UAAQ,EACzB,qBAAqB,UAAQ,GAC5B,YAAY,CAmLd"}
1
+ {"version":3,"file":"vite-importmap-plugin.d.ts","sourceRoot":"","sources":["../src/vite-importmap-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAMzC,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAEpD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,QAAO,MAQ7C,CAAC;AA4CF;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,WAAW,EAAE,MAAM,EACnB,kBAAkB,EAAE,MAAM,EAAE,EAC5B,iBAAiB,UAAQ,EACzB,qBAAqB,UAAQ,GAC5B,YAAY,CAiLd"}
@@ -47,7 +47,10 @@ function replaceIdPrefix(keys, packageName) {
47
47
  /**
48
48
  * Generate and injects the importmap tag into index.html
49
49
  * @param importmapElements The importmap elements to be included
50
+ * @param packageName The application name identifier
50
51
  * @param sharedDependencies The shared packages (other than application bundles)
52
+ * @param externalImportMap Flag to control if the importmap should be externalized
53
+ * @param placeholderEntryPoint Flag to control if the importmap should be a placeholder
51
54
  */
52
55
  export default function generateImportmap(importmapElements, packageName, sharedDependencies, externalImportMap = false, placeholderEntryPoint = false) {
53
56
  const keys = Object.keys(importmapElements);
@@ -124,8 +127,7 @@ document.currentScript.after(im);
124
127
  if (!devMode) {
125
128
  return;
126
129
  }
127
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
128
- // @ts-ignore an hack: we want to add the plugin only after the config is resolved
130
+ // @ts-expect-error an hack: we want to add the plugin only after the config is resolved
129
131
  resolvedConfig.plugins.push(replaceIdPrefix(devKeys, packageName));
130
132
  },
131
133
  /**
@@ -133,7 +135,6 @@ document.currentScript.after(im);
133
135
  * It will be used to create a new configuration with:
134
136
  * - bundles replace with the final location (e.g. -> "bundle": "src/pages/Main" transformed to "bundle": "pages/Main.js",
135
137
  * @param options build options
136
- * @param bundle bundles information
137
138
  */
138
139
  async generateBundle(options) {
139
140
  if (!externalImportMap || placeholderEntryPoint) {
@@ -1 +1 @@
1
- {"version":3,"file":"vite-importmap-plugin.js","sourceRoot":"","sources":["../src/vite-importmap-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAKxB,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAE7C,MAAM,SAAS,GAAG,OAAO,CAAC;AAE1B,MAAM,CAAC,MAAM,iBAAiB,GAA2B;IACvD,kBAAkB,EAAE,UAAU;CAC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H;SACF;QACD,iBAAiB;YACf,CAAC,CAAC,OAAO,CAAC;gBACN,eAAe,EAAE,eAAe;aACjC,CAAC;YACJ,CAAC,CAAC,KAAK;KACV,CAAC;AACJ,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type { NormalizedOutputOptions } from \"rollup\";\nimport type { PluginOption } from \"vite\";\n\nimport virtual from \"@rollup/plugin-virtual\";\n\nconst ID_PREFIX = `/@id/`;\n\nexport const extraDependencies: Record<string, string> = {\n \"@hv/uikit-icons/\": \"./icons/\"\n};\n\n/**\n * Auxiliary function to get the extraDependencies string\n * @returns a string with the extraDependencies content separated by commas\n */\nexport const getExtraDependenciesString = (): string => {\n let extraDependenciesString = \"\";\n // eslint-disable-next-line no-restricted-syntax, guard-for-in\n for (const key in extraDependencies) {\n extraDependenciesString += `\\\\\"${key}\\\\\": \\\\\"${extraDependencies[key]}\\\\\",`;\n }\n extraDependenciesString = extraDependenciesString.slice(0, -1);\n return extraDependenciesString;\n};\n\nfunction replaceIdPrefix(\n keys: (string | RegExp)[],\n packageName: string\n): PluginOption {\n const reg = new RegExp(\n `(/${packageName})?${ID_PREFIX}(${keys.join(\"|\")})`,\n \"g\"\n );\n\n return {\n name: \"vite-plugin-importmap-replace-idprefix\",\n enforce: \"pre\",\n apply: \"serve\",\n\n // while in dev, we need to prevent 'vite:import-analysis' on runtime modules\n transform: code =>\n reg.test(code) ? code.replace(reg, (m, s1, s2) => s2) : code,\n\n // and to say its resolved (as external)\n resolveId: (id: string) =>\n keys.some(key =>\n typeof key === \"string\" ? id.startsWith(key) : key.test(id)\n )\n ? {\n id,\n external: true\n }\n : undefined,\n\n // Avoid the warning: The following dependencies are imported but could not be resolved: [dependency] (imported by [sourceFile])\n load: (id: string) => {\n if (keys.includes(id)) {\n // Vite will try to resolve the modules even when externalized\n // In order to suppress the warning, a stub module is returned\n return \"export default {};\";\n }\n\n return undefined;\n }\n };\n}\n\n/**\n * Generate and injects the importmap tag into index.html\n * @param importmapElements The importmap elements to be included\n * @param sharedDependencies The shared packages (other than application bundles)\n */\nexport default function generateImportmap(\n importmapElements: Record<string, string>,\n packageName: string,\n sharedDependencies: string[],\n externalImportMap = false,\n placeholderEntryPoint = false\n): PluginOption {\n const keys = Object.keys(importmapElements);\n const devKeys = keys.filter(\n key => !sharedDependencies.some(lib => lib.startsWith(key))\n );\n\n let devMode = false;\n\n const importmapString = JSON.stringify(\n { imports: importmapElements },\n null,\n 2\n );\n\n const importmapScript = `const im = document.createElement('script');\nim.type = 'importmap';\nim.textContent = \\`${importmapString}\\`;\ndocument.currentScript.after(im);\n`;\n\n return [\n {\n name: \"vite-plugin-importmap\",\n enforce: \"pre\",\n\n // don't optimize / pre-transform deps that are in the importmap\n // except for react and react-dom when in dev mode\n config(config, { command }) {\n devMode = command !== \"build\";\n\n // vite docs says we can mutate the passed-in config directly\n // assigning to a new variable just to avoid the eslint warning\n const returnValue = config;\n\n // make sure optimizeDeps is defined\n returnValue.optimizeDeps = returnValue.optimizeDeps ?? {};\n\n returnValue.optimizeDeps.exclude = [\n ...(config.optimizeDeps?.exclude ?? []),\n ...(devMode ? devKeys : keys)\n ];\n\n if (devMode) {\n return;\n }\n\n // mark the modules referenced in the importmap as external\n const excludedModules = keys.map(key => {\n if (key.endsWith(\"/\")) {\n return new RegExp(`^${key}.*`);\n }\n\n return key;\n });\n\n console.info(\"Shared packages marked as external: \", excludedModules);\n\n // make sure build's rollupOptions is defined\n returnValue.build = returnValue.build ?? {};\n returnValue.build.rollupOptions = returnValue.build.rollupOptions ?? {};\n returnValue.build.rollupOptions.external =\n returnValue.build.rollupOptions.external ?? [];\n\n if (typeof returnValue.build.rollupOptions.external === \"function\") {\n // in case the developer has defined a custom external function\n // we wrap it and check our excluded modules first and call the original function if needed\n const originalExternal = returnValue.build.rollupOptions.external;\n\n returnValue.build.rollupOptions.external = (id, ...args) => {\n if (excludedModules.some(m => m === id)) {\n return true;\n }\n\n return originalExternal(id, ...args);\n };\n } else {\n // otherwise we just add our excluded modules to the list supplied by the developer\n const externalModules: (string | RegExp)[] = [];\n\n if (Array.isArray(returnValue.build.rollupOptions.external)) {\n externalModules.push(...returnValue.build.rollupOptions.external);\n } else {\n externalModules.push(returnValue.build.rollupOptions.external);\n }\n\n externalModules.push(...excludedModules);\n\n returnValue.build.rollupOptions.external = externalModules;\n }\n },\n\n // while in dev, we need to prevent 'vite:import-analysis' on runtime modules\n // and also to say they're resolved (as external)\n // (it will still output an error in the console, but it won't break)\n // known issue: https://github.com/vitejs/vite/issues/11633\n configResolved(resolvedConfig) {\n if (!devMode) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore an hack: we want to add the plugin only after the config is resolved\n resolvedConfig.plugins.push(replaceIdPrefix(devKeys, packageName));\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(options: NormalizedOutputOptions) {\n if (!externalImportMap || placeholderEntryPoint) {\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 // support for external import maps isn't yet available (https://github.com/WICG/import-maps/issues/235)\n // workaround: https://github.com/WICG/import-maps/issues/235#issuecomment-1002340944\n fs.writeFileSync(\n path.resolve(targetDir, \"importmap.js\"),\n importmapScript\n );\n },\n\n // inject the importmap script and also the es-module-shims script\n transformIndexHtml: {\n order: \"post\",\n handler: html => ({\n html,\n tags: [\n {\n tag: \"script\",\n attrs: { async: true, src: \"./bundles/es-module-shims.js\" },\n injectTo: \"head-prepend\"\n },\n externalImportMap\n ? {\n tag: \"script\",\n attrs: { src: \"./importmap.js\" },\n injectTo: \"head-prepend\"\n }\n : {\n tag: \"script\",\n attrs: { type: \"importmap\" },\n injectTo: \"head-prepend\",\n children: placeholderEntryPoint\n ? \"%%APPSHELL_IMPORTMAP%%\"\n : importmapString\n }\n ]\n })\n }\n },\n externalImportMap\n ? virtual({\n \"/importmap.js\": importmapScript\n })\n : false\n ];\n}\n"]}
1
+ {"version":3,"file":"vite-importmap-plugin.js","sourceRoot":"","sources":["../src/vite-importmap-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAKxB,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAE7C,MAAM,SAAS,GAAG,OAAO,CAAC;AAE1B,MAAM,CAAC,MAAM,iBAAiB,GAA2B;IACvD,kBAAkB,EAAE,UAAU;CAC/B,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAW,EAAE;IACrD,IAAI,uBAAuB,GAAG,EAAE,CAAC;IACjC,8DAA8D;IAC9D,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACpC,uBAAuB,IAAI,MAAM,GAAG,WAAW,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC;IAC9E,CAAC;IACD,uBAAuB,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/D,OAAO,uBAAuB,CAAC;AACjC,CAAC,CAAC;AAEF,SAAS,eAAe,CACtB,IAAyB,EACzB,WAAmB;IAEnB,MAAM,GAAG,GAAG,IAAI,MAAM,CACpB,KAAK,WAAW,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EACnD,GAAG,CACJ,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,wCAAwC;QAC9C,OAAO,EAAE,KA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,IAAI,CAAC,EAAE,CAAC,CAAC;oBAChB,IAAI;oBACJ,IAAI,EAAE;wBACJ;4BACE,GAAG,EAAE,QAAQ;4BACb,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,8BAA8B,EAAE;4BAC3D,QAAQ,EAAE,cAAc;yBACzB;wBACD,iBAAiB;4BACf,CAAC,CAAC;gCACE,GAAG,EAAE,QAAQ;gCACb,KAAK,EAAE,EAAE,GAAG,EAAE,gBAAgB,EAAE;gCAChC,QAAQ,EAAE,cAAc;6BACzB;4BACH,CAAC,CAAC;gCACE,GAAG,EAAE,QAAQ;gCACb,KAAK,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;gCAC5B,QAAQ,EAAE,cAAc;gCACxB,QAAQ,EAAE,qBAAqB;oCAC7B,CAAC,CAAC,wBAAwB;oCAC1B,CAAC,CAAC,eAAe;6BACpB;qBACN;iBACF,CAAC;aACH;SACF;QACD,iBAAiB;YACf,CAAC,CAAC,OAAO,CAAC;gBACN,eAAe,EAAE,eAAe;aACjC,CAAC;YACJ,CAAC,CAAC,KAAK;KACV,CAAC;AACJ,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type { NormalizedOutputOptions } from \"rollup\";\nimport type { PluginOption } from \"vite\";\n\nimport virtual from \"@rollup/plugin-virtual\";\n\nconst ID_PREFIX = `/@id/`;\n\nexport const extraDependencies: Record<string, string> = {\n \"@hv/uikit-icons/\": \"./icons/\"\n};\n\n/**\n * Auxiliary function to get the extraDependencies string\n * @returns a string with the extraDependencies content separated by commas\n */\nexport const getExtraDependenciesString = (): string => {\n let extraDependenciesString = \"\";\n // eslint-disable-next-line no-restricted-syntax, guard-for-in\n for (const key in extraDependencies) {\n extraDependenciesString += `\\\\\"${key}\\\\\": \\\\\"${extraDependencies[key]}\\\\\",`;\n }\n extraDependenciesString = extraDependenciesString.slice(0, -1);\n return extraDependenciesString;\n};\n\nfunction replaceIdPrefix(\n keys: (string | RegExp)[],\n packageName: string\n): PluginOption {\n const reg = new RegExp(\n `(/${packageName})?${ID_PREFIX}(${keys.join(\"|\")})`,\n \"g\"\n );\n\n return {\n name: \"vite-plugin-importmap-replace-idprefix\",\n enforce: \"pre\",\n apply: \"serve\",\n\n // while in dev, we need to prevent 'vite:import-analysis' on runtime modules\n transform: code =>\n reg.test(code) ? code.replace(reg, (m, s1, s2) => s2) : code,\n\n // and to say its resolved (as external)\n resolveId: (id: string) =>\n keys.some(key =>\n typeof key === \"string\" ? id.startsWith(key) : key.test(id)\n )\n ? {\n id,\n external: true\n }\n : undefined,\n\n // Avoid the warning: The following dependencies are imported but could not be resolved: [dependency] (imported by [sourceFile])\n load: (id: string) => {\n if (keys.includes(id)) {\n // Vite will try to resolve the modules even when externalized\n // In order to suppress the warning, a stub module is returned\n return \"export default {};\";\n }\n\n return undefined;\n }\n };\n}\n\n/**\n * Generate and injects the importmap tag into index.html\n * @param importmapElements The importmap elements to be included\n * @param packageName The application name identifier\n * @param sharedDependencies The shared packages (other than application bundles)\n * @param externalImportMap Flag to control if the importmap should be externalized\n * @param placeholderEntryPoint Flag to control if the importmap should be a placeholder\n */\nexport default function generateImportmap(\n importmapElements: Record<string, string>,\n packageName: string,\n sharedDependencies: string[],\n externalImportMap = false,\n placeholderEntryPoint = false\n): PluginOption {\n const keys = Object.keys(importmapElements);\n const devKeys = keys.filter(\n key => !sharedDependencies.some(lib => lib.startsWith(key))\n );\n\n let devMode = false;\n\n const importmapString = JSON.stringify(\n { imports: importmapElements },\n null,\n 2\n );\n\n const importmapScript = `const im = document.createElement('script');\nim.type = 'importmap';\nim.textContent = \\`${importmapString}\\`;\ndocument.currentScript.after(im);\n`;\n\n return [\n {\n name: \"vite-plugin-importmap\",\n enforce: \"pre\",\n\n // don't optimize / pre-transform deps that are in the importmap\n // except for react and react-dom when in dev mode\n config(config, { command }) {\n devMode = command !== \"build\";\n\n // vite docs says we can mutate the passed-in config directly\n // assigning to a new variable just to avoid the eslint warning\n const returnValue = config;\n\n // make sure optimizeDeps is defined\n returnValue.optimizeDeps = returnValue.optimizeDeps ?? {};\n\n returnValue.optimizeDeps.exclude = [\n ...(config.optimizeDeps?.exclude ?? []),\n ...(devMode ? devKeys : keys)\n ];\n\n if (devMode) {\n return;\n }\n\n // mark the modules referenced in the importmap as external\n const excludedModules = keys.map(key => {\n if (key.endsWith(\"/\")) {\n return new RegExp(`^${key}.*`);\n }\n\n return key;\n });\n\n console.info(\"Shared packages marked as external: \", excludedModules);\n\n // make sure build's rollupOptions is defined\n returnValue.build = returnValue.build ?? {};\n returnValue.build.rollupOptions = returnValue.build.rollupOptions ?? {};\n returnValue.build.rollupOptions.external =\n returnValue.build.rollupOptions.external ?? [];\n\n if (typeof returnValue.build.rollupOptions.external === \"function\") {\n // in case the developer has defined a custom external function\n // we wrap it and check our excluded modules first and call the original function if needed\n const originalExternal = returnValue.build.rollupOptions.external;\n\n returnValue.build.rollupOptions.external = (id, ...args) => {\n if (excludedModules.some(m => m === id)) {\n return true;\n }\n\n return originalExternal(id, ...args);\n };\n } else {\n // otherwise we just add our excluded modules to the list supplied by the developer\n const externalModules: (string | RegExp)[] = [];\n\n if (Array.isArray(returnValue.build.rollupOptions.external)) {\n externalModules.push(...returnValue.build.rollupOptions.external);\n } else {\n externalModules.push(returnValue.build.rollupOptions.external);\n }\n\n externalModules.push(...excludedModules);\n\n returnValue.build.rollupOptions.external = externalModules;\n }\n },\n\n // while in dev, we need to prevent 'vite:import-analysis' on runtime modules\n // and also to say they're resolved (as external)\n // (it will still output an error in the console, but it won't break)\n // known issue: https://github.com/vitejs/vite/issues/11633\n configResolved(resolvedConfig) {\n if (!devMode) {\n return;\n }\n\n // @ts-expect-error an hack: we want to add the plugin only after the config is resolved\n resolvedConfig.plugins.push(replaceIdPrefix(devKeys, packageName));\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 (!externalImportMap || placeholderEntryPoint) {\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 // support for external import maps isn't yet available (https://github.com/WICG/import-maps/issues/235)\n // workaround: https://github.com/WICG/import-maps/issues/235#issuecomment-1002340944\n fs.writeFileSync(\n path.resolve(targetDir, \"importmap.js\"),\n importmapScript\n );\n },\n\n // inject the importmap script and also the es-module-shims script\n transformIndexHtml: {\n order: \"post\",\n handler: html => ({\n html,\n tags: [\n {\n tag: \"script\",\n attrs: { async: true, src: \"./bundles/es-module-shims.js\" },\n injectTo: \"head-prepend\"\n },\n externalImportMap\n ? {\n tag: \"script\",\n attrs: { src: \"./importmap.js\" },\n injectTo: \"head-prepend\"\n }\n : {\n tag: \"script\",\n attrs: { type: \"importmap\" },\n injectTo: \"head-prepend\",\n children: placeholderEntryPoint\n ? \"%%APPSHELL_IMPORTMAP%%\"\n : importmapString\n }\n ]\n })\n }\n },\n externalImportMap\n ? virtual({\n \"/importmap.js\": importmapScript\n })\n : false\n ];\n}\n"]}
@@ -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;AAc7C,OAAO,EACL,iBAAiB,EAIlB,MAAM,mBAAmB,CAAC;AAc3B,MAAM,MAAM,qBAAqB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAErD,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAA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C;;;;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;;;;;;;;;;;OAWG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,iBAAS,kBAAkB,CACzB,IAAI,GAAE,yBAA8B,EACpC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,YAAY,CAkLd;AAED,eAAe,kBAAkB,CAAC"}
@@ -101,12 +101,11 @@ function appShellVitePlugin(opts = {}, env = {}) {
101
101
  acc[`${key}/`] = value;
102
102
  return acc;
103
103
  }, {}),
104
- [`${packageJson.name}/`]: appShellConfiguration.baseUrl ?? "/",
104
+ [`${packageJson.name}/`]: "./",
105
105
  ...(devMode
106
106
  ? modules.concat(autoViewsBundles).reduce((acc, module) => {
107
107
  const finalModule = getFinalModuleName(module);
108
- acc[`${packageJson.name}/${finalModule}.js`] =
109
- (appShellConfiguration.baseUrl ?? "/") + module;
108
+ acc[`${packageJson.name}/${finalModule}.js`] = `./${module}`;
110
109
  return acc;
111
110
  }, {})
112
111
  : {})
@@ -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,EAAg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AC,gBAAgB,CAAC,CACjC;QAED,wDAAwD;QACxD,cAAc,EAAE;QAEhB,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\";\nimport fixCrossOrigin from \"./vite-crossorigin-fix-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 packageJson.name,\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 const module = resolveModule(dep.bundleSrc);\n try {\n return [module, resolveModule(`${dep.bundleSrc}.map`)];\n } catch {\n return [module];\n }\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 // allow crossorigin=\"use-credentials\" in the index.html\n fixCrossOrigin(),\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;AACvE,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAE9D,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,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K,CAAC,GAAG,KAAK,MAAM,EAAE,CAAC;oBAC7D,OAAO,GAAG,CAAC;gBACb,CAAC,EACD,EAA4B,CAC7B;gBACH,CAAC,CAAC,EAAE,CAAC;SACR,EACD,WAAW,CAAC,IAAI,EAChB,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,EACnE,iBAAiB,IAAI,eAAe,EACpC,kBAAkB,CACnB;QAED,4CAA4C;QAC5C,eAAe,IAAI,cAAc,EAAE;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,wDAAwD;QACxD,cAAc,EAAE;QAEhB,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\";\nimport fixCrossOrigin from \"./vite-crossorigin-fix-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 packageJson.name,\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 const module = resolveModule(dep.bundleSrc);\n try {\n return [module, resolveModule(`${dep.bundleSrc}.map`)];\n } catch {\n return [module];\n }\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\n ...(devMode\n ? modules.concat(autoViewsBundles).reduce(\n (acc, module) => {\n const finalModule = getFinalModuleName(module);\n acc[`${packageJson.name}/${finalModule}.js`] = `./${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 // allow crossorigin=\"use-credentials\" in the index.html\n fixCrossOrigin(),\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 +1 @@
1
- {"version":3,"file":"vite-watch-config-plugin.d.ts","sourceRoot":"","sources":["../src/vite-watch-config-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AA2CzE,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,cAAc,EAAE,gBAAgB,EAChC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,kBAAkB,CAAC,EAAE,MAAM,EAC3B,oBAAoB,CAAC,EAAE,MAAM,GAC5B,YAAY,CA+Cd"}
1
+ {"version":3,"file":"vite-watch-config-plugin.d.ts","sourceRoot":"","sources":["../src/vite-watch-config-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AA2CzE,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,cAAc,EAAE,gBAAgB,EAChC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,kBAAkB,CAAC,EAAE,MAAM,EAC3B,oBAAoB,CAAC,EAAE,MAAM,GAC5B,YAAY,CA8Cd"}
@@ -1,7 +1,7 @@
1
1
  import path from "path";
2
2
  import { require } from "./nodeModule.js";
3
- import { getPublicPath, replaceSelf } from "./config-utils.js";
4
3
  import { replaceReferencesToSelf } from "./vite-configuration-processor-plugin.js";
4
+ import { replaceSelf } from "./config-utils.js";
5
5
  const prepareConfigForDevMode = (config, selfAppName) => {
6
6
  const { mainPanel, header, theming, providers } = config;
7
7
  const replacedConfig = {
@@ -59,8 +59,7 @@ export default function serveAppShellConfig(appShellConfig, root, selfAppName, a
59
59
  server.watcher.on("unlink", restartServer2);
60
60
  server.watcher.on("add", restartServer2);
61
61
  }
62
- const publicPath = getPublicPath(appShellConfig);
63
- server.middlewares.use(`${publicPath}app-shell.config.json`, async (req, res) => {
62
+ server.middlewares.use(`${server.config.base}app-shell.config.json`, async (req, res) => {
64
63
  res.end(JSON.stringify(prepareConfigForDevMode(appShellConfig, selfAppName)));
65
64
  });
66
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"vite-watch-config-plugin.js","sourceRoot":"","sources":["../src/vite-watch-config-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;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EAAE,CAAC;gBACjC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC;gBAC7D,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;gBAC5C,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;YAC3C,CAAC;YAED,MAAM,UAAU,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;YACjD,MAAM,CAAC,WAAW,CAAC,GAAG,CACpB,GAAG,UAAU,uBAAuB,EACpC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;gBACjB,GAAG,CAAC,GAAG,CACL,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC,CACrE,CAAC;YACJ,CAAC,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import path from \"path\";\n\nimport type { PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport { require } from \"./nodeModule.js\";\nimport { getPublicPath, replaceSelf } from \"./config-utils.js\";\nimport { replaceReferencesToSelf } from \"./vite-configuration-processor-plugin.js\";\n\nconst prepareConfigForDevMode = (\n config: HvAppShellConfig,\n selfAppName: string\n) => {\n const { mainPanel, header, theming, providers } = config;\n const replacedConfig: HvAppShellConfig = {\n ...config\n };\n const self = `${selfAppName}/`;\n // Main panel - Views\n if (mainPanel?.views && replacedConfig.mainPanel) {\n replacedConfig.mainPanel.views = replaceReferencesToSelf(\n mainPanel.views,\n selfAppName\n );\n }\n // Header - Actions\n if (header?.actions && replacedConfig.header) {\n replacedConfig.header.actions = replaceReferencesToSelf(\n header.actions,\n selfAppName\n );\n }\n // Theming\n if (theming?.themes && replacedConfig.theming) {\n replacedConfig.theming.themes = theming.themes?.map(theme => {\n return replaceSelf(theme, self);\n });\n }\n // Providers\n if (providers) {\n replacedConfig.providers = replaceReferencesToSelf(providers, selfAppName);\n }\n\n return replacedConfig;\n};\n\nexport default function serveAppShellConfig(\n appShellConfig: HvAppShellConfig,\n root: string,\n selfAppName: string,\n appShellConfigFile?: string,\n automaticViewsFolder?: string\n): PluginOption {\n return {\n name: \"vite-plugin-watch-app-shell-config\",\n apply: \"serve\",\n\n configureServer(server) {\n const restartServer = (file: string) => {\n if (appShellConfigFile != null && file.endsWith(appShellConfigFile)) {\n console.info(\"App Shell configuration file changed. Reloading...\");\n delete require.cache[require.resolve(appShellConfigFile)];\n server\n .restart()\n .catch(e => console.error(`Restart failed with: ${e}`));\n }\n };\n\n const restartServer2 = (file: string) => {\n if (automaticViewsFolder != null && /\\/index\\.[tj]sx?$/.exec(file)) {\n console.info(\"Automatic views folder changed. Reloading...\");\n server\n .restart()\n .catch(e => console.error(`Restart failed with: ${e}`));\n }\n };\n\n if (appShellConfigFile != null) {\n server.watcher.add(appShellConfigFile);\n server.watcher.on(\"change\", restartServer);\n }\n\n if (automaticViewsFolder != null) {\n server.watcher.add(path.resolve(root, automaticViewsFolder));\n server.watcher.on(\"unlink\", restartServer2);\n server.watcher.on(\"add\", restartServer2);\n }\n\n const publicPath = getPublicPath(appShellConfig);\n server.middlewares.use(\n `${publicPath}app-shell.config.json`,\n async (req, res) => {\n res.end(\n JSON.stringify(prepareConfigForDevMode(appShellConfig, selfAppName))\n );\n }\n );\n }\n };\n}\n"]}
1
+ {"version":3,"file":"vite-watch-config-plugin.js","sourceRoot":"","sources":["../src/vite-watch-config-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,uBAAuB,GAAG,CAC9B,MAA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CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;YAC3C,CAAC;YAED,MAAM,CAAC,WAAW,CAAC,GAAG,CACpB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,uBAAuB,EAC5C,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;gBACjB,GAAG,CAAC,GAAG,CACL,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC,CACrE,CAAC;YACJ,CAAC,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import path from \"path\";\n\nimport type { PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport { require } from \"./nodeModule.js\";\nimport { replaceReferencesToSelf } from \"./vite-configuration-processor-plugin.js\";\nimport { replaceSelf } from \"./config-utils.js\";\n\nconst prepareConfigForDevMode = (\n config: HvAppShellConfig,\n selfAppName: string\n) => {\n const { mainPanel, header, theming, providers } = config;\n const replacedConfig: HvAppShellConfig = {\n ...config\n };\n const self = `${selfAppName}/`;\n // Main panel - Views\n if (mainPanel?.views && replacedConfig.mainPanel) {\n replacedConfig.mainPanel.views = replaceReferencesToSelf(\n mainPanel.views,\n selfAppName\n );\n }\n // Header - Actions\n if (header?.actions && replacedConfig.header) {\n replacedConfig.header.actions = replaceReferencesToSelf(\n header.actions,\n selfAppName\n );\n }\n // Theming\n if (theming?.themes && replacedConfig.theming) {\n replacedConfig.theming.themes = theming.themes?.map(theme => {\n return replaceSelf(theme, self);\n });\n }\n // Providers\n if (providers) {\n replacedConfig.providers = replaceReferencesToSelf(providers, selfAppName);\n }\n\n return replacedConfig;\n};\n\nexport default function serveAppShellConfig(\n appShellConfig: HvAppShellConfig,\n root: string,\n selfAppName: string,\n appShellConfigFile?: string,\n automaticViewsFolder?: string\n): PluginOption {\n return {\n name: \"vite-plugin-watch-app-shell-config\",\n apply: \"serve\",\n\n configureServer(server) {\n const restartServer = (file: string) => {\n if (appShellConfigFile != null && file.endsWith(appShellConfigFile)) {\n console.info(\"App Shell configuration file changed. Reloading...\");\n delete require.cache[require.resolve(appShellConfigFile)];\n server\n .restart()\n .catch(e => console.error(`Restart failed with: ${e}`));\n }\n };\n\n const restartServer2 = (file: string) => {\n if (automaticViewsFolder != null && /\\/index\\.[tj]sx?$/.exec(file)) {\n console.info(\"Automatic views folder changed. Reloading...\");\n server\n .restart()\n .catch(e => console.error(`Restart failed with: ${e}`));\n }\n };\n\n if (appShellConfigFile != null) {\n server.watcher.add(appShellConfigFile);\n server.watcher.on(\"change\", restartServer);\n }\n\n if (automaticViewsFolder != null) {\n server.watcher.add(path.resolve(root, automaticViewsFolder));\n server.watcher.on(\"unlink\", restartServer2);\n server.watcher.on(\"add\", restartServer2);\n }\n\n server.middlewares.use(\n `${server.config.base}app-shell.config.json`,\n async (req, res) => {\n res.end(\n JSON.stringify(prepareConfigForDevMode(appShellConfig, selfAppName))\n );\n }\n );\n }\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hitachivantara/app-shell-vite-plugin",
3
- "version": "1.5.2",
3
+ "version": "1.6.1",
4
4
  "description": "AppShell Vite Plugin",
5
5
  "author": "Hitachi Vantara - Boba Fett Team",
6
6
  "license": "Apache-2.0",
@@ -38,8 +38,8 @@
38
38
  "dependencies": {
39
39
  "@emotion/cache": "^11.11.0",
40
40
  "@emotion/react": "^11.11.1",
41
- "@hitachivantara/app-shell-shared": "1.3.0",
42
- "@hitachivantara/app-shell-ui": "1.5.0",
41
+ "@hitachivantara/app-shell-shared": "1.4.0",
42
+ "@hitachivantara/app-shell-ui": "1.6.0",
43
43
  "@hitachivantara/uikit-react-icons": "^5.10.1",
44
44
  "@hitachivantara/uikit-react-shared": "^5.1.43",
45
45
  "@rollup/plugin-commonjs": "^25.0.7",
@@ -64,5 +64,5 @@
64
64
  "peerDependencies": {
65
65
  "vite": "^4.1.4 || ^5.0.4"
66
66
  },
67
- "gitHead": "0e7f62ae71bf4f6626445c977518a90be50a7e1c"
67
+ "gitHead": "a5e510ddd0eb8aeed19ea2bf8005918bb7e3b04f"
68
68
  }