@@ -27,12 +27,13 @@ async function main() {
2727 process . argv . includes ( "-g" ) || process . argv . includes ( "--global" ) ;
2828
2929 let pkg = await readPackageJson ( ) ;
30- let pkgName = pkg . name ;
31- if ( pkgName . includes ( "/" ) ) {
30+ let mainBasename = pkg . name ;
31+ if ( mainBasename . includes ( "/" ) ) {
3232 let index = 1 ;
33- index += pkgName . lastIndexOf ( "/" ) ;
34- pkgName = pkgName . slice ( index ) ;
33+ index += mainBasename . lastIndexOf ( "/" ) ;
34+ mainBasename = mainBasename . slice ( index ) ;
3535 }
36+ let moduleName = toTitleCase ( mainBasename ) ;
3637
3738 // await Fs.mkdir("./docs", { recursive: true });
3839 // let fh = await Fs.open("./docs/.gitkeep", "a");
@@ -81,9 +82,9 @@ async function main() {
8182 "// auto-generated by `jswt reexport`" ,
8283 "// DO NOT EDIT" ,
8384 "" ,
84- `import ${ pkgName } from "${ prefix } /${ pkgName } .js";` ,
85+ `import ${ moduleName } from "${ prefix } /${ mainBasename } .js";` ,
8586 "" ,
86- `export default ${ pkgName } ;` ,
87+ `export default ${ moduleName } ;` ,
8788 "" ,
8889 ] . join ( "\n" ) ,
8990 ) ;
@@ -96,7 +97,7 @@ async function main() {
9697 pkg ,
9798 tsconfigTxt ,
9899 prefix ,
99- `${ prefix } /${ pkgName } .js` ,
100+ `${ prefix } /${ mainBasename } .js` ,
100101 ) ;
101102 }
102103
@@ -216,23 +217,22 @@ async function main() {
216217
217218 let indexNames = [ "index.js" , "./index.js" ] ;
218219 let mainIsIndex = indexNames . includes ( pkg . main ) ;
219- let mainPath = `${ prefix } /${ pkgName } .js` ;
220+ let mainFilePath = `${ prefix } /${ mainBasename } .js` ;
220221 if ( ! mainIsIndex ) {
221222 // ensures that filepath has leading './'
222- mainPath = Path . relative ( "." , pkg . main ) ;
223- mainPath = `./${ mainPath } ` ;
223+ mainFilePath = Path . relative ( "." , pkg . main ) ;
224+ mainFilePath = `./${ mainFilePath } ` ;
224225 }
225226
226227 {
227- let mainName = toTitleCase ( pkgName ) ;
228228 await initFile (
229- mainPath ,
229+ mainFilePath ,
230230 [
231- `let ${ mainName } = {};` ,
231+ `let ${ moduleName } = {};` ,
232232 "" ,
233- `${ mainName } .answer = 42;` ,
233+ `${ moduleName } .answer = 42;` ,
234234 "" ,
235- `export default ${ mainName } ;` ,
235+ `export default ${ moduleName } ;` ,
236236 "" ,
237237 ] . join ( "\n" ) ,
238238 ) ;
@@ -241,7 +241,7 @@ async function main() {
241241 let hasIndex = await fileExists ( "./index.js" ) ;
242242 if ( ! hasIndex ) {
243243 if ( mainIsIndex ) {
244- let allArgs = [ "pkg" , "set" , `main=${ mainPath } ` ] ;
244+ let allArgs = [ "pkg" , "set" , `main=${ mainFilePath } ` ] ;
245245 await exec ( "npm" , allArgs ) ;
246246 await sortAndWritePackageJson ( ) ;
247247 }
@@ -287,7 +287,7 @@ async function main() {
287287 let allArgs = [
288288 "pkg" ,
289289 "set" ,
290- `files[]=${ mainPath } ` ,
290+ `files[]=${ mainFilePath } ` ,
291291 `files[]=./bin/*.js` ,
292292 `files[]=./lib/*.js` ,
293293 `files[]=./tests/*.js` ,
@@ -318,7 +318,7 @@ async function main() {
318318 "pkg" ,
319319 "set" ,
320320 "type=module" ,
321- `exports[.]=${ mainPath } ` ,
321+ `exports[.]=${ mainFilePath } ` ,
322322 `exports[./*]=${ prefix } /*` ,
323323 ] ;
324324 await exec ( "npm" , allArgs ) ;
@@ -334,7 +334,7 @@ async function main() {
334334 "pkg" ,
335335 "set" ,
336336 "type=module" ,
337- `imports[${ pkg . name } ]=${ mainPath } ` ,
337+ `imports[${ pkg . name } ]=${ mainFilePath } ` ,
338338 `imports[${ pkg . name } /]=${ prefix } /` ,
339339 ] ;
340340 await exec ( "npm" , allArgs ) ;
@@ -346,7 +346,7 @@ async function main() {
346346 `<script type="importmap">` ,
347347 ` {` ,
348348 ` "imports": {` ,
349- ` "${ pkg . name } ": "${ mainPath } ",` ,
349+ ` "${ pkg . name } ": "${ mainFilePath } ",` ,
350350 ` "${ pkg . name } /": "${ prefix } /"` ,
351351 ` }` ,
352352 ` }` ,
@@ -631,10 +631,10 @@ async function getLatest20xx() {
631631 * @param {String } pkg.name
632632 * @param {String } tsconfigTxt
633633 * @param {String } prefix
634- * @param {String } mainPath
634+ * @param {String } mainFilePath
635635 * @returns
636636 */
637- async function createJsConfig ( pkg , tsconfigTxt , prefix , mainPath ) {
637+ async function createJsConfig ( pkg , tsconfigTxt , prefix , mainFilePath ) {
638638 if ( ! tsconfigTxt . includes ( `"include":` ) ) {
639639 let includables = [
640640 "*.js" ,
@@ -653,7 +653,7 @@ async function createJsConfig(pkg, tsconfigTxt, prefix, mainPath) {
653653
654654 {
655655 let lines = [
656- ` "${ pkg . name } ": ["${ mainPath } "]` ,
656+ ` "${ pkg . name } ": ["${ mainFilePath } "]` ,
657657 ` "${ pkg . name } /*": ["${ prefix } /*"]` ,
658658 ] ;
659659 let str = lines . join ( `,\n` ) ;
0 commit comments