ultimate-jekyll-manager 0.0.202 → 0.0.204

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.
@@ -203,6 +203,7 @@ async function sendUserSignupMetadata(user, webManager) {
203
203
  const response = await authorizedFetch(serverApiURL, {
204
204
  method: 'POST',
205
205
  response: 'json',
206
+ tries: 3,
206
207
  body: payload,
207
208
  });
208
209
 
@@ -25,7 +25,7 @@ export async function authorizedFetch(url, options = {}) {
25
25
  }
26
26
 
27
27
  // Get the ID token - let it throw if it fails
28
- const idToken = await user.getIdToken();
28
+ const idToken = await user.getIdToken(true);
29
29
 
30
30
  // Ensure headers object exists
31
31
  if (!requestOptions.headers) {
@@ -33,7 +33,7 @@ export async function authorizedFetch(url, options = {}) {
33
33
  }
34
34
 
35
35
  // Set the Authorization header with Bearer token
36
- requestOptions.headers['Authorization'] = 'Bearer ' + idToken;
36
+ requestOptions.headers['Authorization'] = `Bearer ${idToken}`;
37
37
 
38
38
  // Make the request using wonderful-fetch
39
39
  return fetch(url, requestOptions);
package/dist/cli.js CHANGED
@@ -2,6 +2,9 @@
2
2
  const path = require('path');
3
3
  const jetpack = require('fs-jetpack');
4
4
 
5
+ // Load .env file from current working directory (project root)
6
+ require('dotenv').config({ path: path.join(process.cwd(), '.env') });
7
+
5
8
  // Command Aliases
6
9
  const DEFAULT = 'setup';
7
10
  const ALIASES = {
@@ -6,6 +6,7 @@ const { execute } = require('node-powertools');
6
6
 
7
7
  /**
8
8
  * Detects and sets GITHUB_REPOSITORY environment variable if not already set
9
+ * Uses GitHub API to verify/correct the owner in case repo was transferred
9
10
  * @param {Object} logger - Logger instance for output
10
11
  * @returns {Promise<string|null>} - Repository in format "owner/repo" or null if detection fails
11
12
  */
@@ -20,16 +21,54 @@ async function detectGitHubRepository(logger = console) {
20
21
 
21
22
  // Parse GitHub repository from remote URL
22
23
  // Supports: https://github.com/owner/repo.git, git@github.com:owner/repo.git
23
- const match = result.match(/github\.com[:/]([^/]+\/[^.\s]+)/);
24
+ const match = result.match(/github\.com[:/]([^/]+)\/([^.\s]+)/);
24
25
 
25
- if (match) {
26
- process.env.GITHUB_REPOSITORY = match[1];
27
- logger.log(`Auto-detected repository from git remote: ${process.env.GITHUB_REPOSITORY}`);
28
- return process.env.GITHUB_REPOSITORY;
29
- } else {
26
+ if (!match) {
30
27
  logger.warn(`⚠️ Could not parse GitHub repository from git remote URL: ${result}`);
31
28
  return null;
32
29
  }
30
+
31
+ let owner = match[1];
32
+ let repo = match[2];
33
+
34
+ // If GH_TOKEN is available, verify the current owner via GitHub API
35
+ // This handles cases where repos were transferred to a different owner
36
+ if (process.env.GH_TOKEN) {
37
+ try {
38
+ const { Octokit } = require('@octokit/rest');
39
+ const octokit = new Octokit({ auth: process.env.GH_TOKEN });
40
+
41
+ // GitHub API automatically redirects to the current location of transferred repos
42
+ const { data } = await octokit.repos.get({ owner, repo });
43
+
44
+ // Check if the repo was transferred (owner changed)
45
+ if (data.owner.login !== owner) {
46
+ logger.log(`🔄 Repository was transferred: ${owner}/${repo} → ${data.owner.login}/${repo}`);
47
+
48
+ // Update the local git remote to the new owner
49
+ const newOwner = data.owner.login;
50
+ const newUrl = result.includes('git@')
51
+ ? `git@github.com:${newOwner}/${repo}.git`
52
+ : `https://github.com/${newOwner}/${repo}.git`;
53
+
54
+ try {
55
+ await execute(`git remote set-url origin ${newUrl}`, { log: false });
56
+ logger.log(`✅ Updated git remote origin to: ${newUrl}`);
57
+ } catch (remoteError) {
58
+ logger.warn(`⚠️ Could not update git remote: ${remoteError.message}`);
59
+ }
60
+
61
+ owner = newOwner;
62
+ }
63
+ } catch (apiError) {
64
+ // If API call fails, fall back to git remote value
65
+ logger.warn(`⚠️ Could not verify repository owner via GitHub API: ${apiError.message}`);
66
+ }
67
+ }
68
+
69
+ process.env.GITHUB_REPOSITORY = `${owner}/${repo}`;
70
+ logger.log(`Auto-detected repository from git remote: ${process.env.GITHUB_REPOSITORY}`);
71
+ return process.env.GITHUB_REPOSITORY;
33
72
  } catch (e) {
34
73
  // Ignore errors from git command (e.g., not a git repo, no remote)
35
74
  if (logger.warn) {
@@ -101,6 +101,9 @@ class GitHubCache {
101
101
  this.logger.log(`📦 Zip file: ${zipFileName}`);
102
102
  this.logger.log(`📂 Extract directory: ${extractDir}`);
103
103
  this.logger.log(`📁 Directory contents: ${JSON.stringify(dirContents)}`);
104
+ this.logger.log(`🔍 Debug - this.owner: ${this.owner}, this.repo: ${this.repo}`);
105
+ this.logger.log(`🔍 Debug - GITHUB_REPOSITORY env: ${process.env.GITHUB_REPOSITORY}`);
106
+ this.logger.log(`🔍 Debug - Pattern being used: ^${this.owner}-${this.repo}-[a-f0-9]+$`);
104
107
 
105
108
  // GitHub zipball format: {owner}-{repo}-{sha}
106
109
  // Match this pattern to avoid picking up other cache directories (like imagemin, translation)
@@ -7,7 +7,7 @@ const path = require('path');
7
7
  const jetpack = require('fs-jetpack');
8
8
  const wp = require('webpack');
9
9
  const ReplacePlugin = require('../plugins/webpack/replace.js');
10
- const stripDevBlocksLoader = require.resolve('../loaders/webpack/strip-dev-blocks-loader.js');
10
+ const stripDevBlocksLoader = require.resolve('../loaders/webpack/strip-dev-blocks.js');
11
11
  const yaml = require('js-yaml');
12
12
  const version = require('wonderful-version');
13
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-jekyll-manager",
3
- "version": "0.0.202",
3
+ "version": "0.0.204",
4
4
  "description": "Ultimate Jekyll dependency manager",
5
5
  "main": "dist/index.js",
6
6
  "exports": {