From 40236fbcdafcf4caca6cf23f839d17bbfdc915a8 Mon Sep 17 00:00:00 2001 From: Valentin Degenne Date: Wed, 8 Oct 2025 10:57:54 +0200 Subject: [PATCH 1/3] feat: add script to build package.json exports list --- scripts/exports/build-exports-list.ts | 64 +++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 scripts/exports/build-exports-list.ts diff --git a/scripts/exports/build-exports-list.ts b/scripts/exports/build-exports-list.ts new file mode 100644 index 0000000000..62aad5bcc5 --- /dev/null +++ b/scripts/exports/build-exports-list.ts @@ -0,0 +1,64 @@ +import {readdirSync, readFileSync, writeFileSync} from 'node:fs'; +import path, {dirname} from 'node:path'; +import {fileURLToPath} from 'node:url'; +import {COMPONENT_CUSTOM_ELEMENTS} from '../component-custom-elements.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +let exports: {[path: string]: {import: string; types: string}} = { + './all.js': { + import: './all.js', + types: './all.d.ts', + }, +}; + +Object.keys(COMPONENT_CUSTOM_ELEMENTS).forEach((component) => { + let paths: string[] = []; + paths.push( + ...COMPONENT_CUSTOM_ELEMENTS[ + component as keyof typeof COMPONENT_CUSTOM_ELEMENTS + ], + ); + + // add internals to the list of paths. + const componentDirname = component.toLocaleLowerCase(); + const internalDir = path.resolve( + `${__dirname}/../../${componentDirname}/internal/`, + ); + try { + const internals = readdirSync(internalDir, {withFileTypes: true}) + .filter( + (f) => + f.isFile() && + f.name.endsWith('.ts') && + !f.name.endsWith('.d.ts') && + !f.name.includes('_test') && + !f.name.includes('-styles'), + ) + .map((f) => path.join(componentDirname, 'internal', f.name)); + + paths.push(...internals); + } catch { + // no internal directory → ignore + } + + paths.forEach((filepath) => { + filepath = filepath.replace(/\.ts$/, ''); + exports[`./${filepath}.js`] = { + import: `./${filepath}.js`, + types: `./${filepath}.d.ts`, + }; + }); +}); + +const packageJson = JSON.parse( + readFileSync(path.resolve(__dirname, '../../package.json')).toString(), +); + +packageJson.exports = exports; + +writeFileSync( + path.resolve(__dirname, '../../package.json'), + JSON.stringify(packageJson, null, 2) + '\n', +); From ed52c965008dd201a736bb70b94266d560e6ea46 Mon Sep 17 00:00:00 2001 From: Valentin Degenne Date: Wed, 8 Oct 2025 11:17:02 +0200 Subject: [PATCH 2/3] some renamings --- scripts/exports/build-exports-list.ts | 35 +++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/scripts/exports/build-exports-list.ts b/scripts/exports/build-exports-list.ts index 62aad5bcc5..7cccffb1d3 100644 --- a/scripts/exports/build-exports-list.ts +++ b/scripts/exports/build-exports-list.ts @@ -1,12 +1,14 @@ import {readdirSync, readFileSync, writeFileSync} from 'node:fs'; -import path, {dirname} from 'node:path'; +import pathlib from 'node:path'; import {fileURLToPath} from 'node:url'; import {COMPONENT_CUSTOM_ELEMENTS} from '../component-custom-elements.js'; const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); +const __dirname = pathlib.dirname(__filename); -let exports: {[path: string]: {import: string; types: string}} = { +type ExportEntry = {import: string; types: string}; + +let exports: {[path: string]: ExportEntry} = { './all.js': { import: './all.js', types: './all.d.ts', @@ -22,9 +24,9 @@ Object.keys(COMPONENT_CUSTOM_ELEMENTS).forEach((component) => { ); // add internals to the list of paths. - const componentDirname = component.toLocaleLowerCase(); - const internalDir = path.resolve( - `${__dirname}/../../${componentDirname}/internal/`, + const componentName = component.toLocaleLowerCase(); + const internalDir = pathlib.resolve( + `${__dirname}/../../${componentName}/internal/`, ); try { const internals = readdirSync(internalDir, {withFileTypes: true}) @@ -36,7 +38,7 @@ Object.keys(COMPONENT_CUSTOM_ELEMENTS).forEach((component) => { !f.name.includes('_test') && !f.name.includes('-styles'), ) - .map((f) => path.join(componentDirname, 'internal', f.name)); + .map((f) => pathlib.join(componentName, 'internal', f.name)); paths.push(...internals); } catch { @@ -44,21 +46,18 @@ Object.keys(COMPONENT_CUSTOM_ELEMENTS).forEach((component) => { } paths.forEach((filepath) => { - filepath = filepath.replace(/\.ts$/, ''); - exports[`./${filepath}.js`] = { - import: `./${filepath}.js`, - types: `./${filepath}.d.ts`, + const path = filepath.replace(/\.ts$/, ''); + exports[`./${path}.js`] = { + import: `./${path}.js`, + types: `./${path}.d.ts`, }; }); }); -const packageJson = JSON.parse( - readFileSync(path.resolve(__dirname, '../../package.json')).toString(), -); +const packageLocation = pathlib.resolve(__dirname, '../../package.json'); + +const packageJson = JSON.parse(readFileSync(packageLocation).toString()); packageJson.exports = exports; -writeFileSync( - path.resolve(__dirname, '../../package.json'), - JSON.stringify(packageJson, null, 2) + '\n', -); +writeFileSync(packageLocation, JSON.stringify(packageJson, null, 2) + '\n'); From 3441ef1d3069de190d823e4fb88b09c43c7fbde7 Mon Sep 17 00:00:00 2001 From: Valentin Degenne Date: Wed, 8 Oct 2025 20:48:15 +0200 Subject: [PATCH 3/3] few adjustments --- scripts/exports/build-exports-list.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/exports/build-exports-list.ts b/scripts/exports/build-exports-list.ts index 7cccffb1d3..fe5129f457 100644 --- a/scripts/exports/build-exports-list.ts +++ b/scripts/exports/build-exports-list.ts @@ -16,7 +16,7 @@ let exports: {[path: string]: ExportEntry} = { }; Object.keys(COMPONENT_CUSTOM_ELEMENTS).forEach((component) => { - let paths: string[] = []; + const paths: string[] = []; paths.push( ...COMPONENT_CUSTOM_ELEMENTS[ component as keyof typeof COMPONENT_CUSTOM_ELEMENTS @@ -38,7 +38,7 @@ Object.keys(COMPONENT_CUSTOM_ELEMENTS).forEach((component) => { !f.name.includes('_test') && !f.name.includes('-styles'), ) - .map((f) => pathlib.join(componentName, 'internal', f.name)); + .map((f) => `${componentName}/internal/${f.name}`); paths.push(...internals); } catch { @@ -54,10 +54,17 @@ Object.keys(COMPONENT_CUSTOM_ELEMENTS).forEach((component) => { }); }); -const packageLocation = pathlib.resolve(__dirname, '../../package.json'); +const packageLocation = pathlib.resolve( + `${__dirname}/../../package.json`, +); -const packageJson = JSON.parse(readFileSync(packageLocation).toString()); +const packageJson = JSON.parse( + readFileSync(packageLocation).toString(), +); packageJson.exports = exports; -writeFileSync(packageLocation, JSON.stringify(packageJson, null, 2) + '\n'); +writeFileSync( + packageLocation, + JSON.stringify(packageJson, null, 2) + '\n', +);