@trackunit/iris-app-webpack-plugin 0.0.196 → 0.0.197
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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.0.197](https://github.com/Trackunit/manager/compare/iris-app-webpack-plugin/0.0.196...iris-app-webpack-plugin/0.0.197) (2024-05-21)
|
|
6
|
+
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `iris-app-api` updated to version `0.0.196`
|
|
5
10
|
## [0.0.196](https://github.com/Trackunit/manager/compare/iris-app-webpack-plugin/0.0.195...iris-app-webpack-plugin/0.0.196) (2024-05-13)
|
|
6
11
|
|
|
7
12
|
### Dependency Updates
|
package/package.json
CHANGED
|
@@ -75,7 +75,7 @@ class TrackunitIrisAppWebpackPlugin {
|
|
|
75
75
|
if (!stats.hasErrors()) {
|
|
76
76
|
setTimeout(() => {
|
|
77
77
|
// eslint-disable-next-line no-console
|
|
78
|
-
console.log(GREEN, "\n✨ Iris App is now started, check it out ✨\nhttps://new.manager.trackunit.com/iris-sdk-portal
|
|
78
|
+
console.log(GREEN, "\n✨ Iris App is now started, check it out ✨\nhttps://new.manager.trackunit.com/iris-sdk-portal#runLocal\n", RESET);
|
|
79
79
|
}, 0);
|
|
80
80
|
}
|
|
81
81
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrackunitIrisAppWebpackPlugin.js","sourceRoot":"","sources":["../../../../../../libs/iris-app-sdk/iris-app-webpack-plugin/src/lib/TrackunitIrisAppWebpackPlugin.ts"],"names":[],"mappings":";;;;AAAA,0DAUiC;AACjC,mCAAqC;AACrC,2CAAoC;AACpC,+CAAyB;AACzB,mDAA6B;AAC7B,qCAA+B;AAS/B,MAAM,KAAK,GAAG,SAAS,C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AAW,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC/D,IAAI,YAAY,CAAC,MAAM,EAAE,CAAC;oBACxB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;gBACjF,CAAC;qBAAM,CAAC;oBACN,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;gBAClD,CAAC;gBACD,oEAAoE;gBACpE,oDAAoD;gBACpD,WAAW,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YAC3D,CAAC,CAAA,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AArMD,sEAqMC","sourcesContent":["import {\n CustomFieldTranslationArray,\n irisAppCspInput,\n irisAppDefaultCsp,\n IrisAppManifest,\n isCustomFieldTranslationArray,\n languageKeys,\n TranslationKey,\n TranslationLanguageKeys,\n Translations,\n} from \"@trackunit/iris-app-api\";\nimport { randomBytes } from \"crypto\";\nimport { getCSP } from \"csp-header\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { exit } from \"process\";\nimport * as wp from \"webpack\";\n\ninterface TrackunitIrisAppWebpackPluginOptions {\n nxRootDir: string;\n appDir: string;\n manifest: IrisAppManifest;\n}\n\nconst RESET = \"\\x1b[0m\";\nconst GREEN = \"\\x1b[32m\";\nconst RED = \"\\x1b[31m\";\nconst YELLOW = \"\\x1b[33m\";\n\nconst convertTranslationKeyIfNeeded = (\n translationObj: string | Translations | TranslationKey | null | undefined,\n srcDir: string\n) => {\n if (isTranslationKey(translationObj)) {\n const translationKey = translationObj.key;\n\n const enTranslationFilePath = path.join(srcDir, \"locales\", \"en\", \"translation.json\");\n if (!fs.existsSync(enTranslationFilePath)) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation file not found for: \"${translationObj.key}\" looked here: ${enTranslationFilePath}`,\n RESET\n );\n exit(1);\n }\n const enTranslations = JSON.parse(fs.readFileSync(enTranslationFilePath, \"utf8\"));\n if (!enTranslations[translationKey]) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation not found for: \"${translationObj.key}\" looked here: ${enTranslationFilePath}`,\n RESET\n );\n exit(1);\n }\n\n languageKeys.forEach(languageCode => {\n const translationFilePath = path.join(srcDir, \"locales\", languageCode, \"translation.json\");\n if (fs.existsSync(translationFilePath)) {\n const translations = JSON.parse(fs.readFileSync(translationFilePath, \"utf8\"));\n // Here we substitute the translation key with the actual translation\n (translationObj as unknown as Translations)[languageCode] = translations[translationKey];\n } else {\n // eslint-disable-next-line no-console\n console.log(\n YELLOW,\n ` ✨ Warning translation file not found for: \"${translationObj.key}\" looked here: ${translationFilePath}`,\n RESET\n );\n }\n });\n delete (translationObj as { key?: string }).key;\n }\n};\n\nconst isTranslationKey = (\n object: string | Translations | TranslationKey | undefined | null\n): object is TranslationKey => {\n return !!(object as { key?: string })?.key;\n};\n\n/**\n * Webpack plugin that generates a manifest.json file\n */\nexport class TrackunitIrisAppWebpackPlugin {\n /**\n * @param options - Plugin options\n * @param {string} options.appDir - Directory path where the app resides\n * @param {object} options.manifest - Object containing the app's manifest\n */\n public constructor(private options: TrackunitIrisAppWebpackPluginOptions) {}\n\n /**\n Webpack plugin for generating a Markdown file from app manifest and index HTML file.\n */\n public apply(compiler: wp.Compiler) {\n const pluginName = TrackunitIrisAppWebpackPlugin.name;\n\n // webpack module instance can be accessed from the compiler object,\n // this ensures that correct version of the module is used\n // (do not require/import the webpack or any symbols from it directly).\n const { webpack } = compiler;\n\n // Compilation object gives us reference to some useful constants.\n const { Compilation } = webpack;\n\n // RawSource is one of the \"sources\" classes that should be used\n // to represent asset sources in compilation.\n const { RawSource } = webpack.sources;\n\n compiler.hooks.done.tap(\"AfterBuildPlugin\", stats => {\n if (!stats.hasErrors()) {\n setTimeout(() => {\n // eslint-disable-next-line no-console\n console.log(\n GREEN,\n \"\\n✨ Iris App is now started, check it out ✨\\nhttps://new.manager.trackunit.com/iris-sdk-portal/main#runLocal\\n\",\n RESET\n );\n }, 0);\n }\n });\n\n // Tapping to the \"thisCompilation\" hook in order to further tap\n // to the compilation process on an earlier stage.\n compiler.hooks.thisCompilation.tap(pluginName, (compilation: wp.Compilation) => {\n // Tapping to the assets processing pipeline on a specific stage.\n compilation.contextDependencies.add(this.options.appDir);\n compilation.hooks.processAssets.tap(\n {\n name: pluginName,\n\n // Using one of the later asset processing stages to ensure\n // that all assets were already added to the compilation by other plugins.\n stage: Compilation.PROCESS_ASSETS_STAGE_DERIVED,\n },\n async assets => {\n // \"assets\" is an object that contains all assets\n // in the compilation, the keys of the object are pathnames of the assets\n // and the values are file sources.\n\n // Iterating over all the assets and\n // generating content for our Markdown file.\n if (!this.options?.manifest) {\n throw Error(\"you must provide a app manifest\");\n }\n const manifest = this.options.manifest;\n const indexContents = fs.readFileSync(path.join(__dirname, \"index.html\"), \"utf8\");\n\n const manifestJson = this.options.manifest;\n\n const appSrc = path.join(this.options.appDir, \"src\");\n this.options.manifest.customFieldDefinitions?.forEach(customFieldDefinition => {\n if (isCustomFieldTranslationArray(customFieldDefinition.translations)) {\n const foundEn = customFieldDefinition.translations.find(translation => translation.language === \"en\");\n if (!foundEn) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation not found for language \"en\" you must supply the english translation for custom field: ${customFieldDefinition.key}`,\n RESET\n );\n exit(1);\n }\n } else {\n convertTranslationKeyIfNeeded(customFieldDefinition.translations.title, appSrc);\n convertTranslationKeyIfNeeded(customFieldDefinition.translations.description, appSrc);\n\n // now transform to array\n\n const titles: Translations = customFieldDefinition.translations.title as unknown as Translations;\n const descriptions: Translations = customFieldDefinition.translations\n .description as unknown as Translations;\n const keys = Object.keys(titles) as TranslationLanguageKeys[];\n\n const foundEn = keys.indexOf(\"en\") !== -1;\n if (!foundEn) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation not found for language \"en\" you must supply the english translation for custom field: ${customFieldDefinition.key}`,\n RESET\n );\n exit(1);\n }\n const translations: CustomFieldTranslationArray = [\n {\n language: \"en\",\n title: titles.en,\n description: descriptions.en,\n },\n ];\n\n keys.forEach(language => {\n if (language !== \"en\") {\n translations.push({\n language,\n title: titles[language]!,\n description: descriptions[language],\n });\n }\n });\n customFieldDefinition.translations = translations;\n }\n });\n\n manifestJson.extensions = this.options.manifest.extensions;\n this.options.manifest.extensions?.forEach(extension => {\n const translationKey =\n (extension.type !== \"IRIS_APP_SETTINGS_EXTENSION\" &&\n extension.type !== \"WIDGET_EXTENSION\" &&\n extension.menuItem?.name) ||\n null;\n convertTranslationKeyIfNeeded(translationKey, extension.sourceRoot);\n\n const headerTranslationKey =\n (extension.type === \"WIDGET_EXTENSION\" && extension.header && extension.header.name) || null;\n convertTranslationKeyIfNeeded(headerTranslationKey, extension.sourceRoot);\n\n if (extension.type === \"REPORT_EXTENSION\" && isTranslationKey(extension.menuItem?.description)) {\n const description = extension.menuItem.description;\n convertTranslationKeyIfNeeded(description, extension.sourceRoot);\n }\n if (extension.type === \"ASSET_HOME_EXTENSION\" || extension.type === \"FLEET_EXTENSION\") {\n if (extension.conditions?.brand) {\n if (Array.isArray(extension.conditions.brand)) {\n extension.conditions.brand.forEach(brand => {\n if (typeof brand !== \"string\") {\n brand.pattern = brand.pattern.toString();\n }\n });\n } else if (typeof extension.conditions.brand !== \"string\") {\n extension.conditions.brand.pattern = extension.conditions.brand.pattern.toString();\n }\n }\n if (extension.conditions?.model) {\n if (Array.isArray(extension.conditions.model)) {\n extension.conditions.model.forEach(model => {\n if (typeof model !== \"string\") {\n model.pattern = model.pattern.toString();\n }\n });\n } else if (typeof extension.conditions.model !== \"string\") {\n extension.conditions.model.pattern = extension.conditions.model.pattern.toString();\n }\n }\n }\n });\n\n manifestJson.extensions = this.options.manifest.extensions;\n compilation.emitAsset(\"manifest.json\", new RawSource(JSON.stringify(manifestJson, null, 2)));\n\n const packageJson = fs.readFileSync(`${this.options.appDir}/package.json`, \"utf8\");\n compilation.emitAsset(\"package.json\", new RawSource(packageJson));\n\n const scopeAndModuleNonce = randomBytes(16).toString(\"base64\");\n\n const csp = getCSP({\n directives: irisAppCspInput(manifest.validDomains, manifest.cspHeader),\n presets: {\n irisAppDefaultCsp,\n localDev: { \"connect-src\": [\"ws://localhost:8097/\"], \"script-src\": [`'nonce-${scopeAndModuleNonce}'`] },\n },\n });\n let html = indexContents.replace(\"{{cspContent}}\", csp);\n\n html = html.replace(\"{{nonce}}\", scopeAndModuleNonce);\n\n html = html.replace(\"{{scope}}\", JSON.parse(packageJson).name);\n if (manifestJson.scopes) {\n html = html.replace(\"{{manifestScopes}}\", JSON.stringify(manifestJson.scopes));\n } else {\n html = html.replace(\"{{manifestScopes}}\", \"[]\");\n }\n // Adding new asset to the compilation, so it would be automatically\n // generated by the webpack in the output directory.\n compilation.emitAsset(\"index.html\", new RawSource(html));\n }\n );\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TrackunitIrisAppWebpackPlugin.js","sourceRoot":"","sources":["../../../../../../libs/iris-app-sdk/iris-app-webpack-plugin/src/lib/TrackunitIrisAppWebpackPlugin.ts"],"names":[],"mappings":";;;;AAAA,0DAUiC;AACjC,mCAAqC;AACrC,2CAAoC;AACpC,+CAAyB;AACzB,mDAA6B;AAC7B,qCAA+B;AAS/B,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,MAAM,KAAK,GAAG,UAAU,CAAC;AACzB,MAAM,GAAG,GAAG,UAAU,CAAC;AACvB,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B,MAAM,6BAA6B,GAAG,CACpC,cAAyE,EACzE,MAAc,EACd,EAAE;IACF,IAAI,gBAAgB,CAAC,cAAc,CAAC,EAAE,CAAC;QACrC,MAAM,cAAc,GAAG,cAAc,CAAC,GAAG,CAAC;QAE1C,MAAM,qBA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OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;gBAClD,CAAC;gBACD,oEAAoE;gBACpE,oDAAoD;gBACpD,WAAW,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YAC3D,CAAC,CAAA,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AArMD,sEAqMC","sourcesContent":["import {\n CustomFieldTranslationArray,\n irisAppCspInput,\n irisAppDefaultCsp,\n IrisAppManifest,\n isCustomFieldTranslationArray,\n languageKeys,\n TranslationKey,\n TranslationLanguageKeys,\n Translations,\n} from \"@trackunit/iris-app-api\";\nimport { randomBytes } from \"crypto\";\nimport { getCSP } from \"csp-header\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { exit } from \"process\";\nimport * as wp from \"webpack\";\n\ninterface TrackunitIrisAppWebpackPluginOptions {\n nxRootDir: string;\n appDir: string;\n manifest: IrisAppManifest;\n}\n\nconst RESET = \"\\x1b[0m\";\nconst GREEN = \"\\x1b[32m\";\nconst RED = \"\\x1b[31m\";\nconst YELLOW = \"\\x1b[33m\";\n\nconst convertTranslationKeyIfNeeded = (\n translationObj: string | Translations | TranslationKey | null | undefined,\n srcDir: string\n) => {\n if (isTranslationKey(translationObj)) {\n const translationKey = translationObj.key;\n\n const enTranslationFilePath = path.join(srcDir, \"locales\", \"en\", \"translation.json\");\n if (!fs.existsSync(enTranslationFilePath)) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation file not found for: \"${translationObj.key}\" looked here: ${enTranslationFilePath}`,\n RESET\n );\n exit(1);\n }\n const enTranslations = JSON.parse(fs.readFileSync(enTranslationFilePath, \"utf8\"));\n if (!enTranslations[translationKey]) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation not found for: \"${translationObj.key}\" looked here: ${enTranslationFilePath}`,\n RESET\n );\n exit(1);\n }\n\n languageKeys.forEach(languageCode => {\n const translationFilePath = path.join(srcDir, \"locales\", languageCode, \"translation.json\");\n if (fs.existsSync(translationFilePath)) {\n const translations = JSON.parse(fs.readFileSync(translationFilePath, \"utf8\"));\n // Here we substitute the translation key with the actual translation\n (translationObj as unknown as Translations)[languageCode] = translations[translationKey];\n } else {\n // eslint-disable-next-line no-console\n console.log(\n YELLOW,\n ` ✨ Warning translation file not found for: \"${translationObj.key}\" looked here: ${translationFilePath}`,\n RESET\n );\n }\n });\n delete (translationObj as { key?: string }).key;\n }\n};\n\nconst isTranslationKey = (\n object: string | Translations | TranslationKey | undefined | null\n): object is TranslationKey => {\n return !!(object as { key?: string })?.key;\n};\n\n/**\n * Webpack plugin that generates a manifest.json file\n */\nexport class TrackunitIrisAppWebpackPlugin {\n /**\n * @param options - Plugin options\n * @param {string} options.appDir - Directory path where the app resides\n * @param {object} options.manifest - Object containing the app's manifest\n */\n public constructor(private options: TrackunitIrisAppWebpackPluginOptions) {}\n\n /**\n Webpack plugin for generating a Markdown file from app manifest and index HTML file.\n */\n public apply(compiler: wp.Compiler) {\n const pluginName = TrackunitIrisAppWebpackPlugin.name;\n\n // webpack module instance can be accessed from the compiler object,\n // this ensures that correct version of the module is used\n // (do not require/import the webpack or any symbols from it directly).\n const { webpack } = compiler;\n\n // Compilation object gives us reference to some useful constants.\n const { Compilation } = webpack;\n\n // RawSource is one of the \"sources\" classes that should be used\n // to represent asset sources in compilation.\n const { RawSource } = webpack.sources;\n\n compiler.hooks.done.tap(\"AfterBuildPlugin\", stats => {\n if (!stats.hasErrors()) {\n setTimeout(() => {\n // eslint-disable-next-line no-console\n console.log(\n GREEN,\n \"\\n✨ Iris App is now started, check it out ✨\\nhttps://new.manager.trackunit.com/iris-sdk-portal#runLocal\\n\",\n RESET\n );\n }, 0);\n }\n });\n\n // Tapping to the \"thisCompilation\" hook in order to further tap\n // to the compilation process on an earlier stage.\n compiler.hooks.thisCompilation.tap(pluginName, (compilation: wp.Compilation) => {\n // Tapping to the assets processing pipeline on a specific stage.\n compilation.contextDependencies.add(this.options.appDir);\n compilation.hooks.processAssets.tap(\n {\n name: pluginName,\n\n // Using one of the later asset processing stages to ensure\n // that all assets were already added to the compilation by other plugins.\n stage: Compilation.PROCESS_ASSETS_STAGE_DERIVED,\n },\n async assets => {\n // \"assets\" is an object that contains all assets\n // in the compilation, the keys of the object are pathnames of the assets\n // and the values are file sources.\n\n // Iterating over all the assets and\n // generating content for our Markdown file.\n if (!this.options?.manifest) {\n throw Error(\"you must provide a app manifest\");\n }\n const manifest = this.options.manifest;\n const indexContents = fs.readFileSync(path.join(__dirname, \"index.html\"), \"utf8\");\n\n const manifestJson = this.options.manifest;\n\n const appSrc = path.join(this.options.appDir, \"src\");\n this.options.manifest.customFieldDefinitions?.forEach(customFieldDefinition => {\n if (isCustomFieldTranslationArray(customFieldDefinition.translations)) {\n const foundEn = customFieldDefinition.translations.find(translation => translation.language === \"en\");\n if (!foundEn) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation not found for language \"en\" you must supply the english translation for custom field: ${customFieldDefinition.key}`,\n RESET\n );\n exit(1);\n }\n } else {\n convertTranslationKeyIfNeeded(customFieldDefinition.translations.title, appSrc);\n convertTranslationKeyIfNeeded(customFieldDefinition.translations.description, appSrc);\n\n // now transform to array\n\n const titles: Translations = customFieldDefinition.translations.title as unknown as Translations;\n const descriptions: Translations = customFieldDefinition.translations\n .description as unknown as Translations;\n const keys = Object.keys(titles) as TranslationLanguageKeys[];\n\n const foundEn = keys.indexOf(\"en\") !== -1;\n if (!foundEn) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation not found for language \"en\" you must supply the english translation for custom field: ${customFieldDefinition.key}`,\n RESET\n );\n exit(1);\n }\n const translations: CustomFieldTranslationArray = [\n {\n language: \"en\",\n title: titles.en,\n description: descriptions.en,\n },\n ];\n\n keys.forEach(language => {\n if (language !== \"en\") {\n translations.push({\n language,\n title: titles[language]!,\n description: descriptions[language],\n });\n }\n });\n customFieldDefinition.translations = translations;\n }\n });\n\n manifestJson.extensions = this.options.manifest.extensions;\n this.options.manifest.extensions?.forEach(extension => {\n const translationKey =\n (extension.type !== \"IRIS_APP_SETTINGS_EXTENSION\" &&\n extension.type !== \"WIDGET_EXTENSION\" &&\n extension.menuItem?.name) ||\n null;\n convertTranslationKeyIfNeeded(translationKey, extension.sourceRoot);\n\n const headerTranslationKey =\n (extension.type === \"WIDGET_EXTENSION\" && extension.header && extension.header.name) || null;\n convertTranslationKeyIfNeeded(headerTranslationKey, extension.sourceRoot);\n\n if (extension.type === \"REPORT_EXTENSION\" && isTranslationKey(extension.menuItem?.description)) {\n const description = extension.menuItem.description;\n convertTranslationKeyIfNeeded(description, extension.sourceRoot);\n }\n if (extension.type === \"ASSET_HOME_EXTENSION\" || extension.type === \"FLEET_EXTENSION\") {\n if (extension.conditions?.brand) {\n if (Array.isArray(extension.conditions.brand)) {\n extension.conditions.brand.forEach(brand => {\n if (typeof brand !== \"string\") {\n brand.pattern = brand.pattern.toString();\n }\n });\n } else if (typeof extension.conditions.brand !== \"string\") {\n extension.conditions.brand.pattern = extension.conditions.brand.pattern.toString();\n }\n }\n if (extension.conditions?.model) {\n if (Array.isArray(extension.conditions.model)) {\n extension.conditions.model.forEach(model => {\n if (typeof model !== \"string\") {\n model.pattern = model.pattern.toString();\n }\n });\n } else if (typeof extension.conditions.model !== \"string\") {\n extension.conditions.model.pattern = extension.conditions.model.pattern.toString();\n }\n }\n }\n });\n\n manifestJson.extensions = this.options.manifest.extensions;\n compilation.emitAsset(\"manifest.json\", new RawSource(JSON.stringify(manifestJson, null, 2)));\n\n const packageJson = fs.readFileSync(`${this.options.appDir}/package.json`, \"utf8\");\n compilation.emitAsset(\"package.json\", new RawSource(packageJson));\n\n const scopeAndModuleNonce = randomBytes(16).toString(\"base64\");\n\n const csp = getCSP({\n directives: irisAppCspInput(manifest.validDomains, manifest.cspHeader),\n presets: {\n irisAppDefaultCsp,\n localDev: { \"connect-src\": [\"ws://localhost:8097/\"], \"script-src\": [`'nonce-${scopeAndModuleNonce}'`] },\n },\n });\n let html = indexContents.replace(\"{{cspContent}}\", csp);\n\n html = html.replace(\"{{nonce}}\", scopeAndModuleNonce);\n\n html = html.replace(\"{{scope}}\", JSON.parse(packageJson).name);\n if (manifestJson.scopes) {\n html = html.replace(\"{{manifestScopes}}\", JSON.stringify(manifestJson.scopes));\n } else {\n html = html.replace(\"{{manifestScopes}}\", \"[]\");\n }\n // Adding new asset to the compilation, so it would be automatically\n // generated by the webpack in the output directory.\n compilation.emitAsset(\"index.html\", new RawSource(html));\n }\n );\n });\n }\n}\n"]}
|