From 7ef28da95a90625457efd3fdd14e816c3a9208f2 Mon Sep 17 00:00:00 2001 From: Ryan Waskiewicz Date: Fri, 13 Oct 2023 16:13:52 -0400 Subject: [PATCH] fix(compiler): persist polyfills on build in #4317 (b042d8b), a polyfill for node's `path.join` was [removed](https://github.com/ionic-team/stencil/pull/4317/files#diff-734f69edf83052dfd5ce6df10429550680537c6da66ef9b7cfbda11efdff5117L36), but wasn't backfilled with stencil's `@utils` package version in `generate-esm.ts`. without this change, the destination computed for the polyfills is not normalized for users of Windows OS's. when the destination path is not normalized here (but is normalized in other parts of the code), it creates a situation where stencil's in memory-fs both: 1. marks the polyfills to be copied 2. marks the _previous_ polyfills to be removed normally, if we're performing a copy operation, we don't bother with the deletion (as the copy overwrites the existing polyfills). this is important, as stencil performs its copy operations before it performs its deletions. to ensure that a recently copied file is not subsequently deleted, stencil performs a [check on the files it will delete and removes them from the 'to delete' list](https://github.com/ionic-team/stencil/blob/15a7f89f677bad012dd82a088ce64149a7e48a61/src/compiler/sys/in-memory-fs.ts#L1250-L1253) based on the destination filename. since the destination filename on windows is not normalized and the filename for the same file to delete is (normalized), the check fails to acknowledge we're going to copy this file. this causes the following behavior on a stencil build: - if the polyfills directory exists, mark it to be copied, but subsequently delete it - if the polyfills directory does not exist, mark it to be copied. it will not be marked to be deleted because it does not exist on disk when the list of files to delete is calculated (prior to the copy) Fixes: #4661 STENCIL-918 --- src/compiler/output-targets/dist-lazy/generate-esm.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/output-targets/dist-lazy/generate-esm.ts b/src/compiler/output-targets/dist-lazy/generate-esm.ts index 57570672955..f0faaabe11e 100644 --- a/src/compiler/output-targets/dist-lazy/generate-esm.ts +++ b/src/compiler/output-targets/dist-lazy/generate-esm.ts @@ -1,5 +1,4 @@ -import { generatePreamble, relativeImport } from '@utils'; -import { join } from 'path'; +import { generatePreamble, join, relativeImport } from '@utils'; import type { OutputOptions, RollupBuild } from 'rollup'; import type * as d from '../../../declarations';