From 0932d6c09590db583193bbbff85e8b89303a78b9 Mon Sep 17 00:00:00 2001 From: Thijs Louisse Date: Tue, 5 Nov 2024 20:56:33 +0100 Subject: [PATCH 1/2] fix: expand script that corrects types after build --- .changeset/happy-toes-yell.md | 5 ++++ package-lock.json | 2 +- .../core/src/ScopedElementsMixin.js | 6 ++--- .../ui/scripts/types-correct-after-build.js | 25 ++++++++++++++----- 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 .changeset/happy-toes-yell.md 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..34deefb0a0 100644 --- a/packages/ui/components/core/src/ScopedElementsMixin.js +++ b/packages/ui/components/core/src/ScopedElementsMixin.js @@ -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'. - * Then 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 + * This file is a combination of '@open-wc/scoped-elements@v3/lit-element.js' and '@open-wc/scoped-elements@v3/html-element.js'. + * 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 internal * 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..f557e947e6 100644 --- a/packages/ui/scripts/types-correct-after-build.js +++ b/packages/ui/scripts/types-correct-after-build.js @@ -11,23 +11,36 @@ */ 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() { - const fileNames = await globby([`${packageRoot}/dist-types`]); +async function alignLitImportsAndFixLocalPaths() { + const fileNames = await globby('dist-types/**', { cwd: packageRoot }); + 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(); From 7eccc2433dd8ced7aa3a4280ad084c669e27f75b Mon Sep 17 00:00:00 2001 From: Thijs Louisse Date: Wed, 6 Nov 2024 11:48:51 +0100 Subject: [PATCH 2/2] fix(providence-analytics): optimisedGlob allows cwd with trailing slash --- .changeset/happy-bears-rescue.md | 5 +++ .../src/program/utils/optimised-glob.js | 15 ++++++- .../program/utils/optimised-glob.test.js | 40 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 .changeset/happy-bears-rescue.md diff --git a/.changeset/happy-bears-rescue.md b/.changeset/happy-bears-rescue.md new file mode 100644 index 0000000000..6c66dc2be9 --- /dev/null +++ b/.changeset/happy-bears-rescue.md @@ -0,0 +1,5 @@ +--- +'providence-analytics': patch +--- + +optimisedGlob: allow providing cwd with trailing slash diff --git a/packages-node/providence-analytics/src/program/utils/optimised-glob.js b/packages-node/providence-analytics/src/program/utils/optimised-glob.js index 2e49a95091..bb0d349318 100644 --- a/packages-node/providence-analytics/src/program/utils/optimised-glob.js +++ b/packages-node/providence-analytics/src/program/utils/optimised-glob.js @@ -116,7 +116,6 @@ export const parseGlobToRegex = memoize( } regexResultStr += currentChar; } - return new RegExp(`^${regexResultStr}$`); }, ); @@ -138,6 +137,15 @@ function isRootGlob(glob) { return glob.startsWith('/') || glob.startsWith('!/') || Boolean(glob.match(/^([A-Z]:\\|\\\\)/)); } +/** + * Makes sure cwd does not end with a slash + * @param {string} str + * @returns {string} + */ +function normalizeCwd(str) { + return str.endsWith('/') ? str.slice(0, -1) : str; +} + /** * @param {DirentWithPath} dirent * @param {{cwd:string}} cfg @@ -369,6 +377,8 @@ export async function optimisedGlob(globOrGlobs, providedOptions = {}) { ...providedOptions, }; + options.cwd = normalizeCwd(options.cwd); + if (!options.onlyFiles) { // This makes behavior aligned with globby options.onlyDirectories = true; @@ -403,6 +413,7 @@ export async function optimisedGlob(globOrGlobs, providedOptions = {}) { globstar: options.globstar, extglob: options.extglob, }); + if (isNegative) { matchRegexesNegative.push(regexForGlob); } else { @@ -416,8 +427,8 @@ export async function optimisedGlob(globOrGlobs, providedOptions = {}) { const fullStartPath = path.join(cwd, startPath); try { const allDirEntsRelativeToCwd = await getAllDirentsRelativeToCwd(fullStartPath, { - cwd, fs: options.fs, + cwd, }); globEntries.push(...allDirEntsRelativeToCwd); diff --git a/packages-node/providence-analytics/test-node/program/utils/optimised-glob.test.js b/packages-node/providence-analytics/test-node/program/utils/optimised-glob.test.js index a6b0683ef1..a4d252214c 100644 --- a/packages-node/providence-analytics/test-node/program/utils/optimised-glob.test.js +++ b/packages-node/providence-analytics/test-node/program/utils/optimised-glob.test.js @@ -157,6 +157,37 @@ function runSuiteForOptimisedGlob() { 'my/folder/some/file.js', ]); }); + + it('supports patterns like "my", "my/**" and "my/**/*" ', async () => { + const files = await runOptimisedGlobAndCheckGlobbyParity('my/**', testCfg); + + const allMy = [ + 'my/folder/some/anotherFile.d.ts', + 'my/folder/some/anotherFile.js', + 'my/folder/some/file.d.ts', + 'my/folder/some/file.js', + 'my/folder/lvl1/some/anotherFile.d.ts', + 'my/folder/lvl1/some/anotherFile.js', + 'my/folder/lvl1/some/file.d.ts', + 'my/folder/lvl1/some/file.js', + 'my/folder/lvl1/lvl2/some/anotherFile.d.ts', + 'my/folder/lvl1/lvl2/some/anotherFile.js', + 'my/folder/lvl1/lvl2/some/file.d.ts', + 'my/folder/lvl1/lvl2/some/file.js', + 'my/folder/lvl1/lvl2/lvl3/some/anotherFile.d.ts', + 'my/folder/lvl1/lvl2/lvl3/some/anotherFile.js', + 'my/folder/lvl1/lvl2/lvl3/some/file.d.ts', + 'my/folder/lvl1/lvl2/lvl3/some/file.js', + ]; + + expect(files).to.deep.equal(allMy); + + const files2 = await runOptimisedGlobAndCheckGlobbyParity('my/**/*', testCfg); + + expect(files2).to.deep.equal(allMy); + + // TODO: "my" (this will need a code change: preprocess 'my' to 'my/**') + }); }); describe('Accolade patterns', () => { @@ -351,6 +382,15 @@ function runSuiteForOptimisedGlob() { }); expect(files).to.deep.equal(['file.js']); }); + + it('supports cwd ending with "/"', async () => { + const files = await runOptimisedGlobAndCheckGlobbyParity('my/folder/*/some/file.js', { + ...testCfg, + cwd: '/fakeFs/', + }); + + expect(files).to.deep.equal(['my/folder/lvl1/some/file.js']); + }); }); }); }