@tnldotdev/tnl 0.1.0-rc.15 → 0.1.0-rc.20
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/NOTICE +6 -0
- package/README.md +176 -14
- package/THIRD_PARTY_LICENSES.txt +6597 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +4 -0
- package/dist/internal/dev.d.ts +41 -0
- package/dist/internal/dev.js +387 -0
- package/dist/internal/runtime.d.ts +22 -0
- package/dist/internal/runtime.js +118 -0
- package/dist/next.d.ts +10 -0
- package/dist/next.js +75 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.js +98 -0
- package/lib/config.d.ts +69 -0
- package/lib/config.mjs +3 -0
- package/lib/launcher.mjs +7 -6
- package/lib/native-targets.mjs +12 -0
- package/package.json +57 -9
package/dist/vite.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { canonicalLoopbackTarget, readDevelopmentContext, registerLocalTarget, requestTunnelAssignment, runtimePayload, } from "./internal/dev.js";
|
|
2
|
+
const runtimeDefineName = "process.env.TNL_PROJECT_RUNTIME";
|
|
3
|
+
/** Adds tnl project metadata and safe `tnl dev` routing to a Vite development server. */
|
|
4
|
+
export default function tnl(...arguments_) {
|
|
5
|
+
if (arguments_.length !== 0) {
|
|
6
|
+
throw new Error("tnl() does not accept tunnel options; use project configuration");
|
|
7
|
+
}
|
|
8
|
+
let assignment = null;
|
|
9
|
+
let localPortRegistered = false;
|
|
10
|
+
return {
|
|
11
|
+
name: "tnl",
|
|
12
|
+
enforce: "post",
|
|
13
|
+
apply: "serve",
|
|
14
|
+
async config(userConfig = {}, configEnvironment) {
|
|
15
|
+
assignment = null;
|
|
16
|
+
localPortRegistered = false;
|
|
17
|
+
if (configEnvironment.command !== "serve" || configEnvironment.isPreview === true) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const development = readDevelopmentContext();
|
|
21
|
+
if (development.bootstrap === null) {
|
|
22
|
+
if (development.localProject === null) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
return runtimeDefine(runtimePayload(development.localProject, false));
|
|
26
|
+
}
|
|
27
|
+
const server = userConfig.server ?? {};
|
|
28
|
+
validateAllowedHosts(server.allowedHosts);
|
|
29
|
+
assignment = await requestTunnelAssignment("vite", development.bootstrap);
|
|
30
|
+
const result = {
|
|
31
|
+
...runtimeDefine(runtimePayload(assignment.project, true)),
|
|
32
|
+
server: {
|
|
33
|
+
allowedHosts: addAllowedHost(server.allowedHosts, assignment.hostname),
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
if (development.bootstrap.port === undefined) {
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
...result,
|
|
41
|
+
server: {
|
|
42
|
+
...result.server,
|
|
43
|
+
port: development.bootstrap.port,
|
|
44
|
+
// Let Vite report a fallback listener so tnl can reject it with the target diagnostic.
|
|
45
|
+
strictPort: false,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
configureServer(server) {
|
|
50
|
+
const configured = assignment;
|
|
51
|
+
if (configured === null) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (server.httpServer === null) {
|
|
55
|
+
throw new Error("Vite middleware mode cannot register a listening target with tnl dev");
|
|
56
|
+
}
|
|
57
|
+
const originalListen = server.listen.bind(server);
|
|
58
|
+
server.listen = async (port, isRestart) => {
|
|
59
|
+
const listening = await originalListen(port, isRestart);
|
|
60
|
+
if (localPortRegistered) {
|
|
61
|
+
return listening;
|
|
62
|
+
}
|
|
63
|
+
const address = server.httpServer?.address();
|
|
64
|
+
if (address === null || address === undefined || typeof address === "string") {
|
|
65
|
+
await server.close();
|
|
66
|
+
throw new Error("Vite did not report its listening port to tnl dev");
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
await registerLocalTarget(configured, canonicalLoopbackTarget(address.address, address.port));
|
|
70
|
+
localPortRegistered = true;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
await server.close();
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
return listening;
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function runtimeDefine(payload) {
|
|
82
|
+
return {
|
|
83
|
+
define: {
|
|
84
|
+
[runtimeDefineName]: JSON.stringify(payload),
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function addAllowedHost(allowedHosts, hostname) {
|
|
89
|
+
if (allowedHosts === true) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return [...new Set([...(allowedHosts ?? []), hostname])];
|
|
93
|
+
}
|
|
94
|
+
function validateAllowedHosts(value) {
|
|
95
|
+
if (value !== undefined && value !== true && !Array.isArray(value)) {
|
|
96
|
+
throw new Error("Vite server.allowedHosts must be an array or true when used with tnl");
|
|
97
|
+
}
|
|
98
|
+
}
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export interface TNL {
|
|
2
|
+
server?: string;
|
|
3
|
+
team?: string;
|
|
4
|
+
tunnel?: {
|
|
5
|
+
host?: string;
|
|
6
|
+
subdomain?: string;
|
|
7
|
+
public?: boolean;
|
|
8
|
+
ephemeral?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* @maxItems 63
|
|
11
|
+
*/
|
|
12
|
+
allowIP?: string[];
|
|
13
|
+
};
|
|
14
|
+
publish?: Publish;
|
|
15
|
+
dev?: Dev;
|
|
16
|
+
services?: {
|
|
17
|
+
[k: string]: {
|
|
18
|
+
directory?: string;
|
|
19
|
+
server?: string;
|
|
20
|
+
team?: string;
|
|
21
|
+
tunnel?: {
|
|
22
|
+
host?: string;
|
|
23
|
+
subdomain?: string;
|
|
24
|
+
public?: boolean;
|
|
25
|
+
ephemeral?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* @maxItems 63
|
|
28
|
+
*/
|
|
29
|
+
allowIP?: string[];
|
|
30
|
+
};
|
|
31
|
+
publish?: Publish;
|
|
32
|
+
dev?: Dev;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface Publish {
|
|
37
|
+
target?: string | number;
|
|
38
|
+
}
|
|
39
|
+
export interface Dev {
|
|
40
|
+
/**
|
|
41
|
+
* @minItems 1
|
|
42
|
+
*/
|
|
43
|
+
command?: [string, ...string[]];
|
|
44
|
+
port?: number;
|
|
45
|
+
startupTimeout?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Details about the Git worktree or project directory containing tnl.config.ts. */
|
|
49
|
+
export interface TnlWorktree {
|
|
50
|
+
readonly isGit: boolean;
|
|
51
|
+
/** DNS-safe name keyed to this worktree and client state directory. */
|
|
52
|
+
readonly label: string;
|
|
53
|
+
readonly name: string;
|
|
54
|
+
readonly root: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Values available to a tnl.config.ts configuration factory. */
|
|
58
|
+
export interface TnlConfigContext {
|
|
59
|
+
readonly cwd: string;
|
|
60
|
+
readonly env: Readonly<Record<string, string>>;
|
|
61
|
+
readonly worktree: TnlWorktree;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type TnlConfigFactory = (context: TnlConfigContext) => TNL | Promise<TNL>;
|
|
65
|
+
|
|
66
|
+
export type TnlConfigInput = TNL | TnlConfigFactory;
|
|
67
|
+
|
|
68
|
+
/** Provides type checking for an implicit-version-1 tnl.config.ts configuration. */
|
|
69
|
+
export declare function defineConfig<const Config extends TnlConfigInput>(config: Config): Config;
|
package/lib/config.mjs
ADDED
package/lib/launcher.mjs
CHANGED
|
@@ -2,16 +2,17 @@ import { constants, accessSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import process from "node:process";
|
|
5
|
+
import { nativeTargets } from "./native-targets.mjs";
|
|
5
6
|
|
|
6
7
|
const require = createRequire(import.meta.url);
|
|
7
8
|
const launcherManifest = new URL("../package.json", import.meta.url);
|
|
8
9
|
|
|
9
|
-
const nativePackages = new Map(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const nativePackages = new Map(
|
|
11
|
+
nativeTargets.map(({ platform, architecture, packageName }) => [
|
|
12
|
+
`${platform}-${architecture}`,
|
|
13
|
+
packageName,
|
|
14
|
+
]),
|
|
15
|
+
);
|
|
15
16
|
|
|
16
17
|
export function nativePackageName(platform, architecture) {
|
|
17
18
|
const packageName = nativePackages.get(`${platform}-${architecture}`);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Internal distribution catalog shared by the launcher and release scripts.
|
|
2
|
+
* Node architecture names belong here; Go artifact paths and versions do not.
|
|
3
|
+
* Entries retain native publish order. This module is not a public package export.
|
|
4
|
+
*/
|
|
5
|
+
export const nativeTargets = Object.freeze(
|
|
6
|
+
[
|
|
7
|
+
{ platform: "darwin", architecture: "arm64", packageName: "@tnldotdev/tnl-darwin-arm64" },
|
|
8
|
+
{ platform: "darwin", architecture: "x64", packageName: "@tnldotdev/tnl-darwin-x64" },
|
|
9
|
+
{ platform: "linux", architecture: "arm64", packageName: "@tnldotdev/tnl-linux-arm64" },
|
|
10
|
+
{ platform: "linux", architecture: "x64", packageName: "@tnldotdev/tnl-linux-x64" },
|
|
11
|
+
].map((target) => Object.freeze(target)),
|
|
12
|
+
);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tnldotdev/tnl",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
4
|
-
"description": "The tnl client for project-local development
|
|
3
|
+
"version": "0.1.0-rc.20",
|
|
4
|
+
"description": "The tnl client and framework integrations for project-local development.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -13,22 +13,70 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"bin",
|
|
16
|
-
"
|
|
16
|
+
"dist",
|
|
17
|
+
"lib",
|
|
18
|
+
"NOTICE",
|
|
19
|
+
"THIRD_PARTY_LICENSES.txt"
|
|
17
20
|
],
|
|
18
21
|
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./config": {
|
|
30
|
+
"types": "./lib/config.d.ts",
|
|
31
|
+
"import": "./lib/config.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./next": {
|
|
34
|
+
"types": "./dist/next.d.ts",
|
|
35
|
+
"import": "./dist/next.js",
|
|
36
|
+
"default": "./dist/next.js"
|
|
37
|
+
},
|
|
38
|
+
"./vite": {
|
|
39
|
+
"types": "./dist/vite.d.ts",
|
|
40
|
+
"import": "./dist/vite.js",
|
|
41
|
+
"default": "./dist/vite.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
19
44
|
"publishConfig": {
|
|
20
45
|
"access": "public"
|
|
21
46
|
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "pnpm run clean && tsc --project tsconfig.json",
|
|
49
|
+
"clean": "node ../../scripts/clean-package.mjs",
|
|
50
|
+
"prepack": "pnpm run build"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"next": "16.3.4",
|
|
54
|
+
"react": "19.2.8",
|
|
55
|
+
"react-dom": "19.2.8",
|
|
56
|
+
"vite": "8.2.2"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"next": ">=16.3.4",
|
|
60
|
+
"vite": ">=6.0.9"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"next": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"vite": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
22
70
|
"engines": {
|
|
23
|
-
"node": ">=22.
|
|
71
|
+
"node": ">=22.18"
|
|
24
72
|
},
|
|
25
73
|
"optionalDependencies": {
|
|
26
|
-
"@tnldotdev/tnl-darwin-arm64": "0.1.0-rc.
|
|
27
|
-
"@tnldotdev/tnl-darwin-x64": "0.1.0-rc.
|
|
28
|
-
"@tnldotdev/tnl-linux-arm64": "0.1.0-rc.
|
|
29
|
-
"@tnldotdev/tnl-linux-x64": "0.1.0-rc.
|
|
74
|
+
"@tnldotdev/tnl-darwin-arm64": "0.1.0-rc.20",
|
|
75
|
+
"@tnldotdev/tnl-darwin-x64": "0.1.0-rc.20",
|
|
76
|
+
"@tnldotdev/tnl-linux-arm64": "0.1.0-rc.20",
|
|
77
|
+
"@tnldotdev/tnl-linux-x64": "0.1.0-rc.20"
|
|
30
78
|
},
|
|
31
79
|
"tnl": {
|
|
32
|
-
"commit": "
|
|
80
|
+
"commit": "a2073944387d90f6b7a83ec28a409964b06a28a7"
|
|
33
81
|
}
|
|
34
82
|
}
|