create-prisma-php-app 4.0.0-alpha.73 → 4.0.0-alpha.74

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/dist/index.js +70 -32
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -80,9 +80,10 @@ export async function installComposerDependencies(baseDir, dependencies) {
80
80
  fs.mkdirSync(baseDir, { recursive: true });
81
81
  }
82
82
  /* ------------------------------------------------------------------ */
83
- /* 2. Try composer init (with better error handling) */
83
+ /* 2. Create composer.json directly (more reliable) */
84
84
  /* ------------------------------------------------------------------ */
85
85
  if (!existsAlready) {
86
+ // Try composer init first, but don't rely on it
86
87
  const initArgs = [
87
88
  ...baseArgs,
88
89
  "init",
@@ -96,78 +97,109 @@ export async function installComposerDependencies(baseDir, dependencies) {
96
97
  "--version",
97
98
  "1.0.0",
98
99
  ];
99
- console.log(`Executing: ${cmd} ${initArgs.join(" ")}`);
100
- console.log(`Working directory: ${baseDir}`);
100
+ console.log(`Attempting composer init...`);
101
101
  const res = spawnSync(cmd, initArgs, {
102
102
  cwd: baseDir,
103
- stdio: ["ignore", "pipe", "pipe"], // Capture output for debugging
103
+ stdio: ["ignore", "pipe", "pipe"],
104
104
  encoding: "utf8",
105
105
  });
106
- if (res.status !== 0) {
107
- console.log(`Composer init failed with status ${res.status}`);
108
- if (res.stderr) {
109
- console.log(`Composer stderr: ${res.stderr}`);
110
- }
111
- if (res.stdout) {
112
- console.log(`Composer stdout: ${res.stdout}`);
106
+ // Check if composer.json was actually created
107
+ const composerJsonCreated = fs.existsSync(composerJsonPath);
108
+ if (res.status === 0 && composerJsonCreated) {
109
+ console.log("✓ Composer init successful and composer.json created");
110
+ } else {
111
+ if (res.status !== 0) {
112
+ console.log(`Composer init failed with status ${res.status}`);
113
+ if (res.stderr) console.log(`Stderr: ${res.stderr}`);
114
+ } else {
115
+ console.log(
116
+ `Composer init reported success but didn't create composer.json`
117
+ );
113
118
  }
114
- // Create fallback composer.json
115
- console.log("Creating fallback composer.json...");
119
+ // Always create composer.json manually
120
+ console.log("Creating composer.json manually...");
116
121
  const defaultComposerJson = {
117
122
  name: "tsnc/prisma-php-app",
118
123
  type: "project",
119
124
  version: "1.0.0",
120
- require: { php: "^8.2" },
121
- autoload: { "psr-4": { "": "src/" } },
125
+ require: {
126
+ php: "^8.2",
127
+ },
128
+ autoload: {
129
+ "psr-4": {
130
+ "": "src/",
131
+ },
132
+ },
122
133
  };
123
134
  try {
135
+ // Ensure we're writing to the correct absolute path
136
+ const absoluteComposerPath = path.resolve(baseDir, "composer.json");
137
+ console.log(`Writing composer.json to: ${absoluteComposerPath}`);
124
138
  fs.writeFileSync(
125
- composerJsonPath,
139
+ absoluteComposerPath,
126
140
  JSON.stringify(defaultComposerJson, null, 2),
127
141
  { encoding: "utf8" }
128
142
  );
129
- console.log(`✓ Created fallback composer.json at ${composerJsonPath}`);
143
+ // Verify the file was actually created
144
+ if (fs.existsSync(absoluteComposerPath)) {
145
+ console.log(`✓ Successfully created composer.json`);
146
+ } else {
147
+ throw new Error(
148
+ "File creation appeared to succeed but file doesn't exist"
149
+ );
150
+ }
130
151
  } catch (writeError) {
131
- console.error(`✗ Failed to create fallback composer.json:`, writeError);
132
- console.error(`Attempted to write to: ${composerJsonPath}`);
133
- console.error(`Base directory exists: ${fs.existsSync(baseDir)}`);
152
+ console.error(`✗ Failed to create composer.json:`, writeError);
153
+ // Additional debugging
154
+ console.error(`Base directory: ${baseDir}`);
155
+ console.error(`Absolute base directory: ${path.resolve(baseDir)}`);
156
+ console.error(`Target file path: ${composerJsonPath}`);
134
157
  console.error(
135
- `Base directory stats:`,
136
- fs.existsSync(baseDir) ? fs.statSync(baseDir) : "N/A"
158
+ `Absolute target file path: ${path.resolve(composerJsonPath)}`
137
159
  );
160
+ console.error(`Current working directory: ${process.cwd()}`);
161
+ console.error(`Base directory exists: ${fs.existsSync(baseDir)}`);
162
+ if (fs.existsSync(baseDir)) {
163
+ try {
164
+ const stats = fs.statSync(baseDir);
165
+ console.error(`Base directory is writable: ${stats.isDirectory()}`);
166
+ } catch (statError) {
167
+ console.error(`Cannot stat base directory: ${statError}`);
168
+ }
169
+ }
138
170
  throw new Error(`Cannot create composer.json: ${writeError}`);
139
171
  }
140
- } else {
141
- console.log("✓ Composer init successful");
142
172
  }
143
173
  }
144
174
  /* ------------------------------------------------------------------ */
145
- /* 3. Verify composer.json exists before proceeding */
175
+ /* 3. Final verification that composer.json exists */
146
176
  /* ------------------------------------------------------------------ */
147
- if (!fs.existsSync(composerJsonPath)) {
148
- console.error(`✗ composer.json still not found at ${composerJsonPath}`);
177
+ const finalComposerPath = path.resolve(baseDir, "composer.json");
178
+ if (!fs.existsSync(finalComposerPath)) {
179
+ console.error(`✗ composer.json still not found at ${finalComposerPath}`);
149
180
  console.error(`Directory contents:`, fs.readdirSync(baseDir));
150
181
  throw new Error(
151
- "Failed to create composer.json - file does not exist after init/fallback"
182
+ "Failed to create composer.json - file does not exist after all attempts"
152
183
  );
153
184
  }
154
185
  /* ------------------------------------------------------------------ */
155
- /* 4. Ensure PSR-4 autoload entry */
186
+ /* 4. Read and update composer.json */
156
187
  /* ------------------------------------------------------------------ */
157
188
  let json;
158
189
  try {
159
- const jsonContent = fs.readFileSync(composerJsonPath, "utf8");
190
+ const jsonContent = fs.readFileSync(finalComposerPath, "utf8");
160
191
  console.log("✓ Successfully read composer.json");
161
192
  json = JSON.parse(jsonContent);
162
193
  } catch (readError) {
163
194
  console.error("✗ Failed to read/parse composer.json:", readError);
164
195
  throw new Error(`Cannot read composer.json: ${readError}`);
165
196
  }
197
+ // Ensure PSR-4 autoload entry
166
198
  json.autoload ??= {};
167
199
  json.autoload["psr-4"] ??= {};
168
200
  json.autoload["psr-4"][""] ??= "src/";
169
201
  try {
170
- fs.writeFileSync(composerJsonPath, JSON.stringify(json, null, 2));
202
+ fs.writeFileSync(finalComposerPath, JSON.stringify(json, null, 2));
171
203
  console.log("✓ Updated composer.json with PSR-4 autoload");
172
204
  } catch (writeError) {
173
205
  console.error("✗ Failed to update composer.json:", writeError);
@@ -187,7 +219,13 @@ export async function installComposerDependencies(baseDir, dependencies) {
187
219
  ...dependencies,
188
220
  ].join(" ")}`;
189
221
  console.log(`Executing: ${requireCmd}`);
190
- execSync(requireCmd, { stdio: "inherit", cwd: baseDir });
222
+ console.log(`Working directory: ${baseDir}`);
223
+ execSync(requireCmd, {
224
+ stdio: "inherit",
225
+ cwd: baseDir,
226
+ // Ensure the working directory is correct
227
+ env: { ...process.env },
228
+ });
191
229
  console.log("✓ Composer dependencies installed");
192
230
  } catch (installError) {
193
231
  console.error("✗ Failed to install composer dependencies:", installError);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "4.0.0-alpha.73",
3
+ "version": "4.0.0-alpha.74",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",