-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
put all imports in top-level imports field
- Loading branch information
Showing
12 changed files
with
82 additions
and
294 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
// merge tshy.imports with package.json imports | ||
|
||
import { Package, TshyConfig } from './types.js' | ||
import { Package } from './types.js' | ||
|
||
// strip the ./src/ and turn ts extension into js | ||
const stripSrc = (ti: TshyConfig['imports']): Package['imports'] => { | ||
if (!ti) return undefined | ||
// strip the ./src/ and turn ts extension into js for built imports | ||
// leave unbuilt imports alone, they'll be symlinked | ||
export default (pkg: Package): Package['imports'] => { | ||
const { imports } = pkg | ||
if (!imports) return undefined | ||
return Object.fromEntries( | ||
Object.entries(ti).map(([k, v]) => [ | ||
Object.entries(imports).map(([k, v]) => [ | ||
k, | ||
'./' + | ||
v | ||
.substring('./src/'.length) | ||
.replace(/\.([cm]?)ts$/, '.$1js') | ||
.replace(/\.tsx$/, '.js'), | ||
typeof v === 'string' && v.startsWith('./src/') | ||
? './' + | ||
v | ||
.substring('./src/'.length) | ||
.replace(/\.([cm]?)ts$/, '.$1js') | ||
.replace(/\.tsx$/, '.js') | ||
: v, | ||
]) | ||
) | ||
} | ||
|
||
export default (pkg: Package): Package['imports'] => { | ||
const { tshy } = pkg | ||
if (!tshy?.imports && !pkg.imports) return undefined | ||
return { | ||
...pkg.imports, | ||
...stripSrc(tshy?.imports), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.