@atlassian/webresource-webpack-plugin 4.10.2-64a2ef2
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/.eslintignore +20 -0
- package/.eslintrc +72 -0
- package/.nvmrc +1 -0
- package/.prettierrc +6 -0
- package/CHANGELOG.md +318 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +13 -0
- package/README.md +709 -0
- package/RELEASE.md +17 -0
- package/package.json +118 -0
- package/src/AppResources.js +198 -0
- package/src/QUnitTestResources.js +88 -0
- package/src/WebpackHelpers.js +176 -0
- package/src/WebpackRuntimeHelpers.js +7 -0
- package/src/WrmPlugin.js +676 -0
- package/src/defaults/builtInProvidedDependencies.js +22 -0
- package/src/flattenReduce.js +1 -0
- package/src/helpers/options-parser.js +32 -0
- package/src/helpers/provided-dependencies.js +21 -0
- package/src/helpers/string.js +12 -0
- package/src/helpers/web-resource-entrypoints.js +66 -0
- package/src/helpers/web-resource-generator.js +138 -0
- package/src/helpers/web-resource-parser.js +44 -0
- package/src/helpers/xml.js +44 -0
- package/src/logger.js +28 -0
- package/src/mergeMaps.js +32 -0
- package/src/renderCondition.js +29 -0
- package/src/renderTransformation.js +44 -0
- package/src/settings/base-dependencies.js +42 -0
- package/src/shims/qunit-require-shim.js +19 -0
- package/src/types/typedefs.js +50 -0
- package/src/webpack-modules/EmptyExportsModule.js +26 -0
- package/src/webpack-modules/ProvidedExternalDependencyModule.js +30 -0
- package/src/webpack-modules/WrmDependencyModule.js +12 -0
- package/src/webpack-modules/WrmResourceModule.js +33 -0
- package/test/.eslintrc +11 -0
- package/test/unit/ProvidedExternalDependencyModule.test.js +63 -0
- package/test/unit/WebpackHelpers.test.js +37 -0
- package/test/unit/renderCondition.test.js +240 -0
- package/test/unit/renderTransformation.test.js +69 -0
- package/test/unit/webpack-modules/WrmDependencyModule.test.js +24 -0
- package/test/use-cases/.eslintrc +14 -0
- package/test/use-cases/asset-content-type/asset-content-type.test.js +50 -0
- package/test/use-cases/asset-content-type/src/app.js +8 -0
- package/test/use-cases/asset-content-type/src/ice.png +0 -0
- package/test/use-cases/asset-content-type/src/rect.svg +4 -0
- package/test/use-cases/asset-content-type/webpack.config.js +33 -0
- package/test/use-cases/asset-loading-via-js/asset-loading-via-js.test.js +61 -0
- package/test/use-cases/asset-loading-via-js/src/app.js +8 -0
- package/test/use-cases/asset-loading-via-js/src/ice.png +0 -0
- package/test/use-cases/asset-loading-via-js/src/rect.svg +4 -0
- package/test/use-cases/asset-loading-via-js/webpack.config.js +31 -0
- package/test/use-cases/associations-complex/associations-complex.test.js +82 -0
- package/test/use-cases/associations-complex/package-lock.json +73 -0
- package/test/use-cases/associations-complex/package.json +9 -0
- package/test/use-cases/associations-complex/src/copied-file-should-be-ignored.js +0 -0
- package/test/use-cases/associations-complex/src/entry.js +5 -0
- package/test/use-cases/associations-complex/src/entry2.js +5 -0
- package/test/use-cases/associations-complex/src/qunit.tests.js +2 -0
- package/test/use-cases/associations-complex/src/to-be-chunked.js +1 -0
- package/test/use-cases/associations-complex/webpack.config.js +48 -0
- package/test/use-cases/associations-simple/associations-simple.test.js +65 -0
- package/test/use-cases/associations-simple/package-lock.json +69 -0
- package/test/use-cases/associations-simple/package.json +5 -0
- package/test/use-cases/associations-simple/src/simple.js +3 -0
- package/test/use-cases/associations-simple/webpack.config.js +27 -0
- package/test/use-cases/async-chunks/async-chunks.test.js +113 -0
- package/test/use-cases/async-chunks/src/app.js +9 -0
- package/test/use-cases/async-chunks/src/async-bar.js +4 -0
- package/test/use-cases/async-chunks/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks/webpack.config.js +40 -0
- package/test/use-cases/async-chunks-named-context/async-chunks-named-context.test.js +76 -0
- package/test/use-cases/async-chunks-named-context/src/app.js +9 -0
- package/test/use-cases/async-chunks-named-context/src/app2.js +5 -0
- package/test/use-cases/async-chunks-named-context/src/async-async-async-bar.js +4 -0
- package/test/use-cases/async-chunks-named-context/src/async-async-bar-two.js +1 -0
- package/test/use-cases/async-chunks-named-context/src/async-async-bar.js +6 -0
- package/test/use-cases/async-chunks-named-context/src/async-bar.js +7 -0
- package/test/use-cases/async-chunks-named-context/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks-named-context/webpack.config.js +43 -0
- package/test/use-cases/async-chunks-of-async-chunks/async-chunks-of-async-chunks.test.js +117 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/app.js +9 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-async-async-bar.js +4 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-async-bar-two.js +1 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-async-bar.js +6 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-bar.js +7 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks-of-async-chunks/webpack.config.js +43 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/async-chunks-of-async-chunks-with-multiple-entrypoints.test.js +156 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/app.js +9 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/app2.js +5 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-async-bar.js +4 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-bar-two.js +1 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-bar.js +6 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-bar.js +7 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/webpack.config.js +43 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/css-and-assets-distribution-via-mini-css-extract-plugin.test.js +72 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/app.js +8 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/app2.js +6 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/ice.png +0 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/ice2.jpg +0 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/rect.svg +4 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/rect2.svg +4 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/styles.css +8 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/styles2.css +8 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/webpack.config.js +51 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/css-and-assets-via-extract-text-plugin.test.js +87 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-one.css +7 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-one.js +3 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-two.css +3 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-two.js +1 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/ice.png +0 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/webpack.config.js +46 -0
- package/test/use-cases/css-and-assets-via-style-loader/css-and-assets-via-style-loader.test.js +46 -0
- package/test/use-cases/css-and-assets-via-style-loader/src/app.js +6 -0
- package/test/use-cases/css-and-assets-via-style-loader/src/ice.png +0 -0
- package/test/use-cases/css-and-assets-via-style-loader/src/styles.css +7 -0
- package/test/use-cases/css-and-assets-via-style-loader/webpack.config.js +46 -0
- package/test/use-cases/cyclic-dependencies/cyclic.test.js +24 -0
- package/test/use-cases/cyclic-dependencies/src/a.js +3 -0
- package/test/use-cases/cyclic-dependencies/src/b.js +3 -0
- package/test/use-cases/cyclic-dependencies/src/root.js +3 -0
- package/test/use-cases/cyclic-dependencies/webpack.config.js +24 -0
- package/test/use-cases/data-providers/data-providers.test.js +111 -0
- package/test/use-cases/data-providers/src/first.js +2 -0
- package/test/use-cases/data-providers/src/second.js +2 -0
- package/test/use-cases/data-providers/src/third.js +2 -0
- package/test/use-cases/data-providers/webpack.config.js +73 -0
- package/test/use-cases/data-providers/webpack.config.with-map.js +33 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/ensure-runtime-overwrite-of-mini-css-extract-plugin.test.js +86 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/app.js +5 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/app2.js +5 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/ice.png +0 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/ice2.jpg +0 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/rect.svg +4 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/rect2.svg +4 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/styles.css +8 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/styles2.css +8 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/webpack.after.config.js +51 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/webpack.before.config.js +51 -0
- package/test/use-cases/jsonp-function-name/jsonp-function-name.test.js +37 -0
- package/test/use-cases/jsonp-function-name/src/app.js +1 -0
- package/test/use-cases/jsonp-function-name/src/foo.js +2 -0
- package/test/use-cases/jsonp-function-name/webpack.config.js +35 -0
- package/test/use-cases/jsonp-function-name-default/jsonp-function-name-default.test.js +39 -0
- package/test/use-cases/jsonp-function-name-default/src/app.js +1 -0
- package/test/use-cases/jsonp-function-name-default/src/foo.js +2 -0
- package/test/use-cases/jsonp-function-name-default/webpack.config.js +34 -0
- package/test/use-cases/location-prefix/location-prefix.test.js +29 -0
- package/test/use-cases/location-prefix/src/simple.js +6 -0
- package/test/use-cases/location-prefix/webpack.config.js +25 -0
- package/test/use-cases/provided-module-replacement/provided-module-replacement.test.js +63 -0
- package/test/use-cases/provided-module-replacement/src/app.js +3 -0
- package/test/use-cases/provided-module-replacement/webpack.config.with-map.js +33 -0
- package/test/use-cases/provided-module-replacement/webpack.config.with-object.js +34 -0
- package/test/use-cases/provided-modules-replacement-with-amd-target/provided-modules-replacement-with-amd-target.test.js +62 -0
- package/test/use-cases/provided-modules-replacement-with-amd-target/src/app.js +3 -0
- package/test/use-cases/provided-modules-replacement-with-amd-target/webpack.config.js +41 -0
- package/test/use-cases/qunit-test-wrm-web-resource/qunit-test-wrm-web-resource.test.js +157 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/app.2.js +6 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/app.js +8 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/bar-dep.js +8 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/bar-dep_test.js +1 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/foo-async.js +3 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/foo-dep.js +4 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/foo-dep_test.js +1 -0
- package/test/use-cases/qunit-test-wrm-web-resource/webpack.config.js +24 -0
- package/test/use-cases/resource-parameters/resource-parameters.test.js +77 -0
- package/test/use-cases/resource-parameters/src/app.js +12 -0
- package/test/use-cases/resource-parameters/src/ice.png +0 -0
- package/test/use-cases/resource-parameters/src/ice2.jpg +0 -0
- package/test/use-cases/resource-parameters/src/rect.svg +4 -0
- package/test/use-cases/resource-parameters/webpack.config.js +62 -0
- package/test/use-cases/resource-parameters/webpack.svg.config.js +30 -0
- package/test/use-cases/simple/simple.test.js +83 -0
- package/test/use-cases/simple/src/simple.js +3 -0
- package/test/use-cases/simple/webpack.config.js +24 -0
- package/test/use-cases/single-runtime-chunk/single-runtime-chunk.test.js +132 -0
- package/test/use-cases/single-runtime-chunk/src/first.js +2 -0
- package/test/use-cases/single-runtime-chunk/src/second.js +2 -0
- package/test/use-cases/single-runtime-chunk/src/shared.js +3 -0
- package/test/use-cases/single-runtime-chunk/src/third.js +2 -0
- package/test/use-cases/single-runtime-chunk/webpack.config.js +33 -0
- package/test/use-cases/specify-asset-dev-hash/specify-asset-dev-hash.test.js +33 -0
- package/test/use-cases/specify-asset-dev-hash/src/feature.js +6 -0
- package/test/use-cases/specify-asset-dev-hash/src/library.js +6 -0
- package/test/use-cases/specify-asset-dev-hash/webpack.config.js +71 -0
- package/test/use-cases/specify-conditions/specify-conditions.test.js +106 -0
- package/test/use-cases/specify-conditions/src/app.js +5 -0
- package/test/use-cases/specify-conditions/webpack.config.js +65 -0
- package/test/use-cases/specify-explicit-context/specify-explicit-context.test.js +89 -0
- package/test/use-cases/specify-explicit-context/src/app.js +5 -0
- package/test/use-cases/specify-explicit-context/webpack.config.js +34 -0
- package/test/use-cases/specify-explicit-context-no-autogenerated/specify-explicit-context-no-autogenerated.test.js +84 -0
- package/test/use-cases/specify-explicit-context-no-autogenerated/src/app.js +5 -0
- package/test/use-cases/specify-explicit-context-no-autogenerated/webpack.config.js +35 -0
- package/test/use-cases/specify-explicit-name/specify-explicit-name.test.js +110 -0
- package/test/use-cases/specify-explicit-name/src/app.js +5 -0
- package/test/use-cases/specify-explicit-name/webpack.config.js +43 -0
- package/test/use-cases/specify-explicit-state/specify-explicit-state.test.js +96 -0
- package/test/use-cases/specify-explicit-state/src/app.js +5 -0
- package/test/use-cases/specify-explicit-state/webpack.config.js +51 -0
- package/test/use-cases/specify-transformation/disable-transformations.test.js +77 -0
- package/test/use-cases/specify-transformation/extend-transformations.test.js +69 -0
- package/test/use-cases/specify-transformation/specify-transformation.test.js +100 -0
- package/test/use-cases/specify-transformation/src/app.js +13 -0
- package/test/use-cases/specify-transformation/src/ice.png +0 -0
- package/test/use-cases/specify-transformation/src/rect.svg +4 -0
- package/test/use-cases/specify-transformation/src/test.html +1 -0
- package/test/use-cases/specify-transformation/src/test.less +1 -0
- package/test/use-cases/specify-transformation/src/test.txt +1 -0
- package/test/use-cases/specify-transformation/webpack.disable-tranformations.config.js +31 -0
- package/test/use-cases/specify-transformation/webpack.extend-tranformations.config.js +34 -0
- package/test/use-cases/specify-transformation/webpack.specify-transformations.config.js +35 -0
- package/test/use-cases/split-chunks/split-chunks.test.js +102 -0
- package/test/use-cases/split-chunks/src/app.js +7 -0
- package/test/use-cases/split-chunks/src/app2.js +7 -0
- package/test/use-cases/split-chunks/src/bar.js +2 -0
- package/test/use-cases/split-chunks/src/foo.js +2 -0
- package/test/use-cases/split-chunks/src/foo2.js +2 -0
- package/test/use-cases/split-chunks/webpack.config.js +42 -0
- package/test/use-cases/split-chunks-with-runtime/split-chunks-with-runtime.test.js +114 -0
- package/test/use-cases/split-chunks-with-runtime/src/app.js +7 -0
- package/test/use-cases/split-chunks-with-runtime/src/app2.js +7 -0
- package/test/use-cases/split-chunks-with-runtime/src/bar.js +2 -0
- package/test/use-cases/split-chunks-with-runtime/src/foo.js +2 -0
- package/test/use-cases/split-chunks-with-runtime/src/foo2.js +2 -0
- package/test/use-cases/split-chunks-with-runtime/webpack.config.js +43 -0
- package/test/use-cases/split-chunks-with-tests/split-chunks-with-tests.test.js +216 -0
- package/test/use-cases/split-chunks-with-tests/src/app.js +7 -0
- package/test/use-cases/split-chunks-with-tests/src/app2.js +7 -0
- package/test/use-cases/split-chunks-with-tests/src/bar.js +2 -0
- package/test/use-cases/split-chunks-with-tests/src/bar_test.js +1 -0
- package/test/use-cases/split-chunks-with-tests/src/foo.js +2 -0
- package/test/use-cases/split-chunks-with-tests/src/foo2.js +2 -0
- package/test/use-cases/split-chunks-with-tests/src/foo_test.js +1 -0
- package/test/use-cases/split-chunks-with-tests/webpack.config.js +43 -0
- package/test/use-cases/standalone/src/standalone-1.js +1 -0
- package/test/use-cases/standalone/src/standalone-2.js +1 -0
- package/test/use-cases/standalone/standalone.test.js +53 -0
- package/test/use-cases/standalone/webpack.config.js +25 -0
- package/test/use-cases/wrm-dependency-loading/src-amd/app.js +7 -0
- package/test/use-cases/wrm-dependency-loading/src-es6/app.js +7 -0
- package/test/use-cases/wrm-dependency-loading/webpack.config.amd.js +22 -0
- package/test/use-cases/wrm-dependency-loading/webpack.config.es6.js +22 -0
- package/test/use-cases/wrm-dependency-loading/wrm-dependency-loading.test.js +60 -0
- package/test/use-cases/wrm-manifest-path/src/a.js +3 -0
- package/test/use-cases/wrm-manifest-path/src/app.js +3 -0
- package/test/use-cases/wrm-manifest-path/src/app2.js +3 -0
- package/test/use-cases/wrm-manifest-path/src/b.js +3 -0
- package/test/use-cases/wrm-manifest-path/webpack.config.js +27 -0
- package/test/use-cases/wrm-manifest-path/wrm-manifest-path.test.js +57 -0
- package/test/use-cases/wrm-resource-loading/src-amd/app.js +6 -0
- package/test/use-cases/wrm-resource-loading/src-es6/app.js +5 -0
- package/test/use-cases/wrm-resource-loading/src-relative/app.js +5 -0
- package/test/use-cases/wrm-resource-loading/webpack.config.amd.js +23 -0
- package/test/use-cases/wrm-resource-loading/webpack.config.es6.js +23 -0
- package/test/use-cases/wrm-resource-loading/webpack.config.relative.js +23 -0
- package/test/use-cases/wrm-resource-loading/wrm-resource-loading.test.js +89 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { buildProvidedDependency } = require('../helpers/provided-dependencies');
|
|
2
|
+
|
|
3
|
+
const webresourcePluginName = 'com.atlassian.plugins.atlassian-plugins-webresource-plugin';
|
|
4
|
+
const webresourceDep = buildProvidedDependency.bind(undefined, webresourcePluginName);
|
|
5
|
+
|
|
6
|
+
const builtInProvidedDependencies = new Map()
|
|
7
|
+
.set(
|
|
8
|
+
'wrm/require',
|
|
9
|
+
buildProvidedDependency(
|
|
10
|
+
'com.atlassian.plugins.atlassian-plugins-webresource-rest',
|
|
11
|
+
'web-resource-manager',
|
|
12
|
+
'WRM.require',
|
|
13
|
+
'wrm/require'
|
|
14
|
+
)
|
|
15
|
+
)
|
|
16
|
+
.set('wrm/context-path', webresourceDep('context-path', 'WRM.contextPath', 'wrm/context-path'))
|
|
17
|
+
.set('wrm/data', webresourceDep('data', 'WRM.data', 'wrm/data'))
|
|
18
|
+
.set('wrm/format', webresourceDep('format', 'WRM.format', 'wrm/format'));
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
builtInProvidedDependencies,
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = (a, b) => a.concat(b);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const pathSeparatorRegex = new RegExp(`^\\${path.sep}|\\${path.sep}$`, 'g');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts an object in to a Map.
|
|
7
|
+
* @param {Object} original
|
|
8
|
+
* @returns {Map} a map with key-value pairs from the object.
|
|
9
|
+
* returns an empty map if the original value was falsy or not an object.
|
|
10
|
+
*/
|
|
11
|
+
function toMap(original) {
|
|
12
|
+
if (original instanceof Map) {
|
|
13
|
+
return original;
|
|
14
|
+
}
|
|
15
|
+
return original && typeof original === 'object' ? new Map(Object.entries(original)) : new Map();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function extractPathPrefixForXml(pathPrefix) {
|
|
19
|
+
if (!pathPrefix || pathPrefix === '' || pathPrefix === '/') {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// remove leading/trailing path separator
|
|
24
|
+
const withoutLeadingTrailingSeparators = pathPrefix.replace(pathSeparatorRegex, '');
|
|
25
|
+
// readd trailing slash - this time OS independent always a "/"
|
|
26
|
+
return withoutLeadingTrailingSeparators + '/';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = {
|
|
30
|
+
toMap,
|
|
31
|
+
extractPathPrefixForXml,
|
|
32
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {String} pluginKey
|
|
4
|
+
* @param {String} resourceKey
|
|
5
|
+
* @param {String} importVar
|
|
6
|
+
* @param {String} importAmd
|
|
7
|
+
* @return {{dependency: string, import: {var: *, amd: *}}}
|
|
8
|
+
*/
|
|
9
|
+
function buildProvidedDependency(pluginKey, resourceKey, importVar, importAmd) {
|
|
10
|
+
return {
|
|
11
|
+
dependency: `${pluginKey}:${resourceKey}`,
|
|
12
|
+
import: {
|
|
13
|
+
var: importVar,
|
|
14
|
+
amd: importAmd,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
buildProvidedDependency,
|
|
21
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {*} val - the initial value of varying type
|
|
3
|
+
* @returns {string} a trimmed string value
|
|
4
|
+
*/
|
|
5
|
+
function parseString(val) {
|
|
6
|
+
let maybeStr = val && val.length ? String(val) : '';
|
|
7
|
+
return maybeStr.trim();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
parseString,
|
|
12
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const { parseWebResourceAttributes } = require('./web-resource-parser');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {String} entry
|
|
5
|
+
* @param {Map<String, Array<String>>} contextMap
|
|
6
|
+
* @param {Boolean} addEntrypointNameAsContext
|
|
7
|
+
* @returns {Array<String>}
|
|
8
|
+
*/
|
|
9
|
+
function getContextForEntry(entry, contextMap, addEntrypointNameAsContext) {
|
|
10
|
+
const contexts = [].concat(contextMap.get(entry));
|
|
11
|
+
if (addEntrypointNameAsContext) {
|
|
12
|
+
contexts.unshift(entry);
|
|
13
|
+
}
|
|
14
|
+
return contexts.filter(context => context && typeof context === 'string');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {String} entry
|
|
19
|
+
* @param {Map<String, String>} webresourceKeyMap
|
|
20
|
+
* @returns {WebResourceAttributes}
|
|
21
|
+
*/
|
|
22
|
+
function getWebresourceAttributesForEntry(entry, webresourceKeyMap) {
|
|
23
|
+
const wrKey = webresourceKeyMap.get(entry);
|
|
24
|
+
|
|
25
|
+
// Create the default attribute values
|
|
26
|
+
let attrs = { key: `entrypoint-${entry}`, moduleId: entry };
|
|
27
|
+
|
|
28
|
+
// Extend the attributes with parsed, valid values
|
|
29
|
+
if (typeof wrKey === 'object') {
|
|
30
|
+
attrs = Object.assign(attrs, parseWebResourceAttributes(wrKey));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Override the key if a non-empty string is provided
|
|
34
|
+
if (typeof wrKey === 'string') {
|
|
35
|
+
attrs = Object.assign(attrs, parseWebResourceAttributes({ key: wrKey }));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return attrs;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {String} entry
|
|
43
|
+
* @param {Map<String, Object>} conditionMap
|
|
44
|
+
* @returns {*}
|
|
45
|
+
*/
|
|
46
|
+
function getConditionForEntry(entry, conditionMap) {
|
|
47
|
+
return conditionMap.get(entry);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves the list of data providers for given entrypoint
|
|
52
|
+
*
|
|
53
|
+
* @param {String} entrypoint - webpack entrypoint key
|
|
54
|
+
* @param {Map<String, DataProvider[]>} dataProvidersMap - All data providers from plugin options
|
|
55
|
+
* @return {DataProvider[]} - List of data providers for given entry point
|
|
56
|
+
*/
|
|
57
|
+
function getDataProvidersForEntry(entrypoint, dataProvidersMap) {
|
|
58
|
+
return dataProvidersMap.get(entrypoint) || [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = {
|
|
62
|
+
getContextForEntry,
|
|
63
|
+
getConditionForEntry,
|
|
64
|
+
getWebresourceAttributesForEntry,
|
|
65
|
+
getDataProvidersForEntry,
|
|
66
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { renderElement } = require('./xml');
|
|
3
|
+
const { parseWebResourceAttributes } = require('./web-resource-parser');
|
|
4
|
+
const renderCondition = require('../renderCondition');
|
|
5
|
+
const renderTransformation = require('../renderTransformation');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Renders list of data providers {@see DataProvider} as <data key="provider-key" class="data.provider.Class" /> elements
|
|
9
|
+
*
|
|
10
|
+
* @param {DataProvider[]} dataProviders
|
|
11
|
+
* @return {string[]}
|
|
12
|
+
*/
|
|
13
|
+
const renderDataProviders = dataProviders => {
|
|
14
|
+
if (!Array.isArray(dataProviders) || !dataProviders.length < 0) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return dataProviders.map(dataProvider =>
|
|
19
|
+
renderElement('data', {
|
|
20
|
+
key: dataProvider.key,
|
|
21
|
+
class: dataProvider.class,
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function generateContext(contexts) {
|
|
27
|
+
return contexts ? contexts.map(context => `<context>${context}</context>`).join('') : '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function generateDependencies(dependencies) {
|
|
31
|
+
return dependencies ? dependencies.map(dependency => `<dependency>${dependency}</dependency>`).join('\n') : '';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {Resource} resource
|
|
36
|
+
* @param {Map<String, Array<Object>>} parameterMap
|
|
37
|
+
* @returns {string} an XML representation of a {@link Resource}.
|
|
38
|
+
*/
|
|
39
|
+
function generateResourceElement(resource, parameterMap) {
|
|
40
|
+
const { name, location } = resource;
|
|
41
|
+
const assetContentType = path.extname(location).substr(1);
|
|
42
|
+
const parameters = parameterMap.get(assetContentType) || [];
|
|
43
|
+
const children = [];
|
|
44
|
+
const renderParameters = attributes => children.push(renderElement('param', attributes));
|
|
45
|
+
parameters.forEach(renderParameters);
|
|
46
|
+
|
|
47
|
+
return renderElement(
|
|
48
|
+
'resource',
|
|
49
|
+
{
|
|
50
|
+
type: 'download',
|
|
51
|
+
name,
|
|
52
|
+
location,
|
|
53
|
+
},
|
|
54
|
+
children
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Generates a <resource> descriptor that will glue the source code for a file to the qunit test runner.
|
|
60
|
+
* @param {filepath} filepath
|
|
61
|
+
* @returns {string} an XML representation of a {@link Resource}.
|
|
62
|
+
*/
|
|
63
|
+
function generateQunitResourceElement(filepath) {
|
|
64
|
+
return renderElement('resource', { type: 'qunit', name: filepath, location: filepath });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {Map<String, Array<Object>>} parameterMap
|
|
69
|
+
* @param {Resource[]} resources
|
|
70
|
+
* @returns {string} an XML string of all {@link Resource} elements
|
|
71
|
+
*/
|
|
72
|
+
function generateResources(parameterMap, resources) {
|
|
73
|
+
return resources
|
|
74
|
+
.filter(r => !!r)
|
|
75
|
+
.map(resource => generateResourceElement(resource, parameterMap))
|
|
76
|
+
.join('\n');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {WrmEntrypoint} webresource
|
|
81
|
+
* @param {Map<String, Array<String>>} transformations
|
|
82
|
+
* @param {String} pathPrefix
|
|
83
|
+
* @param {Map<String, Array<Object>>} parameterMap
|
|
84
|
+
* @param standalone
|
|
85
|
+
* @returns {string} an XML representation of the {@link WrmEntrypoint}.
|
|
86
|
+
*/
|
|
87
|
+
function createWebResource(webresource, transformations, pathPrefix = '', parameterMap = new Map(), standalone) {
|
|
88
|
+
const { resources = [], externalResources = [], contexts, dependencies, conditions, dataProviders } = webresource;
|
|
89
|
+
const attributes = parseWebResourceAttributes(webresource.attributes);
|
|
90
|
+
const allResources = [];
|
|
91
|
+
const children = [];
|
|
92
|
+
|
|
93
|
+
/** convert filepaths in to {@link Resource}s. */
|
|
94
|
+
const convertFilePaths = location => pathPrefix + location;
|
|
95
|
+
|
|
96
|
+
// add resources for direct dependencies (e.g., JS and CSS files)
|
|
97
|
+
allResources.push(...resources.map(res => ({ name: res, location: convertFilePaths(res) })));
|
|
98
|
+
|
|
99
|
+
if (standalone) {
|
|
100
|
+
children.push(generateResources(parameterMap, allResources));
|
|
101
|
+
} else {
|
|
102
|
+
// add resources for indirect dependencies (e.g., images extracted from CSS)
|
|
103
|
+
allResources.push(...externalResources.map(wr => ({ name: wr.name, location: convertFilePaths(wr.location) })));
|
|
104
|
+
|
|
105
|
+
children.push(
|
|
106
|
+
renderTransformation(transformations, allResources),
|
|
107
|
+
generateContext(contexts),
|
|
108
|
+
generateDependencies(dependencies),
|
|
109
|
+
generateResources(parameterMap, allResources),
|
|
110
|
+
renderCondition(conditions),
|
|
111
|
+
...renderDataProviders(dataProviders)
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return renderElement('web-resource', attributes, children);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function createResourceDescriptors(jsonDescriptors, transformations, pathPrefix, parameterMap, standalone) {
|
|
119
|
+
const descriptors = jsonDescriptors.map(descriptor =>
|
|
120
|
+
createWebResource(descriptor, transformations, pathPrefix, parameterMap, standalone)
|
|
121
|
+
);
|
|
122
|
+
return descriptors.join('');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function createTestResourceDescriptors(jsonTestDescriptors, transformations) {
|
|
126
|
+
const testDescriptors = jsonTestDescriptors.map(descriptor => createWebResource(descriptor, transformations));
|
|
127
|
+
return testDescriptors.join('');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function createQUnitResourceDescriptors(qUnitTestFiles) {
|
|
131
|
+
return qUnitTestFiles.map(generateQunitResourceElement).join('');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = {
|
|
135
|
+
createResourceDescriptors,
|
|
136
|
+
createTestResourceDescriptors,
|
|
137
|
+
createQUnitResourceDescriptors,
|
|
138
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const { parseString } = require('./string');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Object} data - key value pairs of potentially invalid metadata for a web-resource.
|
|
5
|
+
* @returns {WebResourceAttributes} a valid set of metadata for a web-resource.
|
|
6
|
+
*/
|
|
7
|
+
function parseWebResourceAttributes(data = {}) {
|
|
8
|
+
const attributes = {};
|
|
9
|
+
// Only parse objects.
|
|
10
|
+
if (data && data.hasOwnProperty) {
|
|
11
|
+
// define the key if a non-empty string was provided
|
|
12
|
+
if (data.hasOwnProperty('key')) {
|
|
13
|
+
let customKey = parseString(data.key);
|
|
14
|
+
if (customKey) {
|
|
15
|
+
attributes.key = customKey;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// define the state as either enabled or disabled
|
|
20
|
+
if (data.hasOwnProperty('state')) {
|
|
21
|
+
let isEnabled = true;
|
|
22
|
+
if (typeof data.state === 'boolean') {
|
|
23
|
+
isEnabled = data.state;
|
|
24
|
+
} else if (typeof data.state === 'string') {
|
|
25
|
+
isEnabled = !(data.state === 'disabled');
|
|
26
|
+
}
|
|
27
|
+
attributes.state = isEnabled ? 'enabled' : 'disabled';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// define the name if a non-empty string was provided
|
|
31
|
+
if (data.hasOwnProperty('name')) {
|
|
32
|
+
let customName = parseString(data.name);
|
|
33
|
+
if (customName) {
|
|
34
|
+
attributes.name = customName;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return attributes;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
parseWebResourceAttributes,
|
|
44
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Object} attributes
|
|
3
|
+
* @returns {string}
|
|
4
|
+
*/
|
|
5
|
+
function stringifyAttributes(attributes) {
|
|
6
|
+
if (!attributes) {
|
|
7
|
+
return '';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
' ' +
|
|
12
|
+
Object.keys(attributes)
|
|
13
|
+
.map(key => {
|
|
14
|
+
const val = typeof attributes[key] === 'undefined' ? '' : String(attributes[key]);
|
|
15
|
+
return `${key}="${val}"`;
|
|
16
|
+
})
|
|
17
|
+
.join(' ')
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function renderElement(name, attributes, children) {
|
|
22
|
+
if (typeof attributes === 'object') {
|
|
23
|
+
attributes = stringifyAttributes(attributes);
|
|
24
|
+
}
|
|
25
|
+
// avoid outputting 'undefined' when attributes aren't present.
|
|
26
|
+
if (!attributes) {
|
|
27
|
+
attributes = '';
|
|
28
|
+
}
|
|
29
|
+
// convert children array in to a string.
|
|
30
|
+
// assume they are string values already. (todo: refactor for nested rendering?)
|
|
31
|
+
if (Array.isArray(children)) {
|
|
32
|
+
children = children.join('\n');
|
|
33
|
+
}
|
|
34
|
+
// render self-closing tags based on whether there is no child input.
|
|
35
|
+
if (!children) {
|
|
36
|
+
return `<${name}${attributes}/>`;
|
|
37
|
+
}
|
|
38
|
+
return `<${name}${attributes}>${children}</${name}>`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = {
|
|
42
|
+
renderElement,
|
|
43
|
+
stringifyAttributes,
|
|
44
|
+
};
|
package/src/logger.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
let verbose = false;
|
|
3
|
+
const setVerbose = arg => (verbose = arg);
|
|
4
|
+
|
|
5
|
+
function log(...args) {
|
|
6
|
+
if (verbose) {
|
|
7
|
+
console.log(...args);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function warn(...args) {
|
|
12
|
+
if (verbose) {
|
|
13
|
+
console.warn(...args);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function error(...args) {
|
|
18
|
+
if (verbose) {
|
|
19
|
+
console.error(...args);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
log,
|
|
25
|
+
warn,
|
|
26
|
+
error,
|
|
27
|
+
setVerbose,
|
|
28
|
+
};
|
package/src/mergeMaps.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const defaultMerger = (v, k, map) => map.set(k, v);
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Combines multiple maps in to a single map, allowing control over how
|
|
5
|
+
* the values for keys are stored in the new map.
|
|
6
|
+
*
|
|
7
|
+
* The default behaviour is the value from the last map wins.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const a = new Map([['first', 1], ['second', 2]]);
|
|
11
|
+
* const b = new Map(['first', 100], ['third', 300]);
|
|
12
|
+
* mergeMaps(a, b) // Map(3) {'first' => 100, 'second' => 2, 'third' => 300}
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const a = new Map([['one', [1,2,3]]]);
|
|
16
|
+
* const b = new Map([['one', [4,5,6]]]);
|
|
17
|
+
* const merger = (map, k, newVal) => {
|
|
18
|
+
* const oldVal = map.get(k);
|
|
19
|
+
* map.set(k, [].concat(oldVal).concat(newVal));
|
|
20
|
+
* }
|
|
21
|
+
* mergeMaps(a, b, merger) // Map(1) {'one' => [1,2,3,4,5,6]}
|
|
22
|
+
*/
|
|
23
|
+
const mergeMaps = (...maps) => {
|
|
24
|
+
const source = new Map();
|
|
25
|
+
const merger = typeof maps[maps.length - 1] === 'function' ? maps.pop() : defaultMerger;
|
|
26
|
+
maps.forEach(map => {
|
|
27
|
+
Array.from(map.entries()).reduce((m, [k, v]) => merger(v, k, m), source);
|
|
28
|
+
});
|
|
29
|
+
return source;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = mergeMaps;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const { renderElement } = require('./helpers/xml');
|
|
2
|
+
|
|
3
|
+
function renderParams(params) {
|
|
4
|
+
if (!params) {
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
return params.map(param => renderElement('param', param.attributes, param.value)).join('');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = function renderCondition(condition) {
|
|
11
|
+
if (!condition) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// we have actual conditions
|
|
16
|
+
if (Array.isArray(condition)) {
|
|
17
|
+
return condition.map(renderCondition).join('');
|
|
18
|
+
}
|
|
19
|
+
// we have a "conditions"-joiner for multiple sub conditions
|
|
20
|
+
if (condition.type) {
|
|
21
|
+
return renderElement('conditions', { type: condition.type }, renderCondition(condition.conditions));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return renderElement(
|
|
25
|
+
'condition',
|
|
26
|
+
` class="${condition.class}" ${condition.invert ? `invert="true"` : ''}`,
|
|
27
|
+
renderParams(condition.params)
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { renderElement } = require('./helpers/xml');
|
|
3
|
+
const { toMap } = require('./helpers/options-parser');
|
|
4
|
+
|
|
5
|
+
function renderTransformer(transformers) {
|
|
6
|
+
if (transformers && transformers.length) {
|
|
7
|
+
return transformers.map(transformer => renderElement('transformer', { key: transformer })).join('');
|
|
8
|
+
}
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generates the appropriate function to be used when filtering a transform map down to only those required.
|
|
14
|
+
* @param {Resource[]} resources
|
|
15
|
+
* @returns {function}
|
|
16
|
+
*/
|
|
17
|
+
function transformFilterFactory(resources) {
|
|
18
|
+
if (resources && resources.length) {
|
|
19
|
+
const resourceFiletypes = resources.map(resource => path.extname(resource.location).substr(1));
|
|
20
|
+
return ext => resourceFiletypes.includes(ext);
|
|
21
|
+
}
|
|
22
|
+
return () => true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Converts a map of filetype-to-transformer entries in to the set of XML transform elements
|
|
27
|
+
* required for a given set of resources. Renders every transform if no resources are provided.
|
|
28
|
+
* @param {Map<String, Array<String>>} transformations
|
|
29
|
+
* @param {Resource[]} resources
|
|
30
|
+
* @returns {string} the rendered XML for each necessary transform.
|
|
31
|
+
*/
|
|
32
|
+
module.exports = function renderTransformation(transformations, resources = []) {
|
|
33
|
+
const transMap = toMap(transformations);
|
|
34
|
+
return Array.from(transMap.keys())
|
|
35
|
+
.filter(transformFilterFactory(resources))
|
|
36
|
+
.map(fileExtension =>
|
|
37
|
+
renderElement(
|
|
38
|
+
'transformation',
|
|
39
|
+
{ extension: fileExtension },
|
|
40
|
+
renderTransformer(transMap.get(fileExtension))
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
.join('');
|
|
44
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Collects a set of web-resource dependencies that should be added
|
|
4
|
+
* to all the web-resources generated during compilation.
|
|
5
|
+
*/
|
|
6
|
+
const _ = require('lodash');
|
|
7
|
+
const CROSS_PLATFORM_BASE_DEPS = [];
|
|
8
|
+
|
|
9
|
+
function process(arr) {
|
|
10
|
+
return _.chain([].concat(CROSS_PLATFORM_BASE_DEPS, arr))
|
|
11
|
+
.filter(val => !!val)
|
|
12
|
+
.uniq()
|
|
13
|
+
.value();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let configuredContexts = [];
|
|
17
|
+
|
|
18
|
+
function getBaseDependencies() {
|
|
19
|
+
// defensively cloning so consumers can't accidentally add anything
|
|
20
|
+
return [...configuredContexts];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function setBaseDependencies(val) {
|
|
24
|
+
const contexts = [];
|
|
25
|
+
if (val instanceof Array) {
|
|
26
|
+
contexts.push(...val);
|
|
27
|
+
} else if (typeof val === 'string') {
|
|
28
|
+
contexts.push(val);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
configuredContexts = process(contexts);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function addBaseDependency(val) {
|
|
35
|
+
configuredContexts = process([...configuredContexts, val]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
addBaseDependency,
|
|
40
|
+
getBaseDependencies,
|
|
41
|
+
setBaseDependencies,
|
|
42
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Used for qunit-tests to prevent them from failing if "resources"/"dependencies" are required.
|
|
3
|
+
* This injects a window.require to capture and ignore require-requests to "wr-dependency!/wr-resource!",
|
|
4
|
+
* while forwarding everything else
|
|
5
|
+
*/
|
|
6
|
+
module.exports = `
|
|
7
|
+
!function(){
|
|
8
|
+
var old_require = window.require;
|
|
9
|
+
window.require = function(modRequest){
|
|
10
|
+
if(modRequest.indexOf('wr-dependency!') === 0) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
if(modRequest.indexOf('wr-resource!') === 0) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return old_require.apply(this, arguments);
|
|
17
|
+
}
|
|
18
|
+
}();
|
|
19
|
+
`;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {String} filepath - a relative filepath in unix format.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {String} filename
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {String} wrKey
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {String} wrDep - a composite string in the format "maven.groupId.artifactId:webresource-key"
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {Object} Resource
|
|
19
|
+
* @property {filepath} location - the relative path for the resource,
|
|
20
|
+
* starting from the root of the plugin's classpath (the JAR file).
|
|
21
|
+
* @property {filename} name - the asset's filename as it appears in the browser at runtime.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {Object} WebResourceAttributes
|
|
26
|
+
* @property {wrKey} key - the unique identifier for this web-resource.
|
|
27
|
+
* @property {string} [name] - the human-readable name of the web-resource.
|
|
28
|
+
* @property {true|false} [state] - whether this web-resource should output its resources at runtime or not.
|
|
29
|
+
* If absent, a web-resource is assumed to be enabled.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {Object} WrmEntrypoint
|
|
34
|
+
* @description wraps a set of related resources with metadata the WRM can understand and reason about as a discrete unit.
|
|
35
|
+
* @property {WebResourceAttributes} attributes - the metadata for this web-resource.
|
|
36
|
+
* @property {filepath[]} resources - the locations of all resources directly referenced by this entrypoint's graph.
|
|
37
|
+
* @property {Resource[]} externalResources - a filename and filepath pair for resources
|
|
38
|
+
* discovered by the WRM plugin's loaders.
|
|
39
|
+
* @property {wrDep[]} [dependencies] - a list of other web-resources this one should depend upon.
|
|
40
|
+
* @property {string[]} [contexts] - a list of contexts the web-resource should be loaded in to.
|
|
41
|
+
* @property {object[]} [conditions] - a list of conditions to apply to the web-resource to determine whether
|
|
42
|
+
* it should output its resources at runtime or not.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {Object} DataProvider
|
|
47
|
+
* @description Data provider shape used by `dataProvidersMap` option.
|
|
48
|
+
* @property {String} key - Data provider key e.g. `my-data-provider`
|
|
49
|
+
* @property {String} class - Data provider Java class e.g. `my.data.provider.JavaClass`
|
|
50
|
+
*/
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const DllModule = require('webpack/lib/DllModule');
|
|
2
|
+
const RawSource = require('webpack-sources').RawSource;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This module type allows inclusion of special dependencies in the webpack compilation process
|
|
6
|
+
* that ultimately output nothing in the compiled bundles.
|
|
7
|
+
*
|
|
8
|
+
* This is of use when including certain file types with no associated loader in the compilation process,
|
|
9
|
+
* as is the case with things like Atlassian Soy templates.
|
|
10
|
+
*/
|
|
11
|
+
class EmptyExportsModule extends DllModule {
|
|
12
|
+
constructor(dependency, type) {
|
|
13
|
+
super(null, [], dependency, type);
|
|
14
|
+
this._dependency = dependency;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
chunkCondition() {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
source() {
|
|
22
|
+
return new RawSource('module.exports = undefined;');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = EmptyExportsModule;
|