Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions packages/php-wasm/node-builds/7-2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,33 @@ const packageDir = existsSync(join(currentDirPath, 'jspi'))
: dirname(currentDirPath);

export async function getPHPLoaderModule(): Promise<PHPLoaderModule> {
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_7_2.js');
// Detect Jest environment and use require() to avoid dynamic import() issues
// For all other environments (ESM, modern CommonJS, Vitest), use dynamic import()
// which works in Node.js 12.20+ regardless of whether the code is running in ESM or CJS.
// Jest runs tests in a VM context that doesn't support dynamic import() without
// the --experimental-vm-modules flag. Jest sets JEST_WORKER_ID when running tests.
// Error without flag: "A dynamic import callback was invoked without --experimental-vm-modules"
// See: https://jestjs.io/docs/ecmascript-modules
const shouldUseRequire = process.env && process.env['JEST_WORKER_ID'];

if (shouldUseRequire) {
// Use require() specifically for Jest
if (await jspi()) {
// @ts-ignore
return require('../jspi/php_7_2.js');
} else {
// @ts-ignore
return require('../asyncify/php_7_2.js');
}
} else {
// @ts-ignore
return await import('../asyncify/php_7_2.js');
// Use dynamic import() for all other environments
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_7_2.js');
} else {
// @ts-ignore
return await import('../asyncify/php_7_2.js');
}
}
}

Expand Down
31 changes: 26 additions & 5 deletions packages/php-wasm/node-builds/7-3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,33 @@ const packageDir = existsSync(join(currentDirPath, 'jspi'))
: dirname(currentDirPath);

export async function getPHPLoaderModule(): Promise<PHPLoaderModule> {
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_7_3.js');
// Detect Jest environment and use require() to avoid dynamic import() issues
// For all other environments (ESM, modern CommonJS, Vitest), use dynamic import()
// which works in Node.js 12.20+ regardless of whether the code is running in ESM or CJS.
// Jest runs tests in a VM context that doesn't support dynamic import() without
// the --experimental-vm-modules flag. Jest sets JEST_WORKER_ID when running tests.
// Error without flag: "A dynamic import callback was invoked without --experimental-vm-modules"
// See: https://jestjs.io/docs/ecmascript-modules
const shouldUseRequire = process.env && process.env['JEST_WORKER_ID'];

if (shouldUseRequire) {
// Use require() specifically for Jest
if (await jspi()) {
// @ts-ignore
return require('../jspi/php_7_3.js');
} else {
// @ts-ignore
return require('../asyncify/php_7_3.js');
}
} else {
// @ts-ignore
return await import('../asyncify/php_7_3.js');
// Use dynamic import() for all other environments
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_7_3.js');
} else {
// @ts-ignore
return await import('../asyncify/php_7_3.js');
}
}
}

Expand Down
31 changes: 26 additions & 5 deletions packages/php-wasm/node-builds/7-4/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,33 @@ const packageDir = existsSync(join(currentDirPath, 'jspi'))
: dirname(currentDirPath);

export async function getPHPLoaderModule(): Promise<PHPLoaderModule> {
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_7_4.js');
// Detect Jest environment and use require() to avoid dynamic import() issues
// For all other environments (ESM, modern CommonJS, Vitest), use dynamic import()
// which works in Node.js 12.20+ regardless of whether the code is running in ESM or CJS.
// Jest runs tests in a VM context that doesn't support dynamic import() without
// the --experimental-vm-modules flag. Jest sets JEST_WORKER_ID when running tests.
// Error without flag: "A dynamic import callback was invoked without --experimental-vm-modules"
// See: https://jestjs.io/docs/ecmascript-modules
const shouldUseRequire = process.env && process.env['JEST_WORKER_ID'];

if (shouldUseRequire) {
// Use require() specifically for Jest
if (await jspi()) {
// @ts-ignore
return require('../jspi/php_7_4.js');
} else {
// @ts-ignore
return require('../asyncify/php_7_4.js');
}
} else {
// @ts-ignore
return await import('../asyncify/php_7_4.js');
// Use dynamic import() for all other environments
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_7_4.js');
} else {
// @ts-ignore
return await import('../asyncify/php_7_4.js');
}
}
}

Expand Down
31 changes: 26 additions & 5 deletions packages/php-wasm/node-builds/8-0/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,33 @@ const packageDir = existsSync(join(currentDirPath, 'jspi'))
: dirname(currentDirPath);

export async function getPHPLoaderModule(): Promise<PHPLoaderModule> {
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_0.js');
// Detect Jest environment and use require() to avoid dynamic import() issues
// For all other environments (ESM, modern CommonJS, Vitest), use dynamic import()
// which works in Node.js 12.20+ regardless of whether the code is running in ESM or CJS.
// Jest runs tests in a VM context that doesn't support dynamic import() without
// the --experimental-vm-modules flag. Jest sets JEST_WORKER_ID when running tests.
// Error without flag: "A dynamic import callback was invoked without --experimental-vm-modules"
// See: https://jestjs.io/docs/ecmascript-modules
const shouldUseRequire = process.env && process.env['JEST_WORKER_ID'];

if (shouldUseRequire) {
// Use require() specifically for Jest
if (await jspi()) {
// @ts-ignore
return require('../jspi/php_8_0.js');
} else {
// @ts-ignore
return require('../asyncify/php_8_0.js');
}
} else {
// @ts-ignore
return await import('../asyncify/php_8_0.js');
// Use dynamic import() for all other environments
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_0.js');
} else {
// @ts-ignore
return await import('../asyncify/php_8_0.js');
}
}
}

Expand Down
31 changes: 26 additions & 5 deletions packages/php-wasm/node-builds/8-1/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,33 @@ const packageDir = existsSync(join(currentDirPath, 'jspi'))
: dirname(currentDirPath);

export async function getPHPLoaderModule(): Promise<PHPLoaderModule> {
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_1.js');
// Detect Jest environment and use require() to avoid dynamic import() issues
// For all other environments (ESM, modern CommonJS, Vitest), use dynamic import()
// which works in Node.js 12.20+ regardless of whether the code is running in ESM or CJS.
// Jest runs tests in a VM context that doesn't support dynamic import() without
// the --experimental-vm-modules flag. Jest sets JEST_WORKER_ID when running tests.
// Error without flag: "A dynamic import callback was invoked without --experimental-vm-modules"
// See: https://jestjs.io/docs/ecmascript-modules
const shouldUseRequire = process.env && process.env['JEST_WORKER_ID'];

if (shouldUseRequire) {
// Use require() specifically for Jest
if (await jspi()) {
// @ts-ignore
return require('../jspi/php_8_1.js');
} else {
// @ts-ignore
return require('../asyncify/php_8_1.js');
}
} else {
// @ts-ignore
return await import('../asyncify/php_8_1.js');
// Use dynamic import() for all other environments
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_1.js');
} else {
// @ts-ignore
return await import('../asyncify/php_8_1.js');
}
}
}

Expand Down
31 changes: 26 additions & 5 deletions packages/php-wasm/node-builds/8-2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,33 @@ const packageDir = existsSync(join(currentDirPath, 'jspi'))
: dirname(currentDirPath);

export async function getPHPLoaderModule(): Promise<PHPLoaderModule> {
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_2.js');
// Detect Jest environment and use require() to avoid dynamic import() issues
// For all other environments (ESM, modern CommonJS, Vitest), use dynamic import()
// which works in Node.js 12.20+ regardless of whether the code is running in ESM or CJS.
// Jest runs tests in a VM context that doesn't support dynamic import() without
// the --experimental-vm-modules flag. Jest sets JEST_WORKER_ID when running tests.
// Error without flag: "A dynamic import callback was invoked without --experimental-vm-modules"
// See: https://jestjs.io/docs/ecmascript-modules
const shouldUseRequire = process.env && process.env['JEST_WORKER_ID'];

if (shouldUseRequire) {
// Use require() specifically for Jest
if (await jspi()) {
// @ts-ignore
return require('../jspi/php_8_2.js');
} else {
// @ts-ignore
return require('../asyncify/php_8_2.js');
}
} else {
// @ts-ignore
return await import('../asyncify/php_8_2.js');
// Use dynamic import() for all other environments
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_2.js');
} else {
// @ts-ignore
return await import('../asyncify/php_8_2.js');
}
}
}

Expand Down
32 changes: 27 additions & 5 deletions packages/php-wasm/node-builds/8-3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,34 @@ const packageDir = existsSync(join(currentDirPath, 'jspi'))
: dirname(currentDirPath);

export async function getPHPLoaderModule(): Promise<PHPLoaderModule> {
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_3.js');
// Detect Jest environment and use require() instead of dynamic import()
// Jest runs tests in a VM context that doesn't support dynamic import() without
// the --experimental-vm-modules flag. Jest sets JEST_WORKER_ID when running tests.
// For all other environments (ESM, modern CommonJS, Vitest), dynamic import() works fine.
// See: https://jestjs.io/docs/ecmascript-modules
const isJest =
typeof process !== 'undefined' &&
process.env &&
process.env['JEST_WORKER_ID'];

if (isJest) {
// Use require() for Jest
if (await jspi()) {
// @ts-ignore
return require('../jspi/php_8_3.js');
} else {
// @ts-ignore
return require('../asyncify/php_8_3.js');
}
} else {
// @ts-ignore
return await import('../asyncify/php_8_3.js');
// Use dynamic import() for all other environments
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_3.js');
} else {
// @ts-ignore
return await import('../asyncify/php_8_3.js');
}
}
}

Expand Down
31 changes: 26 additions & 5 deletions packages/php-wasm/node-builds/8-4/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,33 @@ const packageDir = existsSync(join(currentDirPath, 'jspi'))
: dirname(currentDirPath);

export async function getPHPLoaderModule(): Promise<PHPLoaderModule> {
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_4.js');
// Detect Jest environment and use require() to avoid dynamic import() issues
// For all other environments (ESM, modern CommonJS, Vitest), use dynamic import()
// which works in Node.js 12.20+ regardless of whether the code is running in ESM or CJS.
// Jest runs tests in a VM context that doesn't support dynamic import() without
// the --experimental-vm-modules flag. Jest sets JEST_WORKER_ID when running tests.
// Error without flag: "A dynamic import callback was invoked without --experimental-vm-modules"
// See: https://jestjs.io/docs/ecmascript-modules
const shouldUseRequire = process.env && process.env['JEST_WORKER_ID'];

if (shouldUseRequire) {
// Use require() specifically for Jest
if (await jspi()) {
// @ts-ignore
return require('../jspi/php_8_4.js');
} else {
// @ts-ignore
return require('../asyncify/php_8_4.js');
}
} else {
// @ts-ignore
return await import('../asyncify/php_8_4.js');
// Use dynamic import() for all other environments
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_4.js');
} else {
// @ts-ignore
return await import('../asyncify/php_8_4.js');
}
}
}

Expand Down
31 changes: 26 additions & 5 deletions packages/php-wasm/node-builds/8-5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,33 @@ const packageDir = existsSync(join(currentDirPath, 'jspi'))
: dirname(currentDirPath);

export async function getPHPLoaderModule(): Promise<PHPLoaderModule> {
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_5.js');
// Detect Jest environment and use require() to avoid dynamic import() issues
// For all other environments (ESM, modern CommonJS, Vitest), use dynamic import()
// which works in Node.js 12.20+ regardless of whether the code is running in ESM or CJS.
// Jest runs tests in a VM context that doesn't support dynamic import() without
// the --experimental-vm-modules flag. Jest sets JEST_WORKER_ID when running tests.
// Error without flag: "A dynamic import callback was invoked without --experimental-vm-modules"
// See: https://jestjs.io/docs/ecmascript-modules
const shouldUseRequire = process.env && process.env['JEST_WORKER_ID'];

if (shouldUseRequire) {
// Use require() specifically for Jest
if (await jspi()) {
// @ts-ignore
return require('../jspi/php_8_5.js');
} else {
// @ts-ignore
return require('../asyncify/php_8_5.js');
}
} else {
// @ts-ignore
return await import('../asyncify/php_8_5.js');
// Use dynamic import() for all other environments
if (await jspi()) {
// @ts-ignore
return await import('../jspi/php_8_5.js');
} else {
// @ts-ignore
return await import('../asyncify/php_8_5.js');
}
}
}

Expand Down
Loading
Loading