@soleil-se/build-app 2.4.0 → 2.4.1

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
@@ -4,6 +4,10 @@ title: Changelog
4
4
 
5
5
  Baseras på [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) och använder [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.4.1] - 2025-09-26
8
+
9
+ - Byt ut `.replaceAll` till motsvarande `.split().join()` eller `.replace()` för regex på serversidan då det inte stöds i Rhino.
10
+
7
11
  ## [2.4.0] - 2025-09-26
8
12
 
9
13
  - Lägg till stöd för TypeScript, läs mer i [Readme](https://docs.soleil.se/build/app/#typescript).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soleil-se/build-app",
3
3
  "description": "Script for building WebApps, RESTApps and Widgets with Svelte in Sitevision.",
4
- "version": "2.4.0",
4
+ "version": "2.4.1",
5
5
  "bin": {
6
6
  "build-app": "./bin/index.js",
7
7
  "sv-app-build": "./bin/index.js"
@@ -52,13 +52,14 @@
52
52
  "rollup-plugin-string": "3.0.0",
53
53
  "rollup-plugin-svelte": "7.2.3",
54
54
  "slash": "5.1.0",
55
+ "magic-string": "^0.30.19",
55
56
  "svelte-preprocess": "6.0.3",
56
57
  "tslib": "^2.8.1",
57
58
  "@soleil-se/build-config": "^1.3.1",
58
59
  "@soleil-se/build-utils": "^1.8.3"
59
60
  },
60
61
  "devDependencies": {
61
- "svelte": "^5.38.10",
62
+ "svelte": "^5.39.6",
62
63
  "typescript": "^5.9.2"
63
64
  },
64
65
  "publishConfig": {
@@ -0,0 +1,42 @@
1
+ import MagicString from 'magic-string';
2
+
3
+ export default function replaceReplaceAll() {
4
+ return {
5
+ name: 'replace-replaceall',
6
+ transform(code) {
7
+ if (code.includes('.replaceAll(')) {
8
+ const magicString = new MagicString(code);
9
+
10
+ // Replace .replaceAll(string, replacement) with .split(string).join(replacement)
11
+ // Updated to handle complex expressions like String(value), obj.prop, func(), etc.
12
+ const stringRegex = /((?:\w+(?:\.\w+)*|\w+\([^)]*\)|[a-zA-Z_$][\w$]*(?:\[[^\]]*\])*))\.replaceAll\((['"`])(.*?)\2,\s*(.*?)\)/g;
13
+ let match;
14
+
15
+ // eslint-disable-next-line no-cond-assign
16
+ while ((match = stringRegex.exec(code)) !== null) {
17
+ const [fullMatch, expression, quote, searchValue, replaceValue] = match;
18
+ const replacement = `${expression}.split(${quote}${searchValue}${quote}).join(${replaceValue})`;
19
+ magicString.overwrite(match.index, match.index + fullMatch.length, replacement);
20
+ }
21
+
22
+ // Replace .replaceAll(regex, replacement) with .replace(regex, replacement)
23
+ // Simple replacement - just change the method name
24
+ const regexPattern = /\.replaceAll\((\/.+?\/[gimuy]*),\s*(.*?)\)/g;
25
+ let regexMatch;
26
+
27
+ // eslint-disable-next-line no-cond-assign
28
+ while ((regexMatch = regexPattern.exec(code)) !== null) {
29
+ const [fullMatch, regexPart, replaceValue] = regexMatch;
30
+ const replacement = `.replace(${regexPart}, ${replaceValue})`;
31
+ magicString.overwrite(regexMatch.index, regexMatch.index + fullMatch.length, replacement);
32
+ }
33
+
34
+ return {
35
+ code: magicString.toString(),
36
+ map: magicString.generateMap({ hires: true }),
37
+ };
38
+ }
39
+ return null;
40
+ },
41
+ };
42
+ }
package/rollup/server.js CHANGED
@@ -16,6 +16,7 @@ import getStringPlugin from './api/getStringPlugin.js';
16
16
  import getTypescriptPlugin from './api/getTypescriptPlugin.js';
17
17
 
18
18
  import sitevision from './plugins/sitevision.js';
19
+ import replaceReplaceAll from './plugins/replaceReplaceAll.js';
19
20
 
20
21
  export default function rollupServer({
21
22
  debug,
@@ -44,6 +45,7 @@ export default function rollupServer({
44
45
  getSveltePlugin({ input: inputs[0], extractCss, ssr: true }),
45
46
  getPostcssPlugin({ extractCss, debug }),
46
47
  getBabelServerPlugin(),
48
+ replaceReplaceAll(),
47
49
  getTerserPlugin({ debug }),
48
50
  ];
49
51