Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.14.1 to 1.15.0

dist/esm/build-live-commonjs.d.ts

12

dist/esm/build.js
import chalk from 'chalk';
import config from './config.js';
import { syncContentSync } from 'sync-content';

@@ -14,2 +15,4 @@ import bins from './bins.js';

import writePackage from './write-package.js';
import { buildLiveESM } from './build-live-esm.js';
import { buildLiveCommonJS } from './build-live-commonjs.js';
export default async () => {

@@ -19,6 +22,11 @@ cleanBuildTmp();

await linkImports(pkg, 'src');
const liveDev = config.liveDev &&
process.env.npm_command !== 'publish' &&
process.env.npm_command !== 'pack';
const esm = liveDev ? buildLiveESM : buildESM;
const commonjs = liveDev ? buildLiveCommonJS : buildCommonJS;
if (dialects.includes('esm'))
buildESM();
esm();
if (dialects.includes('commonjs'))
buildCommonJS();
commonjs();
await unlinkImports(pkg, 'src');

@@ -25,0 +33,0 @@ unlinkSelfDep(pkg, 'src');

3

dist/esm/config.js

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

validBoolean(e, 'selfLink') &&
validBoolean(e, 'main');
validBoolean(e, 'main') &&
validBoolean(e, 'liveDev');
const match = (e, pattern) => pattern.some(m => m.match(e));

@@ -36,0 +37,0 @@ const parsePattern = (p) => Array.isArray(p)

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

const { esmDialects = [], commonjsDialects = [] } = config;
const liveDev = config.liveDev &&
process.env.npm_command !== 'publish' &&
process.env.npm_command !== 'pack';
const getTargetForDialectCondition = (s, dialect, condition, type, polyfills = new Map()) => {

@@ -19,6 +22,10 @@ if (s === undefined)

const pf = dialect === 'commonjs' ? 'cjs' : dialect;
const rel = relative(resolve('./src'), resolve(polyfills.get(pf)?.map.get(s) ?? s));
const target = liveDev
? rel
: rel.replace(/\.([mc]?)tsx?$/, '.$1js');
return !s || !s.startsWith('./src/')
? s
: dialects.includes(type)
? `./dist/${dialect}/${relative(resolve('./src'), resolve(polyfills.get(pf)?.map.get(s) ?? s)).replace(/\.([mc]?)tsx?$/, '.$1js')}`
? `./dist/${dialect}/${target}`
: undefined;

@@ -57,8 +64,15 @@ }

for (const d of esmDialects) {
const source = s && (polyfills.get(d)?.map.get(s) ?? s);
const target = getTargetForDialectCondition(s, d, d, 'esm', polyfills);
if (target) {
exp[d] = {
types: target.replace(/\.js$/, '.d.ts'),
default: target,
};
exp[d] = liveDev
? {
source,
default: target,
}
: {
types: target.replace(/\.js$/, '.d.ts'),
source,
default: target,
};
}

@@ -69,8 +83,15 @@ }

for (const d of commonjsDialects) {
const source = s && (polyfills.get(d)?.map.get(s) ?? s);
const target = getTargetForDialectCondition(s, d, d, 'commonjs', polyfills);
if (target) {
exp[d] = {
types: target.replace(/\.js$/, '.d.ts'),
default: target,
};
exp[d] = liveDev
? {
source,
default: target,
}
: {
types: target.replace(/\.js$/, '.d.ts'),
source,
default: target,
};
}

@@ -81,12 +102,24 @@ }

if (impTarget) {
exp.import = {
types: impTarget.replace(/\.(m?)js$/, '.d.$1ts'),
default: impTarget,
};
exp.import = liveDev
? {
source: s,
default: impTarget,
}
: {
types: impTarget.replace(/\.(m?)js$/, '.d.$1ts'),
source: s,
default: impTarget,
};
}
if (reqTarget) {
exp.require = {
types: reqTarget.replace(/\.(c?)js$/, '.d.$1ts'),
default: reqTarget,
};
exp.require = liveDev
? {
source: s,
default: reqTarget,
}
: {
types: reqTarget.replace(/\.(c?)js$/, '.d.$1ts'),
source: s,
default: reqTarget,
};
}

@@ -93,0 +126,0 @@ }

@@ -11,2 +11,3 @@ import type { ConditionalValue, ExportsSubpaths, Imports } from 'resolve-import';

exclude?: string[];
liveDev?: boolean;
};

@@ -13,0 +14,0 @@ export type TshyConfig = TshyConfigMaybeGlobExports & {

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

@@ -279,2 +279,3 @@ # tshy - TypeScript HYbridizer

"types": "./dist/esm/foo.d.ts",
"source": "./src/foo.ts",
"default": "./dist/esm/foo.js"

@@ -284,2 +285,3 @@ },

"types": "./dist/commonjs/foo.d.ts",
"source": "./src/foo.ts",
"default": "./dist/commonjs/foo.js"

@@ -350,2 +352,3 @@ }

"types": "./dist/commonjs/index.d.ts",
"source": "./src/index.ts",
"default": "./dist/commonjs/index.js"

@@ -355,2 +358,3 @@ },

"types": "./dist/esm/index.d.ts",
"source": "./src/index.ts",
"default": "./dist/esm/index.js"

@@ -362,2 +366,3 @@ }

"types": "./dist/commonjs/component/foo.d.ts",
"source": "./src/component/foo.ts",
"default": "./dist/commonjs/component/foo.js"

@@ -367,2 +372,3 @@ },

"types": "./dist/esm/component/foo.d.ts",
"source": "./src/component/foo.ts",
"default": "./dist/esm/component/foo.js"

@@ -390,2 +396,27 @@ }

### Live Dev
Set `"liveDev": true` in the tshy config in `package.json` to
build in link mode. In this mode, the files are hard-linked into
place in the `dist` folder, so that edits are immediately visible.
This is particularly beneficial in monorepo projects, where
workspaces may be edited in parallel, and so it's handy to have
changes reflected in real time without a rebuild.
Of course, tools that can't handle TypeScript will have a problem
with this, so any generic `node` program will not be able to run
your code. For this reason:
- `liveDev` is always disabled when the `npm_command` environment
variable is `'publish'` or `'pack'`. In these situations, your
code is being built for public consumption, and must be
compiled.
- Code in dist will not be able to be loaded in the node repl
unless you run it with a loader, such as `node --import=tsx`.
- Because it links files into place, a rebuild _is_ required when
a file is added or removed.
See also: "Loading from Source", below.
### Package `#imports`

@@ -584,2 +615,3 @@

"types": "./dist/commonjs/index.d.ts",
"source": "./src/index.js",
"default": "./dist/commonjs/index.js"

@@ -589,2 +621,3 @@ },

"types": "./dist/esm/index.d.ts",
"source": "./src/index.ts",
"default": "./dist/esm/index.js"

@@ -694,2 +727,3 @@ }

"types": "./dist/deno/index.d.ts",
"source": "./src/index.ts",
"default": "./dist/deno/index.js"

@@ -699,2 +733,3 @@ },

"types": "./dist/browser/index.d.ts",
"default": "./src/index.ts",
"default": "./dist/browser/index.js"

@@ -704,2 +739,3 @@ },

"types": "./dist/webpack/index.d.ts",
"source": "./src/index.ts",
"default": "./dist/webpack/index.js"

@@ -709,2 +745,3 @@ },

"types": "./dist/commonjs/index.d.ts",
"source": "./src/index.ts",
"default": "./dist/commonjs/index.js"

@@ -714,2 +751,3 @@ },

"types": "./dist/esm/index.d.ts",
"source": "./src/index.ts",
"default": "./dist/esm/index.js"

@@ -739,2 +777,40 @@ }

If dialect overrides are used, then the `"source"` export
condition will refer to the original source for the override. For
example:
```json
{
"exports": {
".": {
"deno": {
"types": "./dist/deno/index.d.ts",
"source": "./src/index-deno.mts",
"default": "./dist/deno/index.js"
},
"browser": {
"types": "./dist/browser/index.d.ts",
"default": "./src/index-browser.mts",
"default": "./dist/browser/index.js"
},
"webpack": {
"types": "./dist/webpack/index.d.ts",
"source": "./src/index-webpack.cts",
"default": "./dist/webpack/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"source": "./src/index-cjs.cts",
"default": "./dist/commonjs/index.js"
},
"import": {
"types": "./dist/esm/index.d.ts",
"source": "./src/index.ts",
"default": "./dist/esm/index.js"
}
}
}
}
```
Note that the `commonjs` override uses the abbreviated `cjs`

@@ -796,2 +872,35 @@ name (historical reasons, it was originally the only override

### Loading from Source
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.
For example, in editors such as VS Code and neovim/CoC that use
the TypeScript language services, you can give them a `tsconfig`
that contains this:
```json
{
"compilerOptions": {
"customConditions": ["source"]
}
}
```
If you are loading your program with a custom Node.js importer
like [`tsx`](https://npm.im/tsx) that can load TypeScript
directly, you can specify it like this:
```bash
node --import=tsx --conditions=source ./script.ts
```
Other TypeScript-aware tools may have other mechanisms for
specifying export conditions. Refer to their documentation for
more information.
See also: "Live Dev", above.
### Custom `project`

@@ -798,0 +907,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

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