diff --git a/.changeset/happy-toes-yell.md b/.changeset/happy-toes-yell.md new file mode 100644 index 0000000000..94451a2cb5 --- /dev/null +++ b/.changeset/happy-toes-yell.md @@ -0,0 +1,5 @@ +--- +'@lion/ui': patch +--- + +expand script that corrects types after build diff --git a/package-lock.json b/package-lock.json index 596463e3f1..d2dc292225 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28596,7 +28596,7 @@ }, "packages/ui": { "name": "@lion/ui", - "version": "0.8.1", + "version": "0.8.3", "license": "MIT", "dependencies": { "@bundled-es-modules/message-format": "^6.2.4", diff --git a/packages/ui/components/core/src/ScopedElementsMixin.js b/packages/ui/components/core/src/ScopedElementsMixin.js index a41f6e9f61..355322e928 100644 --- a/packages/ui/components/core/src/ScopedElementsMixin.js +++ b/packages/ui/components/core/src/ScopedElementsMixin.js @@ -21,8 +21,8 @@ export function supportsScopedRegistry() { } /** - * This file is combination of '@open-wc/scoped-elements@v3/lit-element.js' and '@open-wc/scoped-elements@v3/html-element.js'. - * Then on top of those, some code from '@open-wc/scoped-elements@v2' is brought to to make polyfill not mandatory. + * This file is a combination of '@open-wc/scoped-elements@v3/lit-element.js' and '@open-wc/scoped-elements@v3/html-element.js'. + * On top of those, some code from '@open-wc/scoped-elements@v2' is brought to to make polyfill not mandatory. * This can be a great help for ssr scenarios, allowing elements to be consumed without needing knowledge about internall * consumption. * (N.B. at this point in time, this is limited to the scenario where there's one version of lion on the page). diff --git a/packages/ui/scripts/types-correct-after-build.js b/packages/ui/scripts/types-correct-after-build.js index 7c13852292..24b714ae5b 100644 --- a/packages/ui/scripts/types-correct-after-build.js +++ b/packages/ui/scripts/types-correct-after-build.js @@ -11,23 +11,35 @@ */ import fs from 'fs'; +// @ts-expect-error // eslint-disable-next-line import/no-extraneous-dependencies -import { globby } from 'globby'; +import { optimisedGlob as globby } from 'providence-analytics/utils.js'; import { fileURLToPath } from 'url'; const packageRoot = fileURLToPath(new URL('../', import.meta.url)); -async function alignLitImports() { +async function alignLitImportsAndFixLocalpaths() { const fileNames = await globby([`${packageRoot}/dist-types`]); for (const fileName of fileNames) { // eslint-disable-next-line no-await-in-loop const contents = await fs.promises.readFile(fileName, 'utf-8'); - const replaced = contents.replace( + const replaced1 = contents.replace( /(LitElement.*\}) from "lit-element\/lit-element\.js/g, '$1 from "lit', ); - fs.promises.writeFile(fileName, replaced); + + // Now "unresolve" all paths that reference '../**/node_modules/**' + // These are outside of the bundled repo and therefore break in consuming context + // Also, they are resolved to their local context via the export map, this should be 'unwinded' + + const re = /\("(..\/)*?node_modules\/@open-wc\/scoped-elements\/types\.js"\)/g; + const replaced2 = replaced1.replace(re, '("@open-wc/scoped-elements/lit-element.js")'); + + // For now, we did a quick and dirty fix with specific knowledge of this repo, + // because we expect https://github.com/microsoft/TypeScript/issues/51622 to be solved in the future. + + fs.promises.writeFile(fileName, replaced2); } } -alignLitImports(); +alignLitImportsAndFixLocalpaths();