storyblok 4.23.1 → 4.23.2
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 +78 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -5002,6 +5002,69 @@ const STORYBLOK_PROPERTY_TYPES = {
|
|
|
5002
5002
|
};
|
|
5003
5003
|
const isStoryblokPropertyType = (type) => typeof type === "string" && Object.hasOwn(STORYBLOK_PROPERTY_TYPES, type);
|
|
5004
5004
|
//#endregion
|
|
5005
|
+
//#region src/utils/user-module.ts
|
|
5006
|
+
/**
|
|
5007
|
+
* A missing file is a bad invocation, so it surfaces as a {@link CommandError}
|
|
5008
|
+
* instead of Node's resolution failure with its `Require stack:` dump. The file
|
|
5009
|
+
* is checked before the import rather than by inspecting the failure: a module
|
|
5010
|
+
* the file itself imports and cannot resolve raises `Cannot find module
|
|
5011
|
+
* '<specifier>'` with a `Require stack:` naming the file, so matching the path
|
|
5012
|
+
* against the message reported a missing dependency as a missing file.
|
|
5013
|
+
*/
|
|
5014
|
+
async function resolveExistingFile(path, fileDescription) {
|
|
5015
|
+
const absolutePath = resolve(path);
|
|
5016
|
+
try {
|
|
5017
|
+
await stat(absolutePath);
|
|
5018
|
+
} catch {
|
|
5019
|
+
throw new CommandError(`${fileDescription} not found at "${path}".`);
|
|
5020
|
+
}
|
|
5021
|
+
return absolutePath;
|
|
5022
|
+
}
|
|
5023
|
+
/**
|
|
5024
|
+
* The path is resolved to an absolute path first, so jiti's base URL does not
|
|
5025
|
+
* affect which file is loaded; `tsconfigPaths` does read a tsconfig relative to
|
|
5026
|
+
* that base URL, but jiti evaluates each module through a child instance rooted
|
|
5027
|
+
* at the module itself, so the aliases applied to the file come from the user's
|
|
5028
|
+
* project and not from the CLI's own tsconfig.
|
|
5029
|
+
*/
|
|
5030
|
+
async function createUserModuleJiti(options) {
|
|
5031
|
+
const { createJiti } = await import("jiti");
|
|
5032
|
+
return createJiti(import.meta.url, {
|
|
5033
|
+
interopDefault: options.interopDefault,
|
|
5034
|
+
tsconfigPaths: process.env.JITI_TSCONFIG_PATHS !== "false"
|
|
5035
|
+
});
|
|
5036
|
+
}
|
|
5037
|
+
/**
|
|
5038
|
+
* Loads a user-provided `.ts`, `.js`, `.mjs`, `.cjs`, or `.json` file and
|
|
5039
|
+
* returns all of its exports.
|
|
5040
|
+
*/
|
|
5041
|
+
async function importUserModule(path, fileDescription) {
|
|
5042
|
+
const absolutePath = await resolveExistingFile(path, fileDescription);
|
|
5043
|
+
return await (await createUserModuleJiti({ interopDefault: true })).import(absolutePath);
|
|
5044
|
+
}
|
|
5045
|
+
/**
|
|
5046
|
+
* Loads a user-provided `.ts`, `.js`, `.mjs`, `.cjs`, or `.json` file and
|
|
5047
|
+
* returns its default export (`module.exports` for CommonJS, the parsed content
|
|
5048
|
+
* for JSON), or `undefined` when it has none. Named exports are never used in
|
|
5049
|
+
* its place, so a file without a default export can be reported as such.
|
|
5050
|
+
*/
|
|
5051
|
+
async function importUserModuleDefault(path, fileDescription) {
|
|
5052
|
+
const absolutePath = await resolveExistingFile(path, fileDescription);
|
|
5053
|
+
if (extname(absolutePath) === ".json") return parseJsonFile(absolutePath, path, fileDescription);
|
|
5054
|
+
const userModule = await (await createUserModuleJiti({ interopDefault: false })).import(absolutePath);
|
|
5055
|
+
return await (isEsModuleNamespace(userModule) ? userModule.default : userModule);
|
|
5056
|
+
}
|
|
5057
|
+
async function parseJsonFile(absolutePath, path, fileDescription) {
|
|
5058
|
+
try {
|
|
5059
|
+
return JSON.parse(await readFile(absolutePath, "utf8"));
|
|
5060
|
+
} catch (error) {
|
|
5061
|
+
throw new CommandError(`${fileDescription} at "${path}" is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
function isEsModuleNamespace(value) {
|
|
5065
|
+
return Object.prototype.toString.call(value) === "[object Module]" || isRecord(value) && value.__esModule === true;
|
|
5066
|
+
}
|
|
5067
|
+
//#endregion
|
|
5005
5068
|
//#region src/commands/types/generate/utils.ts
|
|
5006
5069
|
/**
|
|
5007
5070
|
* Explicit type-name overrides for Storyblok field types where the generated
|
|
@@ -5258,7 +5321,7 @@ const getComponentPropertiesTypeAnnotations = async (component, options, spaceDa
|
|
|
5258
5321
|
if (isLayoutFieldType(propertyType)) return acc;
|
|
5259
5322
|
const propertyTypeAnnotation = { [key]: getPropertyTypeAnnotation(schema, options.typePrefix, options.typeSuffix) };
|
|
5260
5323
|
if (propertyType === "custom" && customFieldsParser) {
|
|
5261
|
-
const customField =
|
|
5324
|
+
const customField = customFieldsParser(key, schema);
|
|
5262
5325
|
return {
|
|
5263
5326
|
...acc,
|
|
5264
5327
|
...customField
|
|
@@ -5299,17 +5362,18 @@ const getComponentPropertiesTypeAnnotations = async (component, options, spaceDa
|
|
|
5299
5362
|
};
|
|
5300
5363
|
}, Promise.resolve({}));
|
|
5301
5364
|
};
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
}
|
|
5365
|
+
function isCustomFieldsParser(value) {
|
|
5366
|
+
return typeof value === "function";
|
|
5367
|
+
}
|
|
5368
|
+
async function loadCustomFieldsParser(path) {
|
|
5369
|
+
const parser = await importUserModuleDefault(path, "Custom fields parser file");
|
|
5370
|
+
if (!isCustomFieldsParser(parser)) throw new CommandError(`The custom fields parser file at "${path}" must default-export a function.`);
|
|
5371
|
+
return parser;
|
|
5372
|
+
}
|
|
5310
5373
|
async function loadCompilerOptions(path) {
|
|
5311
|
-
|
|
5312
|
-
|
|
5374
|
+
const compilerOptions = await importUserModuleDefault(path, "Compiler options file");
|
|
5375
|
+
if (!isRecord(compilerOptions)) throw new CommandError(`The compiler options file at "${path}" must default-export an options object.`);
|
|
5376
|
+
return compilerOptions;
|
|
5313
5377
|
}
|
|
5314
5378
|
const generateTypes = async (spaceData, options = { strict: false }) => {
|
|
5315
5379
|
try {
|
|
@@ -10055,36 +10119,13 @@ function collectSchemaExports(moduleExports) {
|
|
|
10055
10119
|
};
|
|
10056
10120
|
}
|
|
10057
10121
|
/**
|
|
10058
|
-
* Loads a TypeScript schema entry file
|
|
10059
|
-
* exports. The path is resolved to an absolute path first, so jiti's base URL
|
|
10060
|
-
* does not affect which file is loaded; `tsconfigPaths` does read a tsconfig
|
|
10061
|
-
* relative to that base URL, but jiti evaluates each module through a child
|
|
10062
|
-
* instance rooted at the module itself, so the aliases applied to the entry
|
|
10063
|
-
* file come from the user's project and not from the CLI's own tsconfig.
|
|
10122
|
+
* Loads a TypeScript schema entry file and returns its raw module exports.
|
|
10064
10123
|
* Shared by `schema push` (wire mapping) and the validate commands (DSL
|
|
10065
|
-
* shape).
|
|
10124
|
+
* shape). Throws when the file is missing or fails to evaluate — fatal for
|
|
10066
10125
|
* the callers.
|
|
10067
|
-
*
|
|
10068
|
-
* A missing entry file is a bad invocation, so it surfaces as a
|
|
10069
|
-
* {@link CommandError} instead of Node's resolution failure with its `Require
|
|
10070
|
-
* stack:` dump. The file is checked before the import rather than by inspecting
|
|
10071
|
-
* the failure: a module the entry file itself imports and cannot resolve raises
|
|
10072
|
-
* `Cannot find module '<specifier>'` with a `Require stack:` naming the entry
|
|
10073
|
-
* file, so matching the entry path against the message reported a missing
|
|
10074
|
-
* dependency as a missing entry file.
|
|
10075
10126
|
*/
|
|
10076
10127
|
async function loadSchemaModule(entryPath) {
|
|
10077
|
-
|
|
10078
|
-
try {
|
|
10079
|
-
await stat(entryAbs);
|
|
10080
|
-
} catch {
|
|
10081
|
-
throw new CommandError(`Schema entry file not found at "${entryPath}".`);
|
|
10082
|
-
}
|
|
10083
|
-
const { createJiti } = await import("jiti");
|
|
10084
|
-
return await createJiti(import.meta.url, {
|
|
10085
|
-
interopDefault: true,
|
|
10086
|
-
tsconfigPaths: process.env.JITI_TSCONFIG_PATHS !== "false"
|
|
10087
|
-
}).import(entryAbs);
|
|
10128
|
+
return await importUserModule(entryPath, "Schema entry file");
|
|
10088
10129
|
}
|
|
10089
10130
|
//#endregion
|
|
10090
10131
|
//#region src/lib/validation/adapter.ts
|