@@ -27,12 +27,13 @@ async function main() {
27
27
process . argv . includes ( "-g" ) || process . argv . includes ( "--global" ) ;
28
28
29
29
let pkg = await readPackageJson ( ) ;
30
- let pkgName = pkg . name ;
31
- if ( pkgName . includes ( "/" ) ) {
30
+ let mainBasename = pkg . name ;
31
+ if ( mainBasename . includes ( "/" ) ) {
32
32
let index = 1 ;
33
- index += pkgName . lastIndexOf ( "/" ) ;
34
- pkgName = pkgName . slice ( index ) ;
33
+ index += mainBasename . lastIndexOf ( "/" ) ;
34
+ mainBasename = mainBasename . slice ( index ) ;
35
35
}
36
+ let moduleName = toTitleCase ( mainBasename ) ;
36
37
37
38
// await Fs.mkdir("./docs", { recursive: true });
38
39
// let fh = await Fs.open("./docs/.gitkeep", "a");
@@ -81,9 +82,9 @@ async function main() {
81
82
"// auto-generated by `jswt reexport`" ,
82
83
"// DO NOT EDIT" ,
83
84
"" ,
84
- `import ${ pkgName } from "${ prefix } /${ pkgName } .js";` ,
85
+ `import ${ moduleName } from "${ prefix } /${ mainBasename } .js";` ,
85
86
"" ,
86
- `export default ${ pkgName } ;` ,
87
+ `export default ${ moduleName } ;` ,
87
88
"" ,
88
89
] . join ( "\n" ) ,
89
90
) ;
@@ -95,7 +96,7 @@ async function main() {
95
96
jsconfig = await createJsConfig (
96
97
pkg ,
97
98
tsconfigTxt ,
98
- `${ prefix } /${ pkgName } .js` ,
99
+ `${ prefix } /${ mainBasename } .js` ,
99
100
) ;
100
101
}
101
102
@@ -215,23 +216,22 @@ async function main() {
215
216
216
217
let indexNames = [ "index.js" , "./index.js" ] ;
217
218
let mainIsIndex = indexNames . includes ( pkg . main ) ;
218
- let mainPath = `${ prefix } /${ pkgName } .js` ;
219
+ let mainFilePath = `${ prefix } /${ mainBasename } .js` ;
219
220
if ( ! mainIsIndex ) {
220
221
// ensures that filepath has leading './'
221
- mainPath = Path . relative ( "." , pkg . main ) ;
222
- mainPath = `./${ mainPath } ` ;
222
+ mainFilePath = Path . relative ( "." , pkg . main ) ;
223
+ mainFilePath = `./${ mainFilePath } ` ;
223
224
}
224
225
225
226
{
226
- let mainName = toTitleCase ( pkgName ) ;
227
227
await initFile (
228
- mainPath ,
228
+ mainFilePath ,
229
229
[
230
- `let ${ mainName } = {};` ,
230
+ `let ${ moduleName } = {};` ,
231
231
"" ,
232
- `${ mainName } .answer = 42;` ,
232
+ `${ moduleName } .answer = 42;` ,
233
233
"" ,
234
- `export default ${ mainName } ;` ,
234
+ `export default ${ moduleName } ;` ,
235
235
"" ,
236
236
] . join ( "\n" ) ,
237
237
) ;
@@ -240,7 +240,7 @@ async function main() {
240
240
let hasIndex = await fileExists ( "./index.js" ) ;
241
241
if ( ! hasIndex ) {
242
242
if ( mainIsIndex ) {
243
- let allArgs = [ "pkg" , "set" , `main=${ mainPath } ` ] ;
243
+ let allArgs = [ "pkg" , "set" , `main=${ mainFilePath } ` ] ;
244
244
await exec ( "npm" , allArgs ) ;
245
245
await sortAndWritePackageJson ( ) ;
246
246
}
@@ -286,7 +286,7 @@ async function main() {
286
286
let allArgs = [
287
287
"pkg" ,
288
288
"set" ,
289
- `files[]=${ mainPath } ` ,
289
+ `files[]=${ mainFilePath } ` ,
290
290
`files[]=./bin/*.js` ,
291
291
`files[]=./lib/*.js` ,
292
292
`files[]=./tests/*.js` ,
@@ -317,7 +317,7 @@ async function main() {
317
317
"pkg" ,
318
318
"set" ,
319
319
"type=module" ,
320
- `exports[.]=${ mainPath } ` ,
320
+ `exports[.]=${ mainFilePath } ` ,
321
321
`exports[./*]=./*` ,
322
322
] ;
323
323
await exec ( "npm" , allArgs ) ;
@@ -333,7 +333,7 @@ async function main() {
333
333
"pkg" ,
334
334
"set" ,
335
335
"type=module" ,
336
- `imports[${ pkg . name } ]=${ mainPath } ` ,
336
+ `imports[${ pkg . name } ]=${ mainFilePath } ` ,
337
337
] ;
338
338
await exec ( "npm" , allArgs ) ;
339
339
await sortAndWritePackageJson ( ) ;
@@ -344,7 +344,7 @@ async function main() {
344
344
`<script type="importmap">` ,
345
345
` {` ,
346
346
` "imports": {` ,
347
- ` "${ pkg . name } ": "${ mainPath } ",` ,
347
+ ` "${ pkg . name } ": "${ mainFilePath } ",` ,
348
348
` "${ pkg . name } /": "./"` ,
349
349
` }` ,
350
350
` }` ,
@@ -628,10 +628,10 @@ async function getLatest20xx() {
628
628
* @param {Object } pkg
629
629
* @param {String } pkg.name
630
630
* @param {String } tsconfigTxt
631
- * @param {String } mainPath
631
+ * @param {String } mainFilePath
632
632
* @returns
633
633
*/
634
- async function createJsConfig ( pkg , tsconfigTxt , mainPath ) {
634
+ async function createJsConfig ( pkg , tsconfigTxt , mainFilePath ) {
635
635
if ( ! tsconfigTxt . includes ( `"include":` ) ) {
636
636
let includables = [
637
637
"*.js" ,
@@ -650,7 +650,7 @@ async function createJsConfig(pkg, tsconfigTxt, mainPath) {
650
650
651
651
{
652
652
let lines = [
653
- ` "${ pkg . name } ": ["${ mainPath } "]` ,
653
+ ` "${ pkg . name } ": ["${ mainFilePath } "]` ,
654
654
` "${ pkg . name } /*": ["./*"]` ,
655
655
] ;
656
656
let str = lines . join ( `,\n` ) ;
0 commit comments