fix: expand script that corrects types after build
This commit is contained in:
parent
8d178a548a
commit
0582868e41
4 changed files with 28 additions and 10 deletions
5
.changeset/happy-toes-yell.md
Normal file
5
.changeset/happy-toes-yell.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/ui': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
expand script that corrects types after build
|
||||||
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -28596,7 +28596,7 @@
|
||||||
},
|
},
|
||||||
"packages/ui": {
|
"packages/ui": {
|
||||||
"name": "@lion/ui",
|
"name": "@lion/ui",
|
||||||
"version": "0.8.1",
|
"version": "0.8.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@bundled-es-modules/message-format": "^6.2.4",
|
"@bundled-es-modules/message-format": "^6.2.4",
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ 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'.
|
* This file is a 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.
|
* To make the polyfill an opt-in, some code from '@open-wc/scoped-elements@v2' is added as well.
|
||||||
* This can be a great help for ssr scenarios, allowing elements to be consumed without needing knowledge about internall
|
* This can be a great help for ssr scenarios, allowing elements to be consumed without needing knowledge about internal
|
||||||
* consumption.
|
* consumption.
|
||||||
* (N.B. at this point in time, this is limited to the scenario where there's one version of lion on the page).
|
* (N.B. at this point in time, this is limited to the scenario where there's one version of lion on the page).
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -11,23 +11,36 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
// @ts-expect-error
|
||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
// 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';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
const packageRoot = fileURLToPath(new URL('../', import.meta.url));
|
const packageRoot = fileURLToPath(new URL('../', import.meta.url));
|
||||||
|
|
||||||
async function alignLitImports() {
|
async function alignLitImportsAndFixLocalPaths() {
|
||||||
const fileNames = await globby([`${packageRoot}/dist-types`]);
|
const fileNames = await globby('dist-types/**', { cwd: packageRoot });
|
||||||
|
|
||||||
for (const fileName of fileNames) {
|
for (const fileName of fileNames) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
const contents = await fs.promises.readFile(fileName, 'utf-8');
|
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,
|
/(LitElement.*\}) from "lit-element\/lit-element\.js/g,
|
||||||
'$1 from "lit',
|
'$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();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue