three-blocks-login 0.1.11 → 0.1.12
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/README.md +75 -51
- package/bin/login.js +29 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npx -y three-blocks-login@latest@latest
|
|
|
16
16
|
|
|
17
17
|
The CLI supports three modes for storing authentication:
|
|
18
18
|
|
|
19
|
-
### 1. Project Mode (
|
|
19
|
+
### 1. Project Mode (Default)
|
|
20
20
|
|
|
21
21
|
Writes `.npmrc` to the current directory. Best for project-specific authentication.
|
|
22
22
|
|
|
@@ -24,15 +24,7 @@ Writes `.npmrc` to the current directory. Best for project-specific authenticati
|
|
|
24
24
|
npx -y three-blocks-login@latest --mode project --scope @three-blocks --channel stable
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
**
|
|
28
|
-
|
|
29
|
-
```json
|
|
30
|
-
{
|
|
31
|
-
"scripts": {
|
|
32
|
-
"preinstall": "npx -y three-blocks-login@latest"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
```
|
|
27
|
+
**For CI/CD:** Run this command BEFORE `pnpm install`, not as a preinstall hook. See [CI/CD Setup](#cicd-setup) for platform-specific examples.
|
|
36
28
|
|
|
37
29
|
**Note:** Flags are optional - the CLI auto-detects `--mode project` in CI environments, defaults to `--scope @three-blocks`, and `--channel stable`.
|
|
38
30
|
|
|
@@ -79,64 +71,77 @@ npx -y three-blocks-login@latest --mode user
|
|
|
79
71
|
| `THREE_BLOCKS_LOGIN_PRINT_SHELL` | Print shell exports in env mode (`1`) |
|
|
80
72
|
| `CI` | Enable non-interactive mode (`1`) |
|
|
81
73
|
|
|
82
|
-
## CI/CD
|
|
74
|
+
## CI/CD Setup
|
|
83
75
|
|
|
84
|
-
|
|
76
|
+
> ⚠️ **pnpm users:** The preinstall hook approach is unreliable with pnpm because pnpm resolves packages BEFORE running preinstall scripts. Use the **CI Install Override** approach below instead.
|
|
85
77
|
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
@three-blocks:registry=https://three-blocks-196905988268.d.codeartifact.ap-northeast-1.amazonaws.com/npm/core/
|
|
89
|
-
```
|
|
78
|
+
### Recommended: CI Install Override (All CIs)
|
|
90
79
|
|
|
91
|
-
|
|
92
|
-
```json
|
|
93
|
-
{
|
|
94
|
-
"scripts": {
|
|
95
|
-
"preinstall": "npx -y three-blocks-login@latest"
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
```
|
|
80
|
+
Run the login command BEFORE `pnpm install`, not as a preinstall hook:
|
|
99
81
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
82
|
+
#### Vercel
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
// vercel.json
|
|
86
|
+
{
|
|
87
|
+
"installCommand": "npx -y three-blocks-login@latest && pnpm install"
|
|
88
|
+
}
|
|
89
|
+
```
|
|
103
90
|
|
|
104
|
-
|
|
91
|
+
Set `THREE_BLOCKS_SECRET_KEY` in Vercel → Project Settings → Environment Variables.
|
|
105
92
|
|
|
106
|
-
|
|
107
|
-
- Preinstall script adds the **AUTH TOKEN** dynamically
|
|
108
|
-
- This solves pnpm's resolution timing issue (it needs to know the registry before running preinstall)
|
|
93
|
+
#### AWS Amplify
|
|
109
94
|
|
|
110
|
-
|
|
95
|
+
```yaml
|
|
96
|
+
# amplify.yml
|
|
97
|
+
version: 1
|
|
98
|
+
frontend:
|
|
99
|
+
phases:
|
|
100
|
+
preBuild:
|
|
101
|
+
commands:
|
|
102
|
+
- npx -y three-blocks-login@latest
|
|
103
|
+
- pnpm install
|
|
104
|
+
build:
|
|
105
|
+
commands:
|
|
106
|
+
- pnpm build
|
|
107
|
+
```
|
|
111
108
|
|
|
112
|
-
|
|
113
|
-
2. Navigate to: Settings → Environment Variables
|
|
114
|
-
3. Add `THREE_BLOCKS_SECRET_KEY` environment variable
|
|
115
|
-
4. Set the value to your license key (starts with `tb_...`)
|
|
116
|
-
5. Make sure it's available in all environments (Production, Preview, Development)
|
|
109
|
+
Set `THREE_BLOCKS_SECRET_KEY` in Amplify Console → App Settings → Environment Variables.
|
|
117
110
|
|
|
118
|
-
|
|
111
|
+
#### GitHub Actions
|
|
119
112
|
|
|
120
113
|
```yaml
|
|
121
|
-
- name:
|
|
114
|
+
- name: Auth three-blocks
|
|
122
115
|
run: npx -y three-blocks-login@latest
|
|
123
116
|
env:
|
|
124
117
|
THREE_BLOCKS_SECRET_KEY: ${{ secrets.THREE_BLOCKS_SECRET_KEY }}
|
|
118
|
+
|
|
119
|
+
- name: Install dependencies
|
|
120
|
+
run: pnpm install
|
|
125
121
|
```
|
|
126
122
|
|
|
127
|
-
|
|
123
|
+
#### Netlify
|
|
128
124
|
|
|
129
|
-
|
|
125
|
+
```toml
|
|
126
|
+
# netlify.toml
|
|
127
|
+
[build]
|
|
128
|
+
command = "npx -y three-blocks-login@latest && pnpm install && pnpm build"
|
|
129
|
+
```
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
Set `THREE_BLOCKS_SECRET_KEY` in Netlify → Site Settings → Environment Variables.
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
#### Generic CI
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
Always run login before install:
|
|
136
|
+
```bash
|
|
137
|
+
npx -y three-blocks-login@latest && pnpm install
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Alternative: Preinstall Hook (npm only)
|
|
136
141
|
|
|
137
|
-
**
|
|
142
|
+
> ⚠️ This approach only works reliably with **npm**, not pnpm. For pnpm, use CI Install Override above.
|
|
138
143
|
|
|
139
|
-
1. **Commit a base `.npmrc`**
|
|
144
|
+
1. **Commit a base `.npmrc`** (no auth token):
|
|
140
145
|
```
|
|
141
146
|
@three-blocks:registry=https://three-blocks-196905988268.d.codeartifact.ap-northeast-1.amazonaws.com/npm/core/
|
|
142
147
|
```
|
|
@@ -150,12 +155,31 @@ npx -y three-blocks-login@latest --mode user
|
|
|
150
155
|
}
|
|
151
156
|
```
|
|
152
157
|
|
|
153
|
-
3. **
|
|
158
|
+
3. **Set `THREE_BLOCKS_SECRET_KEY`** in CI environment variables.
|
|
159
|
+
|
|
160
|
+
## Troubleshooting
|
|
161
|
+
|
|
162
|
+
### 401 Unauthorized on Vercel/Amplify/CI
|
|
163
|
+
|
|
164
|
+
**Problem:** Getting `ERR_PNPM_FETCH_401` or 401 errors in CI.
|
|
165
|
+
|
|
166
|
+
**Root Cause:** pnpm resolves packages BEFORE running preinstall scripts. If you're using a preinstall hook with pnpm, it won't work reliably.
|
|
167
|
+
|
|
168
|
+
**Solution:** Use CI Install Override instead of preinstall hooks.
|
|
169
|
+
|
|
170
|
+
For Vercel, add to `vercel.json`:
|
|
171
|
+
```json
|
|
172
|
+
{
|
|
173
|
+
"installCommand": "npx -y three-blocks-login@latest && pnpm install"
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
For other CIs, see the [CI/CD Setup](#cicd-setup) section above.
|
|
154
178
|
|
|
155
|
-
**
|
|
156
|
-
-
|
|
157
|
-
-
|
|
158
|
-
-
|
|
179
|
+
**Also check:**
|
|
180
|
+
- `THREE_BLOCKS_SECRET_KEY` is set in CI environment variables
|
|
181
|
+
- `.npmrc` does NOT contain an `_authToken` line (tokens expire in 12h)
|
|
182
|
+
- Remove any preinstall hook from `package.json` if using CI override
|
|
159
183
|
|
|
160
184
|
### License Key Format
|
|
161
185
|
|
package/bin/login.js
CHANGED
|
@@ -241,6 +241,32 @@ if ( SKIP_LOGIN ) {
|
|
|
241
241
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
// Detect pnpm + preinstall timing issue
|
|
245
|
+
const isPnpmPreinstall = () => {
|
|
246
|
+
|
|
247
|
+
const lifecycle = String( process.env.npm_lifecycle_event || '' ).toLowerCase();
|
|
248
|
+
const userAgent = String( process.env.npm_config_user_agent || '' ).toLowerCase();
|
|
249
|
+
return lifecycle === 'preinstall' && userAgent.includes( 'pnpm' );
|
|
250
|
+
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const warnPnpmPreinstall = () => {
|
|
254
|
+
|
|
255
|
+
if ( ! isPnpmPreinstall() || QUIET ) return;
|
|
256
|
+
console.error( '' );
|
|
257
|
+
console.error( cyan( '⚠' ) + ' ' + bold( 'pnpm preinstall timing warning' ) );
|
|
258
|
+
console.error( dim( ' pnpm resolves packages BEFORE running preinstall hooks.' ) );
|
|
259
|
+
console.error( dim( ' If you see 401 errors, use CI install command override instead:' ) );
|
|
260
|
+
console.error( '' );
|
|
261
|
+
console.error( dim( ' Vercel: ' ) + cyan( '"installCommand": "npx -y three-blocks-login@latest && pnpm install"' ) );
|
|
262
|
+
console.error( dim( ' Amplify: ' ) + cyan( 'preBuild: npx -y three-blocks-login@latest && pnpm install' ) );
|
|
263
|
+
console.error( dim( ' Generic: ' ) + cyan( 'npx -y three-blocks-login@latest && pnpm install' ) );
|
|
264
|
+
console.error( '' );
|
|
265
|
+
console.error( dim( ' Docs: https://threejs-blocks.com/auth-guide' ) );
|
|
266
|
+
console.error( '' );
|
|
267
|
+
|
|
268
|
+
};
|
|
269
|
+
|
|
244
270
|
// Load .env from current working directory (no deps)
|
|
245
271
|
loadEnvFromDotfile( process.cwd() );
|
|
246
272
|
|
|
@@ -722,6 +748,9 @@ const log = {
|
|
|
722
748
|
|
|
723
749
|
( async () => {
|
|
724
750
|
|
|
751
|
+
// Warn about pnpm preinstall timing issue early
|
|
752
|
+
warnPnpmPreinstall();
|
|
753
|
+
|
|
725
754
|
try {
|
|
726
755
|
|
|
727
756
|
let LICENSE = args.license || process.env.THREE_BLOCKS_SECRET_KEY;
|