Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87ab8d8

Browse files
committed
chore: major refactor
1 parent de17d9c commit 87ab8d8

File tree

88 files changed

+4176
-3602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+4176
-3602
lines changed

packages/cli/src/builders/__tests__/__snapshots__/phpBuilder.test.ts.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ exports[`createPhpBuilder generates base controller artifacts from the AST chann
4040
"attributes": {},
4141
"nodeType": "Name",
4242
"parts": [
43-
"Demo",
44-
"Plugin",
43+
"DemoPlugin",
4544
"Generated",
4645
"Rest",
4746
],

packages/cli/src/builders/__tests__/phpBuilder.test.ts

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import type { Workspace } from '../../workspace/types';
1515
import { buildPhpPrettyPrinter } from '@wpkernel/php-driver';
1616
import { makeWorkspaceMock } from '../../../tests/workspace.test-support';
1717
import { buildReporter } from '@wpkernel/test-utils/builders/tests/builder-harness.test-support';
18+
import {
19+
createMinimalIr,
20+
createPipelineContext,
21+
} from '../php/test-support/php-builder.test-support';
1822

1923
jest.mock('@wpkernel/php-driver', () => ({
2024
buildPhpPrettyPrinter: jest.fn(() => ({
@@ -55,41 +59,12 @@ function buildWorkspace(): Workspace {
5559
});
5660
}
5761

58-
const ir: IRv1 = {
62+
const ir = createMinimalIr({
5963
meta: {
60-
version: 1,
61-
namespace: 'demo-plugin',
62-
sanitizedNamespace: 'DemoPlugin',
6364
origin: 'wpk.config.ts',
6465
sourcePath: 'wpk.config.ts',
6566
},
66-
config: {
67-
version: 1,
68-
namespace: 'demo-plugin',
69-
schemas: {},
70-
resources: {},
71-
} as IRv1['config'],
72-
schemas: [],
73-
resources: [],
74-
capabilities: [],
75-
capabilityMap: {
76-
sourcePath: undefined,
77-
definitions: [],
78-
fallback: {
79-
capability: 'manage_options',
80-
appliesTo: 'resource',
81-
},
82-
missing: [],
83-
unused: [],
84-
warnings: [],
85-
},
86-
blocks: [],
87-
php: {
88-
namespace: 'Demo\\Plugin',
89-
autoload: 'inc/',
90-
outputDir: '.generated/php',
91-
},
92-
};
67+
});
9368

9469
function setupPrettyPrinterMock() {
9570
const prettyPrint = jest.fn(async ({ program }) => ({
@@ -108,11 +83,7 @@ describe('createPhpBuilder', () => {
10883
it('queues helper programs in the channel before writing', async () => {
10984
const workspace = buildWorkspace();
11085
const reporter = buildReporter();
111-
const context = {
112-
workspace,
113-
reporter,
114-
phase: 'generate' as const,
115-
};
86+
const context = createPipelineContext({ workspace, reporter });
11687
const queueWrite = jest.fn();
11788
const output: BuilderOutput = {
11889
actions: [],
@@ -222,11 +193,7 @@ describe('createPhpBuilder', () => {
222193
it('reports capability map warnings when fallbacks are required', async () => {
223194
const workspace = buildWorkspace();
224195
const reporter = buildReporter();
225-
const context = {
226-
workspace,
227-
reporter,
228-
phase: 'generate' as const,
229-
};
196+
const context = createPipelineContext({ workspace, reporter });
230197

231198
const helper = createPhpCapabilityHelper();
232199
const queueWrite = jest.fn();
@@ -282,7 +249,8 @@ describe('createPhpBuilder', () => {
282249
'Capability falling back to default capability.',
283250
expect.objectContaining({
284251
capability: 'manage_todo',
285-
capabilities: ['manage_options'],
252+
capabilities: ['manage_demoplugin'],
253+
fallbackCapability: 'manage_demoplugin',
286254
scope: 'resource',
287255
})
288256
);
@@ -300,11 +268,11 @@ describe('createPhpBuilder', () => {
300268

301269
await builder.apply(
302270
{
303-
context: {
271+
context: createPipelineContext({
304272
workspace,
305273
reporter,
306274
phase: 'init',
307-
},
275+
}),
308276
input: {
309277
phase: 'init',
310278
options: {
@@ -342,11 +310,7 @@ describe('createPhpBuilder', () => {
342310

343311
await builder.apply(
344312
{
345-
context: {
346-
workspace,
347-
reporter,
348-
phase: 'generate',
349-
},
313+
context: createPipelineContext({ workspace, reporter }),
350314
input: {
351315
phase: 'generate',
352316
options: {

packages/cli/src/builders/blocks/__tests__/derived.test.ts renamed to packages/cli/src/builders/__tests__/shared.blocks.derived.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { deriveResourceBlocks } from '../derived';
1+
import { deriveResourceBlocks } from '../shared.blocks.derived';
22
import type {
33
IRBlock,
44
IRHashProvenance,
@@ -7,8 +7,8 @@ import type {
77
IRRoute,
88
IRSchema,
99
IRv1,
10-
} from '../../../ir/publicTypes';
11-
import type { WPKernelConfigV1 } from '../../../config/types';
10+
} from '../../ir/publicTypes';
11+
import type { WPKernelConfigV1 } from '../../config/types';
1212

1313
describe('deriveResourceBlocks', () => {
1414
it('derives manifest attributes from schema definitions', () => {

packages/cli/src/builders/blocks/__tests__/manifest.test.ts renamed to packages/cli/src/builders/__tests__/shared.blocks.manifest.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
withWorkspace as baseWithWorkspace,
44
type BuilderHarnessContext,
55
} from '@wpkernel/test-utils/builders/tests/ts.test-support';
6-
import { buildWorkspace } from '../../../workspace';
7-
import type { Workspace } from '../../../workspace';
8-
import type { IRBlock } from '../../../ir/publicTypes';
9-
import { collectBlockManifests } from '../manifest';
6+
import { buildWorkspace } from '../../workspace';
7+
import type { Workspace } from '../../workspace';
8+
import type { IRBlock } from '../../ir/publicTypes';
9+
import { collectBlockManifests } from '../shared.blocks.manifest';
1010

1111
const withWorkspace = (
1212
run: (context: BuilderHarnessContext<Workspace>) => Promise<void>

packages/cli/src/builders/bundler.ts

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import type {
88
PipelineContext,
99
} from '../runtime/types';
1010
import type { Workspace } from '../workspace/types';
11+
import {
12+
type PackageJsonLike,
13+
type RollupDriverArtifacts,
14+
type AssetManifestUIEntry,
15+
type RollupDriverConfig,
16+
type AssetManifest,
17+
} from './types';
1118

1219
const BUNDLER_TRANSACTION_LABEL = 'builder.generate.bundler.core';
1320
const BUNDLER_CONFIG_PATH = path.posix.join('.wpk', 'bundler', 'config.json');
@@ -43,54 +50,16 @@ const REACT_EXTERNALS = [
4350
'react/jsx-dev-runtime',
4451
];
4552

46-
interface PackageJsonLike {
47-
readonly name?: string;
48-
readonly version?: string;
49-
readonly peerDependencies?: Record<string, string>;
50-
readonly dependencies?: Record<string, string>;
51-
}
52-
53-
interface RollupDriverConfig {
54-
readonly driver: 'rollup';
55-
readonly input: Record<string, string>;
56-
readonly outputDir: string;
57-
readonly format: 'esm';
58-
readonly external: readonly string[];
59-
readonly globals: Record<string, string>;
60-
readonly alias: readonly {
61-
readonly find: string;
62-
readonly replacement: string;
63-
}[];
64-
readonly sourcemap: {
65-
readonly development: boolean;
66-
readonly production: boolean;
67-
};
68-
readonly optimizeDeps: { readonly exclude: readonly string[] };
69-
readonly assetManifest: { readonly path: string };
70-
}
71-
72-
interface AssetManifestUIEntry {
73-
readonly handle: string;
74-
readonly asset: string;
75-
readonly script: string;
76-
}
77-
78-
interface AssetManifest {
79-
readonly entry: string;
80-
readonly dependencies: readonly string[];
81-
readonly version: string;
82-
readonly ui?: AssetManifestUIEntry;
83-
}
84-
85-
interface RollupDriverArtifacts {
86-
readonly config: RollupDriverConfig;
87-
readonly assetManifest: AssetManifest;
88-
}
89-
9053
function sortUnique(values: Iterable<string>): string[] {
9154
return Array.from(new Set(values)).sort();
9255
}
9356

57+
/**
58+
* Converts a dependency slug into the matching `wp.foo` global name.
59+
*
60+
* @param slug
61+
* @category AST Builders
62+
*/
9463
export function toWordPressGlobal(slug: string): string {
9564
const segments = slug.split('-');
9665
const formatted = segments
@@ -146,6 +115,13 @@ export function buildExternalList(pkg: PackageJsonLike | null): string[] {
146115
]);
147116
}
148117

118+
/**
119+
* Maps external module IDs to the globals Rollup should reference.
120+
*
121+
* @category AST Builders
122+
* @param externals - The list of externalized package names.
123+
* @returns Record of module ID → global expression.
124+
*/
149125
export function buildGlobalsMap(
150126
externals: readonly string[]
151127
): Record<string, string> {

packages/cli/src/builders/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
export { createBundler } from './bundler';
22
export { createPhpBuilder } from './php';
3-
export type {
4-
CreatePhpBuilderOptions,
5-
PhpDriverConfigurationOptions,
6-
} from './php';
7-
export { createTsBuilder } from './ts';
8-
export { createTsCapabilityBuilder } from './ts/capability-builder';
9-
export { createTsIndexBuilder } from './ts/index-builder';
3+
export type { CreatePhpBuilderOptions } from './php';
4+
export type { PhpDriverConfigurationOptions } from '@wpkernel/php-json-ast';
5+
export {
6+
createTsBuilder,
7+
createTsCapabilityBuilder,
8+
createTsIndexBuilder,
9+
createJsBlocksBuilder,
10+
buildTsFormatter,
11+
} from './ts';
1012
export type {
1113
CreateTsBuilderOptions,
1214
TsBuilderCreator,
@@ -15,8 +17,7 @@ export type {
1517
TsBuilderAfterEmitOptions,
1618
TsBuilderEmitOptions,
1719
ResourceDescriptor,
18-
} from './ts';
19-
export { createJsBlocksBuilder } from './ts/blocks';
20+
} from './types';
2021
export { createPatcher } from './patcher';
2122
export { createApplyPlanBuilder } from './plan';
2223
export { createPhpDriverInstaller } from '@wpkernel/php-driver';

0 commit comments

Comments
 (0)