Comparing version 2.0.6 to 2.0.7
import { DaemonClient } from './client.js'; | ||
import './hooks/require.js'; | ||
export * from './client.js'; | ||
export * from './types.js'; | ||
export * from './client.js'; | ||
export declare const tsimp: DaemonClient; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -26,2 +26,3 @@ "use strict"; | ||
require("./hooks/require.js"); | ||
__exportStar(require("./client.js"), exports); | ||
__exportStar(require("./types.js"), exports); | ||
@@ -41,5 +42,4 @@ //@ts-ignore | ||
} | ||
__exportStar(require("./client.js"), exports); | ||
// the imp is a client of the daemon | ||
exports.tsimp = new client_js_1.DaemonClient(); | ||
//# sourceMappingURL=index.js.map |
@@ -8,5 +8,5 @@ "use strict"; | ||
const typescript_1 = __importDefault(require("typescript")); | ||
const ts_sys_cached_js_1 = require("../ts-sys-cached.js"); | ||
const create_mode_aware_cache_key_js_1 = require("./create-mode-aware-cache-key.js"); | ||
const get_canonical_filename_js_1 = require("./get-canonical-filename.js"); | ||
const ts_sys_cached_js_1 = require("../ts-sys-cached.js"); | ||
const tsconfig_js_1 = require("./tsconfig.js"); | ||
@@ -13,0 +13,0 @@ // ResolveTypeReferenceDirectiveReferences internal cache |
@@ -12,5 +12,5 @@ "use strict"; | ||
const get_url_js_1 = require("../get-url.js"); | ||
const ts_sys_cached_js_1 = require("../ts-sys-cached.js"); | ||
const language_service_js_1 = require("./language-service.js"); | ||
const load_js_1 = require("./load.js"); | ||
const ts_sys_cached_js_1 = require("../ts-sys-cached.js"); | ||
exports.serviceName = 'tsimp'; | ||
@@ -17,0 +17,0 @@ exports.daemonScript = (0, url_1.fileURLToPath)((0, get_url_js_1.getUrl)('./service/daemon.mjs')); |
import { DaemonClient } from './client.js'; | ||
import './hooks/require.js'; | ||
export * from './client.js'; | ||
export * from './types.js'; | ||
export * from './client.js'; | ||
export declare const tsimp: DaemonClient; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,2 +6,3 @@ import Module from 'node:module'; | ||
import './hooks/require.js'; | ||
export * from './client.js'; | ||
export * from './types.js'; | ||
@@ -21,5 +22,4 @@ //@ts-ignore | ||
} | ||
export * from './client.js'; | ||
// the imp is a client of the daemon | ||
export const tsimp = new DaemonClient(); | ||
//# sourceMappingURL=index.js.map |
import ts from 'typescript'; | ||
import { getCurrentDirectory } from '../ts-sys-cached.js'; | ||
import { createModeAwareCacheKey } from './create-mode-aware-cache-key.js'; | ||
import { getCanonicalFileName } from './get-canonical-filename.js'; | ||
import { getCurrentDirectory } from '../ts-sys-cached.js'; | ||
import { tsconfig } from './tsconfig.js'; | ||
@@ -6,0 +6,0 @@ // ResolveTypeReferenceDirectiveReferences internal cache |
@@ -9,5 +9,5 @@ // define the client and server for the persistent daemon that | ||
import { getUrl } from '../get-url.js'; | ||
import { fileExists } from '../ts-sys-cached.js'; | ||
import { getLanguageService } from './language-service.js'; | ||
import { load } from './load.js'; | ||
import { fileExists } from '../ts-sys-cached.js'; | ||
export const serviceName = 'tsimp'; | ||
@@ -14,0 +14,0 @@ export const daemonScript = fileURLToPath(getUrl('./service/daemon.mjs')); |
{ | ||
"name": "tsimp", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"license": "BlueOak-1.0.0", | ||
@@ -70,2 +70,3 @@ "files": [ | ||
"devDependencies": { | ||
"@swc-node/register": "^1.6.8", | ||
"@types/node": "^20.8.4", | ||
@@ -72,0 +73,0 @@ "chalk": "^5.3.0", |
126
README.md
@@ -120,11 +120,2 @@ # tsimp 😈 | ||
### File Extensions, Module Resolution, etc. | ||
The same rules for file extensions, module resolution, and | ||
everything else apply when using `tsimp` as when using `tsc`. | ||
That is, if you're running in ESM mode, you may need to write | ||
your imports ending in `.js` even though the actual file on disk | ||
is `.ts`, because that's how TS does it. | ||
## Configuration | ||
@@ -162,4 +153,4 @@ | ||
"compilerOptions": { | ||
"sourceMap": true, | ||
"skipLibCheck": true | ||
"skipLibCheck": true, | ||
"strict": false | ||
} | ||
@@ -173,4 +164,18 @@ } | ||
## `"module"` and `"moduleResolution"` | ||
### Config File Changes and `extends` Options | ||
If the `tsconfig.json` file used by tsimp changes, then it will | ||
automatically expire its memory and disk caches, because new | ||
options can result in very different results. | ||
However, while `extends` is fully supported (if `tsc` can load | ||
it, so can `tsimp`, because that's how it loads config), any | ||
extended config files will _not_ be tracked for changes or cause | ||
the cache to expire. | ||
When in doubt, `tsimp --restart` will reload everything as | ||
needed. | ||
### `"module"`, `"moduleResolution"`, and other must-haves | ||
The ultimate resulting module style for tsimp _must_ be something | ||
@@ -184,4 +189,34 @@ intelligible by Node, without any additional bundling or | ||
## Compilation Diagnostics | ||
Also, the following fields are always hard-coded by tsimp: | ||
- `outDir` Because tsimp isn't a build tool, but rather a module | ||
importer, it doesn't actually write the emitted JavaScript to | ||
disk. (Ok, technically it does, but only as a cache.) So, the | ||
`outDir` is hard-coded to `.tsimp-compiled`, but this is never | ||
used. | ||
- `sourceMap` This is always set to `undefined`, because: | ||
- `inlineSourceMap` is always set to `true`. It's just much | ||
simpler and faster to have the sourcemap inline with the | ||
generated JavaScript output. | ||
- `inlineSources` is always set to `false`. There is no need to | ||
bloat the output, when the input is definitely present on disk. | ||
- `declarationMap` and `declaration` are always set to `false`, | ||
because type declarations are not relevant. | ||
- `noEmit` is always set `false`, because the entire point is to | ||
get the JavaScript code for Node to run. That said, the "emit" | ||
is fully virtual, and nothing is written to disk (except to | ||
avoid compiling the same code multiple times). | ||
### File Extensions, Module Resolution, etc. | ||
The same rules for file extensions, module resolution, and | ||
everything else apply when using `tsimp` as when using `tsc`. | ||
That means: if you're running in ESM mode, you need to write your | ||
imports ending in `.js` even though the actual file on disk is | ||
`.ts`, because that's how TS does it when `module` is set to | ||
`"NodeNext"` and the target dialect is ESM. | ||
### Compilation Diagnostics | ||
Set the `TSIMP_DIAG` environment variable to control what happens | ||
@@ -197,1 +232,66 @@ when there are compilation diagnostics. | ||
option.) | ||
## How fast is it? | ||
If the daemon is running, it's very fast, even if type checking | ||
is enabled. If the daemon is running and its previously compiled | ||
the file you're running, it's _zomg extremely_ fast, like "so fast | ||
you'll think it's broken" fast, outperforming TypeScript | ||
compilers written in Rust and Go, since it literally doesn't have | ||
to do anything except check some file stats and then hand the | ||
cached results to Node. (In fact, since it caches in memory as | ||
well as to disk, it might even be _faster_ in many cases than | ||
running plain old JavaScript, if the program is large.) | ||
And, this is with full type checking, which is sort of the point | ||
of using TypeScript. No matter how fast your compiler is, if | ||
you're then running `tsc --noEmit` to check your types, then it's | ||
not actually gaining much. | ||
If the daemon is _not_ running, and it's a cold start with no | ||
cache, it's pretty slow, comparable with ts-node, especially if | ||
type checking is enabled. | ||
An exceptionally not scientific example comparison: | ||
<pre style="color:#eeeeee;background:#222222;position:relative" title="tapjs/tsimp main - tapjs/tsimp"> | ||
$ time node --loader @swc-node/register/esm hello.ts | ||
(node:89220) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`: | ||
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("%40swc-node/register/esm", pathToFileURL("./"));' | ||
(Use `node --trace-warnings ...` to show where the warning was created) | ||
hello, world | ||
real 0m0.268s | ||
user 0m0.255s | ||
sys 0m0.033s | ||
$ time node --import=tsx hello.ts | ||
hello, world | ||
real 0m0.135s | ||
user 0m0.126s | ||
sys 0m0.020s | ||
$ time node --import=./dist/esm/hooks/import.mjs hello.ts | ||
<span style="color:#00ffff">hello.ts</span>:<span style="color:#ffff00">2</span>:<span style="color:#ffff00">18</span> - <span style="color:#ff3030">error</span><span style="color:#404040"> TS2322: </span>Type 'string' is not assignable to type 'boolean'. | ||
<span style="color:#222222;background:#eeeeee">2</span> const f: Foo = { bar: 'hello' } | ||
<span style="color:#222222;background:#eeeeee"> </span> <span style="color:#ff3030"> ~~~ | ||
</span> <span style="color:#00ffff">hello.ts</span>:<span style="color:#ffff00">1</span>:<span style="color:#ffff00">14 | ||
</span> <span style="color:#222222;background:#eeeeee">1</span> type Foo = { bar: boolean } | ||
<span style="color:#222222;background:#eeeeee"> </span> <span style="color:#00ffff"> ~~~ | ||
</span> The expected type comes from property 'bar' which is declared here on type 'Foo' | ||
hello, world | ||
real 0m0.126s | ||
user 0m0.110s | ||
sys 0m0.022s | ||
</pre> | ||
## How is it so fast? | ||
![meme comic "We need this to run faster" "rewrite it in rust" "rewrite it in zig" "use basic caching and work skipping" guy gets thrown out window](https://github.com/tapjs/tsimp/raw/main/faster.jpg) | ||
Basic caching and work skipping. |
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
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
373541
2992
293
11