diff --git a/packages/nx-extensions/src/executors/package-json/executor.ts b/packages/nx-extensions/src/executors/package-json/executor.ts index ff4e245d9e6..3540545a1a8 100644 --- a/packages/nx-extensions/src/executors/package-json/executor.ts +++ b/packages/nx-extensions/src/executors/package-json/executor.ts @@ -1,6 +1,11 @@ import * as fs from 'fs'; import { createPackageJson } from '@nx/js'; -import type { ExecutorContext, ProjectGraphDependency } from '@nx/devkit'; +import type { + ExecutorContext, + FileData, + ProjectFileMap, + ProjectGraphDependency, +} from '@nx/devkit'; import { serializeJson, logger, @@ -12,6 +17,8 @@ import { HelperDependency, readTsConfig, } from '@nx/js'; +import { readFileMapCache } from 'nx/src/project-graph/nx-deps-cache'; +import { fileDataDepTarget } from 'nx/src/config/project-graph'; import type { PackageJsonExecutorSchema } from './schema'; interface ExecutorEvent { @@ -52,7 +59,12 @@ export default async function* packageJsonExecutor( }); } - const monorepoDependencies = getMonorepoDependencies(context); + const sourceFileMap = getSourceOnlyFileMap(); + const sourceDeps = getSourceDependencyTargets( + sourceFileMap, + context.projectName + ); + const monorepoDependencies = getMonorepoDependencies(context, sourceDeps); // Read optional dependencies from the original package.json let originalOptionalDependencies: Record | undefined; @@ -75,7 +87,9 @@ export default async function* packageJsonExecutor( context, helperDependencies, monorepoDependencies, - originalOptionalDependencies + originalOptionalDependencies, + sourceFileMap, + sourceDeps ); if (built === false) { return { @@ -109,7 +123,9 @@ async function buildPackageJson( context: ExecutorContext, helperDependencies: ProjectGraphDependency[], monorepoDependencies: MonorepoDependency[], - originalOptionalDependencies?: Record + originalOptionalDependencies?: Record, + sourceFileMap?: ProjectFileMap, + sourceDeps?: Set ) { const packageJson = createPackageJson( context.projectName, @@ -119,7 +135,8 @@ async function buildPackageJson( root: context.root, isProduction: true, helperDependencies: helperDependencies.map((dep) => dep.target), - } as any + } as any, + sourceFileMap ); let main = packageJson.main ?? event.outfile; @@ -136,6 +153,17 @@ async function buildPackageJson( packageJson.dependencies = {}; } + // Remove external dependencies that are not directly imported by source + // files. createPackageJson flattens transitive dependencies, but published + // libraries should only declare their direct dependencies. + if (sourceDeps) { + for (const name of Object.keys(packageJson.dependencies)) { + if (!sourceDeps.has(`npm:${name}`)) { + delete packageJson.dependencies[name]; + } + } + } + for (const dep of monorepoDependencies) { packageJson.dependencies[dep.name] = dep.version; } @@ -178,12 +206,6 @@ async function buildPackageJson( options.outputPath + '/package.json', serializeJson(packageJson) ); - - // Lock file doesn't work with monorepoDependencies - // fs.writeFileSync( - // getLockFileName(), - // createLockFile(packageJson) - // ); } interface MonorepoDependency { @@ -191,8 +213,41 @@ interface MonorepoDependency { version: string; } +function isSourceFile(filePath: string): boolean { + return !/\/tests?\//.test(filePath); +} + +function getSourceOnlyFileMap(): ProjectFileMap { + const cache = readFileMapCache(); + const fullFileMap = cache?.fileMap?.projectFileMap || {}; + const filtered: ProjectFileMap = {}; + for (const [project, files] of Object.entries(fullFileMap)) { + filtered[project] = (files as FileData[]).filter((f) => + isSourceFile(f.file) + ); + } + return filtered; +} + +function getSourceDependencyTargets( + sourceFileMap: ProjectFileMap, + projectName?: string +): Set { + const targets = new Set(); + if (projectName) { + const projectFiles = sourceFileMap[projectName] || []; + for (const fileData of projectFiles) { + for (const dep of fileData.deps || []) { + targets.add(fileDataDepTarget(dep)); + } + } + } + return targets; +} + function getMonorepoDependencies( - context: ExecutorContext + context: ExecutorContext, + sourceDeps: Set ): MonorepoDependency[] { const monorepoDeps: MonorepoDependency[] = []; for (const repoDep of context.projectGraph.dependencies[ @@ -207,6 +262,9 @@ function getMonorepoDependencies( if (!(repoDep.target in context.projectGraph.nodes)) { continue; } + if (!sourceDeps.has(repoDep.target)) { + continue; + } const targetSourceRoot = context.projectGraph.nodes[repoDep.target].data.root; const packageJsonPath = `${targetSourceRoot}/package.json`; diff --git a/packages/php-wasm/node-polyfills/src/lib/blob.spec.ts b/packages/php-wasm/node-polyfills/src/test/blob.spec.ts similarity index 99% rename from packages/php-wasm/node-polyfills/src/lib/blob.spec.ts rename to packages/php-wasm/node-polyfills/src/test/blob.spec.ts index d09925785c4..8539bd476db 100644 --- a/packages/php-wasm/node-polyfills/src/lib/blob.spec.ts +++ b/packages/php-wasm/node-polyfills/src/test/blob.spec.ts @@ -1,4 +1,4 @@ -import './blob'; +import '../lib/blob'; describe('File class', () => { it('Should exist', () => { diff --git a/packages/php-wasm/node-polyfills/src/lib/custom-event.spec.ts b/packages/php-wasm/node-polyfills/src/test/custom-event.spec.ts similarity index 92% rename from packages/php-wasm/node-polyfills/src/lib/custom-event.spec.ts rename to packages/php-wasm/node-polyfills/src/test/custom-event.spec.ts index 7cdc263e91a..7d041c98f0d 100644 --- a/packages/php-wasm/node-polyfills/src/lib/custom-event.spec.ts +++ b/packages/php-wasm/node-polyfills/src/test/custom-event.spec.ts @@ -1,4 +1,4 @@ -import './custom-event'; +import '../lib/custom-event'; describe('CustomEvent class', () => { it('Should exist', () => { diff --git a/packages/php-wasm/progress/src/lib/progress-tracker.spec.ts b/packages/php-wasm/progress/src/test/progress-tracker.spec.ts similarity index 98% rename from packages/php-wasm/progress/src/lib/progress-tracker.spec.ts rename to packages/php-wasm/progress/src/test/progress-tracker.spec.ts index b03f89bf1cb..73158786c43 100644 --- a/packages/php-wasm/progress/src/lib/progress-tracker.spec.ts +++ b/packages/php-wasm/progress/src/test/progress-tracker.spec.ts @@ -1,5 +1,5 @@ -import { ProgressTracker } from './progress-tracker'; -import type { ProgressTrackerEvent } from './progress-tracker'; +import { ProgressTracker } from '../lib/progress-tracker'; +import type { ProgressTrackerEvent } from '../lib/progress-tracker'; describe('Tracks total progress', () => { it('A single ProgressTracker populated via fillSlowly (stopBeforeFinishing=true)', async () => { diff --git a/packages/php-wasm/scopes/src/index.ts b/packages/php-wasm/scopes/src/index.ts index 0b39b64dfe8..2127c2a6f66 100644 --- a/packages/php-wasm/scopes/src/index.ts +++ b/packages/php-wasm/scopes/src/index.ts @@ -1,117 +1 @@ -/** - * Scopes are unique strings, like `my-site`, used to uniquely brand - * the outgoing HTTP traffic from each browser tab. This helps the - * main thread distinguish between the relevant and irrelevant - * messages received from the Service Worker. - * - * Scopes are included in the `PHPRequestHandler.absoluteUrl` as follows: - * - * An **unscoped** URL: http://localhost:8778/wp-login.php - * A **scoped** URL: http://localhost:8778/scope:my-site/wp-login.php - * - * For more information, see the README section on scopes. - */ - -/** - * Checks if the given URL contains scope information. - * - * @example - * ```js - * isURLScoped(new URL('http://localhost/scope:my-site/index.php')); - * // true - * - * isURLScoped(new URL('http://localhost/index.php')); - * // false - * ``` - * - * @param url The URL to check. - * @returns `true` if the URL contains scope information, `false` otherwise. - */ -export function isURLScoped(url: URL): boolean { - return url.pathname.startsWith(`/scope:`); -} - -/** - * Returns the scope stored in the given URL. - * - * @example - * ```js - * getScopeFromURL(new URL('http://localhost/scope:my-site/index.php')); - * // '96253' - * - * getScopeFromURL(new URL('http://localhost/index.php')); - * // null - * ``` - * - * @param url The URL. - * @returns The scope if the URL contains a scope, `null` otherwise. - */ -export function getURLScope(url: URL): string | null { - if (isURLScoped(url)) { - return url.pathname.split('/')[1].split(':')[1]; - } - return null; -} - -/** - * Returns a new URL with the requested scope information. - * - * @example - * ```js - * setURLScope(new URL('http://localhost/index.php'), 'my-site'); - * // URL('http://localhost/scope:my-site/index.php') - * - * setURLScope(new URL('http://localhost/scope:my-site/index.php'), 'my-site'); - * // URL('http://localhost/scope:my-site/index.php') - * - * setURLScope(new URL('http://localhost/index.php'), null); - * // URL('http://localhost/index.php') - * ``` - * - * @param url The URL to scope. - * @param scope The scope value. - * @returns A new URL with the scope information in it. - */ -export function setURLScope(url: URL | string, scope: string | null): URL { - let newUrl = new URL(url); - - if (isURLScoped(newUrl)) { - if (scope) { - const parts = newUrl.pathname.split('/'); - parts[1] = `scope:${scope}`; - newUrl.pathname = parts.join('/'); - } else { - newUrl = removeURLScope(newUrl); - } - } else if (scope) { - const suffix = newUrl.pathname === '/' ? '' : newUrl.pathname; - newUrl.pathname = `/scope:${scope}${suffix}`; - } - - return newUrl; -} - -/** - * Returns a new URL without any scope information. - * - * @example - * ```js - * removeURLScope(new URL('http://localhost/scope:my-site/index.php')); - * // URL('http://localhost/index.php') - * - * removeURLScope(new URL('http://localhost/index.php')); - * // URL('http://localhost/index.php') - * ``` - * - * @param url The URL to remove scope information from. - * @returns A new URL without the scope information. - */ -export function removeURLScope(url: URL): URL { - if (!isURLScoped(url)) { - return url; - } - const newUrl = new URL(url); - const parts = newUrl.pathname.split('/'); - newUrl.pathname = '/' + parts.slice(2).join('/'); - return newUrl; -} +export * from './lib/scope'; diff --git a/packages/php-wasm/scopes/src/lib/scope.ts b/packages/php-wasm/scopes/src/lib/scope.ts new file mode 100644 index 00000000000..0b39b64dfe8 --- /dev/null +++ b/packages/php-wasm/scopes/src/lib/scope.ts @@ -0,0 +1,117 @@ +/** + * Scopes are unique strings, like `my-site`, used to uniquely brand + * the outgoing HTTP traffic from each browser tab. This helps the + * main thread distinguish between the relevant and irrelevant + * messages received from the Service Worker. + * + * Scopes are included in the `PHPRequestHandler.absoluteUrl` as follows: + * + * An **unscoped** URL: http://localhost:8778/wp-login.php + * A **scoped** URL: http://localhost:8778/scope:my-site/wp-login.php + * + * For more information, see the README section on scopes. + */ + +/** + * Checks if the given URL contains scope information. + * + * @example + * ```js + * isURLScoped(new URL('http://localhost/scope:my-site/index.php')); + * // true + * + * isURLScoped(new URL('http://localhost/index.php')); + * // false + * ``` + * + * @param url The URL to check. + * @returns `true` if the URL contains scope information, `false` otherwise. + */ +export function isURLScoped(url: URL): boolean { + return url.pathname.startsWith(`/scope:`); +} + +/** + * Returns the scope stored in the given URL. + * + * @example + * ```js + * getScopeFromURL(new URL('http://localhost/scope:my-site/index.php')); + * // '96253' + * + * getScopeFromURL(new URL('http://localhost/index.php')); + * // null + * ``` + * + * @param url The URL. + * @returns The scope if the URL contains a scope, `null` otherwise. + */ +export function getURLScope(url: URL): string | null { + if (isURLScoped(url)) { + return url.pathname.split('/')[1].split(':')[1]; + } + return null; +} + +/** + * Returns a new URL with the requested scope information. + * + * @example + * ```js + * setURLScope(new URL('http://localhost/index.php'), 'my-site'); + * // URL('http://localhost/scope:my-site/index.php') + * + * setURLScope(new URL('http://localhost/scope:my-site/index.php'), 'my-site'); + * // URL('http://localhost/scope:my-site/index.php') + * + * setURLScope(new URL('http://localhost/index.php'), null); + * // URL('http://localhost/index.php') + * ``` + * + * @param url The URL to scope. + * @param scope The scope value. + * @returns A new URL with the scope information in it. + */ +export function setURLScope(url: URL | string, scope: string | null): URL { + let newUrl = new URL(url); + + if (isURLScoped(newUrl)) { + if (scope) { + const parts = newUrl.pathname.split('/'); + parts[1] = `scope:${scope}`; + newUrl.pathname = parts.join('/'); + } else { + newUrl = removeURLScope(newUrl); + } + } else if (scope) { + const suffix = newUrl.pathname === '/' ? '' : newUrl.pathname; + newUrl.pathname = `/scope:${scope}${suffix}`; + } + + return newUrl; +} + +/** + * Returns a new URL without any scope information. + * + * @example + * ```js + * removeURLScope(new URL('http://localhost/scope:my-site/index.php')); + * // URL('http://localhost/index.php') + * + * removeURLScope(new URL('http://localhost/index.php')); + * // URL('http://localhost/index.php') + * ``` + * + * @param url The URL to remove scope information from. + * @returns A new URL without the scope information. + */ +export function removeURLScope(url: URL): URL { + if (!isURLScoped(url)) { + return url; + } + const newUrl = new URL(url); + const parts = newUrl.pathname.split('/'); + newUrl.pathname = '/' + parts.slice(2).join('/'); + return newUrl; +} diff --git a/packages/php-wasm/scopes/src/index.spec.ts b/packages/php-wasm/scopes/src/test/scope.test.ts similarity index 95% rename from packages/php-wasm/scopes/src/index.spec.ts rename to packages/php-wasm/scopes/src/test/scope.test.ts index d7472711f88..eb802c9f6c8 100644 --- a/packages/php-wasm/scopes/src/index.spec.ts +++ b/packages/php-wasm/scopes/src/test/scope.test.ts @@ -1,4 +1,9 @@ -import { getURLScope, isURLScoped, removeURLScope, setURLScope } from './index'; +import { + getURLScope, + isURLScoped, + removeURLScope, + setURLScope, +} from '../lib/scope'; describe('getURLScope', () => { it('should return the scope from a scoped URL', () => { diff --git a/packages/php-wasm/universal/src/lib/comlink-sync.spec.ts b/packages/php-wasm/universal/src/test/comlink-sync.spec.ts similarity index 96% rename from packages/php-wasm/universal/src/lib/comlink-sync.spec.ts rename to packages/php-wasm/universal/src/test/comlink-sync.spec.ts index 4f83a667c11..a3cba56d2b2 100644 --- a/packages/php-wasm/universal/src/lib/comlink-sync.spec.ts +++ b/packages/php-wasm/universal/src/test/comlink-sync.spec.ts @@ -1,6 +1,5 @@ -import { describe, it, expect } from 'vitest'; import { MessageChannel, Worker as NodeWorker } from 'worker_threads'; -import { NodeSABSyncReceiveMessageTransport } from './comlink-sync'; +import { NodeSABSyncReceiveMessageTransport } from '../lib/comlink-sync'; // Node.js < 23 does not support TypeScript and won't run this test. const nodeVersion = parseInt(process.version.slice(1).split('.')[0], 10); @@ -85,13 +84,13 @@ describe.skipIf(nodeVersion < 23)('Comlink Sync Communication Tests', () => { }); } - const comlinkSyncPath = import.meta.dirname + '/comlink-sync.ts'; + const comlinkSyncPath = import.meta.dirname + '/../lib/comlink-sync.ts'; // Simple inline worker code that doesn't depend on complex imports const serverWorkerCode = ` import { parentPort } from 'worker_threads'; import { exposeSync, NodeSABSyncReceiveMessageTransport } from "${comlinkSyncPath}"; export {}; - + const testAPI = { ping: () => 'pong', add: (a, b) => a + b, @@ -100,7 +99,7 @@ describe.skipIf(nodeVersion < 23)('Comlink Sync Communication Tests', () => { processArray: (numbers) => numbers.reduce((sum, num) => sum + num, 0), throwError: () => { throw new Error('Test error from sync API server'); } }; - + parentPort?.on('message', async (data) => { if (data.type === 'setup' && data.port) { const transport = await NodeSABSyncReceiveMessageTransport.create(); @@ -114,7 +113,7 @@ describe.skipIf(nodeVersion < 23)('Comlink Sync Communication Tests', () => { const clientWorkerCode = ` import { parentPort } from 'worker_threads'; import { wrapSync, NodeSABSyncReceiveMessageTransport } from "${comlinkSyncPath}"; - + let syncAPI = null; parentPort?.on('message', async (data) => { if (data.type === 'setup' && data.port) { @@ -125,7 +124,7 @@ describe.skipIf(nodeVersion < 23)('Comlink Sync Communication Tests', () => { try { const testName = data.testName; let result; - + switch (testName) { case 'ping': result = await syncAPI.ping(); @@ -153,16 +152,16 @@ describe.skipIf(nodeVersion < 23)('Comlink Sync Communication Tests', () => { default: result = 'Unknown test: ' + testName; } - - parentPort?.postMessage({ - type: 'test-result', + + parentPort?.postMessage({ + type: 'test-result', testName, result, success: true }); } catch (error) { - parentPort?.postMessage({ - type: 'test-result', + parentPort?.postMessage({ + type: 'test-result', testName: data.testName, result: error.message, success: false @@ -170,7 +169,7 @@ describe.skipIf(nodeVersion < 23)('Comlink Sync Communication Tests', () => { } } }); - + parentPort?.postMessage({ type: 'loaded' }); `; diff --git a/packages/php-wasm/universal/src/lib/file-lock-interval-tree.spec.ts b/packages/php-wasm/universal/src/test/file-lock-interval-tree.spec.ts similarity index 98% rename from packages/php-wasm/universal/src/lib/file-lock-interval-tree.spec.ts rename to packages/php-wasm/universal/src/test/file-lock-interval-tree.spec.ts index 4323fdf45e4..c038c2db72b 100644 --- a/packages/php-wasm/universal/src/lib/file-lock-interval-tree.spec.ts +++ b/packages/php-wasm/universal/src/test/file-lock-interval-tree.spec.ts @@ -1,5 +1,5 @@ -import { FileLockIntervalTree } from './file-lock-interval-tree'; -import type { LockedRange } from './file-lock-manager'; +import { FileLockIntervalTree } from '../lib/file-lock-interval-tree'; +import type { LockedRange } from '../lib/file-lock-manager'; function sharedLock(start: bigint, end: bigint, pid = 1, fd = 1): LockedRange { return { type: 'shared', start, end, pid, fd }; diff --git a/packages/php-wasm/universal/src/lib/file-lock-manager-in-memory.spec.ts b/packages/php-wasm/universal/src/test/file-lock-manager-in-memory.spec.ts similarity index 99% rename from packages/php-wasm/universal/src/lib/file-lock-manager-in-memory.spec.ts rename to packages/php-wasm/universal/src/test/file-lock-manager-in-memory.spec.ts index 8db0609c84e..a388b686d7f 100644 --- a/packages/php-wasm/universal/src/lib/file-lock-manager-in-memory.spec.ts +++ b/packages/php-wasm/universal/src/test/file-lock-manager-in-memory.spec.ts @@ -1,5 +1,5 @@ import { writeFileSync, unlinkSync } from 'fs'; -import { FileLockManagerInMemory } from './file-lock-manager-in-memory'; +import { FileLockManagerInMemory } from '../lib/file-lock-manager-in-memory'; import type { WholeFileLockOp } from '../lib/file-lock-manager'; const TEST_FILE1 = new URL('test1.txt', import.meta.url).pathname; diff --git a/packages/php-wasm/universal/src/lib/http-cookie-store.spec.ts b/packages/php-wasm/universal/src/test/http-cookie-store.spec.ts similarity index 90% rename from packages/php-wasm/universal/src/lib/http-cookie-store.spec.ts rename to packages/php-wasm/universal/src/test/http-cookie-store.spec.ts index fad03d69500..13ca5f8a3f9 100644 --- a/packages/php-wasm/universal/src/lib/http-cookie-store.spec.ts +++ b/packages/php-wasm/universal/src/test/http-cookie-store.spec.ts @@ -1,4 +1,4 @@ -import { HttpCookieStore } from './http-cookie-store'; +import { HttpCookieStore } from '../lib/http-cookie-store'; describe('HTTPCookieStore', () => { it('should store and retrieve cookies', () => { diff --git a/packages/php-wasm/universal/src/lib/object-pool-proxy.spec.ts b/packages/php-wasm/universal/src/test/object-pool-proxy.spec.ts similarity index 98% rename from packages/php-wasm/universal/src/lib/object-pool-proxy.spec.ts rename to packages/php-wasm/universal/src/test/object-pool-proxy.spec.ts index c2509e5619b..bb09c1d28ec 100644 --- a/packages/php-wasm/universal/src/lib/object-pool-proxy.spec.ts +++ b/packages/php-wasm/universal/src/test/object-pool-proxy.spec.ts @@ -1,5 +1,4 @@ -import { describe, it, expect } from 'vitest'; -import { createObjectPoolProxy } from './object-pool-proxy'; +import { createObjectPoolProxy } from '../lib/object-pool-proxy'; describe('createPoolProxy', () => { it('throws if no instances are provided', () => { diff --git a/packages/php-wasm/universal/src/lib/php-request-handler.spec.ts b/packages/php-wasm/universal/src/test/php-request-handler.spec.ts similarity index 98% rename from packages/php-wasm/universal/src/lib/php-request-handler.spec.ts rename to packages/php-wasm/universal/src/test/php-request-handler.spec.ts index 31cdd80b9a5..5956ebceba6 100644 --- a/packages/php-wasm/universal/src/lib/php-request-handler.spec.ts +++ b/packages/php-wasm/universal/src/test/php-request-handler.spec.ts @@ -1,7 +1,6 @@ -import { describe, expect, it, vi } from 'vitest'; -import { PHPRequestHandler } from './php-request-handler'; -import { PHPResponse, StreamedPHPResponse } from './php-response'; -import type { PHP } from './php'; +import { PHPRequestHandler } from '../lib/php-request-handler'; +import { PHPResponse, StreamedPHPResponse } from '../lib/php-response'; +import type { PHP } from '../lib/php'; /** * Creates a mock PHP instance with a simulated filesystem. diff --git a/packages/php-wasm/universal/src/lib/php-response.spec.ts b/packages/php-wasm/universal/src/test/php-response.spec.ts similarity index 99% rename from packages/php-wasm/universal/src/lib/php-response.spec.ts rename to packages/php-wasm/universal/src/test/php-response.spec.ts index 64d5a5d95b4..d6c76afd63b 100644 --- a/packages/php-wasm/universal/src/lib/php-response.spec.ts +++ b/packages/php-wasm/universal/src/test/php-response.spec.ts @@ -1,5 +1,4 @@ -import { describe, expect, it } from 'vitest'; -import { PHPResponse, StreamedPHPResponse } from './php-response'; +import { PHPResponse, StreamedPHPResponse } from '../lib/php-response'; /** * Creates a ReadableStream from a string. diff --git a/packages/php-wasm/universal/src/lib/php-worker.spec.ts b/packages/php-wasm/universal/src/test/php-worker.spec.ts similarity index 94% rename from packages/php-wasm/universal/src/lib/php-worker.spec.ts rename to packages/php-wasm/universal/src/test/php-worker.spec.ts index 4a87f67f469..474a79af4b6 100644 --- a/packages/php-wasm/universal/src/lib/php-worker.spec.ts +++ b/packages/php-wasm/universal/src/test/php-worker.spec.ts @@ -1,6 +1,5 @@ -import { PHPWorker } from './php-worker'; -import { describe, expect, test, vi } from 'vitest'; -import type { PHP } from './php'; +import { PHPWorker } from '../lib/php-worker'; +import type { PHP } from '../lib/php'; type PhpEvent = { type: string; [key: string]: unknown }; type PhpEventListener = (event: PhpEvent) => void | Promise; diff --git a/packages/php-wasm/universal/src/lib/process-id-allocator.spec.ts b/packages/php-wasm/universal/src/test/process-id-allocator.spec.ts similarity index 96% rename from packages/php-wasm/universal/src/lib/process-id-allocator.spec.ts rename to packages/php-wasm/universal/src/test/process-id-allocator.spec.ts index ae9aad82ac9..c7638f92cd6 100644 --- a/packages/php-wasm/universal/src/lib/process-id-allocator.spec.ts +++ b/packages/php-wasm/universal/src/test/process-id-allocator.spec.ts @@ -1,5 +1,4 @@ -import { describe, it, expect } from 'vitest'; -import { ProcessIdAllocator } from './process-id-allocator'; +import { ProcessIdAllocator } from '../lib/process-id-allocator'; describe('ProcessIdAllocator', () => { it('claims IDs starting from initialId', () => { diff --git a/packages/php-wasm/util/src/lib/create-spawn-handler.spec.ts b/packages/php-wasm/util/src/test/create-spawn-handler.spec.ts similarity index 92% rename from packages/php-wasm/util/src/lib/create-spawn-handler.spec.ts rename to packages/php-wasm/util/src/test/create-spawn-handler.spec.ts index 4ddfbf5f1a8..6657500fb57 100644 --- a/packages/php-wasm/util/src/lib/create-spawn-handler.spec.ts +++ b/packages/php-wasm/util/src/test/create-spawn-handler.spec.ts @@ -1,5 +1,5 @@ -import type { ProcessApi } from './create-spawn-handler'; -import { createSpawnHandler } from './create-spawn-handler'; +import type { ProcessApi } from '../lib/create-spawn-handler'; +import { createSpawnHandler } from '../lib/create-spawn-handler'; describe('createSpawnHandler', () => { it('should create and execute a spawn handler', async () => { diff --git a/packages/php-wasm/util/src/lib/paths.spec.ts b/packages/php-wasm/util/src/test/paths.spec.ts similarity index 99% rename from packages/php-wasm/util/src/lib/paths.spec.ts rename to packages/php-wasm/util/src/test/paths.spec.ts index ad3794cebc6..a54c03999dd 100644 --- a/packages/php-wasm/util/src/lib/paths.spec.ts +++ b/packages/php-wasm/util/src/test/paths.spec.ts @@ -4,7 +4,7 @@ import { joinPaths, normalizePath, toPosixPath, -} from './paths'; +} from '../lib/paths'; describe('joinPaths', () => { it('should join paths correctly', () => { diff --git a/packages/php-wasm/util/src/lib/semaphore.spec.ts b/packages/php-wasm/util/src/test/semaphore.spec.ts similarity index 96% rename from packages/php-wasm/util/src/lib/semaphore.spec.ts rename to packages/php-wasm/util/src/test/semaphore.spec.ts index d5858d05d14..1336049d1bc 100644 --- a/packages/php-wasm/util/src/lib/semaphore.spec.ts +++ b/packages/php-wasm/util/src/test/semaphore.spec.ts @@ -1,4 +1,4 @@ -import Semaphore, { AcquireTimeoutError } from './semaphore'; +import Semaphore, { AcquireTimeoutError } from '../lib/semaphore'; describe('RequestsPerIntervaledSemaphore', () => { it('should limit the number of concurrent lock holders', async () => { diff --git a/packages/php-wasm/util/src/lib/split-shell-command.spec.ts b/packages/php-wasm/util/src/test/split-shell-command.spec.ts similarity index 97% rename from packages/php-wasm/util/src/lib/split-shell-command.spec.ts rename to packages/php-wasm/util/src/test/split-shell-command.spec.ts index 90ac6c146d9..e6597c07a43 100644 --- a/packages/php-wasm/util/src/lib/split-shell-command.spec.ts +++ b/packages/php-wasm/util/src/test/split-shell-command.spec.ts @@ -1,4 +1,4 @@ -import { splitShellCommand } from './split-shell-command'; +import { splitShellCommand } from '../lib/split-shell-command'; describe('splitShellCommand', () => { it('Should split a shell command into an array', () => { diff --git a/packages/php-wasm/web-service-worker/src/index.ts b/packages/php-wasm/web-service-worker/src/index.ts index b627feb5087..4714973479f 100644 --- a/packages/php-wasm/web-service-worker/src/index.ts +++ b/packages/php-wasm/web-service-worker/src/index.ts @@ -1,4 +1,4 @@ -export * from './utils'; -export * from './messaging'; -export { fetchWithCorsProxy } from './fetch-with-cors-proxy'; -export { FirewallInterferenceError } from './firewall-interference-error'; +export * from './lib/utils'; +export * from './lib/messaging'; +export { fetchWithCorsProxy } from './lib/fetch-with-cors-proxy'; +export { FirewallInterferenceError } from './lib/firewall-interference-error'; diff --git a/packages/php-wasm/web-service-worker/src/fetch-with-cors-proxy.ts b/packages/php-wasm/web-service-worker/src/lib/fetch-with-cors-proxy.ts similarity index 100% rename from packages/php-wasm/web-service-worker/src/fetch-with-cors-proxy.ts rename to packages/php-wasm/web-service-worker/src/lib/fetch-with-cors-proxy.ts diff --git a/packages/php-wasm/web-service-worker/src/firewall-interference-error.ts b/packages/php-wasm/web-service-worker/src/lib/firewall-interference-error.ts similarity index 100% rename from packages/php-wasm/web-service-worker/src/firewall-interference-error.ts rename to packages/php-wasm/web-service-worker/src/lib/firewall-interference-error.ts diff --git a/packages/php-wasm/web-service-worker/src/messaging.ts b/packages/php-wasm/web-service-worker/src/lib/messaging.ts similarity index 100% rename from packages/php-wasm/web-service-worker/src/messaging.ts rename to packages/php-wasm/web-service-worker/src/lib/messaging.ts diff --git a/packages/php-wasm/web-service-worker/src/utils.ts b/packages/php-wasm/web-service-worker/src/lib/utils.ts similarity index 100% rename from packages/php-wasm/web-service-worker/src/utils.ts rename to packages/php-wasm/web-service-worker/src/lib/utils.ts diff --git a/packages/php-wasm/web-service-worker/src/fetch-with-cors-proxy.spec.ts b/packages/php-wasm/web-service-worker/src/test/fetch-with-cors-proxy.spec.ts similarity index 98% rename from packages/php-wasm/web-service-worker/src/fetch-with-cors-proxy.spec.ts rename to packages/php-wasm/web-service-worker/src/test/fetch-with-cors-proxy.spec.ts index e628e0a0ee7..8eeb1257679 100644 --- a/packages/php-wasm/web-service-worker/src/fetch-with-cors-proxy.spec.ts +++ b/packages/php-wasm/web-service-worker/src/test/fetch-with-cors-proxy.spec.ts @@ -1,6 +1,6 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; -import { fetchWithCorsProxy } from './fetch-with-cors-proxy'; -import { FirewallInterferenceError } from './firewall-interference-error'; +import { fetchWithCorsProxy } from '../lib/fetch-with-cors-proxy'; +import { FirewallInterferenceError } from '../lib/firewall-interference-error'; describe('fetchWithCorsProxy', () => { afterEach(() => { diff --git a/packages/php-wasm/web-service-worker/src/utils.spec.ts b/packages/php-wasm/web-service-worker/src/test/utils.spec.ts similarity index 98% rename from packages/php-wasm/web-service-worker/src/utils.spec.ts rename to packages/php-wasm/web-service-worker/src/test/utils.spec.ts index ffca7d77517..a0e421740c8 100644 --- a/packages/php-wasm/web-service-worker/src/utils.spec.ts +++ b/packages/php-wasm/web-service-worker/src/test/utils.spec.ts @@ -1,8 +1,9 @@ +import { describe, expect, it } from 'vitest'; import { cloneRequest, getRequestHeaders, removeContentSecurityPolicyDirective, -} from './utils'; +} from '../lib/utils'; describe('cloneRequest', () => { it('should clone request headers', async () => { diff --git a/packages/php-wasm/web/playwright.config.ts b/packages/php-wasm/web/playwright.config.ts index 670101ab8fc..c4beec5f0b5 100644 --- a/packages/php-wasm/web/playwright.config.ts +++ b/packages/php-wasm/web/playwright.config.ts @@ -3,6 +3,7 @@ import { defineConfig, devices } from '@playwright/test'; export default defineConfig({ outputDir: './src/test/test-results', testDir: './src/test', + testMatch: 'php-dynamic-loading.spec.ts', fullyParallel: false, forbidOnly: !!process.env['CI'], workers: 1, diff --git a/packages/php-wasm/web/src/lib/tcp-over-fetch-websocket.spec.ts b/packages/php-wasm/web/src/test/tcp-over-fetch-websocket.spec.ts similarity index 99% rename from packages/php-wasm/web/src/lib/tcp-over-fetch-websocket.spec.ts rename to packages/php-wasm/web/src/test/tcp-over-fetch-websocket.spec.ts index 149f592bd85..6ac60cdccd3 100644 --- a/packages/php-wasm/web/src/lib/tcp-over-fetch-websocket.spec.ts +++ b/packages/php-wasm/web/src/test/tcp-over-fetch-websocket.spec.ts @@ -1,7 +1,7 @@ import { TCPOverFetchWebsocket, RawBytesFetch, -} from './tcp-over-fetch-websocket'; +} from '../lib/tcp-over-fetch-websocket'; import express, { type Express } from 'express'; import http from 'http'; import https from 'https'; @@ -9,12 +9,12 @@ import tls from 'tls'; import { Duplex } from 'stream'; import type { AddressInfo } from 'net'; import zlib from 'zlib'; -import { generateCertificate as generateCACertificate } from './tls/certificates'; -import type { GeneratedCertificate } from './tls/certificates'; +import { generateCertificate as generateCACertificate } from '../lib/tls/certificates'; +import type { GeneratedCertificate } from '../lib/tls/certificates'; import { generateCertificate, cleanupCertificate, -} from './test-utils/generate-certificate'; +} from './utils/generate-certificate'; const pygmalion = `PREFACE TO PYGMALION. diff --git a/packages/php-wasm/web/src/lib/tls/certificates.spec.ts b/packages/php-wasm/web/src/test/tls/certificates.spec.ts similarity index 98% rename from packages/php-wasm/web/src/lib/tls/certificates.spec.ts rename to packages/php-wasm/web/src/test/tls/certificates.spec.ts index 545ede401ba..3fce7f80b9b 100644 --- a/packages/php-wasm/web/src/lib/tls/certificates.spec.ts +++ b/packages/php-wasm/web/src/test/tls/certificates.spec.ts @@ -1,4 +1,7 @@ -import { generateCertificate, certificateToPEM } from './certificates'; +import { + generateCertificate, + certificateToPEM, +} from '../../lib/tls/certificates'; import { execSync } from 'child_process'; import { writeFileSync, mkdirSync, rmdirSync } from 'fs'; import { tmpdir } from 'os'; diff --git a/packages/php-wasm/web/src/lib/tls/1_2/prf.spec.ts b/packages/php-wasm/web/src/test/tls/prf.spec.ts similarity index 97% rename from packages/php-wasm/web/src/lib/tls/1_2/prf.spec.ts rename to packages/php-wasm/web/src/test/tls/prf.spec.ts index 439563c225d..0f4ea4d1a1e 100644 --- a/packages/php-wasm/web/src/lib/tls/1_2/prf.spec.ts +++ b/packages/php-wasm/web/src/test/tls/prf.spec.ts @@ -1,4 +1,4 @@ -import { hmacSha256, tls12Prf } from './prf'; +import { hmacSha256, tls12Prf } from '../../lib/tls/1_2/prf'; describe('hmacSha256', () => { it('should match the expected HMAC', async () => { diff --git a/packages/php-wasm/web/src/lib/test-utils/generate-certificate.ts b/packages/php-wasm/web/src/test/utils/generate-certificate.ts similarity index 100% rename from packages/php-wasm/web/src/lib/test-utils/generate-certificate.ts rename to packages/php-wasm/web/src/test/utils/generate-certificate.ts diff --git a/packages/php-wasm/xdebug-bridge/src/tests/cdp-server.spec.ts b/packages/php-wasm/xdebug-bridge/src/test/cdp-server.spec.ts similarity index 100% rename from packages/php-wasm/xdebug-bridge/src/tests/cdp-server.spec.ts rename to packages/php-wasm/xdebug-bridge/src/test/cdp-server.spec.ts diff --git a/packages/php-wasm/xdebug-bridge/src/tests/dbgp-session.spec.ts b/packages/php-wasm/xdebug-bridge/src/test/dbgp-session.spec.ts similarity index 100% rename from packages/php-wasm/xdebug-bridge/src/tests/dbgp-session.spec.ts rename to packages/php-wasm/xdebug-bridge/src/test/dbgp-session.spec.ts diff --git a/packages/php-wasm/xdebug-bridge/src/tests/fixtures/array.php b/packages/php-wasm/xdebug-bridge/src/test/fixtures/array.php similarity index 100% rename from packages/php-wasm/xdebug-bridge/src/tests/fixtures/array.php rename to packages/php-wasm/xdebug-bridge/src/test/fixtures/array.php diff --git a/packages/php-wasm/xdebug-bridge/src/tests/fixtures/test.php b/packages/php-wasm/xdebug-bridge/src/test/fixtures/test.php similarity index 100% rename from packages/php-wasm/xdebug-bridge/src/tests/fixtures/test.php rename to packages/php-wasm/xdebug-bridge/src/test/fixtures/test.php diff --git a/packages/php-wasm/xdebug-bridge/src/tests/mocker.ts b/packages/php-wasm/xdebug-bridge/src/test/mocker.ts similarity index 100% rename from packages/php-wasm/xdebug-bridge/src/tests/mocker.ts rename to packages/php-wasm/xdebug-bridge/src/test/mocker.ts diff --git a/packages/php-wasm/xdebug-bridge/src/tests/run-cli.spec.ts b/packages/php-wasm/xdebug-bridge/src/test/run-cli.spec.ts similarity index 100% rename from packages/php-wasm/xdebug-bridge/src/tests/run-cli.spec.ts rename to packages/php-wasm/xdebug-bridge/src/test/run-cli.spec.ts diff --git a/packages/php-wasm/xdebug-bridge/src/tests/start-bridge.spec.ts b/packages/php-wasm/xdebug-bridge/src/test/start-bridge.spec.ts similarity index 100% rename from packages/php-wasm/xdebug-bridge/src/tests/start-bridge.spec.ts rename to packages/php-wasm/xdebug-bridge/src/test/start-bridge.spec.ts diff --git a/packages/php-wasm/xdebug-bridge/src/tests/xdebug-cdp-bridge.spec.ts b/packages/php-wasm/xdebug-bridge/src/test/xdebug-cdp-bridge.spec.ts similarity index 100% rename from packages/php-wasm/xdebug-bridge/src/tests/xdebug-cdp-bridge.spec.ts rename to packages/php-wasm/xdebug-bridge/src/test/xdebug-cdp-bridge.spec.ts diff --git a/packages/playground/blueprints/tests/fixtures/blueprint.json b/packages/playground/blueprints/src/tests/fixtures/blueprint.json similarity index 100% rename from packages/playground/blueprints/tests/fixtures/blueprint.json rename to packages/playground/blueprints/src/tests/fixtures/blueprint.json diff --git a/packages/playground/blueprints/tests/fixtures/blueprint.zip b/packages/playground/blueprints/src/tests/fixtures/blueprint.zip similarity index 100% rename from packages/playground/blueprints/tests/fixtures/blueprint.zip rename to packages/playground/blueprints/src/tests/fixtures/blueprint.zip diff --git a/packages/playground/blueprints/tests/fixtures/demo.png b/packages/playground/blueprints/src/tests/fixtures/demo.png similarity index 100% rename from packages/playground/blueprints/tests/fixtures/demo.png rename to packages/playground/blueprints/src/tests/fixtures/demo.png diff --git a/packages/playground/blueprints/src/lib/steps/fixtures/import-tt5-subset-of-demo-blueprint-playgroundcontent.xml b/packages/playground/blueprints/src/tests/fixtures/import-tt5-subset-of-demo-blueprint-playgroundcontent.xml similarity index 100% rename from packages/playground/blueprints/src/lib/steps/fixtures/import-tt5-subset-of-demo-blueprint-playgroundcontent.xml rename to packages/playground/blueprints/src/tests/fixtures/import-tt5-subset-of-demo-blueprint-playgroundcontent.xml diff --git a/packages/playground/blueprints/src/lib/steps/fixtures/import-wxr-base-url-rewriting.xml b/packages/playground/blueprints/src/tests/fixtures/import-wxr-base-url-rewriting.xml similarity index 100% rename from packages/playground/blueprints/src/lib/steps/fixtures/import-wxr-base-url-rewriting.xml rename to packages/playground/blueprints/src/tests/fixtures/import-wxr-base-url-rewriting.xml diff --git a/packages/playground/blueprints/src/lib/steps/fixtures/import-wxr-comprehensive.xml b/packages/playground/blueprints/src/tests/fixtures/import-wxr-comprehensive.xml similarity index 100% rename from packages/playground/blueprints/src/lib/steps/fixtures/import-wxr-comprehensive.xml rename to packages/playground/blueprints/src/tests/fixtures/import-wxr-comprehensive.xml diff --git a/packages/playground/blueprints/src/lib/steps/fixtures/import-wxr-site-editor-template.xml b/packages/playground/blueprints/src/tests/fixtures/import-wxr-site-editor-template.xml similarity index 100% rename from packages/playground/blueprints/src/lib/steps/fixtures/import-wxr-site-editor-template.xml rename to packages/playground/blueprints/src/tests/fixtures/import-wxr-site-editor-template.xml diff --git a/packages/playground/blueprints/src/lib/steps/fixtures/import-wxr-slash-issue.xml b/packages/playground/blueprints/src/tests/fixtures/import-wxr-slash-issue.xml similarity index 100% rename from packages/playground/blueprints/src/lib/steps/fixtures/import-wxr-slash-issue.xml rename to packages/playground/blueprints/src/tests/fixtures/import-wxr-slash-issue.xml diff --git a/packages/playground/blueprints/tests/fixtures/text_file.txt b/packages/playground/blueprints/src/tests/fixtures/text_file.txt similarity index 100% rename from packages/playground/blueprints/tests/fixtures/text_file.txt rename to packages/playground/blueprints/src/tests/fixtures/text_file.txt diff --git a/packages/playground/blueprints/tests/fixtures/wp-cli.phar b/packages/playground/blueprints/src/tests/fixtures/wp-cli.phar similarity index 100% rename from packages/playground/blueprints/tests/fixtures/wp-cli.phar rename to packages/playground/blueprints/src/tests/fixtures/wp-cli.phar diff --git a/packages/playground/blueprints/src/lib/steps/activate-plugin.spec.ts b/packages/playground/blueprints/src/tests/steps/activate-plugin.spec.ts similarity index 99% rename from packages/playground/blueprints/src/lib/steps/activate-plugin.spec.ts rename to packages/playground/blueprints/src/tests/steps/activate-plugin.spec.ts index 087892ef8d1..2181c415a8a 100644 --- a/packages/playground/blueprints/src/lib/steps/activate-plugin.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/activate-plugin.spec.ts @@ -4,7 +4,7 @@ import { getSqliteDriverModule, getWordPressModule, } from '@wp-playground/wordpress-builds'; -import { activatePlugin } from './activate-plugin'; +import { activatePlugin } from '../../lib/steps/activate-plugin'; import { phpVar } from '@php-wasm/util'; import type { PHPRequestHandler } from '@php-wasm/universal'; import { loadNodeRuntime } from '@php-wasm/node'; diff --git a/packages/playground/blueprints/src/lib/steps/activate-theme.spec.ts b/packages/playground/blueprints/src/tests/steps/activate-theme.spec.ts similarity index 98% rename from packages/playground/blueprints/src/lib/steps/activate-theme.spec.ts rename to packages/playground/blueprints/src/tests/steps/activate-theme.spec.ts index d979b127f89..df82ace8ea5 100644 --- a/packages/playground/blueprints/src/lib/steps/activate-theme.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/activate-theme.spec.ts @@ -5,7 +5,7 @@ import { getSqliteDriverModule, getWordPressModule, } from '@wp-playground/wordpress-builds'; -import { activateTheme } from './activate-theme'; +import { activateTheme } from '../../lib/steps/activate-theme'; import { phpVar } from '@php-wasm/util'; import type { PHPRequestHandler } from '@php-wasm/universal'; import { bootWordPressAndRequestHandler } from '@wp-playground/wordpress'; diff --git a/packages/playground/blueprints/src/lib/steps/cp.spec.ts b/packages/playground/blueprints/src/tests/steps/cp.spec.ts similarity index 98% rename from packages/playground/blueprints/src/lib/steps/cp.spec.ts rename to packages/playground/blueprints/src/tests/steps/cp.spec.ts index 5e942b1958d..fdbc2c0e5d5 100644 --- a/packages/playground/blueprints/src/lib/steps/cp.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/cp.spec.ts @@ -1,6 +1,6 @@ import { PHP } from '@php-wasm/universal'; import { RecommendedPHPVersion } from '@wp-playground/common'; -import { cp } from './cp'; +import { cp } from '../../lib/steps/cp'; import { loadNodeRuntime } from '@php-wasm/node'; import { logger } from '@php-wasm/logger'; import { vi } from 'vitest'; diff --git a/packages/playground/blueprints/src/lib/steps/define-wp-config-consts.spec.ts b/packages/playground/blueprints/src/tests/steps/define-wp-config-consts.spec.ts similarity index 96% rename from packages/playground/blueprints/src/lib/steps/define-wp-config-consts.spec.ts rename to packages/playground/blueprints/src/tests/steps/define-wp-config-consts.spec.ts index 68561ac008a..1ed5cbc0188 100644 --- a/packages/playground/blueprints/src/lib/steps/define-wp-config-consts.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/define-wp-config-consts.spec.ts @@ -1,5 +1,5 @@ import { PHP } from '@php-wasm/universal'; -import { defineBeforeRun } from './define-wp-config-consts'; +import { defineBeforeRun } from '../../lib/steps/define-wp-config-consts'; import { RecommendedPHPVersion } from '@wp-playground/common'; import { loadNodeRuntime } from '@php-wasm/node'; import { setupPlatformLevelMuPlugins } from '@wp-playground/wordpress'; diff --git a/packages/playground/blueprints/src/lib/steps/enable-multisite.spec.ts b/packages/playground/blueprints/src/tests/steps/enable-multisite.spec.ts similarity index 93% rename from packages/playground/blueprints/src/lib/steps/enable-multisite.spec.ts rename to packages/playground/blueprints/src/tests/steps/enable-multisite.spec.ts index 94db5fa9320..35441e814f5 100644 --- a/packages/playground/blueprints/src/lib/steps/enable-multisite.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/enable-multisite.spec.ts @@ -3,12 +3,12 @@ import { getSqliteDriverModule, getWordPressModule, } from '@wp-playground/wordpress-builds'; -import { enableMultisite } from './enable-multisite'; +import { enableMultisite } from '../../lib/steps/enable-multisite'; import { bootWordPressAndRequestHandler } from '@wp-playground/wordpress'; import { loadNodeRuntime } from '@php-wasm/node'; import { readFileSync } from 'fs'; import { join } from 'path'; -import { login } from './login'; +import { login } from '../../lib/steps/login'; import type { PHPRequest, PHPRequestHandler } from '@php-wasm/universal'; describe('Blueprint step enableMultisite', () => { @@ -24,7 +24,7 @@ describe('Blueprint step enableMultisite', () => { sqliteIntegrationPluginZip: await getSqliteDriverModule(), createFiles: { '/tmp/wp-cli.phar': readFileSync( - join(__dirname, '../../../tests/fixtures/wp-cli.phar') + join(__dirname, '/../fixtures/wp-cli.phar') ), }, }); diff --git a/packages/playground/blueprints/src/lib/steps/import-theme-starter-content.spec.ts b/packages/playground/blueprints/src/tests/steps/import-theme-starter-content.spec.ts similarity index 96% rename from packages/playground/blueprints/src/lib/steps/import-theme-starter-content.spec.ts rename to packages/playground/blueprints/src/tests/steps/import-theme-starter-content.spec.ts index b41e400db7a..cd0e8ca13ed 100644 --- a/packages/playground/blueprints/src/lib/steps/import-theme-starter-content.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/import-theme-starter-content.spec.ts @@ -4,7 +4,7 @@ import { getSqliteDriverModule, getWordPressModule, } from '@wp-playground/wordpress-builds'; -import { importThemeStarterContent } from './import-theme-starter-content'; +import { importThemeStarterContent } from '../../lib/steps/import-theme-starter-content'; import type { PHPRequestHandler } from '@php-wasm/universal'; import { bootWordPressAndRequestHandler } from '@wp-playground/wordpress'; import { loadNodeRuntime } from '@php-wasm/node'; diff --git a/packages/playground/blueprints/src/lib/steps/import-wordpress-files.spec.ts b/packages/playground/blueprints/src/tests/steps/import-wordpress-files.spec.ts similarity index 98% rename from packages/playground/blueprints/src/lib/steps/import-wordpress-files.spec.ts rename to packages/playground/blueprints/src/tests/steps/import-wordpress-files.spec.ts index cc4cbd07a04..130134fe2a7 100644 --- a/packages/playground/blueprints/src/lib/steps/import-wordpress-files.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/import-wordpress-files.spec.ts @@ -1,7 +1,7 @@ import type { PHP, PHPRequestHandler } from '@php-wasm/universal'; import { RecommendedPHPVersion } from '@wp-playground/common'; -import { importWordPressFiles } from './import-wordpress-files'; -import { zipWpContent } from './zip-wp-content'; +import { importWordPressFiles } from '../../lib/steps/import-wordpress-files'; +import { zipWpContent } from '../../lib/steps/zip-wp-content'; import { getSqliteDriverModule, getWordPressModule, diff --git a/packages/playground/blueprints/src/lib/steps/import-wxr.spec.ts b/packages/playground/blueprints/src/tests/steps/import-wxr.spec.ts similarity index 94% rename from packages/playground/blueprints/src/lib/steps/import-wxr.spec.ts rename to packages/playground/blueprints/src/tests/steps/import-wxr.spec.ts index 52f9693e510..f599c1d2d40 100644 --- a/packages/playground/blueprints/src/lib/steps/import-wxr.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/import-wxr.spec.ts @@ -4,14 +4,14 @@ import { getSqliteDriverModule, getWordPressModule, } from '@wp-playground/wordpress-builds'; -import { importWxr } from './import-wxr'; +import { importWxr } from '../../lib/steps/import-wxr'; import { readFile } from 'fs/promises'; -import { installPlugin } from './install-plugin'; +import { installPlugin } from '../../lib/steps/install-plugin'; import type { PHPRequestHandler } from '@php-wasm/universal'; import { bootWordPressAndRequestHandler } from '@wp-playground/wordpress'; import { loadNodeRuntime } from '@php-wasm/node'; -import { CorePluginResource } from '../v1/resources'; -import { resetData } from './reset-data'; +import { CorePluginResource } from '../../lib/v1/resources'; +import { resetData } from '../../lib/steps/reset-data'; describe('Blueprint step importWxr', () => { let php: PHP; @@ -100,7 +100,7 @@ describe('Blueprint step importWxr', () => { 'Should import a WXR file with JSON-encoded UTF-8 characters', async () => { const fileData = await readFile( - __dirname + '/fixtures/import-wxr-slash-issue.xml' + __dirname + '/../fixtures/import-wxr-slash-issue.xml' ); const file = new File([fileData], 'import.wxr'); @@ -135,7 +135,7 @@ describe('Blueprint step importWxr', () => { 'Should create and associate wp_theme taxonomy terms for Site Editor templates', async () => { const fileData = await readFile( - __dirname + '/fixtures/import-wxr-site-editor-template.xml' + __dirname + '/../fixtures/import-wxr-site-editor-template.xml' ); const file = new File([fileData], 'import.wxr'); @@ -158,7 +158,7 @@ describe('Blueprint step importWxr', () => { 'Should rewrite site URLs in the imported content', async () => { const fileData = await readFile( - __dirname + '/fixtures/import-wxr-base-url-rewriting.xml' + __dirname + '/../fixtures/import-wxr-base-url-rewriting.xml' ); const file = new File([fileData], 'import.wxr'); @@ -212,7 +212,7 @@ describe('Blueprint step importWxr', () => { async () => { const fileData = await readFile( __dirname + - '/fixtures/import-tt5-subset-of-demo-blueprint-playgroundcontent.xml' + '/../fixtures/import-tt5-subset-of-demo-blueprint-playgroundcontent.xml' ); const file = new File([fileData], 'import.wxr'); @@ -265,7 +265,7 @@ describe('Blueprint step importWxr', () => { 'Should replace all post authors with admin user', async () => { const fileData = await readFile( - __dirname + '/fixtures/import-wxr-comprehensive.xml' + __dirname + '/../fixtures/import-wxr-comprehensive.xml' ); const file = new File([fileData], 'import.wxr'); diff --git a/packages/playground/blueprints/src/lib/steps/install-plugin.spec.ts b/packages/playground/blueprints/src/tests/steps/install-plugin.spec.ts similarity index 99% rename from packages/playground/blueprints/src/lib/steps/install-plugin.spec.ts rename to packages/playground/blueprints/src/tests/steps/install-plugin.spec.ts index ee0f5726de1..6cd58cc22bf 100644 --- a/packages/playground/blueprints/src/lib/steps/install-plugin.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/install-plugin.spec.ts @@ -1,6 +1,6 @@ import { PHP } from '@php-wasm/universal'; import { RecommendedPHPVersion } from '@wp-playground/common'; -import { installPlugin } from './install-plugin'; +import { installPlugin } from '../../lib/steps/install-plugin'; import { phpVar } from '@php-wasm/util'; import { PHPRequestHandler } from '@php-wasm/universal'; import { loadNodeRuntime } from '@php-wasm/node'; diff --git a/packages/playground/blueprints/src/lib/steps/install-theme.spec.ts b/packages/playground/blueprints/src/tests/steps/install-theme.spec.ts similarity index 98% rename from packages/playground/blueprints/src/lib/steps/install-theme.spec.ts rename to packages/playground/blueprints/src/tests/steps/install-theme.spec.ts index 241088b9a01..971d46e58da 100644 --- a/packages/playground/blueprints/src/lib/steps/install-theme.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/install-theme.spec.ts @@ -1,7 +1,7 @@ import { PHP } from '@php-wasm/universal'; import { phpVar } from '@php-wasm/util'; import { RecommendedPHPVersion } from '@wp-playground/common'; -import { installTheme } from './install-theme'; +import { installTheme } from '../../lib/steps/install-theme'; import { PHPRequestHandler } from '@php-wasm/universal'; import { loadNodeRuntime } from '@php-wasm/node'; diff --git a/packages/playground/blueprints/src/lib/steps/login.spec.ts b/packages/playground/blueprints/src/tests/steps/login.spec.ts similarity index 95% rename from packages/playground/blueprints/src/lib/steps/login.spec.ts rename to packages/playground/blueprints/src/tests/steps/login.spec.ts index 0a6ed5768a9..ac3fb4ab454 100644 --- a/packages/playground/blueprints/src/lib/steps/login.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/login.spec.ts @@ -4,11 +4,11 @@ import { getSqliteDriverModule, getWordPressModule, } from '@wp-playground/wordpress-builds'; -import { login } from './login'; +import { login } from '../../lib/steps/login'; import type { PHPRequestHandler } from '@php-wasm/universal'; import { bootWordPressAndRequestHandler } from '@wp-playground/wordpress'; import { loadNodeRuntime } from '@php-wasm/node'; -import { defineWpConfigConsts } from './define-wp-config-consts'; +import { defineWpConfigConsts } from '../../lib/steps/define-wp-config-consts'; import { joinPaths, phpVar } from '@php-wasm/util'; describe('Blueprint step login', () => { diff --git a/packages/playground/blueprints/src/lib/steps/mkdir.spec.ts b/packages/playground/blueprints/src/tests/steps/mkdir.spec.ts similarity index 97% rename from packages/playground/blueprints/src/lib/steps/mkdir.spec.ts rename to packages/playground/blueprints/src/tests/steps/mkdir.spec.ts index 91b1717c264..eccd1effb96 100644 --- a/packages/playground/blueprints/src/lib/steps/mkdir.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/mkdir.spec.ts @@ -1,6 +1,6 @@ import { PHP } from '@php-wasm/universal'; import { RecommendedPHPVersion } from '@wp-playground/common'; -import { mkdir } from './mkdir'; +import { mkdir } from '../../lib/steps/mkdir'; import { loadNodeRuntime } from '@php-wasm/node'; import { logger } from '@php-wasm/logger'; import { vi } from 'vitest'; diff --git a/packages/playground/blueprints/src/lib/steps/mv.spec.ts b/packages/playground/blueprints/src/tests/steps/mv.spec.ts similarity index 98% rename from packages/playground/blueprints/src/lib/steps/mv.spec.ts rename to packages/playground/blueprints/src/tests/steps/mv.spec.ts index 763d18349cc..866ed722617 100644 --- a/packages/playground/blueprints/src/lib/steps/mv.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/mv.spec.ts @@ -1,6 +1,6 @@ import { PHP } from '@php-wasm/universal'; import { RecommendedPHPVersion } from '@wp-playground/common'; -import { mv } from './mv'; +import { mv } from '../../lib/steps/mv'; import { loadNodeRuntime } from '@php-wasm/node'; import { logger } from '@php-wasm/logger'; import { vi } from 'vitest'; diff --git a/packages/playground/blueprints/src/lib/steps/reset-data.spec.ts b/packages/playground/blueprints/src/tests/steps/reset-data.spec.ts similarity index 96% rename from packages/playground/blueprints/src/lib/steps/reset-data.spec.ts rename to packages/playground/blueprints/src/tests/steps/reset-data.spec.ts index c9d680a0a62..00e3922e601 100644 --- a/packages/playground/blueprints/src/lib/steps/reset-data.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/reset-data.spec.ts @@ -1,6 +1,6 @@ import type { PHP } from '@php-wasm/universal'; import { RecommendedPHPVersion } from '@wp-playground/common'; -import { resetData } from './reset-data'; +import { resetData } from '../../lib/steps/reset-data'; import { getSqliteDriverModule, getWordPressModule, diff --git a/packages/playground/blueprints/src/lib/steps/rm.spec.ts b/packages/playground/blueprints/src/tests/steps/rm.spec.ts similarity index 97% rename from packages/playground/blueprints/src/lib/steps/rm.spec.ts rename to packages/playground/blueprints/src/tests/steps/rm.spec.ts index 12c375f7419..bf3a0c86055 100644 --- a/packages/playground/blueprints/src/lib/steps/rm.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/rm.spec.ts @@ -1,6 +1,6 @@ import { PHP } from '@php-wasm/universal'; import { RecommendedPHPVersion } from '@wp-playground/common'; -import { rm } from './rm'; +import { rm } from '../../lib/steps/rm'; import { loadNodeRuntime } from '@php-wasm/node'; import { logger } from '@php-wasm/logger'; import { vi } from 'vitest'; diff --git a/packages/playground/blueprints/src/lib/steps/rmdir.spec.ts b/packages/playground/blueprints/src/tests/steps/rmdir.spec.ts similarity index 97% rename from packages/playground/blueprints/src/lib/steps/rmdir.spec.ts rename to packages/playground/blueprints/src/tests/steps/rmdir.spec.ts index f80089cdcc1..fc191ec547f 100644 --- a/packages/playground/blueprints/src/lib/steps/rmdir.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/rmdir.spec.ts @@ -1,6 +1,6 @@ import { PHP } from '@php-wasm/universal'; import { RecommendedPHPVersion } from '@wp-playground/common'; -import { rmdir } from './rmdir'; +import { rmdir } from '../../lib/steps/rmdir'; import { loadNodeRuntime } from '@php-wasm/node'; import { logger } from '@php-wasm/logger'; import { vi } from 'vitest'; diff --git a/packages/playground/blueprints/src/lib/steps/run-php.spec.ts b/packages/playground/blueprints/src/tests/steps/run-php.spec.ts similarity index 98% rename from packages/playground/blueprints/src/lib/steps/run-php.spec.ts rename to packages/playground/blueprints/src/tests/steps/run-php.spec.ts index 797f547feb8..56822327029 100644 --- a/packages/playground/blueprints/src/lib/steps/run-php.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/run-php.spec.ts @@ -1,5 +1,5 @@ import { PHP } from '@php-wasm/universal'; -import { runPHP } from './run-php'; +import { runPHP } from '../../lib/steps/run-php'; import { loadNodeRuntime } from '@php-wasm/node'; import { logger } from '@php-wasm/logger'; import { vi } from 'vitest'; diff --git a/packages/playground/blueprints/src/lib/steps/run-sql.spec.ts b/packages/playground/blueprints/src/tests/steps/run-sql.spec.ts similarity index 99% rename from packages/playground/blueprints/src/lib/steps/run-sql.spec.ts rename to packages/playground/blueprints/src/tests/steps/run-sql.spec.ts index 9b7037a3d04..c547d61b338 100644 --- a/packages/playground/blueprints/src/lib/steps/run-sql.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/run-sql.spec.ts @@ -1,6 +1,6 @@ import type { PHP } from '@php-wasm/universal'; import { phpVars } from '@php-wasm/util'; -import { runSql } from './run-sql'; +import { runSql } from '../../lib/steps/run-sql'; import type { PHPRequestHandler } from '@php-wasm/universal'; import { loadNodeRuntime } from '@php-wasm/node'; import { RecommendedPHPVersion } from '@wp-playground/common'; @@ -54,7 +54,7 @@ describe('Blueprint step runSql', () => { return $query; }); }); - + file_put_contents(${js.outputLogPath}, ''); ` ); diff --git a/packages/playground/blueprints/src/lib/steps/set-site-language.spec.ts b/packages/playground/blueprints/src/tests/steps/set-site-language.spec.ts similarity index 94% rename from packages/playground/blueprints/src/lib/steps/set-site-language.spec.ts rename to packages/playground/blueprints/src/tests/steps/set-site-language.spec.ts index c65c9ac08a4..d5754d51c6a 100644 --- a/packages/playground/blueprints/src/lib/steps/set-site-language.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/set-site-language.spec.ts @@ -1,4 +1,4 @@ -import { getWordPressTranslationUrl } from './set-site-language'; +import { getWordPressTranslationUrl } from '../../lib/steps/set-site-language'; describe('getWordPressTranslationUrl()', () => { [ diff --git a/packages/playground/blueprints/src/lib/steps/site-data.spec.ts b/packages/playground/blueprints/src/tests/steps/site-data.spec.ts similarity index 95% rename from packages/playground/blueprints/src/lib/steps/site-data.spec.ts rename to packages/playground/blueprints/src/tests/steps/site-data.spec.ts index 1a0e3ecf31f..9b9d84cbef4 100644 --- a/packages/playground/blueprints/src/lib/steps/site-data.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/site-data.spec.ts @@ -4,7 +4,7 @@ import { getSqliteDriverModule, getWordPressModule, } from '@wp-playground/wordpress-builds'; -import { setSiteOptions } from './site-data'; +import { setSiteOptions } from '../../lib/steps/site-data'; import type { PHPRequestHandler } from '@php-wasm/universal'; import { bootWordPressAndRequestHandler } from '@wp-playground/wordpress'; import { loadNodeRuntime } from '@php-wasm/node'; diff --git a/packages/playground/blueprints/src/lib/steps/wp-cli.spec.ts b/packages/playground/blueprints/src/tests/steps/wp-cli.spec.ts similarity index 96% rename from packages/playground/blueprints/src/lib/steps/wp-cli.spec.ts rename to packages/playground/blueprints/src/tests/steps/wp-cli.spec.ts index c9758f657ec..b9565d8c5df 100644 --- a/packages/playground/blueprints/src/lib/steps/wp-cli.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/wp-cli.spec.ts @@ -1,5 +1,5 @@ import type { PHP } from '@php-wasm/universal'; -import { splitShellCommand, wpCLI } from './wp-cli'; +import { splitShellCommand, wpCLI } from '../../lib/steps/wp-cli'; import { readFileSync } from 'fs'; import { join } from 'path'; import { @@ -24,7 +24,7 @@ describe('Blueprint step wpCLI', () => { sqliteIntegrationPluginZip: await getSqliteDriverModule(), createFiles: { '/tmp/wp-cli.phar': readFileSync( - join(__dirname, '../../../tests/fixtures/wp-cli.phar') + join(__dirname, '../fixtures/wp-cli.phar') ), }, }); diff --git a/packages/playground/blueprints/src/lib/steps/write-file.spec.ts b/packages/playground/blueprints/src/tests/steps/write-file.spec.ts similarity index 98% rename from packages/playground/blueprints/src/lib/steps/write-file.spec.ts rename to packages/playground/blueprints/src/tests/steps/write-file.spec.ts index 686acbf6317..1a9d71e7677 100644 --- a/packages/playground/blueprints/src/lib/steps/write-file.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/write-file.spec.ts @@ -1,6 +1,6 @@ import { PHP } from '@php-wasm/universal'; import { RecommendedPHPVersion } from '@wp-playground/common'; -import { writeFile } from './write-file'; +import { writeFile } from '../../lib/steps/write-file'; import { loadNodeRuntime } from '@php-wasm/node'; import { logger } from '@php-wasm/logger'; import { vi } from 'vitest'; diff --git a/packages/playground/blueprints/src/lib/steps/write-files.spec.ts b/packages/playground/blueprints/src/tests/steps/write-files.spec.ts similarity index 94% rename from packages/playground/blueprints/src/lib/steps/write-files.spec.ts rename to packages/playground/blueprints/src/tests/steps/write-files.spec.ts index a0ca2d44d76..48297f7e9ec 100644 --- a/packages/playground/blueprints/src/lib/steps/write-files.spec.ts +++ b/packages/playground/blueprints/src/tests/steps/write-files.spec.ts @@ -1,5 +1,5 @@ import { PHP } from '@php-wasm/universal'; -import { writeFiles } from './write-files'; +import { writeFiles } from '../../lib/steps/write-files'; import { PHPRequestHandler } from '@php-wasm/universal'; import { loadNodeRuntime } from '@php-wasm/node'; import { RecommendedPHPVersion } from '@wp-playground/common'; diff --git a/packages/playground/blueprints/src/lib/v1/compile.spec.ts b/packages/playground/blueprints/src/tests/v1/compile.spec.ts similarity index 98% rename from packages/playground/blueprints/src/lib/v1/compile.spec.ts rename to packages/playground/blueprints/src/tests/v1/compile.spec.ts index fb2b4051add..8f421db5e56 100644 --- a/packages/playground/blueprints/src/lib/v1/compile.spec.ts +++ b/packages/playground/blueprints/src/tests/v1/compile.spec.ts @@ -3,8 +3,8 @@ import { compileBlueprintV1, runBlueprintV1Steps, validateBlueprint, -} from './compile'; -import { defineWpConfigConsts } from '../steps/define-wp-config-consts'; +} from '../../lib/v1/compile'; +import { defineWpConfigConsts } from '../../lib/steps/define-wp-config-consts'; import { RecommendedPHPVersion } from '@wp-playground/common'; import { PHPRequestHandler } from '@php-wasm/universal'; import { loadNodeRuntime } from '@php-wasm/node'; @@ -95,10 +95,7 @@ describe('Blueprints', () => { it('should compile and run a zip-based blueprint', async () => { // Load the real zip file from the test directory - const zipPath = path.resolve( - __dirname, - '../../../tests/fixtures/blueprint.zip' - ); + const zipPath = path.resolve(__dirname, '../fixtures/blueprint.zip'); const zipData = fs.readFileSync(zipPath).buffer; const zipBundle = ZipFilesystem.fromArrayBuffer(zipData); const compiledBlueprint = await compileBlueprintV1(zipBundle); diff --git a/packages/playground/blueprints/src/lib/v1/resources.spec.ts b/packages/playground/blueprints/src/tests/v1/resources.spec.ts similarity index 99% rename from packages/playground/blueprints/src/lib/v1/resources.spec.ts rename to packages/playground/blueprints/src/tests/v1/resources.spec.ts index 5c352f24981..cd51c93a2e9 100644 --- a/packages/playground/blueprints/src/lib/v1/resources.spec.ts +++ b/packages/playground/blueprints/src/tests/v1/resources.spec.ts @@ -6,7 +6,7 @@ import { rewriteGithubProxyUrl, ZipResource, Resource, -} from './resources'; +} from '../../lib/v1/resources'; import { expect, describe, it, vi, beforeEach, afterEach } from 'vitest'; import { StreamedFile } from '@php-wasm/stream-compression'; import { mkdtemp, rm, writeFile, mkdir } from 'fs/promises'; diff --git a/packages/playground/storage/package.json b/packages/playground/storage/package.json index f4222097ff8..a048eef62e9 100644 --- a/packages/playground/storage/package.json +++ b/packages/playground/storage/package.json @@ -36,16 +36,6 @@ "type": "module", "types": "index.d.ts", "dependencies": { - "async-lock": "^1.4.1", - "clean-git-ref": "^2.0.1", - "crc-32": "^1.2.0", - "diff3": "0.0.3", - "ignore": "^5.1.4", - "minimisted": "^2.0.0", - "pako": "^1.0.10", - "pify": "^4.0.1", - "readable-stream": "^3.4.0", - "sha.js": "^2.4.9", - "simple-get": "^4.0.1" + "pako": "^1.0.10" } } diff --git a/packages/playground/storage/src/lib/changeset.spec.ts b/packages/playground/storage/src/test/changeset.spec.ts similarity index 98% rename from packages/playground/storage/src/lib/changeset.spec.ts rename to packages/playground/storage/src/test/changeset.spec.ts index 363b019698d..4fb94e88484 100644 --- a/packages/playground/storage/src/lib/changeset.spec.ts +++ b/packages/playground/storage/src/test/changeset.spec.ts @@ -1,4 +1,4 @@ -import { changeset } from './changeset'; +import { changeset } from '../lib/changeset'; describe('changeset', () => { it('should return an empty changeset when no files have changed', async () => { diff --git a/packages/playground/storage/src/lib/filesystems.spec.ts b/packages/playground/storage/src/test/filesystems.spec.ts similarity index 98% rename from packages/playground/storage/src/lib/filesystems.spec.ts rename to packages/playground/storage/src/test/filesystems.spec.ts index 10c04f55d48..b37b0d7f475 100644 --- a/packages/playground/storage/src/lib/filesystems.spec.ts +++ b/packages/playground/storage/src/test/filesystems.spec.ts @@ -1,4 +1,3 @@ -import type { Filesystem } from './filesystems'; import { InMemoryFilesystem, InMemoryFilesystemBackend, @@ -6,11 +5,11 @@ import { OverlayFilesystem, FetchFilesystem, NodeJsFilesystem, -} from './filesystems'; + type ReadableFilesystemBackend, +} from '../lib/filesystems'; import { StreamedFile } from '@php-wasm/stream-compression'; import type { FileTree } from '@php-wasm/universal'; import type { BlobReader, ZipReader } from '@zip.js/zip.js'; -import { vi, describe, it, expect, beforeEach } from 'vitest'; import path from 'path'; // Mock fetch for FetchFilesystem tests @@ -136,8 +135,8 @@ describe('ZipFilesystem', () => { }); describe('OverlayFilesystem', () => { - let primaryFs: Filesystem; - let fallbackFs: Filesystem; + let primaryFs: ReadableFilesystemBackend; + let fallbackFs: ReadableFilesystemBackend; let overlayFs: OverlayFilesystem; beforeEach(() => { @@ -423,7 +422,7 @@ describe('NodeJsFilesystem', () => { beforeEach(() => { filesystem = new NodeJsFilesystem( - path.join(__dirname, '..', '..', 'tests', 'fixtures') + path.join(__dirname, '..', 'test', 'fixtures') ); }); diff --git a/packages/playground/storage/tests/fixtures/pygmalion.txt b/packages/playground/storage/src/test/fixtures/pygmalion.txt similarity index 100% rename from packages/playground/storage/tests/fixtures/pygmalion.txt rename to packages/playground/storage/src/test/fixtures/pygmalion.txt diff --git a/packages/playground/storage/src/lib/git-sparse-checkout.spec.ts b/packages/playground/storage/src/test/git-sparse-checkout.spec.ts similarity index 99% rename from packages/playground/storage/src/lib/git-sparse-checkout.spec.ts rename to packages/playground/storage/src/test/git-sparse-checkout.spec.ts index 60acfd3d2fe..e485810625a 100644 --- a/packages/playground/storage/src/lib/git-sparse-checkout.spec.ts +++ b/packages/playground/storage/src/test/git-sparse-checkout.spec.ts @@ -4,8 +4,7 @@ import { listGitFiles, resolveCommitHash, type GitAdditionalHeaders, -} from './git-sparse-checkout'; -import { vi } from 'vitest'; +} from '../lib/git-sparse-checkout'; describe('listRefs', () => { it('should return the latest commit hash for a given ref', async () => { diff --git a/packages/playground/storage/src/lib/paths.spec.ts b/packages/playground/storage/src/test/paths.spec.ts similarity index 94% rename from packages/playground/storage/src/lib/paths.spec.ts rename to packages/playground/storage/src/test/paths.spec.ts index 1d6130a811a..d2e4ac1015b 100644 --- a/packages/playground/storage/src/lib/paths.spec.ts +++ b/packages/playground/storage/src/test/paths.spec.ts @@ -1,5 +1,5 @@ -import type { GitFileTree } from './git-sparse-checkout'; -import { listDescendantFiles } from './paths'; +import type { GitFileTree } from '../lib/git-sparse-checkout'; +import { listDescendantFiles } from '../lib/paths'; const testTree: GitFileTree[] = [ { diff --git a/packages/playground/storage/tests/filesystems.spec.ts b/packages/playground/storage/tests/filesystems.spec.ts deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/packages/playground/test-built-npm-packages/commonjs-and-jest/tests/deps.spec.ts b/packages/playground/test-built-npm-packages/commonjs-and-jest/tests/deps.spec.ts new file mode 100644 index 00000000000..94aab6f64e9 --- /dev/null +++ b/packages/playground/test-built-npm-packages/commonjs-and-jest/tests/deps.spec.ts @@ -0,0 +1,100 @@ +const path = require('path'); +const fs = require('fs'); + +const repoRoot = path.resolve(__dirname, '../../../../..'); +const nodeModulesDir = path.resolve(__dirname, '..', 'node_modules'); + +/** + * Maps a package name like "@php-wasm/web" to its project directory + * in the repo like "packages/php-wasm/web". + */ +function getProjectDirectory(packageName: string): string | null { + const match = packageName.match(/^@(php-wasm|wp-playground)\/(.+)$/); + if (!match) return null; + const layer = match[1] === 'wp-playground' ? 'playground' : match[1]; + return path.join(repoRoot, 'packages', layer, match[2]); +} + +/** + * Returns the list of source files for a project by reading the + * tsconfig.lib.json include/exclude patterns — but as a simpler + * approximation, returns all .ts files NOT inside a /test/ directory. + */ +function getSourceImports(projectDir: string): Set { + const imports = new Set(); + function walk(dir: string) { + if (!fs.existsSync(dir)) return; + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + const full = path.join(dir, entry.name); + if (entry.isDirectory()) { + if (entry.name !== 'test' && entry.name !== 'node_modules') { + walk(full); + } + } else if ( + entry.name.endsWith('.ts') || + entry.name.endsWith('.tsx') + ) { + const content = fs.readFileSync(full, 'utf-8'); + // Match: import '...', import('...'), from '...' + const patterns = [ + /from\s+['"]([^./][^'"]*)['"]/g, + /import\s+['"]([^./][^'"]*)['"]/g, + /import\(\s*['"]([^./][^'"]*)['"]\s*\)/g, + ]; + for (const re of patterns) { + let m; + while ((m = re.exec(content)) !== null) { + const imp = m[1]; + const pkg = imp.startsWith('@') + ? imp.split('/').slice(0, 2).join('/') + : imp.split('/')[0]; + imports.add(pkg); + } + } + } + } + } + walk(path.join(projectDir, 'src')); + + return imports; +} + +function getInstalledPackages(): Array<{ name: string; dir: string }> { + const results: Array<{ name: string; dir: string }> = []; + for (const scope of ['@php-wasm', '@wp-playground']) { + const scopeDir = path.join(nodeModulesDir, scope); + if (!fs.existsSync(scopeDir)) continue; + for (const pkg of fs.readdirSync(scopeDir)) { + const pkgDir = path.join(scopeDir, pkg); + const pkgJsonPath = path.join(pkgDir, 'package.json'); + if (!fs.existsSync(pkgJsonPath)) continue; + const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')); + results.push({ name: pkgJson.name, dir: pkgDir }); + } + } + return results; +} + +describe('Built package dependencies', () => { + getInstalledPackages().forEach((pkg) => { + it(`${pkg.name} should only declare dependencies imported from source files`, () => { + const directory = getProjectDirectory(pkg.name); + + if (!directory || !fs.existsSync(directory)) return; + + const sourceImports = getSourceImports(directory); + + const packageJsonFile = JSON.parse( + fs.readFileSync(path.join(pkg.dir, 'package.json'), 'utf-8') + ); + + const dependencies = Object.keys( + packageJsonFile.dependencies || {} + ); + + for (const dependency of dependencies) { + expect(sourceImports).toContain(dependency); + } + }); + }); +}); diff --git a/packages/playground/test-built-npm-packages/es-modules-and-vitest/run-tests.ts b/packages/playground/test-built-npm-packages/es-modules-and-vitest/run-tests.ts index 73053a3be4d..2fc1bd66bd3 100644 --- a/packages/playground/test-built-npm-packages/es-modules-and-vitest/run-tests.ts +++ b/packages/playground/test-built-npm-packages/es-modules-and-vitest/run-tests.ts @@ -35,55 +35,59 @@ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) { ); } +const testFiles = ['./tests/deps.spec.ts', './tests/wp.spec.ts']; + for (const phpVersion of SupportedPHPVersions) { console.log(`\nRunning tests for PHP ${phpVersion}...`); - const child = spawn( - process.execPath, - [ - '--experimental-strip-types', - '--experimental-transform-types', - '--test', - '--test-concurrency=1', - './tests/wp.spec.ts', - ], - { - env: { - ...process.env, - PHP_VERSION: phpVersion, - }, - stdio: 'inherit', - } - ); - - let timeoutHandle: NodeJS.Timeout | undefined; - const promiseToClose = new Promise((resolve) => { - child.on('close', (code) => resolve(code)); - }); - const promiseToTimeout = new Promise((_, reject) => { - timeoutHandle = setTimeout(() => { - reject(new Error(`Test timed out after ${timeoutMs}ms`)); - }, timeoutMs); - }); + for (const file of testFiles) { + const child = spawn( + process.execPath, + [ + '--experimental-strip-types', + '--experimental-transform-types', + '--test', + '--test-concurrency=1', + file, + ], + { + env: { + ...process.env, + PHP_VERSION: phpVersion, + }, + stdio: 'inherit', + } + ); - try { - const code = await Promise.race([promiseToClose, promiseToTimeout]); - results.push({ - phpVersion, - code, + let timeoutHandle: NodeJS.Timeout | undefined; + const promiseToClose = new Promise((resolve) => { + child.on('close', (code) => resolve(code)); }); - } catch (e) { - console.error(`PHP ${phpVersion}: timed out after ${timeoutMs}ms.`); - results.push({ - phpVersion, - code: null, - timeout: true, + const promiseToTimeout = new Promise((_, reject) => { + timeoutHandle = setTimeout(() => { + reject(new Error(`Test timed out after ${timeoutMs}ms`)); + }, timeoutMs); }); - child.kill('SIGKILL'); - await promiseToClose; - } finally { - if (timeoutHandle) { - clearTimeout(timeoutHandle); + + try { + const code = await Promise.race([promiseToClose, promiseToTimeout]); + results.push({ + phpVersion, + code, + }); + } catch (e) { + console.error(`PHP ${phpVersion}: timed out after ${timeoutMs}ms.`); + results.push({ + phpVersion, + code: null, + timeout: true, + }); + child.kill('SIGKILL'); + await promiseToClose; + } finally { + if (timeoutHandle) { + clearTimeout(timeoutHandle); + } } } } diff --git a/packages/playground/test-built-npm-packages/es-modules-and-vitest/tests/deps.spec.ts b/packages/playground/test-built-npm-packages/es-modules-and-vitest/tests/deps.spec.ts new file mode 100644 index 00000000000..730397d4f18 --- /dev/null +++ b/packages/playground/test-built-npm-packages/es-modules-and-vitest/tests/deps.spec.ts @@ -0,0 +1,107 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert/strict'; +import path from 'node:path'; +import fs from 'node:fs'; +import { fileURLToPath } from 'node:url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const repoRoot = path.resolve(__dirname, '../../../../..'); +const nodeModulesDir = path.resolve(__dirname, '..', 'node_modules'); + +/** + * Maps a package name like "@php-wasm/web" to its project directory + * in the repo like "packages/php-wasm/web". + */ +function getProjectDirectory(packageName: string): string | null { + const match = packageName.match(/^@(php-wasm|wp-playground)\/(.+)$/); + if (!match) return null; + const layer = match[1] === 'wp-playground' ? 'playground' : match[1]; + return path.join(repoRoot, 'packages', layer, match[2]); +} + +/** + * Returns the list of source files for a project by reading the + * tsconfig.lib.json include/exclude patterns — but as a simpler + * approximation, returns all .ts files NOT inside a /test/ directory. + */ +function getSourceImports(projectDir: string): Set { + const imports = new Set(); + function walk(dir: string) { + if (!fs.existsSync(dir)) return; + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + const full = path.join(dir, entry.name); + if (entry.isDirectory()) { + if (entry.name !== 'test' && entry.name !== 'node_modules') { + walk(full); + } + } else if ( + entry.name.endsWith('.ts') || + entry.name.endsWith('.tsx') + ) { + const content = fs.readFileSync(full, 'utf-8'); + // Match: import '...', import('...'), from '...' + const patterns = [ + /from\s+['"]([^./][^'"]*)['"]/g, + /import\s+['"]([^./][^'"]*)['"]/g, + /import\(\s*['"]([^./][^'"]*)['"]\s*\)/g, + ]; + for (const re of patterns) { + let m; + while ((m = re.exec(content)) !== null) { + const imp = m[1]; + const pkg = imp.startsWith('@') + ? imp.split('/').slice(0, 2).join('/') + : imp.split('/')[0]; + imports.add(pkg); + } + } + } + } + } + walk(path.join(projectDir, 'src')); + + return imports; +} + +function getInstalledPackages(): Array<{ name: string; dir: string }> { + const results: Array<{ name: string; dir: string }> = []; + for (const scope of ['@php-wasm', '@wp-playground']) { + const scopeDir = path.join(nodeModulesDir, scope); + if (!fs.existsSync(scopeDir)) continue; + for (const pkg of fs.readdirSync(scopeDir)) { + const pkgDir = path.join(scopeDir, pkg); + const pkgJsonPath = path.join(pkgDir, 'package.json'); + if (!fs.existsSync(pkgJsonPath)) continue; + const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')); + results.push({ name: pkgJson.name, dir: pkgDir }); + } + } + return results; +} + +describe('Built package dependencies', () => { + getInstalledPackages().forEach((pkg) => { + it(`${pkg.name} should only declare dependencies imported from source files`, () => { + const directory = getProjectDirectory(pkg.name); + + if (!directory || !fs.existsSync(directory)) return; + + const sourceImports = getSourceImports(directory); + + const packageJsonFile = JSON.parse( + fs.readFileSync(path.join(pkg.dir, 'package.json'), 'utf-8') + ); + + const dependencies = Object.keys( + packageJsonFile.dependencies || {} + ); + + for (const dependency of dependencies) { + assert.ok( + sourceImports.has(dependency), + `${pkg.name} declares dependency "${dependency}" but it is not imported from any source file` + ); + } + }); + }); +}); diff --git a/packages/playground/wordpress-builds/src/get-wordpress-module-details.spec.ts b/packages/playground/wordpress-builds/src/test/get-wordpress-module-details.spec.ts similarity index 85% rename from packages/playground/wordpress-builds/src/get-wordpress-module-details.spec.ts rename to packages/playground/wordpress-builds/src/test/get-wordpress-module-details.spec.ts index 1bc4c2979b3..4836ce5fdb2 100644 --- a/packages/playground/wordpress-builds/src/get-wordpress-module-details.spec.ts +++ b/packages/playground/wordpress-builds/src/test/get-wordpress-module-details.spec.ts @@ -7,7 +7,7 @@ * and should still be linted and picked up by the test runner. */ -import { getWordPressModuleDetails } from './wordpress/get-wordpress-module-details'; +import { getWordPressModuleDetails } from '../wordpress/get-wordpress-module-details'; describe('getWordPressModuleDetails()', () => { it('should return a data loader module', async () => {