lapeh 2.3.2 → 2.3.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.
Files changed (2) hide show
  1. package/bin/index.js +91 -5
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
@@ -47,7 +47,16 @@ function runDev() {
47
47
  const bootstrapPath = fs.existsSync(localBootstrapPath) ? localBootstrapPath : fallbackBootstrapPath;
48
48
 
49
49
  // We execute a script that requires ts-node to run lib/bootstrap.ts
50
- execSync(`npx nodemon --watch src --watch lib --ext ts,json --exec "node -r ${tsNodePath} -r ${tsConfigPathsPath} ${bootstrapPath}"`, { stdio: 'inherit' });
50
+ // IMPORTANT: We need to use 'npx' to run nodemon from the project's node_modules,
51
+ // BUT we also need to ensure we use the project's ts-node and tsconfig-paths.
52
+
53
+ // The previous error "Cannot find module 'E:\PROJECT\ANY\2026\TESTING'" suggests an issue with argument parsing or path spaces.
54
+ // The path contains spaces "TESTING LAPEH". When passed to `exec`, it might be splitting.
55
+ // We should quote the paths properly.
56
+
57
+ const cmd = `npx nodemon --watch src --watch lib --ext ts,json --exec "node -r \\"${tsNodePath}\\" -r \\"${tsConfigPathsPath}\\" \\"${bootstrapPath}\\""`;
58
+
59
+ execSync(cmd, { stdio: 'inherit' });
51
60
  } catch (error) {
52
61
  // Ignore error
53
62
  }
@@ -55,9 +64,86 @@ function runDev() {
55
64
 
56
65
  function runStart() {
57
66
  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()"`;
67
+
68
+ // In framework-as-dependency model, the bootstrap logic is inside node_modules/lapeh/dist/lib/bootstrap.js
69
+ // But wait, the user's project is compiled to `dist/` in their project root.
70
+ // The user's `dist` folder will contain their compiled code (src/*).
71
+ // But where is the framework code?
72
+ // 1. If user builds their project, they build `src` -> `dist/src`.
73
+ // 2. The framework code resides in `node_modules/lapeh/dist` (if lapeh is installed as dependency) OR `node_modules/lapeh/lib` (if ts-node).
74
+
75
+ // We need to resolve where `bootstrap` is.
76
+ // Since we are running `lapeh start` from the CLI package itself.
77
+
78
+ let bootstrapPath;
79
+ try {
80
+ // Try to resolve from the project's node_modules
81
+ const projectNodeModules = path.join(process.cwd(), 'node_modules');
82
+ const lapehDist = path.join(projectNodeModules, 'lapeh', 'dist', 'lib', 'bootstrap.js');
83
+ const lapehLib = path.join(projectNodeModules, 'lapeh', 'lib', 'bootstrap.js');
84
+
85
+ if (fs.existsSync(lapehDist)) {
86
+ bootstrapPath = lapehDist;
87
+ } else if (fs.existsSync(lapehLib)) {
88
+ // Fallback to lib if dist doesn't exist (e.g. in dev environment or simple install)
89
+ // But `start` implies production, so we should prefer compiled JS.
90
+ // If lapeh package.json "main" points to index.js (in root) or lib/bootstrap.ts?
91
+ // Actually, for `start` we usually run `node dist/src/index.js` or similar?
92
+ // No, Lapeh framework entry point is `bootstrap()`.
93
+
94
+ // Let's rely on `require.resolve` relative to the CWD
95
+ // We want to require 'lapeh/lib/bootstrap' or 'lapeh/dist/lib/bootstrap'
96
+
97
+ // If we are in `node_modules/lapeh/bin/index.js`, `..` is `node_modules/lapeh`.
98
+ // So we can require('../lib/bootstrap') directly?
99
+ // Yes, if we are running the CLI from the installed package.
100
+ bootstrapPath = path.resolve(__dirname, '../lib/bootstrap.js');
101
+ if (!fs.existsSync(bootstrapPath)) {
102
+ // Try typescript source? No, production run shouldn't use TS.
103
+ bootstrapPath = path.resolve(__dirname, '../dist/lib/bootstrap.js');
104
+ }
105
+ }
106
+
107
+ // Correct approach:
108
+ // The CLI is running. We want to execute the bootstrap function.
109
+ // We can import it right here in this process!
110
+ // But `runStart` is inside `bin/index.js` which is likely a JS file.
111
+ // We can require('../lib/bootstrap') or '../dist/lib/bootstrap'.
112
+
113
+ const frameworkBootstrap = require('../lib/bootstrap');
114
+ frameworkBootstrap.bootstrap();
115
+ return; // Exit this function, let the bootstrap take over
116
+
117
+ } catch (e) {
118
+ // If direct require fails (maybe because of ESM/CJS mix or path issues), fallback to child process
119
+ }
120
+
121
+ // Fallback to previous logic if direct require fails, but fixed path
122
+ // The error showed: '.../dist/lib/bootstrap.js' not found.
123
+ // Because `lapeh` package structure might be:
124
+ // lapeh/
125
+ // bin/index.js
126
+ // lib/bootstrap.ts (and compiled .js?)
127
+ // package.json
128
+
129
+ // If we are running from `bin/index.js`, the bootstrap is at `../lib/bootstrap.js` (if compiled) or we need to compile it?
130
+ // "lapeh" framework is usually shipped as JS.
131
+
132
+ const possiblePaths = [
133
+ path.join(__dirname, '../lib/bootstrap.js'),
134
+ path.join(__dirname, '../dist/lib/bootstrap.js'),
135
+ path.join(process.cwd(), 'node_modules/lapeh/lib/bootstrap.js')
136
+ ];
137
+
138
+ bootstrapPath = possiblePaths.find(p => fs.existsSync(p));
139
+
140
+ if (!bootstrapPath) {
141
+ console.error('❌ Could not find Lapeh bootstrap file.');
142
+ console.error(' Searched in:', possiblePaths);
143
+ process.exit(1);
144
+ }
145
+
146
+ const cmd = `node -e "require('${bootstrapPath.replace(/\\/g, '/')}').bootstrap()"`;
61
147
  execSync(cmd, {
62
148
  stdio: 'inherit',
63
149
  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.4",
4
4
  "description": "Framework API Express yang siap pakai (Standardized)",
5
5
  "main": "index.js",
6
6
  "bin": {