vite-plugin-php 1.0.69 → 1.0.71

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/README.md CHANGED
@@ -22,6 +22,8 @@ Check out the [starter repo](https://github.com/nititech/php-vite-starter) for a
22
22
 
23
23
  | Version | Feature |
24
24
  | ------- | ----------------------------------------------------------------------------------------------------------- |
25
+ | 1.0.71 | Fixed assets prepending for namespaced PHP-files |
26
+ | 1.0.70 | Added include path override for relative PHP imports in dev mode |
25
27
  | 1.0.69 | Using new token format to escape PHP in HTML |
26
28
  | 1.0.68 | Improved transpiled code evaluation (removed native `eval()`) |
27
29
  | 1.0.67 | Removed whitespaces from PHP responses in dev mode |
@@ -29,8 +31,6 @@ Check out the [starter repo](https://github.com/nititech/php-vite-starter) for a
29
31
  | 1.0.65 | Fixed request body forwarding for all request methods |
30
32
  | 1.0.62 | HTML transforms are now only applied to HTML contents during dev |
31
33
  | 1.0.60 | Fixed inline module transpiling -> PHP code is being properly inserted into transpiled inline module chunks |
32
- | 1.0.55 | Fixed pure PHP file processing |
33
- | 1.0.50 | Using native Rollup pipeline to generate bundle -> proper error messages during build |
34
34
  | ... | ... |
35
35
 
36
36
  ## Write some PHP code in your `index.php`
package/dist/index.cjs CHANGED
@@ -6977,6 +6977,19 @@ function consoleHijack(entries) {
6977
6977
  });
6978
6978
  }
6979
6979
 
6980
+ const namespacePattern = new RegExp(
6981
+ /(.+?)(<\?(?:php|)\s+namespace\s\S+?(?:\s*;|\s*{).+)(<\/.+?>|<.+?\/>)(.+|$)/,
6982
+ "si"
6983
+ );
6984
+ function processOutput(input) {
6985
+ let out = input;
6986
+ out = out.replace(
6987
+ namespacePattern,
6988
+ (match, assets, contents, lastTag, trailingContent) => contents + lastTag + "\r\n" + assets.trim() + trailingContent
6989
+ );
6990
+ return out;
6991
+ }
6992
+
6980
6993
  const internalParam = "__314159265359__";
6981
6994
  function usePHP(cfg = {}) {
6982
6995
  const {
@@ -7246,6 +7259,7 @@ function usePHP(cfg = {}) {
7246
7259
  escapedCode: item.source.toString(),
7247
7260
  phpCodes: meta.phpCodes
7248
7261
  });
7262
+ item.source = processOutput(item.source);
7249
7263
  }
7250
7264
  } else if (item.type === "chunk" && item.facadeModuleId) {
7251
7265
  const meta = this.getModuleInfo(
@@ -7256,6 +7270,7 @@ function usePHP(cfg = {}) {
7256
7270
  escapedCode: item.code,
7257
7271
  phpCodes: meta.phpCodes
7258
7272
  });
7273
+ item.code = processOutput(item.code);
7259
7274
  }
7260
7275
  }
7261
7276
  });
package/dist/index.mjs CHANGED
@@ -6964,6 +6964,19 @@ function consoleHijack(entries) {
6964
6964
  });
6965
6965
  }
6966
6966
 
6967
+ const namespacePattern = new RegExp(
6968
+ /(.+?)(<\?(?:php|)\s+namespace\s\S+?(?:\s*;|\s*{).+)(<\/.+?>|<.+?\/>)(.+|$)/,
6969
+ "si"
6970
+ );
6971
+ function processOutput(input) {
6972
+ let out = input;
6973
+ out = out.replace(
6974
+ namespacePattern,
6975
+ (match, assets, contents, lastTag, trailingContent) => contents + lastTag + "\r\n" + assets.trim() + trailingContent
6976
+ );
6977
+ return out;
6978
+ }
6979
+
6967
6980
  const internalParam = "__314159265359__";
6968
6981
  function usePHP(cfg = {}) {
6969
6982
  const {
@@ -7233,6 +7246,7 @@ function usePHP(cfg = {}) {
7233
7246
  escapedCode: item.source.toString(),
7234
7247
  phpCodes: meta.phpCodes
7235
7248
  });
7249
+ item.source = processOutput(item.source);
7236
7250
  }
7237
7251
  } else if (item.type === "chunk" && item.facadeModuleId) {
7238
7252
  const meta = this.getModuleInfo(
@@ -7243,6 +7257,7 @@ function usePHP(cfg = {}) {
7243
7257
  escapedCode: item.code,
7244
7258
  phpCodes: meta.phpCodes
7245
7259
  });
7260
+ item.code = processOutput(item.code);
7246
7261
  }
7247
7262
  }
7248
7263
  });
package/dist/router.php CHANGED
@@ -13,6 +13,15 @@ $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
13
13
  $_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'];
14
14
  $_SERVER['QUERY_STRING'] = http_build_query($_GET);
15
15
 
16
+ ini_set(
17
+ 'include_path',
18
+ implode(PATH_SEPARATOR, [
19
+ dirname($_SERVER['SCRIPT_FILENAME']),
20
+ $_SERVER['DOCUMENT_ROOT'],
21
+ ini_get('include_path'),
22
+ ]),
23
+ );
24
+
16
25
  $source = file_get_contents($sourceFile);
17
26
 
18
27
  $tokensFile = "$sourceFile.json";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-php",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
4
4
  "author": "Nikita 'donnikitos' Nitichevski <me@donnikitos.com> (https://donnikitos.com/)",
5
5
  "repository": {
6
6
  "type": "git",