@valbuild/init 0.60.23 → 0.60.27

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/init",
3
- "version": "0.60.23",
3
+ "version": "0.60.27",
4
4
  "description": "Initialize a new val.build project",
5
5
  "exports": {
6
6
  "./main": {
package/src/init.ts CHANGED
@@ -76,10 +76,15 @@ type Analysis = Partial<{
76
76
  isTypeScript: boolean;
77
77
  isJavaScript: boolean;
78
78
 
79
- // Val package:
80
- isValInstalled: boolean;
81
- valVersion: string;
82
- valVersionIsSatisfied: boolean;
79
+ // @valbuild/core package:
80
+ isValCoreInstalled: boolean;
81
+ valCoreVersion: string;
82
+ valCoreVersionIsSatisfied: boolean;
83
+
84
+ // @valbuild/next package:
85
+ isValNextInstalled: boolean;
86
+ valNextVersion: string;
87
+ valNextVersionIsSatisfied: boolean;
83
88
 
84
89
  // eslint:
85
90
  eslintRcJsonPath: string;
@@ -129,13 +134,17 @@ const analyze = async (root: string, files: string[]): Promise<Analysis> => {
129
134
  if (packageJsonText) {
130
135
  try {
131
136
  const packageJson = JSON.parse(packageJsonText);
132
- analysis.isValInstalled = !!packageJson.dependencies["@valbuild/next"];
137
+ analysis.isValCoreInstalled =
138
+ !!packageJson.dependencies["@valbuild/core"];
139
+ analysis.isValNextInstalled =
140
+ !!packageJson.dependencies["@valbuild/next"];
133
141
  analysis.isNextInstalled = !!packageJson.dependencies["next"];
134
142
  analysis.valEslintVersion =
135
143
  packageJson.devDependencies["@valbuild/eslint-plugin"] ||
136
144
  packageJson.dependencies["@valbuild/eslint-plugin"];
137
145
  analysis.nextVersion = packageJson.dependencies["next"];
138
- analysis.valVersion = packageJson.dependencies["@valbuild/next"];
146
+ analysis.valCoreVersion = packageJson.dependencies["@valbuild/core"];
147
+ analysis.valNextVersion = packageJson.dependencies["@valbuild/next"];
139
148
  } catch (err) {
140
149
  throw new Error(
141
150
  `Failed to parse package.json in file: ${packageJsonPath}`
@@ -152,10 +161,19 @@ const analyze = async (root: string, files: string[]): Promise<Analysis> => {
152
161
  );
153
162
  }
154
163
  }
155
- if (analysis.valVersion) {
156
- const minValVersion = semver.minVersion(analysis.valVersion)?.version;
164
+ if (analysis.valNextVersion) {
165
+ const minValVersion = semver.minVersion(analysis.valNextVersion)?.version;
166
+ if (minValVersion) {
167
+ analysis.valNextVersionIsSatisfied = semver.satisfies(
168
+ minValVersion,
169
+ ">=" + MIN_VAL_VERSION
170
+ );
171
+ }
172
+ }
173
+ if (analysis.valCoreVersion) {
174
+ const minValVersion = semver.minVersion(analysis.valCoreVersion)?.version;
157
175
  if (minValVersion) {
158
- analysis.valVersionIsSatisfied = semver.satisfies(
176
+ analysis.valCoreVersionIsSatisfied = semver.satisfies(
159
177
  minValVersion,
160
178
  ">=" + MIN_VAL_VERSION
161
179
  );
@@ -303,13 +321,40 @@ async function plan(
303
321
  logger.error("Val requires a Next.js project");
304
322
  return { abort: true };
305
323
  }
306
- if (!analysis.isValInstalled) {
324
+ if (!analysis.isValCoreInstalled) {
325
+ logger.error("Install @valbuild/core first");
326
+ return { abort: true };
327
+ } else {
328
+ if (!analysis.valCoreVersionIsSatisfied) {
329
+ logger.warn(
330
+ ` This init script expects @valbuild/core >= ${MIN_VAL_VERSION}. Found: ${analysis.valCoreVersion}`
331
+ );
332
+ const answer = !defaultAnswers
333
+ ? await confirm({
334
+ message: "Continue?",
335
+ default: false,
336
+ })
337
+ : false;
338
+ if (!answer) {
339
+ logger.error(
340
+ `Aborted: @valbuild/core version is not satisfied.\n\nInstall the @valbuild/core@${MIN_VAL_VERSION} package with your favorite package manager.\n\nExample:\n\n npm install -D @valbuild/core@${MIN_VAL_VERSION}\n`
341
+ );
342
+ return { abort: true };
343
+ }
344
+ } else {
345
+ logger.info(
346
+ ` Val version: found ${analysis.valCoreVersion} >= ${MIN_VAL_VERSION}`,
347
+ { isGood: true }
348
+ );
349
+ }
350
+ }
351
+ if (!analysis.isValNextInstalled) {
307
352
  logger.error("Install @valbuild/next first");
308
353
  return { abort: true };
309
354
  } else {
310
- if (!analysis.valVersionIsSatisfied) {
355
+ if (!analysis.valNextVersionIsSatisfied) {
311
356
  logger.warn(
312
- ` This init script expects @valbuild/next >= ${MIN_VAL_VERSION}. Found: ${analysis.valVersion}`
357
+ ` This init script expects @valbuild/next >= ${MIN_VAL_VERSION}. Found: ${analysis.valNextVersion}`
313
358
  );
314
359
  const answer = !defaultAnswers
315
360
  ? await confirm({
@@ -319,13 +364,13 @@ async function plan(
319
364
  : false;
320
365
  if (!answer) {
321
366
  logger.error(
322
- `Aborted: val version is not satisfied.\n\nInstall the @valbuild/next@${MIN_VAL_VERSION} package with your favorite package manager.\n\nExample:\n\n npm install -D @valbuild/next@${MIN_VAL_VERSION}\n`
367
+ `Aborted: @valbuild/next version is not satisfied.\n\nInstall the @valbuild/next@${MIN_VAL_VERSION} package with your favorite package manager.\n\nExample:\n\n npm install -D @valbuild/next@${MIN_VAL_VERSION}\n`
323
368
  );
324
369
  return { abort: true };
325
370
  }
326
371
  } else {
327
372
  logger.info(
328
- ` Val version: found ${analysis.valVersion} >= ${MIN_VAL_VERSION}`,
373
+ ` Val version: found ${analysis.valNextVersion} >= ${MIN_VAL_VERSION}`,
329
374
  { isGood: true }
330
375
  );
331
376
  }
@@ -698,11 +743,11 @@ async function plan(
698
743
  } catch {
699
744
  // ignore - dir does not exist (most likely)
700
745
  }
701
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
702
- const currentRecommendations: string[] = (currentSettings as any)
703
- .recommendations;
746
+ const currentRecommendations: string[] | undefined =
747
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
748
+ (currentSettings as any).recommendations;
704
749
  const valBuildIntelliSense = "valbuild.vscode-val-build";
705
- if (!currentRecommendations.includes(valBuildIntelliSense)) {
750
+ if (!currentRecommendations?.includes(valBuildIntelliSense)) {
706
751
  currentSettings = {
707
752
  ...currentSettings,
708
753
  recommendations: (currentRecommendations || []).concat(
package/src/templates.ts CHANGED
@@ -101,9 +101,9 @@ export const testSchema = s.object({
101
101
  text: s.string(),
102
102
 
103
103
  /**
104
- * Optional fields are marked with \`.optional()\`
104
+ * Nullable are optional fields in the UI that can be null or not
105
105
  */
106
- optionals: s.string().optional(),
106
+ optionals: s.string().nullable(),
107
107
 
108
108
  arrays: s.array(s.string()),
109
109
  /**
@@ -140,7 +140,7 @@ export const testSchema = s.object({
140
140
  *
141
141
  * @see ValImage component to see how to render this in your app
142
142
  */
143
- image: s.image().optional(),
143
+ image: s.image().nullable(),
144
144
 
145
145
  /**
146
146
  * String enums: presents as a dropdown in the UI