@hitachivantara/app-shell-vite-plugin 0.18.0 → 0.18.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.
|
@@ -19,7 +19,7 @@ export const getExtraDependenciesString = () => {
|
|
|
19
19
|
return extraDependenciesString;
|
|
20
20
|
};
|
|
21
21
|
function replaceIdPrefix(keys, packageName) {
|
|
22
|
-
const reg = new RegExp(`(/${packageName})
|
|
22
|
+
const reg = new RegExp(`(/${packageName})?${ID_PREFIX}(${keys.join("|")})`, "g");
|
|
23
23
|
return {
|
|
24
24
|
name: "vite-plugin-importmap-replace-idprefix",
|
|
25
25
|
enforce: "pre",
|
|
@@ -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/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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CAAC,aAAa,CACd,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,EACvC,eAAe,CAChB,CAAC;YACJ,CAAC;YAED,kEAAkE;YAClE,kBAAkB,EAAE;gBAClB,KAAK,EAAE,MAAM;gBACb,OAAO,EAAE,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 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,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AAE,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 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitachivantara/app-shell-vite-plugin",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "AppShell Vite Plugin",
|
|
5
5
|
"author": "Hitachi Vantara - Boba Fett Team",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"@types/react-dom": "^18.0.11",
|
|
61
61
|
"tsc-watch": "^6.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "2e601e6925c5426f068e58cb740b6a5ddf8dc109"
|
|
64
64
|
}
|