@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,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const utils_1 = require("ts-jest/utils");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const atlassian_webresource_webpack_plugin_1 = tslib_1.__importDefault(require("atlassian-webresource-webpack-plugin"));
|
|
7
|
-
const util_1 = require("util");
|
|
8
|
-
const test_helper_1 = require("./tests/test-helper");
|
|
9
|
-
// eslint-disable-next-line import/order
|
|
10
|
-
const webpack = require("webpack");
|
|
11
|
-
const Plugin = require("./ClientsideExtensionsWebpackPlugin");
|
|
12
|
-
const inputDir = path_1.resolve(__dirname, '__fixtures__/basic/');
|
|
13
|
-
const outputDir = path_1.resolve(__dirname, '__fixtures__/target/');
|
|
14
|
-
beforeAll(() => {
|
|
15
|
-
// Silent-down the webpack compilation errors
|
|
16
|
-
jest.spyOn(console, 'error').mockImplementation();
|
|
17
|
-
});
|
|
18
|
-
afterAll(() => {
|
|
19
|
-
utils_1.mocked(console.error).mockRestore();
|
|
20
|
-
});
|
|
21
|
-
describe('basic compilation', () => {
|
|
22
|
-
const basicWrmPlugin = new atlassian_webresource_webpack_plugin_1.default({
|
|
23
|
-
pluginKey: 'a.fake.plugin.key',
|
|
24
|
-
xmlDescriptors: path_1.resolve(outputDir, 'wrm.xml'),
|
|
25
|
-
});
|
|
26
|
-
const basicPlugin = new Plugin({
|
|
27
|
-
cwd: inputDir,
|
|
28
|
-
pattern: '**/extension*.js',
|
|
29
|
-
});
|
|
30
|
-
// base config for all tests
|
|
31
|
-
const baseWebpackConfig = {
|
|
32
|
-
entry: {
|
|
33
|
-
first: path_1.resolve(inputDir, 'first.js'),
|
|
34
|
-
second: path_1.resolve(inputDir, 'second.js'),
|
|
35
|
-
...basicPlugin.generateEntrypoints(),
|
|
36
|
-
},
|
|
37
|
-
optimization: {
|
|
38
|
-
minimize: false,
|
|
39
|
-
},
|
|
40
|
-
plugins: [basicWrmPlugin, basicPlugin],
|
|
41
|
-
output: {
|
|
42
|
-
path: outputDir,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
let stats;
|
|
46
|
-
const fileExists = (path) => {
|
|
47
|
-
if (!stats) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
return Boolean(stats.compilation.assets[path]);
|
|
51
|
-
};
|
|
52
|
-
beforeAll(async () => {
|
|
53
|
-
const compiler = webpack(baseWebpackConfig);
|
|
54
|
-
const run = util_1.promisify(compiler.run.bind(compiler));
|
|
55
|
-
stats = (await run());
|
|
56
|
-
});
|
|
57
|
-
it("generates an xml file next to the wrm plugin's output", () => {
|
|
58
|
-
expect(fileExists('wrm.xml')).toBe(true);
|
|
59
|
-
expect(fileExists('wr-generated-clientside-extensions.xml')).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
it('generates web-items', () => {
|
|
62
|
-
const fileName = 'wr-generated-clientside-extensions.xml';
|
|
63
|
-
expect(fileExists(fileName)).toBe(true);
|
|
64
|
-
const xmlFileContent = test_helper_1.fileContent(path_1.join(outputDir, fileName));
|
|
65
|
-
const foundExtensions = String(xmlFileContent).match(/<web-item\s/g);
|
|
66
|
-
expect(foundExtensions).not.toBe(null);
|
|
67
|
-
expect(foundExtensions === null || foundExtensions === void 0 ? void 0 : foundExtensions.length).toBe(3);
|
|
68
|
-
});
|
|
69
|
-
it('outputs compiled extension code to an appropriate location', () => {
|
|
70
|
-
expect(fileExists('extension-1-js.js')).toBe(true);
|
|
71
|
-
expect(fileExists('extension-2-js.js')).toBe(true);
|
|
72
|
-
expect(fileExists('nested-extension-42-js.js')).toBe(true);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
//# sourceMappingURL=ClientsideExtensionsWebpackPlugin.basic.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClientsideExtensionsWebpackPlugin.basic.test.js","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.basic.test.ts"],"names":[],"mappings":";;;AAAA,yCAAuC;AACvC,+BAAqC;AAErC,wHAA6D;AAC7D,+BAAiC;AACjC,qDAAkD;AAElD,wCAAwC;AACxC,mCAAoC;AACpC,8DA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AAmB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,MAAM,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { mocked } from 'ts-jest/utils';\nimport { resolve, join } from 'path';\nimport type { Stats } from 'webpack';\nimport WrmPlugin from 'atlassian-webresource-webpack-plugin';\nimport { promisify } from 'util';\nimport { fileContent } from './tests/test-helper';\n\n// eslint-disable-next-line import/order\nimport webpack = require('webpack');\nimport Plugin = require('./ClientsideExtensionsWebpackPlugin');\n\nconst inputDir = resolve(__dirname, '__fixtures__/basic/');\nconst outputDir = resolve(__dirname, '__fixtures__/target/');\n\nbeforeAll(() => {\n // Silent-down the webpack compilation errors\n jest.spyOn(console, 'error').mockImplementation();\n});\n\nafterAll(() => {\n mocked(console.error).mockRestore();\n});\n\ndescribe('basic compilation', () => {\n const basicWrmPlugin = new WrmPlugin({\n pluginKey: 'a.fake.plugin.key',\n xmlDescriptors: resolve(outputDir, 'wrm.xml'),\n });\n\n const basicPlugin = new Plugin({\n cwd: inputDir,\n pattern: '**/extension*.js',\n });\n\n // base config for all tests\n const baseWebpackConfig = {\n entry: {\n first: resolve(inputDir, 'first.js'),\n second: resolve(inputDir, 'second.js'),\n ...basicPlugin.generateEntrypoints(),\n },\n optimization: {\n minimize: false,\n },\n plugins: [basicWrmPlugin, basicPlugin],\n output: {\n path: outputDir,\n },\n };\n\n let stats: Stats;\n\n const fileExists = (path: string) => {\n if (!stats) {\n return false;\n }\n\n return Boolean(stats.compilation.assets[path]);\n };\n\n beforeAll(async () => {\n const compiler = webpack(baseWebpackConfig);\n const run = promisify(compiler.run.bind(compiler));\n stats = (await run()) as Stats;\n });\n\n it(\"generates an xml file next to the wrm plugin's output\", () => {\n expect(fileExists('wrm.xml')).toBe(true);\n expect(fileExists('wr-generated-clientside-extensions.xml')).toBe(true);\n });\n\n it('generates web-items', () => {\n const fileName = 'wr-generated-clientside-extensions.xml';\n expect(fileExists(fileName)).toBe(true);\n\n const xmlFileContent = fileContent(join(outputDir, fileName));\n const foundExtensions = String(xmlFileContent).match(/<web-item\\s/g);\n expect(foundExtensions).not.toBe(null);\n expect(foundExtensions?.length).toBe(3);\n });\n\n it('outputs compiled extension code to an appropriate location', () => {\n expect(fileExists('extension-1-js.js')).toBe(true);\n expect(fileExists('extension-2-js.js')).toBe(true);\n expect(fileExists('nested-extension-42-js.js')).toBe(true);\n });\n});\n"]}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const util_1 = require("util");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const atlassian_webresource_webpack_plugin_1 = tslib_1.__importDefault(require("atlassian-webresource-webpack-plugin"));
|
|
7
|
-
const utils_1 = require("ts-jest/utils");
|
|
8
|
-
// eslint-disable-next-line import/order
|
|
9
|
-
const test_helper_1 = require("./tests/test-helper");
|
|
10
|
-
const path = require("path");
|
|
11
|
-
const webpack = require("webpack");
|
|
12
|
-
const Plugin = require("./ClientsideExtensionsWebpackPlugin");
|
|
13
|
-
const PLUGIN_KEY = 'a.fake.plugin.key';
|
|
14
|
-
beforeAll(() => {
|
|
15
|
-
// Silent-down the webpack compilation errors
|
|
16
|
-
jest.spyOn(console, 'error').mockImplementation();
|
|
17
|
-
});
|
|
18
|
-
afterAll(() => {
|
|
19
|
-
utils_1.mocked(console.error).mockRestore();
|
|
20
|
-
});
|
|
21
|
-
describe('condition compilation', () => {
|
|
22
|
-
const inputDir = path.resolve(__dirname, '__fixtures__/conditions/');
|
|
23
|
-
const outputDir = path.resolve(__dirname, '__fixtures__/target/');
|
|
24
|
-
const xmlCseOutputFilename = 'wr-generated-cse-conditions.xml';
|
|
25
|
-
const xmlWebresourcesOutputFilename = 'wr-generated-webresources-conditions.xml';
|
|
26
|
-
const basicWrmPlugin = new atlassian_webresource_webpack_plugin_1.default({
|
|
27
|
-
pluginKey: PLUGIN_KEY,
|
|
28
|
-
xmlDescriptors: path_1.resolve(outputDir, xmlWebresourcesOutputFilename),
|
|
29
|
-
});
|
|
30
|
-
const csePlugin = new Plugin({
|
|
31
|
-
cwd: inputDir,
|
|
32
|
-
pattern: '**/*.extension.js',
|
|
33
|
-
xmlDescriptors: path_1.resolve(outputDir, xmlCseOutputFilename),
|
|
34
|
-
});
|
|
35
|
-
// base config for all tests
|
|
36
|
-
const baseWebpackConfig = {
|
|
37
|
-
entry: csePlugin.generateEntrypoints(),
|
|
38
|
-
optimization: {
|
|
39
|
-
minimize: false,
|
|
40
|
-
},
|
|
41
|
-
plugins: [basicWrmPlugin, csePlugin],
|
|
42
|
-
output: {
|
|
43
|
-
path: outputDir,
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
beforeAll(async () => {
|
|
47
|
-
const compiler = webpack(baseWebpackConfig);
|
|
48
|
-
const run = util_1.promisify(compiler.run.bind(compiler));
|
|
49
|
-
await run();
|
|
50
|
-
});
|
|
51
|
-
it('should generate the simple condition with class', () => {
|
|
52
|
-
const expectedExtensionPoint = 'simple.condition';
|
|
53
|
-
const expectedWebItemKey = 'simple-condition__extension__js';
|
|
54
|
-
const expectedCondition = {
|
|
55
|
-
attrs: { class: 'com.acme.MyCondition' },
|
|
56
|
-
};
|
|
57
|
-
const expectedWebItemDeclarationShape = expect.objectContaining({
|
|
58
|
-
'web-item': expect.arrayContaining([
|
|
59
|
-
{
|
|
60
|
-
attrs: {
|
|
61
|
-
key: expectedWebItemKey,
|
|
62
|
-
section: expectedExtensionPoint,
|
|
63
|
-
weight: expect.anything(),
|
|
64
|
-
},
|
|
65
|
-
label: expect.anything(),
|
|
66
|
-
condition: [expectedCondition],
|
|
67
|
-
link: expect.anything(),
|
|
68
|
-
},
|
|
69
|
-
]),
|
|
70
|
-
});
|
|
71
|
-
const outputJson = test_helper_1.getOutputContentAsJson(test_helper_1.fileContent(path_1.join(outputDir, xmlCseOutputFilename)));
|
|
72
|
-
expect(outputJson).toContainEqual(expectedWebItemDeclarationShape);
|
|
73
|
-
});
|
|
74
|
-
it('should generate the condition with class params', () => {
|
|
75
|
-
const expectedExtensionPoint = 'condition.with.params';
|
|
76
|
-
const expectedWebItemKey = 'condition-with-params__extension__js';
|
|
77
|
-
const expectedParam = {
|
|
78
|
-
attrs: {
|
|
79
|
-
name: 'permission',
|
|
80
|
-
},
|
|
81
|
-
'#text': 'admin',
|
|
82
|
-
};
|
|
83
|
-
const expectedCondition = {
|
|
84
|
-
attrs: { class: 'com.acme.MyConditionWithParams' },
|
|
85
|
-
param: [expectedParam],
|
|
86
|
-
};
|
|
87
|
-
const expectedWebItemDeclarationShape = expect.objectContaining({
|
|
88
|
-
'web-item': expect.arrayContaining([
|
|
89
|
-
{
|
|
90
|
-
attrs: {
|
|
91
|
-
key: expectedWebItemKey,
|
|
92
|
-
section: expectedExtensionPoint,
|
|
93
|
-
weight: expect.anything(),
|
|
94
|
-
},
|
|
95
|
-
label: expect.anything(),
|
|
96
|
-
condition: [expectedCondition],
|
|
97
|
-
link: expect.anything(),
|
|
98
|
-
},
|
|
99
|
-
]),
|
|
100
|
-
});
|
|
101
|
-
const outputJson = test_helper_1.getOutputContentAsJson(test_helper_1.fileContent(path_1.join(outputDir, xmlCseOutputFilename)));
|
|
102
|
-
expect(outputJson).toContainEqual(expectedWebItemDeclarationShape);
|
|
103
|
-
});
|
|
104
|
-
it('should generate conjunction of two conditions with params', () => {
|
|
105
|
-
const expectedExtensionPoint = 'two.conditions.with.params';
|
|
106
|
-
const expectedWebItemKey = 'two-conditions-with-params__extension__js';
|
|
107
|
-
// First condition
|
|
108
|
-
const expectedFistConditionParam = {
|
|
109
|
-
attrs: {
|
|
110
|
-
name: 'MyParam',
|
|
111
|
-
},
|
|
112
|
-
'#text': 'My Value',
|
|
113
|
-
};
|
|
114
|
-
const expectedFirstCondition = {
|
|
115
|
-
attrs: { class: 'com.acme.MyFirstCondition' },
|
|
116
|
-
param: [expectedFistConditionParam],
|
|
117
|
-
};
|
|
118
|
-
// Second condition
|
|
119
|
-
const expectedSecondConditionParamFoo = {
|
|
120
|
-
attrs: {
|
|
121
|
-
name: 'foo',
|
|
122
|
-
},
|
|
123
|
-
'#text': 'bar',
|
|
124
|
-
};
|
|
125
|
-
const expectedSecondConditionParamBiz = {
|
|
126
|
-
attrs: {
|
|
127
|
-
name: 'biz',
|
|
128
|
-
},
|
|
129
|
-
'#text': 'baz',
|
|
130
|
-
};
|
|
131
|
-
const expectedSecondCondition = {
|
|
132
|
-
attrs: { class: 'com.acme.MySecondCondition' },
|
|
133
|
-
param: [expectedSecondConditionParamFoo, expectedSecondConditionParamBiz],
|
|
134
|
-
};
|
|
135
|
-
// Condition
|
|
136
|
-
const expectedConditions = {
|
|
137
|
-
attrs: {
|
|
138
|
-
type: 'AND',
|
|
139
|
-
},
|
|
140
|
-
condition: [expectedFirstCondition, expectedSecondCondition],
|
|
141
|
-
};
|
|
142
|
-
const expectedWebItemDeclarationShape = expect.objectContaining({
|
|
143
|
-
'web-item': expect.arrayContaining([
|
|
144
|
-
{
|
|
145
|
-
attrs: {
|
|
146
|
-
key: expectedWebItemKey,
|
|
147
|
-
section: expectedExtensionPoint,
|
|
148
|
-
weight: expect.anything(),
|
|
149
|
-
},
|
|
150
|
-
label: expect.anything(),
|
|
151
|
-
conditions: [expectedConditions],
|
|
152
|
-
link: expect.anything(),
|
|
153
|
-
},
|
|
154
|
-
]),
|
|
155
|
-
});
|
|
156
|
-
const outputJson = test_helper_1.getOutputContentAsJson(test_helper_1.fileContent(path_1.join(outputDir, xmlCseOutputFilename)));
|
|
157
|
-
expect(outputJson).toContainEqual(expectedWebItemDeclarationShape);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
describe('condition compilation errors', () => {
|
|
161
|
-
const inputDir = path.resolve(__dirname, '__fixtures__/conditions-errors/');
|
|
162
|
-
const outputDir = path.resolve(__dirname, '__fixtures__/target/');
|
|
163
|
-
const xmlOutputFilename = 'wr-generated-cse-condition-errors.xml';
|
|
164
|
-
const getWebpackConfig = (csePattern) => {
|
|
165
|
-
const basicWrmPlugin = new atlassian_webresource_webpack_plugin_1.default({
|
|
166
|
-
pluginKey: PLUGIN_KEY,
|
|
167
|
-
xmlDescriptors: path_1.resolve(outputDir, 'wrm.xml'),
|
|
168
|
-
});
|
|
169
|
-
const csePlugin = new Plugin({
|
|
170
|
-
cwd: inputDir,
|
|
171
|
-
pattern: csePattern,
|
|
172
|
-
xmlDescriptors: path_1.resolve(outputDir, xmlOutputFilename),
|
|
173
|
-
});
|
|
174
|
-
const webpackConfig = {
|
|
175
|
-
entry: csePlugin.generateEntrypoints(),
|
|
176
|
-
plugins: [basicWrmPlugin, csePlugin],
|
|
177
|
-
optimization: {
|
|
178
|
-
minimize: false,
|
|
179
|
-
},
|
|
180
|
-
output: {
|
|
181
|
-
path: outputDir,
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
return webpackConfig;
|
|
185
|
-
};
|
|
186
|
-
const compile = async (config) => {
|
|
187
|
-
const compiler = webpack(config);
|
|
188
|
-
const run = util_1.promisify(compiler.run.bind(compiler));
|
|
189
|
-
return (await run());
|
|
190
|
-
};
|
|
191
|
-
it('should throw an error when specifying an empty @condition annotation', async () => {
|
|
192
|
-
const errorFile = '**/empty-condition.*';
|
|
193
|
-
// error is Sync because it's the plugin that fails, not webpack compilation.
|
|
194
|
-
expect(() => compile(getWebpackConfig(errorFile))).toThrowError();
|
|
195
|
-
});
|
|
196
|
-
it('should throw an error when specifying an invalid condition class', async () => {
|
|
197
|
-
const errorFile = '**/invalid-condition-class.*';
|
|
198
|
-
expect(() => compile(getWebpackConfig(errorFile))).toThrowError();
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
//# sourceMappingURL=ClientsideExtensionsWebpackPlugin.conditions.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClientsideExtensionsWebpackPlugin.conditions.test.js","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.conditions.test.ts"],"names":[],"mappings":";;;AACA,+BAAiC;AACjC,+BAAqC;AACrC,wHAA6D;AAC7D,yCAAuC;AACvC,wCAAwC;AACxC,qDAA0E;AAE1E,6BAA8B;AAC9B,mCAAoC;AACpC,8DAA+D;AAE/D,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAEvC,SAAS,CAAC,GAAG,EAAE;IACX,6CAA6C;IAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,kBAAkB,EAAE,CAAC;AACtD,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,GAAG,EAAE;IACV,cAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AACxC,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,0BAA0B,CAAC,CAAC;IACrE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC;IAClE,MAAM,oBAAoB,GAAG,iCAAiC,CAAC;IAC/D,MAAM,6BAA6B,GAAG,0CAA0C,CAAC;IAEjF,MAAM,cAAc,GAAG,IAAI,8CAAS,CAAC;QACjC,SAAS,EAAE,UAAU;QACrB,cAAc,EAAE,cAAO,CAAC,SAAS,EAAE,6BAA6B,CAAC;KACpE,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC;QACzB,GAAG,EAAE,QAAQ;QACb,OAAO,EAAE,mBAAmB;QAC5B,cAAc,EAAE,cAAO,CAAC,SAAS,EA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OAAO,CAAC,MAAM,GAAG,EAAE,CAAU,CAAC;IAClC,CAAC,CAAC;IAEF,EAAE,CAAC,sEAAsE,EAAE,KAAK,IAAI,EAAE;QAClF,MAAM,SAAS,GAAG,sBAAsB,CAAC;QAEzC,6EAA6E;QAC7E,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;IACtE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kEAAkE,EAAE,KAAK,IAAI,EAAE;QAC9E,MAAM,SAAS,GAAG,8BAA8B,CAAC;QAEjD,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;IACtE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import type { Stats } from 'webpack';\nimport { promisify } from 'util';\nimport { join, resolve } from 'path';\nimport WrmPlugin from 'atlassian-webresource-webpack-plugin';\nimport { mocked } from 'ts-jest/utils';\n// eslint-disable-next-line import/order\nimport { fileContent, getOutputContentAsJson } from './tests/test-helper';\n\nimport path = require('path');\nimport webpack = require('webpack');\nimport Plugin = require('./ClientsideExtensionsWebpackPlugin');\n\nconst PLUGIN_KEY = 'a.fake.plugin.key';\n\nbeforeAll(() => {\n // Silent-down the webpack compilation errors\n jest.spyOn(console, 'error').mockImplementation();\n});\n\nafterAll(() => {\n mocked(console.error).mockRestore();\n});\n\ndescribe('condition compilation', () => {\n const inputDir = path.resolve(__dirname, '__fixtures__/conditions/');\n const outputDir = path.resolve(__dirname, '__fixtures__/target/');\n const xmlCseOutputFilename = 'wr-generated-cse-conditions.xml';\n const xmlWebresourcesOutputFilename = 'wr-generated-webresources-conditions.xml';\n\n const basicWrmPlugin = new WrmPlugin({\n pluginKey: PLUGIN_KEY,\n xmlDescriptors: resolve(outputDir, xmlWebresourcesOutputFilename),\n });\n\n const csePlugin = new Plugin({\n cwd: inputDir,\n pattern: '**/*.extension.js',\n xmlDescriptors: resolve(outputDir, xmlCseOutputFilename),\n });\n\n // base config for all tests\n const baseWebpackConfig = {\n entry: csePlugin.generateEntrypoints(),\n optimization: {\n minimize: false,\n },\n plugins: [basicWrmPlugin, csePlugin],\n output: {\n path: outputDir,\n },\n };\n\n beforeAll(async () => {\n const compiler = webpack(baseWebpackConfig);\n const run = promisify(compiler.run.bind(compiler));\n await run();\n });\n\n it('should generate the simple condition with class', () => {\n const expectedExtensionPoint = 'simple.condition';\n const expectedWebItemKey = 'simple-condition__extension__js';\n const expectedCondition = {\n attrs: { class: 'com.acme.MyCondition' },\n };\n\n const expectedWebItemDeclarationShape = expect.objectContaining({\n 'web-item': expect.arrayContaining([\n {\n attrs: {\n key: expectedWebItemKey,\n section: expectedExtensionPoint,\n weight: expect.anything(),\n },\n label: expect.anything(),\n condition: [expectedCondition],\n link: expect.anything(),\n },\n ]),\n });\n\n const outputJson = getOutputContentAsJson(fileContent(join(outputDir, xmlCseOutputFilename)));\n expect(outputJson).toContainEqual(expectedWebItemDeclarationShape);\n });\n\n it('should generate the condition with class params', () => {\n const expectedExtensionPoint = 'condition.with.params';\n const expectedWebItemKey = 'condition-with-params__extension__js';\n const expectedParam = {\n attrs: {\n name: 'permission',\n },\n '#text': 'admin',\n };\n const expectedCondition = {\n attrs: { class: 'com.acme.MyConditionWithParams' },\n param: [expectedParam],\n };\n\n const expectedWebItemDeclarationShape = expect.objectContaining({\n 'web-item': expect.arrayContaining([\n {\n attrs: {\n key: expectedWebItemKey,\n section: expectedExtensionPoint,\n weight: expect.anything(),\n },\n label: expect.anything(),\n condition: [expectedCondition],\n link: expect.anything(),\n },\n ]),\n });\n\n const outputJson = getOutputContentAsJson(fileContent(join(outputDir, xmlCseOutputFilename)));\n expect(outputJson).toContainEqual(expectedWebItemDeclarationShape);\n });\n\n it('should generate conjunction of two conditions with params', () => {\n const expectedExtensionPoint = 'two.conditions.with.params';\n const expectedWebItemKey = 'two-conditions-with-params__extension__js';\n\n // First condition\n const expectedFistConditionParam = {\n attrs: {\n name: 'MyParam',\n },\n '#text': 'My Value',\n };\n\n const expectedFirstCondition = {\n attrs: { class: 'com.acme.MyFirstCondition' },\n param: [expectedFistConditionParam],\n };\n\n // Second condition\n const expectedSecondConditionParamFoo = {\n attrs: {\n name: 'foo',\n },\n '#text': 'bar',\n };\n\n const expectedSecondConditionParamBiz = {\n attrs: {\n name: 'biz',\n },\n '#text': 'baz',\n };\n\n const expectedSecondCondition = {\n attrs: { class: 'com.acme.MySecondCondition' },\n param: [expectedSecondConditionParamFoo, expectedSecondConditionParamBiz],\n };\n\n // Condition\n const expectedConditions = {\n attrs: {\n type: 'AND',\n },\n\n condition: [expectedFirstCondition, expectedSecondCondition],\n };\n\n const expectedWebItemDeclarationShape = expect.objectContaining({\n 'web-item': expect.arrayContaining([\n {\n attrs: {\n key: expectedWebItemKey,\n section: expectedExtensionPoint,\n weight: expect.anything(),\n },\n label: expect.anything(),\n conditions: [expectedConditions],\n link: expect.anything(),\n },\n ]),\n });\n\n const outputJson = getOutputContentAsJson(fileContent(join(outputDir, xmlCseOutputFilename)));\n expect(outputJson).toContainEqual(expectedWebItemDeclarationShape);\n });\n});\n\ndescribe('condition compilation errors', () => {\n const inputDir = path.resolve(__dirname, '__fixtures__/conditions-errors/');\n const outputDir = path.resolve(__dirname, '__fixtures__/target/');\n const xmlOutputFilename = 'wr-generated-cse-condition-errors.xml';\n\n const getWebpackConfig = (csePattern: string) => {\n const basicWrmPlugin = new WrmPlugin({\n pluginKey: PLUGIN_KEY,\n xmlDescriptors: resolve(outputDir, 'wrm.xml'),\n });\n\n const csePlugin = new Plugin({\n cwd: inputDir,\n pattern: csePattern,\n xmlDescriptors: resolve(outputDir, xmlOutputFilename),\n });\n\n const webpackConfig = {\n entry: csePlugin.generateEntrypoints(),\n plugins: [basicWrmPlugin, csePlugin],\n optimization: {\n minimize: false,\n },\n output: {\n path: outputDir,\n },\n };\n\n return webpackConfig;\n };\n\n const compile = async (config: webpack.Configuration) => {\n const compiler = webpack(config);\n const run = promisify(compiler.run.bind(compiler));\n\n return (await run()) as Stats;\n };\n\n it('should throw an error when specifying an empty @condition annotation', async () => {\n const errorFile = '**/empty-condition.*';\n\n // error is Sync because it's the plugin that fails, not webpack compilation.\n expect(() => compile(getWebpackConfig(errorFile))).toThrowError();\n });\n\n it('should throw an error when specifying an invalid condition class', async () => {\n const errorFile = '**/invalid-condition-class.*';\n\n expect(() => compile(getWebpackConfig(errorFile))).toThrowError();\n });\n});\n"]}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const path_1 = require("path");
|
|
5
|
-
const util_1 = require("util");
|
|
6
|
-
const atlassian_webresource_webpack_plugin_1 = tslib_1.__importDefault(require("atlassian-webresource-webpack-plugin"));
|
|
7
|
-
const utils_1 = require("ts-jest/utils");
|
|
8
|
-
const test_helper_1 = require("./tests/test-helper");
|
|
9
|
-
// eslint-disable-next-line import/order
|
|
10
|
-
const webpack = require("webpack");
|
|
11
|
-
const Plugin = require("./ClientsideExtensionsWebpackPlugin");
|
|
12
|
-
const inputDir = path_1.resolve(__dirname, '__fixtures__/metadata/');
|
|
13
|
-
const outputDir = path_1.resolve(__dirname, '__fixtures__/target/');
|
|
14
|
-
beforeAll(() => {
|
|
15
|
-
// Silent-down the webpack compilation errors
|
|
16
|
-
jest.spyOn(console, 'error').mockImplementation();
|
|
17
|
-
});
|
|
18
|
-
afterAll(() => {
|
|
19
|
-
utils_1.mocked(console.error).mockRestore();
|
|
20
|
-
});
|
|
21
|
-
describe('comment metadata to XML attributes/elements', () => {
|
|
22
|
-
const fileName = 'metadata-test-fragments.xml';
|
|
23
|
-
const basicWrmPlugin = new atlassian_webresource_webpack_plugin_1.default({
|
|
24
|
-
pluginKey: 'a.fake.plugin.key',
|
|
25
|
-
xmlDescriptors: path_1.resolve(outputDir, 'metadata-test.xml'),
|
|
26
|
-
});
|
|
27
|
-
const basicPlugin = new Plugin({
|
|
28
|
-
cwd: inputDir,
|
|
29
|
-
pattern: '**/*.extension.js',
|
|
30
|
-
xmlDescriptors: path_1.resolve(outputDir, fileName),
|
|
31
|
-
});
|
|
32
|
-
// base config for all tests
|
|
33
|
-
const baseWebpackConfig = {
|
|
34
|
-
entry: {
|
|
35
|
-
...basicPlugin.generateEntrypoints(),
|
|
36
|
-
},
|
|
37
|
-
optimization: {
|
|
38
|
-
minimize: false,
|
|
39
|
-
},
|
|
40
|
-
plugins: [basicWrmPlugin, basicPlugin],
|
|
41
|
-
output: {
|
|
42
|
-
path: outputDir,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
beforeAll(async () => {
|
|
46
|
-
const compiler = webpack(baseWebpackConfig);
|
|
47
|
-
const run = util_1.promisify(compiler.run.bind(compiler));
|
|
48
|
-
await run();
|
|
49
|
-
});
|
|
50
|
-
it('should replace $key with the key of the extension when specified', () => {
|
|
51
|
-
const webItemDeclaration = /<web-item key="key_replacement_test__extension__js" section="webpage-with-condition" weight="">/;
|
|
52
|
-
const labelDeclaration = /<label key="My Extension key is a.fake.plugin.key:key_replacement_test__extension__js"\/>/;
|
|
53
|
-
const linkDeclaration = /<link >\/plugins\/servlet\/my-page-with-condition\?q=a.fake.plugin.key:key_replacement_test__extension__js<\/link>/;
|
|
54
|
-
const urlDeclaration = /<url-pattern >\/my-page-with-condition\?q=a.fake.plugin.key:key_replacement_test__extension__js<\/url-pattern>/;
|
|
55
|
-
const xmlFileContent = test_helper_1.fileContent(path_1.join(outputDir, fileName));
|
|
56
|
-
expect(xmlFileContent).toMatch(webItemDeclaration);
|
|
57
|
-
expect(xmlFileContent).toMatch(labelDeclaration);
|
|
58
|
-
expect(xmlFileContent).toMatch(linkDeclaration);
|
|
59
|
-
expect(xmlFileContent).toMatch(urlDeclaration);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
//# sourceMappingURL=ClientsideExtensionsWebpackPlugin.metadata.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClientsideExtensionsWebpackPlugin.metadata.test.js","sourceRoot":"","sources":["../../lib/ClientsideExtensionsWebpackPlugin.metadata.test.ts"],"names":[],"mappings":";;;AAAA,+BAAqC;AACrC,+BAAiC;AACjC,wHAA6D;AAC7D,yCAAuC;AACvC,qDAAkD;AAElD,wCAAwC;AACxC,mCAAoC;AACpC,8DAA+D;AAE/D,MAAM,QAAQ,GAAG,cAAO,CAAC,SAAS,EAAE,wBAAwB,CAAC,CAAC;AAC9D,MAAM,SAAS,GAAG,cAAO,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC;AAE7D,SAAS,CAAC,GAAG,EAAE;IACX,6CAA6C;IAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,kBAAkB,EAAE,CAAC;AACtD,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,GAAG,EAAE;IACV,cAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AACxC,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,6CAA6C,EAAE,GAAG,EAAE;IACzD,MAAM,QAAQ,GAAG,6BAA6B,CAAC;IAE/C,MAAM,cAAc,GAAG,IAAI,8CAAS,CAAC;QACjC,SAAS,EAAE,mBAAmB;QAC9B,cAAc,EAAE,cAAO,CAAC,SAAS,EAAE,mBAAmB,CAAC;KAC1D,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC;QAC3B,GAAG,EAAE,QAAQ;QACb,OAAO,EAAE,mBAAmB;QAC5B,cAAc,EAAE,cAAO,CAAC,SAAS,EAAE,QAAQ,CAAC;KAC/C,CAAC,CAAC;IAEH,4BAA4B;IAC5B,MAAM,iBAAiB,GAAG;QACtB,KAAK,EAAE;YACH,GAAG,WAAW,CAAC,mBAAmB,EAAE;SACvC;QACD,YAAY,EAAE;YACV,QAAQ,EAAE,KAAK;SAClB;QACD,OAAO,EAAE,CAAC,cAAc,EAAE,WAAW,CAAC;QACtC,MAAM,EAAE;YACJ,IAAI,EAAE,SAAS;SAClB;KACJ,CAAC;IAEF,SAAS,CAAC,KAAK,IAAI,EAAE;QACjB,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAC5C,MAAM,GAAG,GAAG,gBAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QACnD,MAAM,GAAG,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE;QACxE,MAAM,kBAAkB,GAAG,iGAAiG,CAAC;QAC7H,MAAM,gBAAgB,GAAG,2FAA2F,CAAC;QAErH,MAAM,eAAe,GACjB,oHAAoH,CAAC;QAEzH,MAAM,cAAc,GAChB,gHAAgH,CAAC;QAErH,MAAM,cAAc,GAAG,yBAAW,CAAC,WAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;QAE9D,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QACnD,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACjD,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QAChD,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { resolve, join } from 'path';\nimport { promisify } from 'util';\nimport WrmPlugin from 'atlassian-webresource-webpack-plugin';\nimport { mocked } from 'ts-jest/utils';\nimport { fileContent } from './tests/test-helper';\n\n// eslint-disable-next-line import/order\nimport webpack = require('webpack');\nimport Plugin = require('./ClientsideExtensionsWebpackPlugin');\n\nconst inputDir = resolve(__dirname, '__fixtures__/metadata/');\nconst outputDir = resolve(__dirname, '__fixtures__/target/');\n\nbeforeAll(() => {\n // Silent-down the webpack compilation errors\n jest.spyOn(console, 'error').mockImplementation();\n});\n\nafterAll(() => {\n mocked(console.error).mockRestore();\n});\n\ndescribe('comment metadata to XML attributes/elements', () => {\n const fileName = 'metadata-test-fragments.xml';\n\n const basicWrmPlugin = new WrmPlugin({\n pluginKey: 'a.fake.plugin.key',\n xmlDescriptors: resolve(outputDir, 'metadata-test.xml'),\n });\n\n const basicPlugin = new Plugin({\n cwd: inputDir,\n pattern: '**/*.extension.js',\n xmlDescriptors: resolve(outputDir, fileName),\n });\n\n // base config for all tests\n const baseWebpackConfig = {\n entry: {\n ...basicPlugin.generateEntrypoints(),\n },\n optimization: {\n minimize: false,\n },\n plugins: [basicWrmPlugin, basicPlugin],\n output: {\n path: outputDir,\n },\n };\n\n beforeAll(async () => {\n const compiler = webpack(baseWebpackConfig);\n const run = promisify(compiler.run.bind(compiler));\n await run();\n });\n\n it('should replace $key with the key of the extension when specified', () => {\n const webItemDeclaration = /<web-item key=\"key_replacement_test__extension__js\" section=\"webpage-with-condition\" weight=\"\">/;\n const labelDeclaration = /<label key=\"My Extension key is a.fake.plugin.key:key_replacement_test__extension__js\"\\/>/;\n\n const linkDeclaration =\n /<link >\\/plugins\\/servlet\\/my-page-with-condition\\?q=a.fake.plugin.key:key_replacement_test__extension__js<\\/link>/;\n\n const urlDeclaration =\n /<url-pattern >\\/my-page-with-condition\\?q=a.fake.plugin.key:key_replacement_test__extension__js<\\/url-pattern>/;\n\n const xmlFileContent = fileContent(join(outputDir, fileName));\n\n expect(xmlFileContent).toMatch(webItemDeclaration);\n expect(xmlFileContent).toMatch(labelDeclaration);\n expect(xmlFileContent).toMatch(linkDeclaration);\n expect(xmlFileContent).toMatch(urlDeclaration);\n });\n});\n"]}
|