@zenstackhq/cli 3.8.0-beta.2 → 3.8.0-beta.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.
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ import "dotenv/config";
6
6
  import { DataModel, Enum, isDataField, isDataSource, isEnum, isInvocationExpr, isLiteralExpr, isPlugin } from "@zenstackhq/language/ast";
7
7
  import path from "node:path";
8
8
  import { invariant, lowerCaseFirst, singleDebounce } from "@zenstackhq/common-helpers";
9
- import { PrismaSchemaGenerator, TsSchemaGenerator } from "@zenstackhq/sdk";
9
+ import { PrismaSchemaGenerator, TsSchemaGenerator, detectImportFileExtension } from "@zenstackhq/sdk";
10
10
  import { createJiti } from "jiti";
11
11
  import crypto, { createHash, randomUUID } from "node:crypto";
12
12
  import fs from "node:fs";
@@ -289,7 +289,7 @@ async function checkPluginResolution(schemaFile, model) {
289
289
  for (const plugin of plugins) {
290
290
  const provider = getPluginProvider(plugin);
291
291
  if (!provider.startsWith("@core/")) {
292
- const pluginSourcePath = plugin.$cstNode?.parent?.element.$document?.uri?.fsPath ?? schemaFile;
292
+ const pluginSourcePath = plugin.$cstNode?.container?.astNode.$document?.uri?.fsPath ?? schemaFile;
293
293
  await loadPluginModule(provider, path.dirname(pluginSourcePath));
294
294
  }
295
295
  }
@@ -2305,7 +2305,7 @@ async function runPull(options) {
2305
2305
  model.declarations.splice(index, 1);
2306
2306
  deletedEnums.push(colors.red(`- Enum ${decl.name} deleted`));
2307
2307
  });
2308
- newModel.declarations.filter((d) => [DataModel, Enum].includes(d.$type)).forEach((_declaration) => {
2308
+ newModel.declarations.filter((d) => d.$type === DataModel.$type || d.$type === Enum.$type).forEach((_declaration) => {
2309
2309
  const newDataModel = _declaration;
2310
2310
  const declarations = services.shared.workspace.IndexManager.allElements(newDataModel.$type, docsSet).toArray();
2311
2311
  const originalDataModel = declarations.find((d) => getDbName(d.node) === getDbName(newDataModel))?.node;
@@ -2602,8 +2602,9 @@ const plugin = {
2602
2602
  }
2603
2603
  const lite = pluginOptions["lite"] === true;
2604
2604
  const liteOnly = pluginOptions["liteOnly"] === true;
2605
- const importWithFileExtension = pluginOptions["importWithFileExtension"];
2606
- if (importWithFileExtension && typeof importWithFileExtension !== "string") throw new Error("The \"importWithFileExtension\" option must be a string if specified.");
2605
+ let importWithFileExtension = pluginOptions["importWithFileExtension"];
2606
+ if (importWithFileExtension === void 0) importWithFileExtension = detectImportFileExtension(outDir);
2607
+ else if (typeof importWithFileExtension !== "string") throw new Error("The \"importWithFileExtension\" option must be a string if specified.");
2607
2608
  const generateModelTypes = pluginOptions["generateModels"] !== false;
2608
2609
  const generateInputTypes = pluginOptions["generateInput"] !== false;
2609
2610
  await new TsSchemaGenerator().generate(model, {
@@ -2640,7 +2641,7 @@ async function run$5(options) {
2640
2641
  const logsEnabled = !options.silent;
2641
2642
  if (logsEnabled) console.log(colors.green(`\nEnabled watch mode!`));
2642
2643
  const schemaExtensions = ZModelLanguageMetaData.fileExtensions;
2643
- const getRootModelWatchPaths = (model) => new Set(model.declarations.filter((v) => v.$cstNode?.parent?.element.$type === "Model" && !!v.$cstNode.parent.element.$document?.uri?.fsPath).map((v) => v.$cstNode.parent.element.$document.uri.fsPath));
2644
+ const getRootModelWatchPaths = (model) => new Set(model.declarations.filter((v) => v.$cstNode?.container?.astNode.$type === "Model" && !!v.$cstNode.container.astNode.$document?.uri?.fsPath).map((v) => v.$cstNode.container.astNode.$document.uri.fsPath));
2644
2645
  const watchedPaths = getRootModelWatchPaths(model);
2645
2646
  if (logsEnabled) {
2646
2647
  const logPaths = [...watchedPaths].map((at) => `- ${at}`).join("\n");
@@ -2722,7 +2723,7 @@ async function runPlugins(schemaFile, model, outputPath, options) {
2722
2723
  cliPlugin = plugins_exports[provider.slice(6)];
2723
2724
  if (!cliPlugin) throw new CliError(`Unknown core plugin: ${provider}`);
2724
2725
  } else {
2725
- const pluginSourcePath = plugin.$cstNode?.parent?.element.$document?.uri?.fsPath ?? schemaFile;
2726
+ const pluginSourcePath = plugin.$cstNode?.container?.astNode.$document?.uri?.fsPath ?? schemaFile;
2726
2727
  cliPlugin = await loadPluginModule(provider, path.dirname(pluginSourcePath));
2727
2728
  }
2728
2729
  if (cliPlugin) {