ts-node-pack 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/index.js +10 -16
- package/src/rewrite-specifiers.d.ts +1 -1
- package/src/rewrite-specifiers.js +1 -1
- package/src/validation.js +1 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-node-pack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Pack a TypeScript package into a Node-compatible npm tarball without modifying the source tree",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
".": "./src/index.js"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"amaro": "^0.3.2",
|
|
31
|
+
"npm-packlist": "^10.0.4"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=20"
|
|
35
35
|
},
|
|
36
|
-
"packageManager": "pnpm@
|
|
36
|
+
"packageManager": "pnpm@11.1.2",
|
|
37
37
|
"types": "./src/index.d.ts"
|
|
38
38
|
}
|
package/src/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { tmpdir } from "node:os";
|
|
|
14
14
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
15
15
|
import { promisify } from "node:util";
|
|
16
16
|
import packlist from "npm-packlist";
|
|
17
|
-
import
|
|
17
|
+
import { transformSync } from "amaro";
|
|
18
18
|
import { rewriteTsSpecifiers } from "./rewrite-specifiers.js";
|
|
19
19
|
import { validate } from "./validation.js";
|
|
20
20
|
|
|
@@ -173,7 +173,7 @@ export async function tsNodePack(
|
|
|
173
173
|
rootDir: packageDir,
|
|
174
174
|
outDir: stagingDir,
|
|
175
175
|
declaration: true,
|
|
176
|
-
//
|
|
176
|
+
// amaro handles .js emit (Phase 6); tsc only emits .d.ts.
|
|
177
177
|
emitDeclarationOnly: true,
|
|
178
178
|
// Extract types from JS+JSDoc sources in mixed packages.
|
|
179
179
|
allowJs: true,
|
|
@@ -201,10 +201,10 @@ export async function tsNodePack(
|
|
|
201
201
|
|
|
202
202
|
// ── Phase 6: Strip types and rewrite specifiers ─────────────────────
|
|
203
203
|
// Single-pass transform of every staging file that could contain a
|
|
204
|
-
// relative module specifier: .ts/.mts get
|
|
204
|
+
// relative module specifier: .ts/.mts get type-stripped then
|
|
205
205
|
// specifier-rewritten (one read, one write, original unlinked);
|
|
206
206
|
// .js/.mjs/.d.ts/.d.mts just get specifier-rewritten in place.
|
|
207
|
-
//
|
|
207
|
+
// amaro preserves line and column positions, so no
|
|
208
208
|
// sourcemaps are needed for debugging.
|
|
209
209
|
log("Phase 6: Stripping types and rewriting specifiers...");
|
|
210
210
|
const { strippedCount, rewrittenCount } = await processStagingFiles(stagingDir, log);
|
|
@@ -348,7 +348,7 @@ async function runTsc(emitConfigPath, cwd, log) {
|
|
|
348
348
|
* changed, written once. Sourcemap files (.d.ts.map, .d.mts.map) are
|
|
349
349
|
* skipped because they're binary-encoded JSON with no specifiers.
|
|
350
350
|
*
|
|
351
|
-
* Throws if
|
|
351
|
+
* Throws if amaro rejects a .ts/.mts file (non-erasable
|
|
352
352
|
* syntax like `enum`, `namespace`, or parameter properties).
|
|
353
353
|
*/
|
|
354
354
|
async function processStagingFiles(stagingDir, log) {
|
|
@@ -372,16 +372,10 @@ async function processStagingFiles(stagingDir, log) {
|
|
|
372
372
|
|
|
373
373
|
let content = source;
|
|
374
374
|
if (isTs || isMts) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
);
|
|
380
|
-
});
|
|
381
|
-
if (errors.length > 0) {
|
|
382
|
-
throw new Error(
|
|
383
|
-
"ts-blank-space rejected non-erasable TypeScript:\n " + errors.join("\n "),
|
|
384
|
-
);
|
|
375
|
+
try {
|
|
376
|
+
content = transformSync(source).code;
|
|
377
|
+
} catch (err ) {
|
|
378
|
+
throw new Error(`amaro rejected TypeScript in ${rel}:\n ${err.message}`);
|
|
385
379
|
}
|
|
386
380
|
}
|
|
387
381
|
content = rewriteTsSpecifiers(content);
|
|
@@ -628,7 +622,7 @@ export function rewritePackageJson(pkg) {
|
|
|
628
622
|
return result;
|
|
629
623
|
}
|
|
630
624
|
|
|
631
|
-
// `.ts`/`.tsx` → `.js`; `.mts` → `.mjs`. Matches what
|
|
625
|
+
// `.ts`/`.tsx` → `.js`; `.mts` → `.mjs`. Matches what amaro
|
|
632
626
|
// writes in Phase 6 and the specifier-rewrite pass in rewrite-specifiers.ts.
|
|
633
627
|
function rewriteTsToJs(p) {
|
|
634
628
|
if (typeof p !== "string") return p;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* `../`) ending in `.ts`, `.tsx`, or `.mts`, embedded in one of six
|
|
6
6
|
* specific syntactic contexts. The output replaces the extension with
|
|
7
7
|
* `.js` (for `.ts`/`.tsx`) or `.mjs` (for `.mts`), matching what
|
|
8
|
-
*
|
|
8
|
+
* amaro produces in the type stripping phase.
|
|
9
9
|
*
|
|
10
10
|
* Why regex is sound here:
|
|
11
11
|
*
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* `../`) ending in `.ts`, `.tsx`, or `.mts`, embedded in one of six
|
|
6
6
|
* specific syntactic contexts. The output replaces the extension with
|
|
7
7
|
* `.js` (for `.ts`/`.tsx`) or `.mjs` (for `.mts`), matching what
|
|
8
|
-
*
|
|
8
|
+
* amaro produces in the type stripping phase.
|
|
9
9
|
*
|
|
10
10
|
* Why regex is sound here:
|
|
11
11
|
*
|
package/src/validation.js
CHANGED
|
@@ -8,11 +8,7 @@ import { readdir, readFile } from "node:fs/promises";
|
|
|
8
8
|
import { join, relative } from "node:path";
|
|
9
9
|
import { TS_SPECIFIER_PATTERNS } from "./rewrite-specifiers.js";
|
|
10
10
|
|
|
11
|
-
export async function validate(
|
|
12
|
-
stagingDir,
|
|
13
|
-
pkg,
|
|
14
|
-
log = () => {},
|
|
15
|
-
) {
|
|
11
|
+
export async function validate(stagingDir, pkg, log = () => {}) {
|
|
16
12
|
const errors = [];
|
|
17
13
|
|
|
18
14
|
// Check .js/.mjs and .d.ts/.d.mts files for remaining .ts specifiers
|