Socket
Socket
Sign inDemoInstall

tshy

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tshy - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

3

dist/esm/config.js

@@ -9,3 +9,4 @@ // get the config and package and stuff

(e.exports === undefined || validExports(e['exports'])) &&
(e.dialects === undefined || validDialects(e['dialects']));
(e.dialects === undefined || validDialects(e['dialects'])) &&
(e.selfLink === undefined || typeof e.selfLink === 'boolean');
const getConfig = (pkg, sources) => {

@@ -12,0 +13,0 @@ const tshy = validConfig(pkg.tshy) ? pkg.tshy : {};

@@ -1,7 +0,11 @@

import { Export, TshyConfig, TshyExport } from './types.js';
/// <reference types="node" resolution-mode="require"/>
import { Export, Package, TshyConfig, TshyExport } from './types.js';
export declare const getImpTarget: (s: string | TshyExport | undefined | null) => string | undefined | null;
export declare const getReqTarget: (s: string | TshyExport | undefined | null, polyfills: Map<string, string>) => string | null | undefined;
export declare const getExports: (c: TshyConfig, polyfills: Map<string, string>) => Record<string, Export>;
export declare const setMain: (c: TshyConfig | undefined, pkg: Package & {
exports: Record<string, Export>;
}) => undefined;
declare const _default: Record<string, Export>;
export default _default;
//# sourceMappingURL=exports.d.ts.map

@@ -8,2 +8,3 @@ import { relative, resolve } from 'node:path/posix';

import { resolveExport } from './resolve-export.js';
import { isDialect } from './valid-dialects.js';
export const getImpTarget = (s) => {

@@ -20,3 +21,3 @@ if (s === undefined)

}
return resolveExport(s, 'import');
return resolveExport(s, ['import']);
};

@@ -34,3 +35,3 @@ export const getReqTarget = (s, polyfills) => {

}
return getReqTarget(resolveExport(s, 'require'), polyfills);
return getReqTarget(resolveExport(s, ['require']), polyfills);
};

@@ -42,3 +43,3 @@ export const getExports = (c, polyfills) => {

fail('no exports on tshy config (is there code in ./src?)');
process.exit(1);
return process.exit(1);
}

@@ -77,7 +78,31 @@ /* c8 ignore stop */

};
export const setMain = (c, pkg) => {
if (c?.main !== undefined) {
if (!isDialect(c.main)) {
fail(`config.main must be 'commonjs' or 'esm', got: ${c.main}`);
return process.exit(1);
}
const m = c.main === 'commonjs' ? 'require' : 'import';
const mod = resolveExport(pkg.exports['.'], [m]);
if (!mod) {
fail(`could not resolve exports['.'] for tshy.main '${m}'`);
return process.exit(1);
}
const types = resolveExport(pkg.exports['.'], [m, 'types']);
pkg.main = mod;
if (types && types !== mod)
pkg.types = types;
else
delete pkg.types;
}
else {
delete pkg.main;
delete pkg.types;
}
};
// These are all defined by exports, so it's just confusing otherwise
delete pkg.module;
delete pkg.main;
delete pkg.types;
export default pkg.exports = getExports(config, polyfills);
pkg.exports = getExports(config, polyfills);
setMain(config, pkg);
export default pkg.exports;
//# sourceMappingURL=exports.js.map

@@ -6,3 +6,3 @@ // get the package.json data for the cwd

try {
return Object.assign(JSON.parse(readFileSync('package.json', 'utf8')), { type: 'module' });
return JSON.parse(readFileSync('package.json', 'utf8'));
}

@@ -9,0 +9,0 @@ catch (er) {

@@ -1,2 +0,2 @@

export declare const resolveExport: (exp: any, m: 'import' | 'require') => string | undefined | null;
export declare const resolveExport: (exp: any, conditions: ('import' | 'require' | 'types')[]) => string | undefined | null;
//# sourceMappingURL=resolve-export.d.ts.map

@@ -1,2 +0,2 @@

export const resolveExport = (exp, m) => {
export const resolveExport = (exp, conditions) => {
if (typeof exp === 'string')

@@ -10,3 +10,3 @@ return exp;

for (const e of exp) {
const u = resolveExport(e, m);
const u = resolveExport(e, conditions);
if (u || u === null)

@@ -17,9 +17,11 @@ return u;

}
if (exp[m])
return resolveExport(exp[m], m);
if (exp.node)
return resolveExport(exp.node, m);
if (exp.default)
return resolveExport(exp.default, m);
const conds = [...conditions, 'node', 'default'];
for (const [c, e] of Object.entries(exp)) {
if (conds.includes(c)) {
const u = resolveExport(e, conditions);
if (u || u === null)
return u;
}
}
};
//# sourceMappingURL=resolve-export.js.map

@@ -36,4 +36,7 @@ // link the package folder into ./target/node_modules/<pkgname>

export const link = (pkg, where) => {
if (!pkg.name || linkedAlready(pkg))
if (!pkg.name ||
pkg?.tshy?.selfLink === false ||
linkedAlready(pkg)) {
return;
}
const dest = resolve(where, 'node_modules', pkg.name);

@@ -45,7 +48,16 @@ const dir = dirname(dest);

dirsMade.set(dest, made);
symlinkSync(src, dest);
try {
symlinkSync(src, dest);
}
catch {
rimrafSync(dest);
symlinkSync(src, dest);
}
};
export const unlink = (pkg, where) => {
if (!pkg.name || linkedAlready(pkg))
if (!pkg.name ||
pkg?.tshy?.selfLink === false ||
linkedAlready(pkg)) {
return;
}
const dest = resolve(where, 'node_modules', pkg.name);

@@ -52,0 +64,0 @@ rimrafSync(dest);

export type TshyConfig = {
exports?: Record<string, TshyExport>;
dialects?: Dialect[];
selfLink?: boolean;
main?: Dialect;
};

@@ -30,2 +32,4 @@ export type Dialect = 'commonjs' | 'esm';

version: string;
main?: string;
types?: string;
type?: 'module';

@@ -32,0 +36,0 @@ bin?: string | Record<string, string>;

import { Dialect } from './types.js';
export declare const isDialect: (d: any) => d is Dialect;
declare const _default: (d: any) => d is Dialect[];
export default _default;
//# sourceMappingURL=valid-dialects.d.ts.map
import fail from './fail.js';
const isDialect = (d) => d === 'commonjs' || d === 'esm';
export const isDialect = (d) => d === 'commonjs' || d === 'esm';
export default (d) => {

@@ -4,0 +4,0 @@ if (!!d &&

import { join } from 'path/posix';
import { resolveExport } from './resolve-export.js';
export default (exp) => {
const i = resolveExport(exp, 'import');
const r = resolveExport(exp, 'require');
const i = resolveExport(exp, ['import']);
const r = resolveExport(exp, ['require']);
if (i && join(i).startsWith('src/'))

@@ -7,0 +7,0 @@ return false;

{
"name": "tshy",
"version": "1.1.1",
"version": "1.2.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)",

@@ -51,2 +51,4 @@ # tshy - TypeScript HYbridizer

### `exports`
You can set other entry points by putting this in your

@@ -115,3 +117,3 @@ `package.json` file:

## Making Noise
### Making Noise

@@ -126,3 +128,3 @@ On failure, all logs will be printed.

## Selecting Dialects
### Selecting Dialects

@@ -144,2 +146,73 @@ You can tell tshy which dialect you're building for by setting

### Suppressing the self-link
See below about **Local Package `exports`** for an explanation of
what this is.
Suppress the symlink to the project folder into a `node_modules`
folder in `dist` and `src` by doing this:
```json
{
"tshy": {
"selfLink": false
}
}
```
### Old Style Exports
Versions of node prior to 12.10.0 (published in early to mid
2016) did not have support for `exports` as a means for defining
package entry points.
By default, tshy deletes the `main` field, rather than maintain
this affordance for versions of node that met their end of life
more than a year ago. However, some tools still rely on `main`
and have not been updated to read the package entry points via
`exports`.
You can tell tshy to export a top-level `main` and `types` field
by setting `main` to either `commonjs` or `esm`. If `main` is set
to `"commonjs"`, then the package will not have `"type":
"module"` set.
If the specified dialect is not built, or if a `"."` export is
not created, or if the `"."` export does not support the
specified dialect, then the build will fail.
For example, this config:
```json
{
"tshy": {
"exports": {
".": "./src/index.ts"
},
"main": "commonjs"
}
}
```
will produce:
```json
{
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"exports": {
".": {
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
}
}
}
}
```
## CommonJS Dialect Polyfills

@@ -306,2 +379,14 @@

You can suppress the self-linking by putting this config in
`package.json` but be advised this means that you won't be able
to import from local package exports:
```json
{
"tshy": {
"selfLink": false
}
}
```
<details>

@@ -308,0 +393,0 @@ <summary>tl;dr explanation</summary>

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc