@elementor/externalize-wordpress-assets-webpack-plugin 0.3.1 → 0.3.3

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/CHANGELOG.md CHANGED
@@ -3,24 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [0.3.1](https://github.com/elementor/elementor-packages/compare/@elementor/externalize-wordpress-assets-webpack-plugin@0.3.0...@elementor/externalize-wordpress-assets-webpack-plugin@0.3.1) (2023-10-19)
6
+ ## [0.3.3](https://github.com/elementor/elementor-packages/compare/@elementor/externalize-wordpress-assets-webpack-plugin@0.3.2...@elementor/externalize-wordpress-assets-webpack-plugin@0.3.3) (2024-08-05)
7
7
 
8
- **Note:** Version bump only for package @elementor/externalize-wordpress-assets-webpack-plugin
8
+ ### Bug Fixes
9
9
 
10
+ - publish only necessary files to npm ([#226](https://github.com/elementor/elementor-packages/issues/226)) ([d808e2f](https://github.com/elementor/elementor-packages/commit/d808e2f60eb7ca2d7b8560d0b79c0e62c2f969a8))
10
11
 
12
+ ## [0.3.2](https://github.com/elementor/elementor-packages/compare/@elementor/externalize-wordpress-assets-webpack-plugin@0.3.1...@elementor/externalize-wordpress-assets-webpack-plugin@0.3.2) (2024-07-16)
11
13
 
14
+ **Note:** Version bump only for package @elementor/externalize-wordpress-assets-webpack-plugin
12
15
 
16
+ ## [0.3.1](https://github.com/elementor/elementor-packages/compare/@elementor/externalize-wordpress-assets-webpack-plugin@0.3.0...@elementor/externalize-wordpress-assets-webpack-plugin@0.3.1) (2023-10-19)
13
17
 
14
- # [0.3.0](https://github.com/elementor/elementor-packages/compare/@elementor/externalize-wordpress-assets-webpack-plugin@0.2.1...@elementor/externalize-wordpress-assets-webpack-plugin@0.3.0) (2023-07-11)
18
+ **Note:** Version bump only for package @elementor/externalize-wordpress-assets-webpack-plugin
15
19
 
20
+ # [0.3.0](https://github.com/elementor/elementor-packages/compare/@elementor/externalize-wordpress-assets-webpack-plugin@0.2.1...@elementor/externalize-wordpress-assets-webpack-plugin@0.3.0) (2023-07-11)
16
21
 
17
22
  ### Features
18
23
 
19
- * **webpack-plugins:** simplify logic ([#78](https://github.com/elementor/elementor-packages/issues/78)) ([e4cadc0](https://github.com/elementor/elementor-packages/commit/e4cadc06be61450437274610e65b9d92eb245844))
20
-
21
-
22
-
23
-
24
+ - **webpack-plugins:** simplify logic ([#78](https://github.com/elementor/elementor-packages/issues/78)) ([e4cadc0](https://github.com/elementor/elementor-packages/commit/e4cadc06be61450437274610e65b9d92eb245844))
24
25
 
25
26
  ## 0.2.1 (2023-07-02)
26
27
 
package/dist/index.js CHANGED
@@ -52,10 +52,7 @@ function replaceGlobal(global, matches) {
52
52
  return result;
53
53
  }
54
54
  function kebabToCamelCase(kebabCase) {
55
- return kebabCase.replace(
56
- /-(\w)/g,
57
- (_, w) => w.toUpperCase()
58
- );
55
+ return kebabCase.replace(/-(\w)/g, (_, w) => w.toUpperCase());
59
56
  }
60
57
 
61
58
  // src/plugin.ts
@@ -94,16 +91,19 @@ var ExternalizeWordPressAssetsWebpackPlugin = class {
94
91
  if (!transformEntryNameToGlobal) {
95
92
  return;
96
93
  }
97
- compiler.options.entry = Object.entries(entry).reduce((carry, [name, entryItem]) => ({
98
- ...carry,
99
- [name]: {
100
- ...entryItem,
101
- library: {
102
- name: transformEntryNameToGlobal(kebabToCamelCase(name)),
103
- type: this.options.type
94
+ compiler.options.entry = Object.entries(entry).reduce(
95
+ (carry, [name, entryItem]) => ({
96
+ ...carry,
97
+ [name]: {
98
+ ...entryItem,
99
+ library: {
100
+ name: transformEntryNameToGlobal(kebabToCamelCase(name)),
101
+ type: this.options.type
102
+ }
104
103
  }
105
- }
106
- }), {});
104
+ }),
105
+ {}
106
+ );
107
107
  }
108
108
  };
109
109
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/plugin.ts","../src/utils.ts"],"sourcesContent":["export { default as ExternalizeWordPressAssetsWebpackPlugin } from './plugin';\n","import { ExternalsPlugin, Compiler } from 'webpack';\nimport { kebabToCamelCase, transformRequestToGlobal } from './utils';\nimport { RequestToGlobalMap, Global } from './types';\n\ntype Options = {\n\ttype: string,\n\tglobal?: ( entryName: string ) => Global,\n\tmap: RequestToGlobalMap\n};\n\nexport default class ExternalizeWordPressAssetsWebpackPlugin {\n\toptions: Options;\n\n\texternalPlugin: ExternalsPlugin;\n\n\tconstructor( options: Pick<Options, 'map' | 'global'> ) {\n\t\tthis.options = {\n\t\t\tmap: options.map,\n\t\t\tglobal: options.global,\n\t\t\ttype: 'window',\n\t\t};\n\n\t\tthis.externalPlugin = new ExternalsPlugin(\n\t\t\tthis.options.type,\n\t\t\t( { request }, callback ) => this.externalsPluginCallback( request, callback )\n\t\t);\n\t}\n\n\tapply( compiler: Compiler ) {\n\t\tthis.externalPlugin.apply( compiler );\n\n\t\tcompiler.hooks.environment.tap( this.constructor.name, () => {\n\t\t\tthis.exposeEntry( compiler );\n\t\t} );\n\t}\n\n\texternalsPluginCallback(\n\t\trequest: string | undefined,\n\t\tcallback: ( err?: undefined, result?: Global ) => void\n\t) {\n\t\tconst global = transformRequestToGlobal( request, this.options.map );\n\n\t\tif ( ! global ) {\n\t\t\tcallback();\n\n\t\t\treturn;\n\t\t}\n\n\t\tcallback( undefined, global );\n\t}\n\n\texposeEntry( compiler: Compiler ) {\n\t\tcompiler.options.output.enabledLibraryTypes?.push( this.options.type );\n\n\t\tconst transformEntryNameToGlobal = this.options.global;\n\t\tconst entry = compiler.options.entry;\n\n\t\tif ( ! transformEntryNameToGlobal ) {\n\t\t\treturn;\n\t\t}\n\n\t\tcompiler.options.entry = Object.entries( entry )\n\t\t\t.reduce( ( carry, [ name, entryItem ] ) => ( {\n\t\t\t\t...carry,\n\t\t\t\t[ name ]: {\n\t\t\t\t\t...entryItem,\n\t\t\t\t\tlibrary: {\n\t\t\t\t\t\tname: transformEntryNameToGlobal( kebabToCamelCase( name ) ),\n\t\t\t\t\t\ttype: this.options.type,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} ), {} );\n\t}\n}\n","import { RequestToGlobalMap } from './types';\n\nexport function transformRequestToGlobal( request: string | undefined, map: RequestToGlobalMap ) {\n\tif ( ! request ) {\n\t\treturn null;\n\t}\n\n\tfor ( const item of map ) {\n\t\tlet { request: requestRegex, global } = item;\n\n\t\tif ( ! ( requestRegex instanceof RegExp ) ) {\n\t\t\trequestRegex = new RegExp( `^${ requestRegex }$` );\n\t\t}\n\n\t\tconst matches = request.match( requestRegex );\n\n\t\tif ( matches ) {\n\t\t\treturn replaceGlobal( global, matches );\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function replaceGlobal( global: string | string[], matches: RegExpMatchArray ) {\n\tlet result = typeof global === 'string' ? [ global ] : [ ...global ];\n\n\tmatches.forEach( ( value, index ) => {\n\t\t// Replace regex backreferences with capture groups.\n\t\t// The user can set ['something', '$1', 'a', '$2'] in the global, and the backreferences will\n\t\t// be replaced by the matched groups in the regex.\n\t\tresult = result.map( ( item ) => item.replace( `$${ index }`, kebabToCamelCase( value ) ) );\n\t} );\n\n\treturn result;\n}\n\nexport function kebabToCamelCase( kebabCase: string ) {\n\treturn kebabCase.replace(\n\t\t/-(\\w)/g,\n\t\t( _, w: string ) => w.toUpperCase()\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAA0C;;;ACEnC,SAAS,yBAA0B,SAA6B,KAA0B;AAChG,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AAEA,aAAY,QAAQ,KAAM;AACzB,QAAI,EAAE,SAAS,cAAc,OAAO,IAAI;AAExC,QAAK,EAAI,wBAAwB,SAAW;AAC3C,qBAAe,IAAI,OAAQ,IAAK,YAAa,GAAI;AAAA,IAClD;AAEA,UAAM,UAAU,QAAQ,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AAErE,UAAM,6BAA6B,KAAK,QAAQ;AAChD,UAAM,QAAQ,SAAS,QAAQ;AAE/B,QAAK,CAAE,4BAA6B;AACnC;AAAA,IACD;AAEA,aAAS,QAAQ,QAAQ,OAAO,QAAS,KAAM,EAC7C,OAAQ,CAAE,OAAO,CAAE,MAAM,SAAU,OAAS;AAAA,MAC5C,GAAG;AAAA,MACH,CAAE,IAAK,GAAG;AAAA,QACT,GAAG;AAAA,QACH,SAAS;AAAA,UACR,MAAM,2BAA4B,iBAAkB,IAAK,CAAE;AAAA,UAC3D,MAAM,KAAK,QAAQ;AAAA,QACpB;AAAA,MACD;AAAA,IACD,IAAK,CAAC,CAAE;AAAA,EACV;AACD;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/plugin.ts","../src/utils.ts"],"sourcesContent":["export { default as ExternalizeWordPressAssetsWebpackPlugin } from './plugin';\n","import { ExternalsPlugin, Compiler } from 'webpack';\nimport { kebabToCamelCase, transformRequestToGlobal } from './utils';\nimport { RequestToGlobalMap, Global } from './types';\n\ntype Options = {\n\ttype: string;\n\tglobal?: ( entryName: string ) => Global;\n\tmap: RequestToGlobalMap;\n};\n\nexport default class ExternalizeWordPressAssetsWebpackPlugin {\n\toptions: Options;\n\n\texternalPlugin: ExternalsPlugin;\n\n\tconstructor( options: Pick< Options, 'map' | 'global' > ) {\n\t\tthis.options = {\n\t\t\tmap: options.map,\n\t\t\tglobal: options.global,\n\t\t\ttype: 'window',\n\t\t};\n\n\t\tthis.externalPlugin = new ExternalsPlugin( this.options.type, ( { request }, callback ) =>\n\t\t\tthis.externalsPluginCallback( request, callback )\n\t\t);\n\t}\n\n\tapply( compiler: Compiler ) {\n\t\tthis.externalPlugin.apply( compiler );\n\n\t\tcompiler.hooks.environment.tap( this.constructor.name, () => {\n\t\t\tthis.exposeEntry( compiler );\n\t\t} );\n\t}\n\n\texternalsPluginCallback( request: string | undefined, callback: ( err?: undefined, result?: Global ) => void ) {\n\t\tconst global = transformRequestToGlobal( request, this.options.map );\n\n\t\tif ( ! global ) {\n\t\t\tcallback();\n\n\t\t\treturn;\n\t\t}\n\n\t\tcallback( undefined, global );\n\t}\n\n\texposeEntry( compiler: Compiler ) {\n\t\tcompiler.options.output.enabledLibraryTypes?.push( this.options.type );\n\n\t\tconst transformEntryNameToGlobal = this.options.global;\n\t\tconst entry = compiler.options.entry;\n\n\t\tif ( ! transformEntryNameToGlobal ) {\n\t\t\treturn;\n\t\t}\n\n\t\tcompiler.options.entry = Object.entries( entry ).reduce(\n\t\t\t( carry, [ name, entryItem ] ) => ( {\n\t\t\t\t...carry,\n\t\t\t\t[ name ]: {\n\t\t\t\t\t...entryItem,\n\t\t\t\t\tlibrary: {\n\t\t\t\t\t\tname: transformEntryNameToGlobal( kebabToCamelCase( name ) ),\n\t\t\t\t\t\ttype: this.options.type,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} ),\n\t\t\t{}\n\t\t);\n\t}\n}\n","import { RequestToGlobalMap } from './types';\n\nexport function transformRequestToGlobal( request: string | undefined, map: RequestToGlobalMap ) {\n\tif ( ! request ) {\n\t\treturn null;\n\t}\n\n\tfor ( const item of map ) {\n\t\tlet { request: requestRegex, global } = item;\n\n\t\tif ( ! ( requestRegex instanceof RegExp ) ) {\n\t\t\trequestRegex = new RegExp( `^${ requestRegex }$` );\n\t\t}\n\n\t\tconst matches = request.match( requestRegex );\n\n\t\tif ( matches ) {\n\t\t\treturn replaceGlobal( global, matches );\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function replaceGlobal( global: string | string[], matches: RegExpMatchArray ) {\n\tlet result = typeof global === 'string' ? [ global ] : [ ...global ];\n\n\tmatches.forEach( ( value, index ) => {\n\t\t// Replace regex backreferences with capture groups.\n\t\t// The user can set ['something', '$1', 'a', '$2'] in the global, and the backreferences will\n\t\t// be replaced by the matched groups in the regex.\n\t\tresult = result.map( ( item ) => item.replace( `$${ index }`, kebabToCamelCase( value ) ) );\n\t} );\n\n\treturn result;\n}\n\nexport function k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AAA,EAEA,MAAO,UAAqB;AAC3B,SAAK,eAAe,MAAO,QAAS;AAEpC,aAAS,MAAM,YAAY,IAAK,KAAK,YAAY,MAAM,MAAM;AAC5D,WAAK,YAAa,QAAS;AAAA,IAC5B,CAAE;AAAA,EACH;AAAA,EAEA,wBAAyB,SAA6B,UAAyD;AAC9G,UAAM,SAAS,yBAA0B,SAAS,KAAK,QAAQ,GAAI;AAEnE,QAAK,CAAE,QAAS;AACf,eAAS;AAET;AAAA,IACD;AAEA,aAAU,QAAW,MAAO;AAAA,EAC7B;AAAA,EAEA,YAAa,UAAqB;AACjC,aAAS,QAAQ,OAAO,qBAAqB,KAAM,KAAK,QAAQ,IAAK;AAErE,UAAM,6BAA6B,KAAK,QAAQ;AAChD,UAAM,QAAQ,SAAS,QAAQ;AAE/B,QAAK,CAAE,4BAA6B;AACnC;AAAA,IACD;AAEA,aAAS,QAAQ,QAAQ,OAAO,QAAS,KAAM,EAAE;AAAA,MAChD,CAAE,OAAO,CAAE,MAAM,SAAU,OAAS;AAAA,QACnC,GAAG;AAAA,QACH,CAAE,IAAK,GAAG;AAAA,UACT,GAAG;AAAA,UACH,SAAS;AAAA,YACR,MAAM,2BAA4B,iBAAkB,IAAK,CAAE;AAAA,YAC3D,MAAM,KAAK,QAAQ;AAAA,UACpB;AAAA,QACD;AAAA,MACD;AAAA,MACA,CAAC;AAAA,IACF;AAAA,EACD;AACD;","names":[]}
package/dist/index.mjs CHANGED
@@ -26,10 +26,7 @@ function replaceGlobal(global, matches) {
26
26
  return result;
27
27
  }
28
28
  function kebabToCamelCase(kebabCase) {
29
- return kebabCase.replace(
30
- /-(\w)/g,
31
- (_, w) => w.toUpperCase()
32
- );
29
+ return kebabCase.replace(/-(\w)/g, (_, w) => w.toUpperCase());
33
30
  }
34
31
 
35
32
  // src/plugin.ts
@@ -68,16 +65,19 @@ var ExternalizeWordPressAssetsWebpackPlugin = class {
68
65
  if (!transformEntryNameToGlobal) {
69
66
  return;
70
67
  }
71
- compiler.options.entry = Object.entries(entry).reduce((carry, [name, entryItem]) => ({
72
- ...carry,
73
- [name]: {
74
- ...entryItem,
75
- library: {
76
- name: transformEntryNameToGlobal(kebabToCamelCase(name)),
77
- type: this.options.type
68
+ compiler.options.entry = Object.entries(entry).reduce(
69
+ (carry, [name, entryItem]) => ({
70
+ ...carry,
71
+ [name]: {
72
+ ...entryItem,
73
+ library: {
74
+ name: transformEntryNameToGlobal(kebabToCamelCase(name)),
75
+ type: this.options.type
76
+ }
78
77
  }
79
- }
80
- }), {});
78
+ }),
79
+ {}
80
+ );
81
81
  }
82
82
  };
83
83
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts","../src/utils.ts"],"sourcesContent":["import { ExternalsPlugin, Compiler } from 'webpack';\nimport { kebabToCamelCase, transformRequestToGlobal } from './utils';\nimport { RequestToGlobalMap, Global } from './types';\n\ntype Options = {\n\ttype: string,\n\tglobal?: ( entryName: string ) => Global,\n\tmap: RequestToGlobalMap\n};\n\nexport default class ExternalizeWordPressAssetsWebpackPlugin {\n\toptions: Options;\n\n\texternalPlugin: ExternalsPlugin;\n\n\tconstructor( options: Pick<Options, 'map' | 'global'> ) {\n\t\tthis.options = {\n\t\t\tmap: options.map,\n\t\t\tglobal: options.global,\n\t\t\ttype: 'window',\n\t\t};\n\n\t\tthis.externalPlugin = new ExternalsPlugin(\n\t\t\tthis.options.type,\n\t\t\t( { request }, callback ) => this.externalsPluginCallback( request, callback )\n\t\t);\n\t}\n\n\tapply( compiler: Compiler ) {\n\t\tthis.externalPlugin.apply( compiler );\n\n\t\tcompiler.hooks.environment.tap( this.constructor.name, () => {\n\t\t\tthis.exposeEntry( compiler );\n\t\t} );\n\t}\n\n\texternalsPluginCallback(\n\t\trequest: string | undefined,\n\t\tcallback: ( err?: undefined, result?: Global ) => void\n\t) {\n\t\tconst global = transformRequestToGlobal( request, this.options.map );\n\n\t\tif ( ! global ) {\n\t\t\tcallback();\n\n\t\t\treturn;\n\t\t}\n\n\t\tcallback( undefined, global );\n\t}\n\n\texposeEntry( compiler: Compiler ) {\n\t\tcompiler.options.output.enabledLibraryTypes?.push( this.options.type );\n\n\t\tconst transformEntryNameToGlobal = this.options.global;\n\t\tconst entry = compiler.options.entry;\n\n\t\tif ( ! transformEntryNameToGlobal ) {\n\t\t\treturn;\n\t\t}\n\n\t\tcompiler.options.entry = Object.entries( entry )\n\t\t\t.reduce( ( carry, [ name, entryItem ] ) => ( {\n\t\t\t\t...carry,\n\t\t\t\t[ name ]: {\n\t\t\t\t\t...entryItem,\n\t\t\t\t\tlibrary: {\n\t\t\t\t\t\tname: transformEntryNameToGlobal( kebabToCamelCase( name ) ),\n\t\t\t\t\t\ttype: this.options.type,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} ), {} );\n\t}\n}\n","import { RequestToGlobalMap } from './types';\n\nexport function transformRequestToGlobal( request: string | undefined, map: RequestToGlobalMap ) {\n\tif ( ! request ) {\n\t\treturn null;\n\t}\n\n\tfor ( const item of map ) {\n\t\tlet { request: requestRegex, global } = item;\n\n\t\tif ( ! ( requestRegex instanceof RegExp ) ) {\n\t\t\trequestRegex = new RegExp( `^${ requestRegex }$` );\n\t\t}\n\n\t\tconst matches = request.match( requestRegex );\n\n\t\tif ( matches ) {\n\t\t\treturn replaceGlobal( global, matches );\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function replaceGlobal( global: string | string[], matches: RegExpMatchArray ) {\n\tlet result = typeof global === 'string' ? [ global ] : [ ...global ];\n\n\tmatches.forEach( ( value, index ) => {\n\t\t// Replace regex backreferences with capture groups.\n\t\t// The user can set ['something', '$1', 'a', '$2'] in the global, and the backreferences will\n\t\t// be replaced by the matched groups in the regex.\n\t\tresult = result.map( ( item ) => item.replace( `$${ index }`, kebabToCamelCase( value ) ) );\n\t} );\n\n\treturn result;\n}\n\nexport function kebabToCamelCase( kebabCase: string ) {\n\treturn kebabCase.replace(\n\t\t/-(\\w)/g,\n\t\t( _, w: string ) => w.toUpperCase()\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M;AAC5D,WAAK,YAAa,QAAS;AAAA,IAC5B,CAAE;AAAA,EACH;AAAA,EAEA,wBACC,SACA,UACC;AACD,UAAM,SAAS,yBAA0B,SAAS,KAAK,QAAQ,GAAI;AAEnE,QAAK,CAAE,QAAS;AACf,eAAS;AAET;AAAA,IACD;AAEA,aAAU,QAAW,MAAO;AAAA,EAC7B;AAAA,EAEA,YAAa,UAAqB;AACjC,aAAS,QAAQ,OAAO,qBAAqB,KAAM,KAAK,QAAQ,IAAK;AAErE,UAAM,6BAA6B,KAAK,QAAQ;AAChD,UAAM,QAAQ,SAAS,QAAQ;AAE/B,QAAK,CAAE,4BAA6B;AACnC;AAAA,IACD;AAEA,aAAS,QAAQ,QAAQ,OAAO,QAAS,KAAM,EAC7C,OAAQ,CAAE,OAAO,CAAE,MAAM,SAAU,OAAS;AAAA,MAC5C,GAAG;AAAA,MACH,CAAE,IAAK,GAAG;AAAA,QACT,GAAG;AAAA,QACH,SAAS;AAAA,UACR,MAAM,2BAA4B,iBAAkB,IAAK,CAAE;AAAA,UAC3D,MAAM,KAAK,QAAQ;AAAA,QACpB;AAAA,MACD;AAAA,IACD,IAAK,CAAC,CAAE;AAAA,EACV;AACD;","names":[]}
1
+ {"version":3,"sources":["../src/plugin.ts","../src/utils.ts"],"sourcesContent":["import { ExternalsPlugin, Compiler } from 'webpack';\nimport { kebabToCamelCase, transformRequestToGlobal } from './utils';\nimport { RequestToGlobalMap, Global } from './types';\n\ntype Options = {\n\ttype: string;\n\tglobal?: ( entryName: string ) => Global;\n\tmap: RequestToGlobalMap;\n};\n\nexport default class ExternalizeWordPressAssetsWebpackPlugin {\n\toptions: Options;\n\n\texternalPlugin: ExternalsPlugin;\n\n\tconstructor( options: Pick< Options, 'map' | 'global' > ) {\n\t\tthis.options = {\n\t\t\tmap: options.map,\n\t\t\tglobal: options.global,\n\t\t\ttype: 'window',\n\t\t};\n\n\t\tthis.externalPlugin = new ExternalsPlugin( this.options.type, ( { request }, callback ) =>\n\t\t\tthis.externalsPluginCallback( request, callback )\n\t\t);\n\t}\n\n\tapply( compiler: Compiler ) {\n\t\tthis.externalPlugin.apply( compiler );\n\n\t\tcompiler.hooks.environment.tap( this.constructor.name, () => {\n\t\t\tthis.exposeEntry( compiler );\n\t\t} );\n\t}\n\n\texternalsPluginCallback( request: string | undefined, callback: ( err?: undefined, result?: Global ) => void ) {\n\t\tconst global = transformRequestToGlobal( request, this.options.map );\n\n\t\tif ( ! global ) {\n\t\t\tcallback();\n\n\t\t\treturn;\n\t\t}\n\n\t\tcallback( undefined, global );\n\t}\n\n\texposeEntry( compiler: Compiler ) {\n\t\tcompiler.options.output.enabledLibraryTypes?.push( this.options.type );\n\n\t\tconst transformEntryNameToGlobal = this.options.global;\n\t\tconst entry = compiler.options.entry;\n\n\t\tif ( ! transformEntryNameToGlobal ) {\n\t\t\treturn;\n\t\t}\n\n\t\tcompiler.options.entry = Object.entries( entry ).reduce(\n\t\t\t( carry, [ name, entryItem ] ) => ( {\n\t\t\t\t...carry,\n\t\t\t\t[ name ]: {\n\t\t\t\t\t...entryItem,\n\t\t\t\t\tlibrary: {\n\t\t\t\t\t\tname: transformEntryNameToGlobal( kebabToCamelCase( name ) ),\n\t\t\t\t\t\ttype: this.options.type,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} ),\n\t\t\t{}\n\t\t);\n\t}\n}\n","import { RequestToGlobalMap } from './types';\n\nexport function transformRequestToGlobal( request: string | undefined, map: RequestToGlobalMap ) {\n\tif ( ! request ) {\n\t\treturn null;\n\t}\n\n\tfor ( const item of map ) {\n\t\tlet { request: requestRegex, global } = item;\n\n\t\tif ( ! ( requestRegex instanceof RegExp ) ) {\n\t\t\trequestRegex = new RegExp( `^${ requestRegex }$` );\n\t\t}\n\n\t\tconst matches = request.match( requestRegex );\n\n\t\tif ( matches ) {\n\t\t\treturn replaceGlobal( global, matches );\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function replaceGlobal( global: string | string[], matches: RegExpMatchArray ) {\n\tlet result = typeof global === 'string' ? [ global ] : [ ...global ];\n\n\tmatches.forEach( ( value, index ) => {\n\t\t// Replace regex backreferences with capture groups.\n\t\t// The user can set ['something', '$1', 'a', '$2'] in the global, and the backreferences will\n\t\t// be replaced by the matched groups in the regex.\n\t\tresult = result.map( ( item ) => item.replace( `$${ index }`, kebabToCamelCase( value ) ) );\n\t} );\n\n\treturn result;\n}\n\nexport function kebabToCamelCase( kebabCase: string ) {\n\treturn kebabCase.replace( /-(\\w)/g, ( _, w: string ) => w.toUpperCase() );\n}\n"],"mappings":";AAAA,SAAS,uBAAiC;;;ACEnC,SAAS,yBAA0B,SAA6B,KAA0B;AAChG,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AAEA,aAAY,QAAQ,KAAM;AACzB,QAAI,EAAE,SAAS,cAAc,OAAO,IAAI;AAExC,QAAK,EAAI,wBAAwB,SAAW;AAC3C,qBAAe,IAAI,OAAQ,IAAK,YAAa,GAAI;AAAA,IAClD;AAEA,UAAM,UAAU,QAAQ,MAAO,YAAa;AAE5C,QAAK,SAAU;AACd,aAAO,cAAe,QAAQ,OAAQ;AAAA,IACvC;AAAA,EACD;AAEA,SAAO;AACR;AAEO,SAAS,cAAe,QAA2B,SAA4B;AACrF,MAAI,SAAS,OAAO,WAAW,WAAW,CAAE,MAAO,IAAI,CAAE,GAAG,MAAO;AAEnE,UAAQ,QAAS,CAAE,OAAO,UAAW;AAIpC,aAAS,OAAO,IAAK,CAAE,SAAU,KAAK,QAAS,IAAK,KAAM,IAAI,iBAAkB,KAAM,CAAE,CAAE;AAAA,EAC3F,CAAE;AAEF,SAAO;AACR;AAEO,SAAS,iBAAkB,WAAoB;AACrD,SAAO,UAAU,QAAS,UAAU,CAAE,GAAG,MAAe,EAAE,YAAY,CAAE;AACzE;;;AD7BA,IAAqB,0CAArB,MAA6D;AAAA,EAC5D;AAAA,EAEA;AAAA,EAEA,YAAa,SAA6C;AACzD,SAAK,UAAU;AAAA,MACd,KAAK,QAAQ;AAAA,MACb,QAAQ,QAAQ;AAAA,MAChB,MAAM;AAAA,IACP;AAEA,SAAK,iBAAiB,IAAI;AAAA,MAAiB,KAAK,QAAQ;AAAA,MAAM,CAAE,EAAE,QAAQ,GAAG,aAC5E,KAAK,wBAAyB,SAAS,QAAS;AAAA,IACjD;AAAA,EACD;AAAA,EAEA,MAAO,UAAqB;AAC3B,SAAK,eAAe,MAAO,QAAS;AAEpC,aAAS,MAAM,YAAY,IAAK,KAAK,YAAY,MAAM,MAAM;AAC5D,WAAK,YAAa,QAAS;AAAA,IAC5B,CAAE;AAAA,EACH;AAAA,EAEA,wBAAyB,SAA6B,UAAyD;AAC9G,UAAM,SAAS,yBAA0B,SAAS,KAAK,QAAQ,GAAI;AAEnE,QAAK,CAAE,QAAS;AACf,eAAS;AAET;AAAA,IACD;AAEA,aAAU,QAAW,MAAO;AAAA,EAC7B;AAAA,EAEA,YAAa,UAAqB;AACjC,aAAS,QAAQ,OAAO,qBAAqB,KAAM,KAAK,QAAQ,IAAK;AAErE,UAAM,6BAA6B,KAAK,QAAQ;AAChD,UAAM,QAAQ,SAAS,QAAQ;AAE/B,QAAK,CAAE,4BAA6B;AACnC;AAAA,IACD;AAEA,aAAS,QAAQ,QAAQ,OAAO,QAAS,KAAM,EAAE;AAAA,MAChD,CAAE,OAAO,CAAE,MAAM,SAAU,OAAS;AAAA,QACnC,GAAG;AAAA,QACH,CAAE,IAAK,GAAG;AAAA,UACT,GAAG;AAAA,UACH,SAAS;AAAA,YACR,MAAM,2BAA4B,iBAAkB,IAAK,CAAE;AAAA,YAC3D,MAAM,KAAK,QAAQ;AAAA,UACpB;AAAA,QACD;AAAA,MACD;AAAA,MACA,CAAC;AAAA,IACF;AAAA,EACD;AACD;","names":[]}
package/package.json CHANGED
@@ -1,38 +1,45 @@
1
1
  {
2
- "name": "@elementor/externalize-wordpress-assets-webpack-plugin",
3
- "version": "0.3.1",
4
- "private": false,
5
- "author": "Elementor Team",
6
- "homepage": "https://elementor.com/",
7
- "license": "GPL-3.0-or-later",
8
- "main": "dist/index.js",
9
- "module": "dist/index.mjs",
10
- "types": "dist/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.js",
15
- "types": "./dist/index.d.ts"
16
- },
17
- "./package.json": "./package.json"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/elementor/elementor-packages.git",
22
- "directory": "packages/tools/externalize-wordpress-assets-webpack-plugin"
23
- },
24
- "bugs": {
25
- "url": "https://github.com/elementor/elementor-packages/issues"
26
- },
27
- "publishConfig": {
28
- "access": "public"
29
- },
30
- "scripts": {
31
- "build": "tsup --config=../../tsup.build.ts",
32
- "dev": "tsup --config=../../tsup.dev.ts --format=esm,cjs"
33
- },
34
- "peerDependencies": {
35
- "webpack": "5.x"
36
- },
37
- "gitHead": "c692bd825e856d1ac04f671b425a57c1b8466512"
2
+ "name": "@elementor/externalize-wordpress-assets-webpack-plugin",
3
+ "version": "0.3.3",
4
+ "private": false,
5
+ "author": "Elementor Team",
6
+ "homepage": "https://elementor.com/",
7
+ "license": "GPL-3.0-or-later",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.mjs",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/elementor/elementor-packages.git",
22
+ "directory": "packages/tools/externalize-wordpress-assets-webpack-plugin"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/elementor/elementor-packages/issues"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "files": [
31
+ "README.md",
32
+ "CHANGELOG.md",
33
+ "/dist",
34
+ "/src",
35
+ "!**/__tests__"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsup --config=../../tsup.build.ts",
39
+ "dev": "tsup --config=../../tsup.dev.ts --format=esm,cjs"
40
+ },
41
+ "peerDependencies": {
42
+ "webpack": "5.x"
43
+ },
44
+ "gitHead": "f4ca33da0842a29d83736d0a173633085edddaee"
38
45
  }
package/src/plugin.ts CHANGED
@@ -3,9 +3,9 @@ import { kebabToCamelCase, transformRequestToGlobal } from './utils';
3
3
  import { RequestToGlobalMap, Global } from './types';
4
4
 
5
5
  type Options = {
6
- type: string,
7
- global?: ( entryName: string ) => Global,
8
- map: RequestToGlobalMap
6
+ type: string;
7
+ global?: ( entryName: string ) => Global;
8
+ map: RequestToGlobalMap;
9
9
  };
10
10
 
11
11
  export default class ExternalizeWordPressAssetsWebpackPlugin {
@@ -13,16 +13,15 @@ export default class ExternalizeWordPressAssetsWebpackPlugin {
13
13
 
14
14
  externalPlugin: ExternalsPlugin;
15
15
 
16
- constructor( options: Pick<Options, 'map' | 'global'> ) {
16
+ constructor( options: Pick< Options, 'map' | 'global' > ) {
17
17
  this.options = {
18
18
  map: options.map,
19
19
  global: options.global,
20
20
  type: 'window',
21
21
  };
22
22
 
23
- this.externalPlugin = new ExternalsPlugin(
24
- this.options.type,
25
- ( { request }, callback ) => this.externalsPluginCallback( request, callback )
23
+ this.externalPlugin = new ExternalsPlugin( this.options.type, ( { request }, callback ) =>
24
+ this.externalsPluginCallback( request, callback )
26
25
  );
27
26
  }
28
27
 
@@ -34,10 +33,7 @@ export default class ExternalizeWordPressAssetsWebpackPlugin {
34
33
  } );
35
34
  }
36
35
 
37
- externalsPluginCallback(
38
- request: string | undefined,
39
- callback: ( err?: undefined, result?: Global ) => void
40
- ) {
36
+ externalsPluginCallback( request: string | undefined, callback: ( err?: undefined, result?: Global ) => void ) {
41
37
  const global = transformRequestToGlobal( request, this.options.map );
42
38
 
43
39
  if ( ! global ) {
@@ -59,8 +55,8 @@ export default class ExternalizeWordPressAssetsWebpackPlugin {
59
55
  return;
60
56
  }
61
57
 
62
- compiler.options.entry = Object.entries( entry )
63
- .reduce( ( carry, [ name, entryItem ] ) => ( {
58
+ compiler.options.entry = Object.entries( entry ).reduce(
59
+ ( carry, [ name, entryItem ] ) => ( {
64
60
  ...carry,
65
61
  [ name ]: {
66
62
  ...entryItem,
@@ -69,6 +65,8 @@ export default class ExternalizeWordPressAssetsWebpackPlugin {
69
65
  type: this.options.type,
70
66
  },
71
67
  },
72
- } ), {} );
68
+ } ),
69
+ {}
70
+ );
73
71
  }
74
72
  }
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type Global = string | string[];
2
2
 
3
- export type RequestToGlobalMap = Array<{
4
- request: string | RegExp,
5
- global: Global
6
- }>
3
+ export type RequestToGlobalMap = Array< {
4
+ request: string | RegExp;
5
+ global: Global;
6
+ } >;
package/src/utils.ts CHANGED
@@ -36,8 +36,5 @@ export function replaceGlobal( global: string | string[], matches: RegExpMatchAr
36
36
  }
37
37
 
38
38
  export function kebabToCamelCase( kebabCase: string ) {
39
- return kebabCase.replace(
40
- /-(\w)/g,
41
- ( _, w: string ) => w.toUpperCase()
42
- );
39
+ return kebabCase.replace( /-(\w)/g, ( _, w: string ) => w.toUpperCase() );
43
40
  }
@@ -1,116 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`@elementor/externalize-wordpress-assets-webpack-plugin should externalize Elementor & WordPress assets 1`] = `
4
- ""use strict";
5
- (self["webpackChunk"] = self["webpackChunk"] || []).push([["my-app-test"],{
6
-
7
- /***/ "./.":
8
- /*!***********!*\\
9
- !*** ./. ***!
10
- \\***********/
11
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
12
-
13
- __webpack_require__.r(__webpack_exports__);
14
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
15
- /* harmony export */ test: () => (/* binding */ test)
16
- /* harmony export */ });
17
- /* harmony import */ var _elementor_editor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/editor */ "@elementor/editor");
18
- /* harmony import */ var _elementor_editor__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_editor__WEBPACK_IMPORTED_MODULE_0__);
19
- /* harmony import */ var _elementor_editor_panels__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @elementor/editor-panels */ "@elementor/editor-panels");
20
- /* harmony import */ var _elementor_editor_panels__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_elementor_editor_panels__WEBPACK_IMPORTED_MODULE_1__);
21
- /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
22
- /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_2__);
23
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! react */ "react");
24
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_3__);
25
- /* harmony import */ var react_dom__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! react-dom */ "react-dom");
26
- /* harmony import */ var react_dom__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(react_dom__WEBPACK_IMPORTED_MODULE_4__);
27
- /* harmony import */ var _other_package_name__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @other/package-name */ "@other/package-name");
28
- /* harmony import */ var _other_package_name__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_other_package_name__WEBPACK_IMPORTED_MODULE_5__);
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
- _elementor_editor__WEBPACK_IMPORTED_MODULE_0___default()();
38
- _elementor_editor_panels__WEBPACK_IMPORTED_MODULE_1___default()();
39
- _wordpress_element__WEBPACK_IMPORTED_MODULE_2___default()();
40
- react__WEBPACK_IMPORTED_MODULE_3___default()();
41
- react_dom__WEBPACK_IMPORTED_MODULE_4___default()();
42
- _other_package_name__WEBPACK_IMPORTED_MODULE_5___default()();
43
-
44
- const test = 'This is test for exporting something';
45
-
46
-
47
- /***/ }),
48
-
49
- /***/ "react":
50
- /*!**************************!*\\
51
- !*** external ["React"] ***!
52
- \\**************************/
53
- /***/ ((module) => {
54
-
55
- module.exports = window["React"];
56
-
57
- /***/ }),
58
-
59
- /***/ "react-dom":
60
- /*!*****************************!*\\
61
- !*** external ["ReactDOM"] ***!
62
- \\*****************************/
63
- /***/ ((module) => {
64
-
65
- module.exports = window["ReactDOM"];
66
-
67
- /***/ }),
68
-
69
- /***/ "@elementor/editor":
70
- /*!***********************************************!*\\
71
- !*** external ["elementorPackages","editor"] ***!
72
- \\***********************************************/
73
- /***/ ((module) => {
74
-
75
- module.exports = window["elementorPackages"]["editor"];
76
-
77
- /***/ }),
78
-
79
- /***/ "@elementor/editor-panels":
80
- /*!*****************************************************!*\\
81
- !*** external ["elementorPackages","editorPanels"] ***!
82
- \\*****************************************************/
83
- /***/ ((module) => {
84
-
85
- module.exports = window["elementorPackages"]["editorPanels"];
86
-
87
- /***/ }),
88
-
89
- /***/ "@other/package-name":
90
- /*!*************************************!*\\
91
- !*** external ["otherPackageName"] ***!
92
- \\*************************************/
93
- /***/ ((module) => {
94
-
95
- module.exports = window["otherPackageName"];
96
-
97
- /***/ }),
98
-
99
- /***/ "@wordpress/element":
100
- /*!*********************************!*\\
101
- !*** external ["wp","element"] ***!
102
- \\*********************************/
103
- /***/ ((module) => {
104
-
105
- module.exports = window["wp"]["element"];
106
-
107
- /***/ })
108
-
109
- },
110
- /******/ __webpack_require__ => { // webpackRuntimeModules
111
- /******/ var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
112
- /******/ var __webpack_exports__ = (__webpack_exec__("./."));
113
- /******/ (window.elementorPackages = window.elementorPackages || {}).myAppTest = __webpack_exports__;
114
- /******/ }
115
- ]);"
116
- `;
@@ -1,83 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- import * as fs from 'fs';
6
- import * as path from 'path';
7
- import { webpack } from 'webpack';
8
- import { ExternalizeWordPressAssetsWebpackPlugin } from '../index';
9
- import { vol } from 'memfs';
10
-
11
- jest.mock( 'fs', () => jest.requireActual( 'memfs' ) );
12
-
13
- describe( '@elementor/externalize-wordpress-assets-webpack-plugin', () => {
14
- beforeEach( () => {
15
- const fileContent = `
16
- import editor from '@elementor/editor';
17
- import editorPanels from '@elementor/editor-panels';
18
- import wp from '@wordpress/element';
19
- import React from 'react';
20
- import ReactDOM from 'react-dom';
21
- import other from '@other/package-name';
22
-
23
- editor();
24
- editorPanels();
25
- wp();
26
- React();
27
- ReactDOM();
28
- other();
29
-
30
- export const test = 'This is test for exporting something';
31
- `;
32
-
33
- fs.writeFileSync( path.resolve( '/app.js' ), fileContent );
34
- } );
35
-
36
- afterEach( () => {
37
- vol.reset();
38
- } );
39
-
40
- it( 'should externalize Elementor & WordPress assets', ( done ) => {
41
- // Arrange.
42
- const compiler = webpack( {
43
- mode: 'development',
44
- devtool: false,
45
- entry: { 'my-app-test': path.resolve( '/app.js' ) },
46
- context: path.resolve( '/app.js' ),
47
- optimization: { runtimeChunk: 'single' },
48
- output: {
49
- filename: '[name].js',
50
- path: path.resolve( '/dist' ),
51
- },
52
- plugins: [
53
- new ExternalizeWordPressAssetsWebpackPlugin( {
54
- global: ( entryName ) => [ 'elementorPackages', entryName ],
55
- map: [
56
- { request: 'react', global: 'React' },
57
- { request: 'react-dom', global: 'ReactDOM' },
58
- { request: /^@elementor\/(.+)$/, global: [ 'elementorPackages', '$1' ] },
59
- { request: /^@wordpress\/(.+)$/, global: [ 'wp', '$1' ] },
60
- { request: '@other/package-name', global: 'otherPackageName' },
61
- ],
62
- } ),
63
- ],
64
- } );
65
-
66
- // Expect.
67
- expect.assertions( 4 );
68
-
69
- // Act.
70
- compiler.run( ( err, stats ) => {
71
- // Assert.
72
- expect( err ).toBe( null );
73
- expect( stats?.hasErrors() ).toBe( false );
74
- expect( stats?.hasWarnings() ).toBe( false );
75
-
76
- const fileContent = fs.readFileSync( path.resolve( `/dist/my-app-test.js` ), { encoding: 'utf8' } );
77
-
78
- expect( fileContent ).toMatchSnapshot();
79
-
80
- done();
81
- } );
82
- } );
83
- } );