@titanpl/packet 7.0.1 → 7.0.4

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/index.js CHANGED
@@ -67,15 +67,6 @@ export async function build(root = process.cwd()) {
67
67
  outDir: dist,
68
68
  });
69
69
 
70
- const tanfigPath = path.join(root, "tanfig.json");
71
- if (fs.existsSync(tanfigPath)) {
72
- fs.copyFileSync(tanfigPath, path.join(dist, "tanfig.json"));
73
- }
74
- const titanExtPath = path.join(root, "titan.json");
75
- if (fs.existsSync(titanExtPath)) {
76
- fs.copyFileSync(titanExtPath, path.join(dist, "titan.json"));
77
- }
78
-
79
70
  return dist;
80
71
  }
81
72
 
@@ -133,7 +124,7 @@ export async function release(root = process.cwd()) {
133
124
  copyDir(dist, path.join(buildDir, "dist"));
134
125
 
135
126
  // Step 6: Copy essential config files (mandatory for runtime)
136
- const essentials = ["package.json", "tanfig.json", "titan.json"];
127
+ const essentials = ["package.json", "tanfig.json", "titan.json", "t.env", ".env"];
137
128
  for (const f of essentials) {
138
129
  const src = path.join(root, f);
139
130
  if (fs.existsSync(src)) {
@@ -43,6 +43,15 @@ export async function buildMetadata(root, dist) {
43
43
  JSON.stringify(actionMap, null, 2)
44
44
  );
45
45
 
46
+ // Sync essential files to dist (needed for runtime path resolution & env)
47
+ const essentials = ["package.json", "tanfig.json", "titan.json", "t.env", ".env"];
48
+ for (const f of essentials) {
49
+ const src = path.join(root, f);
50
+ if (fs.existsSync(src)) {
51
+ fs.copyFileSync(src, path.join(dist, f));
52
+ }
53
+ }
54
+
46
55
  } catch (err) {
47
56
  console.error("\x1b[31m❌ Failed to parse routes from app.js\x1b[0m", err);
48
57
  process.exit(1);
@@ -33,6 +33,29 @@ const NODE_BUILTIN_MAP = {
33
33
  "node:util": "@titanpl/node/util",
34
34
  };
35
35
 
36
+ const createTitanRootResolverPlugin = (root) => {
37
+ return {
38
+ name: "titan-root-resolver",
39
+ setup(build) {
40
+ // Handle paths starting with ./ or ../ manually to check root first if needed
41
+ build.onResolve({ filter: /^\.\.?\// }, args => {
42
+ const potentialPath = path.join(root, args.path.replace(/^\.\//, ''));
43
+ if (fs.existsSync(potentialPath)) {
44
+ return { path: potentialPath };
45
+ }
46
+ // Fallback to default
47
+ return null;
48
+ });
49
+
50
+ // Special handling for paths that looks like project folders
51
+ const projectFolders = ['app', 'config', 'db', 'public', 'static', 'views', 'auth'];
52
+ build.onResolve({ filter: new RegExp(`^(${projectFolders.join('|')})(\\/|$)`) }, args => {
53
+ return { path: path.join(root, args.path) };
54
+ });
55
+ }
56
+ };
57
+ };
58
+
36
59
  const createTitanNodeCompatPlugin = (root) => {
37
60
  const rootRequire = createRequire(path.join(root, 'package.json'));
38
61
 
@@ -99,6 +122,7 @@ export async function bundleFile(options) {
99
122
  if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
100
123
 
101
124
  try {
125
+ const root = options.root || process.cwd();
102
126
  const result = await esbuild.build({
103
127
  entryPoints: [entryPoint],
104
128
  bundle: true,
@@ -108,7 +132,20 @@ export async function bundleFile(options) {
108
132
  platform: 'node',
109
133
  target,
110
134
  logLevel: 'silent',
111
- plugins: [createTitanNodeCompatPlugin(options.root || process.cwd())],
135
+ absWorkingDir: root,
136
+ plugins: [
137
+ createTitanRootResolverPlugin(root),
138
+ createTitanNodeCompatPlugin(root)
139
+ ],
140
+ alias: {
141
+ "app": path.join(root, "app"),
142
+ "config": path.join(root, "config"),
143
+ "db": path.join(root, "db"),
144
+ "public": path.join(root, "public"),
145
+ "static": path.join(root, "static"),
146
+ "views": path.join(root, "views"),
147
+ "auth": path.join(root, "auth"),
148
+ },
112
149
  banner: { js: "var Titan = t;" },
113
150
  footer: options.footer || {}
114
151
  });
package/js/titan/dev.js CHANGED
@@ -208,8 +208,9 @@ export async function dev(options) {
208
208
  // Watch for changes inside app/
209
209
  const appDir = path.join(root, "app");
210
210
  const envFile = path.join(root, ".env");
211
+ const tEnvFile = path.join(root, "t.env");
211
212
 
212
- const watcher = chokidar.watch([appDir, envFile], {
213
+ const watcher = chokidar.watch([appDir, envFile, tEnvFile], {
213
214
  ignoreInitial: true,
214
215
  awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 }
215
216
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/packet",
3
- "version": "7.0.1",
3
+ "version": "7.0.4",
4
4
  "description": "The bundler for TitanPl servers.",
5
5
  "keywords": [
6
6
  "bundler",
@@ -67,6 +67,15 @@ export async function buildMetadata(root, dist) {
67
67
  JSON.stringify(actionMap, null, 2)
68
68
  );
69
69
 
70
+ // Sync essential files to dist (needed for runtime path resolution & env)
71
+ const essentials = ["package.json", "tanfig.json", "titan.json", "t.env", ".env"];
72
+ for (const f of essentials) {
73
+ const src = path.join(root, f);
74
+ if (fs.existsSync(src)) {
75
+ fs.copyFileSync(src, path.join(dist, f));
76
+ }
77
+ }
78
+
70
79
  } catch (err) {
71
80
  console.error("\x1b[31m❌ Failed to parse routes from application logic\x1b[0m", err);
72
81
  process.exit(1);
@@ -34,6 +34,29 @@ const NODE_BUILTIN_MAP = {
34
34
  "node:util": "@titanpl/node/util",
35
35
  };
36
36
 
37
+ const createTitanRootResolverPlugin = (root) => {
38
+ return {
39
+ name: "titan-root-resolver",
40
+ setup(build) {
41
+ // Handle paths starting with ./ or ../ manually to check root first if needed
42
+ build.onResolve({ filter: /^\.\.?\// }, args => {
43
+ const potentialPath = path.join(root, args.path.replace(/^\.\//, ''));
44
+ if (fs.existsSync(potentialPath)) {
45
+ return { path: potentialPath };
46
+ }
47
+ // Fallback to default
48
+ return null;
49
+ });
50
+
51
+ // Special handling for paths that looks like project folders
52
+ const projectFolders = ['app', 'config', 'db', 'public', 'static', 'views', 'auth'];
53
+ build.onResolve({ filter: new RegExp(`^(${projectFolders.join('|')})(\\/|$)`) }, args => {
54
+ return { path: path.join(root, args.path) };
55
+ });
56
+ }
57
+ };
58
+ };
59
+
37
60
  const createTitanNodeCompatPlugin = (root) => {
38
61
  const rootRequire = createRequire(path.join(root, 'package.json'));
39
62
 
@@ -143,6 +166,7 @@ export async function bundleFile(options) {
143
166
  if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
144
167
 
145
168
  try {
169
+ const root = options.root || process.cwd();
146
170
  const result = await esbuild.build({
147
171
  entryPoints: [entryPoint],
148
172
  bundle: true,
@@ -152,7 +176,20 @@ export async function bundleFile(options) {
152
176
  platform: 'node',
153
177
  target,
154
178
  logLevel: 'silent',
155
- plugins: [createTitanNodeCompatPlugin(options.root || process.cwd())],
179
+ absWorkingDir: root,
180
+ plugins: [
181
+ createTitanRootResolverPlugin(root),
182
+ createTitanNodeCompatPlugin(root)
183
+ ],
184
+ alias: {
185
+ "app": path.join(root, "app"),
186
+ "config": path.join(root, "config"),
187
+ "db": path.join(root, "db"),
188
+ "public": path.join(root, "public"),
189
+ "static": path.join(root, "static"),
190
+ "views": path.join(root, "views"),
191
+ "auth": path.join(root, "auth"),
192
+ },
156
193
  banner: { js: "var Titan = t;" },
157
194
  footer: options.footer || {}
158
195
  });
package/ts/titan/dev.js CHANGED
@@ -209,9 +209,10 @@ export async function dev(options) {
209
209
  // Watch for changes inside app/
210
210
  const appDir = path.join(root, "app");
211
211
  const envFile = path.join(root, ".env");
212
+ const tEnvFile = path.join(root, "t.env");
212
213
  const tsConfig = path.join(root, "tsconfig.json");
213
214
 
214
- const watcher = chokidar.watch([appDir, envFile, tsConfig], {
215
+ const watcher = chokidar.watch([appDir, envFile, tEnvFile, tsConfig], {
215
216
  ignoreInitial: true,
216
217
  awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 }
217
218
  });