@tsparticles/cli 3.4.2 → 3.4.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.
@@ -2,6 +2,35 @@ import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises";
2
2
  import { existsSync } from "node:fs";
3
3
  import klaw from "klaw";
4
4
  import path from "node:path";
5
+ /**
6
+ * @param value -
7
+ * @param version -
8
+ * @returns -
9
+ */
10
+ function resolveWorkspaceVersion(value, version) {
11
+ if (!value.startsWith("workspace:")) {
12
+ return value;
13
+ }
14
+ const spec = value.slice("workspace:".length);
15
+ if (!spec || spec === "*") {
16
+ return version;
17
+ }
18
+ if (spec === "^" || spec === "~") {
19
+ return `${spec}${version}`;
20
+ }
21
+ return spec;
22
+ }
23
+ /**
24
+ * @param deps -
25
+ * @param version -
26
+ * @returns -
27
+ */
28
+ function resolveDeps(deps, version) {
29
+ return Object.fromEntries(Object.entries(deps).map(([name, value]) => [
30
+ name,
31
+ resolveWorkspaceVersion(value, version),
32
+ ]));
33
+ }
5
34
  /**
6
35
  * @param basePath -
7
36
  * @param silent -
@@ -16,10 +45,10 @@ export async function buildDistFiles(basePath, silent) {
16
45
  const pkgInfo = JSON.parse((await readFile(path.join(basePath, "package.json"))).toString()), libPackage = path.join(basePath, "package.dist.json"), distPath = path.join(basePath, pkgInfo.publishConfig?.directory ?? "dist"), data = await readFile(libPackage), text = data.toString(), libObj = JSON.parse(text);
17
46
  libObj["version"] = pkgInfo.version;
18
47
  if (pkgInfo.dependencies) {
19
- libObj["dependencies"] = JSON.parse(JSON.stringify(pkgInfo.dependencies).replaceAll("workspace:", ""));
48
+ libObj["dependencies"] = resolveDeps(pkgInfo.dependencies, pkgInfo.version);
20
49
  }
21
50
  if (pkgInfo.peerDependencies) {
22
- libObj["peerDependencies"] = JSON.parse(JSON.stringify(pkgInfo.peerDependencies).replaceAll("workspace:", ""));
51
+ libObj["peerDependencies"] = resolveDeps(pkgInfo.peerDependencies, pkgInfo.version);
23
52
  }
24
53
  const jsonIndent = 2, newLibPackageContents = `${JSON.stringify(libObj, undefined, jsonIndent)}\n`;
25
54
  if (newLibPackageContents !== text) {
@@ -72,7 +72,7 @@
72
72
  "unpkg": "tsparticles.empty.template.min.js",
73
73
  "module": "index.js",
74
74
  "types": "index.d.ts",
75
- "dependencies": {
75
+ "peerDependencies": {
76
76
  "@tsparticles/engine": "^3.9.1"
77
77
  }
78
78
  }
@@ -86,6 +86,7 @@
86
86
  "@swc/core": "^1.15.21",
87
87
  "@tsparticles/cli": "latest",
88
88
  "@tsparticles/depcruise-config": "^3.4.4",
89
+ "@tsparticles/engine": "^3.9.1",
89
90
  "@tsparticles/eslint-config": "^3.4.4",
90
91
  "@tsparticles/prettier-config": "^3.4.4",
91
92
  "@tsparticles/tsconfig": "^3.4.4",
@@ -105,7 +106,7 @@
105
106
  "webpack-bundle-analyzer": "^5.3.0",
106
107
  "webpack-cli": "^7.0.2"
107
108
  },
108
- "dependencies": {
109
+ "peerDependencies": {
109
110
  "@tsparticles/engine": "^3.9.1"
110
111
  }
111
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/cli",
3
- "version": "3.4.2",
3
+ "version": "3.4.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {
@@ -3,6 +3,43 @@ import { existsSync } from "node:fs";
3
3
  import klaw from "klaw";
4
4
  import path from "node:path";
5
5
 
6
+ /**
7
+ * @param value -
8
+ * @param version -
9
+ * @returns -
10
+ */
11
+ function resolveWorkspaceVersion(value: string, version: string): string {
12
+ if (!value.startsWith("workspace:")) {
13
+ return value;
14
+ }
15
+
16
+ const spec = value.slice("workspace:".length);
17
+
18
+ if (!spec || spec === "*") {
19
+ return version;
20
+ }
21
+
22
+ if (spec === "^" || spec === "~") {
23
+ return `${spec}${version}`;
24
+ }
25
+
26
+ return spec;
27
+ }
28
+
29
+ /**
30
+ * @param deps -
31
+ * @param version -
32
+ * @returns -
33
+ */
34
+ function resolveDeps(deps: Record<string, string>, version: string): Record<string, string> {
35
+ return Object.fromEntries(
36
+ Object.entries(deps).map(([name, value]) => [
37
+ name,
38
+ resolveWorkspaceVersion(value, version),
39
+ ]),
40
+ );
41
+ }
42
+
6
43
  /**
7
44
  * @param basePath -
8
45
  * @param silent -
@@ -31,11 +68,11 @@ export async function buildDistFiles(basePath: string, silent: boolean): Promise
31
68
  libObj["version"] = pkgInfo.version;
32
69
 
33
70
  if (pkgInfo.dependencies) {
34
- libObj["dependencies"] = JSON.parse(JSON.stringify(pkgInfo.dependencies).replaceAll("workspace:", ""));
71
+ libObj["dependencies"] = resolveDeps(pkgInfo.dependencies, pkgInfo.version);
35
72
  }
36
73
 
37
74
  if (pkgInfo.peerDependencies) {
38
- libObj["peerDependencies"] = JSON.parse(JSON.stringify(pkgInfo.peerDependencies).replaceAll("workspace:", ""));
75
+ libObj["peerDependencies"] = resolveDeps(pkgInfo.peerDependencies, pkgInfo.version);
39
76
  }
40
77
 
41
78
  const jsonIndent = 2,