@atlassian/clientside-extensions-webpack-plugin 2.4.3 → 2.4.4

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
@@ -2,31 +2,8 @@
2
2
 
3
3
  ## Webpack plugin
4
4
 
5
- A webpack plugin to faciliate the consumption of client-side extensions using webpack. It will read comment annotations to create the
6
- necesary web-fragments XML declarations for plugin devs.
5
+ A webpack plugin to facilitate the consumption of client-side extensions using webpack. It will read comment annotations to create the
6
+ necessary web-fragments XML declarations for plugin devs.
7
7
 
8
- Refer to the [official documentation](https://developer.atlassian.com/server/framework/clientside-extensions) for more information.
9
-
10
- ## Usage
11
-
12
- Similar to the [`atlassian-webresource-webpack-plugin`](https://www.npmjs.com/package/atlassian-webresource-webpack-plugin), add this
13
- webpack plugin to your webpack config to automatically generate plugin module descriptors from clientside extensions in the source code.
14
-
15
- In your webpack config:
16
-
17
- ```ts
18
- plugins: [
19
- new ClientsideExtensionWebpackPlugin({
20
- // All options are optional
21
- cwd: 'frontend/src/example',
22
- pattern: 'extension/example/**/*-extension.js*',
23
- }),
24
- ];
25
- ```
26
-
27
- ### Options
28
-
29
- - `pattern?: string` Define a pattern of files to search through to find clientside-extension annotations
30
- - `cwd?: string` Define a working directory, defaults to the node process CWD
31
- - `xmlDescriptors?: string` Define the output filename that will contain the XML plugin module descriptors, defaults to `wr-generated-clientside-extensions.xml`
32
- - `ignore?: string[]` Define patterns of files to ignore when searching for clientside-extension annotations, defaults to: `['**/node_modules/**', 'build/**', 'target/**',]`
8
+ Refer to the [official webpack plugin documentation](https://developer.atlassian.com/server/framework/clientside-extensions/reference/webpack-plugin/webpack-plugin/)
9
+ for more information.
@@ -22,9 +22,13 @@ module.exports = class ClientsideExtensionsWebpackPlugin {
22
22
  this.pattern = options.pattern;
23
23
  this.cwd = options.cwd || process.cwd();
24
24
  const ignore = options.ignore || ['**/node_modules/**', 'build/**', 'target/**'];
25
- this.manifests = ClientsideExtensionsWebpackPlugin.findFilesByPattern(this.pattern, this.cwd, ignore)
25
+ utils_1.debugLog(`cwd: ${this.cwd}`);
26
+ const globFoundFiles = ClientsideExtensionsWebpackPlugin.findFilesByPattern(this.pattern, this.cwd, ignore);
27
+ utils_1.debugLog(`Glob found (with the pattern: ${this.pattern}) these files: ${globFoundFiles}`);
28
+ this.manifests = globFoundFiles
26
29
  .map((file) => ClientsideExtensionsWebpackPlugin.parseManifestFromComment(file, this.cwd))
27
30
  .filter(utils_1.isNotNull);
31
+ utils_1.debugLog(`Found the following manifests ${JSON.stringify(this.manifests)}`);
28
32
  }
29
33
  generateEntrypoints() {
30
34
  return this.manifests.reduce((agg, manifest) => {
@@ -121,6 +125,7 @@ module.exports = class ClientsideExtensionsWebpackPlugin {
121
125
  filePath,
122
126
  ...annotations,
123
127
  };
128
+ utils_1.debugLog(`Generated manifest: ${JSON.stringify(manifest)}`);
124
129
  return manifest;
125
130
  }
126
131
  static parseManifestFromComment(file, cwd) {
@@ -1 +1 @@
1
- {"version":3,"file":"ClientsideExtensionsWebpackPlugin.js","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.ts"],"names":[],"mappings":";;AAAA,oDAAoB;AACpB,wDAAwB;AAExB,wDAAwB;AACxB,yEAAyC;AACzC,6CAA+C;AAC/C,8FAA0D;AAC1D,oFAAmD;AAEnD,wEAA+C;AAE/C,sGAA8E;AAC9E,2FAAuG;AACvG,uDAAiF;AAGjF,mCAAiD;AAEjD,gFAA4E;AAY5E,iBAAS,MAAM,iCAAiC;IAS5C,YAAY,UAA8C,EAAE;QACxD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;SAC9E;QAED,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,OAAO,CA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O,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;QAE1E,IAAI,CAAC,SAAS,EAAE;YACZ,MAAM,IAAI,KAAK,CACX,iIAAiI,CACpI,CAAC;SACL;QAED,OAAQ,SAAoE,CAAC,OAAO,CAAC;IACzF,CAAC;IAEO,MAAM,CAAC,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,mBAAS,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACJ,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 { 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\nexport = class 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 this.manifests = ClientsideExtensionsWebpackPlugin.findFilesByPattern(this.pattern, this.cwd, ignore)\n .map((file) => ClientsideExtensionsWebpackPlugin.parseManifestFromComment(file, this.cwd))\n .filter(isNotNull);\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.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 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 });\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"]}
1
+ {"version":3,"file":"ClientsideExtensionsWebpackPlugin.js","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.ts"],"names":[],"mappings":";;AAAA,oDAAoB;AACpB,wDAAwB;AAExB,wDAAwB;AACxB,yEAAyC;AACzC,6CAA+C;AAC/C,8FAA0D;AAC1D,oFAAmD;AAEnD,wEAA+C;AAE/C,sGAA8E;AAC9E,2FAAuG;AACvG,uDAAiF;AAGjF,mCAA2D;AAE3D,gFAA4E;AAY5E,iBAAS,MAAM,iCAAiC;IAS5C,YAAY,UAA8C,EAAE;QACxD,IAAI,CAAC,OAAO,CAAC,OAAO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AAoB,CAAC,GAAW;QAC3C,OAAO,mBAAS,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACJ,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\nexport = class 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.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 });\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"]}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const lib_1 = require("comment-parser/lib");
5
5
  const camelCase_1 = tslib_1.__importDefault(require("lodash/camelCase"));
6
+ const utils_1 = require("./utils");
6
7
  const CLIENTSIDE_EXTENSION_ANNOTATION = 'clientside-extension';
7
8
  const MULTI_VALUE_ANNOTATIONS = ['condition'];
8
9
  const getClientSideExtensionAnnotations = (comments) => comments.find((comment) => comment.tags.some(({ tag }) => tag === CLIENTSIDE_EXTENSION_ANNOTATION));
@@ -11,6 +12,7 @@ const getClientSideExtensionAnnotations = (comments) => comments.find((comment)
11
12
  */
12
13
  const transformComment = (fileContent) => {
13
14
  const comments = lib_1.parse(fileContent);
15
+ utils_1.debugLog(`Parsing raw comments: ${JSON.stringify(comments)}`);
14
16
  const extensionAnnotationsComment = getClientSideExtensionAnnotations(comments);
15
17
  if (!extensionAnnotationsComment) {
16
18
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"transform-comment.js","sourceRoot":"","sources":["../../lib/transform-comment.ts"],"names":[],"mappings":";;;AACA,4CAA2D;AAC3D,yEAAyC;AAGzC,MAAM,+BAA+B,GAAG,sBAAsB,CAAC;AAC/D,MAAM,uBAAuB,GAAG,CAAC,WAAW,CAAC,CAAC;AAE9C,MAAM,iCAAiC,GAAG,CAAC,QAA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import type { Block } from 'comment-parser/lib';\nimport { parse as parseComment } from 'comment-parser/lib';\nimport camelCase from 'lodash/camelCase';\nimport type { AnnotationKey, MultiValueAnnotationKey, RawAnnotations, SingleValueAnnotationKey } from './annotations';\n\nconst CLIENTSIDE_EXTENSION_ANNOTATION = 'clientside-extension';\nconst MULTI_VALUE_ANNOTATIONS = ['condition'];\n\nconst getClientSideExtensionAnnotations = (comments: Block[]) =>\n comments.find((comment) => comment.tags.some(({ tag }) => tag === CLIENTSIDE_EXTENSION_ANNOTATION));\n\n/**\n * Transforms a raw comment with annotations into annotations map\n */\nconst transformComment = (fileContent: string) => {\n const comments = parseComment(fileContent);\n const extensionAnnotationsComment = getClientSideExtensionAnnotations(comments);\n\n if (!extensionAnnotationsComment) {\n return null;\n }\n\n const annotations = {} as RawAnnotations;\n\n for (const { tag, name, description } of extensionAnnotationsComment.tags) {\n const annotationKey = camelCase(tag) as AnnotationKey;\n const annotationValue = [name, description].join(' ').trim();\n\n // Merge annotations of the same type\n if (MULTI_VALUE_ANNOTATIONS.includes(annotationKey)) {\n const prevValue = annotations[annotationKey];\n const wrappedPrevValue = Array.isArray(prevValue) ? (prevValue as string[]) : [];\n\n annotations[annotationKey as MultiValueAnnotationKey] = [...wrappedPrevValue, annotationValue];\n\n // eslint-disable-next-line no-continue\n continue;\n }\n\n annotations[annotationKey as SingleValueAnnotationKey] = annotationValue;\n }\n\n return annotations;\n};\n\nexport default transformComment;\n"]}
1
+ {"version":3,"file":"transform-comment.js","sourceRoot":"","sources":["../../lib/transform-comment.ts"],"names":[],"mappings":";;;AACA,4CAA2D;AAC3D,yEAAyC;AAEzC,mCAAmC;AAEnC,MAAM,+BAA+B,GAAG,sBAAsB,CAAC;AAC/D,MAAM,uBAAuB,GAAG,CAAC,WAAW,CAAC,CAAC;AAE9C,MAAM,iCAAiC,GAAG,CAAC,QAAiB,EAAE,EAAE,CAC5D,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAA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ent":["import type { Block } from 'comment-parser/lib';\nimport { parse as parseComment } from 'comment-parser/lib';\nimport camelCase from 'lodash/camelCase';\nimport type { AnnotationKey, MultiValueAnnotationKey, RawAnnotations, SingleValueAnnotationKey } from './annotations';\nimport { debugLog } from './utils';\n\nconst CLIENTSIDE_EXTENSION_ANNOTATION = 'clientside-extension';\nconst MULTI_VALUE_ANNOTATIONS = ['condition'];\n\nconst getClientSideExtensionAnnotations = (comments: Block[]) =>\n comments.find((comment) => comment.tags.some(({ tag }) => tag === CLIENTSIDE_EXTENSION_ANNOTATION));\n\n/**\n * Transforms a raw comment with annotations into annotations map\n */\nconst transformComment = (fileContent: string) => {\n const comments = parseComment(fileContent);\n\n debugLog(`Parsing raw comments: ${JSON.stringify(comments)}`);\n\n const extensionAnnotationsComment = getClientSideExtensionAnnotations(comments);\n\n if (!extensionAnnotationsComment) {\n return null;\n }\n\n const annotations = {} as RawAnnotations;\n\n for (const { tag, name, description } of extensionAnnotationsComment.tags) {\n const annotationKey = camelCase(tag) as AnnotationKey;\n const annotationValue = [name, description].join(' ').trim();\n\n // Merge annotations of the same type\n if (MULTI_VALUE_ANNOTATIONS.includes(annotationKey)) {\n const prevValue = annotations[annotationKey];\n const wrappedPrevValue = Array.isArray(prevValue) ? (prevValue as string[]) : [];\n\n annotations[annotationKey as MultiValueAnnotationKey] = [...wrappedPrevValue, annotationValue];\n\n // eslint-disable-next-line no-continue\n continue;\n }\n\n annotations[annotationKey as SingleValueAnnotationKey] = annotationValue;\n }\n\n return annotations;\n};\n\nexport default transformComment;\n"]}
package/dist/cjs/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNotNullOrUndefined = exports.isNotNull = exports.replaceKey = exports.isPageExtension = exports.getKeyValue = void 0;
3
+ exports.debugLog = exports.isNotNullOrUndefined = exports.isNotNull = exports.replaceKey = exports.isPageExtension = exports.getKeyValue = void 0;
4
4
  // Utility helper that can be used to read property from an object and provide typing
5
5
  exports.getKeyValue = (obj, key) => obj[key];
6
6
  exports.isPageExtension = (options) => Boolean(options.pageUrl);
@@ -16,4 +16,11 @@ function isNotNullOrUndefined(input) {
16
16
  return input !== undefined && input != null;
17
17
  }
18
18
  exports.isNotNullOrUndefined = isNotNullOrUndefined;
19
+ function debugLog(message) {
20
+ if (process.env.CSE_DEBUG) {
21
+ // eslint-disable-next-line prefer-rest-params,no-console
22
+ console.debug(message);
23
+ }
24
+ }
25
+ exports.debugLog = debugLog;
19
26
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":";;;AAEA,qFAAqF;AACxE,QAAA,WAAW,GAAG,CAAuB,GAAM,EAAE,GAAM,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjE,QAAA,eAAe,GAAG,CAAC,OAAoC,EAAW,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAE3G,MAAM,SAAS,GAAG,QAAQ,CAAC;AACd,QAAA,UAAU,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE;IACnD,OAAO,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF,SAAgB,SAAS,CAAI,KAAe;IACxC,OAAO,KAAK,IAAI,IAAI,CAAC;AACzB,CAAC;AAFD,8BAEC;AAED,SAAgB,oBAAoB,CAAI,KAA2B;IAC/D,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,IAAI,IAAI,CAAC;AAChD,CAAC;AAFD,oDAEC","sourcesContent":["import type { ClientsideExtensionsOptions } from './types';\n\n// Utility helper that can be used to read property from an object and provide typing\nexport const getKeyValue = <T, K extends keyof T>(obj: T, key: K) => obj[key];\n\nexport const isPageExtension = (options: ClientsideExtensionsOptions): boolean => Boolean(options.pageUrl);\n\nconst KEY_REGEX = /\\$key/g;\nexport const replaceKey = (str: string, key: string) => {\n return str.replace(KEY_REGEX, key);\n};\n\nexport function isNotNull<T>(input: null | T): input is T {\n return input != null;\n}\n\nexport function isNotNullOrUndefined<T>(input: null | undefined | T): input is T {\n return input !== undefined && input != null;\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":";;;AAEA,qFAAqF;AACxE,QAAA,WAAW,GAAG,CAAuB,GAAM,EAAE,GAAM,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjE,QAAA,eAAe,GAAG,CAAC,OAAoC,EAAW,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAE3G,MAAM,SAAS,GAAG,QAAQ,CAAC;AACd,QAAA,UAAU,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE;IACnD,OAAO,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF,SAAgB,SAAS,CAAI,KAAe;IACxC,OAAO,KAAK,IAAI,IAAI,CAAC;AACzB,CAAC;AAFD,8BAEC;AAED,SAAgB,oBAAoB,CAAI,KAA2B;IAC/D,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,IAAI,IAAI,CAAC;AAChD,CAAC;AAFD,oDAEC;AAED,SAAgB,QAAQ,CAAC,OAAe;IACpC,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE;QACvB,yDAAyD;QACzD,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;KAC1B;AACL,CAAC;AALD,4BAKC","sourcesContent":["import type { ClientsideExtensionsOptions } from './types';\n\n// Utility helper that can be used to read property from an object and provide typing\nexport const getKeyValue = <T, K extends keyof T>(obj: T, key: K) => obj[key];\n\nexport const isPageExtension = (options: ClientsideExtensionsOptions): boolean => Boolean(options.pageUrl);\n\nconst KEY_REGEX = /\\$key/g;\nexport const replaceKey = (str: string, key: string) => {\n return str.replace(KEY_REGEX, key);\n};\n\nexport function isNotNull<T>(input: null | T): input is T {\n return input != null;\n}\n\nexport function isNotNullOrUndefined<T>(input: null | undefined | T): input is T {\n return input !== undefined && input != null;\n}\n\nexport function debugLog(message: String): void {\n if (process.env.CSE_DEBUG) {\n // eslint-disable-next-line prefer-rest-params,no-console\n console.debug(message);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ClientsideExtensionsWebpackPlugin.d.ts","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAe,QAAQ,EAAyB,MAAM,SAAS,CAAC;AAM5E,OAAO,KAAK,EAAiF,cAAc,EAAE,MAAM,eAAe,CAAC;AAOnI,OAAO,KAAK,EAAE,4BAA4B,EAAE,2BAA2B,EAAgB,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAQ1H,UAAU,kCAAkC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;;mBAWwB,kCAAkC;0BAR7B,MAAM;sBAEV,MAAM;;mBAIT,4BAA4B,EAAE;;;;wBA0BjC,QAAQ;;8CA6CiC,2BAA2B,EAAE,cAAc,iBAAiB;oDAUtD,2BAA2B,EAAE,cAAc,iBAAiB;+CAejE,2BAA2B,EAAE,cAAc,iBAAiB;qDAoBlG,cAAc,YACpB,MAAM,OACX,MAAM,GACZ,4BAA4B;mCA2Be,MAAM,OAAO,MAAM,GAAG,4BAA4B,GAAG,IAAI;gCAY5D,MAAM,OAAO,MAAM;yCAIV,QAAQ,GAAG,iBAAiB;oCAgBjC,MAAM;uCAIH,MAAM,YAAY,4BAA4B,GAAG,2BAA2B;8BAYrF,MAAM;;AAzMnD,kBA4ME"}
1
+ {"version":3,"file":"ClientsideExtensionsWebpackPlugin.d.ts","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAe,QAAQ,EAAyB,MAAM,SAAS,CAAC;AAM5E,OAAO,KAAK,EAAiF,cAAc,EAAE,MAAM,eAAe,CAAC;AAOnI,OAAO,KAAK,EAAE,4BAA4B,EAAE,2BAA2B,EAAgB,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAQ1H,UAAU,kCAAkC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;;mBAWwB,kCAAkC;0BAR7B,MAAM;sBAEV,MAAM;;mBAIT,4BAA4B,EAAE;;;;wBAkCjC,QAAQ;;8CA6CiC,2BAA2B,EAAE,cAAc,iBAAiB;oDAUtD,2BAA2B,EAAE,cAAc,iBAAiB;+CAejE,2BAA2B,EAAE,cAAc,iBAAiB;qDAoBlG,cAAc,YACpB,MAAM,OACX,MAAM,GACZ,4BAA4B;mCA6Be,MAAM,OAAO,MAAM,GAAG,4BAA4B,GAAG,IAAI;gCAY5D,MAAM,OAAO,MAAM;yCAIV,QAAQ,GAAG,iBAAiB;oCAgBjC,MAAM;uCAIH,MAAM,YAAY,4BAA4B,GAAG,2BAA2B;8BAYrF,MAAM;;AAnNnD,kBAsNE"}
@@ -1 +1 @@
1
- {"version":3,"file":"transform-comment.d.ts","sourceRoot":"","sources":["../../lib/transform-comment.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA0C,cAAc,EAA4B,MAAM,eAAe,CAAC;AAQtH;;GAEG;AACH,QAAA,MAAM,gBAAgB,gBAAiB,MAAM,0BA6B5C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"transform-comment.d.ts","sourceRoot":"","sources":["../../lib/transform-comment.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA0C,cAAc,EAA4B,MAAM,eAAe,CAAC;AAStH;;GAEG;AACH,QAAA,MAAM,gBAAgB,gBAAiB,MAAM,0BAgC5C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -4,4 +4,5 @@ export declare const isPageExtension: (options: ClientsideExtensionsOptions) =>
4
4
  export declare const replaceKey: (str: string, key: string) => string;
5
5
  export declare function isNotNull<T>(input: null | T): input is T;
6
6
  export declare function isNotNullOrUndefined<T>(input: null | undefined | T): input is T;
7
+ export declare function debugLog(message: String): void;
7
8
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAG3D,eAAO,MAAM,WAAW,gDAAqD,CAAC;AAE9E,eAAO,MAAM,eAAe,YAAa,2BAA2B,KAAG,OAAmC,CAAC;AAG3G,eAAO,MAAM,UAAU,QAAS,MAAM,OAAO,MAAM,WAElD,CAAC;AAEF,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,CAExD;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,CAE/E"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAG3D,eAAO,MAAM,WAAW,gDAAqD,CAAC;AAE9E,eAAO,MAAM,eAAe,YAAa,2BAA2B,KAAG,OAAmC,CAAC;AAG3G,eAAO,MAAM,UAAU,QAAS,MAAM,OAAO,MAAM,WAElD,CAAC;AAEF,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,CAExD;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,CAE/E;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAK9C"}
@@ -14,7 +14,7 @@ import generateWebpageDescriptor, { PAGE_DATA_PROVIDER_DATA_KEY } from './genera
14
14
  import { generateEntrypointCode, isPageExtension } from './generator/entrypoint';
15
15
 
16
16
  import type { ClientsideExtensionsManifest, ClientsideExtensionsOptions, DataProvider, IWrmPluginOptions } from './types';
17
- import { getKeyValue, isNotNull } from './utils';
17
+ import { debugLog, getKeyValue, isNotNull } from './utils';
18
18
 
19
19
  import transformConditionToConditionMapObject from './generator/conditions';
20
20
 
@@ -47,9 +47,17 @@ export = class ClientsideExtensionsWebpackPlugin {
47
47
  this.cwd = options.cwd || process.cwd();
48
48
  const ignore = options.ignore || ['**/node_modules/**', 'build/**', 'target/**'];
49
49
 
50
- this.manifests = ClientsideExtensionsWebpackPlugin.findFilesByPattern(this.pattern, this.cwd, ignore)
50
+ debugLog(`cwd: ${this.cwd}`);
51
+
52
+ const globFoundFiles = ClientsideExtensionsWebpackPlugin.findFilesByPattern(this.pattern, this.cwd, ignore);
53
+
54
+ debugLog(`Glob found (with the pattern: ${this.pattern}) these files: ${globFoundFiles}`);
55
+
56
+ this.manifests = globFoundFiles
51
57
  .map((file) => ClientsideExtensionsWebpackPlugin.parseManifestFromComment(file, this.cwd))
52
58
  .filter(isNotNull);
59
+
60
+ debugLog(`Found the following manifests ${JSON.stringify(this.manifests)}`);
53
61
  }
54
62
 
55
63
  public generateEntrypoints() {
@@ -178,6 +186,8 @@ export = class ClientsideExtensionsWebpackPlugin {
178
186
  ...annotations,
179
187
  };
180
188
 
189
+ debugLog(`Generated manifest: ${JSON.stringify(manifest)}`);
190
+
181
191
  return manifest;
182
192
  }
183
193
 
@@ -2,6 +2,7 @@ import type { Block } from 'comment-parser/lib';
2
2
  import { parse as parseComment } from 'comment-parser/lib';
3
3
  import camelCase from 'lodash/camelCase';
4
4
  import type { AnnotationKey, MultiValueAnnotationKey, RawAnnotations, SingleValueAnnotationKey } from './annotations';
5
+ import { debugLog } from './utils';
5
6
 
6
7
  const CLIENTSIDE_EXTENSION_ANNOTATION = 'clientside-extension';
7
8
  const MULTI_VALUE_ANNOTATIONS = ['condition'];
@@ -14,6 +15,9 @@ const getClientSideExtensionAnnotations = (comments: Block[]) =>
14
15
  */
15
16
  const transformComment = (fileContent: string) => {
16
17
  const comments = parseComment(fileContent);
18
+
19
+ debugLog(`Parsing raw comments: ${JSON.stringify(comments)}`);
20
+
17
21
  const extensionAnnotationsComment = getClientSideExtensionAnnotations(comments);
18
22
 
19
23
  if (!extensionAnnotationsComment) {
package/lib/utils.ts CHANGED
@@ -17,3 +17,10 @@ export function isNotNull<T>(input: null | T): input is T {
17
17
  export function isNotNullOrUndefined<T>(input: null | undefined | T): input is T {
18
18
  return input !== undefined && input != null;
19
19
  }
20
+
21
+ export function debugLog(message: String): void {
22
+ if (process.env.CSE_DEBUG) {
23
+ // eslint-disable-next-line prefer-rest-params,no-console
24
+ console.debug(message);
25
+ }
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlassian/clientside-extensions-webpack-plugin",
3
- "version": "2.4.3",
3
+ "version": "2.4.4",
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",
@@ -71,8 +71,8 @@
71
71
  "webpack": "^4.0.0 || ^5.0.0"
72
72
  },
73
73
  "devDependencies": {
74
- "@atlassian/clientside-extensions": "^2.4.3",
75
- "@atlassian/clientside-extensions-registry": "^2.4.3",
74
+ "@atlassian/clientside-extensions": "^2.4.4",
75
+ "@atlassian/clientside-extensions-registry": "^2.4.4",
76
76
  "@types/glob": "7.1.4",
77
77
  "@types/lodash": "4.14.175",
78
78
  "@types/webpack": "5.28.0",
@@ -87,5 +87,5 @@
87
87
  "engines": {
88
88
  "node": ">=12.19.0"
89
89
  },
90
- "gitHead": "9ce0846abde618df3383f87d259023088f04d21b"
90
+ "gitHead": "f231082bf82640c83abf57ed1c83c1b669ea69f3"
91
91
  }