@atlassian/clientside-extensions-webpack-plugin 5.1.0 → 5.1.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.
@@ -53,7 +53,16 @@ class ClientsideExtensionsWebpackPlugin {
53
53
  agg[fileName] = (0, entrypoint_1.generateEntrypointCode)(extensionOption);
54
54
  return agg;
55
55
  }, {});
56
- new webpack_virtual_modules_1.default(virtualModules).apply(compiler);
56
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
57
+ // @ts-expect-error This is non-standard and from rspack
58
+ if (compiler === null || compiler === void 0 ? void 0 : compiler.rspack) {
59
+ // eslint-disable-next-line import/no-extraneous-dependencies,node/no-extraneous-import
60
+ // @ts-expect-error Rspack doesn't expose the types for this
61
+ new require('@rspack/core').rspack.experiments.VirtualModulesPlugin(virtualModules).apply(compiler);
62
+ }
63
+ else {
64
+ new webpack_virtual_modules_1.default(virtualModules).apply(compiler);
65
+ }
57
66
  compiler.hooks.compilation.tap('Tap compilation for XML generation', (compilation) => {
58
67
  const webfragmentDescriptors = extensionsOptions.map((extensionOption) => (0, webfragmentDescriptor_1.default)(extensionOption));
59
68
  const webpageDescriptors = extensionsOptions.map((extensionOption) => (0, webpageDescriptor_1.default)(extensionOption));
@@ -1 +1 @@
1
- {"version":3,"file":"ClientsideExtensionsWebpackPlugin.js","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.ts"],"names":[],"mappings":";;AAAA,oDAAoB;AACpB,wDAAwB;AAExB,+BAA4B;AAC5B,yEAAyC;AACzC,6CAA+C;AAC/C,8FAA0D;AAC1D,oFAAmD;AAEnD,wEAA+C;AAE/C,sGAA8E;AAC9E,2FAAuG;AACvG,uDAAiF;AAGjF,mCAA2D;AAE3D,gFAA4E;AAY5E,MAAM,iCAAiC;IASnC,YAAY,UAA8C,EAAE;QACxD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,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;QAC7B,MAAM,WAAW,GAAG,cAAc,EAAE,EAAE,CAAC;QAEvC,OAAO;YACH,GAAG,QAAQ;YACX,SAAS;YACT,UAAU,EAAE,WAAW;YACvB,uBAAuB,EAAE,GAAG,SAAS,IAAI,GAAG,EAAE;SACjD,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,GAAW;QAC3C,OAAO,IAAA,mBAAS,EAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACJ;AAED,iBAAS,iCAAiC,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport type { Compilation, Compiler, WebpackPluginInstance } from 'webpack';\nimport { glob } from 'glob';\nimport kebabCase from 'lodash/kebabCase';\nimport { pd as PrettyData } from 'pretty-data';\nimport VirtualModulePlugin from 'webpack-virtual-modules';\nimport transformComment from './transform-comment';\nimport type { AnnotationKey, AnnotationParserFunction, AnnotationParserOptions, Annotations, RawAnnotations } from './annotations';\nimport annotationsParsers from './annotations';\n\nimport generateWebfragmentDescriptor from './generator/webfragmentDescriptor';\nimport generateWebpageDescriptor, { PAGE_DATA_PROVIDER_DATA_KEY } from './generator/webpageDescriptor';\nimport { generateEntrypointCode, isPageExtension } from './generator/entrypoint';\n\nimport type { ClientsideExtensionsManifest, ClientsideExtensionsOptions, DataProvider, IWrmPluginOptions } from './types';\nimport { debugLog, getKeyValue, isNotNull } from './utils';\n\nimport transformConditionToConditionMapObject from './generator/conditions';\n\n// Infer the type \"Source\" which is not exposed by Webpack\ntype Asset = Compilation['assets'] extends Record<string, infer S> ? S : never;\n\ninterface IClientsideExtensionsPluginOptions {\n pattern?: string;\n cwd?: string;\n xmlDescriptors?: string;\n ignore?: string[];\n}\n\nclass ClientsideExtensionsWebpackPlugin {\n private readonly pattern: string;\n\n private readonly cwd: string;\n\n private readonly outputFilename?: string;\n\n private manifests: ClientsideExtensionsManifest[];\n\n constructor(options: IClientsideExtensionsPluginOptions = {}) {\n if (!options.pattern) {\n throw new Error('No pattern was specified to match clientside extensions');\n }\n\n this.outputFilename = options.xmlDescriptors;\n this.pattern = options.pattern;\n this.cwd = options.cwd || process.cwd();\n const ignore = options.ignore || ['**/node_modules/**', 'build/**', 'target/**'];\n\n debugLog(`cwd: ${this.cwd}`);\n\n const globFoundFiles = ClientsideExtensionsWebpackPlugin.findFilesByPattern(this.pattern, this.cwd, ignore);\n\n debugLog(`Glob found (with the pattern: ${this.pattern}) these files: ${globFoundFiles}`);\n\n this.manifests = globFoundFiles\n .map((file) => ClientsideExtensionsWebpackPlugin.parseManifestFromComment(file, this.cwd))\n .filter(isNotNull);\n\n debugLog(`Found the following manifests ${JSON.stringify(this.manifests)}`);\n }\n\n public generateEntrypoints() {\n return this.manifests.reduce((agg, manifest) => {\n const id = ClientsideExtensionsWebpackPlugin.getIdFromManifestKey(manifest.key);\n agg[id] = ClientsideExtensionsWebpackPlugin.getFilenameForEntry(id);\n\n return agg;\n }, {} as { [key: string]: string });\n }\n\n apply(compiler: Compiler) {\n const wrmOptions = ClientsideExtensionsWebpackPlugin.getWrmWebpackPluginOptions(compiler);\n\n const extensionsOptions = this.manifests.map((manifest) => {\n return ClientsideExtensionsWebpackPlugin.manifestToPluginOptions(wrmOptions.pluginKey, manifest);\n });\n\n // side effect\n ClientsideExtensionsWebpackPlugin.addContextToEntrypoints(extensionsOptions, wrmOptions);\n\n // side effect\n ClientsideExtensionsWebpackPlugin.addDataProvidersToEntrypoints(extensionsOptions, wrmOptions);\n\n // side effect\n ClientsideExtensionsWebpackPlugin.addConditionToEntrypoint(extensionsOptions, wrmOptions);\n\n const virtualModules = extensionsOptions.reduce((agg, extensionOption) => {\n const fileName = ClientsideExtensionsWebpackPlugin.getFilenameForEntry(extensionOption.id);\n agg[fileName] = generateEntrypointCode(extensionOption);\n return agg;\n }, {} as Record<string, string>);\n new VirtualModulePlugin(virtualModules).apply(compiler);\n\n compiler.hooks.compilation.tap('Tap compilation for XML generation', (compilation) => {\n const webfragmentDescriptors = extensionsOptions.map((extensionOption) => generateWebfragmentDescriptor(extensionOption));\n const webpageDescriptors = extensionsOptions.map((extensionOption) => generateWebpageDescriptor(extensionOption));\n\n const descriptors = [...webfragmentDescriptors, ...webpageDescriptors].join('');\n const xmlDescriptors = PrettyData.xml(`<clientside-extension>${descriptors}</clientside-extension>`);\n\n const xmlDescriptorDirname = path.dirname(\n path.relative(compiler.options.output.path || '', this.outputFilename || wrmOptions.xmlDescriptors),\n );\n const xmlDescriptorFilename = path.basename(this.outputFilename || 'wr-generated-clientside-extensions.xml');\n const webpanelXmlDescriptorFilename = path.join(xmlDescriptorDirname, xmlDescriptorFilename);\n\n compilation.hooks.additionalAssets.tap('Generate clientside-extension XML', () => {\n compilation.assets[webpanelXmlDescriptorFilename] = {\n source: () => Buffer.from(xmlDescriptors),\n size: () => Buffer.byteLength(xmlDescriptors),\n } as Asset;\n });\n });\n }\n\n private static addContextToEntrypoints(extensionOptions: ClientsideExtensionsOptions[], wrmOptions: IWrmPluginOptions) {\n extensionOptions\n .filter((extensionOption) => !isPageExtension(extensionOption))\n .forEach((extensionOption) => {\n const { contextMap } = wrmOptions;\n const entrypointId = ClientsideExtensionsWebpackPlugin.getIdFromManifestKey(extensionOption.key);\n const context = extensionOption.extensionPoint;\n\n contextMap.set(entrypointId, [context]);\n });\n }\n\n private static addDataProvidersToEntrypoints(extensionOptions: ClientsideExtensionsOptions[], wrmOptions: IWrmPluginOptions) {\n extensionOptions\n .filter((extensionOption) => Boolean(extensionOption.pageDataProvider))\n .forEach((extensionOption) => {\n const { dataProvidersMap } = wrmOptions;\n const entrypointId = ClientsideExtensionsWebpackPlugin.getIdFromManifestKey(extensionOption.key);\n const dataProvider: DataProvider = {\n key: PAGE_DATA_PROVIDER_DATA_KEY,\n class: extensionOption.pageDataProvider!,\n };\n\n dataProvidersMap.set(entrypointId, [dataProvider]);\n });\n }\n\n private static addConditionToEntrypoint(extensionOptions: ClientsideExtensionsOptions[], wrmOptions: IWrmPluginOptions) {\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const hasCondition = (extensionOptions: ClientsideExtensionsOptions) => Boolean(extensionOptions.condition);\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const isNotPageExtension = (extensionOptions: ClientsideExtensionsOptions) => !isPageExtension(extensionOptions);\n\n extensionOptions\n .filter(hasCondition)\n .filter(isNotPageExtension)\n .forEach((extensionOption) => {\n const entrypointId = ClientsideExtensionsWebpackPlugin.getIdFromManifestKey(extensionOption.key);\n const conditionMap = transformConditionToConditionMapObject(extensionOption.condition!);\n\n const conditionMapPluginOption = wrmOptions.conditionMap as Map<string, object>;\n\n conditionMapPluginOption.set(entrypointId, conditionMap);\n });\n }\n\n private static transformAnnotationsIntoManifest(\n rawAnnotations: RawAnnotations,\n filePath: string,\n cwd: string,\n ): ClientsideExtensionsManifest {\n const parserOptions: AnnotationParserOptions = {\n cwd,\n filePath,\n };\n\n const annotations = {} as Annotations;\n const entries = Object.entries(annotationsParsers) as [[AnnotationKey, AnnotationParserFunction]];\n\n for (const [annotationKey, annotationParser] of entries) {\n const rawAnnotation = getKeyValue(rawAnnotations, annotationKey);\n const newAnnotations = annotationParser(rawAnnotation, rawAnnotations, parserOptions);\n\n if (newAnnotations !== null) {\n Object.assign(annotations, newAnnotations);\n }\n }\n\n const manifest: ClientsideExtensionsManifest = {\n id: ClientsideExtensionsWebpackPlugin.getIdFromManifestKey(annotations.key),\n filePath,\n ...annotations,\n };\n\n debugLog(`Generated manifest: ${JSON.stringify(manifest)}`);\n\n return manifest;\n }\n\n private static parseManifestFromComment(file: string, cwd: string): ClientsideExtensionsManifest | null {\n const fileContent = fs.readFileSync(file, 'utf8');\n const annotations = transformComment(fileContent);\n\n if (!annotations) {\n console.warn(`Client-side Extension: The file: \"${file}\" does not contain meta comments. Skipping XML-descriptor generation.`);\n return null;\n }\n\n return ClientsideExtensionsWebpackPlugin.transformAnnotationsIntoManifest(annotations, file, cwd);\n }\n\n private static findFilesByPattern(pattern: string, cwd: string, ignore?: string[]) {\n return glob.sync(pattern, { absolute: true, cwd, ignore, dotRelative: true });\n }\n\n private static getWrmWebpackPluginOptions(compiler: Compiler): IWrmPluginOptions {\n const { plugins } = compiler.options;\n if (!plugins) {\n throw new Error(`Something went mighty wrong. Can't find any plugins in webpack`);\n }\n const wrmPlugin = plugins.find((p) => p.constructor.name === 'WrmPlugin');\n\n if (!wrmPlugin) {\n throw new Error(\n `Can't find the WrmPlugin. Make sure you are using this plugin only in conjunction with the @atlassian/webresource-webpack-plugin`,\n );\n }\n\n return (wrmPlugin as WebpackPluginInstance & { options: IWrmPluginOptions }).options;\n }\n\n private static getFilenameForEntry(manifestId: string) {\n return `./generated-clientside-extension/${manifestId}.js`;\n }\n\n private static manifestToPluginOptions(pluginKey: string, manifest: ClientsideExtensionsManifest): ClientsideExtensionsOptions {\n const { id, key } = manifest;\n const resourceKey = `entrypoint-${id}`;\n\n return {\n ...manifest,\n pluginKey,\n entryPoint: resourceKey,\n fullyQualifiedNamespace: `${pluginKey}:${key}`,\n };\n }\n\n private static getIdFromManifestKey(key: string) {\n return kebabCase(key);\n }\n}\n\nexport = ClientsideExtensionsWebpackPlugin;\n"]}
1
+ {"version":3,"file":"ClientsideExtensionsWebpackPlugin.js","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.ts"],"names":[],"mappings":";;AAAA,oDAAoB;AACpB,wDAAwB;AAExB,+BAA4B;AAC5B,yEAAyC;AACzC,6CAA+C;AAC/C,8FAA0D;AAC1D,oFAAmD;AAEnD,wEAA+C;AAE/C,sGAA8E;AAC9E,2FAAuG;AACvG,uDAAiF;AAGjF,mCAA2D;AAE3D,gFAA4E;AAY5E,MAAM,iCAAiC;IASnC,YAAY,UAA8C,EAAE;QACxD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC/E,CAAC;QAED,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,OA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,mBAAmB,CAAC,UAAkB;QACjD,OAAO,oCAAoC,UAAU,KAAK,CAAC;IAC/D,CAAC;IAEO,MAAM,CAAC,uBAAuB,CAAC,SAAiB,EAAE,QAAsC;QAC5F,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,QAAQ,CAAC;QAC7B,MAAM,WAAW,GAAG,cAAc,EAAE,EAAE,CAAC;QAEvC,OAAO;YACH,GAAG,QAAQ;YACX,SAAS;YACT,UAAU,EAAE,WAAW;YACvB,uBAAuB,EAAE,GAAG,SAAS,IAAI,GAAG,EAAE;SACjD,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,GAAW;QAC3C,OAAO,IAAA,mBAAS,EAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACJ;AAED,iBAAS,iCAAiC,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport type { Compilation, Compiler, WebpackPluginInstance } from 'webpack';\nimport { glob } from 'glob';\nimport kebabCase from 'lodash/kebabCase';\nimport { pd as PrettyData } from 'pretty-data';\nimport VirtualModulePlugin from 'webpack-virtual-modules';\nimport transformComment from './transform-comment';\nimport type { AnnotationKey, AnnotationParserFunction, AnnotationParserOptions, Annotations, RawAnnotations } from './annotations';\nimport annotationsParsers from './annotations';\n\nimport generateWebfragmentDescriptor from './generator/webfragmentDescriptor';\nimport generateWebpageDescriptor, { PAGE_DATA_PROVIDER_DATA_KEY } from './generator/webpageDescriptor';\nimport { generateEntrypointCode, isPageExtension } from './generator/entrypoint';\n\nimport type { ClientsideExtensionsManifest, ClientsideExtensionsOptions, DataProvider, IWrmPluginOptions } from './types';\nimport { debugLog, getKeyValue, isNotNull } from './utils';\n\nimport transformConditionToConditionMapObject from './generator/conditions';\n\n// Infer the type \"Source\" which is not exposed by Webpack\ntype Asset = Compilation['assets'] extends Record<string, infer S> ? S : never;\n\ninterface IClientsideExtensionsPluginOptions {\n pattern?: string;\n cwd?: string;\n xmlDescriptors?: string;\n ignore?: string[];\n}\n\nclass ClientsideExtensionsWebpackPlugin {\n private readonly pattern: string;\n\n private readonly cwd: string;\n\n private readonly outputFilename?: string;\n\n private manifests: ClientsideExtensionsManifest[];\n\n constructor(options: IClientsideExtensionsPluginOptions = {}) {\n if (!options.pattern) {\n throw new Error('No pattern was specified to match clientside extensions');\n }\n\n this.outputFilename = options.xmlDescriptors;\n this.pattern = options.pattern;\n this.cwd = options.cwd || process.cwd();\n const ignore = options.ignore || ['**/node_modules/**', 'build/**', 'target/**'];\n\n debugLog(`cwd: ${this.cwd}`);\n\n const globFoundFiles = ClientsideExtensionsWebpackPlugin.findFilesByPattern(this.pattern, this.cwd, ignore);\n\n debugLog(`Glob found (with the pattern: ${this.pattern}) these files: ${globFoundFiles}`);\n\n this.manifests = globFoundFiles\n .map((file) => ClientsideExtensionsWebpackPlugin.parseManifestFromComment(file, this.cwd))\n .filter(isNotNull);\n\n debugLog(`Found the following manifests ${JSON.stringify(this.manifests)}`);\n }\n\n public generateEntrypoints() {\n return this.manifests.reduce((agg, manifest) => {\n const id = ClientsideExtensionsWebpackPlugin.getIdFromManifestKey(manifest.key);\n agg[id] = ClientsideExtensionsWebpackPlugin.getFilenameForEntry(id);\n\n return agg;\n }, {} as { [key: string]: string });\n }\n\n apply(compiler: Compiler) {\n const wrmOptions = ClientsideExtensionsWebpackPlugin.getWrmWebpackPluginOptions(compiler);\n\n const extensionsOptions = this.manifests.map((manifest) => {\n return ClientsideExtensionsWebpackPlugin.manifestToPluginOptions(wrmOptions.pluginKey, manifest);\n });\n\n // side effect\n ClientsideExtensionsWebpackPlugin.addContextToEntrypoints(extensionsOptions, wrmOptions);\n\n // side effect\n ClientsideExtensionsWebpackPlugin.addDataProvidersToEntrypoints(extensionsOptions, wrmOptions);\n\n // side effect\n ClientsideExtensionsWebpackPlugin.addConditionToEntrypoint(extensionsOptions, wrmOptions);\n\n const virtualModules = extensionsOptions.reduce((agg, extensionOption) => {\n const fileName = ClientsideExtensionsWebpackPlugin.getFilenameForEntry(extensionOption.id);\n agg[fileName] = generateEntrypointCode(extensionOption);\n return agg;\n }, {} as Record<string, string>);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error This is non-standard and from rspack\n if (compiler?.rspack) {\n // eslint-disable-next-line import/no-extraneous-dependencies,node/no-extraneous-import\n // @ts-expect-error Rspack doesn't expose the types for this\n new require('@rspack/core').rspack.experiments.VirtualModulesPlugin(virtualModules).apply(compiler);\n } else {\n new VirtualModulePlugin(virtualModules).apply(compiler);\n }\n\n compiler.hooks.compilation.tap('Tap compilation for XML generation', (compilation) => {\n const webfragmentDescriptors = extensionsOptions.map((extensionOption) => generateWebfragmentDescriptor(extensionOption));\n const webpageDescriptors = extensionsOptions.map((extensionOption) => generateWebpageDescriptor(extensionOption));\n\n const descriptors = [...webfragmentDescriptors, ...webpageDescriptors].join('');\n const xmlDescriptors = PrettyData.xml(`<clientside-extension>${descriptors}</clientside-extension>`);\n\n const xmlDescriptorDirname = path.dirname(\n path.relative(compiler.options.output.path || '', this.outputFilename || wrmOptions.xmlDescriptors),\n );\n const xmlDescriptorFilename = path.basename(this.outputFilename || 'wr-generated-clientside-extensions.xml');\n const webpanelXmlDescriptorFilename = path.join(xmlDescriptorDirname, xmlDescriptorFilename);\n\n compilation.hooks.additionalAssets.tap('Generate clientside-extension XML', () => {\n compilation.assets[webpanelXmlDescriptorFilename] = {\n source: () => Buffer.from(xmlDescriptors),\n size: () => Buffer.byteLength(xmlDescriptors),\n } as Asset;\n });\n });\n }\n\n private static addContextToEntrypoints(extensionOptions: ClientsideExtensionsOptions[], wrmOptions: IWrmPluginOptions) {\n extensionOptions\n .filter((extensionOption) => !isPageExtension(extensionOption))\n .forEach((extensionOption) => {\n const { contextMap } = wrmOptions;\n const entrypointId = ClientsideExtensionsWebpackPlugin.getIdFromManifestKey(extensionOption.key);\n const context = extensionOption.extensionPoint;\n\n contextMap.set(entrypointId, [context]);\n });\n }\n\n private static addDataProvidersToEntrypoints(extensionOptions: ClientsideExtensionsOptions[], wrmOptions: IWrmPluginOptions) {\n extensionOptions\n .filter((extensionOption) => Boolean(extensionOption.pageDataProvider))\n .forEach((extensionOption) => {\n const { dataProvidersMap } = wrmOptions;\n const entrypointId = ClientsideExtensionsWebpackPlugin.getIdFromManifestKey(extensionOption.key);\n const dataProvider: DataProvider = {\n key: PAGE_DATA_PROVIDER_DATA_KEY,\n class: extensionOption.pageDataProvider!,\n };\n\n dataProvidersMap.set(entrypointId, [dataProvider]);\n });\n }\n\n private static addConditionToEntrypoint(extensionOptions: ClientsideExtensionsOptions[], wrmOptions: IWrmPluginOptions) {\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const hasCondition = (extensionOptions: ClientsideExtensionsOptions) => Boolean(extensionOptions.condition);\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const isNotPageExtension = (extensionOptions: ClientsideExtensionsOptions) => !isPageExtension(extensionOptions);\n\n extensionOptions\n .filter(hasCondition)\n .filter(isNotPageExtension)\n .forEach((extensionOption) => {\n const entrypointId = ClientsideExtensionsWebpackPlugin.getIdFromManifestKey(extensionOption.key);\n const conditionMap = transformConditionToConditionMapObject(extensionOption.condition!);\n\n const conditionMapPluginOption = wrmOptions.conditionMap as Map<string, object>;\n\n conditionMapPluginOption.set(entrypointId, conditionMap);\n });\n }\n\n private static transformAnnotationsIntoManifest(\n rawAnnotations: RawAnnotations,\n filePath: string,\n cwd: string,\n ): ClientsideExtensionsManifest {\n const parserOptions: AnnotationParserOptions = {\n cwd,\n filePath,\n };\n\n const annotations = {} as Annotations;\n const entries = Object.entries(annotationsParsers) as [[AnnotationKey, AnnotationParserFunction]];\n\n for (const [annotationKey, annotationParser] of entries) {\n const rawAnnotation = getKeyValue(rawAnnotations, annotationKey);\n const newAnnotations = annotationParser(rawAnnotation, rawAnnotations, parserOptions);\n\n if (newAnnotations !== null) {\n Object.assign(annotations, newAnnotations);\n }\n }\n\n const manifest: ClientsideExtensionsManifest = {\n id: ClientsideExtensionsWebpackPlugin.getIdFromManifestKey(annotations.key),\n filePath,\n ...annotations,\n };\n\n debugLog(`Generated manifest: ${JSON.stringify(manifest)}`);\n\n return manifest;\n }\n\n private static parseManifestFromComment(file: string, cwd: string): ClientsideExtensionsManifest | null {\n const fileContent = fs.readFileSync(file, 'utf8');\n const annotations = transformComment(fileContent);\n\n if (!annotations) {\n console.warn(`Client-side Extension: The file: \"${file}\" does not contain meta comments. Skipping XML-descriptor generation.`);\n return null;\n }\n\n return ClientsideExtensionsWebpackPlugin.transformAnnotationsIntoManifest(annotations, file, cwd);\n }\n\n private static findFilesByPattern(pattern: string, cwd: string, ignore?: string[]) {\n return glob.sync(pattern, { absolute: true, cwd, ignore, dotRelative: true });\n }\n\n private static getWrmWebpackPluginOptions(compiler: Compiler): IWrmPluginOptions {\n const { plugins } = compiler.options;\n if (!plugins) {\n throw new Error(`Something went mighty wrong. Can't find any plugins in webpack`);\n }\n const wrmPlugin = plugins.find((p) => p.constructor.name === 'WrmPlugin');\n\n if (!wrmPlugin) {\n throw new Error(\n `Can't find the WrmPlugin. Make sure you are using this plugin only in conjunction with the @atlassian/webresource-webpack-plugin`,\n );\n }\n\n return (wrmPlugin as WebpackPluginInstance & { options: IWrmPluginOptions }).options;\n }\n\n private static getFilenameForEntry(manifestId: string) {\n return `./generated-clientside-extension/${manifestId}.js`;\n }\n\n private static manifestToPluginOptions(pluginKey: string, manifest: ClientsideExtensionsManifest): ClientsideExtensionsOptions {\n const { id, key } = manifest;\n const resourceKey = `entrypoint-${id}`;\n\n return {\n ...manifest,\n pluginKey,\n entryPoint: resourceKey,\n fullyQualifiedNamespace: `${pluginKey}:${key}`,\n };\n }\n\n private static getIdFromManifestKey(key: string) {\n return kebabCase(key);\n }\n}\n\nexport = ClientsideExtensionsWebpackPlugin;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ClientsideExtensionsWebpackPlugin.d.ts","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.ts"],"names":[],"mappings":"AAEA,OA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AC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,cAAM,iCAAiC;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAE7B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAS;IAEzC,OAAO,CAAC,SAAS,CAAiC;gBAEtC,OAAO,GAAE,kCAAuC;IAuBrD,mBAAmB;;;IAS1B,KAAK,CAAC,QAAQ,EAAE,QAAQ;IAqDxB,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAYtC,OAAO,CAAC,MAAM,CAAC,6BAA6B;IAe5C,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAmBvC,OAAO,CAAC,MAAM,CAAC,gCAAgC;IAiC/C,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAYvC,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAIjC,OAAO,CAAC,MAAM,CAAC,0BAA0B;IAgBzC,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAIlC,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAYtC,OAAO,CAAC,MAAM,CAAC,oBAAoB;CAGtC;AAED,SAAS,iCAAiC,CAAC"}
@@ -90,7 +90,15 @@ class ClientsideExtensionsWebpackPlugin {
90
90
  agg[fileName] = generateEntrypointCode(extensionOption);
91
91
  return agg;
92
92
  }, {} as Record<string, string>);
93
- new VirtualModulePlugin(virtualModules).apply(compiler);
93
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
94
+ // @ts-expect-error This is non-standard and from rspack
95
+ if (compiler?.rspack) {
96
+ // eslint-disable-next-line import/no-extraneous-dependencies,node/no-extraneous-import
97
+ // @ts-expect-error Rspack doesn't expose the types for this
98
+ new require('@rspack/core').rspack.experiments.VirtualModulesPlugin(virtualModules).apply(compiler);
99
+ } else {
100
+ new VirtualModulePlugin(virtualModules).apply(compiler);
101
+ }
94
102
 
95
103
  compiler.hooks.compilation.tap('Tap compilation for XML generation', (compilation) => {
96
104
  const webfragmentDescriptors = extensionsOptions.map((extensionOption) => generateWebfragmentDescriptor(extensionOption));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlassian/clientside-extensions-webpack-plugin",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
4
4
  "description": "Allows for simple creation of client-side extensions",
5
5
  "main": "./dist/cjs/ClientsideExtensionsWebpackPlugin.js",
6
6
  "types": "./dist/types/ClientsideExtensionsWebpackPlugin.d.ts",
@@ -55,7 +55,7 @@
55
55
  ],
56
56
  "publishConfig": {
57
57
  "access": "public",
58
- "@atlassian:registry": "https://packages.atlassian.com/api/npm/npm-public/"
58
+ "registry": "https://packages.atlassian.com/api/npm/npm-public/"
59
59
  },
60
60
  "dependencies": {
61
61
  "comment-parser": "~1.3.0",
@@ -71,8 +71,8 @@
71
71
  "webpack": "^5.0.0"
72
72
  },
73
73
  "devDependencies": {
74
- "@atlassian/clientside-extensions": "^5.1.0",
75
- "@atlassian/clientside-extensions-registry": "^5.1.0",
74
+ "@atlassian/clientside-extensions": "^5.1.1",
75
+ "@atlassian/clientside-extensions-registry": "^5.1.1",
76
76
  "@atlassian/webresource-webpack-plugin": "^7.0.3",
77
77
  "@types/lodash": "4.14.177",
78
78
  "@types/webpack": "5.28.0",
@@ -86,5 +86,5 @@
86
86
  "engines": {
87
87
  "node": ">=20.18.1"
88
88
  },
89
- "gitHead": "9864e5937d68e51d7a26eece1238be16589135b5"
89
+ "gitHead": "435c0d1351646cd51849e1f857097c08fa527700"
90
90
  }