@atlassian/clientside-extensions-webpack-plugin 2.4.1 → 2.5.0-84fa90d-kwd5ix2w
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/dist/cjs/ClientsideExtensionsWebpackPlugin.js +21 -20
- package/dist/cjs/ClientsideExtensionsWebpackPlugin.js.map +1 -1
- package/dist/cjs/annotations/index.js +2 -2
- package/dist/cjs/annotations/index.js.map +1 -1
- package/dist/cjs/annotations/key.js +1 -1
- package/dist/cjs/annotations/key.js.map +1 -1
- package/dist/cjs/annotations/label.js +2 -2
- package/dist/cjs/annotations/label.js.map +1 -1
- package/dist/cjs/annotations/link.js +2 -2
- package/dist/cjs/annotations/link.js.map +1 -1
- package/dist/cjs/annotations/parsers.js +14 -10
- package/dist/cjs/annotations/parsers.js.map +1 -1
- package/dist/cjs/generator/conditions.js +2 -2
- package/dist/cjs/generator/conditions.js.map +1 -1
- package/dist/cjs/generator/entrypoint.js +5 -4
- package/dist/cjs/generator/entrypoint.js.map +1 -1
- package/dist/cjs/generator/webfragmentDescriptor.js +7 -7
- package/dist/cjs/generator/webfragmentDescriptor.js.map +1 -1
- package/dist/cjs/generator/webpageDescriptor.js +6 -6
- package/dist/cjs/generator/webpageDescriptor.js.map +1 -1
- package/dist/cjs/generator/xml.js +7 -5
- package/dist/cjs/generator/xml.js.map +1 -1
- package/dist/cjs/tests/test-helper.js +8 -6
- package/dist/cjs/tests/test-helper.js.map +1 -1
- package/dist/cjs/transform-comment.js +4 -4
- package/dist/cjs/transform-comment.js.map +1 -1
- package/dist/cjs/utils.js +6 -3
- package/dist/cjs/utils.js.map +1 -1
- package/dist/types/ClientsideExtensionsWebpackPlugin.d.ts +21 -24
- package/dist/types/ClientsideExtensionsWebpackPlugin.d.ts.map +1 -1
- package/lib/ClientsideExtensionsWebpackPlugin.basic.test.ts +30 -17
- package/lib/ClientsideExtensionsWebpackPlugin.conditions.test.ts +20 -14
- package/lib/ClientsideExtensionsWebpackPlugin.metadata.test.ts +9 -4
- package/lib/ClientsideExtensionsWebpackPlugin.ts +4 -2
- package/lib/ClientsideExtensionsWebpackPlugin.webpages.test.ts +35 -22
- package/lib/generator/xml.ts +1 -1
- package/lib/tests/test-helper.ts +1 -1
- package/lib/transform-comment.ts +2 -2
- package/package.json +12 -11
- package/tsconfig.all.json +6 -0
- package/tsconfig.json +5 -1
- package/dist/cjs/ClientsideExtensionsWebpackPlugin.basic.test.js +0 -75
- package/dist/cjs/ClientsideExtensionsWebpackPlugin.basic.test.js.map +0 -1
- package/dist/cjs/ClientsideExtensionsWebpackPlugin.conditions.test.js +0 -201
- package/dist/cjs/ClientsideExtensionsWebpackPlugin.conditions.test.js.map +0 -1
- package/dist/cjs/ClientsideExtensionsWebpackPlugin.metadata.test.js +0 -62
- package/dist/cjs/ClientsideExtensionsWebpackPlugin.metadata.test.js.map +0 -1
- package/dist/cjs/ClientsideExtensionsWebpackPlugin.webpages.test.js +0 -442
- package/dist/cjs/ClientsideExtensionsWebpackPlugin.webpages.test.js.map +0 -1
- package/dist/types/ClientsideExtensionsWebpackPlugin.basic.test.d.ts +0 -2
- package/dist/types/ClientsideExtensionsWebpackPlugin.basic.test.d.ts.map +0 -1
- package/dist/types/ClientsideExtensionsWebpackPlugin.conditions.test.d.ts +0 -2
- package/dist/types/ClientsideExtensionsWebpackPlugin.conditions.test.d.ts.map +0 -1
- package/dist/types/ClientsideExtensionsWebpackPlugin.metadata.test.d.ts +0 -2
- package/dist/types/ClientsideExtensionsWebpackPlugin.metadata.test.d.ts.map +0 -1
- package/dist/types/ClientsideExtensionsWebpackPlugin.webpages.test.d.ts +0 -2
- package/dist/types/ClientsideExtensionsWebpackPlugin.webpages.test.d.ts.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const
|
|
5
|
-
const camelCase_1 = tslib_1.__importDefault(require("lodash/camelCase"));
|
|
4
|
+
const comment_parser_1 = require("comment-parser");
|
|
5
|
+
const camelCase_1 = (0, tslib_1.__importDefault)(require("lodash/camelCase"));
|
|
6
6
|
const CLIENTSIDE_EXTENSION_ANNOTATION = 'clientside-extension';
|
|
7
7
|
const MULTI_VALUE_ANNOTATIONS = ['condition'];
|
|
8
8
|
const getClientSideExtensionAnnotations = (comments) => comments.find((comment) => comment.tags.some(({ tag }) => tag === CLIENTSIDE_EXTENSION_ANNOTATION));
|
|
@@ -10,14 +10,14 @@ const getClientSideExtensionAnnotations = (comments) => comments.find((comment)
|
|
|
10
10
|
* Transforms a raw comment with annotations into annotations map
|
|
11
11
|
*/
|
|
12
12
|
const transformComment = (fileContent) => {
|
|
13
|
-
const comments =
|
|
13
|
+
const comments = (0, comment_parser_1.parse)(fileContent);
|
|
14
14
|
const extensionAnnotationsComment = getClientSideExtensionAnnotations(comments);
|
|
15
15
|
if (!extensionAnnotationsComment) {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
18
|
const annotations = {};
|
|
19
19
|
for (const { tag, name, description } of extensionAnnotationsComment.tags) {
|
|
20
|
-
const annotationKey = camelCase_1.default(tag);
|
|
20
|
+
const annotationKey = (0, camelCase_1.default)(tag);
|
|
21
21
|
const annotationValue = [name, description].join(' ').trim();
|
|
22
22
|
// Merge annotations of the same type
|
|
23
23
|
if (MULTI_VALUE_ANNOTATIONS.includes(annotationKey)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-comment.js","sourceRoot":"","sources":["../../lib/transform-comment.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"transform-comment.js","sourceRoot":"","sources":["../../lib/transform-comment.ts"],"names":[],"mappings":";;;AACA,mDAAuD;AACvD,8EAAyC;AAGzC,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,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,+BAA+B,CAAC,CAAC,CAAC;AAExG;;GAEG;AACH,MAAM,gBAAgB,GAAG,CAAC,WAAmB,EAAE,EAAE;IAC7C,MAAM,QAAQ,GAAG,IAAA,sBAAY,EAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,2BAA2B,GAAG,iCAAiC,CAAC,QAAQ,CAAC,CAAC;IAEhF,IAAI,CAAC,2BAA2B,EAAE;QAC9B,OAAO,IAAI,CAAC;KACf;IAED,MAAM,WAAW,GAAG,EAAoB,CAAC;IAEzC,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,2BAA2B,CAAC,IAAI,EAAE;QACvE,MAAM,aAAa,GAAG,IAAA,mBAAS,EAAC,GAAG,CAAkB,CAAC;QACtD,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QAE7D,qCAAqC;QACrC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;YACjD,MAAM,SAAS,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC;YAC7C,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAE,SAAsB,CAAC,CAAC,CAAC,EAAE,CAAC;YAEjF,WAAW,CAAC,aAAwC,CAAC,GAAG,CAAC,GAAG,gBAAgB,EAAE,eAAe,CAAC,CAAC;YAE/F,uCAAuC;YACvC,SAAS;SACZ;QAED,WAAW,CAAC,aAAyC,CAAC,GAAG,eAAe,CAAC;KAC5E;IAED,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAEF,kBAAe,gBAAgB,CAAC","sourcesContent":["import type { Block } from 'comment-parser';\nimport { parse as parseComment } from 'comment-parser';\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"]}
|
package/dist/cjs/utils.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
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
|
-
|
|
6
|
-
exports.
|
|
5
|
+
const getKeyValue = (obj, key) => obj[key];
|
|
6
|
+
exports.getKeyValue = getKeyValue;
|
|
7
|
+
const isPageExtension = (options) => Boolean(options.pageUrl);
|
|
8
|
+
exports.isPageExtension = isPageExtension;
|
|
7
9
|
const KEY_REGEX = /\$key/g;
|
|
8
|
-
|
|
10
|
+
const replaceKey = (str, key) => {
|
|
9
11
|
return str.replace(KEY_REGEX, key);
|
|
10
12
|
};
|
|
13
|
+
exports.replaceKey = replaceKey;
|
|
11
14
|
function isNotNull(input) {
|
|
12
15
|
return input != null;
|
|
13
16
|
}
|
package/dist/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":";;;AAEA,qFAAqF;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":";;;AAEA,qFAAqF;AAC9E,MAAM,WAAW,GAAG,CAAuB,GAAM,EAAE,GAAM,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAAjE,QAAA,WAAW,eAAsD;AAEvE,MAAM,eAAe,GAAG,CAAC,OAAoC,EAAW,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAA9F,QAAA,eAAe,mBAA+E;AAE3G,MAAM,SAAS,GAAG,QAAQ,CAAC;AACpB,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE;IACnD,OAAO,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AACvC,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB;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,32 +1,29 @@
|
|
|
1
1
|
import type { Compiler } from 'webpack';
|
|
2
|
-
import type { RawAnnotations } from './annotations';
|
|
3
|
-
import type { ClientsideExtensionsManifest, ClientsideExtensionsOptions, IWrmPluginOptions } from './types';
|
|
4
2
|
interface IClientsideExtensionsPluginOptions {
|
|
5
3
|
pattern?: string;
|
|
6
4
|
cwd?: string;
|
|
7
5
|
xmlDescriptors?: string;
|
|
8
6
|
}
|
|
9
|
-
declare
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
apply(compiler: Compiler): void;
|
|
7
|
+
declare class ClientsideExtensionsWebpackPlugin {
|
|
8
|
+
private readonly pattern;
|
|
9
|
+
private readonly cwd;
|
|
10
|
+
private readonly outputFilename?;
|
|
11
|
+
private manifests;
|
|
12
|
+
constructor(options?: IClientsideExtensionsPluginOptions);
|
|
13
|
+
generateEntrypoints(): {
|
|
14
|
+
[key: string]: string;
|
|
19
15
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
apply(compiler: Compiler): void;
|
|
17
|
+
private static addContextToEntrypoints;
|
|
18
|
+
private static addDataProvidersToEntrypoints;
|
|
19
|
+
private static addConditionToEntrypoint;
|
|
20
|
+
private static transformAnnotationsIntoManifest;
|
|
21
|
+
private static parseManifestFromComment;
|
|
22
|
+
private static findFilesByPattern;
|
|
23
|
+
private static getWrmWebpackPluginOptions;
|
|
24
|
+
private static getFilenameForEntry;
|
|
25
|
+
private static manifestToPluginOptions;
|
|
26
|
+
private static getIdFromManifestKey;
|
|
27
|
+
}
|
|
28
|
+
export = ClientsideExtensionsWebpackPlugin;
|
|
32
29
|
//# sourceMappingURL=ClientsideExtensionsWebpackPlugin.d.ts.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"ClientsideExtensionsWebpackPlugin.d.ts","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAe,QAAQ,EAAyB,MAAM,SAAS,CAAC;AAqB5E,UAAU,kCAAkC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;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;IAiBrD,mBAAmB;;;IAS1B,KAAK,CAAC,QAAQ,EAAE,QAAQ;IA6CxB,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAUtC,OAAO,CAAC,MAAM,CAAC,6BAA6B;IAe5C,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAmBvC,OAAO,CAAC,MAAM,CAAC,gCAAgC;IA+B/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"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { mocked } from 'ts-jest/utils';
|
|
2
|
-
import
|
|
2
|
+
import path from 'path';
|
|
3
3
|
import type { Stats } from 'webpack';
|
|
4
4
|
import WrmPlugin from 'atlassian-webresource-webpack-plugin';
|
|
5
|
-
import { promisify } from 'util';
|
|
6
5
|
import { fileContent } from './tests/test-helper';
|
|
7
6
|
|
|
8
7
|
// eslint-disable-next-line import/order
|
|
9
8
|
import webpack = require('webpack');
|
|
10
9
|
import Plugin = require('./ClientsideExtensionsWebpackPlugin');
|
|
11
10
|
|
|
12
|
-
const inputDir = resolve(__dirname, '__fixtures__/basic/');
|
|
13
|
-
const outputDir = resolve(__dirname, '__fixtures__/target/');
|
|
11
|
+
const inputDir = path.resolve(__dirname, '__fixtures__/basic/');
|
|
12
|
+
const outputDir = path.resolve(__dirname, '__fixtures__/target/');
|
|
14
13
|
|
|
15
14
|
beforeAll(() => {
|
|
16
15
|
// Silent-down the webpack compilation errors
|
|
@@ -24,7 +23,7 @@ afterAll(() => {
|
|
|
24
23
|
describe('basic compilation', () => {
|
|
25
24
|
const basicWrmPlugin = new WrmPlugin({
|
|
26
25
|
pluginKey: 'a.fake.plugin.key',
|
|
27
|
-
xmlDescriptors: resolve(outputDir, 'wrm.xml'),
|
|
26
|
+
xmlDescriptors: path.resolve(outputDir, 'wrm.xml'),
|
|
28
27
|
});
|
|
29
28
|
|
|
30
29
|
const basicPlugin = new Plugin({
|
|
@@ -35,8 +34,8 @@ describe('basic compilation', () => {
|
|
|
35
34
|
// base config for all tests
|
|
36
35
|
const baseWebpackConfig = {
|
|
37
36
|
entry: {
|
|
38
|
-
first: resolve(inputDir, 'first.js'),
|
|
39
|
-
second: resolve(inputDir, 'second.js'),
|
|
37
|
+
first: path.resolve(inputDir, 'first.js'),
|
|
38
|
+
second: path.resolve(inputDir, 'second.js'),
|
|
40
39
|
...basicPlugin.generateEntrypoints(),
|
|
41
40
|
},
|
|
42
41
|
optimization: {
|
|
@@ -50,30 +49,44 @@ describe('basic compilation', () => {
|
|
|
50
49
|
|
|
51
50
|
let stats: Stats;
|
|
52
51
|
|
|
53
|
-
const fileExists = (
|
|
52
|
+
const fileExists = (filePath: string) => {
|
|
54
53
|
if (!stats) {
|
|
55
|
-
|
|
54
|
+
throw new Error('webpack compilation failed');
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
if (!(filePath in stats.compilation.assets)) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`File "${filePath}" was not crated by running webpack bundle process: \n${Object.keys(stats.compilation.assets).join(
|
|
60
|
+
', ',
|
|
61
|
+
)}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return Boolean(stats.compilation.assets[filePath]);
|
|
59
66
|
};
|
|
60
67
|
|
|
61
68
|
beforeAll(async () => {
|
|
62
69
|
const compiler = webpack(baseWebpackConfig);
|
|
63
|
-
const run = promisify(compiler.run.bind(compiler));
|
|
64
|
-
stats = (await run()) as Stats;
|
|
65
|
-
});
|
|
66
70
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
compiler.run((err, webpackStats) => {
|
|
73
|
+
if (err) {
|
|
74
|
+
reject(err);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
stats = webpackStats!;
|
|
79
|
+
|
|
80
|
+
resolve(stats);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
70
83
|
});
|
|
71
84
|
|
|
72
85
|
it('generates web-items', () => {
|
|
73
86
|
const fileName = 'wr-generated-clientside-extensions.xml';
|
|
74
87
|
expect(fileExists(fileName)).toBe(true);
|
|
75
88
|
|
|
76
|
-
const xmlFileContent = fileContent(join(outputDir, fileName));
|
|
89
|
+
const xmlFileContent = fileContent(path.join(outputDir, fileName));
|
|
77
90
|
const foundExtensions = String(xmlFileContent).match(/<web-item\s/g);
|
|
78
91
|
expect(foundExtensions).not.toBe(null);
|
|
79
92
|
expect(foundExtensions?.length).toBe(3);
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { Stats } from 'webpack';
|
|
2
2
|
import { promisify } from 'util';
|
|
3
|
-
import
|
|
3
|
+
import path from 'path';
|
|
4
4
|
import WrmPlugin from 'atlassian-webresource-webpack-plugin';
|
|
5
5
|
import { mocked } from 'ts-jest/utils';
|
|
6
6
|
// eslint-disable-next-line import/order
|
|
7
|
+
import webpack = require('webpack');
|
|
7
8
|
import { fileContent, getOutputContentAsJson } from './tests/test-helper';
|
|
8
9
|
|
|
9
|
-
import path = require('path');
|
|
10
|
-
import webpack = require('webpack');
|
|
11
10
|
import Plugin = require('./ClientsideExtensionsWebpackPlugin');
|
|
12
11
|
|
|
13
12
|
const PLUGIN_KEY = 'a.fake.plugin.key';
|
|
@@ -29,13 +28,13 @@ describe('condition compilation', () => {
|
|
|
29
28
|
|
|
30
29
|
const basicWrmPlugin = new WrmPlugin({
|
|
31
30
|
pluginKey: PLUGIN_KEY,
|
|
32
|
-
xmlDescriptors: resolve(outputDir, xmlWebresourcesOutputFilename),
|
|
31
|
+
xmlDescriptors: path.resolve(outputDir, xmlWebresourcesOutputFilename),
|
|
33
32
|
});
|
|
34
33
|
|
|
35
34
|
const csePlugin = new Plugin({
|
|
36
35
|
cwd: inputDir,
|
|
37
36
|
pattern: '**/*.extension.js',
|
|
38
|
-
xmlDescriptors: resolve(outputDir, xmlCseOutputFilename),
|
|
37
|
+
xmlDescriptors: path.resolve(outputDir, xmlCseOutputFilename),
|
|
39
38
|
});
|
|
40
39
|
|
|
41
40
|
// base config for all tests
|
|
@@ -78,7 +77,7 @@ describe('condition compilation', () => {
|
|
|
78
77
|
]),
|
|
79
78
|
});
|
|
80
79
|
|
|
81
|
-
const outputJson = getOutputContentAsJson(fileContent(join(outputDir, xmlCseOutputFilename)));
|
|
80
|
+
const outputJson = getOutputContentAsJson(fileContent(path.join(outputDir, xmlCseOutputFilename)));
|
|
82
81
|
expect(outputJson).toContainEqual(expectedWebItemDeclarationShape);
|
|
83
82
|
});
|
|
84
83
|
|
|
@@ -111,7 +110,7 @@ describe('condition compilation', () => {
|
|
|
111
110
|
]),
|
|
112
111
|
});
|
|
113
112
|
|
|
114
|
-
const outputJson = getOutputContentAsJson(fileContent(join(outputDir, xmlCseOutputFilename)));
|
|
113
|
+
const outputJson = getOutputContentAsJson(fileContent(path.join(outputDir, xmlCseOutputFilename)));
|
|
115
114
|
expect(outputJson).toContainEqual(expectedWebItemDeclarationShape);
|
|
116
115
|
});
|
|
117
116
|
|
|
@@ -176,7 +175,7 @@ describe('condition compilation', () => {
|
|
|
176
175
|
]),
|
|
177
176
|
});
|
|
178
177
|
|
|
179
|
-
const outputJson = getOutputContentAsJson(fileContent(join(outputDir, xmlCseOutputFilename)));
|
|
178
|
+
const outputJson = getOutputContentAsJson(fileContent(path.join(outputDir, xmlCseOutputFilename)));
|
|
180
179
|
expect(outputJson).toContainEqual(expectedWebItemDeclarationShape);
|
|
181
180
|
});
|
|
182
181
|
});
|
|
@@ -189,13 +188,13 @@ describe('condition compilation errors', () => {
|
|
|
189
188
|
const getWebpackConfig = (csePattern: string) => {
|
|
190
189
|
const basicWrmPlugin = new WrmPlugin({
|
|
191
190
|
pluginKey: PLUGIN_KEY,
|
|
192
|
-
xmlDescriptors: resolve(outputDir, 'wrm.xml'),
|
|
191
|
+
xmlDescriptors: path.resolve(outputDir, 'wrm.xml'),
|
|
193
192
|
});
|
|
194
193
|
|
|
195
194
|
const csePlugin = new Plugin({
|
|
196
195
|
cwd: inputDir,
|
|
197
196
|
pattern: csePattern,
|
|
198
|
-
xmlDescriptors: resolve(outputDir, xmlOutputFilename),
|
|
197
|
+
xmlDescriptors: path.resolve(outputDir, xmlOutputFilename),
|
|
199
198
|
});
|
|
200
199
|
|
|
201
200
|
const webpackConfig = {
|
|
@@ -212,17 +211,24 @@ describe('condition compilation errors', () => {
|
|
|
212
211
|
return webpackConfig;
|
|
213
212
|
};
|
|
214
213
|
|
|
215
|
-
const compile =
|
|
214
|
+
const compile = (config: webpack.Configuration): Promise<Stats> => {
|
|
216
215
|
const compiler = webpack(config);
|
|
217
|
-
const run = promisify(compiler.run.bind(compiler));
|
|
218
216
|
|
|
219
|
-
return (
|
|
217
|
+
return new Promise<Stats>((resolve, reject) => {
|
|
218
|
+
compiler.run((err, stats) => {
|
|
219
|
+
if (err) {
|
|
220
|
+
reject(err);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
resolve(stats!);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
220
227
|
};
|
|
221
228
|
|
|
222
229
|
it('should throw an error when specifying an empty @condition annotation', async () => {
|
|
223
230
|
const errorFile = '**/empty-condition.*';
|
|
224
231
|
|
|
225
|
-
// error is Sync because it's the plugin that fails, not webpack compilation.
|
|
226
232
|
expect(() => compile(getWebpackConfig(errorFile))).toThrowError();
|
|
227
233
|
});
|
|
228
234
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { resolve, join } from 'path';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
2
|
import WrmPlugin from 'atlassian-webresource-webpack-plugin';
|
|
4
3
|
import { mocked } from 'ts-jest/utils';
|
|
5
4
|
import { fileContent } from './tests/test-helper';
|
|
@@ -48,10 +47,16 @@ describe('comment metadata to XML attributes/elements', () => {
|
|
|
48
47
|
},
|
|
49
48
|
};
|
|
50
49
|
|
|
51
|
-
beforeAll(
|
|
50
|
+
beforeAll((done) => {
|
|
52
51
|
const compiler = webpack(baseWebpackConfig);
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
|
|
53
|
+
compiler.run((err) => {
|
|
54
|
+
if (err) {
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
done();
|
|
59
|
+
});
|
|
55
60
|
});
|
|
56
61
|
|
|
57
62
|
it('should replace $key with the key of the extension when specified', () => {
|
|
@@ -27,7 +27,7 @@ interface IClientsideExtensionsPluginOptions {
|
|
|
27
27
|
xmlDescriptors?: string;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
class ClientsideExtensionsWebpackPlugin {
|
|
31
31
|
private readonly pattern: string;
|
|
32
32
|
|
|
33
33
|
private readonly cwd: string;
|
|
@@ -233,4 +233,6 @@ export = class ClientsideExtensionsWebpackPlugin {
|
|
|
233
233
|
private static getIdFromManifestKey(key: string) {
|
|
234
234
|
return kebabCase(key);
|
|
235
235
|
}
|
|
236
|
-
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export = ClientsideExtensionsWebpackPlugin;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { Stats } from 'webpack';
|
|
2
|
-
import
|
|
3
|
-
import { resolve, join } from 'path';
|
|
2
|
+
import path from 'path';
|
|
4
3
|
import WrmPlugin from 'atlassian-webresource-webpack-plugin';
|
|
5
4
|
import { mocked } from 'ts-jest/utils';
|
|
6
5
|
// eslint-disable-next-line import/order
|
|
6
|
+
import webpack = require('webpack');
|
|
7
7
|
import { getOutputContentAsJson, fileContent } from './tests/test-helper';
|
|
8
8
|
|
|
9
|
-
import path = require('path');
|
|
10
|
-
import webpack = require('webpack');
|
|
11
9
|
import Plugin = require('./ClientsideExtensionsWebpackPlugin');
|
|
12
10
|
|
|
13
11
|
const { PAGE_DATA_PROVIDER_DATA_KEY } = require('./generator/webpageDescriptor');
|
|
@@ -33,13 +31,13 @@ describe('webpages compilation', () => {
|
|
|
33
31
|
|
|
34
32
|
const basicWrmPlugin = new WrmPlugin({
|
|
35
33
|
pluginKey: PLUGIN_KEY,
|
|
36
|
-
xmlDescriptors: resolve(outputDir, wrmXmlOutputFilename),
|
|
34
|
+
xmlDescriptors: path.resolve(outputDir, wrmXmlOutputFilename),
|
|
37
35
|
});
|
|
38
36
|
|
|
39
37
|
const csePlugin = new Plugin({
|
|
40
38
|
cwd: inputDir,
|
|
41
39
|
pattern: '**/*.extension.js',
|
|
42
|
-
xmlDescriptors: resolve(outputDir, cseXmlOutputFilename),
|
|
40
|
+
xmlDescriptors: path.resolve(outputDir, cseXmlOutputFilename),
|
|
43
41
|
});
|
|
44
42
|
|
|
45
43
|
// base config for all tests
|
|
@@ -57,13 +55,19 @@ describe('webpages compilation', () => {
|
|
|
57
55
|
},
|
|
58
56
|
};
|
|
59
57
|
|
|
60
|
-
const getWrmOutputContentAsJson = () => getOutputContentAsJson(fileContent(join(outputDir, wrmXmlOutputFilename)));
|
|
61
|
-
const getCseOutputContentAsJson = () => getOutputContentAsJson(fileContent(join(outputDir, cseXmlOutputFilename)));
|
|
58
|
+
const getWrmOutputContentAsJson = () => getOutputContentAsJson(fileContent(path.join(outputDir, wrmXmlOutputFilename)));
|
|
59
|
+
const getCseOutputContentAsJson = () => getOutputContentAsJson(fileContent(path.join(outputDir, cseXmlOutputFilename)));
|
|
62
60
|
|
|
63
|
-
beforeAll(
|
|
61
|
+
beforeAll((done) => {
|
|
64
62
|
const compiler = webpack(baseWebpackConfig);
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
|
|
64
|
+
compiler.run((err) => {
|
|
65
|
+
if (err) {
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
done();
|
|
70
|
+
});
|
|
67
71
|
});
|
|
68
72
|
|
|
69
73
|
it('should generate the web-item and a matching web-page descriptor when using @page-url annotation', () => {
|
|
@@ -450,13 +454,13 @@ describe('webpages compilation errors', () => {
|
|
|
450
454
|
const getWebpackConfig = (csePattern: string) => {
|
|
451
455
|
const basicWrmPlugin = new WrmPlugin({
|
|
452
456
|
pluginKey: PLUGIN_KEY,
|
|
453
|
-
xmlDescriptors: resolve(outputDir, 'wrm.xml'),
|
|
457
|
+
xmlDescriptors: path.resolve(outputDir, 'wrm.xml'),
|
|
454
458
|
});
|
|
455
459
|
|
|
456
460
|
const csePlugin = new Plugin({
|
|
457
461
|
cwd: inputDir,
|
|
458
462
|
pattern: csePattern,
|
|
459
|
-
xmlDescriptors: resolve(outputDir, xmlOutputFilename),
|
|
463
|
+
xmlDescriptors: path.resolve(outputDir, xmlOutputFilename),
|
|
460
464
|
});
|
|
461
465
|
|
|
462
466
|
const webpackConfig = {
|
|
@@ -473,18 +477,27 @@ describe('webpages compilation errors', () => {
|
|
|
473
477
|
return webpackConfig;
|
|
474
478
|
};
|
|
475
479
|
|
|
476
|
-
const compile =
|
|
480
|
+
const compile = (config: webpack.Configuration): Promise<Stats> => {
|
|
477
481
|
const compiler = webpack(config);
|
|
478
|
-
|
|
479
|
-
return (
|
|
482
|
+
|
|
483
|
+
return new Promise<Stats>((resolve, reject) => {
|
|
484
|
+
compiler.run((err, stats) => {
|
|
485
|
+
if (err) {
|
|
486
|
+
reject(err);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
resolve(stats!);
|
|
491
|
+
});
|
|
492
|
+
});
|
|
480
493
|
};
|
|
481
494
|
|
|
482
495
|
it('should throw an error when trying to create an extension with @page-url and no @label annotation', async () => {
|
|
483
496
|
const errorFile = '**/webpage-without-label.*';
|
|
484
497
|
const successFile = '**/webpage-with-label.*';
|
|
485
498
|
|
|
486
|
-
|
|
487
|
-
expect(() =>
|
|
499
|
+
expect(() => getWebpackConfig(errorFile)).toThrowError();
|
|
500
|
+
expect(() => getWebpackConfig(successFile)).not.toThrowError();
|
|
488
501
|
|
|
489
502
|
await expect(compile(getWebpackConfig(successFile))).resolves.toBeTruthy();
|
|
490
503
|
});
|
|
@@ -493,8 +506,8 @@ describe('webpages compilation errors', () => {
|
|
|
493
506
|
const errorFile = '**/webpage-decorator-without-url.*';
|
|
494
507
|
const successFile = '**/webpage-decorator-with-url.*';
|
|
495
508
|
|
|
496
|
-
|
|
497
|
-
expect(() =>
|
|
509
|
+
expect(() => getWebpackConfig(errorFile)).toThrowError();
|
|
510
|
+
expect(() => getWebpackConfig(successFile)).not.toThrowError();
|
|
498
511
|
|
|
499
512
|
await expect(compile(getWebpackConfig(successFile))).resolves.toBeTruthy();
|
|
500
513
|
});
|
|
@@ -503,8 +516,8 @@ describe('webpages compilation errors', () => {
|
|
|
503
516
|
const errorFile = '**/webpage-data-provider-without-url.*';
|
|
504
517
|
const successFile = '**/webpage-data-provider-with-url.*';
|
|
505
518
|
|
|
506
|
-
|
|
507
|
-
expect(() =>
|
|
519
|
+
expect(() => getWebpackConfig(errorFile)).toThrowError();
|
|
520
|
+
expect(() => getWebpackConfig(successFile)).not.toThrowError();
|
|
508
521
|
|
|
509
522
|
await expect(compile(getWebpackConfig(successFile))).resolves.toBeTruthy();
|
|
510
523
|
});
|
package/lib/generator/xml.ts
CHANGED
|
@@ -66,7 +66,7 @@ export const renderCondition = (condition?: null | Condition | Condition[]): str
|
|
|
66
66
|
|
|
67
67
|
return renderElement(
|
|
68
68
|
'condition',
|
|
69
|
-
`class="${condition.class}" ${condition.invert ?
|
|
69
|
+
`class="${condition.class}" ${condition.invert ? 'invert="true"' : ''}`,
|
|
70
70
|
renderParams(condition.params),
|
|
71
71
|
);
|
|
72
72
|
};
|
package/lib/tests/test-helper.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { parse as parseXml } from 'fast-xml-parser';
|
|
|
4
4
|
|
|
5
5
|
export const fileContent = (filePath: string) => {
|
|
6
6
|
if (!existsSync(filePath)) {
|
|
7
|
-
|
|
7
|
+
throw new Error(`File generated by webpack "${filePath}" does not exist`);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
return String(readFileSync(filePath, { encoding: 'utf8' }));
|
package/lib/transform-comment.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Block } from 'comment-parser
|
|
2
|
-
import { parse as parseComment } from 'comment-parser
|
|
1
|
+
import type { Block } from 'comment-parser';
|
|
2
|
+
import { parse as parseComment } from 'comment-parser';
|
|
3
3
|
import camelCase from 'lodash/camelCase';
|
|
4
4
|
import type { AnnotationKey, MultiValueAnnotationKey, RawAnnotations, SingleValueAnnotationKey } from './annotations';
|
|
5
5
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlassian/clientside-extensions-webpack-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-84fa90d-kwd5ix2w",
|
|
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",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"build": "yarn build:cjs && yarn build:artifacts",
|
|
11
11
|
"build:cjs": "tsc -p tsconfig.json",
|
|
12
12
|
"build:artifacts": "cpy ./lib/runtime/** ./dist/cjs/runtime",
|
|
13
|
+
"verify": "tsc --noEmit -p tsconfig.all.json",
|
|
13
14
|
"watch": "tsc --watch",
|
|
14
15
|
"test": "jest",
|
|
15
16
|
"test:webpack4": "WEBPACK_4=true jest",
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
"@atlassian:registry": "https://registry.npmjs.org/"
|
|
59
60
|
},
|
|
60
61
|
"dependencies": {
|
|
61
|
-
"comment-parser": "~1.
|
|
62
|
+
"comment-parser": "~1.3.0",
|
|
62
63
|
"glob": "~7.2.0",
|
|
63
64
|
"lodash": "~4.17.21",
|
|
64
65
|
"pretty-data": "~0.40.0",
|
|
@@ -71,21 +72,21 @@
|
|
|
71
72
|
"webpack": "^4.0.0 || ^5.0.0"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
74
|
-
"@atlassian/clientside-extensions": "^2.
|
|
75
|
-
"@atlassian/clientside-extensions-registry": "^2.
|
|
76
|
-
"@types/glob": "7.
|
|
77
|
-
"@types/lodash": "4.14.
|
|
75
|
+
"@atlassian/clientside-extensions": "^2.5.0-84fa90d-kwd5ix2w",
|
|
76
|
+
"@atlassian/clientside-extensions-registry": "^2.5.0-84fa90d-kwd5ix2w",
|
|
77
|
+
"@types/glob": "7.2.0",
|
|
78
|
+
"@types/lodash": "4.14.177",
|
|
78
79
|
"@types/webpack": "5.28.0",
|
|
79
|
-
"atlassian-webresource-webpack-plugin": "5.
|
|
80
|
+
"atlassian-webresource-webpack-plugin": "5.2.7",
|
|
80
81
|
"atlassian-webresource-webpack-plugin-4": "npm:atlassian-webresource-webpack-plugin@4.9.0",
|
|
81
82
|
"cpy-cli": "3.1.1",
|
|
82
|
-
"fast-xml-parser": "3.
|
|
83
|
-
"ts-jest": "27.0.
|
|
84
|
-
"webpack": "5.
|
|
83
|
+
"fast-xml-parser": "3.21.1",
|
|
84
|
+
"ts-jest": "27.0.6",
|
|
85
|
+
"webpack": "5.64.2",
|
|
85
86
|
"webpack-4": "npm:webpack@4.46.0"
|
|
86
87
|
},
|
|
87
88
|
"engines": {
|
|
88
89
|
"node": ">=12.19.0"
|
|
89
90
|
},
|
|
90
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "84fa90d805babbfd94e536dcc1bb4facd1dc4f59"
|
|
91
92
|
}
|
package/tsconfig.json
CHANGED
|
@@ -7,5 +7,9 @@
|
|
|
7
7
|
"outDir": "./dist/cjs",
|
|
8
8
|
"declarationDir": "./dist/types"
|
|
9
9
|
},
|
|
10
|
-
"include": ["./lib/"]
|
|
10
|
+
"include": ["./lib/"],
|
|
11
|
+
"exclude": [
|
|
12
|
+
/* exclude test files that we include in tsconfig.all.json config and run with "yarn verify" step */
|
|
13
|
+
"./lib/**/*.test.*"
|
|
14
|
+
]
|
|
11
15
|
}
|