@titanpl/packet 4.0.1 → 6.0.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/README.md +0 -1
- package/js/titan/bundle.js +27 -14
- package/package.json +1 -1
- package/ts/titan/bundle.js +27 -14
package/README.md
CHANGED
|
@@ -8,4 +8,3 @@ This library parses all your app routes, components, middleware, and logic paths
|
|
|
8
8
|
## How it works
|
|
9
9
|
This package is triggered whenever you run `titan init` or `titan build` from the `@titanpl/cli`. It hooks into tools like `esbuild` to optimize your scripts efficiently. It strips unnecessary pieces out so that only explicit route actions make their way aggressively over to the Titan runtime engine.
|
|
10
10
|
|
|
11
|
-
**Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
|
package/js/titan/bundle.js
CHANGED
|
@@ -33,20 +33,32 @@ const NODE_BUILTIN_MAP = {
|
|
|
33
33
|
"node:util": "@titanpl/node/util",
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
const createTitanNodeCompatPlugin = (root) => {
|
|
37
|
+
const rootRequire = createRequire(path.join(root, 'package.json'));
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
name: "titan-node-compat",
|
|
41
|
+
setup(build) {
|
|
42
|
+
build.onResolve({ filter: /.*/ }, args => {
|
|
43
|
+
if (NODE_BUILTIN_MAP[args.path]) {
|
|
44
|
+
const shimPkg = NODE_BUILTIN_MAP[args.path];
|
|
45
|
+
try {
|
|
46
|
+
// 1. Try to resolve from project root (local node_modules)
|
|
47
|
+
const resolved = rootRequire.resolve(shimPkg);
|
|
48
|
+
return { path: resolved };
|
|
49
|
+
} catch (e) {
|
|
50
|
+
try {
|
|
51
|
+
// 2. Fallback to CLI's own context
|
|
52
|
+
const resolved = require.resolve(shimPkg);
|
|
53
|
+
return { path: resolved };
|
|
54
|
+
} catch (e2) {
|
|
55
|
+
throw new Error(`[TitanPL] Failed to resolve Node shim: ${shimPkg}. Ensure @titanpl/node is installed.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
46
58
|
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
50
62
|
};
|
|
51
63
|
|
|
52
64
|
function getTitanVersion() {
|
|
@@ -96,7 +108,7 @@ export async function bundleFile(options) {
|
|
|
96
108
|
platform: 'node',
|
|
97
109
|
target,
|
|
98
110
|
logLevel: 'silent',
|
|
99
|
-
plugins: [
|
|
111
|
+
plugins: [createTitanNodeCompatPlugin(options.root || process.cwd())],
|
|
100
112
|
banner: { js: "var Titan = t;" },
|
|
101
113
|
footer: options.footer || {}
|
|
102
114
|
});
|
|
@@ -135,6 +147,7 @@ export async function bundle(options = {}) {
|
|
|
135
147
|
|
|
136
148
|
try {
|
|
137
149
|
await bundleFile({
|
|
150
|
+
root,
|
|
138
151
|
entryPoint,
|
|
139
152
|
outfile,
|
|
140
153
|
footer: {
|
package/package.json
CHANGED
package/ts/titan/bundle.js
CHANGED
|
@@ -34,20 +34,32 @@ const NODE_BUILTIN_MAP = {
|
|
|
34
34
|
"node:util": "@titanpl/node/util",
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
const createTitanNodeCompatPlugin = (root) => {
|
|
38
|
+
const rootRequire = createRequire(path.join(root, 'package.json'));
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
name: "titan-node-compat",
|
|
42
|
+
setup(build) {
|
|
43
|
+
build.onResolve({ filter: /.*/ }, args => {
|
|
44
|
+
if (NODE_BUILTIN_MAP[args.path]) {
|
|
45
|
+
const shimPkg = NODE_BUILTIN_MAP[args.path];
|
|
46
|
+
try {
|
|
47
|
+
// 1. Try to resolve from project root (local node_modules)
|
|
48
|
+
const resolved = rootRequire.resolve(shimPkg);
|
|
49
|
+
return { path: resolved };
|
|
50
|
+
} catch (e) {
|
|
51
|
+
try {
|
|
52
|
+
// 2. Fallback to CLI's own context
|
|
53
|
+
const resolved = require.resolve(shimPkg);
|
|
54
|
+
return { path: resolved };
|
|
55
|
+
} catch (e2) {
|
|
56
|
+
throw new Error(`[TitanPL] Failed to resolve Node shim: ${shimPkg}. Ensure @titanpl/node is installed.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
47
59
|
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
51
63
|
};
|
|
52
64
|
|
|
53
65
|
function getTitanVersion() {
|
|
@@ -140,7 +152,7 @@ export async function bundleFile(options) {
|
|
|
140
152
|
platform: 'node',
|
|
141
153
|
target,
|
|
142
154
|
logLevel: 'silent',
|
|
143
|
-
plugins: [
|
|
155
|
+
plugins: [createTitanNodeCompatPlugin(options.root || process.cwd())],
|
|
144
156
|
banner: { js: "var Titan = t;" },
|
|
145
157
|
footer: options.footer || {}
|
|
146
158
|
});
|
|
@@ -198,6 +210,7 @@ export async function bundle(options = {}) {
|
|
|
198
210
|
|
|
199
211
|
try {
|
|
200
212
|
await bundleFile({
|
|
213
|
+
root,
|
|
201
214
|
entryPoint,
|
|
202
215
|
outfile,
|
|
203
216
|
footer: {
|