@plaudit/webpack-extensions 2.42.2 → 2.42.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const node_crypto_1 = __importDefault(require("node:crypto"));
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
- const json2php_1 = __importDefault(require("json2php"));
9
+ const json_to_php_but_with____injection_1 = __importDefault(require("./json-to-php-but-with-__-injection"));
10
10
  const webpack_1 = require("webpack");
11
11
  class BlockJSONManagingPlugin {
12
12
  standaloneBlocks;
@@ -419,7 +419,7 @@ class BlockJSONManagingPlugin {
419
419
  ]);
420
420
  }
421
421
  compilation.emitAsset("blockdir.config.php", new webpack_1.sources.RawSource("<?php return "
422
- + json2php_1.default.make({ indent: "\t", linebreak: "\n", shortArraySyntax: true })(sortedBlockDirConfigData, "")
422
+ + json_to_php_but_with____injection_1.default.make({ indent: "\t", linebreak: "\n", shortArraySyntax: true })(sortedBlockDirConfigData, "")
423
423
  .replaceAll(/(\n\t*)\[\s+],/gs, "$1[],")
424
424
  .replaceAll(/'rest' => \[\n\t+\[],\n\t+('[^']+')\n\t+]/gs, "'rest' => [[], $1]")
425
425
  + ";"));
@@ -0,0 +1,11 @@
1
+ type MakeProps = {
2
+ linebreak?: string;
3
+ indent?: string;
4
+ shortArraySyntax?: boolean;
5
+ stripSpaces?: boolean;
6
+ };
7
+ declare const make: (props?: MakeProps) => (obj: unknown, parentIndent?: string) => string;
8
+ declare const json2php: ReturnType<typeof make> & {
9
+ make: typeof make;
10
+ };
11
+ export default json2php;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const acceptedObjectTypes = ['[object Array]', '[object Object]'];
4
+ const make = (props = {}) => {
5
+ const linebreak = props.linebreak ?? '';
6
+ const indent = props.indent ?? '';
7
+ const stripSpaces = props.stripSpaces ?? false;
8
+ const shortArraySyntax = props.shortArraySyntax ?? false;
9
+ const arrOpen = shortArraySyntax ? '[' : 'array(';
10
+ const arrClose = shortArraySyntax ? ']' : ')';
11
+ const arrow = stripSpaces ? '=>' : ' => ';
12
+ function transformInner(obj, parentIndent, state) {
13
+ switch (typeof obj) {
14
+ case 'undefined':
15
+ return 'null';
16
+ case 'bigint':
17
+ case 'number':
18
+ case 'boolean':
19
+ return obj.toString();
20
+ case 'string':
21
+ const res = obj.replace("\\", '\\\\').replaceAll("'", "\\'");
22
+ if (!/\s*/.test(res) && !state.isKey && state.path.length === 4 && state.path[1] === 'attributes' && state.path[3] === 'default' && state.parent?.['translatable']) {
23
+ return `__('${res}')`;
24
+ }
25
+ return `'${res}'`;
26
+ case 'object':
27
+ if (obj === null)
28
+ return 'null';
29
+ const objType = Object.prototype.toString.call(obj);
30
+ if (objType === '[object Date]')
31
+ return obj.toISOString();
32
+ if (!acceptedObjectTypes.includes(objType))
33
+ return 'null';
34
+ const nestIndent = parentIndent + indent;
35
+ const items = Array.isArray(obj)
36
+ ? obj.map((item, i) => transformInner(item, nestIndent, { path: [...state.path, i], parent: obj }))
37
+ : Object.entries(obj).map(([key, value]) => {
38
+ return transformInner(key, nestIndent, { path: [...state.path, key], parent: obj, isKey: true })
39
+ + arrow + transformInner(value, nestIndent, { path: [...state.path, key], parent: obj });
40
+ });
41
+ const itemStr = items.join(`,${linebreak === '' && !stripSpaces ? ' ' : linebreak + nestIndent}`);
42
+ return `${arrOpen}${linebreak + nestIndent}${itemStr}${linebreak + parentIndent}${arrClose}`;
43
+ default:
44
+ return 'null';
45
+ }
46
+ }
47
+ return function transform(obj, parentIndent = '') {
48
+ return transformInner(obj, parentIndent, { path: [] });
49
+ };
50
+ };
51
+ const json2php = make();
52
+ json2php.make = make;
53
+ exports.default = json2php;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.42.2",
3
+ "version": "2.42.4",
4
4
  "license": "UNLICENSED",
5
5
  "scripts": {
6
6
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
@@ -21,7 +21,7 @@
21
21
  }
22
22
  },
23
23
  "devDependencies": {
24
- "@plaudit/gutenberg-api-extensions": "^2.66.0",
24
+ "@plaudit/gutenberg-api-extensions": "^2.66.1",
25
25
  "@types/browser-sync-webpack-plugin": "^2.2.5",
26
26
  "@types/node": "^22.13.13",
27
27
  "@types/postcss-functions": "^4.0.4",