From c24849d7a4627ba217c587cad1347dd116236667 Mon Sep 17 00:00:00 2001 From: Sharief Orie Date: Wed, 8 May 2024 17:31:13 +0200 Subject: [PATCH] fix(stencil): resolve `validateConfig` error from @stencil/core@14.17.0 onward --- .../stencil-runtime/stencil-process.spec.ts | 25 +++++++++++++++++++ .../stencil-runtime/stencil-process.ts | 10 ++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 packages/stencil/src/executors/stencil-runtime/stencil-process.spec.ts diff --git a/packages/stencil/src/executors/stencil-runtime/stencil-process.spec.ts b/packages/stencil/src/executors/stencil-runtime/stencil-process.spec.ts new file mode 100644 index 000000000..fa2967d3e --- /dev/null +++ b/packages/stencil/src/executors/stencil-runtime/stencil-process.spec.ts @@ -0,0 +1,25 @@ +import { CompilerSystem, createNodeSys } from '@stencil/core/sys/node'; + +import { loadCoreCompiler } from './stencil-process'; + +function getCompilerExecutingPath(): string { + return require.resolve('@stencil/core/compiler'); +} + +describe('process', () => { + describe('loadCoreCompiler', () => { + it('should return globalThis.stencil', async () => { + const sys: CompilerSystem = createNodeSys({ process }); + + if (sys.getCompilerExecutingPath == null) { + sys.getCompilerExecutingPath = getCompilerExecutingPath; + } + + expect(globalThis.stencil).toBeUndefined(); + + await loadCoreCompiler(sys); + + expect(globalThis.stencil).toBeTruthy(); + }); + }); +}); diff --git a/packages/stencil/src/executors/stencil-runtime/stencil-process.ts b/packages/stencil/src/executors/stencil-runtime/stencil-process.ts index 9c54a129a..0c0175a43 100644 --- a/packages/stencil/src/executors/stencil-runtime/stencil-process.ts +++ b/packages/stencil/src/executors/stencil-runtime/stencil-process.ts @@ -7,9 +7,15 @@ type CoreCompiler = typeof import('@stencil/core/compiler'); export const loadCoreCompiler = async ( sys: CompilerSystem ): Promise => { - await sys.dynamicImport(sys.getCompilerExecutingPath()); + const coreCompiler: CoreCompiler = await sys.dynamicImport( + sys.getCompilerExecutingPath() + ); - return (globalThis as any).stencil; + if (!('stencil' in globalThis)) { + globalThis.stencil = coreCompiler; + } + + return globalThis.stencil; }; export async function createStencilProcess(config: Config): Promise {