@akanjs/cli 0.0.45 → 0.0.47

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/index.js +37 -34
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1878,10 +1878,9 @@ CMD ["npm", "start"]`,
1878
1878
  });
1879
1879
 
1880
1880
  // pkgs/@akanjs/devkit/src/extractDeps.ts
1881
- var fs11, NODE_NATIVE_MODULE_SET, extractDependencies;
1881
+ var NODE_NATIVE_MODULE_SET, extractDependencies;
1882
1882
  var init_extractDeps = __esm({
1883
1883
  "pkgs/@akanjs/devkit/src/extractDeps.ts"() {
1884
- fs11 = __toESM(__require("fs"));
1885
1884
  NODE_NATIVE_MODULE_SET = /* @__PURE__ */ new Set([
1886
1885
  "assert",
1887
1886
  "async_hooks",
@@ -1924,10 +1923,9 @@ CMD ["npm", "start"]`,
1924
1923
  "worker_threads",
1925
1924
  "zlib"
1926
1925
  ]);
1927
- extractDependencies = (bundlePath, pacakgeJson, defaultDependencies = []) => {
1926
+ extractDependencies = (filepaths, pacakgeJson, defaultDependencies = []) => {
1928
1927
  if (!pacakgeJson.dependencies)
1929
1928
  throw new Error("No dependencies found in package.json");
1930
- const code = fs11.readFileSync(bundlePath, "utf8");
1931
1929
  const dependencies = new Set(defaultDependencies);
1932
1930
  const existingDependencies = /* @__PURE__ */ new Set([
1933
1931
  ...Object.keys(pacakgeJson.dependencies ?? {}),
@@ -1938,15 +1936,17 @@ CMD ["npm", "start"]`,
1938
1936
  ...pacakgeJson.devDependencies ?? {}
1939
1937
  };
1940
1938
  const requireRegex = /require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g;
1941
- let requireMatch;
1942
- while ((requireMatch = requireRegex.exec(code)) !== null) {
1943
- const moduleName = requireMatch[1];
1944
- const moduleNameParts = moduleName.split("/");
1945
- const subModuleLength = moduleNameParts.length;
1946
- for (let i = 0; i < subModuleLength; i++) {
1947
- const libName = moduleNameParts.slice(0, i + 1).join("/");
1948
- if (!NODE_NATIVE_MODULE_SET.has(libName) && existingDependencies.has(libName))
1949
- dependencies.add(libName);
1939
+ for (const { text } of filepaths) {
1940
+ let requireMatch;
1941
+ while ((requireMatch = requireRegex.exec(text)) !== null) {
1942
+ const moduleName = requireMatch[1];
1943
+ const moduleNameParts = moduleName.split("/");
1944
+ const subModuleLength = moduleNameParts.length;
1945
+ for (let i = 0; i < subModuleLength; i++) {
1946
+ const libName = moduleNameParts.slice(0, i + 1).join("/");
1947
+ if (!NODE_NATIVE_MODULE_SET.has(libName) && existingDependencies.has(libName))
1948
+ dependencies.add(libName);
1949
+ }
1950
1950
  }
1951
1951
  }
1952
1952
  return Object.fromEntries(
@@ -3450,8 +3450,8 @@ page.tsx_end
3450
3450
  async buildBackend(app, distApp) {
3451
3451
  await this.#prepareCommand(app, distApp, "serve", "backend");
3452
3452
  const akanConfig = await app.getConfig("build");
3453
- await esbuild.build({
3454
- write: true,
3453
+ const buildResult = await esbuild.build({
3454
+ write: false,
3455
3455
  entryPoints: [`${app.cwdPath}/main.ts`],
3456
3456
  bundle: true,
3457
3457
  packages: "external",
@@ -3460,7 +3460,8 @@ page.tsx_end
3460
3460
  logLevel: "warning"
3461
3461
  });
3462
3462
  const rootPackageJson = app.workspace.readJson("package.json");
3463
- const dependencies = extractDependencies(import_path4.default.join(distApp.cwdPath, "backend", "main.js"), rootPackageJson);
3463
+ const dependencies = extractDependencies(buildResult.outputFiles, rootPackageJson);
3464
+ buildResult.outputFiles.map((file) => distApp.writeFile(file.path, file.text));
3464
3465
  const appPackageJson = {
3465
3466
  name: `${app.name}/backend`,
3466
3467
  description: `${app.name} backend`,
@@ -3491,7 +3492,7 @@ page.tsx_end
3491
3492
  const { env } = await this.#prepareCommand(app, distApp, "build", "frontend");
3492
3493
  const akanConfig = await app.getConfig("build");
3493
3494
  await app.spawn("npx", ["next", "build", "--no-lint"], { env });
3494
- await esbuild.build({
3495
+ const buildResult = await esbuild.build({
3495
3496
  entryPoints: [`${app.cwdPath}/next.config.ts`],
3496
3497
  outdir: `${distApp.cwdPath}/frontend`,
3497
3498
  bundle: true,
@@ -3503,11 +3504,9 @@ page.tsx_end
3503
3504
  footer: { js: "module.exports = module.exports.default;" }
3504
3505
  });
3505
3506
  const rootPackageJson = app.workspace.readJson("package.json");
3506
- const dependencies = extractDependencies(
3507
- import_path4.default.join(distApp.cwdPath, "frontend", "next.config.js"),
3508
- rootPackageJson,
3509
- ["next", "react", "react-dom"]
3510
- );
3507
+ const dependencies = buildResult.outputFiles ? extractDependencies(buildResult.outputFiles, rootPackageJson, ["next", "react", "react-dom"]) : {};
3508
+ if (buildResult.outputFiles)
3509
+ buildResult.outputFiles.map((file) => distApp.writeFile(file.path, file.text));
3511
3510
  const appPackageJson = {
3512
3511
  name: `${app.name}/frontend`,
3513
3512
  description: `${app.name} frontend`,
@@ -4187,26 +4186,27 @@ page.tsx_end
4187
4186
  const rootPackageJson = pkg.workspace.readJson("package.json");
4188
4187
  await pkg.workspace.exec(`rm -rf dist/${pkg.name}`);
4189
4188
  await import_promises3.default.rm(`dist/pkgs/${pkg.name}`, { force: true, recursive: true });
4189
+ let buildResult;
4190
4190
  if (pkg.name === "@akanjs/config") {
4191
- await esbuild2.build({
4192
- write: true,
4191
+ buildResult = await esbuild2.build({
4192
+ write: false,
4193
4193
  entryPoints: [`${pkg.cwdPath}/index.ts`],
4194
4194
  bundle: true,
4195
4195
  packages: "external",
4196
4196
  format: "cjs",
4197
4197
  outdir: distPkg.cwdPath,
4198
- logLevel: "warning",
4198
+ logLevel: "error",
4199
4199
  plugins: [(0, import_esbuild_plugin_d.dtsPlugin)({ tsconfig: `${pkg.cwdPath}/tsconfig.json` })]
4200
4200
  });
4201
4201
  await pkg.workspace.exec(`rsync -aq ${pkg.cwdPath}/src/ ${distPkg.cwdPath}/src/`);
4202
4202
  } else if (pkg.name === "@akanjs/cli") {
4203
- await esbuild2.build({
4204
- write: true,
4203
+ buildResult = await esbuild2.build({
4204
+ write: false,
4205
4205
  entryPoints: [`${pkg.cwdPath}/index.ts`],
4206
4206
  bundle: true,
4207
4207
  packages: "external",
4208
4208
  outdir: distPkg.cwdPath,
4209
- logLevel: "warning",
4209
+ logLevel: "error",
4210
4210
  plugins: [(0, import_esbuild_plugin_d.dtsPlugin)({ tsconfig: `${pkg.cwdPath}/tsconfig.json` })]
4211
4211
  });
4212
4212
  await esbuild2.build({
@@ -4223,20 +4223,23 @@ page.tsx_end
4223
4223
  `rsync -aq --exclude="*.ts" --exclude="*.tsx" ${pkg.cwdPath}/src/templates/ ${distPkg.cwdPath}/src/templates/`
4224
4224
  );
4225
4225
  } else {
4226
- await esbuild2.build({
4227
- write: true,
4228
- entryPoints: [`${pkg.cwdPath}/index.ts`],
4229
- bundle: true,
4226
+ buildResult = await esbuild2.build({
4227
+ write: false,
4228
+ entryPoints: [`${pkg.cwdPath}/index.ts`, `${pkg.cwdPath}/src/**/*.ts`, `${pkg.cwdPath}/src/**/*.tsx`],
4229
+ bundle: false,
4230
4230
  packages: "external",
4231
4231
  format: "cjs",
4232
+ // external: ["@akanjs/*"],
4232
4233
  outdir: distPkg.cwdPath,
4233
- logLevel: "warning",
4234
+ logLevel: "error",
4234
4235
  plugins: [(0, import_esbuild_plugin_d.dtsPlugin)({ tsconfig: `${pkg.cwdPath}/tsconfig.json` })]
4235
4236
  });
4236
4237
  }
4237
4238
  const pkgJson = pkg.readJson("package.json");
4238
- const dependencies = extractDependencies(`${distPkg.cwdPath}/index.js`, rootPackageJson);
4239
+ const dependencies = buildResult.outputFiles ? extractDependencies(buildResult.outputFiles, rootPackageJson) : {};
4239
4240
  const pkgPackageJson = { ...pkgJson, main: "./index.js", engines: { node: ">=22" }, dependencies };
4241
+ if (buildResult.outputFiles)
4242
+ buildResult.outputFiles.map((file) => distPkg.writeFile(file.path, file.text));
4240
4243
  distPkg.writeJson("package.json", pkgPackageJson);
4241
4244
  }
4242
4245
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "commonjs",
3
3
  "name": "@akanjs/cli",
4
- "version": "0.0.45",
4
+ "version": "0.0.47",
5
5
  "bin": {
6
6
  "akan": "index.js"
7
7
  },