@wp-typia/block-runtime 0.4.2 → 0.4.4
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/blocks.d.ts +18 -1
- package/dist/blocks.js +95 -2
- package/dist/inspector-runtime.d.ts +5 -6
- package/package.json +1 -1
package/dist/blocks.d.ts
CHANGED
|
@@ -34,6 +34,19 @@ export interface TypiaWebpackConfigOptions {
|
|
|
34
34
|
path: {
|
|
35
35
|
join(...paths: string[]): string;
|
|
36
36
|
};
|
|
37
|
+
projectRoot?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface TypiaWebpackPluginLoaderOptions {
|
|
40
|
+
importTypiaWebpackPlugin: () => Promise<{
|
|
41
|
+
default: () => unknown;
|
|
42
|
+
}>;
|
|
43
|
+
projectRoot?: string;
|
|
44
|
+
}
|
|
45
|
+
interface TypiaWebpackVersionMatrix {
|
|
46
|
+
"@typia/unplugin": string | null;
|
|
47
|
+
"@wordpress/scripts": string | null;
|
|
48
|
+
typia: string | null;
|
|
49
|
+
webpack: string | null;
|
|
37
50
|
}
|
|
38
51
|
type OverrideProperties<TBase, TOverride> = Omit<TBase, keyof TOverride> & TOverride;
|
|
39
52
|
type ScaffoldSupportDefaultControls<TFeature extends string> = Readonly<Partial<Record<TFeature, boolean>> & Record<string, boolean | undefined>>;
|
|
@@ -169,8 +182,12 @@ export interface BuildScaffoldBlockRegistrationResult<TSettings extends object>
|
|
|
169
182
|
name: string;
|
|
170
183
|
settings: TSettings;
|
|
171
184
|
}
|
|
185
|
+
export declare function assertTypiaWebpackCompatibility({ projectRoot, }?: {
|
|
186
|
+
projectRoot?: string;
|
|
187
|
+
}): Promise<TypiaWebpackVersionMatrix>;
|
|
188
|
+
export declare function loadCompatibleTypiaWebpackPlugin({ importTypiaWebpackPlugin, projectRoot, }: TypiaWebpackPluginLoaderOptions): Promise<() => unknown>;
|
|
172
189
|
export declare function buildScaffoldBlockRegistration<TSettings extends object>(metadata: ScaffoldBlockMetadata, overrides: Partial<TSettings> & Record<string, unknown>): BuildScaffoldBlockRegistrationResult<TSettings>;
|
|
173
|
-
export declare function createTypiaWebpackConfig({ defaultConfig, fs, getArtifactEntries, getEditorEntries, getOptionalModuleEntries, importTypiaWebpackPlugin, isScriptModuleAsset, moduleEntriesMode, nonModuleEntriesMode, path, }: TypiaWebpackConfigOptions): Promise<{
|
|
190
|
+
export declare function createTypiaWebpackConfig({ defaultConfig, fs, getArtifactEntries, getEditorEntries, getOptionalModuleEntries, importTypiaWebpackPlugin, isScriptModuleAsset, moduleEntriesMode, nonModuleEntriesMode, path, projectRoot, }: TypiaWebpackConfigOptions): Promise<{
|
|
174
191
|
entry: () => Promise<Record<string, unknown>>;
|
|
175
192
|
plugins: unknown[];
|
|
176
193
|
} | {
|
package/dist/blocks.js
CHANGED
|
@@ -15,6 +15,96 @@ function isModuleConfig(config) {
|
|
|
15
15
|
config !== null &&
|
|
16
16
|
config.output?.module === true);
|
|
17
17
|
}
|
|
18
|
+
function parseMajorVersion(version) {
|
|
19
|
+
if (!version) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const match = /^(\d+)/u.exec(version);
|
|
23
|
+
return match ? Number.parseInt(match[1], 10) : null;
|
|
24
|
+
}
|
|
25
|
+
function readPackageVersion(readFileSync, packageJsonPath) {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(readFileSync(packageJsonPath, "utf8")).version;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function loadNodeRuntimeHelpers() {
|
|
34
|
+
const importNodeModule = Function("specifier", "return import(specifier);");
|
|
35
|
+
const [fsModule, moduleBuiltin, pathBuiltin] = (await Promise.all([
|
|
36
|
+
importNodeModule("node:fs"),
|
|
37
|
+
importNodeModule("node:module"),
|
|
38
|
+
importNodeModule("node:path"),
|
|
39
|
+
]));
|
|
40
|
+
return {
|
|
41
|
+
createRequire: moduleBuiltin.createRequire,
|
|
42
|
+
pathModule: pathBuiltin,
|
|
43
|
+
readFileSync: fsModule.readFileSync,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function resolveInstalledPackageVersion(readFileSync, requireFromProject, packageName) {
|
|
47
|
+
try {
|
|
48
|
+
return readPackageVersion(readFileSync, requireFromProject.resolve(`${packageName}/package.json`));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function resolveWebpackVersion(readFileSync, requireFromProject, createRequire) {
|
|
55
|
+
try {
|
|
56
|
+
const wordpressScriptsPackageJsonPath = requireFromProject.resolve("@wordpress/scripts/package.json");
|
|
57
|
+
const requireFromWordPressScripts = createRequire(wordpressScriptsPackageJsonPath);
|
|
58
|
+
const bundledWebpackVersion = resolveInstalledPackageVersion(readFileSync, requireFromWordPressScripts, "webpack");
|
|
59
|
+
if (bundledWebpackVersion) {
|
|
60
|
+
return bundledWebpackVersion;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// fall through to the project-level webpack resolution below
|
|
65
|
+
}
|
|
66
|
+
return resolveInstalledPackageVersion(readFileSync, requireFromProject, "webpack");
|
|
67
|
+
}
|
|
68
|
+
async function getTypiaWebpackVersionMatrix(projectRoot = process.cwd()) {
|
|
69
|
+
const { createRequire, pathModule, readFileSync } = await loadNodeRuntimeHelpers();
|
|
70
|
+
const packageJsonPath = pathModule.resolve(projectRoot, "package.json");
|
|
71
|
+
const requireFromProject = createRequire(packageJsonPath);
|
|
72
|
+
return {
|
|
73
|
+
"@typia/unplugin": resolveInstalledPackageVersion(readFileSync, requireFromProject, "@typia/unplugin"),
|
|
74
|
+
"@wordpress/scripts": resolveInstalledPackageVersion(readFileSync, requireFromProject, "@wordpress/scripts"),
|
|
75
|
+
typia: resolveInstalledPackageVersion(readFileSync, requireFromProject, "typia"),
|
|
76
|
+
webpack: resolveWebpackVersion(readFileSync, requireFromProject, createRequire),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function formatInstalledMatrix(versionMatrix) {
|
|
80
|
+
return [
|
|
81
|
+
`typia=${versionMatrix.typia ?? "missing"}`,
|
|
82
|
+
`@typia/unplugin=${versionMatrix["@typia/unplugin"] ?? "missing"}`,
|
|
83
|
+
`@wordpress/scripts=${versionMatrix["@wordpress/scripts"] ?? "missing"}`,
|
|
84
|
+
`webpack=${versionMatrix.webpack ?? "missing"}`,
|
|
85
|
+
].join(", ");
|
|
86
|
+
}
|
|
87
|
+
export async function assertTypiaWebpackCompatibility({ projectRoot = process.cwd(), } = {}) {
|
|
88
|
+
const versionMatrix = await getTypiaWebpackVersionMatrix(projectRoot);
|
|
89
|
+
const isSupported = parseMajorVersion(versionMatrix.typia) === 12 &&
|
|
90
|
+
parseMajorVersion(versionMatrix["@typia/unplugin"]) === 12 &&
|
|
91
|
+
parseMajorVersion(versionMatrix["@wordpress/scripts"]) === 30 &&
|
|
92
|
+
parseMajorVersion(versionMatrix.webpack) === 5;
|
|
93
|
+
if (isSupported) {
|
|
94
|
+
return versionMatrix;
|
|
95
|
+
}
|
|
96
|
+
throw new Error([
|
|
97
|
+
"Unsupported Typia/Webpack toolchain for generated wp-typia projects.",
|
|
98
|
+
`Installed versions: ${formatInstalledMatrix(versionMatrix)}.`,
|
|
99
|
+
"Supported matrix: typia 12.x, @typia/unplugin 12.x, @wordpress/scripts 30.x with webpack 5.x.",
|
|
100
|
+
"Generated project defaults were tested against this matrix.",
|
|
101
|
+
].join(" "));
|
|
102
|
+
}
|
|
103
|
+
export async function loadCompatibleTypiaWebpackPlugin({ importTypiaWebpackPlugin, projectRoot = process.cwd(), }) {
|
|
104
|
+
await assertTypiaWebpackCompatibility({ projectRoot });
|
|
105
|
+
const { default: UnpluginTypia } = await importTypiaWebpackPlugin();
|
|
106
|
+
return UnpluginTypia;
|
|
107
|
+
}
|
|
18
108
|
function mergeEntries(existingEntries, nextEntries, mode) {
|
|
19
109
|
if (!nextEntries) {
|
|
20
110
|
return existingEntries;
|
|
@@ -40,8 +130,11 @@ export function buildScaffoldBlockRegistration(metadata, overrides) {
|
|
|
40
130
|
},
|
|
41
131
|
};
|
|
42
132
|
}
|
|
43
|
-
export async function createTypiaWebpackConfig({ defaultConfig, fs, getArtifactEntries, getEditorEntries, getOptionalModuleEntries, importTypiaWebpackPlugin, isScriptModuleAsset = (assetName) => /(^|\/)(interactivity|view)\.asset\.php$/.test(assetName), moduleEntriesMode = "merge", nonModuleEntriesMode = "merge", path, }) {
|
|
44
|
-
const
|
|
133
|
+
export async function createTypiaWebpackConfig({ defaultConfig, fs, getArtifactEntries, getEditorEntries, getOptionalModuleEntries, importTypiaWebpackPlugin, isScriptModuleAsset = (assetName) => /(^|\/)(interactivity|view)\.asset\.php$/.test(assetName), moduleEntriesMode = "merge", nonModuleEntriesMode = "merge", path, projectRoot = process.cwd(), }) {
|
|
134
|
+
const UnpluginTypia = await loadCompatibleTypiaWebpackPlugin({
|
|
135
|
+
importTypiaWebpackPlugin,
|
|
136
|
+
projectRoot,
|
|
137
|
+
});
|
|
45
138
|
const resolvedDefaultConfig = typeof defaultConfig === "function"
|
|
46
139
|
? await defaultConfig()
|
|
47
140
|
: defaultConfig;
|
|
@@ -3,7 +3,6 @@ import { type EditorFieldDescriptor, type EditorModelOptions, type ManifestDocum
|
|
|
3
3
|
import { type ValidationResult } from "./validation.js";
|
|
4
4
|
export type { EditorFieldDescriptor, EditorFieldOption, EditorModelOptions, ManifestAttribute, ManifestDocument, } from "./editor.js";
|
|
5
5
|
export type { ValidationResult } from "./validation.js";
|
|
6
|
-
type UnknownRecord = Record<string, unknown>;
|
|
7
6
|
export interface InspectorSelectOption {
|
|
8
7
|
label: string;
|
|
9
8
|
value: string;
|
|
@@ -63,11 +62,11 @@ export interface InspectorComponentMap {
|
|
|
63
62
|
export interface UseEditorFieldsResult {
|
|
64
63
|
fields: EditorFieldDescriptor[];
|
|
65
64
|
fieldMap: Map<string, EditorFieldDescriptor>;
|
|
66
|
-
getBooleanValue: (source:
|
|
65
|
+
getBooleanValue: (source: object, path: string, fallback: boolean) => boolean;
|
|
67
66
|
getField: (path: string) => EditorFieldDescriptor | undefined;
|
|
68
|
-
getNumberValue: (source:
|
|
67
|
+
getNumberValue: (source: object, path: string, fallback: number) => number;
|
|
69
68
|
getSelectOptions: (path: string, labelMap?: Record<string, string>) => InspectorSelectOption[];
|
|
70
|
-
getStringValue: (source:
|
|
69
|
+
getStringValue: (source: object, path: string, fallback: string) => string;
|
|
71
70
|
manualFields: EditorFieldDescriptor[];
|
|
72
71
|
supportedFields: EditorFieldDescriptor[];
|
|
73
72
|
}
|
|
@@ -112,7 +111,7 @@ export interface InspectorFieldOverride {
|
|
|
112
111
|
renderUnsupported?: (context: FieldControlRenderContext) => ReactNode;
|
|
113
112
|
step?: number;
|
|
114
113
|
}
|
|
115
|
-
export interface InspectorFromManifestProps<T extends
|
|
114
|
+
export interface InspectorFromManifestProps<T extends object> {
|
|
116
115
|
attributes: T;
|
|
117
116
|
children?: ReactNode;
|
|
118
117
|
components?: InspectorComponentMap;
|
|
@@ -126,4 +125,4 @@ export interface InspectorFromManifestProps<T extends UnknownRecord> {
|
|
|
126
125
|
export declare function useEditorFields(manifest: ManifestDocument, options?: EditorModelOptions): UseEditorFieldsResult;
|
|
127
126
|
export declare function useTypedAttributeUpdater<T extends object>(attributes: T, setAttributes: (attrs: Partial<T>) => void, validate?: (value: T) => ValidationResult<T>): TypedAttributeUpdater<T>;
|
|
128
127
|
export declare function FieldControl({ components, field, help, label, max, min, onChange, options, render, renderUnsupported, step, value, }: FieldControlProps): import("react/jsx-runtime").JSX.Element | null;
|
|
129
|
-
export declare function InspectorFromManifest<T extends
|
|
128
|
+
export declare function InspectorFromManifest<T extends object>({ attributes, children, components, fieldLookup, fieldOverrides, initialOpen, onChange, paths, title, }: InspectorFromManifestProps<T>): import("react/jsx-runtime").JSX.Element;
|