11#!/usr/bin/env node
2- var PROGRAM_NAME = process . argv [ 1 ] . replace ( / .* \/ / , "" )
3- var pkg_src = { } , pkg_hash = { }
42
5- findRemappings ( "." )
3+ console . log ( buildRemappings ( "." ) . join ( "\n" ) )
64
7- Object . keys ( pkg_src ) . sort ( ( a , b ) => a . length - b . length ) . sort (
8- ( a , b ) => {
9- var depth = name => pkg_src [ name ] . split ( "/" ) . length
10- return depth ( a ) - depth ( b )
11- }
12- ) . forEach ( name => {
13- console . log ( `${ name } /=${ pkg_src [ name ] } /` )
14- } )
15-
16- function findRemappings ( prefix ) {
17- ls ( `${ prefix } /${ process . env . DAPP_LIB } ` ) . forEach ( name => {
18- var lib = `${ prefix } /${ process . env . DAPP_LIB } `
19- var src = `${ lib } /${ name } /${ process . env . DAPP_SRC } ` . replace ( / ^ .\/ / , "" )
20-
21- // Shortcut when we're ignoring all the Git hash stuff.
22- if ( process . env . DAPP_IGNORE_HASHES ) {
23- pkg_src [ name ] = src
24- findRemappings ( `${ lib } /${ name } ` )
25- return
26- }
5+ function buildRemappings ( prefix ) {
6+ const lib = `${ prefix } /${ process . env . DAPP_LIB } `
7+ const ctx = `${ prefix } /${ process . env . DAPP_SRC } `
278
28- if ( ls ( `${ lib } /${ name } ` ) . includes ( ".git" ) != true ) {
29- console . error ( `${ PROGRAM_NAME } : error: ${ lib } /${ name } is not a Git repository` )
30- console . error ( `${ PROGRAM_NAME } : error: try "dapp update" to initialize submodules` )
31- process . exit ( 1 )
32- }
33-
34- var hash = run ( "git" , [ "-C" , src , "rev-parse" , "HEAD" ] )
9+ const remappings = ls ( lib ) . map ( name => {
10+ return `${ normalize ( ctx ) } :${ name } /=${ normalize ( lib ) } /${ name } /${ process . env . DAPP_SRC } /`
11+ } )
3512
36- if ( pkg_src [ name ] ) {
37- if ( hash != pkg_hash [ name ] ) {
38- console . error ( `${ PROGRAM_NAME } : warning: mismatching packages:` )
39- console . error ( `${ PROGRAM_NAME } : warning: (1) ${ pkg_src [ name ] } ` )
40- console . error ( `${ PROGRAM_NAME } : warning: (2) ${ src } ` )
41- console . error ( `${ PROGRAM_NAME } : warning: using ${ pkg_src [ name ] } . You can override this using \`DAPP_REMAPPINGS\`` )
42- } else if ( src . length < pkg_src [ name ] . length ) {
43- pkg_src [ name ] = src
44- }
45- } else {
46- pkg_src [ name ] = src
47- pkg_hash [ name ] = hash
48- }
13+ return ls ( lib ) . map ( name => {
14+ return buildRemappings ( `${ lib } /${ name } ` )
15+ } ) . concat ( remappings ) . flat ( )
16+ }
4917
50- findRemappings ( `${ lib } /${ name } ` )
51- } )
18+ // strip the leading `.` or `./` from a path
19+ function normalize ( path ) {
20+ return path . replace ( / ^ \. \/ / , "" ) . replace ( / ^ \/ / , "" )
5221}
5322
5423function ls ( dir ) {
@@ -59,8 +28,3 @@ function ls(dir) {
5928 }
6029}
6130
62- function run ( cmd , args ) {
63- return require ( "child_process" ) . execFileSync ( cmd , args , {
64- encoding : "utf-8"
65- } )
66- }
0 commit comments