create-three-blocks-starter 0.0.8 → 0.0.9
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/bin/index.js +104 -27
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -20,13 +20,17 @@ const LOGIN_CLI = 'three-blocks-login'; // public login CLI
|
|
|
20
20
|
const LOGIN_SPEC = `${LOGIN_CLI}@latest`; // force-fresh npx install
|
|
21
21
|
const SCOPE = '@three-blocks';
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const RAW_BLOCKED_NPM_ENV_KEYS = [
|
|
24
24
|
'npm_config__three_blocks_registry',
|
|
25
25
|
'npm_config_verify_deps_before_run',
|
|
26
26
|
'npm_config_global_bin_dir',
|
|
27
27
|
'npm_config__jsr_registry',
|
|
28
28
|
'npm_config_node_linker',
|
|
29
|
-
]
|
|
29
|
+
];
|
|
30
|
+
const BLOCKED_NPM_ENV_KEYS = new Set( RAW_BLOCKED_NPM_ENV_KEYS.map( ( key ) => key.replace( /-/g, '_' ).toLowerCase() ) );
|
|
31
|
+
const LOGIN_HELPER_RELATIVE_PATH = path.join( 'scripts', 'three-blocks-login.cjs' );
|
|
32
|
+
const LOGIN_HELPER_POSIX_PATH = LOGIN_HELPER_RELATIVE_PATH.split( path.sep ).join( '/' );
|
|
33
|
+
const LOGIN_HELPER_COMMAND = `node ./${LOGIN_HELPER_POSIX_PATH}`;
|
|
30
34
|
|
|
31
35
|
let DEBUG = /^1|true|yes$/i.test( String( process.env.THREE_BLOCKS_DEBUG || '' ).trim() );
|
|
32
36
|
|
|
@@ -184,6 +188,67 @@ const stripAuthTokens = ( npmrcPath, hostPatterns = [] ) => {
|
|
|
184
188
|
|
|
185
189
|
};
|
|
186
190
|
|
|
191
|
+
const buildLoginHelperContent = () => `#!/usr/bin/env node
|
|
192
|
+
'use strict';
|
|
193
|
+
|
|
194
|
+
const { spawnSync } = require('node:child_process');
|
|
195
|
+
|
|
196
|
+
const RAW_BLOCKED_KEYS = ${JSON.stringify( RAW_BLOCKED_NPM_ENV_KEYS, null, 2 )};
|
|
197
|
+
const BLOCKED_KEYS = new Set(
|
|
198
|
+
RAW_BLOCKED_KEYS.map( ( key ) => key.replace( /-/g, '_' ).toLowerCase() )
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const normalize = ( key ) => key.replace( /-/g, '_' ).toLowerCase();
|
|
202
|
+
|
|
203
|
+
const scrubEnv = ( source ) => {
|
|
204
|
+
|
|
205
|
+
const next = { ...source };
|
|
206
|
+
for ( const key of Object.keys( next ) ) {
|
|
207
|
+
|
|
208
|
+
if ( BLOCKED_KEYS.has( normalize( key ) ) ) {
|
|
209
|
+
|
|
210
|
+
delete next[ key ];
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return next;
|
|
217
|
+
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const shouldSkip = /^1|true|yes$/i.test( String( process.env.THREE_BLOCKS_LOGIN_SKIP || '' ) );
|
|
221
|
+
if ( shouldSkip ) {
|
|
222
|
+
|
|
223
|
+
process.exit( 0 );
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const env = scrubEnv( process.env );
|
|
228
|
+
const cmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
229
|
+
const args = [ '-y', 'three-blocks-login@latest', ...process.argv.slice( 2 ) ];
|
|
230
|
+
const result = spawnSync( cmd, args, { stdio: 'inherit', env } );
|
|
231
|
+
|
|
232
|
+
if ( result.error ) {
|
|
233
|
+
|
|
234
|
+
console.error( result.error.message || result.error );
|
|
235
|
+
process.exit( 1 );
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
process.exit( result.status ?? 0 );
|
|
240
|
+
`;
|
|
241
|
+
|
|
242
|
+
const ensureLoginHelperScript = async ( targetDir ) => {
|
|
243
|
+
|
|
244
|
+
const helperPath = path.join( targetDir, LOGIN_HELPER_RELATIVE_PATH );
|
|
245
|
+
const helperDir = path.dirname( helperPath );
|
|
246
|
+
await fsp.mkdir( helperDir, { recursive: true } );
|
|
247
|
+
await fsp.writeFile( helperPath, buildLoginHelperContent(), { mode: 0o755 } );
|
|
248
|
+
return helperPath;
|
|
249
|
+
|
|
250
|
+
};
|
|
251
|
+
|
|
187
252
|
const die = ( m ) => {
|
|
188
253
|
|
|
189
254
|
throw new CliError( m );
|
|
@@ -766,40 +831,40 @@ async function main() {
|
|
|
766
831
|
|
|
767
832
|
}
|
|
768
833
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
const txt = fs.readFileSync( tmpNpmrc, 'utf8' );
|
|
776
|
-
const lines = txt.split( /\r?\n/ );
|
|
777
|
-
for ( const rawLine of lines ) {
|
|
834
|
+
// Extract registry URL from temp .npmrc so we can pass it explicitly to npm create
|
|
835
|
+
let registryUrl = '';
|
|
836
|
+
const tempAuthLines = [];
|
|
837
|
+
const tempAuthHosts = new Set();
|
|
838
|
+
try {
|
|
778
839
|
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
840
|
+
const txt = fs.readFileSync( tmpNpmrc, 'utf8' );
|
|
841
|
+
const lines = txt.split( /\r?\n/ );
|
|
842
|
+
for ( const rawLine of lines ) {
|
|
782
843
|
|
|
783
|
-
|
|
784
|
-
|
|
844
|
+
const line = rawLine.replace( /\r/g, '' );
|
|
845
|
+
if ( ! line ) continue;
|
|
846
|
+
if ( ! registryUrl ) {
|
|
785
847
|
|
|
786
|
-
|
|
848
|
+
const m = line.match( /^@[^:]+:registry=(.+)$/ );
|
|
849
|
+
if ( m && m[ 1 ] ) registryUrl = m[ 1 ].trim();
|
|
787
850
|
|
|
788
|
-
|
|
789
|
-
if ( authMatch && authMatch[ 1 ] ) {
|
|
851
|
+
}
|
|
790
852
|
|
|
791
|
-
|
|
792
|
-
|
|
853
|
+
const authMatch = line.match( /^\/\/([^:]+):_authToken=.+$/ );
|
|
854
|
+
if ( authMatch && authMatch[ 1 ] ) {
|
|
793
855
|
|
|
794
|
-
|
|
856
|
+
tempAuthLines.push( line );
|
|
857
|
+
tempAuthHosts.add( authMatch[ 1 ] );
|
|
795
858
|
|
|
796
859
|
}
|
|
797
860
|
|
|
798
|
-
}
|
|
861
|
+
}
|
|
799
862
|
|
|
800
|
-
|
|
863
|
+
} catch ( readErr ) {
|
|
801
864
|
|
|
802
|
-
}
|
|
865
|
+
logDebug( `Could not read temp .npmrc: ${readErr?.message || readErr}` );
|
|
866
|
+
|
|
867
|
+
}
|
|
803
868
|
|
|
804
869
|
if ( ! headerRegistry && registryUrl ) headerRegistry = registryUrl;
|
|
805
870
|
const authHostList = Array.from( tempAuthHosts );
|
|
@@ -967,6 +1032,19 @@ async function main() {
|
|
|
967
1032
|
logWarn( `Warning: could not write .npmrc: ${e?.message || String( e )}` );
|
|
968
1033
|
|
|
969
1034
|
} );
|
|
1035
|
+
let loginHelperReady = false;
|
|
1036
|
+
try {
|
|
1037
|
+
|
|
1038
|
+
await ensureLoginHelperScript( targetDir );
|
|
1039
|
+
loginHelperReady = true;
|
|
1040
|
+
logSuccess( `Prepared login helper script (${LOGIN_HELPER_POSIX_PATH}).` );
|
|
1041
|
+
|
|
1042
|
+
} catch ( helperErr ) {
|
|
1043
|
+
|
|
1044
|
+
logWarn( `Warning: could not write ${LOGIN_HELPER_POSIX_PATH}: ${helperErr?.message || String( helperErr )}` );
|
|
1045
|
+
|
|
1046
|
+
}
|
|
1047
|
+
|
|
970
1048
|
const primedAuth = appendAuthTokenLines( npmrcPath, tempAuthLines );
|
|
971
1049
|
if ( primedAuth ) logDebug( 'Primed .npmrc with short-lived auth token.' );
|
|
972
1050
|
|
|
@@ -980,8 +1058,7 @@ async function main() {
|
|
|
980
1058
|
pkg.scripts = pkg.scripts || {};
|
|
981
1059
|
if ( ! pkg.scripts.preinstall ) {
|
|
982
1060
|
|
|
983
|
-
|
|
984
|
-
pkg.scripts.preinstall = `npx -y ${LOGIN_CLI}@latest`;
|
|
1061
|
+
pkg.scripts.preinstall = loginHelperReady ? LOGIN_HELPER_COMMAND : `npx -y ${LOGIN_CLI}@latest`;
|
|
985
1062
|
|
|
986
1063
|
}
|
|
987
1064
|
|