Skip to content

Commit

Permalink
fix(compiler): persist polyfills on build
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
rwaskiewicz committed Oct 16, 2023
1 parent 183a05b commit 0a1efbd
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/compiler/output-targets/dist-lazy/generate-esm.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 0a1efbd

Please sign in to comment.