create-pw-core 0.0.3 → 0.0.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.
package/dist/index.js CHANGED
@@ -125,44 +125,41 @@ async function main() {
125
125
  }
126
126
  catch (e) { }
127
127
  }
128
- // Look for local pw-core/examples on the user's machine
129
- let localExamplesDir = null;
130
- if (!isDevRepo) {
131
- let current = targetDir;
132
- while (true) {
133
- const candidate = path.join(current, 'pw-core', 'examples');
134
- if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) {
135
- localExamplesDir = candidate;
136
- break;
137
- }
138
- const siblingCandidate = path.join(current, '..', 'pw-core', 'examples');
139
- if (fs.existsSync(siblingCandidate) && fs.statSync(siblingCandidate).isDirectory()) {
140
- localExamplesDir = siblingCandidate;
141
- break;
142
- }
143
- const parent = path.dirname(current);
144
- if (parent === current) {
145
- break;
128
+ // Check for latest version on registry to bypass npx cache issues
129
+ const pkgJsonPath = path.join(__dirname, '../package.json');
130
+ if (fs.existsSync(pkgJsonPath) && !isDevRepo) {
131
+ try {
132
+ const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
133
+ const currentVersion = pkg.version;
134
+ const latestVersion = (0, child_process_1.execSync)('npm view create-pw-core version', {
135
+ stdio: ['ignore', 'pipe', 'ignore'],
136
+ timeout: 3000
137
+ }).toString().trim();
138
+ if (latestVersion && currentVersion !== latestVersion) {
139
+ console.log(`\n\x1b[33mNewer version of create-pw-core found (${latestVersion}). Current: ${currentVersion}\x1b[0m`);
140
+ console.log('\x1b[36mRunning create-pw-core@latest to ensure you have the latest features...\n\x1b[0m');
141
+ const args = process.argv.slice(2);
142
+ const child = (0, child_process_1.spawn)('npx', ['create-pw-core@latest', ...args], {
143
+ stdio: 'inherit',
144
+ shell: true
145
+ });
146
+ await new Promise((resolve) => {
147
+ child.on('close', (code) => {
148
+ rl.close();
149
+ process.exit(code ?? 0);
150
+ });
151
+ });
152
+ return;
146
153
  }
147
- current = parent;
148
154
  }
149
- if (!localExamplesDir) {
150
- const hardcodedPaths = [
151
- 'z:/QECore/pw-core/examples',
152
- 'Z:/QECore/pw-core/examples'
153
- ];
154
- for (const p of hardcodedPaths) {
155
- if (fs.existsSync(p) && fs.statSync(p).isDirectory()) {
156
- localExamplesDir = p;
157
- break;
158
- }
159
- }
155
+ catch (err) {
156
+ // Offline or network error: continue with the cached version
160
157
  }
161
158
  }
162
159
  let templatesDir = path.join(__dirname, 'templates');
163
160
  let templatePkgPath = path.join(templatesDir, 'package.json');
164
- if (isDevRepo || localExamplesDir) {
165
- const srcDir = isDevRepo ? path.join(devRepoPath, 'examples') : localExamplesDir;
161
+ if (isDevRepo) {
162
+ const srcDir = path.join(devRepoPath, 'examples');
166
163
  templatePkgPath = path.join(srcDir, 'package.json');
167
164
  }
168
165
  let templatePkg = {};
@@ -186,8 +183,8 @@ async function main() {
186
183
  }
187
184
  // Copy templates from create-pw-core package to target directory
188
185
  console.log('\nCopying template files...');
189
- if (isDevRepo || localExamplesDir) {
190
- const srcDir = isDevRepo ? path.join(devRepoPath, 'examples') : localExamplesDir;
186
+ if (isDevRepo) {
187
+ const srcDir = path.join(devRepoPath, 'examples');
191
188
  console.log(`\x1b[33mLocal pw-core repository found. Copying templates directly from: ${srcDir}\x1b[0m`);
192
189
  copyRecursiveSync(srcDir, targetDir);
193
190
  }
@@ -240,40 +237,15 @@ async function main() {
240
237
  }
241
238
  }
242
239
  // Check if we are testing locally or installing published package
243
- let pwCoreInstallSource = templatePkg.devDependencies?.['pw-core'] || '^1.0.0';
240
+ let pwCoreInstallSource = 'latest';
244
241
  const envInstallLocal = process.env.PW_CORE_INSTALL_LOCAL;
245
242
  if (envInstallLocal) {
246
243
  // If running in development/local test, use the absolute path to pw-core directory
247
244
  pwCoreInstallSource = `file:${envInstallLocal}`;
248
245
  }
249
- else {
246
+ else if (isDevRepo) {
250
247
  // Check if running in the development repository
251
- if (isDevRepo) {
252
- pwCoreInstallSource = `file:${devRepoPath}`;
253
- }
254
- else {
255
- if (pwCoreInstallSource.startsWith('file:')) {
256
- let resolvedRootPkgPath = '';
257
- if (localExamplesDir) {
258
- resolvedRootPkgPath = path.join(localExamplesDir, '..', 'package.json');
259
- }
260
- if (fs.existsSync(resolvedRootPkgPath)) {
261
- try {
262
- const rootPkg = JSON.parse(fs.readFileSync(resolvedRootPkgPath, 'utf8'));
263
- pwCoreInstallSource = `^${rootPkg.version}`;
264
- }
265
- catch (e) {
266
- pwCoreInstallSource = 'latest';
267
- }
268
- }
269
- else {
270
- pwCoreInstallSource = 'latest';
271
- }
272
- }
273
- else {
274
- pwCoreInstallSource = 'latest';
275
- }
276
- }
248
+ pwCoreInstallSource = `file:${devRepoPath}`;
277
249
  }
278
250
  targetPkg.devDependencies['pw-core'] = pwCoreInstallSource;
279
251
  fs.writeFileSync(packageJsonPath, JSON.stringify(targetPkg, null, 2), 'utf8');
@@ -17,7 +17,7 @@
17
17
  "@playwright/test": "^1.61.0",
18
18
  "@types/node": "^20.11.0",
19
19
  "dotenv": "^16.4.5",
20
- "pw-core": "^0.0.3",
20
+ "pw-core": "^0.0.4",
21
21
  "typescript": "^6.0.3"
22
22
  }
23
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pw-core",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Initialize a pw-core test suite in a project",
5
5
  "bin": {
6
6
  "create-pw-core": "dist/index.js"