lapeh 2.3.2 → 2.3.3

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 +80 -3
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -55,9 +55,86 @@ function runDev() {
55
55
 
56
56
  function runStart() {
57
57
  console.log('🚀 Starting Lapeh production server...');
58
- const distPath = path.join(process.cwd(), 'dist/lib/bootstrap.js');
59
- // For production, we assume built files
60
- const cmd = `node -e "require('${distPath.replace(/\\/g, '/')}').bootstrap()"`;
58
+
59
+ // In framework-as-dependency model, the bootstrap logic is inside node_modules/lapeh/dist/lib/bootstrap.js
60
+ // But wait, the user's project is compiled to `dist/` in their project root.
61
+ // The user's `dist` folder will contain their compiled code (src/*).
62
+ // But where is the framework code?
63
+ // 1. If user builds their project, they build `src` -> `dist/src`.
64
+ // 2. The framework code resides in `node_modules/lapeh/dist` (if lapeh is installed as dependency) OR `node_modules/lapeh/lib` (if ts-node).
65
+
66
+ // We need to resolve where `bootstrap` is.
67
+ // Since we are running `lapeh start` from the CLI package itself.
68
+
69
+ let bootstrapPath;
70
+ try {
71
+ // Try to resolve from the project's node_modules
72
+ const projectNodeModules = path.join(process.cwd(), 'node_modules');
73
+ const lapehDist = path.join(projectNodeModules, 'lapeh', 'dist', 'lib', 'bootstrap.js');
74
+ const lapehLib = path.join(projectNodeModules, 'lapeh', 'lib', 'bootstrap.js');
75
+
76
+ if (fs.existsSync(lapehDist)) {
77
+ bootstrapPath = lapehDist;
78
+ } else if (fs.existsSync(lapehLib)) {
79
+ // Fallback to lib if dist doesn't exist (e.g. in dev environment or simple install)
80
+ // But `start` implies production, so we should prefer compiled JS.
81
+ // If lapeh package.json "main" points to index.js (in root) or lib/bootstrap.ts?
82
+ // Actually, for `start` we usually run `node dist/src/index.js` or similar?
83
+ // No, Lapeh framework entry point is `bootstrap()`.
84
+
85
+ // Let's rely on `require.resolve` relative to the CWD
86
+ // We want to require 'lapeh/lib/bootstrap' or 'lapeh/dist/lib/bootstrap'
87
+
88
+ // If we are in `node_modules/lapeh/bin/index.js`, `..` is `node_modules/lapeh`.
89
+ // So we can require('../lib/bootstrap') directly?
90
+ // Yes, if we are running the CLI from the installed package.
91
+ bootstrapPath = path.resolve(__dirname, '../lib/bootstrap.js');
92
+ if (!fs.existsSync(bootstrapPath)) {
93
+ // Try typescript source? No, production run shouldn't use TS.
94
+ bootstrapPath = path.resolve(__dirname, '../dist/lib/bootstrap.js');
95
+ }
96
+ }
97
+
98
+ // Correct approach:
99
+ // The CLI is running. We want to execute the bootstrap function.
100
+ // We can import it right here in this process!
101
+ // But `runStart` is inside `bin/index.js` which is likely a JS file.
102
+ // We can require('../lib/bootstrap') or '../dist/lib/bootstrap'.
103
+
104
+ const frameworkBootstrap = require('../lib/bootstrap');
105
+ frameworkBootstrap.bootstrap();
106
+ return; // Exit this function, let the bootstrap take over
107
+
108
+ } catch (e) {
109
+ // If direct require fails (maybe because of ESM/CJS mix or path issues), fallback to child process
110
+ }
111
+
112
+ // Fallback to previous logic if direct require fails, but fixed path
113
+ // The error showed: '.../dist/lib/bootstrap.js' not found.
114
+ // Because `lapeh` package structure might be:
115
+ // lapeh/
116
+ // bin/index.js
117
+ // lib/bootstrap.ts (and compiled .js?)
118
+ // package.json
119
+
120
+ // If we are running from `bin/index.js`, the bootstrap is at `../lib/bootstrap.js` (if compiled) or we need to compile it?
121
+ // "lapeh" framework is usually shipped as JS.
122
+
123
+ const possiblePaths = [
124
+ path.join(__dirname, '../lib/bootstrap.js'),
125
+ path.join(__dirname, '../dist/lib/bootstrap.js'),
126
+ path.join(process.cwd(), 'node_modules/lapeh/lib/bootstrap.js')
127
+ ];
128
+
129
+ bootstrapPath = possiblePaths.find(p => fs.existsSync(p));
130
+
131
+ if (!bootstrapPath) {
132
+ console.error('❌ Could not find Lapeh bootstrap file.');
133
+ console.error(' Searched in:', possiblePaths);
134
+ process.exit(1);
135
+ }
136
+
137
+ const cmd = `node -e "require('${bootstrapPath.replace(/\\/g, '/')}').bootstrap()"`;
61
138
  execSync(cmd, {
62
139
  stdio: 'inherit',
63
140
  env: { ...process.env, NODE_ENV: 'production' }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapeh",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "description": "Framework API Express yang siap pakai (Standardized)",
5
5
  "main": "index.js",
6
6
  "bin": {