@testspectra/cli 1.0.6 → 1.0.7
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/dist/commands/init.js +36 -2
- package/package.json +1 -1
- package/src/commands/init.ts +38 -2
- package/testspectra-cli-1.0.7.tgz +0 -0
package/dist/commands/init.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
3
4
|
import { ConfigLoader } from "../config/loader.js";
|
|
4
5
|
import { TypeGenerator } from "../types/generator.js";
|
|
5
6
|
export async function initCommand(options) {
|
|
@@ -92,6 +93,37 @@ export default defineConfig({
|
|
|
92
93
|
console.log(`\x1b[32m[TestSpectra]\x1b[0m Initialized spectra.config.ts with defineConfig`);
|
|
93
94
|
// 3. Create or update package.json with npm scripts & devDependencies
|
|
94
95
|
const packageJsonPath = path.join(cwd, "package.json");
|
|
96
|
+
// Dynamically resolve CLI version
|
|
97
|
+
let cliVersion = "^1.0.6";
|
|
98
|
+
try {
|
|
99
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
100
|
+
const __dirname = path.dirname(__filename);
|
|
101
|
+
const cliPackageJsonPath = path.resolve(__dirname, "../../package.json");
|
|
102
|
+
if (fs.existsSync(cliPackageJsonPath)) {
|
|
103
|
+
const cliPkg = JSON.parse(fs.readFileSync(cliPackageJsonPath, "utf-8"));
|
|
104
|
+
if (cliPkg.version) {
|
|
105
|
+
cliVersion = `^${cliPkg.version}`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch { }
|
|
110
|
+
// Check if cwd is inside the testspectra monorepo with a pnpm-workspace.yaml
|
|
111
|
+
let isInternalWorkspace = false;
|
|
112
|
+
let cur = cwd;
|
|
113
|
+
while (cur !== path.dirname(cur)) {
|
|
114
|
+
if (fs.existsSync(path.join(cur, "pnpm-workspace.yaml"))) {
|
|
115
|
+
try {
|
|
116
|
+
const wsContent = fs.readFileSync(path.join(cur, "pnpm-workspace.yaml"), "utf-8");
|
|
117
|
+
if (wsContent.includes("cli")) {
|
|
118
|
+
isInternalWorkspace = true;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch { }
|
|
123
|
+
}
|
|
124
|
+
cur = path.dirname(cur);
|
|
125
|
+
}
|
|
126
|
+
const cliDepVersion = isInternalWorkspace ? "workspace:*" : cliVersion;
|
|
95
127
|
let pkg = {
|
|
96
128
|
name: path.basename(cwd),
|
|
97
129
|
version: "1.0.0",
|
|
@@ -102,7 +134,7 @@ export default defineConfig({
|
|
|
102
134
|
"type-check": "tsc -b",
|
|
103
135
|
},
|
|
104
136
|
devDependencies: {
|
|
105
|
-
"@testspectra/cli":
|
|
137
|
+
"@testspectra/cli": cliDepVersion,
|
|
106
138
|
"@types/node": "^20.14.0",
|
|
107
139
|
"@wdio/globals": "^9.2.8",
|
|
108
140
|
"@wdio/mocha-framework": "^9.2.8",
|
|
@@ -122,7 +154,9 @@ export default defineConfig({
|
|
|
122
154
|
},
|
|
123
155
|
devDependencies: {
|
|
124
156
|
...(existing.devDependencies || {}),
|
|
125
|
-
"@testspectra/cli": existing.devDependencies?.["@testspectra/cli"]
|
|
157
|
+
"@testspectra/cli": existing.devDependencies?.["@testspectra/cli"]?.startsWith("workspace:") && !isInternalWorkspace
|
|
158
|
+
? cliVersion
|
|
159
|
+
: existing.devDependencies?.["@testspectra/cli"] || cliDepVersion,
|
|
126
160
|
"@types/node": existing.devDependencies?.["@types/node"] || "^20.14.0",
|
|
127
161
|
"@wdio/globals": existing.devDependencies?.["@wdio/globals"] || "^9.2.8",
|
|
128
162
|
"@wdio/mocha-framework": existing.devDependencies?.["@wdio/mocha-framework"] || "^9.2.8",
|
package/package.json
CHANGED
package/src/commands/init.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
3
4
|
import { ConfigLoader } from "../config/loader.js";
|
|
4
5
|
import { TypeGenerator } from "../types/generator.js";
|
|
5
6
|
|
|
@@ -97,6 +98,39 @@ export default defineConfig({
|
|
|
97
98
|
|
|
98
99
|
// 3. Create or update package.json with npm scripts & devDependencies
|
|
99
100
|
const packageJsonPath = path.join(cwd, "package.json");
|
|
101
|
+
|
|
102
|
+
// Dynamically resolve CLI version
|
|
103
|
+
let cliVersion = "^1.0.6";
|
|
104
|
+
try {
|
|
105
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
106
|
+
const __dirname = path.dirname(__filename);
|
|
107
|
+
const cliPackageJsonPath = path.resolve(__dirname, "../../package.json");
|
|
108
|
+
if (fs.existsSync(cliPackageJsonPath)) {
|
|
109
|
+
const cliPkg = JSON.parse(fs.readFileSync(cliPackageJsonPath, "utf-8"));
|
|
110
|
+
if (cliPkg.version) {
|
|
111
|
+
cliVersion = `^${cliPkg.version}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} catch {}
|
|
115
|
+
|
|
116
|
+
// Check if cwd is inside the testspectra monorepo with a pnpm-workspace.yaml
|
|
117
|
+
let isInternalWorkspace = false;
|
|
118
|
+
let cur = cwd;
|
|
119
|
+
while (cur !== path.dirname(cur)) {
|
|
120
|
+
if (fs.existsSync(path.join(cur, "pnpm-workspace.yaml"))) {
|
|
121
|
+
try {
|
|
122
|
+
const wsContent = fs.readFileSync(path.join(cur, "pnpm-workspace.yaml"), "utf-8");
|
|
123
|
+
if (wsContent.includes("cli")) {
|
|
124
|
+
isInternalWorkspace = true;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
} catch {}
|
|
128
|
+
}
|
|
129
|
+
cur = path.dirname(cur);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const cliDepVersion = isInternalWorkspace ? "workspace:*" : cliVersion;
|
|
133
|
+
|
|
100
134
|
let pkg: any = {
|
|
101
135
|
name: path.basename(cwd),
|
|
102
136
|
version: "1.0.0",
|
|
@@ -107,7 +141,7 @@ export default defineConfig({
|
|
|
107
141
|
"type-check": "tsc -b",
|
|
108
142
|
},
|
|
109
143
|
devDependencies: {
|
|
110
|
-
"@testspectra/cli":
|
|
144
|
+
"@testspectra/cli": cliDepVersion,
|
|
111
145
|
"@types/node": "^20.14.0",
|
|
112
146
|
"@wdio/globals": "^9.2.8",
|
|
113
147
|
"@wdio/mocha-framework": "^9.2.8",
|
|
@@ -127,7 +161,9 @@ export default defineConfig({
|
|
|
127
161
|
},
|
|
128
162
|
devDependencies: {
|
|
129
163
|
...(existing.devDependencies || {}),
|
|
130
|
-
"@testspectra/cli": existing.devDependencies?.["@testspectra/cli"]
|
|
164
|
+
"@testspectra/cli": existing.devDependencies?.["@testspectra/cli"]?.startsWith("workspace:") && !isInternalWorkspace
|
|
165
|
+
? cliVersion
|
|
166
|
+
: existing.devDependencies?.["@testspectra/cli"] || cliDepVersion,
|
|
131
167
|
"@types/node": existing.devDependencies?.["@types/node"] || "^20.14.0",
|
|
132
168
|
"@wdio/globals": existing.devDependencies?.["@wdio/globals"] || "^9.2.8",
|
|
133
169
|
"@wdio/mocha-framework": existing.devDependencies?.["@wdio/mocha-framework"] || "^9.2.8",
|
|
Binary file
|