@titanpl/packet 4.0.0 → 4.0.2

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.
@@ -33,20 +33,32 @@ const NODE_BUILTIN_MAP = {
33
33
  "node:util": "@titanpl/node/util",
34
34
  };
35
35
 
36
- const titanNodeCompatPlugin = {
37
- name: "titan-node-compat",
38
- setup(build) {
39
- build.onResolve({ filter: /.*/ }, args => {
40
- if (NODE_BUILTIN_MAP[args.path]) {
41
- try {
42
- const resolved = require.resolve(NODE_BUILTIN_MAP[args.path]);
43
- return { path: resolved };
44
- } catch (e) {
45
- throw new Error(`[TitanPL] Failed to resolve Node shim: ${NODE_BUILTIN_MAP[args.path]}`);
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: [titanNodeCompatPlugin],
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/packet",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "The bundler for TitanPl servers.",
5
5
  "keywords": [
6
6
  "bundler",
@@ -34,20 +34,32 @@ const NODE_BUILTIN_MAP = {
34
34
  "node:util": "@titanpl/node/util",
35
35
  };
36
36
 
37
- const titanNodeCompatPlugin = {
38
- name: "titan-node-compat",
39
- setup(build) {
40
- build.onResolve({ filter: /.*/ }, args => {
41
- if (NODE_BUILTIN_MAP[args.path]) {
42
- try {
43
- const resolved = require.resolve(NODE_BUILTIN_MAP[args.path]);
44
- return { path: resolved };
45
- } catch (e) {
46
- throw new Error(`[TitanPL] Failed to resolve Node shim: ${NODE_BUILTIN_MAP[args.path]}`);
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: [titanNodeCompatPlugin],
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: {