@wolfstar/schema 0.3.0 → 0.4.0
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/esm/config-Ctpk84fx.d.ts +750 -0
- package/dist/esm/config-Ctpk84fx.d.ts.map +1 -0
- package/dist/esm/config.d.ts +2 -398
- package/dist/esm/index.d.ts +28 -184
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +250 -98
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/esm/config.d.ts.map +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -70,7 +70,7 @@ const configDiagnostics = defineDiagnostics({
|
|
|
70
70
|
},
|
|
71
71
|
TSDOWN_CONFIG_FILE_UNSUPPORTED: {
|
|
72
72
|
why: (p) => `\`${p.file}\` is not used with compatibility version ${p.version}`,
|
|
73
|
-
fix: (p) => `Move its options into \`tsdown\` here
|
|
73
|
+
fix: (p) => `Move its options into \`tsdown\` here and drop ${p.file}. \`future.compatibilityVersion\` ${p.legacyVersion} still loads it, but is end-of-life.`
|
|
74
74
|
},
|
|
75
75
|
INVALID_TYPE: {
|
|
76
76
|
why: (p) => `\`${p.path}\` must be ${p.expected}, received ${describeValue(p.value)}`,
|
|
@@ -78,12 +78,20 @@ const configDiagnostics = defineDiagnostics({
|
|
|
78
78
|
},
|
|
79
79
|
INVALID_COMPATIBILITY_VERSION: {
|
|
80
80
|
why: (p) => `Unknown compatibility version ${describeValue(p.value)}`,
|
|
81
|
-
fix: (p) => `Use ${p.
|
|
81
|
+
fix: (p) => `Use one of ${p.supported}; ${p.latestVersion} carries today's defaults.`
|
|
82
|
+
},
|
|
83
|
+
COMPATIBILITY_VERSION_EOL: {
|
|
84
|
+
why: (p) => `Compatibility version ${p.version} is end-of-life and will be removed in the next major`,
|
|
85
|
+
fix: (p) => `Move the options of your tsdown.config.* into \`tsdown\` in stars.config, delete that file, then set \`future.compatibilityVersion\` to ${p.latestVersion} (or remove it).`
|
|
82
86
|
},
|
|
83
87
|
UNKNOWN_OPTION: {
|
|
84
88
|
why: (p) => `Unknown option \`${p.path}\``,
|
|
85
89
|
fix: (p) => `Known options${p.parent ? ` of \`${p.parent}\`` : ""}: ${p.known}.`
|
|
86
90
|
},
|
|
91
|
+
UNKNOWN_HOOK: {
|
|
92
|
+
why: (p) => `Unknown hook \`${p.name}\``,
|
|
93
|
+
fix: (p) => `Known hooks: ${p.known}.`
|
|
94
|
+
},
|
|
87
95
|
EXPERIMENT_REQUIRED: {
|
|
88
96
|
why: (p) => `\`${p.path}\` needs \`${p.requires}\``,
|
|
89
97
|
fix: (p) => `Set \`${p.requires}\` to true as well, or drop \`${p.drop}\`.`
|
|
@@ -92,6 +100,10 @@ const configDiagnostics = defineDiagnostics({
|
|
|
92
100
|
why: (_p) => "`imports` requires the `tsdown` build tool",
|
|
93
101
|
fix: (_p) => "Set `build.tool` to 'tsdown', or remove `imports`/set it to `false`."
|
|
94
102
|
},
|
|
103
|
+
ENV_REQUIRES_ENV_UTILITIES: {
|
|
104
|
+
why: (_p) => "`env` is enabled, but the project does not depend on `@wolfstar/env-utilities`",
|
|
105
|
+
fix: (_p) => "Install it with `pnpm add @wolfstar/env-utilities`, or set `env` to `false`."
|
|
106
|
+
},
|
|
95
107
|
LOCALES_NOT_FOUND: {
|
|
96
108
|
why: (p) => `The locales directory does not exist: ${p.locales}`,
|
|
97
109
|
fix: (_p) => "Point `codegen.i18n.locales` to the base locale directory, relative to the project root."
|
|
@@ -208,6 +220,219 @@ function isFile$1(path) {
|
|
|
208
220
|
}
|
|
209
221
|
}
|
|
210
222
|
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/config/compatibility.ts
|
|
225
|
+
const LEGACY_COMPATIBILITY_VERSION = 3;
|
|
226
|
+
const LATEST_COMPATIBILITY_VERSION = 5;
|
|
227
|
+
/** The version a project without `future.compatibilityVersion` runs on: today, the latest one. */
|
|
228
|
+
const DEFAULT_COMPATIBILITY_VERSION = 5;
|
|
229
|
+
/** Versions still accepted but scheduled for removal in the next major. */
|
|
230
|
+
const EOL_COMPATIBILITY_VERSIONS = /* @__PURE__ */ new Set([3]);
|
|
231
|
+
/** From this version on, `tsdown` is configured from `stars.config` alone and auto imports are on by default. */
|
|
232
|
+
const STARS_CONFIG_TSDOWN_VERSION = 4;
|
|
233
|
+
/** From this version on, `env` is registered automatically in the built entry. */
|
|
234
|
+
const AUTO_ENV_VERSION = 5;
|
|
235
|
+
const COMPATIBILITY_VERSIONS = /* @__PURE__ */ new Set([
|
|
236
|
+
3,
|
|
237
|
+
4,
|
|
238
|
+
5
|
|
239
|
+
]);
|
|
240
|
+
/**
|
|
241
|
+
* Resolves the Nuxt-style compatibility block. Version 5 is the default and version 4 remains supported. Version 3 is
|
|
242
|
+
* end-of-life: it still resolves, with a warning pushed to `warnings`, and is removed in the next major.
|
|
243
|
+
*
|
|
244
|
+
* New behaviour is gated by a named version constant (such as {@link AUTO_ENV_VERSION}), never by
|
|
245
|
+
* {@link LATEST_COMPATIBILITY_VERSION}: bumping the latest version must not move older versions onto other defaults.
|
|
246
|
+
*/
|
|
247
|
+
function resolveFuture(config, validator, warnings) {
|
|
248
|
+
if (config === null || typeof config !== "object" || Array.isArray(config)) throw validator.typeError("future", "an object", config, "Use `{ compatibilityVersion }`.");
|
|
249
|
+
validator.knownKeys(config, "future", ["compatibilityVersion"]);
|
|
250
|
+
const version = config.compatibilityVersion;
|
|
251
|
+
if (version === void 0) return { compatibilityVersion: 5 };
|
|
252
|
+
if (typeof version !== "number" || !COMPATIBILITY_VERSIONS.has(version)) throw validator.error(configDiagnostics.INVALID_COMPATIBILITY_VERSION, {
|
|
253
|
+
value: version,
|
|
254
|
+
supported: [...COMPATIBILITY_VERSIONS].join(", "),
|
|
255
|
+
latestVersion: 5
|
|
256
|
+
});
|
|
257
|
+
if (EOL_COMPATIBILITY_VERSIONS.has(version)) warnings.push(validator.error(configDiagnostics.COMPATIBILITY_VERSION_EOL, {
|
|
258
|
+
version,
|
|
259
|
+
latestVersion: 5
|
|
260
|
+
}));
|
|
261
|
+
return { compatibilityVersion: version };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/config/env.ts
|
|
266
|
+
const ENV_UTILITIES = "@wolfstar/env-utilities";
|
|
267
|
+
const LOADERS = /* @__PURE__ */ new Set(["dotenv", "varlock"]);
|
|
268
|
+
/**
|
|
269
|
+
* Resolves the `env` block. It is on by default from {@link AUTO_ENV_VERSION} on, but only when the project depends on
|
|
270
|
+
* `@wolfstar/env-utilities` (the module the built entry imports) and does not build through Nitro, whose serverless
|
|
271
|
+
* presets have no `.env` files to load. `true`, `enabled: true` or any option at all is an explicit opt-in, which
|
|
272
|
+
* does require the dependency.
|
|
273
|
+
*/
|
|
274
|
+
function resolveEnv(config, packageJson, future, experimental, validator) {
|
|
275
|
+
if (config === false) return {
|
|
276
|
+
enabled: false,
|
|
277
|
+
options: {}
|
|
278
|
+
};
|
|
279
|
+
const forcedOn = config === true;
|
|
280
|
+
const raw = forcedOn || config === void 0 ? {} : config;
|
|
281
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw validator.typeError("env", "an object, `true` or `false`", raw, "Use `{ path, env, prefix, loader, debug, encoding }`, `true` to enable with defaults, or `false` to disable.");
|
|
282
|
+
validator.knownKeys(raw, "env", [
|
|
283
|
+
"enabled",
|
|
284
|
+
"path",
|
|
285
|
+
"env",
|
|
286
|
+
"prefix",
|
|
287
|
+
"loader",
|
|
288
|
+
"debug",
|
|
289
|
+
"encoding"
|
|
290
|
+
]);
|
|
291
|
+
const options = {};
|
|
292
|
+
const path = validator.string(raw.path, "env.path");
|
|
293
|
+
if (path !== void 0) options.path = path;
|
|
294
|
+
const env = validator.string(raw.env, "env.env");
|
|
295
|
+
if (env !== void 0) options.env = env;
|
|
296
|
+
const prefix = validator.string(raw.prefix, "env.prefix");
|
|
297
|
+
if (prefix !== void 0) options.prefix = prefix;
|
|
298
|
+
const loader = validator.string(raw.loader, "env.loader");
|
|
299
|
+
if (loader !== void 0) {
|
|
300
|
+
if (!LOADERS.has(loader)) throw validator.typeError("env.loader", "'dotenv' or 'varlock'", loader, "Use 'dotenv' (default) or 'varlock'.");
|
|
301
|
+
options.loader = loader;
|
|
302
|
+
}
|
|
303
|
+
const debug = validator.boolean(raw.debug, "env.debug");
|
|
304
|
+
if (debug !== void 0) options.debug = debug;
|
|
305
|
+
const encoding = validator.string(raw.encoding, "env.encoding");
|
|
306
|
+
if (encoding !== void 0) options.encoding = encoding;
|
|
307
|
+
const enabled = validator.boolean(raw.enabled, "env.enabled");
|
|
308
|
+
if (enabled === false) return {
|
|
309
|
+
enabled: false,
|
|
310
|
+
options
|
|
311
|
+
};
|
|
312
|
+
const installed = hasDependency(packageJson, ENV_UTILITIES);
|
|
313
|
+
const explicit = forcedOn || enabled === true || Object.keys(options).length > 0;
|
|
314
|
+
if (explicit && !installed) throw validator.error(configDiagnostics.ENV_REQUIRES_ENV_UTILITIES, {});
|
|
315
|
+
const enabledByDefault = installed && future.compatibilityVersion >= 5 && !experimental.enableNitro;
|
|
316
|
+
return {
|
|
317
|
+
enabled: explicit || enabledByDefault,
|
|
318
|
+
options
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region src/config/hooks.ts
|
|
324
|
+
const STARS_HOOK_NAMES = [
|
|
325
|
+
"config:resolved",
|
|
326
|
+
"env:options",
|
|
327
|
+
"prepare:before",
|
|
328
|
+
"prepare:done",
|
|
329
|
+
"builder:created",
|
|
330
|
+
"tsdown:options",
|
|
331
|
+
"build:before",
|
|
332
|
+
"build:done",
|
|
333
|
+
"dev:start",
|
|
334
|
+
"dev:restart",
|
|
335
|
+
"dev:close"
|
|
336
|
+
];
|
|
337
|
+
const KNOWN = new Set(STARS_HOOK_NAMES);
|
|
338
|
+
/**
|
|
339
|
+
* Flattens and validates `hooks`. `hookable`'s own `flatHooks` is not used: it would split an array of callbacks into
|
|
340
|
+
* `name:0`, `name:1` and silently drop anything that is not a function, while a typo in a hook name here should fail
|
|
341
|
+
* loudly rather than register a hook that never runs.
|
|
342
|
+
*/
|
|
343
|
+
function resolveHooks(config, validator) {
|
|
344
|
+
if (config === void 0) return {};
|
|
345
|
+
const resolved = {};
|
|
346
|
+
const visit = (value, path) => {
|
|
347
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw validator.typeError(path ? `hooks.${path}` : "hooks", "an object", value, "Use `{ 'build:done'() {} }` or `{ build: { done() {} } }`.");
|
|
348
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
349
|
+
const name = path ? `${path}:${key}` : key;
|
|
350
|
+
if (entry !== null && typeof entry === "object" && !Array.isArray(entry)) {
|
|
351
|
+
visit(entry, name);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (!KNOWN.has(name)) throw validator.error(configDiagnostics.UNKNOWN_HOOK, {
|
|
355
|
+
name,
|
|
356
|
+
known: STARS_HOOK_NAMES.join(", ")
|
|
357
|
+
});
|
|
358
|
+
const callbacks = Array.isArray(entry) ? entry : [entry];
|
|
359
|
+
for (const callback of callbacks) if (typeof callback !== "function") throw validator.typeError(`hooks.${name}`, "a function or an array of functions", callback, "Pass a function.");
|
|
360
|
+
(resolved[name] ??= []).push(...callbacks);
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
visit(config, "");
|
|
364
|
+
return resolved;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/config/validator.ts
|
|
369
|
+
/** Validates raw `stars.config` values, throwing a `configDiagnostics` diagnostic grounded in the configuration file. */
|
|
370
|
+
var Validator = class {
|
|
371
|
+
constructor(file) {
|
|
372
|
+
this.file = file;
|
|
373
|
+
}
|
|
374
|
+
get sources() {
|
|
375
|
+
return this.file ? [this.file] : void 0;
|
|
376
|
+
}
|
|
377
|
+
error(handle, params) {
|
|
378
|
+
return handle({
|
|
379
|
+
...params,
|
|
380
|
+
sources: this.sources
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
knownKeys(value, path, keys) {
|
|
384
|
+
for (const key of Object.keys(value)) {
|
|
385
|
+
if (keys.includes(key)) continue;
|
|
386
|
+
const fullPath = path ? `${path}.${key}` : key;
|
|
387
|
+
throw this.error(configDiagnostics.UNKNOWN_OPTION, {
|
|
388
|
+
path: fullPath,
|
|
389
|
+
parent: path,
|
|
390
|
+
known: keys.join(", ")
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
string(value, path) {
|
|
395
|
+
if (value === void 0) return void 0;
|
|
396
|
+
if (typeof value !== "string" || value.length === 0) throw this.typeError(path, "a non-empty string", value);
|
|
397
|
+
return value;
|
|
398
|
+
}
|
|
399
|
+
boolean(value, path) {
|
|
400
|
+
if (value === void 0) return void 0;
|
|
401
|
+
if (typeof value !== "boolean") throw this.typeError(path, "a boolean", value);
|
|
402
|
+
return value;
|
|
403
|
+
}
|
|
404
|
+
/** A plain object passed through as-is (e.g. raw `vite`/`tsdown` config merged into the project's own). */
|
|
405
|
+
plainObject(value, path) {
|
|
406
|
+
if (value === void 0) return void 0;
|
|
407
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw this.typeError(path, "an object", value);
|
|
408
|
+
return value;
|
|
409
|
+
}
|
|
410
|
+
stringArray(value, path) {
|
|
411
|
+
if (value === void 0) return void 0;
|
|
412
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) throw this.typeError(path, "an array of strings", value);
|
|
413
|
+
return value;
|
|
414
|
+
}
|
|
415
|
+
nonNegativeNumber(value, path) {
|
|
416
|
+
if (value === void 0) return void 0;
|
|
417
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) throw this.typeError(path, "a non-negative number", value);
|
|
418
|
+
return value;
|
|
419
|
+
}
|
|
420
|
+
stringRecord(value, path) {
|
|
421
|
+
if (value === void 0) return void 0;
|
|
422
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || !Object.values(value).every((item) => typeof item === "string")) throw this.typeError(path, "an object of string values", value);
|
|
423
|
+
return value;
|
|
424
|
+
}
|
|
425
|
+
/** A generic "wrong type" diagnostic. `fix` defaults to the standard "set it or remove it" wording. */
|
|
426
|
+
typeError(path, expected, value, fix) {
|
|
427
|
+
return this.error(configDiagnostics.INVALID_TYPE, {
|
|
428
|
+
path,
|
|
429
|
+
expected,
|
|
430
|
+
value,
|
|
431
|
+
fix: fix ?? `Set \`${path}\` to ${expected} or remove it to use the default.`
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
|
|
211
436
|
//#endregion
|
|
212
437
|
//#region src/config/resolve.ts
|
|
213
438
|
const DEFAULT_ENTRIES = [
|
|
@@ -236,10 +461,6 @@ const DEFAULT_IMPORTS_PRESETS = [
|
|
|
236
461
|
const DEFAULT_IMPORTS_DTS = ".stars/imports.d.ts";
|
|
237
462
|
const DEFAULT_DEV_LOG_FILE = ".stars/dev.log";
|
|
238
463
|
const DEFAULT_TUNNEL_PATH = "/";
|
|
239
|
-
const DEFAULT_COMPATIBILITY_VERSION = 4;
|
|
240
|
-
const LEGACY_COMPATIBILITY_VERSION = 3;
|
|
241
|
-
const LATEST_COMPATIBILITY_VERSION = 4;
|
|
242
|
-
const COMPATIBILITY_VERSIONS = /* @__PURE__ */ new Set([3, 4]);
|
|
243
464
|
const BUILD_TOOLS = /* @__PURE__ */ new Set([
|
|
244
465
|
"tsdown",
|
|
245
466
|
"tsc",
|
|
@@ -286,6 +507,7 @@ function resolveStarsConfig(options) {
|
|
|
286
507
|
const file = options.configFile;
|
|
287
508
|
const config = options.config;
|
|
288
509
|
const validator = new Validator(file);
|
|
510
|
+
const warnings = [];
|
|
289
511
|
validator.knownKeys(config, "", [
|
|
290
512
|
"root",
|
|
291
513
|
"entry",
|
|
@@ -293,6 +515,8 @@ function resolveStarsConfig(options) {
|
|
|
293
515
|
"dev",
|
|
294
516
|
"codegen",
|
|
295
517
|
"imports",
|
|
518
|
+
"env",
|
|
519
|
+
"hooks",
|
|
296
520
|
"experimental",
|
|
297
521
|
"future",
|
|
298
522
|
"vite",
|
|
@@ -303,12 +527,14 @@ function resolveStarsConfig(options) {
|
|
|
303
527
|
if (!isDirectory(root)) throw validator.error(configDiagnostics.ROOT_NOT_FOUND, { root });
|
|
304
528
|
const packageJson = readPackageJson(root, validator);
|
|
305
529
|
const experimental = resolveExperimental(config.experimental ?? {}, validator);
|
|
306
|
-
const future = resolveFuture(config.future ?? {}, validator);
|
|
530
|
+
const future = resolveFuture(config.future ?? {}, validator, warnings);
|
|
307
531
|
const entry = resolveEntry(root, validator.string(config.entry, "entry"), validator);
|
|
308
532
|
const vite = validator.plainObject(config.vite, "vite") ?? {};
|
|
309
533
|
const tsdown = validator.plainObject(config.tsdown, "tsdown") ?? {};
|
|
310
534
|
const build = resolveBuild(root, entry, packageJson, config.build ?? {}, experimental, future, Object.keys(tsdown).length > 0, validator);
|
|
311
|
-
const
|
|
535
|
+
const hooks = resolveHooks(config.hooks, validator);
|
|
536
|
+
const envConfig = resolveEnv(config.env, packageJson, future, experimental, validator);
|
|
537
|
+
const dev = resolveDev(root, entry, packageJson, config.dev ?? {}, env, envConfig.options, options.projectEnv, validator);
|
|
312
538
|
const codegen = resolveCodegen(root, config.codegen ?? {}, validator);
|
|
313
539
|
const imports = resolveImports(root, build.tool, future, config.imports, validator);
|
|
314
540
|
if (Object.keys(tsdown).length > 0 && build.tool !== "tsdown") throw validator.error(configDiagnostics.TSDOWN_OPTIONS_REQUIRE_TSDOWN, { tool: build.tool });
|
|
@@ -323,10 +549,13 @@ function resolveStarsConfig(options) {
|
|
|
323
549
|
dev,
|
|
324
550
|
codegen,
|
|
325
551
|
imports,
|
|
552
|
+
env: envConfig,
|
|
553
|
+
hooks,
|
|
326
554
|
experimental,
|
|
327
555
|
future,
|
|
328
556
|
vite,
|
|
329
|
-
tsdown
|
|
557
|
+
tsdown,
|
|
558
|
+
warnings
|
|
330
559
|
};
|
|
331
560
|
}
|
|
332
561
|
/**
|
|
@@ -418,21 +647,6 @@ function detectBuildTool(root, packageJson, isTypeScriptEntry, experimental, fut
|
|
|
418
647
|
return "none";
|
|
419
648
|
}
|
|
420
649
|
/**
|
|
421
|
-
* Resolves the Nuxt-style compatibility block. Version 4 is the default; version 3 remains an explicit legacy mode.
|
|
422
|
-
*/
|
|
423
|
-
function resolveFuture(config, validator) {
|
|
424
|
-
if (config === null || typeof config !== "object" || Array.isArray(config)) throw validator.typeError("future", "an object", config, "Use `{ compatibilityVersion }`.");
|
|
425
|
-
validator.knownKeys(config, "future", ["compatibilityVersion"]);
|
|
426
|
-
const version = config.compatibilityVersion;
|
|
427
|
-
if (version === void 0) return { compatibilityVersion: 4 };
|
|
428
|
-
if (typeof version !== "number" || !COMPATIBILITY_VERSIONS.has(version)) throw validator.error(configDiagnostics.INVALID_COMPATIBILITY_VERSION, {
|
|
429
|
-
value: version,
|
|
430
|
-
legacyVersion: 3,
|
|
431
|
-
latestVersion: 4
|
|
432
|
-
});
|
|
433
|
-
return { compatibilityVersion: version };
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
650
|
* Resolves the `experimental` block. Every flag is a boolean defaulting to `false`, the way Nuxt's own experimental
|
|
437
651
|
* flags are declared, and the ones that build on each other are checked here rather than surfacing later as a
|
|
438
652
|
* confusing runtime failure.
|
|
@@ -491,16 +705,18 @@ const ENV_PORT_KEYS = ["HTTP_PORT", "PORT"];
|
|
|
491
705
|
* implementation — quoting is stripped, but expansion (`dotenv-expand`) is not. Earlier files win, matching
|
|
492
706
|
* dotenv's own precedence.
|
|
493
707
|
*/
|
|
494
|
-
function readProjectEnvFiles(root, environment = "development") {
|
|
708
|
+
function readProjectEnvFiles(root, environment = "development", options = {}) {
|
|
495
709
|
const result = {};
|
|
496
|
-
const
|
|
710
|
+
const suffixes = [
|
|
497
711
|
`.${environment}.local`,
|
|
498
712
|
...environment === "test" ? [] : [".local"],
|
|
499
713
|
`.${environment}`,
|
|
500
714
|
""
|
|
501
|
-
]
|
|
715
|
+
];
|
|
716
|
+
const bases = options.path ? [options.path] : [join("src", ".env"), ".env"];
|
|
717
|
+
const files = suffixes.flatMap((suffix) => bases.map((base) => `${base}${suffix}`));
|
|
502
718
|
for (const file of files) {
|
|
503
|
-
const path =
|
|
719
|
+
const path = resolve(root, file);
|
|
504
720
|
if (!isFile(path)) continue;
|
|
505
721
|
let contents;
|
|
506
722
|
try {
|
|
@@ -518,12 +734,13 @@ function readProjectEnvFiles(root, environment = "development") {
|
|
|
518
734
|
}
|
|
519
735
|
return result;
|
|
520
736
|
}
|
|
521
|
-
function readDevPortFromEnvFile(root, environment) {
|
|
522
|
-
|
|
737
|
+
function readDevPortFromEnvFile(root, environment, envOptions, projectEnv) {
|
|
738
|
+
if (projectEnv === void 0 && envOptions.loader === "varlock") return null;
|
|
739
|
+
const values = projectEnv ?? readProjectEnvFiles(root, environment, { path: envOptions.path });
|
|
523
740
|
for (const key of ENV_PORT_KEYS) if (values[key]) return values[key];
|
|
524
741
|
return null;
|
|
525
742
|
}
|
|
526
|
-
function resolveDev(root, entry, packageJson, config, env, validator) {
|
|
743
|
+
function resolveDev(root, entry, packageJson, config, env, envOptions, projectEnv, validator) {
|
|
527
744
|
validator.knownKeys(config, "dev", [
|
|
528
745
|
"banner",
|
|
529
746
|
"watch",
|
|
@@ -557,7 +774,7 @@ function resolveDev(root, entry, packageJson, config, env, validator) {
|
|
|
557
774
|
});
|
|
558
775
|
}
|
|
559
776
|
else {
|
|
560
|
-
const port = devEnv.HTTP_PORT ?? env.HTTP_PORT ?? readDevPortFromEnvFile(root, env.NODE_ENV ?? "development") ?? String(3e3);
|
|
777
|
+
const port = devEnv.HTTP_PORT ?? env.HTTP_PORT ?? readDevPortFromEnvFile(root, envOptions.env ?? env.NODE_ENV ?? "development", envOptions, projectEnv) ?? String(3e3);
|
|
561
778
|
url = /^\d+$/.test(port) ? `http://localhost:${port}` : `http://localhost:${DEFAULT_DEV_PORT}`;
|
|
562
779
|
}
|
|
563
780
|
const typecheck = resolveTypecheck(root, packageJson, config.typecheck, validator);
|
|
@@ -738,71 +955,6 @@ function resolveImports(root, buildTool, future, config, validator) {
|
|
|
738
955
|
dts
|
|
739
956
|
};
|
|
740
957
|
}
|
|
741
|
-
var Validator = class {
|
|
742
|
-
constructor(file) {
|
|
743
|
-
this.file = file;
|
|
744
|
-
}
|
|
745
|
-
get sources() {
|
|
746
|
-
return this.file ? [this.file] : void 0;
|
|
747
|
-
}
|
|
748
|
-
error(handle, params) {
|
|
749
|
-
return handle({
|
|
750
|
-
...params,
|
|
751
|
-
sources: this.sources
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
knownKeys(value, path, keys) {
|
|
755
|
-
for (const key of Object.keys(value)) {
|
|
756
|
-
if (keys.includes(key)) continue;
|
|
757
|
-
const fullPath = path ? `${path}.${key}` : key;
|
|
758
|
-
throw this.error(configDiagnostics.UNKNOWN_OPTION, {
|
|
759
|
-
path: fullPath,
|
|
760
|
-
parent: path,
|
|
761
|
-
known: keys.join(", ")
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
string(value, path) {
|
|
766
|
-
if (value === void 0) return void 0;
|
|
767
|
-
if (typeof value !== "string" || value.length === 0) throw this.typeError(path, "a non-empty string", value);
|
|
768
|
-
return value;
|
|
769
|
-
}
|
|
770
|
-
boolean(value, path) {
|
|
771
|
-
if (value === void 0) return void 0;
|
|
772
|
-
if (typeof value !== "boolean") throw this.typeError(path, "a boolean", value);
|
|
773
|
-
return value;
|
|
774
|
-
}
|
|
775
|
-
/** A plain object passed through as-is (e.g. raw `vite`/`tsdown` config merged into the project's own). */
|
|
776
|
-
plainObject(value, path) {
|
|
777
|
-
if (value === void 0) return void 0;
|
|
778
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) throw this.typeError(path, "an object", value);
|
|
779
|
-
return value;
|
|
780
|
-
}
|
|
781
|
-
stringArray(value, path) {
|
|
782
|
-
if (value === void 0) return void 0;
|
|
783
|
-
if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) throw this.typeError(path, "an array of strings", value);
|
|
784
|
-
return value;
|
|
785
|
-
}
|
|
786
|
-
nonNegativeNumber(value, path) {
|
|
787
|
-
if (value === void 0) return void 0;
|
|
788
|
-
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) throw this.typeError(path, "a non-negative number", value);
|
|
789
|
-
return value;
|
|
790
|
-
}
|
|
791
|
-
stringRecord(value, path) {
|
|
792
|
-
if (value === void 0) return void 0;
|
|
793
|
-
if (value === null || typeof value !== "object" || Array.isArray(value) || !Object.values(value).every((item) => typeof item === "string")) throw this.typeError(path, "an object of string values", value);
|
|
794
|
-
return value;
|
|
795
|
-
}
|
|
796
|
-
/** A generic "wrong type" diagnostic. `fix` defaults to the standard "set it or remove it" wording. */
|
|
797
|
-
typeError(path, expected, value, fix) {
|
|
798
|
-
return this.error(configDiagnostics.INVALID_TYPE, {
|
|
799
|
-
path,
|
|
800
|
-
expected,
|
|
801
|
-
value,
|
|
802
|
-
fix: fix ?? `Set \`${path}\` to ${expected} or remove it to use the default.`
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
958
|
function hasDependency(packageJson, name) {
|
|
807
959
|
return Boolean(packageJson?.dependencies?.[name] ?? packageJson?.devDependencies?.[name]);
|
|
808
960
|
}
|
|
@@ -857,5 +1009,5 @@ async function loadStarsConfig(options = {}) {
|
|
|
857
1009
|
}
|
|
858
1010
|
|
|
859
1011
|
//#endregion
|
|
860
|
-
export { CONFIG_EXTENSIONS, CONFIG_FILE_NAMES, configDiagnostics, defineConfig, discoverConfigFile, displayPath, loadConfigFile, loadStarsConfig, readProjectEnvFiles, resolveStarsConfig };
|
|
1012
|
+
export { AUTO_ENV_VERSION, CONFIG_EXTENSIONS, CONFIG_FILE_NAMES, DEFAULT_COMPATIBILITY_VERSION, EOL_COMPATIBILITY_VERSIONS, LATEST_COMPATIBILITY_VERSION, LEGACY_COMPATIBILITY_VERSION, STARS_CONFIG_TSDOWN_VERSION, STARS_HOOK_NAMES, configDiagnostics, defineConfig, discoverConfigFile, displayPath, loadConfigFile, loadStarsConfig, readProjectEnvFiles, resolveEnv, resolveHooks, resolveStarsConfig };
|
|
861
1013
|
//# sourceMappingURL=index.js.map
|