Comparing version 1.17.0 to 1.18.0
@@ -48,2 +48,5 @@ import { relative, resolve } from 'node:path/posix'; | ||
} | ||
/* c8 ignore next - already guarded */ | ||
if (s === null) | ||
continue; | ||
const impTarget = getImpTarget(s, polyfills); | ||
@@ -66,2 +69,3 @@ const reqTarget = getReqTarget(s, polyfills); | ||
source, | ||
...getSourceDialects(source, c), | ||
default: target, | ||
@@ -71,2 +75,3 @@ } | ||
source, | ||
...getSourceDialects(source, c), | ||
types: target.replace(/\.js$/, '.d.ts'), | ||
@@ -87,2 +92,3 @@ default: target, | ||
source, | ||
...getSourceDialects(source, c), | ||
default: target, | ||
@@ -92,2 +98,3 @@ } | ||
source, | ||
...getSourceDialects(source, c), | ||
types: target.replace(/\.js$/, '.d.ts'), | ||
@@ -129,2 +136,8 @@ default: target, | ||
}; | ||
const getSourceDialects = (source, c) => { | ||
const { sourceDialects } = c; | ||
if (!sourceDialects) | ||
return {}; | ||
return Object.fromEntries(sourceDialects.map(s => [s, source])); | ||
}; | ||
export const setMain = (c, pkg) => { | ||
@@ -131,0 +144,0 @@ const mod = resolveExport(pkg.exports['.'], ['require']); |
@@ -10,2 +10,3 @@ import type { ConditionalValue, ExportsSubpaths, Imports } from 'resolve-import'; | ||
esmDialects?: string[]; | ||
sourceDialects?: string[]; | ||
project?: string; | ||
@@ -12,0 +13,0 @@ exclude?: string[]; |
import { TshyConfig } from './types.js'; | ||
declare const _default: ({ commonjsDialects, esmDialects }: TshyConfig) => boolean; | ||
declare const _default: ({ commonjsDialects, esmDialects, sourceDialects, }: TshyConfig) => boolean; | ||
export default _default; | ||
//# sourceMappingURL=valid-extra-dialects.d.ts.map |
@@ -7,5 +7,4 @@ // validate esmDialects and commonjsDialects | ||
for (const av of a) { | ||
if (b.includes(av)) { | ||
if (b.includes(av)) | ||
return av; | ||
} | ||
} | ||
@@ -26,4 +25,5 @@ return false; | ||
d === 'node' || | ||
d === 'source' || | ||
d === 'default') { | ||
fail(`${which} must not contain ${d}`); | ||
fail(`tshy.${which}Dialects must not contain ${JSON.stringify(d)}`); | ||
return process.exit(1); | ||
@@ -34,4 +34,6 @@ } | ||
}; | ||
export default ({ commonjsDialects, esmDialects }) => { | ||
if (commonjsDialects === undefined && esmDialects === undefined) { | ||
export default ({ commonjsDialects, esmDialects, sourceDialects, }) => { | ||
if (commonjsDialects === undefined && | ||
esmDialects === undefined && | ||
sourceDialects === undefined) { | ||
return true; | ||
@@ -46,6 +48,25 @@ } | ||
} | ||
const overlap = arrayOverlap(commonjsDialects, esmDialects); | ||
if (overlap) { | ||
fail('commonjsDialects and esmDialects must be unique, ' + | ||
`found ${overlap} in both lists`); | ||
if (sourceDialects && | ||
!validExtraDialectSet(sourceDialects, 'source')) { | ||
return false; | ||
} | ||
for (const [aname, bname, a, b] of [ | ||
[ | ||
'commonjsDialects', | ||
'esmDialects', | ||
commonjsDialects, | ||
esmDialects, | ||
], | ||
[ | ||
'commonjsDialects', | ||
'sourceDialects', | ||
commonjsDialects, | ||
sourceDialects, | ||
], | ||
['esmDialects', 'sourceDialects', esmDialects, sourceDialects], | ||
]) { | ||
const overlap = arrayOverlap(a, b); | ||
if (!overlap) | ||
continue; | ||
fail(`${aname} and ${bname} must be unique, found ${overlap} in both lists`); | ||
return process.exit(1); | ||
@@ -52,0 +73,0 @@ } |
{ | ||
"name": "tshy", | ||
"version": "1.17.0", | ||
"version": "1.18.0", | ||
"description": "TypeScript HYbridizer - Hybrid (CommonJS/ESM) TypeScript node package builder", | ||
@@ -5,0 +5,0 @@ "author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)", |
@@ -877,6 +877,8 @@ # tshy - TypeScript HYbridizer | ||
If you are using tshy in a monorepo environment, you can | ||
configure TypeScript (and other tools) to resolve to the _source_ | ||
files rather than built artifacts by telling them to use the | ||
`"source"` export condition. | ||
To facilitate jumping directly to source definitions in some | ||
tools, you can define custom `"sourceDialects"` which will be | ||
resolved to the original TypeScript source. These custom dialects | ||
can then be configured to allow build tools (such as tsc) and | ||
editors (such as VS Code and neovim/CoC) to jump directly to | ||
source definitions. | ||
@@ -890,3 +892,3 @@ For example, in editors such as VS Code and neovim/CoC that use | ||
"compilerOptions": { | ||
"customConditions": ["source"] | ||
"customConditions": ["@my-project/source"] | ||
} | ||
@@ -896,2 +898,12 @@ } | ||
And then add this to your `package.json` file: | ||
```json | ||
{ | ||
"tshy": { | ||
"sourceDialects": ["@my-project/source"] | ||
} | ||
} | ||
``` | ||
If you are loading your program with a custom Node.js importer | ||
@@ -902,3 +914,3 @@ like [`tsx`](https://npm.im/tsx) that can load TypeScript | ||
```bash | ||
node --import=tsx --conditions=source ./script.ts | ||
node --import=tsx --conditions=@my-project/source ./script.ts | ||
``` | ||
@@ -912,2 +924,12 @@ | ||
#### Why not just use `"source"` as the target? | ||
Tshy always builds the `"source"` target referencing the location | ||
of the TypeScript file that was built. However, this can cause | ||
problems if tools use this to resolve into dependencies, which | ||
may not ship their TypeScript source. | ||
But if you can configure your tools to _only_ use this import | ||
condition outside of `node_modules`, then it's safe to use. | ||
### Custom `project` | ||
@@ -914,0 +936,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
214385
1627
1052