lapeh 2.3.4 → 2.3.6

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.
Files changed (2) hide show
  1. package/bin/index.js +46 -6
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -54,7 +54,19 @@ function runDev() {
54
54
  // The path contains spaces "TESTING LAPEH". When passed to `exec`, it might be splitting.
55
55
  // We should quote the paths properly.
56
56
 
57
- const cmd = `npx nodemon --watch src --watch lib --ext ts,json --exec "node -r \\"${tsNodePath}\\" -r \\"${tsConfigPathsPath}\\" \\"${bootstrapPath}\\""`;
57
+ // Windows paths with spaces are tricky.
58
+ // We need to use slightly different quoting strategy or use spawn instead of execSync for better argument handling.
59
+ // However, execSync is simpler for now.
60
+
61
+ // Using simple double quotes around the whole argument for node -r might work better if we escape backslashes?
62
+ // Or just ensure paths are quoted.
63
+
64
+ // Let's try to escape backslashes in paths for the string interpolation
65
+ const safeTsNodePath = tsNodePath.replace(/\\/g, '\\\\');
66
+ const safeTsConfigPathsPath = tsConfigPathsPath.replace(/\\/g, '\\\\');
67
+ const safeBootstrapPath = bootstrapPath.replace(/\\/g, '\\\\');
68
+
69
+ const cmd = `npx nodemon --watch src --watch lib --ext ts,json --exec "node -r \\"${safeTsNodePath}\\" -r \\"${safeTsConfigPathsPath}\\" \\"${safeBootstrapPath}\\""`;
58
70
 
59
71
  execSync(cmd, { stdio: 'inherit' });
60
72
  } catch (error) {
@@ -110,9 +122,34 @@ function runStart() {
110
122
  // But `runStart` is inside `bin/index.js` which is likely a JS file.
111
123
  // We can require('../lib/bootstrap') or '../dist/lib/bootstrap'.
112
124
 
113
- const frameworkBootstrap = require('../lib/bootstrap');
114
- frameworkBootstrap.bootstrap();
115
- return; // Exit this function, let the bootstrap take over
125
+ // IMPORTANT: When running from a user's project, the 'lapeh' package is inside node_modules.
126
+ // So `__dirname` is `.../node_modules/lapeh/bin`.
127
+ // We want `.../node_modules/lapeh/lib/bootstrap.js`.
128
+
129
+ let frameworkBootstrap;
130
+ try {
131
+ frameworkBootstrap = require('../lib/bootstrap');
132
+ } catch (e) {
133
+ try {
134
+ frameworkBootstrap = require('../dist/lib/bootstrap');
135
+ } catch (e2) {
136
+ // Try absolute path resolution from CWD if relative require fails
137
+ // This handles cases where CLI might be symlinked or global
138
+ const cwdNodeModules = path.join(process.cwd(), 'node_modules', 'lapeh');
139
+ if (fs.existsSync(path.join(cwdNodeModules, 'lib/bootstrap.js'))) {
140
+ frameworkBootstrap = require(path.join(cwdNodeModules, 'lib/bootstrap.js'));
141
+ } else if (fs.existsSync(path.join(cwdNodeModules, 'dist/lib/bootstrap.js'))) {
142
+ frameworkBootstrap = require(path.join(cwdNodeModules, 'dist/lib/bootstrap.js'));
143
+ } else {
144
+ throw e;
145
+ }
146
+ }
147
+ }
148
+
149
+ if (frameworkBootstrap) {
150
+ frameworkBootstrap.bootstrap();
151
+ return; // Exit this function, let the bootstrap take over
152
+ }
116
153
 
117
154
  } catch (e) {
118
155
  // If direct require fails (maybe because of ESM/CJS mix or path issues), fallback to child process
@@ -132,7 +169,8 @@ function runStart() {
132
169
  const possiblePaths = [
133
170
  path.join(__dirname, '../lib/bootstrap.js'),
134
171
  path.join(__dirname, '../dist/lib/bootstrap.js'),
135
- path.join(process.cwd(), 'node_modules/lapeh/lib/bootstrap.js')
172
+ path.join(process.cwd(), 'node_modules/lapeh/lib/bootstrap.js'),
173
+ path.join(process.cwd(), 'node_modules/lapeh/dist/lib/bootstrap.js')
136
174
  ];
137
175
 
138
176
  bootstrapPath = possiblePaths.find(p => fs.existsSync(p));
@@ -143,7 +181,9 @@ function runStart() {
143
181
  process.exit(1);
144
182
  }
145
183
 
146
- const cmd = `node -e "require('${bootstrapPath.replace(/\\/g, '/')}').bootstrap()"`;
184
+ // Escape backslashes for Windows paths in the require string
185
+ const safeBootstrapPath = bootstrapPath.replace(/\\/g, '/'); // node require uses forward slashes or escaped backslashes
186
+ const cmd = `node -e "require('${safeBootstrapPath}').bootstrap()"`;
147
187
  execSync(cmd, {
148
188
  stdio: 'inherit',
149
189
  env: { ...process.env, NODE_ENV: 'production' }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapeh",
3
- "version": "2.3.4",
3
+ "version": "2.3.6",
4
4
  "description": "Framework API Express yang siap pakai (Standardized)",
5
5
  "main": "index.js",
6
6
  "bin": {