Skip to content
Merged
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
28 changes: 15 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,12 @@ import { getRootDir, getStencilConfigFile, parseTagConfig, transformCompiledCode

const DCE_OUTPUT_TARGET_NAME = 'dist-custom-elements'

let compiler: CoreCompiler.Compiler | undefined
let buildQueue: BuildQueue | undefined

async function cleanup() {
await compiler?.destroy()
compiler = undefined
process.exit(1)
}
process.on('SIGTERM', cleanup)
process.on('SIGINT', cleanup)

export const unpluginFactory: UnpluginFactory<Options | undefined> = (options = {}) => {
const nodeLogger = nodeApi.createNodeLogger()
let distCustomElementsOptions: OutputTargetDistCustomElements | undefined
let compiler: CoreCompiler.Compiler | undefined
let buildQueue: BuildQueue | undefined
const isTest = process.env.NODE_ENV === 'test' || process.env.VITEST === 'true'

return {
name: 'unplugin-stencil',
Expand Down Expand Up @@ -69,8 +61,18 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (options =
buildQueue = new BuildQueue(compiler)
},
async buildEnd() {
// ensure the process exits when the build is finished
process.exit(0)
// Clean up compiler resources when build ends
await compiler?.destroy()
compiler = undefined
buildQueue = undefined

// In test mode, force exit after a short delay to allow cleanup
// This works around Stencil compiler not fully releasing file handles
if (isTest) {
setTimeout(() => {
process.exit(0)
}, 100)
}
},
/**
* `transformInclude` is called for every file that is being transformed.
Expand Down
2 changes: 2 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import stencil from './src/vite'

export default defineConfig({
test: {
watch: false,
coverage: {
enabled: true,
include: [
Expand All @@ -30,6 +31,7 @@ export default defineConfig({
include: ['**/*.spec.{ts,tsx}'],
browser: {
enabled: true,
headless: true,
provider: 'playwright',
instances: [{ browser: 'chromium' }],
},
Expand Down